if (pos > 0) { String scheme = name.substring(0, pos); Context ctx = NamingManager.getURLContext(scheme, environment); if (ctx == null) { throw new NamingException("scheme " + scheme + " not recognized"); return ctx.lookup(name); } else { Object obj = bindings.get(first); if (obj == null) { throw new NameNotFoundException(name); } else if (obj instanceof Context && path.size() > 1) { Context subContext = (Context) obj; obj = subContext.lookup(path.getSuffix(1)); result = NamingManager.getObjectInstance(result, null, null, this.environment); } catch (NamingException e) { throw e; } catch (Exception e) { throw (NamingException) new NamingException("could not look up : " + name).initCause(e);
try { obj = NamingManager.getStateToBind(obj, name, this, _env); } catch (BAD_PARAM e) { NamingException ne = new NotContextException(name.toString()); ne.setRootCause(e); throw ne; } catch (Exception e) {
/** * Register the context builder by registering it with the JNDI NamingManager. * Note that once this has been done, {@code new InitialContext()} will always * return a context from this factory. Use the {@code emptyActivatedContextBuilder()} * static method to get an empty context (for example, in test methods). * @throws IllegalStateException if there's already a naming context builder * registered with the JNDI NamingManager */ public void activate() throws IllegalStateException, NamingException { logger.info("Activating simple JNDI environment"); synchronized (initializationLock) { if (!initialized) { Assert.state(!NamingManager.hasInitialContextFactoryBuilder(), "Cannot activate SimpleNamingContextBuilder: there is already a JNDI provider registered. " + "Note that JNDI is a JVM-wide service, shared at the JVM system class loader level, " + "with no reset option. As a consequence, a JNDI provider must only be registered once per JVM."); NamingManager.setInitialContextFactoryBuilder(this); initialized = true; } } activated = this; }
throw new NamingException ("This context is immutable"); throw new NamingException ("Name is null"); if (cname.size() == 0) throw new NamingException ("Name is empty"); if (cname.size() == 1) Object objToBind = NamingManager.getStateToBind(obj, name, this, null); if (objToBind instanceof Referenceable) if(Log.isDebugEnabled())Log.debug("Checking for existing binding for name="+cname+" for first element of name="+cname.get(0)); String firstComponent = cname.get(0); Binding binding = getBinding (name.get(0)); if (binding == null) throw new NameNotFoundException (name.get(0)+ " is not bound"); ctx = NamingManager.getObjectInstance(ctx, getNameParser("").parse(firstComponent), this, _env); ((Context)ctx).rebind (cname.getSuffix(1), obj); throw new NotContextException ("Object bound at "+firstComponent +" is not a Context");
if (cname.size() == 0) String firstComponent = cname.get(0); Object ctx = null; throw new NameNotFoundException (); if(__log.isDebugEnabled())__log.debug("Dereferencing Reference for "+name.get(0)); try ctx = NamingManager.getObjectInstance(ctx, getNameParser("").parse(firstComponent), __root, _env); throw new NamingException (e.getMessage()); throw new NotContextException(); return ((Context)ctx).list (cname.getSuffix(1));
if (cname.size() == 0) String firstComponent = cname.get(0); Object ctx = null; throw new NameNotFoundException (); ctx = NamingManager.getObjectInstance(ctx, getNameParser("").parse(firstComponent), this, _env); throw new NamingException (e.getMessage()); throw new NotContextException(); return ((Context)ctx).listBindings (cname.getSuffix(1));
if (_nc == null) throw IIOPLogger.ROOT_LOGGER.notANamingContext(name.toString()); if (name.size() == 0) return this; // %%% should clone() so that env can be changed NameComponent[] path = org.wildfly.iiop.openjdk.naming.jndi.CNNameParser.nameToCosName(name); return NamingManager.getObjectInstance(answer, name, this, _env); } catch (NamingException e) { throw e; } catch (Exception e) { NamingException ne = IIOPLogger.ROOT_LOGGER.errorGeneratingObjectViaFactory(); ne.setRootCause(e); throw ne; return cctx.lookup(cpe.getRemainingName());
@Override public Object lookup(Name name) throws NamingException { if (name.isEmpty()) { return this.clone(); String atomicName = normalizedName.get(0); Object atomicNameBinding = bindings.get(atomicName); if (normalizedName.size() == 1) { if (atomicNameBinding == null) { throw new NameNotFoundException("Name ["+atomicName+"] from ["+normalizedName+"] not found in this binding"); return NamingManager.getObjectInstance( atomicNameBinding, new CompositeName().add(atomicName), env); } catch (Exception e) { NamingException _e = new NamingException("NamingManager.getObjectInstance(...) failed"); _e.setRootCause(e); throw _e; return ((Context)atomicNameBinding).lookup(normalizedName.getSuffix(1)); throw new NotContextException(atomicName+" from ["+name+"] is not a context, cannot perform further lookup");
public static void main(String[] args) { File o; try { o = (File) NamingManager.getInitialContext(null).lookup("fs/test"); } catch (NamingException e) { throw new RuntimeException("could not get the test directory", e); } System.out.println(o.getAbsolutePath()); } }
this.parent.bind(name, value, allowOverwrites); } else if ((!allowOverwrites) && this.bindings.get(name.get(0)) != null) throw new NamingException(ContainerJNDIManager.JNDI_RESOURCES.getString( "WinstoneContext.AlreadyExists", name.toString())); else { value = NamingManager.getStateToBind(value, new CompositeName() .add(bindName.get(0)), this, this.environment); synchronized (this.contextLock) {
value = NamingManager.getObjectInstance( value, name, this, env ); throw new NamingException( ex.getMessage() ); if( lookup && name.size() > 1 ) return MemoryContext.class.cast( value ).lookupImpl( name.getSuffix( 1 ), resolveLink ); return Context.class.cast( value ).lookup( name.getSuffix( 1 ) ); throw new NotContextException( simple + " is not a subcontext" );
if (parsedName.namespace() == null) { if (!parsedName.remaining().isEmpty()) { final String firstPart = parsedName.remaining().get(0); int index = firstPart.indexOf(':'); if (index != -1) { if (factory != null) { try { return ((Context) factory.getObjectInstance(null, name, this, getEnvironment())).lookup(name); }catch(NamingException e) { throw e; } catch (Exception e) { NamingException n = new NamingException(e.getMessage()); n.initCause(e); throw n; Context ctx = NamingManager.getURLContext(scheme, getEnvironment()); if(ctx!=null){ return ctx.lookup(name); return super.lookup(parsedName.remaining(),dereference); else return namespaceContext.lookup(parsedName.remaining());
/** * Lookup an object in the default initial context * @param context The context to use * @param name the name to lookup * @param clazz the expected type * @return the object * @throws Exception for any error */ public static <T> T lookup(final Context context, final String name, final Class<T> clazz) throws Exception { Object object = context.lookup(name); if (object instanceof Reference) { return (T)NamingManager.getObjectInstance(object, null, null, null); } return clazz.cast(object); }
/** * Creates an Initial Context for beginning name resolution. Special * requirements of this context are supplied using <code>environment</code>. * @param env The possibly null environment specifying information * to be used in the creation of the initial context. * @return A non-null initial context object that implements the Context * interface. * @exception NamingException If cannot create an initial context. */ public Context getInitialContext(Hashtable<?, ?> env) throws NamingException { String provider = (String) env.get(Context.PROVIDER_URL); String protocol = provider.substring(0, provider.indexOf(':')); Context ctx = NamingManager.getURLContext(protocol, env); return (Context) ctx.lookup(provider); } }
public final static Object resolveObject(Object obj) throws NamingException { if (! (obj instanceof Reference)) return obj; try { return javax.naming.spi.NamingManager.getObjectInstance( obj, null, null, null); } catch (Exception e) { if (logger.isLoggable(BasicLevel.DEBUG)) logger.log(BasicLevel.DEBUG, "", e); NamingException ne = new NamingException(e.getMessage()); ne.setRootCause(e); throw ne; } } }
@Override public void rebind(Name name, Object obj) throws NamingException { if (name.isEmpty()) { throw new InvalidNameException("Name ["+name+"] is empty "); } Name normalizedName = normalizeName(name); String atomicName = normalizedName.get(0); // first component Object atomicNameBinding = bindings.get(atomicName); if (normalizedName.size() == 1) { if (obj instanceof AbstractHierarchicalContext) { ((AbstractHierarchicalContext)obj).parent = this; } bindings.put(atomicName, NamingManager.getStateToBind(obj, new CompositeName().add(atomicName), this, env)); } else { if (atomicNameBinding instanceof Context) { ((Context)atomicNameBinding).rebind(normalizedName.getSuffix(1), obj); } else { throw new NotContextException(format("%s from [%s] is not a context, cannot perform further binding", atomicName, name)); } } }
@Override public void bind(Name name, Object obj) throws NamingException { if (name.isEmpty()) { throw new InvalidNameException(format("Name [%s] is empty ", name)); } Name normalizedName = normalizeName(name); String atomicName = normalizedName.get(0); // first component Object atomicNameBinding = bindings.get(atomicName); if (normalizedName.size() == 1) { if (atomicNameBinding != null) { throw new NameAlreadyBoundException(format("Name [%s] in [%s] is already binded to [%s]", atomicName, normalizedName, atomicNameBinding)); } bindings.put(atomicName, NamingManager.getStateToBind(obj, new CompositeName().add(atomicName), this, env)); } else { if (atomicNameBinding instanceof Context) { ((Context)atomicNameBinding).bind(normalizedName.getSuffix(1), obj); } else { throw new NotContextException(format("%s from [%s] is not a context, cannot perform further binding", atomicName, name)); } } }
public static Object resolve(Object value, String stringName, Name parsedName, Context nameCtx) throws NamingException { if (!(value instanceof Reference)) { return value; } Reference reference = (Reference) value; // for SimpleReference we can just call the getContext method if (reference instanceof SimpleReference) { try { return ((SimpleReference) reference).getContent(); } catch (NamingException e) { throw e; } catch (Exception e) { throw (NamingException) new NamingException("Could not look up : " + stringName == null? parsedName.toString(): stringName).initCause(e); } } // for normal References we have to do it the slow way try { if (parsedName == null) { parsedName = NAME_PARSER.parse(stringName); } return NamingManager.getObjectInstance(reference, parsedName, nameCtx, nameCtx.getEnvironment()); } catch (NamingException e) { throw e; } catch (Exception e) { throw (NamingException) new NamingException("Could not look up : " + stringName == null? parsedName.toString(): stringName).initCause(e); } }
public Object lookup(String name) throws NamingException { if (TraceCarol.isDebugJndiCarol()) TraceCarol.debugJndiCarol("lookup(" + name + ")"); if (name.equals("")) { // Asking to look up this context itself. Create and return // a new instance with its own independent environment. return (new FlatCtx(myEnv)); } try { Object obj = reg.lookup(name); if (obj instanceof RemoteReference) { return NamingManager.getObjectInstance( ((RemoteReference) obj).getReference(), null, this, this.myEnv); } if (TraceCarol.isDebugJndiCarol()) TraceCarol.debugJndiCarol("lookup(" + name + ") returned"); return obj; } catch (java.rmi.NotBoundException e) { throw new NameNotFoundException(e.toString()); } catch (Exception e) { throw new NamingException(e.toString()); } }
NamingException ne = new NameNotFoundException(); ne.setRemainingName(org.wildfly.iiop.openjdk.naming.jndi.CNNameParser.cosNameToName(rest)); ne.setRootCause(e); throw ne; java.lang.Object resolvedObj2; try { resolvedObj2 = NamingManager.getObjectInstance(resolvedObj, cname, ctx, ctx._env); } catch (NamingException ge) { } catch (Exception ge) { NamingException ne = IIOPLogger.ROOT_LOGGER.errorGeneratingObjectViaFactory(); ne.setRootCause(ge); throw ne; } else { cname.add(""); cpe.setAltName(cname);