List of usage examples for javax.naming StringRefAddr StringRefAddr
public StringRefAddr(String addrType, String addr)
From source file:org.apache.synapse.commons.datasource.JNDIBasedDataSourceRepository.java
/** * Helper method to set all default parameter for naming reference of data source * * @param reference The naming reference instance * @param information DataSourceInformation instance *///w ww .j av a 2 s .c o m private static void setCommonParameters(Reference reference, DataSourceInformation information) { reference.add(new StringRefAddr(DataSourceConstants.PROP_DEFAULT_AUTO_COMMIT, String.valueOf(information.isDefaultAutoCommit()))); reference.add(new StringRefAddr(DataSourceConstants.PROP_DEFAULT_READ_ONLY, String.valueOf(information.isDefaultReadOnly()))); reference.add(new StringRefAddr(DataSourceConstants.PROP_TEST_ON_BORROW, String.valueOf(information.isTestOnBorrow()))); reference.add(new StringRefAddr(DataSourceConstants.PROP_TEST_ON_RETURN, String.valueOf(information.isTestOnReturn()))); reference.add(new StringRefAddr(DataSourceConstants.PROP_TIME_BETWEEN_EVICTION_RUNS_MILLIS, String.valueOf(information.getTimeBetweenEvictionRunsMillis()))); reference.add(new StringRefAddr(DataSourceConstants.PROP_NUM_TESTS_PER_EVICTION_RUN, String.valueOf(information.getNumTestsPerEvictionRun()))); reference.add(new StringRefAddr(DataSourceConstants.PROP_MIN_EVICTABLE_IDLE_TIME_MILLIS, String.valueOf(information.getMinEvictableIdleTimeMillis()))); reference.add(new StringRefAddr(DataSourceConstants.PROP_TEST_WHILE_IDLE, String.valueOf(information.isTestWhileIdle()))); String validationQuery = information.getValidationQuery(); if (validationQuery != null && !"".equals(validationQuery)) { reference.add(new StringRefAddr(DataSourceConstants.PROP_VALIDATION_QUERY, validationQuery)); } }
From source file:org.apache.synapse.commons.datasource.JNDIBasedDataSourceRepository.java
/** * Helper method to set all BasicDataSource specific parameter * * @param ref The naming reference instance * @param information DataSourceInformation instance *///from w w w .j ava2 s . c om private static void setBasicDataSourceParameters(Reference ref, DataSourceInformation information) { int defaultTransactionIsolation = information.getDefaultTransactionIsolation(); String defaultCatalog = information.getDefaultCatalog(); if (defaultTransactionIsolation != -1) { ref.add(new StringRefAddr(DataSourceConstants.PROP_DEFAULT_TRANSACTION_ISOLATION, String.valueOf(defaultTransactionIsolation))); } ref.add(new StringRefAddr(DataSourceConstants.PROP_MIN_IDLE, String.valueOf(information.getMaxIdle()))); ref.add(new StringRefAddr(DataSourceConstants.PROP_ACCESS_TO_UNDERLYING_CONNECTION_ALLOWED, String.valueOf(information.isAccessToUnderlyingConnectionAllowed()))); ref.add(new StringRefAddr(DataSourceConstants.PROP_REMOVE_ABANDONED, String.valueOf(information.isRemoveAbandoned()))); ref.add(new StringRefAddr(DataSourceConstants.PROP_REMOVE_ABANDONED_TIMEOUT, String.valueOf(information.getRemoveAbandonedTimeout()))); ref.add(new StringRefAddr(DataSourceConstants.PROP_LOG_ABANDONED, String.valueOf(information.isLogAbandoned()))); ref.add(new StringRefAddr(DataSourceConstants.PROP_POOL_PREPARED_STATEMENTS, String.valueOf(information.isPoolPreparedStatements()))); ref.add(new StringRefAddr(DataSourceConstants.PROP_MAX_OPEN_PREPARED_STATEMENTS, String.valueOf(information.getMaxOpenPreparedStatements()))); ref.add(new StringRefAddr(DataSourceConstants.PROP_INITIAL_SIZE, String.valueOf(information.getInitialSize()))); if (defaultCatalog != null && !"".equals(defaultCatalog)) { ref.add(new StringRefAddr(DataSourceConstants.PROP_DEFAULT_CATALOG, defaultCatalog)); } }
From source file:org.apache.synapse.util.DataSourceRegistrar.java
/** * Helper method to register a single data source .The given data source name is used , * if there is no property with name dsName ,when,data source is binding to the initial context, * * @param dsName The name of the data source * @param dsProperties The property bag * @param initialContext The initial context instance * @param jndiEnv The JNDI environment properties *///from ww w. jav a2 s . c om private static void registerDataSource(String dsName, Properties dsProperties, InitialContext initialContext, Properties jndiEnv) { if (dsName == null || "".equals(dsName)) { if (log.isDebugEnabled()) { log.debug("DataSource name is either empty or null, ignoring.."); } return; } StringBuffer buffer = new StringBuffer(); buffer.append(SynapseConstants.SYNAPSE_DATASOURCES); buffer.append(DOT_STRING); buffer.append(dsName); buffer.append(DOT_STRING); // Prefix for getting particular data source's properties String prefix = buffer.toString(); String driver = getProperty(dsProperties, prefix + PROP_DRIVER_CLS_NAME, null); if (driver == null) { handleException(prefix + PROP_DRIVER_CLS_NAME + " cannot be found."); } String url = getProperty(dsProperties, prefix + PROP_URL, null); if (url == null) { handleException(prefix + PROP_URL + " cannot be found."); } // get other required properties String user = getProperty(dsProperties, prefix + PROP_USER_NAME, "synapse"); String password = getProperty(dsProperties, prefix + PROP_PASSWORD, "synapse"); String dataSourceName = getProperty(dsProperties, prefix + PROP_DSNAME, dsName); //populates context tree populateContextTree(initialContext, dataSourceName); String dsType = getProperty(dsProperties, prefix + "type", "BasicDataSource"); String maxActive = getProperty(dsProperties, prefix + PROP_MAXACTIVE, String.valueOf(GenericObjectPool.DEFAULT_MAX_ACTIVE)); String maxIdle = getProperty(dsProperties, prefix + PROP_MAXIDLE, String.valueOf(GenericObjectPool.DEFAULT_MAX_IDLE)); String maxWait = getProperty(dsProperties, prefix + PROP_MAXWAIT, String.valueOf(GenericObjectPool.DEFAULT_MAX_WAIT)); if ("BasicDataSource".equals(dsType)) { Reference ref = new Reference("javax.sql.DataSource", "org.apache.commons.dbcp.BasicDataSourceFactory", null); ref.add(new StringRefAddr(PROP_DRIVER_CLS_NAME, driver)); ref.add(new StringRefAddr(PROP_URL, url)); ref.add(new StringRefAddr(PROP_USER_NAME, user)); ref.add(new StringRefAddr(PROP_PASSWORD, password)); ref.add(new StringRefAddr(PROP_MAXACTIVE, maxActive)); ref.add(new StringRefAddr(PROP_MAXIDLE, maxIdle)); ref.add(new StringRefAddr(PROP_MAXWAIT, maxWait)); //set BasicDataSource specific parameters setBasicDataSourceParameters(ref, dsProperties, prefix); //set default properties for reference setCommonParameters(ref, dsProperties, prefix); try { initialContext.rebind(dataSourceName, ref); } catch (NamingException e) { String msg = " Error binding name ' " + dataSourceName + " ' to " + "the DataSource(BasicDataSource) reference"; handleException(msg, e); } } else if ("PerUserPoolDataSource".equals(dsType)) { // Construct DriverAdapterCPDS reference String className = getProperty(dsProperties, prefix + PROP_CPDSADAPTER + DOT_STRING + "className", "org.apache.commons.dbcp.cpdsadapter.DriverAdapterCPDS"); String factory = getProperty(dsProperties, prefix + PROP_CPDSADAPTER + DOT_STRING + "factory", "org.apache.commons.dbcp.cpdsadapter.DriverAdapterCPDS"); String name = getProperty(dsProperties, prefix + PROP_CPDSADAPTER + DOT_STRING + "name", "cpds"); Reference cpdsRef = new Reference(className, factory, null); cpdsRef.add(new StringRefAddr(PROP_DRIVER, driver)); cpdsRef.add(new StringRefAddr(PROP_URL, url)); cpdsRef.add(new StringRefAddr(PROP_USER, user)); cpdsRef.add(new StringRefAddr(PROP_PASSWORD, password)); try { initialContext.rebind(name, cpdsRef); } catch (NamingException e) { String msg = "Error binding name '" + name + "' to " + "the DriverAdapterCPDS reference"; handleException(msg, e); } // Construct PerUserPoolDataSource reference Reference ref = new Reference("org.apache.commons.dbcp.datasources.PerUserPoolDataSource", "org.apache.commons.dbcp.datasources.PerUserPoolDataSourceFactory", null); ref.add(new BinaryRefAddr(PROP_JNDI_ENV, serialize(jndiEnv))); ref.add(new StringRefAddr(PROP_DATA_SOURCE_NAME, name)); ref.add(new StringRefAddr(PROP_DEFAULTMAXACTIVE, maxActive)); ref.add(new StringRefAddr(PROP_DEFAULTMAXIDLE, maxIdle)); ref.add(new StringRefAddr(PROP_DEFAULTMAXWAIT, maxWait)); //set default properties for reference setCommonParameters(ref, dsProperties, prefix); try { initialContext.rebind(dataSourceName, ref); } catch (NamingException e) { String msg = "Error binding name ' " + dataSourceName + " ' to " + "the PerUserPoolDataSource reference"; handleException(msg, e); } } else { handleException("Unsupported data source type : " + dsType); } }
From source file:org.apache.synapse.util.DataSourceRegistrar.java
/** * Helper method to set all default parameter for naming reference of data source * * @param reference The naming reference instance * @param properties The properties which contains required parameter value * @param prefix The key prefix for which is used to get data from given properties *//* ww w. j a v a2s . co m*/ private static void setCommonParameters(Reference reference, Properties properties, String prefix) { String defaultAutoCommit = getProperty(properties, prefix + PROP_DEFAULTAUTOCOMMIT, String.valueOf(true)); String defaultReadOnly = getProperty(properties, prefix + PROP_DEFAULTREADONLY, String.valueOf(false)); String testOnBorrow = getProperty(properties, prefix + PROP_TESTONBORROW, String.valueOf(true)); String testOnReturn = getProperty(properties, prefix + PROP_TESTONRETURN, String.valueOf(false)); String timeBetweenEvictionRunsMillis = getProperty(properties, prefix + PROP_TIMEBETWEENEVICTIONRUNSMILLIS, String.valueOf(GenericObjectPool.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS)); String numTestsPerEvictionRun = getProperty(properties, prefix + PROP_NUMTESTSPEREVICTIONRUN, String.valueOf(GenericObjectPool.DEFAULT_NUM_TESTS_PER_EVICTION_RUN)); String minEvictableIdleTimeMillis = getProperty(properties, prefix + PROP_MINEVICTABLEIDLETIMEMILLIS, String.valueOf(GenericObjectPool.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS)); String testWhileIdle = getProperty(properties, prefix + PROP_TESTWHILEIDLE, String.valueOf(false)); String validationQuery = getProperty(properties, prefix + PROP_VALIDATIONQUERY, null); reference.add(new StringRefAddr(PROP_DEFAULTAUTOCOMMIT, defaultAutoCommit)); reference.add(new StringRefAddr(PROP_DEFAULTREADONLY, defaultReadOnly)); reference.add(new StringRefAddr(PROP_TESTONBORROW, testOnBorrow)); reference.add(new StringRefAddr(PROP_TESTONRETURN, testOnReturn)); reference.add(new StringRefAddr(PROP_TIMEBETWEENEVICTIONRUNSMILLIS, timeBetweenEvictionRunsMillis)); reference.add(new StringRefAddr(PROP_NUMTESTSPEREVICTIONRUN, numTestsPerEvictionRun)); reference.add(new StringRefAddr(PROP_MINEVICTABLEIDLETIMEMILLIS, minEvictableIdleTimeMillis)); reference.add(new StringRefAddr(PROP_TESTWHILEIDLE, testWhileIdle)); if (validationQuery != null && !"".equals(validationQuery)) { reference.add(new StringRefAddr(PROP_VALIDATIONQUERY, validationQuery)); } }
From source file:org.apache.synapse.util.DataSourceRegistrar.java
/** * Helper method to set all BasicDataSource specific parameter * * @param reference The naming reference instance * @param properties The properties which contains required parameter value * @param prefix The key prefix for which is used to get data from given properties *//*w w w . j a v a 2 s . c o m*/ private static void setBasicDataSourceParameters(Reference reference, Properties properties, String prefix) { String minIdle = getProperty(properties, prefix + PROP_MINIDLE, String.valueOf(GenericObjectPool.DEFAULT_MIN_IDLE)); String initialSize = getProperty(properties, prefix + PROP_INITIALSIZE, String.valueOf(0)); String defaultTransactionIsolation = getProperty(properties, prefix + PROP_DEFAULTTRANSACTIONISOLATION, null); String defaultCatalog = getProperty(properties, prefix + PROP_DEFAULTCATALOG, null); String accessToUnderlyingConnectionAllowed = getProperty(properties, prefix + PROP_ACCESSTOUNDERLYINGCONNECTIONALLOWED, String.valueOf(false)); String removeAbandoned = getProperty(properties, prefix + PROP_REMOVEABANDONED, String.valueOf(false)); String removeAbandonedTimeout = getProperty(properties, prefix + PROP_REMOVEABANDONEDTIMEOUT, String.valueOf(300)); String logAbandoned = getProperty(properties, prefix + PROP_LOGABANDONED, String.valueOf(false)); String poolPreparedStatements = getProperty(properties, prefix + PROP_POOLPREPAREDSTATEMENTS, String.valueOf(false)); String maxOpenPreparedStatements = getProperty(properties, prefix + PROP_MAXOPENPREPAREDSTATEMENTS, String.valueOf(GenericKeyedObjectPool.DEFAULT_MAX_TOTAL)); reference.add(new StringRefAddr(PROP_MINIDLE, minIdle)); if (defaultTransactionIsolation != null && !"".equals(defaultTransactionIsolation)) { reference.add(new StringRefAddr(PROP_DEFAULTTRANSACTIONISOLATION, defaultTransactionIsolation)); } reference.add( new StringRefAddr(PROP_ACCESSTOUNDERLYINGCONNECTIONALLOWED, accessToUnderlyingConnectionAllowed)); reference.add(new StringRefAddr(PROP_REMOVEABANDONED, removeAbandoned)); reference.add(new StringRefAddr(PROP_REMOVEABANDONEDTIMEOUT, removeAbandonedTimeout)); reference.add(new StringRefAddr(PROP_LOGABANDONED, logAbandoned)); reference.add(new StringRefAddr(PROP_POOLPREPAREDSTATEMENTS, poolPreparedStatements)); reference.add(new StringRefAddr(PROP_MAXOPENPREPAREDSTATEMENTS, maxOpenPreparedStatements)); reference.add(new StringRefAddr(PROP_INITIALSIZE, initialSize)); if (defaultCatalog != null && !"".equals(defaultCatalog)) { reference.add(new StringRefAddr(PROP_DEFAULTCATALOG, defaultCatalog)); } }
From source file:org.compass.core.impl.DefaultCompass.java
public Reference getReference() throws NamingException { return new Reference(DefaultCompass.class.getName(), new StringRefAddr("uuid", uuid), CompassObjectFactory.class.getName(), null); }
From source file:org.enhydra.jdbc.pool.StandardPoolDataSource.java
/** * Retrieves the Reference of this object. Used at binding time by JNDI * to build a reference on this object./*from w ww.j a v a 2 s. co m*/ * * @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 { log.debug("StandardPoolDataSource:getReference return a reference of the object"); Reference ref = super.getReference(); ref.add(new StringRefAddr("checkLevelObject", Integer.toString(getCheckLevelObject()))); ref.add(new StringRefAddr("lifeTime", Long.toString(getLifeTime()))); ref.add(new StringRefAddr("jdbcTestStmt", getJdbcTestStmt())); ref.add(new StringRefAddr("maxSize", Integer.toString(getMaxSize()))); ref.add(new StringRefAddr("minSize", Integer.toString(getMinSize()))); ref.add(new StringRefAddr("dataSourceName", getDataSourceName())); return ref; }
From source file:org.enhydra.jdbc.pool.StandardXAPoolDataSource.java
/** * Retrieves the Reference of this object. Used at binding time by JNDI * to build a reference on this object./*ww w. j a va 2 s . c o m*/ * * @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 { log.debug("StandardXAPoolDataSource:getReference return a reference of the object"); Reference ref = super.getReference(); ref.add(new StringRefAddr("transactionManagerName", this.transactionManagerName)); return ref; }
From source file:org.enhydra.jdbc.standard.StandardDataSource.java
/** * Methods inherited from referenceable//from w w w . j a v a2 s . co m */ public Reference getReference() throws NamingException { // Note that we use getClass().getName() to provide the factory // class name. It is assumed that this class, and all of its // descendants are their own factories. Reference ref = new Reference(getClass().getName(), getClass().getName(), null); ref.add(new StringRefAddr("driverName", getDriverName())); ref.add(new StringRefAddr("url", getUrl())); ref.add(new StringRefAddr("user", getUser())); ref.add(new StringRefAddr("password", getPassword())); ref.add(new StringRefAddr("description", getDescription())); ref.add(new StringRefAddr("loginTimeout", Integer.toString(getLoginTimeout()))); ref.add(new StringRefAddr("transIsolation", Integer.toString(getTransactionIsolation()))); log.debug("StandardDataSource:getReference object returned"); return ref; }
From source file:org.enhydra.jdbc.standard.StandardXADataSource.java
public Reference getReference() throws NamingException { log.debug("StandardXADataSource:getReference return a reference of the object"); Reference ref = super.getReference(); ref.add(new StringRefAddr("transactionManagerName", this.transactionManagerName)); return ref;//from ww w . ja v a 2 s . co m }