src/share/classes/javax/naming/spi/DirectoryManager.java

Print this page




  67 
  68 public class DirectoryManager extends NamingManager {
  69 
  70     /*
  71      * Disallow anyone from creating one of these.
  72      */
  73     DirectoryManager() {}
  74 
  75     /**
  76       * Creates a context in which to continue a <tt>DirContext</tt> operation.
  77       * Operates just like <tt>NamingManager.getContinuationContext()</tt>,
  78       * only the continuation context returned is a <tt>DirContext</tt>.
  79       *
  80       * @param cpe
  81       *         The non-null exception that triggered this continuation.
  82       * @return A non-null <tt>DirContext</tt> object for continuing the operation.
  83       * @exception NamingException If a naming exception occurred.
  84       *
  85       * @see NamingManager#getContinuationContext(CannotProceedException)
  86       */

  87     public static DirContext getContinuationDirContext(
  88             CannotProceedException cpe) throws NamingException {
  89 
  90         Hashtable env = cpe.getEnvironment();
  91         if (env == null) {
  92             env = new Hashtable(7);
  93         } else {
  94             // Make a (shallow) copy of the environment.
  95             env = (Hashtable) env.clone();
  96         }
  97         env.put(CPE, cpe);
  98 
  99         return (new ContinuationDirContext(cpe, env));
 100     }
 101 
 102     /**
 103       * Creates an instance of an object for the specified object,
 104       * attributes, and environment.
 105       * <p>
 106       * This method is the same as <tt>NamingManager.getObjectInstance</tt>
 107       * except for the following differences:
 108       *<ul>
 109       *<li>
 110       * It accepts an <tt>Attributes</tt> parameter that contains attributes
 111       * associated with the object. The <tt>DirObjectFactory</tt> might use these
 112       * attributes to save having to look them up from the directory.
 113       *<li>
 114       * The object factories tried must implement either
 115       * <tt>ObjectFactory</tt> or <tt>DirObjectFactory</tt>.


 200 
 201                 } else {
 202                     // if reference has no factory, check for addresses
 203                     // containing URLs
 204                     // ignore name & attrs params; not used in URL factory
 205 
 206                     answer = processURLAddrs(ref, name, nameCtx, environment);
 207                     if (answer != null) {
 208                         return answer;
 209                     }
 210                 }
 211             }
 212 
 213             // try using any specified factories
 214             answer = createObjectFromFactories(refInfo, name, nameCtx,
 215                                                environment, attrs);
 216             return (answer != null) ? answer : refInfo;
 217     }
 218 
 219     private static Object createObjectFromFactories(Object obj, Name name,
 220             Context nameCtx, Hashtable environment, Attributes attrs)
 221         throws Exception {
 222 
 223         FactoryEnumeration factories = ResourceManager.getFactories(
 224             Context.OBJECT_FACTORIES, environment, nameCtx);
 225 
 226         if (factories == null)
 227             return null;
 228 
 229         ObjectFactory factory;
 230         Object answer = null;
 231         // Try each factory until one succeeds
 232         while (answer == null && factories.hasMore()) {
 233             factory = (ObjectFactory)factories.next();
 234             if (factory instanceof DirObjectFactory) {
 235                 answer = ((DirObjectFactory)factory).
 236                     getObjectInstance(obj, name, nameCtx, environment, attrs);
 237             } else {
 238                 answer =
 239                     factory.getObjectInstance(obj, name, nameCtx, environment);
 240             }




  67 
  68 public class DirectoryManager extends NamingManager {
  69 
  70     /*
  71      * Disallow anyone from creating one of these.
  72      */
  73     DirectoryManager() {}
  74 
  75     /**
  76       * Creates a context in which to continue a <tt>DirContext</tt> operation.
  77       * Operates just like <tt>NamingManager.getContinuationContext()</tt>,
  78       * only the continuation context returned is a <tt>DirContext</tt>.
  79       *
  80       * @param cpe
  81       *         The non-null exception that triggered this continuation.
  82       * @return A non-null <tt>DirContext</tt> object for continuing the operation.
  83       * @exception NamingException If a naming exception occurred.
  84       *
  85       * @see NamingManager#getContinuationContext(CannotProceedException)
  86       */
  87     @SuppressWarnings("unchecked")
  88     public static DirContext getContinuationDirContext(
  89             CannotProceedException cpe) throws NamingException {
  90 
  91         Hashtable<Object,Object> env = (Hashtable<Object,Object>)cpe.getEnvironment();
  92         if (env == null) {
  93             env = new Hashtable<>(7);
  94         } else {
  95             // Make a (shallow) copy of the environment.
  96             env = (Hashtable<Object,Object>) env.clone();
  97         }
  98         env.put(CPE, cpe);
  99 
 100         return (new ContinuationDirContext(cpe, env));
 101     }
 102 
 103     /**
 104       * Creates an instance of an object for the specified object,
 105       * attributes, and environment.
 106       * <p>
 107       * This method is the same as <tt>NamingManager.getObjectInstance</tt>
 108       * except for the following differences:
 109       *<ul>
 110       *<li>
 111       * It accepts an <tt>Attributes</tt> parameter that contains attributes
 112       * associated with the object. The <tt>DirObjectFactory</tt> might use these
 113       * attributes to save having to look them up from the directory.
 114       *<li>
 115       * The object factories tried must implement either
 116       * <tt>ObjectFactory</tt> or <tt>DirObjectFactory</tt>.


 201 
 202                 } else {
 203                     // if reference has no factory, check for addresses
 204                     // containing URLs
 205                     // ignore name & attrs params; not used in URL factory
 206 
 207                     answer = processURLAddrs(ref, name, nameCtx, environment);
 208                     if (answer != null) {
 209                         return answer;
 210                     }
 211                 }
 212             }
 213 
 214             // try using any specified factories
 215             answer = createObjectFromFactories(refInfo, name, nameCtx,
 216                                                environment, attrs);
 217             return (answer != null) ? answer : refInfo;
 218     }
 219 
 220     private static Object createObjectFromFactories(Object obj, Name name,
 221             Context nameCtx, Hashtable<?,?> environment, Attributes attrs)
 222         throws Exception {
 223 
 224         FactoryEnumeration factories = ResourceManager.getFactories(
 225             Context.OBJECT_FACTORIES, environment, nameCtx);
 226 
 227         if (factories == null)
 228             return null;
 229 
 230         ObjectFactory factory;
 231         Object answer = null;
 232         // Try each factory until one succeeds
 233         while (answer == null && factories.hasMore()) {
 234             factory = (ObjectFactory)factories.next();
 235             if (factory instanceof DirObjectFactory) {
 236                 answer = ((DirObjectFactory)factory).
 237                     getObjectInstance(obj, name, nameCtx, environment, attrs);
 238             } else {
 239                 answer =
 240                     factory.getObjectInstance(obj, name, nameCtx, environment);
 241             }