示例#1
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;
  }
示例#2
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;
   /*     */ }