use of javax.naming.RefAddr in project tomee by apache.
the class TomcatJndiBuilder method normalize.
/**
* LinkRef addresses need to be prefixed with java: or they won't resolve
*
* OpenEJB is fine with this, but Tomcat needs them
*
* @param value
* @return
*/
private static Object normalize(final Object value) {
try {
if (!(value instanceof LinkRef)) {
return value;
}
final LinkRef ref = (LinkRef) value;
final RefAddr refAddr = ref.getAll().nextElement();
final String address = refAddr.getContent().toString();
if (address.startsWith("openejb:")) {
return value;
}
if (!address.startsWith("java:")) {
return new LinkRef("java:" + address);
}
} catch (final Exception e) {
// no-op
}
return value;
}
use of javax.naming.RefAddr in project mongo-java-driver by mongodb.
the class MongoClientFactory method getObjectInstance.
/**
* This implementation will create instances of {@link MongoClient} based on a connection string conforming to the format specified in
* {@link MongoClientURI}.
* <p>The connection string is specified in one of two ways:</p>
* <ul>
* <li>As the {@code String} value of a property in the {@code environment} parameter with a key of {@code "connectionString"}</li>
* <li>As the {@code String} value of a {@link RefAddr} with type {@code "connectionString"} in an {@code obj} parameter
* of type {@link Reference}</li>
* </ul>
*
* Specification of the connection string in the {@code environment} parameter takes precedence over specification in the {@code obj}
* parameter. The {@code name} and {@code nameCtx} parameters are ignored.
*
* If a non-empty connection string is not specified in either of these two ways, a {@link MongoException} is thrown.
* @return an instance of {@link MongoClient} based on the specified connection string
* @throws MongoException
*
* Note: Not all options that can be specified via {@link com.mongodb.MongoClientOptions} can be specified via the connection string.
*/
@Override
public Object getObjectInstance(final Object obj, final Name name, final Context nameCtx, final Hashtable<?, ?> environment) throws Exception {
// Some app servers, e.g. Wildfly, use the environment to pass location information to an ObjectFactory
String connectionString = null;
if (environment.get(CONNECTION_STRING) instanceof String) {
connectionString = (String) environment.get(CONNECTION_STRING);
}
if (connectionString == null || connectionString.isEmpty()) {
LOGGER.debug(format("No '%s' property in environment. Casting 'obj' to java.naming.Reference to look for a " + "javax.naming.RefAddr with type equal to '%s'", CONNECTION_STRING, CONNECTION_STRING));
// javax.naming.RefAddr
if (obj instanceof Reference) {
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;
}
}
}
}
}
}
if (connectionString == null || connectionString.isEmpty()) {
throw new MongoException(format("Could not locate '%s' in either environment or obj", CONNECTION_STRING));
}
MongoClientURI uri = new MongoClientURI(connectionString);
return new MongoClient(uri);
}
use of javax.naming.RefAddr in project jackrabbit by apache.
the class ClientRepositoryFactory method getObjectInstance.
/**
* JNDI factory method for creating JCR-RMI clients. Creates a lazy
* client repository instance that uses the reference parameter "url"
* as the RMI URL where the remote repository is looked up when accessed.
*
* @param object reference parameters
* @param name unused
* @param context unused
* @param environment unused
* @return repository client
*/
public Object getObjectInstance(Object object, Name name, Context context, Hashtable environment) {
if (object instanceof Reference) {
Reference reference = (Reference) object;
RefAddr url = reference.get(URL_PARAMETER);
if (url != null && url.getContent() != null) {
try {
return getRepository(url.getContent().toString());
} catch (Exception e) {
return null;
}
}
}
return null;
}
use of javax.naming.RefAddr in project jackrabbit by apache.
the class RepositoryImpl method getReference.
// ------------------------------------------------------< Referenceable >---
/**
* @see Referenceable#getReference()
*/
public Reference getReference() throws NamingException {
if (config instanceof Referenceable) {
Referenceable confref = (Referenceable) config;
if (reference == null) {
reference = new Reference(RepositoryImpl.class.getName(), RepositoryImpl.Factory.class.getName(), null);
// carry over all addresses from referenceable config
for (Enumeration<RefAddr> en = confref.getReference().getAll(); en.hasMoreElements(); ) {
reference.add(en.nextElement());
}
// also add the information required by factory class
reference.add(new StringRefAddr(Factory.RCF, confref.getReference().getFactoryClassName()));
reference.add(new StringRefAddr(Factory.RCC, config.getClass().getName()));
}
return reference;
} else {
throw new javax.naming.OperationNotSupportedException("Contained RepositoryConfig needs to implement javax.naming.Referenceable");
}
}
use of javax.naming.RefAddr in project Payara by payara.
the class PrimitivesAndStringFactory method getObjectInstance.
public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable<?, ?> environment) throws Exception {
Reference ref = (Reference) obj;
Enumeration<RefAddr> refAddrs = ref.getAll();
String type = null;
String value = null;
boolean hasAnyProperties = false;
while (refAddrs.hasMoreElements()) {
hasAnyProperties = true;
RefAddr addr = refAddrs.nextElement();
String propName = addr.getType();
type = ref.getClassName();
if (propName.equalsIgnoreCase("value")) {
value = (String) addr.getContent();
}
}
// if there are no properties at all, back-up obtain the type of the custom resource
if (!hasAnyProperties && type == null) {
type = ref.getClassName();
}
if (type != null && value != null) {
type = type.toUpperCase(Locale.getDefault());
if (type.endsWith("INT") || type.endsWith("INTEGER")) {
return Integer.valueOf(value);
} else if (type.endsWith("LONG")) {
return Long.valueOf(value);
} else if (type.endsWith("DOUBLE")) {
return Double.valueOf(value);
} else if (type.endsWith("FLOAT")) {
return Float.valueOf(value);
} else if (type.endsWith("CHAR") || type.endsWith("CHARACTER")) {
return value.charAt(0);
} else if (type.endsWith("SHORT")) {
return Short.valueOf(value);
} else if (type.endsWith("BYTE")) {
return Byte.valueOf(value);
} else if (type.endsWith("BOOLEAN")) {
return Boolean.valueOf(value);
} else if (type.endsWith("STRING")) {
return value;
} else {
throw new IllegalArgumentException("unknown type [" + type + "] ");
}
} else if (type == null) {
throw new IllegalArgumentException("type cannot be null");
} else {
throw new IllegalAccessException("value cannot be null");
}
}
Aggregations