Search in sources :

Example 31 with StringRefAddr

use of javax.naming.StringRefAddr in project tomcat by apache.

the class NamingContextListener method addResourceEnvRef.

/**
 * Set the specified resources in the naming context.
 *
 * @param resourceEnvRef the resource reference
 */
public void addResourceEnvRef(ContextResourceEnvRef resourceEnvRef) {
    Reference ref = lookForLookupRef(resourceEnvRef);
    if (ref == null) {
        // Create a reference to the resource env.
        ref = new ResourceEnvRef(resourceEnvRef.getType());
        // Adding the additional parameters, if any
        Iterator<String> params = resourceEnvRef.listProperties();
        while (params.hasNext()) {
            String paramName = params.next();
            String paramValue = (String) resourceEnvRef.getProperty(paramName);
            StringRefAddr refAddr = new StringRefAddr(paramName, paramValue);
            ref.add(refAddr);
        }
    }
    try {
        if (log.isDebugEnabled()) {
            log.debug(sm.getString("naming.addResourceEnvRef", resourceEnvRef.getName()));
        }
        createSubcontexts(envCtx, resourceEnvRef.getName());
        envCtx.bind(resourceEnvRef.getName(), ref);
    } catch (NamingException e) {
        log.error(sm.getString("naming.bindFailed", e));
    }
}
Also used : StringRefAddr(javax.naming.StringRefAddr) Reference(javax.naming.Reference) NamingException(javax.naming.NamingException) ResourceEnvRef(org.apache.naming.ResourceEnvRef) ContextResourceEnvRef(org.apache.tomcat.util.descriptor.web.ContextResourceEnvRef)

Example 32 with StringRefAddr

use of javax.naming.StringRefAddr in project tomcat by apache.

the class PerUserPoolDataSource method getReference.

/**
 * Returns a <code>PerUserPoolDataSource</code> {@link Reference}.
 */
@Override
public Reference getReference() throws NamingException {
    final Reference ref = new Reference(getClass().getName(), PerUserPoolDataSourceFactory.class.getName(), null);
    ref.add(new StringRefAddr("instanceKey", getInstanceKey()));
    return ref;
}
Also used : StringRefAddr(javax.naming.StringRefAddr) Reference(javax.naming.Reference)

Example 33 with StringRefAddr

use of javax.naming.StringRefAddr in project druid by alibaba.

the class ProxoolDataSource method populatePropertiesFromReference.

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());
    }
    property = reference.get(ProxoolConstants.HOUSE_KEEPING_SLEEP_TIME_PROPERTY);
    if (property != null) {
        setHouseKeepingSleepTime(Integer.valueOf(property.getContent().toString()).intValue());
    }
    property = reference.get(ProxoolConstants.HOUSE_KEEPING_TEST_SQL_PROPERTY);
    if (property != null) {
        setHouseKeepingTestSql(property.getContent().toString());
    }
    property = reference.get(ProxoolConstants.MAXIMUM_CONNECTION_COUNT_PROPERTY);
    if (property != null) {
        setMaximumConnectionCount(Integer.valueOf(property.getContent().toString()).intValue());
    }
    property = reference.get(ProxoolConstants.MAXIMUM_CONNECTION_LIFETIME_PROPERTY);
    if (property != null) {
        setMaximumConnectionLifetime(Integer.valueOf(property.getContent().toString()).intValue());
    }
    property = reference.get(ProxoolConstants.MAXIMUM_ACTIVE_TIME_PROPERTY);
    if (property != null) {
        setMaximumActiveTime(Long.valueOf(property.getContent().toString()).intValue());
    }
    property = reference.get(ProxoolConstants.MINIMUM_CONNECTION_COUNT_PROPERTY);
    if (property != null) {
        setMinimumConnectionCount(Integer.valueOf(property.getContent().toString()).intValue());
    }
    property = reference.get(ProxoolConstants.OVERLOAD_WITHOUT_REFUSAL_LIFETIME_PROPERTY);
    if (property != null) {
        setOverloadWithoutRefusalLifetime(Integer.valueOf(property.getContent().toString()).intValue());
    }
    property = reference.get(ProxoolConstants.PASSWORD_PROPERTY);
    if (property != null) {
        setPassword(property.getContent().toString());
    }
    property = reference.get(ProxoolConstants.PROTOTYPE_COUNT_PROPERTY);
    if (property != null) {
        setPrototypeCount(Integer.valueOf(property.getContent().toString()).intValue());
    }
    property = reference.get(ProxoolConstants.RECENTLY_STARTED_THRESHOLD_PROPERTY);
    if (property != null) {
        setRecentlyStartedThreshold(Integer.valueOf(property.getContent().toString()).intValue());
    }
    property = reference.get(ProxoolConstants.SIMULTANEOUS_BUILD_THROTTLE_PROPERTY);
    if (property != null) {
        setSimultaneousBuildThrottle(Integer.valueOf(property.getContent().toString()).intValue());
    }
    property = reference.get(ProxoolConstants.STATISTICS_PROPERTY);
    if (property != null) {
        setStatistics(property.getContent().toString());
    }
    property = reference.get(ProxoolConstants.STATISTICS_LOG_LEVEL_PROPERTY);
    if (property != null) {
        setStatisticsLogLevel(property.getContent().toString());
    }
    property = reference.get(ProxoolConstants.TRACE_PROPERTY);
    if (property != null) {
        setTrace("true".equalsIgnoreCase(property.getContent().toString()));
    }
    property = reference.get(ProxoolConstants.DRIVER_URL_PROPERTY);
    if (property != null) {
        setDriverUrl(property.getContent().toString());
    }
    property = reference.get(ProxoolConstants.USER_PROPERTY);
    if (property != null) {
        setUser(property.getContent().toString());
    }
    property = reference.get(ProxoolConstants.VERBOSE_PROPERTY);
    if (property != null) {
        setVerbose("true".equalsIgnoreCase(property.getContent().toString()));
    }
    property = reference.get(ProxoolConstants.JMX_PROPERTY);
    if (property != null) {
        setJmx("true".equalsIgnoreCase(property.getContent().toString()));
    }
    property = reference.get(ProxoolConstants.JMX_AGENT_PROPERTY);
    if (property != null) {
        setJmxAgentId(property.getContent().toString());
    }
    property = reference.get(ProxoolConstants.TEST_BEFORE_USE_PROPERTY);
    if (property != null) {
        setTestBeforeUse("true".equalsIgnoreCase(property.getContent().toString()));
    }
    property = reference.get(ProxoolConstants.TEST_AFTER_USE_PROPERTY);
    if (property != null) {
        setTestAfterUse("true".equalsIgnoreCase(property.getContent().toString()));
    }
    // Pick up any properties that we don't recognise
    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);
        }
    }
}
Also used : RefAddr(javax.naming.RefAddr) StringRefAddr(javax.naming.StringRefAddr) StringRefAddr(javax.naming.StringRefAddr)

