/** * 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; }
/** * 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; }
/** * 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; }
/** * 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; }
/** * 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); }
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; }
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; }
/** * 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$ }
/** * 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$ }
/** * {@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(); } }
/** * 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 Context#getNameParser(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$ }
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; }
/** * 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(); }
@Override public NameParser getNameParser(Name name) throws NamingException { Object obj = lookup(name); if (obj instanceof Context) ((Context) obj).close(); return this; }
@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; }
/** * 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); }
/** * {@inheritDoc} */ public NameParser getNameParser(String name) throws NamingException { ResolveResult result = getRootURLContext(name, environment); Context context = (Context) result.getResolvedObj(); try { return context.getNameParser(result.getRemainingName()); } finally { context.close(); } }
public NameParser getNameParser(Name name) throws NamingException { if (hasMultiNamingSpace(name)) { /* * multi ns, find next ns context, delegate operation to the next * context */ Context nns = findNnsContext(name); Name remainingName = name.getSuffix(1); return nns.getNameParser(remainingName); } return parser; }