@Override synchronized public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable<?, ?> environment) throws Exception { // We only know how to deal with <code>javax.naming.Reference</code> that specify a class name of "javax.sql.DataSource" if (obj instanceof Reference && "javax.sql.DataSource".equals(((Reference) obj).getClassName())) { Reference ref = (Reference) obj; Set<String> hikariPropSet = PropertyElf.getPropertyNames(HikariConfig.class); Properties properties = new Properties(); Enumeration<RefAddr> enumeration = ref.getAll(); while (enumeration.hasMoreElements()) { RefAddr element = enumeration.nextElement(); String type = element.getType(); if (type.startsWith("dataSource.") || hikariPropSet.contains(type)) { properties.setProperty(type, element.getContent().toString()); } } return createDataSource(properties, nameCtx); } return null; }
static ObjectFactory lookForURLs(Reference ref, Hashtable environment) throws NamingException { for (int i = 0; i < ref.size(); i++) { RefAddr addr = ref.get(i); if (addr instanceof StringRefAddr && addr.getType().equalsIgnoreCase("URL")) { String url = (String) addr.getContent(); ObjectFactory answer = processURL(url, environment); if (answer != null) { return answer; } } } return null; }
Enumeration<RefAddr> props = ((Reference) obj).getAll(); while (props.hasMoreElements()) { RefAddr addr = props.nextElement(); if (addr != null) { if (CONNECTION_STRING.equals(addr.getType())) { if (addr.getContent() instanceof String) { connectionString = (String) addr.getContent(); break;
protected Properties toProperties(Enumeration<RefAddr> attributes) { Properties props = new Properties(); while (attributes.hasMoreElements()) { RefAddr attribute = attributes.nextElement(); if ("factory".equals(attribute.getType())) { continue; } String key = attribute.getType(); String value = Framework.expandVars((String) attribute.getContent()); props.put(key, value); } return props; } }
/** * Create a new EJB instance using OpenEJB. * * @param obj The reference object describing the DataSource */ @Override public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable<?,?> environment) throws Exception { Object beanObj = null; if (obj instanceof EjbRef) { Reference ref = (Reference) obj; String factory = DEFAULT_OPENEJB_FACTORY; RefAddr factoryRefAddr = ref.get("openejb.factory"); if (factoryRefAddr != null) { // Retrieving the OpenEJB factory factory = factoryRefAddr.getContent().toString(); } Properties env = new Properties(); env.put(Context.INITIAL_CONTEXT_FACTORY, factory); RefAddr linkRefAddr = ref.get("openejb.link"); if (linkRefAddr != null) { String ejbLink = linkRefAddr.getContent().toString(); beanObj = (new InitialContext(env)).lookup(ejbLink); } } return beanObj; }
final Properties env = new Properties(); String bean = null; final Enumeration addresses = ref.getAll(); while (addresses.hasMoreElements()) { refAddr = (RefAddr) addresses.nextElement(); addrType = refAddr.getType(); if (addrType.startsWith(OPENEJB_PREFIX)) { final String value = refAddr.getContent().toString(); if (addrType.equals(OPENEJB_EJB_LINK)) { bean = value; env.put(key, value); beanObj = (new InitialContext(env)).lookup(bean);
@Override public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable<?, ?> environment) throws Exception { // We only know how to deal with <code>javax.naming.Reference</code>s // that specify a class name of "javax.sql.DataSource" if ((obj == null) || !(obj instanceof Reference)) { return null; } Reference ref = (Reference) obj; if ((!"javax.sql.DataSource".equals(ref.getClassName())) // && (!"com.alibaba.druid.pool.DruidDataSource".equals(ref.getClassName())) // ) { return null; } Properties properties = new Properties(); for (int i = 0; i < ALL_PROPERTIES.length; i++) { String propertyName = ALL_PROPERTIES[i]; RefAddr ra = ref.get(propertyName); if (ra != null) { String propertyValue = ra.getContent().toString(); properties.setProperty(propertyName, propertyValue); } } return createDataSourceInternal(properties); }
/** * @inheritDoc */ public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable<?, ?> environment) throws Exception { if ((obj == null) || !(obj instanceof Reference)) { return null; } Reference ref = (Reference)obj; if (!"javax.sql.DataSource".equals(ref.getClassName())) { return null; } Properties properties = new Properties(); for (int i = 0; i < ref.size(); i++) { String propertyName = ref.get(i).getType(); RefAddr ra = ref.get(propertyName); if (ra != null) { String propertyValue = ra.getContent().toString(); properties.setProperty(propertyName, propertyValue); } } return createDataSource(properties); }
public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable<?, ?> environment) throws Exception { Reference ref = (Reference) obj; if(_logger.isLoggable(Level.FINE)) { _logger.log(Level.FINE,"MailNamingObjectFactory: " + ref + " Name:" + name); } MailConfiguration config = (MailConfiguration) ref.get(0).getContent(); // Note: javax.mail.Session is not serializable, // but we need to get a new instance on every lookup. Properties props = config.getMailProperties(); javax.mail.Session s = javax.mail.Session.getInstance(props, new MailSessionAuthenticator(props)); if("smtps".equals(props.getProperty("mail.transport.protocol"))) { s.setProtocolForAddress("rfc822", "smtps"); } s.setDebugOut(new PrintStream(new MailLogOutputStream())); s.setDebug(true); return s; } }
@Override protected Object getLinked(Reference ref) throws NamingException { // If ejb-link has been specified, resolving the link using JNDI RefAddr linkRefAddr = ref.get(EjbRef.LINK); if (linkRefAddr != null) { // Retrieving the EJB link String ejbLink = linkRefAddr.getContent().toString(); Object beanObj = (new InitialContext()).lookup(ejbLink); return beanObj; } return null; } }
@Override public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable<?, ?> environment) throws Exception { Reference resource = (Reference) obj; if (resource.get("STRING") != null) { String res = (String) resource.get("STRING").getContent(); return res; } else { throw new NamingException("Resource does not have a valid STRING parameter"); } } }
public void stop() { if (jndiName == null) { EtmManager.getEtmMonitor().stop(); } else { EtmMonitor monitor = EtmMonitorRepository.getMonitor((String) reference.get("configfile").getContent()); monitor.stop(); InitialContext ctx = null; try { ctx = new InitialContext(); ctx.unbind(jndiName); } catch (NameNotFoundException e) { // ignore } catch (Exception e) { LOG.warn("Unable to deregister JETM monitor " + jndiName + " from JNDI tree", e); } finally { if (ctx != null) { try { ctx.close(); } catch (NamingException e) { // ignored } } } } }
protected String getProperty(Reference ref, String s) { RefAddr addr = ref.get(s); if (addr == null) { return null; } return (String) addr.getContent(); }
if (ref.getClassName().equals(JdbcDataSource.class.getName())) { JdbcDataSource dataSource = new JdbcDataSource(); dataSource.setURL((String) ref.get("url").getContent()); dataSource.setUser((String) ref.get("user").getContent()); dataSource.setPassword((String) ref.get("password").getContent()); dataSource.setDescription((String) ref.get("description").getContent()); String s = (String) ref.get("loginTimeout").getContent(); dataSource.setLoginTimeout(Integer.parseInt(s)); return dataSource;
/** * Load a given object for the given property name. * @param reference the given reference * @param propertyName the given property * @return the loaded object * @throws NamingException if object is not read. * @param <T> the type of the object to load */ @SuppressWarnings("unchecked") public <T> T getObject(final Reference reference, final String propertyName) throws NamingException { RefAddr refAddr = reference.get(propertyName); T obj = null; if (refAddr != null) { try { obj = (T) Serialization.loadObject((byte[]) refAddr.getContent()); } catch (IOException e) { NamingException ne = new NamingException("Cannot load mail session properties object"); ne.initCause(e); throw ne; } catch (ClassNotFoundException e) { NamingException ne = new NamingException("Cannot load mail session properties object"); ne.initCause(e); throw ne; } } return obj; }
while (props.hasMoreElements()) { RefAddr addr = (RefAddr) props.nextElement(); String propName = addr.getType(); String propValue = (String) addr.getContent(); if (propName.equals("db")) { db = propValue; port = Integer.parseInt(propValue); } catch (NumberFormatException e) { throw new NamingException("Invalid port value " + propValue); throws NamingException { if (property == null || property.trim().equals("")) { throw new NamingException(errorMessage); throws NamingException { if (property == null) { throw new NamingException(errorMessage);
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; } }
static private 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 = new NameNotFoundException( "No object reference bound for specified name"); ne.setRootCause(cpe.getRootCause()); ne.setRemainingName(cpe.getRemainingName()); throw ne; } } throw e; } }
public Object getObjectInstance(Object refObject, Name name, Context context, Hashtable hashtable) throws Exception { // we only handle references if (!(refObject instanceof Reference)) { return null; } Reference reference = (Reference) refObject; /* Removed because JNDI implementations can not be trusted to implement reference.getFactoryClassName() correctly. // check if this is relevant for us if (!ProxoolDataSource.class.getName().equals(reference.getFactoryClassName())) { return null; } */ // check if we've allready parsed the properties. if (!ConnectionPoolManager.getInstance().isPoolExists(reference.get(ProxoolConstants.ALIAS_PROPERTY).toString())) { populatePropertiesFromReference(reference); } return this; }
public Object getObjectInstance(Object object, Name name, Context context, Hashtable<?, ?> table) throws Exception { Reference ref = (Reference) object; Enumeration<RefAddr> addrs = ref.getAll(); Properties props = new Properties(); while (addrs.hasMoreElements()) { RefAddr addr = addrs.nextElement(); if (addr.getType().equals("driverClassName")){ Class.forName((String) addr.getContent()); } else { props.put(addr.getType(), addr.getContent()); } } BoneCPConfig config = new BoneCPConfig(props); return new BoneCPDataSource(config); }