Search in sources :

Example 66 with Name

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);
}
Also used : InitialContext(javax.naming.InitialContext) NameParser(javax.naming.NameParser) Name(javax.naming.Name)

Example 67 with Name

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;
    }
}
Also used : NamingException(javax.naming.NamingException) InitialContext(javax.naming.InitialContext) NameParser(javax.naming.NameParser) Name(javax.naming.Name)

Example 68 with Name

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;
}
Also used : NameNotFoundException(javax.naming.NameNotFoundException) InitialContext(javax.naming.InitialContext) NameParser(javax.naming.NameParser) Name(javax.naming.Name)

Example 69 with Name

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);
}
Also used : InitialContext(javax.naming.InitialContext) NameParser(javax.naming.NameParser) Name(javax.naming.Name)

Example 70 with Name

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;
}
Also used : InitialContext(javax.naming.InitialContext) Name(javax.naming.Name)

Aggregations

Name (javax.naming.Name)107 CompositeName (javax.naming.CompositeName)48 NamingException (javax.naming.NamingException)38 Context (javax.naming.Context)37 InitialContext (javax.naming.InitialContext)36 NameNotFoundException (javax.naming.NameNotFoundException)34 Test (org.junit.Test)32 Reference (javax.naming.Reference)24 NotContextException (javax.naming.NotContextException)22 Binding (javax.naming.Binding)19 CompoundName (javax.naming.CompoundName)19 NameAlreadyBoundException (javax.naming.NameAlreadyBoundException)19 NameParser (javax.naming.NameParser)17 OperationNotSupportedException (javax.naming.OperationNotSupportedException)16 InvalidNameException (javax.naming.InvalidNameException)10 NamingContext (org.eclipse.jetty.jndi.NamingContext)10 IOException (java.io.IOException)8 LinkRef (javax.naming.LinkRef)7 ServiceName (org.jboss.msc.service.ServiceName)7 Referenceable (javax.naming.Referenceable)6