Sistema de Nombrado en Java (JNDI) y II

El interface DirContext contiene los siguientes m�todos (adem�s de sus sobrecargas de java.lang.String) para recuperar los atributos de un objeto del directorio:

Recuperar los atributos de un objeto es la m�s b�sica de las operaciones de directorio del interface DirContext. La mayor�a de las implementaciones de contexto de directorio soportan estos m�todos.

Observa que getAttributes(name) es s�lo un forma corta de escribir:

getAttributes(name, null);

Por lo tanto sus implementaci�n s�lo deber�a llamar a la forma larga:

public Attributes getAttributes(Name name) throws NamingException {
    return getAttributes(name, null);  // Same as attrIds == null
}

La implementaci�n de getAttributes() depende del modelo de atributo del servicio de directorio subyacente. Una implementaci�n real podr�a necesitar no hacer m�s que pasar el nombre y la petici�n al servicio de directorio subyacente para su proceso.

El ejemplo del directorio con forma de �rbol usa un patr�n similar al de las operaciones de Context del ejemplo del espacio de nombres en forma de �rbol. B�sicamente, primero determina si la petici�n es para este contexto o para un contexto u objeto relativo a este contexto. Si es para este contexto, se devuelve una copia de los atributos del contexto. Si es para un objeto hijo inmediato, se envia una copia de los atributos del objeto. De otro modo, se resuelve el siguiente nombre at�mico a un DirContext y la petici�n se pasa a ese contexto:

public Attributes getAttributes(Name name, String[] attrIds) 
    throws NamingException {
    if (name.isEmpty()) {
        // Ask for the attributes of this context
        return deepClone(myAttrs);
    }
	    
    // Extract the components that belong to this namespace
    Name nm = getMyComponents(name);
    String atom = nm.get(0);
    Object inter = bindings.get(atom);

    if (nm.size() == 1) {
        // Atomic name; find object in the internal data structure
	if (inter == null) {
	    throw new NameNotFoundException(name + " not found");
        }

	if (inter instanceof DirContext) {
	    return ((DirContext)inter).getAttributes("", attrIds);
	} else {
	    // Fetch the object's attributes from this context
	    Attributes attrs = (Attributes) bindingAttrs.get(atom);
	    if (attrs == null) {
		return new BasicAttributes();
	    } else {
		return deepClone(attrs);
	    }
	}
    } else {
	// Intermediate name; consume the name in this context 
	// and then continue
	if (!(inter instanceof DirContext)) {
	    throw new NotContextException(atom + " does not name a dircontext");
	}
	return ((DirContext)inter).getAttributes(nm.getSuffix(1), attrIds);
    }
}

COMPARTE ESTE ARTÍCULO

COMPARTIR EN FACEBOOK
COMPARTIR EN TWITTER
COMPARTIR EN LINKEDIN
COMPARTIR EN WHATSAPP
ARTÍCULO ANTERIOR