Java 类javax.naming.Reference 实例源码

项目:lazycat    文件:NamingContextListener.java   
/**
 * 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<String> params = ejb.listProperties();
    while (params.hasNext()) {
        String paramName = 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));
    }

}
项目:tomcat7    文件:DataSourceLinkFactory.java   
/**
 * Create a new DataSource instance.
 * 
 * @param obj The reference object describing the DataSource
 */
@Override
public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable<?,?> environment)
    throws NamingException {
    Object result = super.getObjectInstance(obj, name, nameCtx, environment);
    // Can we process this request?
    if (result!=null) {
        Reference ref = (Reference) obj;
        RefAddr userAttr = ref.get("username");
        RefAddr passAttr = ref.get("password");
        if (userAttr.getContent()!=null && passAttr.getContent()!=null) {
            result = wrapDataSource(result,userAttr.getContent().toString(), passAttr.getContent().toString());
        }
    }
    return result;
}
项目:tomcat7    文件:GenericNamingResourcesFactory.java   
@Override
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;
    Enumeration<RefAddr> refs = ref.getAll();

    String type = ref.getClassName();
    Object o = Class.forName(type).newInstance();

    while (refs.hasMoreElements()) {
        RefAddr addr = refs.nextElement();
        String param = addr.getType();
        String value = null;
        if (addr.getContent()!=null) {
            value = addr.getContent().toString();
        }
        if (setProperty(o, param, value,false)) {

        } else {
            log.debug("Property not configured["+param+"]. No setter found on["+o+"].");
        }
    }
    return o;
}
项目:tomcat7    文件:TesterFactory.java   
@Override
public Object getObjectInstance(Object obj, Name name, Context nameCtx,
        Hashtable<?,?> environment) throws Exception {

    if (obj instanceof Reference) {
        Reference ref = (Reference)obj;
        String className = ref.getClassName();

        if (className == null) {
            throw new RuntimeException();
        }

        if (className.equals("org.apache.naming.resources.TesterObject")) {
            ClassLoader cl = Thread.currentThread().getContextClassLoader();
            Class<?> clazz =
                cl.loadClass("org.apache.naming.resources.TesterObject");
            return clazz.newInstance();
        }
    }
    return null;
}
项目:apache-tomcat-7.0.73-with-comment    文件:NamingContextListener.java   
/**
 * Set the specified resources in the naming context.
 */
public void addResourceEnvRef(ContextResourceEnvRef resourceEnvRef) {

    // Create a reference to the resource env.
    Reference 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 (logger.isDebugEnabled())
            log.debug("  Adding resource env ref " + resourceEnvRef.getName());
        createSubcontexts(envCtx, resourceEnvRef.getName());
        envCtx.bind(resourceEnvRef.getName(), ref);
    } catch (NamingException e) {
        logger.error(sm.getString("naming.bindFailed", e));
    }

}
项目:apache-tomcat-7.0.73-with-comment    文件:TesterFactory.java   
@Override
public Object getObjectInstance(Object obj, Name name, Context nameCtx,
        Hashtable<?,?> environment) throws Exception {

    if (obj instanceof Reference) {
        Reference ref = (Reference)obj;
        String className = ref.getClassName();

        if (className == null) {
            throw new RuntimeException();
        }

        if (className.equals("org.apache.naming.resources.TesterObject")) {
            ClassLoader cl = Thread.currentThread().getContextClassLoader();
            Class<?> clazz =
                cl.loadClass("org.apache.naming.resources.TesterObject");
            return clazz.newInstance();
        }
    }
    return null;
}
项目:the-vigilantes    文件:ConnectionPropertiesImpl.java   
protected void storeToRef(Reference ref) throws SQLException {
    int numPropertiesToSet = PROPERTY_LIST.size();

    for (int i = 0; i < numPropertiesToSet; i++) {
        java.lang.reflect.Field propertyField = PROPERTY_LIST.get(i);

        try {
            ConnectionProperty propToStore = (ConnectionProperty) propertyField.get(this);

            if (ref != null) {
                propToStore.storeTo(ref);
            }
        } catch (IllegalAccessException iae) {
            throw SQLError.createSQLException(Messages.getString("ConnectionProperties.errorNotExpected"), getExceptionInterceptor());
        }
    }
}
项目:the-vigilantes    文件:MysqlDataSource.java   
/**
 * Required method to support this class as a <CODE>Referenceable</CODE>.
 * 
 * @return a Reference to this data source
 * 
 * @throws NamingException
 *             if a JNDI error occurs
 */
