En esta página: Construir en Extensibilidad La lección Los Componentes Esenciales mostró como usar las utilidades JNDI para hacer extensible una implementación de contexto. Cuando estemos construyendo una implementación de contexto de directorio, deberíamos reemplazar aquellas utilidades con las descritas aquí. Leer Objetos Una implementación de contexto de directorio debería usar DirectoryManager.getObjectInstance() antes de devolver un objeto al programa de usuario desde uno de los siguientes métodos: Aquí tenemos como el ejemplo del directorio en forma de árbol llama a getObjectInstance() en su método lookup(): // Code that determine "inter" is the object bound to the // atomic name "atom" ... // Get the object's attributes Attributes attrs; if (inter instanceof DirContext) { attrs = ((DirContext)inter).getAttributes(""); } else { // Fetch the object's attributes from this context attrs = (Attributes) bindingAttrs.get(atom); } // Call getObjectInstance() for using any object factories try { return DirectoryManager.getObjectInstance(inter, new CompositeName().add(atom), this, myEnv, attrs); } catch (Exception e) { NamingException ne = new NamingException("getObjectInstance failed"); ne.setRootCause(e); throw ne; } De forma similar, cuando se devuelve una enumeración generada por Context.listBindings() o las sobrecargas de DirContext.search(), deberíamos llamar a getObjectInstance() para el objeto de cada Binding o SearchResult de la enumeración. Aquí está la definición del método next() de la enumeración: public Object next() throws NamingException { String name = (String)names.nextElement(); Object obj = bindings.get(name); try { // Get the attributes Attributes attrs; if (obj instanceof DirContext) { attrs = ((DirContext)obj).getAttributes(""); } else { // Fetch the object's attributes from this context attrs = (Attributes) bindingAttrs.get(name); } obj = DirectoryManager.getObjectInstance( obj, new CompositeName().add(name), HierDirCtx.this, HierDirCtx.this.myEnv, attrs); } catch (Exception e) { NamingException ne = new NamingException("getObjectInstance failed"); ne.setRootCause(e); throw ne; } return new Binding(name, obj); } Almacenar Objetos Una implementación de contexto de directorio debería usar DirectoryManager.getStateToBind() antes de almacenar un objeto dado por el programa de usuario mediante uno de estos métodos: Aquí tenemos cómo el ejemplo del directorio en forma de árbol llama a getStateToBind() en sus métodos bind() y rebind(): // Code that determined that this is the context in which // to bind the atomic name "atom" to the object "obj" ... // Call getStateToBind for using any state factories DirStateFactory.Result res = DirectoryManager.getStateToBind( obj, new CompositeName().add(atom), this, myEnv, attrs); // Add the object to the internal data structure bindings.put(atom, res.getObject()); // Add the attributes if (res.getAttributes() != null) { bindingAttrs.put(atom, deepClone(res.getAttributes())); } DirectoryManager.getStateToBind() devuelve un ejemplar de DirStateFactory.Result, que es un paquete que consiste en el objeto a unir y los atributos asociados con el objeto. Después de recibir el resultado, la implementación de contexto actualiza sus tablas de uniones y de atributos internas.
|