Search in sources :

Example 76 with NameNotFoundException

use of javax.naming.NameNotFoundException in project Payara by payara.

the class FileDirContext method unbind.

/**
 * Unbinds the named object. Removes the terminal atomic name in name
 * from the target context--that named by all but the terminal atomic
 * part of name.
 * <p>
 * This method is idempotent. It succeeds even if the terminal atomic
 * name is not bound in the target context, but throws
 * NameNotFoundException if any of the intermediate contexts do not exist.
 *
 * @param name the name to bind; may not be empty
 * @exception NameNotFoundException if an intermediate context does not
 * exist
 * @exception NamingException if a naming exception is encountered
 */
public void unbind(String name) throws NamingException {
    File file = file(name, true);
    if (file == null)
        throw new NameNotFoundException(MessageFormat.format(rb.getString(LogFacade.RESOURCES_NOT_FOUND), name));
    // START S1AS8PE 4965170
    fileCache.remove(name);
    // END S1AS8PE 4965170
    if (!file.delete())
        throw new NamingException(MessageFormat.format(rb.getString(LogFacade.RESOURCES_NOT_FOUND), name));
}
Also used : NameNotFoundException(javax.naming.NameNotFoundException) NamingException(javax.naming.NamingException) File(java.io.File)

Example 77 with NameNotFoundException

use of javax.naming.NameNotFoundException in project Payara by payara.

the class GlassfishNamingManagerImpl method createSubContexts.

/**
 * Create any sub-contexts in name that don't already exist.
 *
 * @param name    Name containing sub-contexts to create
 * @param rootCtx in which sub-contexts should be created
 * @throws Exception
 */
private void createSubContexts(Name name, Context rootCtx) throws NamingException {
    int numSubContexts = name.size() - 1;
    Context currentCtx = rootCtx;
    for (int subCtxIndex = 0; subCtxIndex < numSubContexts; subCtxIndex++) {
        String subCtxName = name.get(subCtxIndex);
        try {
            Object obj = currentCtx.lookup(subCtxName);
            if (obj == null) {
                // Doesn't exist so create it.
                currentCtx = currentCtx.createSubcontext(subCtxName);
            } else if (obj instanceof Context) {
                // OK -- no need to create it.
                currentCtx = (Context) obj;
            } else {
                // Context name clashes with existing object.
                throw new NameAlreadyBoundException(subCtxName);
            }
        } catch (NameNotFoundException e) {
            // Doesn't exist so create it.
            currentCtx = currentCtx.createSubcontext(subCtxName);
        }
    }
// End for -- each sub-context
}
Also used : Context(javax.naming.Context) InitialContext(javax.naming.InitialContext) NameAlreadyBoundException(javax.naming.NameAlreadyBoundException) NameNotFoundException(javax.naming.NameNotFoundException)

Example 78 with NameNotFoundException

use of javax.naming.NameNotFoundException in project Payara by payara.

the class GlassfishNamingManagerImpl method lookup.

private Object lookup(String componentId, String name, Context ctx) throws NamingException {
    ComponentIdInfo info = componentIdInfo.get(componentId);
    String logicalJndiName = name;
    boolean replaceName = (info != null) && (info.treatComponentAsModule) && name.startsWith("java:comp");
    if (replaceName) {
        logicalJndiName = logicalCompJndiNameToModule(name);
    }
    Map namespace = getNamespace(componentId, logicalJndiName);
    Object obj = namespace.get(logicalJndiName);
    if (obj == null) {
        throw new NameNotFoundException("No object bound to name " + name);
    }
    if (obj instanceof NamingObjectProxy) {
        NamingObjectProxy namingProxy = (NamingObjectProxy) obj;
        obj = namingProxy.create(ctx);
    } else if (obj instanceof Context) {
        // and return that.
        if (replaceName) {
            obj = new JavaURLContext(name, null);
        }
        if (obj instanceof JavaURLContext) {
            if (ctx instanceof SerialContext) {
                obj = new JavaURLContext((JavaURLContext) obj, (SerialContext) ctx);
            } else {
                obj = new JavaURLContext((JavaURLContext) obj, null);
            }
        }
    }
    return obj;
}
Also used : Context(javax.naming.Context) InitialContext(javax.naming.InitialContext) NamingObjectProxy(org.glassfish.api.naming.NamingObjectProxy) NameNotFoundException(javax.naming.NameNotFoundException) HashMap(java.util.HashMap) Map(java.util.Map)