public Reference getReference() throws NamingException {
    String factoryName = "com.mysql.jdbc.jdbc2.optional.MysqlDataSourceFactory";
    Reference ref = new Reference(getClass().getName(), factoryName, null);
    ref.add(new StringRefAddr(NonRegisteringDriver.USER_PROPERTY_KEY, getUser()));
    ref.add(new StringRefAddr(NonRegisteringDriver.PASSWORD_PROPERTY_KEY, this.password));
    ref.add(new StringRefAddr("serverName", getServerName()));
    ref.add(new StringRefAddr("port", "" + getPort()));
    ref.add(new StringRefAddr("databaseName", getDatabaseName()));
    ref.add(new StringRefAddr("url", getUrl()));
    ref.add(new StringRefAddr("explicitUrl", String.valueOf(this.explicitUrl)));

    //
    // Now store all of the 'non-standard' properties...
    //
    try {
        storeToRef(ref);
    } catch (SQLException sqlEx) {
        throw new NamingException(sqlEx.getMessage());
    }

    return ref;
}
项目:s-store    文件:JDBCDataSourceFactory.java   
/**
 * Creates a JDBCDataSource object using the location or reference
 * information specified.<p>
 *
 * The Reference object should support the properties, database, user,
 * password.
 *
 * @param obj The reference information used in creating a
 *      JDBCDatasource object.
 * @param name ignored
 * @param nameCtx ignored
 * @param environment ignored
 * @return A newly created JDBCDataSource object; null if an object
 *      cannot be created.
 * @exception Exception never
 */
public Object getObjectInstance(Object obj, Name name, Context nameCtx,
                                Hashtable environment) throws Exception {

    String    dsClass = "org.hsqldb.jdbc.JDBCDataSource";
    Reference ref     = (Reference) obj;

    if (ref.getClassName().equals(dsClass)) {
        JDBCDataSource ds = new JDBCDataSource();

        ds.setDatabase((String) ref.get("database").getContent());
        ds.setUser((String) ref.get("user").getContent());
        ds.setPassword((String) ref.get("password").getContent());

        return ds;
    } else {
        return null;
    }
}
项目:OpenVertretung    文件:DataSourceRegressionTest.java   
/**
 * Tests fix for BUG#16791 - NullPointerException in MysqlDataSourceFactory
 * due to Reference containing RefAddrs with null content.
 * 
 * @throws Exception
 *             if the test fails
 */
public void testBug16791() throws Exception {
    MysqlDataSource myDs = new MysqlDataSource();
    myDs.setUrl(dbUrl);
    Reference asRef = myDs.getReference();
    System.out.println(asRef);

    removeFromRef(asRef, "port");
    removeFromRef(asRef, NonRegisteringDriver.USER_PROPERTY_KEY);
    removeFromRef(asRef, NonRegisteringDriver.PASSWORD_PROPERTY_KEY);
    removeFromRef(asRef, "serverName");
    removeFromRef(asRef, "databaseName");

    //MysqlDataSource newDs = (MysqlDataSource)
    new MysqlDataSourceFactory().getObjectInstance(asRef, null, null, null);
}
项目:BibliotecaPS    文件:DataSourceRegressionTest.java   
/**
 * Tests fix for BUG#16791 - NullPointerException in MysqlDataSourceFactory
 * due to Reference containing RefAddrs with null content.
 * 
 * @throws Exception
 *             if the test fails
 */
