@Override public Object getObjectInstance(final Object obj, final Name name, final Context nameCtx, final Hashtable<?, ?> environment) throws Exception { return factory.getObjectInstance(url, name, nameCtx, environment); } }
/** * 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; }
final Object result; if (objectFactory instanceof DirObjectFactory) { result = DirObjectFactory.class.cast(objectFactory).getObjectInstance(ref, name, nameCtx, environment, attributes); } else { result = objectFactory.getObjectInstance(ref, name, nameCtx, environment);
obj = NamingManager.getObjectInstance(obj, cname, _ctx, _env); } catch (NamingException e) { throw e;
result = namingStore.lookup(absoluteName,dereference); } catch(CannotProceedException cpe) { final Context continuationContext = NamingManager.getContinuationContext(cpe); if (continuationContext instanceof NamingContext) { result = ((NamingContext)continuationContext).lookup(cpe.getRemainingName(), dereference); final Object resolvedObject = resolveResult.getResolvedObj(); throw notAContextException(absoluteName.getPrefix(absoluteName.size() - resolveResult.getRemainingName().size())); return ((NamingContext)namingContext).lookup(resolveResult.getRemainingName(), dereference); } else { return namingContext.lookup(resolveResult.getRemainingName());
protected Object foundReferenceInsteadOfContext(final BindingNode bindingNode) throws NamingException { final Name remainingName = targetName.getSuffix(bindingNode.fullName.size()); final Object boundObject = bindingNode.binding.getObject(); checkReferenceForContinuation(remainingName, boundObject); return new ResolveResult(boundObject, remainingName); } }
/** {@inheritDoc} */ @Override public Context getInitialContext(Hashtable<?, ?> environment) throws NamingException { // NOPMD try { final Class<?> clazz = Class.forName(initialContextFactory); final InitialContextFactory icf = (InitialContextFactory) clazz.newInstance(); final Context context = icf.getInitialContext(environment); final JdbcWrapper jdbcWrapper = JdbcWrapper.SINGLETON; return jdbcWrapper.createContextProxy(context); } catch (final ClassNotFoundException e) { throw createNamingException(e); } catch (final InstantiationException e) { throw createNamingException(e); } catch (final IllegalAccessException e) { throw createNamingException(e); } }
private static javax.naming.Context getContinuationContext(CannotProceedException cpe) throws NamingException { try { return NamingManager.getContinuationContext(cpe); } catch (CannotProceedException e) { java.lang.Object resObj = e.getResolvedObj(); if (resObj instanceof Reference) { Reference ref = (Reference) resObj; RefAddr addr = ref.get("nns"); if (addr.getContent() instanceof javax.naming.Context) { NamingException ne = IIOPLogger.ROOT_LOGGER.noReferenceFound(); ne.setRootCause(cpe.getRootCause()); throw ne; } } throw e; } }
@Override public ManagedReference getReference() { try { final Object value = objectFactoryClassInstance.getObjectInstance(name, null, null, environment); return new ImmediateManagedReference(value); } catch (Exception e) { throw new RuntimeException(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; }
/** * This method is used by the iiop and iiopname URL Context factories. */ public static ResolveResult createUsingURL(String url, Hashtable env) throws NamingException { CNCtx ctx = new CNCtx(); if (env != null) { env = (Hashtable) env.clone(); } ctx._env = env; String rest = ctx.initUsingUrl(env != null ? (org.omg.CORBA.ORB) env.get("java.naming.corba.orb") : null, url, env); // rest is the INS name // Return the parsed form to prevent subsequent lookup // from parsing the string as a composite name // The caller should be aware that a toString() of the name // will yield its INS syntax, rather than a composite syntax return new ResolveResult(ctx, parser.parse(rest)); }
@Override protected Context getDefaultInitCtx() throws NamingException { if (!gotDefault) { // if there is an initial context factory prop in the env use it to create the default ctx final String factoryClassName = myProps != null ? (String) myProps.get(Context.INITIAL_CONTEXT_FACTORY) : null; if(factoryClassName == null || InitialContextFactory.class.getName().equals(factoryClassName)) { defaultInitCtx = new DefaultInitialContext(myProps); } else { final ClassLoader classLoader = WildFlySecurityManager.getCurrentContextClassLoaderPrivileged(); try { final Class<?> factoryClass = Class.forName(factoryClassName, true, classLoader); defaultInitCtx = ((javax.naming.spi.InitialContextFactory)factoryClass.newInstance()).getInitialContext(myProps); } catch (NamingException e) { throw e; } catch (Exception e) { throw NamingLogger.ROOT_LOGGER.failedToInstantiate(e, "InitialContextFactory", factoryClassName, classLoader); } } gotDefault = true; } return defaultInitCtx; }
/** {@inheritDoc} */ public NamingEnumeration<NameClassPair> list(final Name name) throws NamingException { check(name, JndiPermission.ACTION_LIST); try { return namingEnumeration(namingStore.list(getAbsoluteName(name))); } catch(CannotProceedException cpe) { final Context continuationContext = NamingManager.getContinuationContext(cpe); return continuationContext.list(cpe.getRemainingName()); } catch (RequireResolveException r) { final Object o = lookup(r.getResolve()); if (o instanceof Context) { return ((Context)o).list(name.getSuffix(r.getResolve().size())); } throw notAContextException(r.getResolve()); } }
@Override public ManagedReference getReference() { try { final Object value = objectFactoryClassInstance.getObjectInstance(name, null, null, environment); return new ImmediateManagedReference(value); } catch (Exception e) { throw new RuntimeException(e); } }
/** * Initialize the naming components required by {@link javax.naming.spi.NamingManager}. */ public static void initializeNamingManager() { // Setup naming environment final String property = WildFlySecurityManager.getPropertyPrivileged(Context.URL_PKG_PREFIXES, null); if(property == null || property.isEmpty()) { WildFlySecurityManager.setPropertyPrivileged(Context.URL_PKG_PREFIXES, PACKAGE_PREFIXES); } else if(!Arrays.asList(property.split(":")).contains(PACKAGE_PREFIXES)) { WildFlySecurityManager.setPropertyPrivileged(Context.URL_PKG_PREFIXES, PACKAGE_PREFIXES + ":" + property); } try { //If we are reusing the JVM. e.g. in tests we should not set this again if (!NamingManager.hasInitialContextFactoryBuilder()) NamingManager.setInitialContextFactoryBuilder(new InitialContextFactoryBuilder()); } catch (NamingException e) { ROOT_LOGGER.failedToSet(e, "InitialContextFactoryBuilder"); } }
return new ResolveResult(obj, suffix(lower, lookupName));
/** {@inheritDoc} */ public NamingEnumeration<Binding> listBindings(final Name name) throws NamingException { check(name, JndiPermission.ACTION_LIST_BINDINGS); try { return namingEnumeration(namingStore.listBindings(getAbsoluteName(name))); } catch(CannotProceedException cpe) { final Context continuationContext = NamingManager.getContinuationContext(cpe); return continuationContext.listBindings(cpe.getRemainingName()); } catch (RequireResolveException r) { final Object o = lookup(r.getResolve()); if (o instanceof Context) { return ((Context)o).listBindings(name.getSuffix(r.getResolve().size())); } throw notAContextException(r.getResolve()); } }
private Object getObjectInstance(final Object object, final Name name, final Hashtable<?, ?> environment) throws NamingException { try { final ObjectFactoryBuilder factoryBuilder = ObjectFactoryBuilder.INSTANCE; final ObjectFactory objectFactory = factoryBuilder.createObjectFactory(object, environment); return objectFactory == null ? null : objectFactory.getObjectInstance(object, name, this, environment); } catch(NamingException e) { throw e; } catch(Throwable t) { throw NamingLogger.ROOT_LOGGER.cannotDeferenceObject(t); } }
final Class<?> factoryClass = classLoader.loadClass(className); final ObjectFactory objectFactory = ObjectFactory.class.cast(factoryClass.newInstance()); final Object result = objectFactory.getObjectInstance(ref, name, nameCtx, environment); if (result != null) { return result;
@Override protected Context getURLOrDefaultInitCtx(String name) throws NamingException { String scheme = getURLScheme(name); if (scheme != null && !scheme.equals("java")) { ObjectFactory factory = urlContextFactories.get(scheme); if (factory != null) { try { return (Context) factory.getObjectInstance(null, null, null, myProps); }catch(NamingException e) { throw e; } catch (Exception e) { NamingException n = new NamingException(e.getMessage()); n.initCause(e); throw n; } } else { Context ctx = delegate.getInitialContext(myProps); if(ctx!=null) { return ctx; } } } return getDefaultInitCtx(); }