本文整理汇总了Java中javax.naming.NameParser类的典型用法代码示例。如果您正苦于以下问题:Java NameParser类的具体用法?Java NameParser怎么用?Java NameParser使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
NameParser类属于javax.naming包,在下文中一共展示了NameParser类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getNameParser
import javax.naming.NameParser; //导入依赖的package包/类
/**
* Retrieves the parser associated with the named context. In a
* federation of namespaces, different naming systems will parse names
* differently. This method allows an application to get a parser for
* parsing names into their atomic components using the naming convention
* of a particular naming system. Within any single naming system,
* NameParser objects returned by this method must be equal (using the
* equals() test).
*
* @param name the name of the context from which to get the parser
* @return a name parser that can parse compound names into their atomic
* components
* @exception NamingException if a naming exception is encountered
*/
@Override
public NameParser getNameParser(Name name)
throws NamingException {
while ((!name.isEmpty()) && (name.get(0).length() == 0))
name = name.getSuffix(1);
if (name.isEmpty())
return nameParser;
if (name.size() > 1) {
Object obj = bindings.get(name.get(0));
if (obj instanceof Context) {
return ((Context) obj).getNameParser(name.getSuffix(1));
} else {
throw new NotContextException
(sm.getString("namingContext.contextExpected"));
}
}
return nameParser;
}
示例2: getNameParser
import javax.naming.NameParser; //导入依赖的package包/类
/**
* Retrieves the parser associated with the named context. In a
* federation of namespaces, different naming systems will parse names
* differently. This method allows an application to get a parser for
* parsing names into their atomic components using the naming convention
* of a particular naming system. Within any single naming system,
* NameParser objects returned by this method must be equal (using the
* equals() test).
*
* @param name the name of the context from which to get the parser
* @return a name parser that can parse compound names into their atomic
* components
* @exception NamingException if a naming exception is encountered
*/
public NameParser getNameParser(Name name)
throws NamingException {
while ((!name.isEmpty()) && (name.get(0).length() == 0))
name = name.getSuffix(1);
if (name.isEmpty())
return nameParser;
if (name.size() > 1) {
Object obj = bindings.get(name.get(0));
if (obj instanceof Context) {
return ((Context) obj).getNameParser(name.getSuffix(1));
} else {
throw new NotContextException
(sm.getString("namingContext.contextExpected"));
}
}
return nameParser;
}
示例3: getNameParser
import javax.naming.NameParser; //导入依赖的package包/类
/**
* Retrieves the parser associated with the named context. In a
* federation of namespaces, different naming systems will parse names
* differently. This method allows an application to get a parser for
* parsing names into their atomic components using the naming convention
* of a particular naming system. Within any single naming system,
* NameParser objects returned by this method must be equal (using the
* equals() test).
*
* @param name the name of the context from which to get the parser
* @return a name parser that can parse compound names into their atomic
* components
* @exception NamingException if a naming exception is encountered
*/
public NameParser getNameParser(Name name)
throws NamingException {
while ((!name.isEmpty()) && (name.get(0).length() == 0))
name = name.getSuffix(1);
if (name.isEmpty())
return nameParser;
if (name.size() > 1) {
Object obj = bindings.get(name.get(0));
if (obj instanceof Context) {
return ((Context) obj).getNameParser(name.getSuffix(1));
} else {
throw new NotContextException
(sm.getString("namingContext.contextExpected"));
}
}
return nameParser;
}
示例4: getNameParser
import javax.naming.NameParser; //导入依赖的package包/类
/**
* Retrieves the parser associated with the named context. In a federation
* of namespaces, different naming systems will parse names differently.
* This method allows an application to get a parser for parsing names into
* their atomic components using the naming convention of a particular
* naming system. Within any single naming system, NameParser objects
* returned by this method must be equal (using the equals() test).
*
* @param name
* the name of the context from which to get the parser
* @return a name parser that can parse compound names into their atomic
* components
* @exception NamingException
* if a naming exception is encountered
*/
@Override
public NameParser getNameParser(Name name) throws NamingException {
while ((!name.isEmpty()) && (name.get(0).length() == 0))
name = name.getSuffix(1);
if (name.isEmpty())
return nameParser;
if (name.size() > 1) {
Object obj = bindings.get(name.get(0));
if (obj instanceof Context) {
return ((Context) obj).getNameParser(name.getSuffix(1));
} else {
throw new NotContextException(sm.getString("namingContext.contextExpected"));
}
}
return nameParser;
}
示例5: getNameParser
import javax.naming.NameParser; //导入依赖的package包/类
/**
* Retrieves the parser associated with the named context. In a
* federation of namespaces, different jndi systems will parse names
* differently. This method allows an application to get a parser for
* parsing names into their atomic components using the jndi convention
* of a particular jndi system. Within any single jndi system,
* NameParser objects returned by this method must be equal (using the
* equals() test).
*
* @param name the name of the context from which to get the parser
* @return a name parser that can parse compound names into their atomic
* components
* @throws NamingException if a jndi exception is encountered
*/
@Override
public NameParser getNameParser(Name name) throws NamingException {
while ((!name.isEmpty()) && (name.get(0).length() == 0)) {
name = name.getSuffix(1);
}
if (name.isEmpty()) {
return NAME_PARSER;
}
if (name.size() > 1) {
Object obj = bindings.get(name.get(0));
if (obj instanceof Context) {
return ((Context) obj).getNameParser(name.getSuffix(1));
} else {
throw new NotContextException(SM.getString("namingContext.contextExpected"));
}
}
return NAME_PARSER;
}
示例6: testDataSource
import javax.naming.NameParser; //导入依赖的package包/类
/**
* Tests that we can get a connection from the DataSource bound in JNDI
* during test setup
*
* @throws Exception
* if an error occurs
*/
public void testDataSource() throws Exception {
NameParser nameParser = this.ctx.getNameParser("");
Name datasourceName = nameParser.parse("_test");
Object obj = this.ctx.lookup(datasourceName);
DataSource boundDs = null;
if (obj instanceof DataSource) {
boundDs = (DataSource) obj;
} else if (obj instanceof Reference) {
//
// For some reason, this comes back as a Reference instance under CruiseControl !?
//
Reference objAsRef = (Reference) obj;
ObjectFactory factory = (ObjectFactory) Class.forName(objAsRef.getFactoryClassName()).newInstance();
boundDs = (DataSource) factory.getObjectInstance(objAsRef, datasourceName, this.ctx, new Hashtable<Object, Object>());
}
assertTrue("Datasource not bound", boundDs != null);
Connection con = boundDs.getConnection();
con.close();
assertTrue("Connection can not be obtained from data source", con != null);
}
示例7: lookupDatasourceInJNDI
import javax.naming.NameParser; //导入依赖的package包/类
private DataSource lookupDatasourceInJNDI(String jndiName) throws Exception {
NameParser nameParser = this.ctx.getNameParser("");
Name datasourceName = nameParser.parse(this.tempDir.getAbsolutePath() + jndiName);
Object obj = this.ctx.lookup(datasourceName);
DataSource boundDs = null;
if (obj instanceof DataSource) {
boundDs = (DataSource) obj;
} else if (obj instanceof Reference) {
//
// For some reason, this comes back as a Reference instance under CruiseControl !?
//
Reference objAsRef = (Reference) obj;
ObjectFactory factory = (ObjectFactory) Class.forName(objAsRef.getFactoryClassName()).newInstance();
boundDs = (DataSource) factory.getObjectInstance(objAsRef, datasourceName, this.ctx, new Hashtable<Object, Object>());
}
return boundDs;
}
示例8: lookupDatasourceInJNDI
import javax.naming.NameParser; //导入依赖的package包/类
private DataSource lookupDatasourceInJNDI(String jndiName) throws Exception {
NameParser nameParser = this.ctx.getNameParser("");
Name datasourceName = nameParser.parse(this.tempDir.getAbsolutePath()
+ jndiName);
Object obj = this.ctx.lookup(datasourceName);
DataSource boundDs = null;
if (obj instanceof DataSource) {
boundDs = (DataSource) obj;
} else if (obj instanceof Reference) {
//
// For some reason, this comes back as a Reference
// instance under CruiseControl !?
//
Reference objAsRef = (Reference) obj;
ObjectFactory factory = (ObjectFactory) Class.forName(
objAsRef.getFactoryClassName()).newInstance();
boundDs = (DataSource) factory.getObjectInstance(objAsRef,
datasourceName, this.ctx, new Hashtable<Object, Object>());
}
return boundDs;
}
示例9: getNameParser
import javax.naming.NameParser; //导入依赖的package包/类
/**
* Tries to look for the context associated with the given name and returns
* the appropriate name parser. For <code>DNSContext</code> this method
* will return an instance of <code>DNSNameParser</code> class.
*
* @param a
* name to return a name parser for
* @return a name parser for the naming system the found context is
* associated with
* @throws NotContextException
* if found object is not a context so we cannot obtain a name
* parser from it
* @throws NamingException
* if such exception was encountered during lookup
* @see Context#getNameParser(Name)
*/
public NameParser getNameParser(Name name) throws NamingException {
Object obj;
if (name == null) {
// jndi.2E=The name is null
throw new NullPointerException(Messages.getString("jndi.2E")); //$NON-NLS-1$
}
obj = lookup(name);
if (obj instanceof DNSContext) {
return nameParser;
} else if (obj instanceof Context) {
return ((Context) obj).getNameParser(""); //$NON-NLS-1$
}
// jndi.4E=found object is not a Context
throw new NotContextException(Messages.getString("jndi.4E")); //$NON-NLS-1$
}
示例10: getNameParser
import javax.naming.NameParser; //导入依赖的package包/类
/**
* Returns the name parser for given name.
*
* @param name
* a name in the string form to return a name parser for
* @return the name parser found
* @throws NotContextException
* if found object is not a context
* @throws NamingException
* if such exception was encountered during lookup
* @see DNSContext#getNameParser(Name) for details
* @see javax.naming.Context#getNameParser(java.lang.String)
*/
public NameParser getNameParser(String name) throws NamingException {
Object obj;
if (name == null) {
// jndi.2E=The name is null
throw new NullPointerException(Messages.getString("jndi.2E")); //$NON-NLS-1$
}
obj = lookup(name);
if (obj instanceof DNSContext) {
return nameParser;
} else if (obj instanceof Context) {
return ((Context) obj).getNameParser(""); //$NON-NLS-1$
}
// jndi.4E=found object is not a Context
throw new NotContextException(Messages.getString("jndi.4E")); //$NON-NLS-1$
}
示例11: getNameParser
import javax.naming.NameParser; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
public NameParser getNameParser(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 getNameParser(name.get(0));
}
Context context = getContinuationContext(name);
try {
return context.getNameParser(name.getSuffix(1));
} finally {
context.close();
}
}
示例12: getLDAPGroupNames
import javax.naming.NameParser; //导入依赖的package包/类
private Collection<Name> getLDAPGroupNames(DirContext ctx, Attributes useratt)
{
Set<Name> foundGroups = new HashSet<Name>();
if( !Check.isEmpty(memberOfField) )
{
Attribute attribute = useratt.get(memberOfField);
try
{
NameParser parser = ctx.getNameParser(""); //$NON-NLS-1$
if( attribute != null )
{
NamingEnumeration<?> enumeration = attribute.getAll();
while( enumeration != null && enumeration.hasMore() )
{
String role = (String) enumeration.next();
Name compound = parser.parse(role);
foundGroups.add(compound);
}
}
}
catch( NamingException e )
{
throw new RuntimeException("Couldn't get memberField", e);
}
}
return foundGroups;
}
示例13: getDistinguishedName
import javax.naming.NameParser; //导入依赖的package包/类
/**
* Returns the distinguished name of a search result.
*
* @param context Our DirContext
* @param base The base DN
* @param result The search result
* @return String containing the distinguished name
*/
protected String getDistinguishedName(DirContext context, String base, SearchResult result)
throws NamingException {
// Get the entry's distinguished name
NameParser parser = context.getNameParser("");
Name contextName = parser.parse(context.getNameInNamespace());
Name baseName = parser.parse(base);
// Bugzilla 32269
Name entryName = parser.parse(new CompositeName(result.getName()).get(0));
Name name = contextName.addAll(baseName);
name = name.addAll(entryName);
return name.toString();
}
示例14: getNameParser
import javax.naming.NameParser; //导入依赖的package包/类
@Override
public NameParser getNameParser(Name name) throws NamingException {
Object obj = lookup(name);
if (obj instanceof Context)
((Context) obj).close();
return this;
}
示例15: getNameParser
import javax.naming.NameParser; //导入依赖的package包/类
@Override
public NameParser getNameParser(final Name name) throws NamingException {
// Do lookup to verify name exists
final Object obj = lookup(name);
if (obj instanceof Context) {
((Context) obj).close();
}
return NamingContext.nameParser;
}