public void testBug16791() throws Exception {
    MysqlDataSource myDs = new MysqlDataSource();
    myDs.setUrl(dbUrl);
    Reference asRef = myDs.getReference();
    System.out.println(asRef);

    removeFromRef(asRef, "port");
    removeFromRef(asRef, NonRegisteringDriver.USER_PROPERTY_KEY);
    removeFromRef(asRef, NonRegisteringDriver.PASSWORD_PROPERTY_KEY);
    removeFromRef(asRef, "serverName");
    removeFromRef(asRef, "databaseName");

    //MysqlDataSource newDs = (MysqlDataSource)
    new MysqlDataSourceFactory().getObjectInstance(asRef, null, null, null);
}
项目:OpenVertretung    文件:ConnectionPropertiesImpl.java   
/**
 * Initializes driver properties that come from a JNDI reference (in the
 * case of a javax.sql.DataSource bound into some name service that doesn't
 * handle Java objects directly).
 * 
 * @param ref
 *            The JNDI Reference that holds RefAddrs for all properties
 * @throws SQLException
 */
protected void initializeFromRef(Reference ref) throws SQLException {
    int numPropertiesToSet = PROPERTY_LIST.size();

    for (int i = 0; i < numPropertiesToSet; i++) {
        java.lang.reflect.Field propertyField = PROPERTY_LIST.get(i);

        try {
            ConnectionProperty propToSet = (ConnectionProperty) propertyField.get(this);

            if (ref != null) {
                propToSet.initializeFrom(ref, getExceptionInterceptor());
            }
        } catch (IllegalAccessException iae) {
            throw SQLError.createSQLException("Internal properties failure", SQLError.SQL_STATE_GENERAL_ERROR, getExceptionInterceptor());
        }
    }

    postInitialization();
}
项目:OpenVertretung    文件:ConnectionPropertiesImpl.java   
protected void storeToRef(Reference ref) throws SQLException {
    int numPropertiesToSet = PROPERTY_LIST.size();

    for (int i = 0; i < numPropertiesToSet; i++) {
        java.lang.reflect.Field propertyField = PROPERTY_LIST.get(i);

        try {
            ConnectionProperty propToStore = (ConnectionProperty) propertyField.get(this);

            if (ref != null) {
                propToStore.storeTo(ref);
            }
        } catch (IllegalAccessException iae) {
            throw SQLError.createSQLException(Messages.getString("ConnectionProperties.errorNotExpected"), getExceptionInterceptor());
        }
    }
}
项目:OpenVertretung    文件:MysqlDataSource.java   
/**
 * Required method to support this class as a <CODE>Referenceable</CODE>.
 * 
 * @return a Reference to this data source
 * 
 * @throws NamingException
 *             if a JNDI error occurs
 */
public Reference getReference() throws NamingException {
    String factoryName = "com.mysql.jdbc.jdbc2.optional.MysqlDataSourceFactory";
    Reference ref = new Reference(getClass().getName(), factoryName, null);
    ref.add(new StringRefAddr(NonRegisteringDriver.USER_PROPERTY_KEY, getUser()));
    ref.add(new StringRefAddr(NonRegisteringDriver.PASSWORD_PROPERTY_KEY, this.password));
    ref.add(new StringRefAddr("serverName", getServerName()));
    ref.add(new StringRefAddr("port", "" + getPort()));
    ref.add(new StringRefAddr("databaseName", getDatabaseName()));
    ref.add(new StringRefAddr("url", getUrl()));
    ref.add(new StringRefAddr("explicitUrl", String.valueOf(this.explicitUrl)));

    //
    // Now store all of the 'non-standard' properties...
    //
    try {
        storeToRef(ref);
    } catch (SQLException sqlEx) {
        throw new NamingException(sqlEx.getMessage());
    }

    return ref;
}
项目:apache-tomcat-7.0.73-with-comment    文件:NamingContextListener.java   
/**
 * 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<String> params = ejb.listProperties();
    while (params.hasNext()) {
        String paramName = 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));
    }

}
项目:lams    文件:NamingContextListener.java   
/**
 * 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));
    }

}
项目:lams    文件:NamingContextListener.java   
/**
 * Set the specified resources in the naming context.
 */
