in qpid-jms-client/src/main/java/org/apache/qpid/jms/jndi/JmsInitialContextFactory.java [63:149]
public Context getInitialContext(Hashtable<?, ?> environment) throws NamingException {
// Copy the environment to ensure we don't modify/reference it, it belongs to the caller.
Hashtable<Object, Object> environmentCopy = new Hashtable<Object, Object>();
environmentCopy.putAll(environment);
String location = null;
if (environmentCopy.containsKey(Context.PROVIDER_URL)) {
location = (String) environment.get(Context.PROVIDER_URL);
} else {
location = System.getProperty(Context.PROVIDER_URL);
}
// If present, check if PROVIDER_URL is a client URI, by seeing if we find a factory for it.
// If we do, set it as the URI to be used for the default connection factories.
boolean providerUri = false;
if (location != null) {
try {
String expanded = expand(location, environmentCopy);
if (ProviderFactory.findProviderFactory(new URI(expanded)) != null) {
environmentCopy.put(CONNECTION_FACTORY_DEFAULT_KEY_PREFIX + REMOTE_URI_PROP, expanded);
providerUri = true;
}
} catch (IOException | URISyntaxException e) {
// Not a valid URI or didnt find a client factory for it.
}
}
try {
// If it wasnt a client URI, check for *optional* properties file to augment given environment
if (!providerUri && location != null) {
BufferedInputStream inputStream;
try {
URL fileURL = new URL(location);
inputStream = new BufferedInputStream(fileURL.openStream());
} catch (MalformedURLException e) {
inputStream = new BufferedInputStream(new FileInputStream(location));
}
Properties p = new Properties();
try {
p.load(inputStream);
} finally {
inputStream.close();
}
for (Map.Entry<Object, Object> entry : p.entrySet()) {
String key = String.valueOf(entry.getKey());
String value = String.valueOf(entry.getValue());
environmentCopy.put(key, value);
}
}
} catch (IOException ioe) {
NamingException ne = new NamingException("Unable to load property file: " + location + ".");
ne.initCause(ioe);
throw ne;
}
// Now inspect the environment and create the bindings for the context
Map<String, Object> bindings = new ConcurrentHashMap<String, Object>();
createConnectionFactories(environmentCopy, bindings);
createQueues(environmentCopy, bindings);
createTopics(environmentCopy, bindings);
// Add sub-contexts for dynamic creation on lookup.
// "dynamicQueues/<queue-name>"
bindings.put(DYNAMIC_QUEUES, new LazyCreateContext() {
private static final long serialVersionUID = 6503881346214855588L;
@Override
protected Object createEntry(String name) {
return new JmsQueue(name);
}
});
// "dynamicTopics/<topic-name>"
bindings.put(DYNAMIC_TOPICS, new LazyCreateContext() {
private static final long serialVersionUID = 2019166796234979615L;
@Override
protected Object createEntry(String name) {
return new JmsTopic(name);
}
});
return createContext(environmentCopy, bindings);
}