本文整理汇总了Java中javax.naming.NameClassPair类的典型用法代码示例。如果您正苦于以下问题:Java NameClassPair类的具体用法?Java NameClassPair怎么用?Java NameClassPair使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
NameClassPair类属于javax.naming包,在下文中一共展示了NameClassPair类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: list
import javax.naming.NameClassPair; //导入依赖的package包/类
/**
* Enumerates the names bound in the named context, along with the class
* names of objects bound to them. The contents of any subcontexts are
* not included.
* <p>
* If a binding is added to or removed from this context, its effect on
* an enumeration previously returned is undefined.
*
* @param name the name of the context to list
* @return an enumeration of the names and class names of the bindings in
* this context. Each element of the enumeration is of type NameClassPair.
* @exception NamingException if a naming exception is encountered
*/
@Override
public NamingEnumeration<NameClassPair> list(Name name)
throws NamingException {
// Removing empty parts
while ((!name.isEmpty()) && (name.get(0).length() == 0))
name = name.getSuffix(1);
if (name.isEmpty()) {
return new NamingContextEnumeration(bindings.values().iterator());
}
NamingEntry entry = bindings.get(name.get(0));
if (entry == null) {
throw new NameNotFoundException
(sm.getString("namingContext.nameNotBound", name, name.get(0)));
}
if (entry.type != NamingEntry.CONTEXT) {
throw new NamingException
(sm.getString("namingContext.contextExpected"));
}
return ((Context) entry.value).list(name.getSuffix(1));
}
示例2: list
import javax.naming.NameClassPair; //导入依赖的package包/类
/**
* Enumerates the names bound in the named context, along with the class
* names of objects bound to them. The contents of any subcontexts are not
* included.
* <p>
* If a binding is added to or removed from this context, its effect on an
* enumeration previously returned is undefined.
*
* @param name
* the name of the context to list
* @return an enumeration of the names and class names of the bindings in
* this context. Each element of the enumeration is of type
* NameClassPair.
* @exception NamingException
* if a naming exception is encountered
*/
@Override
public NamingEnumeration<NameClassPair> list(Name name) throws NamingException {
// Removing empty parts
while ((!name.isEmpty()) && (name.get(0).length() == 0))
name = name.getSuffix(1);
if (name.isEmpty()) {
return new NamingContextEnumeration(bindings.values().iterator());
}
NamingEntry entry = bindings.get(name.get(0));
if (entry == null) {
throw new NameNotFoundException(sm.getString("namingContext.nameNotBound", name, name.get(0)));
}
if (entry.type != NamingEntry.CONTEXT) {
throw new NamingException(sm.getString("namingContext.contextExpected"));
}
return ((Context) entry.value).list(name.getSuffix(1));
}
示例3: service
import javax.naming.NameClassPair; //导入依赖的package包/类
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
try {
Properties p = new Properties();
p.put("java.naming.factory.initial", "org.apache.openejb.client.RemoteInitialContextFactory");
p.put("java.naming.provider.url", "http://localhost:8080/tomee/ejb");
// user and pass optional
// p.put("java.naming.security.principal", "myuser");
// p.put("java.naming.security.credentials", "mypass");
InitialContext ctx = new InitialContext(p);
for (NameClassPair pair : Collections.list(ctx.list(""))) {
System.out.println(pair.getName());
System.out.println(pair.getClassName());
}
// ejbBankAccount = (BankAccountRemote) ctx.lookup("BankAccountEJB");
ejbBankAccount = (BankAccountRemote) ctx.lookup("BankAccountEJBRemote");
ejbBankAccount.transfer(BigDecimal.valueOf(100), 1, 2);
System.out.println("EJB OK");
} catch (Exception ex) {
ex.printStackTrace();
}
}
示例4: list
import javax.naming.NameClassPair; //导入依赖的package包/类
/**
* Enumerates the names bound in the named context, along with the class
* names of objects bound to them. The contents of any subcontexts are
* not included.
* <p>
* If a binding is added to or removed from this context, its effect on
* an enumeration previously returned is undefined.
*
* @param name the name of the context to list
* @return an enumeration of the names and class names of the bindings in
* this context. Each element of the enumeration is of type NameClassPair.
* @throws NamingException if a jndi exception is encountered
*/
@Override
public NamingEnumeration<NameClassPair> list(Name name) throws NamingException {
// Removing empty parts
while ((!name.isEmpty()) && (name.get(0).length() == 0)) {
name = name.getSuffix(1);
}
if (name.isEmpty()) {
return new NamingContextEnumeration(new ArrayList<>(bindings.values()));
}
NamingEntry entry = bindings.get(name.get(0));
if (entry == null) {
throw new NameNotFoundException(SM.getString("namingContext.nameNotBound", name, name.get(0)));
}
if (entry.type != NamingEntry.CONTEXT) {
throw new NamingException(SM.getString("namingContext.contextExpected"));
}
return ((Context) entry.value).list(name.getSuffix(1));
}
示例5: findByTypeWithName
import javax.naming.NameClassPair; //导入依赖的package包/类
public <T> Map<String, T> findByTypeWithName(Class<T> type) {
Map<String, T> answer = new LinkedHashMap<String, T>();
try {
NamingEnumeration<NameClassPair> list = getContext().list("");
while (list.hasMore()) {
NameClassPair pair = list.next();
Object instance = context.lookup(pair.getName());
if (type.isInstance(instance)) {
answer.put(pair.getName(), type.cast(instance));
}
}
} catch (NamingException e) {
// ignore
}
return answer;
}
示例6: findByType
import javax.naming.NameClassPair; //导入依赖的package包/类
public <T> Set<T> findByType(Class<T> type) {
Set<T> answer = new LinkedHashSet<T>();
try {
NamingEnumeration<NameClassPair> list = getContext().list("");
while (list.hasMore()) {
NameClassPair pair = list.next();
Object instance = context.lookup(pair.getName());
if (type.isInstance(instance)) {
answer.add(type.cast(instance));
}
}
} catch (NamingException e) {
// ignore
}
return answer;
}
示例7: list
import javax.naming.NameClassPair; //导入依赖的package包/类
@Override
public NamingEnumeration<NameClassPair> list(final Name name) throws NamingException {
final Name searchName = validateName(name);
// If null, it means we don't know how to handle this -> throw to the
// parent
if (searchName == null) {
return parent.list(name);
} else if (searchName.isEmpty()) {
// listing this context
return new Names(bindings);
}
// Perhaps 'name' names a context
final Object target = lookup(name);
if (target instanceof Context) {
return ((Context) target).list("");
}
throw new NotContextException(name + " cannot be listed");
}
示例8: contextDump
import javax.naming.NameClassPair; //导入依赖的package包/类
private static String contextDump(Context ctx, String root, boolean recurse, int level)
{
StringBuilder sb = new StringBuilder();
try
{
for( NamingEnumeration<NameClassPair> list = ctx.list(root); list.hasMore(); )
{
NameClassPair nc = list.next();
for(int t=0; t<level; ++t)
sb.append('\t');
sb.append(nc);
sb.append("line.separator");
if(recurse)
{
String childPath = root.length() > 0 ? root + "/" + nc.getName() : nc.getName();
contextDump(ctx, childPath, recurse, level+1);
}
}
}
catch(NamingException nX)
{
sb.append(nX.getMessage());
}
return sb.toString();
}
示例9: testRunning
import javax.naming.NameClassPair; //导入依赖的package包/类
@Test
public void testRunning() throws Exception {
DirContext ctx = getContext();
HashSet<String> set = new HashSet<>();
NamingEnumeration<NameClassPair> list = ctx.list("ou=system");
while (list.hasMore()) {
NameClassPair ncp = list.next();
set.add(ncp.getName());
}
Assert.assertTrue(set.contains("uid=admin"));
Assert.assertTrue(set.contains("ou=users"));
Assert.assertTrue(set.contains("ou=groups"));
Assert.assertTrue(set.contains("ou=configuration"));
Assert.assertTrue(set.contains("prefNodeName=sysPrefRoot"));
}
示例10: testRunning
import javax.naming.NameClassPair; //导入依赖的package包/类
@Test
public void testRunning() throws Exception {
Hashtable<String, String> env = new Hashtable<>();
env.put(Context.PROVIDER_URL, "ldap://localhost:1024");
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.SECURITY_AUTHENTICATION, "simple");
env.put(Context.SECURITY_PRINCIPAL, PRINCIPAL);
env.put(Context.SECURITY_CREDENTIALS, CREDENTIALS);
DirContext ctx = new InitialDirContext(env);
HashSet<String> set = new HashSet<>();
NamingEnumeration<NameClassPair> list = ctx.list("ou=system");
while (list.hasMore()) {
NameClassPair ncp = list.next();
set.add(ncp.getName());
}
Assert.assertTrue(set.contains("uid=admin"));
Assert.assertTrue(set.contains("ou=users"));
Assert.assertTrue(set.contains("ou=groups"));
Assert.assertTrue(set.contains("ou=configuration"));
Assert.assertTrue(set.contains("prefNodeName=sysPrefRoot"));
}
示例11: list
import javax.naming.NameClassPair; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
public NamingEnumeration<NameClassPair> list(Name name)
throws NamingException {
if (name.isEmpty()) {
try {
return new NameClassPairEnumeration(registry.list());
} catch (RemoteException e) {
throw (NamingException) newNamingException(e)
.fillInStackTrace();
}
}
Object obj = lookup(name);
if (obj instanceof Context) {
try {
return ((Context) obj).list(""); //$NON-NLS-1$
} finally {
((Context) obj).close();
}
}
// jndi.80=Name specifies an object that is not a context: {0}
throw new NotContextException(Messages.getString("jndi.80", name)); //$NON-NLS-1$
}
示例12: getContextDescription
import javax.naming.NameClassPair; //导入依赖的package包/类
/**
* Create an XML description of a {@link javax.naming.Context} from the server.
* @param outOfScope <code>true</code> if the class for this context is not in the classpath.
* @return An XML string describing the current RMI context.
* @throws NamingException If the RMI context could not be accessed.
*/
private String getContextDescription(boolean outOfScope) throws NamingException {
StringBuilder dsc = getHeader();
dsc.append("<context name=\"").append(rmiRegistryContext.getNameInNamespace()).append("\">\n");
NamingEnumeration<NameClassPair> ne = rmiRegistryContext.list("");
while (ne.hasMore()) {
NameClassPair nc = ne.next();
dsc.append(" <name value=\"").append(nc.getName());
if (nc.isRelative()) dsc.append("\" relative=\"").append(nc.isRelative());
dsc.append("\">\n");
dsc.append(" <class name=\"").append(nc.getClassName()).append("\"");
if (outOfScope) dsc.append(" inscope=\"false\"");
dsc.append("/>\n </name>\n");
}
dsc.append("</context>");
return dsc.toString();
}
示例13: list
import javax.naming.NameClassPair; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
public NamingEnumeration<NameClassPair> list(Name name)
throws NamingException {
if (!(name instanceof CompositeName)) {
// jndi.26=URL context can't accept non-composite name: {0}
throw new InvalidNameException(Messages.getString("jndi.26", name)); //$NON-NLS-1$
}
if (name.size() == 1) {
return list(name.get(0));
}
Context context = getContinuationContext(name);
try {
return context.list(name.getSuffix(1));
} finally {
context.close();
}
}
示例14: testAttributeDefinition
import javax.naming.NameClassPair; //导入依赖的package包/类
public void testAttributeDefinition() throws NamingException {
addMoreAttributeData();
MockLdapContext mockContext = new MockLdapContext(context, null, "");
Attribute attr = new LdapAttribute("objectclass", mockContext);
DirContext attributeDefinition = attr.getAttributeDefinition();
NamingEnumeration<NameClassPair> ne = attributeDefinition.list("");
assertFalse(ne.hasMore());
try {
ne = attributeDefinition.list("invalid");
fail("Should throw NameNotFoundException");
} catch (NameNotFoundException e) {
// Expected.
}
Attributes schemaAttributes = attributeDefinition.getAttributes("");
assertEquals(7, schemaAttributes.size());
assertEquals("1.3.6.1.4.1.1466.115.121.1.38", schemaAttributes.get(
"syntax").get());
assertEquals("objectClass", schemaAttributes.get("name").get());
assertEquals("2.5.4.0", schemaAttributes.get("numericoid").get());
assertEquals("userApplications", schemaAttributes.get("usage").get());
assertEquals("objectIdentifierMatch", schemaAttributes.get("equality")
.get());
}
示例15: testSyntaxDefinition
import javax.naming.NameClassPair; //导入依赖的package包/类
public void testSyntaxDefinition() throws NamingException {
addMoreAttributeData();
MockLdapContext mockContext = new MockLdapContext(context, null, "");
Attribute attr = new LdapAttribute("objectclass", mockContext);
DirContext attributeDefinition = attr.getAttributeSyntaxDefinition();
NamingEnumeration<NameClassPair> ne = attributeDefinition.list("");
assertFalse(ne.hasMore());
try {
ne = attributeDefinition.list("invalid");
fail("Should throw NameNotFoundException");
} catch (NameNotFoundException e) {
// Expected.
}
Attributes schemaAttributes = attributeDefinition.getAttributes("");
assertEquals(3, schemaAttributes.size());
assertEquals("system", schemaAttributes.get("x-schema").get());
assertEquals("true", schemaAttributes.get("x-is-human-readable").get());
assertEquals("1.3.6.1.4.1.1466.115.121.1.38", schemaAttributes.get(
"numericoid").get());
}