public void addResourceEnvRef(ContextResourceEnvRef resourceEnvRef) {

    // Create a reference to the resource env.
    Reference ref = new ResourceEnvRef(resourceEnvRef.getType());
    // Adding the additional parameters, if any
    Iterator params = resourceEnvRef.listProperties();
    while (params.hasNext()) {
        String paramName = (String) params.next();
        String paramValue = (String) resourceEnvRef.getProperty(paramName);
        StringRefAddr refAddr = new StringRefAddr(paramName, paramValue);
        ref.add(refAddr);
    }
    try {
        if (logger.isDebugEnabled())
            log.debug("  Adding resource env ref " + resourceEnvRef.getName());
        createSubcontexts(envCtx, resourceEnvRef.getName());
        envCtx.bind(resourceEnvRef.getName(), ref);
    } catch (NamingException e) {
        logger.error(sm.getString("naming.bindFailed", e));
    }

}
项目:BibliotecaPS    文件:MysqlDataSource.java   
/**
 * Required method to support this class as a <CODE>Referenceable</CODE>.
 * 
 * @return a Reference to this data source
 * 
 * @throws NamingException
 *             if a JNDI error occurs
 */
public Reference getReference() throws NamingException {
    String factoryName = "com.mysql.jdbc.jdbc2.optional.MysqlDataSourceFactory";
    Reference ref = new Reference(getClass().getName(), factoryName, null);
    ref.add(new StringRefAddr(NonRegisteringDriver.USER_PROPERTY_KEY, getUser()));
    ref.add(new StringRefAddr(NonRegisteringDriver.PASSWORD_PROPERTY_KEY, this.password));
    ref.add(new StringRefAddr("serverName", getServerName()));
    ref.add(new StringRefAddr("port", "" + getPort()));
    ref.add(new StringRefAddr("databaseName", getDatabaseName()));
    ref.add(new StringRefAddr("url", getUrl()));
    ref.add(new StringRefAddr("explicitUrl", String.valueOf(this.explicitUrl)));

    //
    // Now store all of the 'non-standard' properties...
    //
    try {
        storeToRef(ref);
    } catch (SQLException sqlEx) {
        throw new NamingException(sqlEx.getMessage());
    }

    return ref;
}
项目:lazycat    文件:DataSourceLinkFactory.java   
/**
 * Create a new DataSource instance.
 * 
 * @param obj
 *            The reference object describing the DataSource
 */
@Override
public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable<?, ?> environment)
        throws NamingException {
    Object result = super.getObjectInstance(obj, name, nameCtx, environment);
    // Can we process this request?
    if (result != null) {
        Reference ref = (Reference) obj;
        RefAddr userAttr = ref.get("username");
        RefAddr passAttr = ref.get("password");
        if (userAttr.getContent() != null && passAttr.getContent() != null) {
            result = wrapDataSource(result, userAttr.getContent().toString(), passAttr.getContent().toString());
        }
    }
    return result;
}
项目:ProyectoPacientes    文件:ConnectionPropertiesImpl.java   
/**
 * Initializes driver properties that come from a JNDI reference (in the
 * case of a javax.sql.DataSource bound into some name service that doesn't
 * handle Java objects directly).
 * 
 * @param ref
 *            The JNDI Reference that holds RefAddrs for all properties
 * @throws SQLException
 */
