Exemplo n.º 1
0
  /**
   * Creates an object for the given URL scheme id using the supplied urlInfo.
   *
   * <p>If urlInfo is null, the result is a context for resolving URLs with the scheme id 'scheme'.
   * If urlInfo is a URL, the result is a context named by the URL. Names passed to this context is
   * assumed to be relative to this context (i.e. not a URL). For example, if urlInfo is
   * "ldap://ldap.wiz.com/o=Wiz,c=us", the resulting context will be that pointed to by "o=Wiz,c=us"
   * on the server 'ldap.wiz.com'. Subsequent names that can be passed to this context will be LDAP
   * names relative to this context (e.g. cn="Barbs Jensen"). If urlInfo is an array of URLs, the
   * URLs are assumed to be equivalent in terms of the context to which they refer. The resulting
   * context is like that of the single URL case. If urlInfo is of any other type, that is handled
   * by the context factory for the URL scheme.
   *
   * @param scheme the URL scheme id for the context
   * @param urlInfo information used to create the context
   * @param name name of this object relative to <code>nameCtx</code>
   * @param nameCtx Context whose provider resource file will be searched for package prefix values
   *     (or null if none)
   * @param environment Environment properties for creating the context
   * @see javax.naming.InitialContext
   */
  private static Object getURLObject(
      String scheme, Object urlInfo, Name name, Context nameCtx, Hashtable<?, ?> environment)
      throws NamingException {

    // e.g. "ftpURLContextFactory"
    ObjectFactory factory =
        (ObjectFactory)
            ResourceManager.getFactory(
                Context.URL_PKG_PREFIXES,
                environment,
                nameCtx,
                "." + scheme + "." + scheme + "URLContextFactory",
                defaultPkgPrefix);

    if (factory == null) return null;

    // Found object factory
    try {
      return factory.getObjectInstance(urlInfo, name, nameCtx, environment);
    } catch (NamingException e) {
      throw e;
    } catch (Exception e) {
      NamingException ne = new NamingException();
      ne.setRootCause(e);
      throw ne;
    }
  }
Exemplo n.º 2
0
  /**
   * Creates an object using the factories specified in the <tt>Context.OBJECT_FACTORIES</tt>
   * property of the environment or of the provider resource file associated with <tt>nameCtx</tt>.
   *
   * @return factory created; null if cannot create
   */
  private static Object createObjectFromFactories(
      Object obj, Name name, Context nameCtx, Hashtable<?, ?> environment) throws Exception {

    FactoryEnumeration factories =
        ResourceManager.getFactories(Context.OBJECT_FACTORIES, environment, nameCtx);

    if (factories == null) return null;

    // Try each factory until one succeeds
    ObjectFactory factory;
    Object answer = null;
    while (answer == null && factories.hasMore()) {
      factory = (ObjectFactory) factories.next();
      answer = factory.getObjectInstance(obj, name, nameCtx, environment);
    }
    return answer;
  }
Exemplo n.º 3
0
  /**
   * Retrieves the state of an object for binding.
   *
   * <p>Service providers that implement the <tt>DirContext</tt> interface should use
   * <tt>DirectoryManager.getStateToBind()</tt>, not this method. Service providers that implement
   * only the <tt>Context</tt> interface should use this method.
   *
   * <p>This method uses the specified state factories in the <tt>Context.STATE_FACTORIES</tt>
   * property from the environment properties, and from the provider resource file associated with
   * <tt>nameCtx</tt>, in that order. The value of this property is a colon-separated list of
   * factory class names that are tried in order, and the first one that succeeds in returning the
   * object's state is the one used. If no object's state can be retrieved in this way, return the
   * object itself. If an exception is encountered while retrieving the state, the exception is
   * passed up to the caller.
   *
   * <p>Note that a state factory (an object that implements the StateFactory interface) must be
   * public and must have a public constructor that accepts no arguments.
   *
   * <p>The <code>name</code> and <code>nameCtx</code> parameters may optionally be used to specify
   * the name of the object being created. See the description of "Name and Context Parameters" in
   * {@link ObjectFactory#getObjectInstance ObjectFactory.getObjectInstance()} for details.
   *
   * <p>This method may return a <tt>Referenceable</tt> object. The service provider obtaining this
   * object may choose to store it directly, or to extract its reference (using
   * <tt>Referenceable.getReference()</tt>) and store that instead.
   *
   * @param obj The non-null object for which to get state to bind.
   * @param name The name of this object relative to <code>nameCtx</code>, or null if no name is
   *     specified.
   * @param nameCtx The context relative to which the <code>name</code> parameter is specified, or
   *     null if <code>name</code> is relative to the default initial context.
   * @param environment The possibly null environment to be used in the creation of the state
   *     factory and the object's state.
   * @return The non-null object representing <tt>obj</tt>'s state for binding. It could be the
   *     object (<tt>obj</tt>) itself.
   * @exception NamingException If one of the factories accessed throws an exception, or if an error
   *     was encountered while loading and instantiating the factory and object classes. A factory
   *     should only throw an exception if it does not want other factories to be used in an attempt
   *     to create an object. See <tt>StateFactory.getStateToBind()</tt>.
   * @see StateFactory
   * @see StateFactory#getStateToBind
   * @see DirectoryManager#getStateToBind
   * @since 1.3
   */
  public static Object getStateToBind(
      Object obj, Name name, Context nameCtx, Hashtable<?, ?> environment) throws NamingException {

    FactoryEnumeration factories =
        ResourceManager.getFactories(Context.STATE_FACTORIES, environment, nameCtx);

    if (factories == null) {
      return obj;
    }

    // Try each factory until one succeeds
    StateFactory factory;
    Object answer = null;
    while (answer == null && factories.hasMore()) {
      factory = (StateFactory) factories.next();
      answer = factory.getStateToBind(obj, name, nameCtx, environment);
    }

    return (answer != null) ? answer : obj;
  }
 /*     */ public static Control getControlInstance(
     Control paramControl, Context paramContext, Hashtable<?, ?> paramHashtable)
     /*     */ throws NamingException
       /*     */ {
   /* 140 */ FactoryEnumeration localFactoryEnumeration =
       ResourceManager.getFactories("java.naming.factory.control", paramHashtable, paramContext);
   /*     */
   /* 143 */ if (localFactoryEnumeration == null) {
     /* 144 */ return paramControl;
     /*     */ }
   /*     */
   /* 148 */ Control localControl = null;
   /*     */
   /* 150 */ while ((localControl == null) && (localFactoryEnumeration.hasMore())) {
     /* 151 */ ControlFactory localControlFactory =
         (ControlFactory) localFactoryEnumeration.next();
     /* 152 */ localControl = localControlFactory.getControlInstance(paramControl);
     /*     */ }
   /*     */
   /* 155 */ return localControl != null ? localControl : paramControl;
   /*     */ }