Ejemplo n.º 1
0
  /**
   * Lists the bindings of a context or subcontext. The operation is delegated to the serial
   * context.
   *
   * @return an enumeration of the bindings of the context.
   * @throws NamingException if there is a naming exception.
   */
  @Override
  public NamingEnumeration<Binding> listBindings(String name) throws NamingException {
    if (name.equals("")) {
      // listing this context
      if (namingManager == null) throw new NamingException();
      return namingManager.listBindings(myName);
    }

    // Perhaps 'name' names a context
    Object target = lookup(name);
    if (target instanceof Context) {
      return ((Context) target).listBindings("");
    }
    throw new NotContextException(name + " cannot be listed");
  }
Ejemplo n.º 2
0
 /**
  * Return the name parser for the specified name.
  *
  * @return the NameParser instance.
  * @throws NamingException if there is an exception.
  */
 @Override
 public NameParser getNameParser(String name) throws NamingException {
   if (namingManager == null) throw new NamingException();
   return namingManager.getNameParser();
 }
Ejemplo n.º 3
0
  /**
   * Lookup an object in the serial context.
   *
   * @return the object that is being looked up.
   * @throws NamingException if there is a naming exception.
   */
  @Override
  public Object lookup(String name) throws NamingException {
    if (_logger.isLoggable(Level.FINE))
      _logger.log(
          Level.FINE,
          "In javaURLContext.lookup, name = " + name + " serialcontext..." + serialContext);

    if (name.equals("")) {
      /**
       * javadocs for Context.lookup: If name is empty, returns a new instance of this context
       * (which represents the same naming context as this context, but its environment may be
       * modified independently and it may be accessed concurrently).
       */
      return new JavaURLContext(myName, myEnv);
    }

    String fullName = name;
    if (!myName.equals("")) {
      if (myName.equals("java:")) fullName = myName + name;
      else fullName = myName + "/" + name;
    }

    try {
      Object obj = null;
      // If we know for sure it's an entry within an environment namespace
      if (fullName.startsWith("java:comp/env/")
          || fullName.startsWith("java:module/env/")
          || fullName.startsWith("java:app/env/")) {
        // refers to a dependency defined by the application
        obj = namingManager.lookup(fullName, serialContext);
      } else {
        // It's either an application-defined dependency in a java:
        // namespace or a special EE platform object.
        // Check for EE platform objects first to prevent overriding.
        obj = NamedNamingObjectManager.tryNamedProxies(name);
        if (obj == null) {
          // try GlassfishNamingManager
          obj = namingManager.lookup(fullName, serialContext);
        }
      }

      if (obj == null) {
        throw new NamingException("No object found for " + name);
      }

      return obj;
    } catch (NamingException ex) {

      Habitat habitat = Globals.getDefaultHabitat();
      ProcessEnvironment processEnv = habitat.getComponent(ProcessEnvironment.class);
      if (fullName.startsWith("java:app/") && processEnv.getProcessType() == ProcessType.ACC) {

        // This could either be an attempt by an app client to access a portable
        // remote session bean JNDI name via the java:app namespace or a lookup of
        // an application-defined java:app environment dependency.  Try them in
        // that order.

        Context ic = namingManager.getInitialContext();
        String appName = (String) namingManager.getInitialContext().lookup("java:app/AppName");

        Object obj = null;

        if (!fullName.startsWith("java:app/env/")) {
          try {

            // Translate the java:app name into the equivalent java:global name so that
            // the lookup will be resolved by the server.
            String newPrefix = "java:global/" + appName + "/";

            int javaAppLength = "java:app/".length();
            String globalLookup = newPrefix + fullName.substring(javaAppLength);

            obj = ic.lookup(globalLookup);

          } catch (NamingException javaappenvne) {
            _logger.log(Level.FINE, "Trying global version of java:app ejb lookup", javaappenvne);
          }
        }

        if (obj == null) {
          ComponentNamingUtil compNamingUtil = habitat.getByContract(ComponentNamingUtil.class);
          String internalGlobalJavaAppName =
              compNamingUtil.composeInternalGlobalJavaAppName(appName, fullName);

          obj = ic.lookup(internalGlobalJavaAppName);
        }

        if (obj == null) {
          throw new NamingException("No object found for " + name);
        }

        return obj;
      }

      throw ex;
    } catch (Exception ex) {
      throw (NamingException)
          (new NameNotFoundException("No object bound for " + fullName)).initCause(ex);
    }
  }