protected void initializeFromRef(Reference ref) throws SQLException {
    int numPropertiesToSet = PROPERTY_LIST.size();

    for (int i = 0; i < numPropertiesToSet; i++) {
        java.lang.reflect.Field propertyField = PROPERTY_LIST.get(i);

        try {
            ConnectionProperty propToSet = (ConnectionProperty) propertyField.get(this);

            if (ref != null) {
                propToSet.initializeFrom(ref, getExceptionInterceptor());
            }
        } catch (IllegalAccessException iae) {
            throw SQLError.createSQLException("Internal properties failure", SQLError.SQL_STATE_GENERAL_ERROR, getExceptionInterceptor());
        }
    }

    postInitialization();
}
项目:ProyectoPacientes    文件:ConnectionPropertiesImpl.java   
protected void storeToRef(Reference ref) throws SQLException {
    int numPropertiesToSet = PROPERTY_LIST.size();

    for (int i = 0; i < numPropertiesToSet; i++) {
        java.lang.reflect.Field propertyField = PROPERTY_LIST.get(i);

        try {
            ConnectionProperty propToStore = (ConnectionProperty) propertyField.get(this);

            if (ref != null) {
                propToStore.storeTo(ref);
            }
        } catch (IllegalAccessException iae) {
            throw SQLError.createSQLException(Messages.getString("ConnectionProperties.errorNotExpected"), getExceptionInterceptor());
        }
    }
}
项目:ProyectoPacientes    文件:MysqlDataSource.java   
/**
 * Required method to support this class as a <CODE>Referenceable</CODE>.
 * 
 * @return a Reference to this data source
 * 
 * @throws NamingException
 *             if a JNDI error occurs
 */
public Reference getReference() throws NamingException {
    String factoryName = "com.mysql.jdbc.jdbc2.optional.MysqlDataSourceFactory";
    Reference ref = new Reference(getClass().getName(), factoryName, null);
    ref.add(new StringRefAddr(NonRegisteringDriver.USER_PROPERTY_KEY, getUser()));
    ref.add(new StringRefAddr(NonRegisteringDriver.PASSWORD_PROPERTY_KEY, this.password));
    ref.add(new StringRefAddr("serverName", getServerName()));
    ref.add(new StringRefAddr("port", "" + getPort()));
    ref.add(new StringRefAddr("databaseName", getDatabaseName()));
    ref.add(new StringRefAddr("url", getUrl()));
    ref.add(new StringRefAddr("explicitUrl", String.valueOf(this.explicitUrl)));

    //
    // Now store all of the 'non-standard' properties...
    //
    try {
        storeToRef(ref);
    } catch (SQLException sqlEx) {
        throw new NamingException(sqlEx.getMessage());
    }

    return ref;
}
项目:jerrydog    文件:NamingContextListener.java   
/**
 * 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
    addAdditionalParameters(ejb.getNamingResources(), ref, ejb.getName());
    try {
        createSubcontexts(envCtx, ejb.getName());
        envCtx.bind(ejb.getName(), ref);
    } catch (NamingException e) {
        log(sm.getString("naming.bindFailed", e));
    }

}
项目:jerrydog    文件:NamingContextListener.java   
/**
 * Set the specified resources in the naming context.
 */
public void addResource(ContextResource resource) {

    // Create a reference to the resource.
    Reference ref = new ResourceRef
        (resource.getType(), resource.getDescription(),
         resource.getScope(), resource.getAuth());
    // Adding the additional parameters, if any
    addAdditionalParameters(resource.getNamingResources(), ref, 
                            resource.getName());
    try {
        if (debug >= 2) {
            log("  Adding resource ref " + resource.getName());
            log("  " + ref);
        }
        createSubcontexts(envCtx, resource.getName());
        envCtx.bind(resource.getName(), ref);
    } catch (NamingException e) {
        log(sm.getString("naming.bindFailed", e));
    }

}
项目:BibliotecaPS    文件:ConnectionPropertiesImpl.java   
protected void storeToRef(Reference ref) throws SQLException {
    int numPropertiesToSet = PROPERTY_LIST.size();

    for (int i = 0; i < numPropertiesToSet; i++) {
        java.lang.reflect.Field propertyField = PROPERTY_LIST.get(i);

        try {
            ConnectionProperty propToStore = (ConnectionProperty) propertyField.get(this);

            if (ref != null) {
                propToStore.storeTo(ref);
            }
        } catch (IllegalAccessException iae) {
            throw SQLError.createSQLException(Messages.getString("ConnectionProperties.errorNotExpected"), getExceptionInterceptor());
        }
    }
}
项目:jerrydog    文件:NamingContextListener.java   
/**
 * Set the specified resource link in the naming context.
 */