Example 34 with StringRefAddr

use of javax.naming.StringRefAddr in project hibernate-orm by hibernate.

the class JBossStandaloneJtaExampleTest method bind.

/**
	 * Helper method that binds the a non serializable object to the JNDI tree.
	 *
	 * @param jndiName  Name under which the object must be bound
	 * @param who       Object to bind in JNDI
	 * @param classType Class type under which should appear the bound object
	 * @param ctx       Naming context under which we bind the object
	 * @throws Exception Thrown if a naming exception occurs during binding
	 */
private void bind(String jndiName, Object who, Class classType, Context ctx) throws Exception {
    // Ah ! This service isn't serializable, so we use a helper class
    NonSerializableFactory.bind(jndiName, who);
    Name n = ctx.getNameParser("").parse(jndiName);
    while (n.size() > 1) {
        String ctxName = n.get(0);
        try {
            ctx = (Context) ctx.lookup(ctxName);
        } catch (NameNotFoundException e) {
            System.out.println("Creating subcontext:" + ctxName);
            ctx = ctx.createSubcontext(ctxName);
        }
        n = n.getSuffix(1);
    }
    // The helper class NonSerializableFactory uses address type nns, we go on to
    // use the helper class to bind the service object in JNDI
    StringRefAddr addr = new StringRefAddr("nns", jndiName);
    Reference ref = new Reference(classType.getName(), addr, NonSerializableFactory.class.getName(), null);
    ctx.rebind(n.get(0), ref);
}
Also used : NameNotFoundException(javax.naming.NameNotFoundException) StringRefAddr(javax.naming.StringRefAddr) Reference(javax.naming.Reference) NonSerializableFactory(org.jboss.util.naming.NonSerializableFactory) Name(javax.naming.Name)

Example 35 with StringRefAddr

use of javax.naming.StringRefAddr in project jetty.project by eclipse.

the class MailSessionReference method setProperties.

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()));
    }
}
Also used : StringRefAddr(javax.naming.StringRefAddr) Iterator(java.util.Iterator) Map(java.util.Map)

Aggregations

StringRefAddr (javax.naming.StringRefAddr)67 Reference (javax.naming.Reference)51 NamingException (javax.naming.NamingException)18 RefAddr (javax.naming.RefAddr)9 Test (org.junit.Test)8 Name (javax.naming.Name)7 Properties (java.util.Properties)6 HashMap (java.util.HashMap)5 Iterator (java.util.Iterator)5 CompositeName (javax.naming.CompositeName)5 NameAlreadyBoundException (javax.naming.NameAlreadyBoundException)5 ObjectFactory (javax.naming.spi.ObjectFactory)5 MalformedURLException (java.net.MalformedURLException)4 Enumeration (java.util.Enumeration)4 Hashtable (java.util.Hashtable)4 Map (java.util.Map)4 Context (javax.naming.Context)4 NameNotFoundException (javax.naming.NameNotFoundException)3 Context (org.apache.catalina.Context)3 NamingContext (org.apache.naming.NamingContext)3