List of usage examples for javax.naming Context bind
public void bind(String name, Object obj) throws NamingException;
From source file:com.egt.core.util.Utils.java
public static void bind2InitialContext(String name, Object obj) { Context c; try {//from w ww . j av a 2 s . co m c = new InitialContext(); Bitacora.trace(c.getClass(), "bind", name, obj); c.bind(name, obj); } catch (NamingException ex) { Bitacora.logFatal(ThrowableUtils.getString(ex)); } }
From source file:org.apache.camel.component.cxf.jaxrs.CxfRsConsumerWithBeanTest.java
@Override protected Context createJndiContext() throws Exception { Context context = super.createJndiContext(); context.bind("service", new ServiceUtil()); return context; }
From source file:com.iterranux.droolsjbpmAtomikosIntegration.TransactionManagerJNDIRegistrator.java
@PostConstruct public void init() { log.debug("Registering TX to JNDI."); try {// w w w .ja va2 s .c o m SimpleNamingContextBuilder.emptyActivatedContextBuilder(); Context context = new InitialContext(); context.bind(userTransactionLookup, userTransaction); context.bind(transactionManagerLookup, transactionManager); } catch (NamingException e) { log.error("JNDI Registration of the Transasction Manager failed.", e); } }
From source file:io.github.arven.flare.ejb.FlareStatelessContainer.java
public FlareStatelessContainer(String id, Context ctx) throws NamingException { this.stateless = new MultiValueMap(); this.ctx = ctx; this.id = id; ctx.bind("DefaultStatelessContainer", this); LoggerFactory.getLogger(FlareStatelessContainer.class).info("Flare created Container(id = {})", id); }
From source file:de.zib.gndms.infra.system.GNDMSystem.java
/** * Retrieves a GNDMSSystem using context.lookup(name). * * A lightweight factory facade is either atomically retrieved from context or bound under name * if name is unbound in context. The factory acts as an intermediary and ensures that at most * one DbSetupFacade ever gets instantiated and initialized. * * This instance is returned by this call from the factory facade. * * @param sharedContext// w w w . ja v a2 s . c o m * @param facadeName * @return GNDMSSystem singleton * @throws NamingException */ @NotNull public static GNDMSystem lookupSystem(@NotNull Context sharedContext, @NotNull Name facadeName, @NotNull GridConfig anySharedConfig, boolean debugModeParam) throws NamingException { try { final SysFactory theFactory = new SysFactory(createLogger(), anySharedConfig, debugModeParam); sharedContext.bind(facadeName, theFactory); return theFactory.getInstance(); } catch (NameAlreadyBoundException ne) { return ((SysFactory) sharedContext.lookup(facadeName)).getInstance(); } }
From source file:de.zib.gndms.infra.system.GNDMSystem.java
/** * @see #lookupSystem(javax.naming.Context, javax.naming.Name, de.zib.gndms.infra.GridConfig, boolean) * * @param sharedContext/* w w w . jav a2 s .co m*/ * @param facadeName * @param anySharedConfig * @param debugModeParam * @return * @throws NamingException */ @SuppressWarnings({ "StaticMethodOnlyUsedInOneClass" }) @NotNull public static GNDMSystem lookupSystem(@NotNull Context sharedContext, @NotNull String facadeName, @NotNull GridConfig anySharedConfig, boolean debugModeParam) throws NamingException { try { final SysFactory theFactory = new SysFactory(createLogger(), anySharedConfig, debugModeParam); sharedContext.bind(facadeName, theFactory); return theFactory.getInstance(); } catch (NameAlreadyBoundException ne) { return ((SysFactory) sharedContext.lookup(facadeName)).getInstance(); } }
From source file:com.ritchey.naming.InitialContextFactory.java
public void createLdapStrings(Properties properties, Context ldap) throws NamingException { Boolean isDatabase = false;/*from ww w . j ava 2 s.co m*/ ldap.bind("url", getValue(isDatabase, "url", "ldap", properties)); ldap.bind("bindUserDistinguishedName", getValue(isDatabase, "bindUserDistinguishedName", "ldap", properties)); ldap.bind("bindUserPassword", getValue(isDatabase, "bindUserPassword", "ldap", properties)); ldap.bind("usersSearchRoot", getValue(isDatabase, "usersSearchRoot", "ldap", properties)); ldap.bind("groupsSearchRoot", getValue(isDatabase, "groupsSearchRoot", "ldap", properties)); ldap.bind("groupsSearchRootSecondary", getValue(isDatabase, "groupsSearchRootSecondary", "ldap", properties)); }
From source file:com.clican.pluto.common.util.JndiUtils.java
/** * Bind the resource manager instance to the JNDI directory. * <p>// w w w. ja v a2 s . c o m * This method will use the full JNDI path provided for the resource * manager, and will create if necessary the individual segments of that * path. * * @param jndiName * The full JNDI path at which the resource manager instance will * be bound in the JNDI directory. JNDI clients can use that path * to obtain the resource manager instance. * @param obj * The object to be bound. * @return <b>true</b> if the resource manager was successfully bound to * JNDI using the provided path; otherwise <b>false</b>. * * @see #unbind(String) */ public static boolean bind(String jndiName, Object obj) { if (log.isDebugEnabled()) { log.debug("Binding object [" + obj + "] in JNDI at path [" + jndiName + "]."); } Context ctx = null; try { // Create a binding that is local to this host only. Hashtable<String, String> ht = new Hashtable<String, String>(); // If a special JNDI initial context factory was specified in the // constructor, then use it. if (jndiInitialContextFactory != null) { ht.put(Context.INITIAL_CONTEXT_FACTORY, jndiInitialContextFactory); } // Turn off binding replication . // ht.put(WLContext.REPLICATE_BINDINGS, "false"); ctx = new InitialContext(ht); String[] arrJndiNames = jndiName.split("/"); String subContext = ""; for (int i = 0; i < arrJndiNames.length - 1; i++) { subContext = subContext + "/" + arrJndiNames[i]; try { ctx.lookup(subContext); } catch (NameNotFoundException e) { ctx.createSubcontext(subContext); } } if (obj instanceof Serializable || jndiInitialContextFactory != null) { ctx.bind(jndiName, obj); } else { NonSerializableFactory.bind(jndiName, obj); } } catch (NamingException ex) { log.error("An error occured while binding [" + jndiName + "] to JNDI:", ex); return false; } finally { if (ctx != null) { try { ctx.close(); } catch (NamingException ne) { log.error("Close context error:", ne); } } } return true; }
From source file:com.ritchey.naming.InitialContextFactory.java
/** * Create a databaseSource for a database by using properties that are * formed with the jndi name (e.g. database.myCoolDatabaseNumber1.url). url, * user, password and driver should all be defined. * * @param database is the jndi name of the database * @param properties represents the values of build.properties * @param jdbc is the context we're going to load * @throws NamingException//w w w . jav a2s. c o m */ public void createDs(String database, Properties properties, Context jdbc) throws NamingException { org.apache.commons.dbcp.BasicDataSource ds = new org.apache.commons.dbcp.BasicDataSource(); try { jdbc.bind(database, ds); } catch (Exception e) { // Quietly suppress NameAlreadyBound Exception } Boolean isDatabase = true; ds.setDriverClassName(getValue(isDatabase, "driver", database, properties)); ds.setUrl(getValue(isDatabase, "url", database, properties)); ds.setUsername(getValue(isDatabase, "user", database, properties)); ds.setPassword(getValue(isDatabase, "password", database, properties)); }
From source file:com.haulmont.multitenancy.TenantsRoutingDatasource.java
@Override public void afterPropertiesSet() throws Exception { dataSources = new ConcurrentHashMap<>(); defaultDataSource = createDataSource(defaultDbAddress); try {/*from w w w.j a va 2 s .c o m*/ Context context = new InitialContext(); String path = AppContext.getProperty(jndiNameAppProperty); if (path == null) throw new IllegalStateException("Property " + jndiNameAppProperty + " is not set"); context.bind(path, this); } catch (NamingException e) { throw new RuntimeException(e); } }