public void addResourceLink(ContextResourceLink resourceLink) {

    // Create a reference to the resource.
    Reference ref = new ResourceLinkRef
        (resourceLink.getType(), resourceLink.getGlobal());
    // Adding the additional parameters, if any
    addAdditionalParameters(resourceLink.getNamingResources(), ref, 
                            resourceLink.getName());
    try {
        if (debug >= 2)
            log("  Adding resource link " + resourceLink.getName());
        createSubcontexts(envCtx, resourceLink.getName());
        envCtx.bind(resourceLink.getName(), ref);
    } catch (NamingException e) {
        log(sm.getString("naming.bindFailed", e));
    }

}
项目:jerrydog    文件:NamingContextListener.java   
/**
 * 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 params = resourceParameters.getParameters();
    Enumeration _enum = params.keys();
    while (_enum.hasMoreElements()) {
        String paramName = (String) _enum.nextElement();
        String paramValue = (String) params.get(paramName);
        StringRefAddr refAddr = new StringRefAddr(paramName, paramValue);
        ref.add(refAddr);
    }
}
项目:apache-tomcat-7.0.73-with-comment    文件:DataSourceLinkFactory.java   
/**
 * Create a new DataSource instance.
 * 
 * @param obj The reference object describing the DataSource
 */
@Override
public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable<?,?> environment)
    throws NamingException {
    Object result = super.getObjectInstance(obj, name, nameCtx, environment);
    // Can we process this request?
    if (result!=null) {
        Reference ref = (Reference) obj;
        RefAddr userAttr = ref.get("username");
        RefAddr passAttr = ref.get("password");
        if (userAttr.getContent()!=null && passAttr.getContent()!=null) {
            result = wrapDataSource(result,userAttr.getContent().toString(), passAttr.getContent().toString());
        }
    }
    return result;
}
项目:parabuild-ci    文件:jdbcDataSourceFactory.java   
/**
 * Creates a jdbcDatasource object using the location or reference
 * information specified.
 *
 * @param obj The reference information used in creating a
 *      jdbcDatasource object.
 * @param name ignored
 * @param nameCtx ignored
 * @param environment ignored
 * @return A newly created jdbcDataSource object; null if an object
 *      cannot be created.
 * @exception Exception never
 */
public Object getObjectInstance(Object obj, Name name, Context nameCtx,
                                Hashtable environment) throws Exception {

    String    dsClass = "org.hsqldb.jdbc.jdbcDataSource";
    Reference ref     = (Reference) obj;

    if (ref.getClassName().equals(dsClass)) {
        jdbcDataSource ds = new jdbcDataSource();

        ds.setDatabase((String) ref.get("database").getContent());
        ds.setUser((String) ref.get("user").getContent());
        ds.setPassword((String) ref.get("password").getContent());

        return ds;
    } else {
        return null;
    }
}
项目:lazycat    文件:NamingContextListener.java   
/**
 * Set the specified resources in the naming context.
 */
public void addResourceEnvRef(ContextResourceEnvRef resourceEnvRef) {

    // Create a reference to the resource env.
    Reference 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 (logger.isDebugEnabled())
            log.debug("  Adding resource env ref " + resourceEnvRef.getName());
        createSubcontexts(envCtx, resourceEnvRef.getName());
        envCtx.bind(resourceEnvRef.getName(), ref);
    } catch (NamingException e) {
        logger.error(sm.getString("naming.bindFailed", e));
    }

}
项目:parabuild-ci    文件:jdbcDataSourceFactory.java   
/**
 * Creates a jdbcDatasource object using the location or reference
 * information specified.<p>
 *
 * The Reference object should support the properties, database, user,
 * password.
 *
 * @param obj The reference information used in creating a
 *      jdbcDatasource object.
 * @param name ignored
 * @param nameCtx ignored
 * @param environment ignored
 * @return A newly created jdbcDataSource object; null if an object
 *      cannot be created.
 * @exception Exception never
 */
