use of javax.naming.Name in project jetty.project by eclipse.
the class NamingEntry method save.
/**
* Save the NamingEntry for later use.
* <p>
* Saving is done by binding the NamingEntry
* itself, and the value it represents into
* JNDI. In this way, we can link to the
* value it represents later, but also
* still retrieve the NamingEntry itself too.
* <p>
* The object is bound at the jndiName passed in.
* This NamingEntry is bound at __/jndiName.
* <p>
* eg
* <pre>
* jdbc/foo : DataSource
* __/jdbc/foo : NamingEntry
* </pre>
*
* @param object the object to save
* @throws NamingException if unable to save
*/
protected void save(Object object) throws NamingException {
__log.debug("SAVE {} in {}", this, _scope);
InitialContext ic = new InitialContext();
NameParser parser = ic.getNameParser("");
Name prefix = NamingEntryUtil.getNameForScope(_scope);
//bind the NamingEntry into the context
Name namingEntryName = NamingEntryUtil.makeNamingEntryName(parser, getJndiName());
namingEntryName.addAll(0, prefix);
_namingEntryNameString = namingEntryName.toString();
NamingUtil.bind(ic, _namingEntryNameString, this);
//bind the object as well
Name objectName = parser.parse(getJndiName());
objectName.addAll(0, prefix);
_objectNameString = objectName.toString();
NamingUtil.bind(ic, _objectNameString, object);
}
use of javax.naming.Name in project jetty.project by eclipse.
the class NamingEntryUtil method getNameForScope.
public static Name getNameForScope(Object scope) {
try {
InitialContext ic = new InitialContext();
NameParser parser = ic.getNameParser("");
Name name = parser.parse("");
if (scope != null) {
name.add(canonicalizeScope(scope));
}
return name;
} catch (NamingException e) {
__log.warn(e);
return null;
}
}
use of javax.naming.Name in project jetty.project by eclipse.
the class NamingEntryUtil method lookupNamingEntry.
/**
* Find a NamingEntry in the given scope.
*
* @param scope the object scope
* @param jndiName the jndi name
* @return the naming entry for the given scope
* @throws NamingException if unable to lookup naming entry
*/
public static NamingEntry lookupNamingEntry(Object scope, String jndiName) throws NamingException {
NamingEntry entry = null;
try {
Name scopeName = getNameForScope(scope);
InitialContext ic = new InitialContext();
NameParser parser = ic.getNameParser("");
Name namingEntryName = makeNamingEntryName(parser, jndiName);
scopeName.addAll(namingEntryName);
entry = (NamingEntry) ic.lookup(scopeName);
} catch (NameNotFoundException ee) {
}
return entry;
}
use of javax.naming.Name in project jetty.project by eclipse.
the class NamingEntryUtil method lookup.
public static Object lookup(Object scope, String jndiName) throws NamingException {
Name scopeName = getNameForScope(scope);
InitialContext ic = new InitialContext();
NameParser parser = ic.getNameParser("");
scopeName.addAll(parser.parse(jndiName));
return ic.lookup(scopeName);
}
use of javax.naming.Name in project jetty.project by eclipse.
the class NamingEntryUtil method makeNamingEntryName.
public static Name makeNamingEntryName(NameParser parser, String jndiName) throws NamingException {
if (jndiName == null)
return null;
if (parser == null) {
InitialContext ic = new InitialContext();
parser = ic.getNameParser("");
}
Name name = parser.parse("");
name.add(NamingEntry.__contextName);
name.addAll(parser.parse(jndiName));
return name;
}
Aggregations