Refine search
/** * Create a Reference instance from a JNDIStorable object * * @param instanceClassName * The name of the class that is being created. * @param po * The properties object to use when configuring the new instance. * * @return Reference * * @throws NamingException if an error occurs while creating the new instance. */ public static Reference createReference(String instanceClassName, JNDIStorable po) throws NamingException { Reference result = new Reference(instanceClassName, JNDIReferenceFactory.class.getName(), null); try { Properties props = po.getProperties(); for (Enumeration iter = props.propertyNames(); iter.hasMoreElements();) { String key = (String)iter.nextElement(); result.add(new StringRefAddr(key, props.getProperty(key))); } } catch (Exception e) { throw new NamingException(e.getMessage()); } return result; }
public static Properties getProperties(Reference reference) { Properties properties = new Properties(); for (Enumeration iter = reference.getAll(); iter.hasMoreElements();) { StringRefAddr addr = (StringRefAddr)iter.nextElement(); properties.put(addr.getType(), (addr.getContent() == null) ? "" : addr.getContent()); } return properties; }
/** * Uses StringRefAddr's to store the information * @param obj The object * @param name Name * @param ctx Context * @param env properties * @return The instance * @throws Exception */ public Object getObjectInstance(Object obj, Name name, Context ctx, Hashtable env) throws Exception { PersistenceManagerFactoryImpl rc = null; if (obj instanceof Reference) { Reference ref = (Reference) obj; if (ref.getClassName().equals(ClassNameConstants.PersistenceManagerFactoryImpl)) { Properties p = new Properties(); for (Enumeration e = ref.getAll(); e.hasMoreElements();) { StringRefAddr sra = (StringRefAddr) e.nextElement(); p.setProperty(sra.getType(), (String) sra.getContent()); } rc = new PersistenceManagerFactoryImpl(); rc.setOptions(p); } } return rc; }
if (object instanceof Reference) { Reference reference = (Reference) object; Class<?> theClass = loadClass(this, reference.getClassName()); if (JNDIStorable.class.isAssignableFrom(theClass)) { JNDIStorable store = (JNDIStorable) theClass.newInstance(); Map<String, String> properties = new HashMap<String, String>(); for (Enumeration<RefAddr> iter = reference.getAll(); iter.hasMoreElements();) { StringRefAddr addr = (StringRefAddr) iter.nextElement(); properties.put(addr.getType(), (addr.getContent() == null) ? "" : addr.getContent().toString());
private void populatePropertiesFromReference(Reference reference) { RefAddr property = reference.get(ProxoolConstants.ALIAS_PROPERTY); if (property != null) { setAlias(property.getContent().toString()); property = reference.get(ProxoolConstants.DRIVER_CLASS_PROPERTY); if (property != null) { setDriver(property.getContent().toString()); property = reference.get(ProxoolConstants.FATAL_SQL_EXCEPTION_WRAPPER_CLASS_PROPERTY); if (property != null) { setFatalSqlExceptionWrapperClass(property.getContent().toString()); Enumeration e = reference.getAll(); while (e.hasMoreElements()) { StringRefAddr stringRefAddr = (StringRefAddr) e.nextElement(); String name = stringRefAddr.getType(); String content = stringRefAddr.getContent().toString(); if (name.indexOf(ProxoolConstants.PROPERTY_PREFIX) != 0) { delegateProperties.put(name, content);
/** * @see Referenceable#getReference() */ public Reference getReference() throws NamingException { if (config instanceof Referenceable) { Referenceable confref = (Referenceable)config; if (reference == null) { reference = new Reference(RepositoryImpl.class.getName(), RepositoryImpl.Factory.class.getName(), null); // carry over all addresses from referenceable config for (Enumeration<RefAddr> en = confref.getReference().getAll(); en.hasMoreElements(); ) { reference.add(en.nextElement()); } // also add the information required by factory class reference.add(new StringRefAddr(Factory.RCF, confref.getReference().getFactoryClassName())); reference.add(new StringRefAddr(Factory.RCC, config.getClass().getName())); } return reference; } else { throw new javax.naming.OperationNotSupportedException("Contained RepositoryConfig needs to implement javax.naming.Referenceable"); } }
InitialContext iniCtx = new InitialContext(); Context ctx = iniCtx; Context java = (Context) iniCtx.lookup("java:"); System.out.println("java: "+java); Context test = ctx.createSubcontext("test"); System.out.println("test created:"+test); ctx.bind("/test/server", hello1); System.out.println("test/server bound"); test.bind("server2", hello2); System.out.println("test/server2 bound"); iniCtx.rebind("test/server2", hello2); System.out.println("test/server2 rebound"); StringRefAddr addr = new StringRefAddr("URL", "file:/tmp"); Reference fsRef = new Reference("javax.naming.Context", addr); ctx.bind("external", fsRef); Context tmpfs = (Context) ctx.lookup("external"); Properties env = new Properties(); env.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory"); env.setProperty(Context.URL_PKG_PREFIXES, "org.jnp.interfaces"); env.setProperty(Context.PROVIDER_URL, "jnp://localhost/test"); System.out.println("+++ Test jnp URL passed as PROVIDER_URL");
/** * Add additional parameters to the reference. */ private void addAdditionalParameters(NamingResources resources, Reference ref, String name) { if (resources == null) { resources = namingResources; } ResourceParams resourceParameters = resources.findResourceParams(name); if (debug >= 2) log(" Resource parameters for " + name + " = " + resourceParameters); if (resourceParameters == null) return; Hashtable<String, String> params = resourceParameters.getParameters(); Enumeration<String> enumeration = params.keys(); while (enumeration.hasMoreElements()) { String paramName = enumeration.nextElement(); String paramValue = params.get(paramName); StringRefAddr refAddr = new StringRefAddr(paramName, paramValue); ref.add(refAddr); } }
public void setProperties (Properties properties) { Iterator entries = properties.entrySet().iterator(); while (entries.hasNext()) { Map.Entry e = (Map.Entry)entries.next(); StringRefAddr sref = (StringRefAddr)get((String)e.getKey()); if (sref != null) throw new RuntimeException ("property "+e.getKey()+" already set on Session reference, can't be changed"); add(new StringRefAddr((String)e.getKey(), (String)e.getValue())); } }
@Test public void getObjectInstance() throws Exception { Reference resource = new Reference("CassandraClientFactory"); resource.add(new StringRefAddr("hosts", cassandraUrl)); resource.add(new StringRefAddr("clusterName", clusterName)); resource.add(new StringRefAddr("keyspace", "Keyspace1")); resource.add(new StringRefAddr("autoDiscoverHosts", "true")); Name jndiName = mock(Name.class); Context context = new InitialContext(); Hashtable<String, String> environment = new Hashtable<String, String>(); Keyspace keyspace = (Keyspace) factory.getObjectInstance(resource, jndiName, context, environment); assertNotNull(keyspace); assertEquals("Keyspace1",keyspace.getKeyspaceName()); } }
InitialContext iniCtx = new InitialContext(); Hashtable<?,?> env = iniCtx.getEnvironment(); log.debug("InitialContext Environment: "); Object providerURL = null; RefAddr refAddr = new StringRefAddr("nns", "ENC"); Reference envRef = new Reference("javax.namingMain.Context", refAddr, ENCFactory.class.getName(), null); Context ctx = (Context)iniCtx.lookup("java:"); ctx.rebind("comp", envRef); ctx.close(); iniCtx.close();
log.debug("Resource Adaptor Object: " + object); String GLOBAL_ENV = "java:"; Context ctx = new InitialContext(); ctx = (Context) ctx.lookup(GLOBAL_ENV + prefix); ctx=ctx.createSubcontext(this.name); } catch (NameAlreadyBoundException e) { log.warn("Context, " + this.name + " is already bounded"); log.warn(e); ctx = (Context) ctx.lookup(this.name); object); StringRefAddr addr = new StringRefAddr("nns", GLOBAL_ENV + prefix + "/" + factoryProvider); log.debug("=============== object:"+object+" addr:"+addr+" ==================="); Reference ref = new Reference(object.getClass().getName(), addr, NonSerializableFactory.class.getName(), null); ctx.rebind(factoryProvider, ref);
HashMap<String,String> dsNames = new HashMap<String,String>(); System.setProperty(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.fscontext.RefFSContextFactory"); System.setProperty(Context.PROVIDER_URL, "file:/home/user/tmp"); InitialContext ic = new InitialContext(); dsNames.put("yourDataSourceName", "jdbc/your_jndi_name"); // Construct BasicDataSource reference Reference ref = new Reference("javax.sql.DataSource", "org.apache.commons.dbcp.BasicDataSourceFactory", null); ref.add(new StringRefAddr("driverClassName", "theDriver")); ref.add(new StringRefAddr("url","theDBURL")); ref.add(new StringRefAddr("username", "obvious")); ref.add(new StringRefAddr("password", "obvious")); ref.add(new StringRefAddr("maxActive", "10")); ref.add(new StringRefAddr("maxIdle", "3")); ref.add(new StringRefAddr("initialSize", "3")); ref.add(new StringRefAddr("maxWait", "5")); ic.rebind("jdbc/your_jndi_name", ref); //And to get a reference to your data source anywhere else in your program: InitialContext ic2 = new InitialContext(); DataSource myDS = (DataSource) ic2.lookup(dsNames.get(dsName));
/** * Register a internal slee component with jndi. * */ public static void registerWithJndi(String prefix, String name, Object object) { String fullName = JVM_ENV + prefix + "/" + name; try { Context ctx = new InitialContext(); try { Util.createSubcontext(ctx, fullName); } catch (NamingException e) { logger.warn("Context, " + fullName + " might have been bound."); logger.warn(e); } ctx = (Context) ctx.lookup(JVM_ENV + prefix); // ctx.createSubcontext(name); // ctx = (Context) ctx.lookup(name); // Util.rebind(JVM_ENV + prefix + "/" + name, object); NonSerializableFactory.rebind(fullName, object); StringRefAddr addr = new StringRefAddr("nns", fullName); Reference ref = new Reference(object.getClass().getName(), addr, NonSerializableFactory.class.getName(), null); Util.rebind(ctx, name, ref); logger.debug("registered with jndi " + fullName); } catch (Exception ex) { logger.warn("registerWithJndi failed for " + fullName, ex); } }
System.setProperty(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.fscontext.RefFSContextFactory"); System.setProperty(Context.PROVIDER_URL, "file:///F:/JNDI/"); Reference ref = new Reference("javax.sql.DataSource","org.apache.commons.dbcp.BasicDataSourceFactory", null); ref.add(new StringRefAddr("driverClassName","com.ibm.db2.jcc.DB2Driver"); ref.add(new StringRefAddr("url","jdbc:db2://myhost.example.com:port/dbname"); ref.add(new StringRefAddr("password", "SomePassord"); ref.add(new StringRefAddr("username", "myUser"); ref.add(new StringRefAddr("maxActive","100")); ref.add(new StringRefAddr("maxWait", "10000")); ref.add(new StringRefAddr("maxIdle", "10")); ref.add(new StringRefAddr("minIdle", "5")); ref.add(new StringRefAddr("testOnBorrow", "true")); ref.add(new StringRefAddr("testOnReturn", "false")); ref.add(new StringRefAddr("testWhileIdle","true")); ref.add(new StringRefAddr("validationQuery","SELECT 1")); ref.add(new StringRefAddr("timeBetweenEvictionRunsMillis",Integer.toString(10*60*1000))); ref.add(new StringRefAddr("minEvictableIdleTimeMillis",Integer.toString(2*60*1000))); ref.add(new StringRefAddr("numTestsPerEvictionRun","10")); ref.add(new StringRefAddr("removeAbandoned", "true")); ref.add(new StringRefAddr("removeAbandonedTimeout", Integer.toString(30*60))); ref.add(new StringRefAddr("logAbandoned", "true")); Context ctx = new InitialContext(); ctx.rebind("jdbc/MyDataSource",ref) ctx.close();
private void bind() throws NamingException { Context ctx = new InitialContext(); // Ah ! We aren't serializable, so we use a helper class NonSerializableFactory.bind(JNDI_NAME, this); // The helper class NonSerializableFactory uses address type nns, we go on to // use the helper class to bind ourselves in JNDI StringRefAddr addr = new StringRefAddr("nns", JNDI_NAME); Reference ref = new Reference(EntityLockMonitor.class.getName(), addr, NonSerializableFactory.class.getName(), null); ctx.bind(JNDI_NAME, ref); }
/** * register this bean to JNDI (rebind) We register actually a Reference * object. */ protected void register() throws NamingException { if (TraceEjb.isDebugIc()) { TraceEjb.interp.log(BasicLevel.DEBUG, ""); } String name = dd.getJndiLocalName(); // Keep it in the static list for later retrieving. homeList.put(name, this); Reference ref = new Reference("org.objectweb.jonas_ejb.container.JLocalHome", "org.objectweb.jonas_ejb.container.HomeFactory", null); ref.add(new StringRefAddr("bean.name", name)); bf.getInitialContext().rebind(name, ref); }
EtmMonitor monitor = EtmMonitorFactory.createEtmMonitor(monitorConfig); ctx = new InitialContext(); ctx.bind(jndiName, etmMonitorReference); ctx.close(); } catch (NamingException e) { reference = new Reference(EtmMonitorConnector.class.getName(), new StringRefAddr("configfile", resource.toString()));
public void start() throws Exception { initialContext(); ClassLoader topLoader = Thread.currentThread().getContextClassLoader(); ENCFactory.setTopClassLoader(topLoader); RefAddr refAddr = new StringRefAddr("nns", "ENC"); Reference envRef = new Reference("javax.naming.Context", refAddr, ENCFactory.class.getName(), null); Context ctx = (Context)iniCtx.lookup("java:"); ctx.rebind("comp", envRef); } }
/** * Set the specified EJBs in the naming context. */ public void addEjb(ContextEjb ejb) { // Create a reference to the EJB. Reference ref = new EjbRef (ejb.getType(), ejb.getHome(), ejb.getRemote(), ejb.getLink()); // Adding the additional parameters, if any Iterator params = ejb.listProperties(); while (params.hasNext()) { String paramName = (String) params.next(); String paramValue = (String) ejb.getProperty(paramName); StringRefAddr refAddr = new StringRefAddr(paramName, paramValue); ref.add(refAddr); } try { createSubcontexts(envCtx, ejb.getName()); envCtx.bind(ejb.getName(), ref); } catch (NamingException e) { logger.error(sm.getString("naming.bindFailed", e)); } }