public Object getObjectInstance(Object obj, Name name, Context nameCtx,
                                Hashtable environment) throws Exception {

    String    dsClass = "org.hsqldb.jdbc.jdbcDataSource";
    Reference ref     = (Reference) obj;

    if (ref.getClassName().equals(dsClass)) {
        jdbcDataSource ds = new jdbcDataSource();

        ds.setDatabase((String) ref.get("database").getContent());
        ds.setUser((String) ref.get("user").getContent());
        ds.setPassword((String) ref.get("password").getContent());

        return ds;
    } else {
        return null;
    }
}
项目:parabuild-ci    文件:jdbcDataSourceFactory.java   
/**
 * Creates a jdbcDatasource object using the location or reference
 * information specified.<p>
 *
 * The Reference object should support the properties, database, user,
 * password.
 *
 * @param obj The reference information used in creating a
 *      jdbcDatasource object.
 * @param name ignored
 * @param nameCtx ignored
 * @param environment ignored
 * @return A newly created jdbcDataSource object; null if an object
 *      cannot be created.
 * @exception Exception never
 */
public Object getObjectInstance(Object obj, Name name, Context nameCtx,
                                Hashtable environment) throws Exception {

    String    dsClass = "org.hsqldb.jdbc.jdbcDataSource";
    Reference ref     = (Reference) obj;

    if (ref.getClassName().equals(dsClass)) {
        jdbcDataSource ds = new jdbcDataSource();

        ds.setDatabase((String) ref.get("database").getContent());
        ds.setUser((String) ref.get("user").getContent());
        ds.setPassword((String) ref.get("password").getContent());

        return ds;
    } else {
        return null;
    }
}
项目:parabuild-ci    文件:jdbcDataSourceFactory.java   
/**
 * Creates a jdbcDatasource object using the location or reference
 * information specified.<p>
 *
 * The Reference object should support the properties, database, user,
 * password.
 *
 * @param obj The reference information used in creating a
 *      jdbcDatasource object.
 * @param name ignored
 * @param nameCtx ignored
 * @param environment ignored
 * @return A newly created jdbcDataSource object; null if an object
 *      cannot be created.
 * @exception Exception never
 */
public Object getObjectInstance(Object obj, Name name, Context nameCtx,
                                Hashtable environment) throws Exception {

    String    dsClass = "org.hsqldb.jdbc.jdbcDataSource";
    Reference ref     = (Reference) obj;

    if (ref.getClassName().equals(dsClass)) {
        jdbcDataSource ds = new jdbcDataSource();

        ds.setDatabase((String) ref.get("database").getContent());
        ds.setUser((String) ref.get("user").getContent());
        ds.setPassword((String) ref.get("password").getContent());

        return ds;
    } else {
        return null;
    }
}
项目:lazycat    文件:OpenEjbFactory.java   
/**
 * 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;

}
项目:OpenDiabetes    文件:JDBCXADataSource.java   
/**
 * Retrieves the Reference of this object.
 *
 * @return The non-null javax.naming.Reference of this object.
 * @exception NamingException If a naming exception was encountered
 *          while retrieving the reference.
 */
public Reference getReference() throws NamingException {

    String    cname = "org.hsqldb.jdbc.JDBCDataSourceFactory";
    Reference ref   = new Reference(getClass().getName(), cname, null);

    ref.add(new StringRefAddr("database", getDatabase()));
    ref.add(new StringRefAddr("user", getUser()));
    ref.add(new StringRefAddr("password", password));
    ref.add(new StringRefAddr("loginTimeout",
                              Integer.toString(loginTimeout)));

    return ref;
}
项目:OpenDiabetes    文件:JDBCPool.java   
/**
 * Retrieves the Reference of this object.
 *
 * @return The non-null Reference of this object.
 * @exception NamingException If a naming exception was encountered
 *          while retrieving the reference.
 */