Example 79 with NameNotFoundException

use of javax.naming.NameNotFoundException in project Payara by payara.

the class GlassfishNamingManagerImpl method listNames.

private ArrayList listNames(String name) throws NamingException {
    // Get the component id and namespace to lookup
    String componentId = getComponentId();
    ComponentIdInfo info = componentIdInfo.get(componentId);
    String logicalJndiName = name;
    boolean replaceName = (info != null) && (info.treatComponentAsModule) && name.startsWith("java:comp");
    if (replaceName) {
        logicalJndiName = logicalCompJndiNameToModule(name);
    }
    Map namespace = getNamespace(componentId, logicalJndiName);
    Object obj = namespace.get(logicalJndiName);
    if (obj == null) {
        throw new NameNotFoundException("No object bound to name " + name);
    }
    if (!(obj instanceof JavaURLContext)) {
        throw new NotContextException(name + " cannot be listed");
    }
    // This iterates over all names in entire component namespace,
    // so its a little inefficient. The alternative is to store
    // a list of bindings in each javaURLContext instance.
    ArrayList list = new ArrayList();
    Iterator itr = namespace.keySet().iterator();
    if (!logicalJndiName.endsWith("/")) {
        logicalJndiName = logicalJndiName + "/";
    }
    while (itr.hasNext()) {
        String key = (String) itr.next();
        // The search string itself is excluded from the returned list
        if (key.startsWith(logicalJndiName) && key.indexOf('/', logicalJndiName.length()) == -1 && !key.equals(logicalJndiName)) {
            String toAdd = replaceName ? logicalModuleJndiNameToComp(key) : key;
            list.add(toAdd);
        }
    }
    return list;
}
Also used : NotContextException(javax.naming.NotContextException) NameNotFoundException(javax.naming.NameNotFoundException) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) HashMap(java.util.HashMap) Map(java.util.Map)

Example 80 with NameNotFoundException

use of javax.naming.NameNotFoundException in project cayenne by apache.

the class JMSBridge method startupExternal.

/**
 * Starts up JMS machinery for "publish/subscribe" model.
 */
@Override
protected void startupExternal() throws Exception {
    Context jndiContext = new InitialContext();
    TopicConnectionFactory connectionFactory = (TopicConnectionFactory) jndiContext.lookup(topicConnectionFactoryName);
    Topic topic = null;
    try {
        topic = (Topic) jndiContext.lookup(externalSubject);
    } catch (NameNotFoundException ex) {
        // can't find topic, try to create it
        topic = topicNotFound(jndiContext, ex);
        if (topic == null) {
            throw ex;
        }
    }
    // config publisher
    if (receivesLocalEvents()) {
        this.sendConnection = connectionFactory.createTopicConnection();
        this.sendSession = sendConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
        this.publisher = sendSession.createPublisher(topic);
    }
    // config subscriber
    if (receivesExternalEvents()) {
        this.receivedConnection = connectionFactory.createTopicConnection();
        this.subscriber = receivedConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE).createSubscriber(topic);
        this.subscriber.setMessageListener(this);
        this.receivedConnection.start();
    }
}
Also used : InitialContext(javax.naming.InitialContext) Context(javax.naming.Context) TopicConnectionFactory(javax.jms.TopicConnectionFactory) NameNotFoundException(javax.naming.NameNotFoundException) Topic(javax.jms.Topic) InitialContext(javax.naming.InitialContext)

Aggregations

NameNotFoundException (javax.naming.NameNotFoundException)168 NamingException (javax.naming.NamingException)81 InitialContext (javax.naming.InitialContext)75 Context (javax.naming.Context)71 Reference (javax.naming.Reference)40 Test (org.junit.Test)39 NotContextException (javax.naming.NotContextException)35 Name (javax.naming.Name)34 NameAlreadyBoundException (javax.naming.NameAlreadyBoundException)33 OperationNotSupportedException (javax.naming.OperationNotSupportedException)29 CompositeName (javax.naming.CompositeName)27 Binding (javax.naming.Binding)22 CompoundName (javax.naming.CompoundName)16 LinkRef (javax.naming.LinkRef)16 IOException (java.io.IOException)12 NamingContext (org.eclipse.jetty.jndi.NamingContext)12 ArrayList (java.util.ArrayList)10 InvalidNameException (javax.naming.InvalidNameException)10 Attributes (javax.naming.directory.Attributes)10 HashMap (java.util.HashMap)7