public Reference getReference() throws NamingException {
    String    cname = "org.hsqldb.jdbc.JDBCDataSourceFactory";
    Reference ref   = new Reference(getClass().getName(), cname, null);

    ref.add(new StringRefAddr("database", source.getDatabase()));
    ref.add(new StringRefAddr("user", source.getUser()));
    ref.add(new StringRefAddr("password", source.password));
    ref.add(new StringRefAddr("loginTimeout",
                              Integer.toString(source.loginTimeout)));
    ref.add(new StringRefAddr("poolSize", Integer.toString(connections.length)));

    return ref;
}
项目:sstore-soft    文件:JDBCDataSource.java   
public Reference getReference() throws NamingException {

        String    cname = "org.hsqldb.jdbc.JDBCDataSourceFactory";
        Reference ref   = new Reference(getClass().getName(), cname, null);

        ref.add(new StringRefAddr("database", getDatabase()));
        ref.add(new StringRefAddr("user", getUser()));
        ref.add(new StringRefAddr("password", password));

        return ref;
    }
项目:apache-tomcat-7.0.73-with-comment    文件:OpenEjbFactory.java   
/**
 * 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;

}
项目:tomcat7    文件:MemoryUserDatabaseFactory.java   
/**
 * <p>Create and return a new <code>MemoryUserDatabase</code> instance
 * that has been configured according to the properties of the
 * specified <code>Reference</code>.  If you instance can be created,
 * return <code>null</code> instead.</p>
 *
 * @param obj The possibly null object containing location or
 *  reference information that can be used in creating an object
 * @param name The name of this object relative to <code>nameCtx</code>
 * @param nameCtx The context relative to which the <code>name</code>
 *  parameter is specified, or <code>null</code> if <code>name</code>
 *  is relative to the default initial context
 * @param environment The possibly null environment that is used in
 *  creating this object
 */
@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 "org.apache.catalina.UserDatabase"
    if ((obj == null) || !(obj instanceof Reference)) {
        return (null);
    }
    Reference ref = (Reference) obj;
    if (!"org.apache.catalina.UserDatabase".equals(ref.getClassName())) {
        return (null);
    }

    // Create and configure a MemoryUserDatabase instance based on the
    // RefAddr values associated with this Reference
    MemoryUserDatabase database = new MemoryUserDatabase(name.toString());
    RefAddr ra = null;

    ra = ref.get("pathname");
    if (ra != null) {
        database.setPathname(ra.getContent().toString());
    }

    ra = ref.get("readonly");
    if (ra != null) {
        database.setReadonly(Boolean.parseBoolean(ra.getContent().toString()));
    }

    // Return the configured database instance
    database.open();
    // Don't try something we know won't work
    if (!database.getReadonly())
        database.save();
    return (database);

}
项目:tomcat7    文件:NamingContextListener.java   
/**
 * Set the specified resource link in the naming context.
 */
public void addResourceLink(ContextResourceLink resourceLink) {

    // Create a reference to the resource.
    Reference ref = new ResourceLinkRef
        (resourceLink.getType(), resourceLink.getGlobal(), resourceLink.getFactory(), null);
    Iterator<String> i = resourceLink.listProperties();
    while (i.hasNext()) {
        String key = i.next();
        Object val = resourceLink.getProperty(key);
        if (val!=null) {
            StringRefAddr refAddr = new StringRefAddr(key, val.toString());
            ref.add(refAddr);
        }
    }
    javax.naming.Context ctx =
        "UserTransaction".equals(resourceLink.getName())
        ? compCtx : envCtx;
    try {
        if (logger.isDebugEnabled())
            log.debug("  Adding resource link " + resourceLink.getName());
        createSubcontexts(envCtx, resourceLink.getName());
        ctx.bind(resourceLink.getName(), ref);
    } catch (NamingException e) {
        logger.error(sm.getString("naming.bindFailed", e));
    }

    ResourceLinkFactory.registerGlobalResourceAccess(
            getGlobalNamingContext(), resourceLink.getName(), resourceLink.getGlobal());
}