Java 类javax.naming.spi.DirStateFactory.Result 实例源码

项目:cn1    文件:DirectoryManager.java   
/**
 * Get the state of an Object. Returns a <code>DirStateFactory</code>.
 * Result which cannot be null. It contains the attributes and object to be
 * bound, either of which may be null. Once returned the caller is the owner
 * of it. The behaviour is like that for the <code>getStateToBind</code>
 * method of <code>NamingManager</code> however it should be noted that
 * the intermediate state factory may be of type
 * <code>DirStateFactory</code> rather than just <code>StateFactory</code>
 * in which case it should also use the supplied <code>Attributes</code>
 * when getting the state.
 * 
 * @param o
 *            An object which may provide reference or location information.
 *            May be null.
 * @param n
 *            The name of the <code>Object</code> relative to the default
 *            initial context (or relative to the Context c if it is
 *            supplied)
 * @param c
 *            The <code>Context</code> to which the <code>Name</code> is
 *            relative
 * @param h
 *            a <code>Hashtable</code> containing environment properties
 *            and values - may be null
 * @param a
 *            <code>Attributes</code> - if some or all of the attributes
 *            of <code>Object o</code> are already known they can be
 *            supplied so that the factory does not have to do the work of
 *            looking them up.
 * @return the state of the object
 * @throws NamingException
 *             if one is encountered
 */
public static DirStateFactory.Result getStateToBind(Object o, Name n,
        Context c, Hashtable<?, ?> h, Attributes a) throws NamingException {

    // obtain state factories from hashtable and service provider resource
    // file
    String fnames[] = EnvironmentReader
            .getFactoryNamesFromEnvironmentAndProviderResource(h, c,
                    Context.STATE_FACTORIES);

    for (String element : fnames) {
        // new factory instance by its class name
        StateFactory factory = null;
        try {
            factory = (StateFactory) classForName(element).newInstance();
        } catch (Exception e) {
            continue;
        }
        if (factory instanceof DirStateFactory) {
            // try obtain state using the DirStateFactory
            Result r = ((DirStateFactory) factory).getStateToBind(o, n, c,
                    h, a);
            // if the result is not null, return it
            if (null != r) {
                return r;
            }
        } else {
            // try obtain state using the StateFactory
            Object state = factory.getStateToBind(o, n, c, h);
            // if a state obtained successfully, return it
            if (null != state) {
                return new Result(state, a);
            }
        }
    }

    // all factories failed, return the input argument o
    return new Result(o, a);
}
项目:nextop-client    文件:DirectoryManager.java   
/**
 * Get the state of an Object. Returns a <code>DirStateFactory</code>.
 * Result which cannot be null. It contains the attributes and object to be
 * bound, either of which may be null. Once returned the caller is the owner
 * of it. The behaviour is like that for the <code>getStateToBind</code>
 * method of <code>NamingManager</code> however it should be noted that
 * the intermediate state factory may be of type
 * <code>DirStateFactory</code> rather than just <code>StateFactory</code>
 * in which case it should also use the supplied <code>Attributes</code>
 * when getting the state.
 * 
 * @param o
 *            An object which may provide reference or location information.
 *            May be null.
 * @param n
 *            The name of the <code>Object</code> relative to the default
 *            initial context (or relative to the Context c if it is
 *            supplied)
 * @param c
 *            The <code>Context</code> to which the <code>Name</code> is
 *            relative
 * @param h
 *            a <code>Hashtable</code> containing environment properties
 *            and values - may be null
 * @param a
 *            <code>Attributes</code> - if some or all of the attributes
 *            of <code>Object o</code> are already known they can be
 *            supplied so that the factory does not have to do the work of
 *            looking them up.
 * @return the state of the object
 * @throws NamingException
 *             if one is encountered
 */
public static Result getStateToBind(Object o, Name n,
        Context c, Hashtable<?, ?> h, Attributes a) throws NamingException {

    // obtain state factories from hashtable and service provider resource
    // file
    String fnames[] = EnvironmentReader
            .getFactoryNamesFromEnvironmentAndProviderResource(h, c,
                    Context.STATE_FACTORIES);

    for (String element : fnames) {
        // new factory instance by its class name
        StateFactory factory = null;
        try {
            factory = (StateFactory) classForName(element).newInstance();
        } catch (Exception e) {
            continue;
        }
        if (factory instanceof DirStateFactory) {
            // try obtain state using the DirStateFactory
            Result r = ((DirStateFactory) factory).getStateToBind(o, n, c,
                    h, a);
            // if the result is not null, return it
            if (null != r) {
                return r;
            }
        } else {
            // try obtain state using the StateFactory
            Object state = factory.getStateToBind(o, n, c, h);
            // if a state obtained successfully, return it
            if (null != state) {
                return new Result(state, a);
            }
        }
    }

    // all factories failed, return the input argument o
    return new Result(o, a);
}
项目:freeVM    文件:DirectoryManager.java   
/**
 * Get the state of an Object. Returns a <code>DirStateFactory</code>.
 * Result which cannot be null. It contains the attributes and object to be
 * bound, either of which may be null. Once returned the caller is the owner
 * of it. The behaviour is like that for the <code>getStateToBind</code>
 * method of <code>NamingManager</code> however it should be noted that
 * the intermediate state factory may be of type
 * <code>DirStateFactory</code> rather than just <code>StateFactory</code>
 * in which case it should also use the supplied <code>Attributes</code>
 * when getting the state.
 * 
 * @param o
 *            An object which may provide reference or location information.
 *            May be null.
 * @param n
 *            The name of the <code>Object</code> relative to the default
 *            initial context (or relative to the Context c if it is
 *            supplied)
 * @param c
 *            The <code>Context</code> to which the <code>Name</code> is
 *            relative
 * @param h
 *            a <code>Hashtable</code> containing environment properties
 *            and values - may be null
 * @param a
 *            <code>Attributes</code> - if some or all of the attributes
 *            of <code>Object o</code> are already known they can be
 *            supplied so that the factory does not have to do the work of
 *            looking them up.
 * @return the state of the object
 * @throws NamingException
 *             if one is encountered
 */
public static DirStateFactory.Result getStateToBind(Object o, Name n,
        Context c, Hashtable<?, ?> h, Attributes a) throws NamingException {

    // obtain state factories from hashtable and service provider resource
    // file
    String fnames[] = EnvironmentReader
            .getFactoryNamesFromEnvironmentAndProviderResource(h, c,
                    Context.STATE_FACTORIES);

    for (String element : fnames) {
        // new factory instance by its class name
        StateFactory factory = null;
        try {
            factory = (StateFactory) classForName(element).newInstance();
        } catch (Exception e) {
            continue;
        }
        if (factory instanceof DirStateFactory) {
            // try obtain state using the DirStateFactory
            Result r = ((DirStateFactory) factory).getStateToBind(o, n, c,
                    h, a);
            // if the result is not null, return it
            if (null != r) {
                return r;
            }
        } else {
            // try obtain state using the StateFactory
            Object state = factory.getStateToBind(o, n, c, h);
            // if a state obtained successfully, return it
            if (null != state) {
                return new Result(state, a);
            }
        }
    }

    // all factories failed, return the input argument o
    return new Result(o, a);
}
项目:cn1    文件:LdapContextImpl.java   
public void bind(Name name, Object obj, Attributes attributes)
        throws NamingException {
    checkName(name);

    if (hasMultiNamingSpace(name)) {
        /*
         * multi ns, find next ns context, delegate operation to the next
         * contex
         */
        DirContext nns = (DirContext) findNnsContext(name);
        Name remainingName = name.getSuffix(1);
        nns.bind(remainingName, attributes);
        return;
    }

    /*
     * there is only one ldap ns
     */
    if (obj == null && attributes == null) {
        // ldap.2E=cannot bind null object without attributes
        throw new IllegalArgumentException(Messages.getString("ldap.2E")); //$NON-NLS-1$
    }

    if (obj == null) {
        createSubcontext(name, attributes);
        return;
    }

    Result result = DirectoryManager.getStateToBind(obj, name, this, env,
            attributes);
    Object o = result.getObject();

    Attributes attrs = null;

    if (o instanceof Reference) {
        attrs = convertRefToAttribute((Reference) o);
    } else if (o instanceof Referenceable) {
        attrs = convertRefToAttribute(((Referenceable) o).getReference());
    } else if (o instanceof Serializable) {
        attrs = convertSerialToAttribute((Serializable) o);
    } else if (o instanceof DirContext) {
        DirContext cxt = (DirContext) o;
        attrs = cxt.getAttributes("");
    } else {
        throw new IllegalArgumentException(Messages.getString("ldap.24")); //$NON-NLS-1$
    }

    NamingEnumeration<? extends Attribute> enu = attrs.getAll();
    if (result.getAttributes() != null) {
        Attributes resultAttributes = result.getAttributes();

        while (enu.hasMore()) {
            Attribute element = enu.next();
            if (element.getID().equalsIgnoreCase("objectClass")) {
                element = mergeAttribute(resultAttributes
                        .get("objectClass"), element);
                Attribute oc = resultAttributes.get("objectClass");
                if (oc != null) {
                    if (!oc.contains("javaContainer") && oc.size() > 0) {
                        element.remove("javaContainer");
                    }
                }
                resultAttributes.put(element);
            } else if (resultAttributes.get(element.getID()) == null) {
                resultAttributes.put(element);
            }
        }

        createSubcontext(name, resultAttributes);
    } else {
        createSubcontext(name, attrs);
    }
}
项目:nextop-client    文件:LdapContextImpl.java   
public void bind(Name name, Object obj, Attributes attributes)
        throws NamingException {
    checkName(name);

    if (hasMultiNamingSpace(name)) {
        /*
         * multi ns, find next ns context, delegate operation to the next
         * contex
         */
        DirContext nns = (DirContext) findNnsContext(name);
        Name remainingName = name.getSuffix(1);
        nns.bind(remainingName, attributes);
        return;
    }

    /*
     * there is only one ldap ns
     */
    if (obj == null && attributes == null) {
        // ldap.2E=cannot bind null object without attributes
        throw new IllegalArgumentException(Messages.getString("ldap.2E")); //$NON-NLS-1$
    }

    if (obj == null) {
        createSubcontext(name, attributes);
        return;
    }

    Result result = DirectoryManager.getStateToBind(obj, name, this, env,
            attributes);
    Object o = result.getObject();

    Attributes attrs = null;

    if (o instanceof Reference) {
        attrs = convertRefToAttribute((Reference) o);
    } else if (o instanceof Referenceable) {
        attrs = convertRefToAttribute(((Referenceable) o).getReference());
    } else if (o instanceof Serializable) {
        attrs = convertSerialToAttribute((Serializable) o);
    } else if (o instanceof DirContext) {
        DirContext cxt = (DirContext) o;
        attrs = cxt.getAttributes("");
    } else {
        throw new IllegalArgumentException(Messages.getString("ldap.24")); //$NON-NLS-1$
    }

    NamingEnumeration<? extends Attribute> enu = attrs.getAll();
    if (result.getAttributes() != null) {
        Attributes resultAttributes = result.getAttributes();

        while (enu.hasMore()) {
            Attribute element = enu.next();
            if (element.getID().equalsIgnoreCase("objectClass")) {
                element = mergeAttribute(resultAttributes
                        .get("objectClass"), element);
                Attribute oc = resultAttributes.get("objectClass");
                if (oc != null) {
                    if (!oc.contains("javaContainer") && oc.size() > 0) {
                        element.remove("javaContainer");
                    }
                }
                resultAttributes.put(element);
            } else if (resultAttributes.get(element.getID()) == null) {
                resultAttributes.put(element);
            }
        }

        createSubcontext(name, resultAttributes);
    } else {
        createSubcontext(name, attrs);
    }
}
项目:freeVM    文件:DirectoryManager.java   
/**
 * Get the state of an Object.
 * Returns a <code>DirStateFactory</code>. Result which cannot be null. It
 * contains the attributes and object to be bound, either of which may be
 * null. Once returned the caller is the owner of it.
 * The behaviour is like that for the <code>getStateToBind</code> method of
 * <code>NamingManager</code> however it should be noted that the
 * intermediate state factory may be of type <code>DirStateFactory</code>
 * rather than just <code>StateFactory</code> in which case it should also
 * use the supplied <code>Attributes</code> when getting the state.
 *
 * @param o An object which may provide reference or location information.
 *          May be null.
 * @param n The name of the <code>Object</code> relative to the default
 *          initial context (or relative to the Context c if it is supplied)
 * @param c The <code>Context</code> to which the <code>Name</code> is
 *          relative
 * @param h a <code>Hashtable</code> containing environment properties and
 *          values - may be null
 * @param a <code>Attributes</code> - if some or all of the attributes of
 *          <code>Object o</code> are already known they can be supplied so
 *          that the factory does not have to do the work of looking them up.
 * @return  the state of the object
 * @throws NamingException if one is encountered
 */
public static DirStateFactory.Result getStateToBind(
    Object o,
    Name n,
    Context c,
    Hashtable<?, ?> h,
    Attributes a)
    throws NamingException {

    // obtain state factories from hashtable and service provider resource file
    String fnames[] =
        EnvironmentReader.getFactoryNamesFromEnvironmentAndProviderResource(
            h,
            c,
            Context.STATE_FACTORIES);

    for (String element : fnames) {
        // new factory instance by its class name
        StateFactory factory = null;
        try {
            factory = (StateFactory) classForName(element).newInstance();
        } catch (Exception e) {
            continue;
        }
        if (factory instanceof DirStateFactory) {
            // try obtain state using the DirStateFactory
            Result r = ((DirStateFactory) factory).getStateToBind(o, n, c, h, a);
            // if the result is not null, return it
            if (null != r) {
                return r;
            }
        } else {
            // try obtain state using the StateFactory
            Object state = factory.getStateToBind(o, n, c, h);
            // if a state obtained successfully, return it
            if (null != state) {
                return new Result(state, a);
            }
        }
    }

    // all factories failed, return the input argument o
    return new Result(o, a);
}
项目:freeVM    文件:LdapContextImpl.java   
public void bind(Name name, Object obj, Attributes attributes)
        throws NamingException {
    checkName(name);

    if (hasMultiNamingSpace(name)) {
        /*
         * multi ns, find next ns context, delegate operation to the next
         * contex
         */
        DirContext nns = (DirContext) findNnsContext(name);
        Name remainingName = name.getSuffix(1);
        nns.bind(remainingName, attributes);
        return;
    }

    /*
     * there is only one ldap ns
     */
    if (obj == null && attributes == null) {
        // ldap.2E=cannot bind null object without attributes
        throw new IllegalArgumentException(Messages.getString("ldap.2E")); //$NON-NLS-1$
    }

    if (obj == null) {
        createSubcontext(name, attributes);
        return;
    }

    Result result = DirectoryManager.getStateToBind(obj, name, this, env,
            attributes);
    Object o = result.getObject();

    Attributes attrs = null;

    if (o instanceof Reference) {
        attrs = convertRefToAttribute((Reference) o);
    } else if (o instanceof Referenceable) {
        attrs = convertRefToAttribute(((Referenceable) o).getReference());
    } else if (o instanceof Serializable) {
        attrs = convertSerialToAttribute((Serializable) o);
    } else if (o instanceof DirContext) {
        DirContext cxt = (DirContext) o;
        attrs = cxt.getAttributes("");
    } else {
        throw new IllegalArgumentException(Messages.getString("ldap.24")); //$NON-NLS-1$
    }

    NamingEnumeration<? extends Attribute> enu = attrs.getAll();
    if (result.getAttributes() != null) {
        Attributes resultAttributes = result.getAttributes();

        while (enu.hasMore()) {
            Attribute element = enu.next();
            if (element.getID().equalsIgnoreCase("objectClass")) {
                element = mergeAttribute(resultAttributes
                        .get("objectClass"), element);
                Attribute oc = resultAttributes.get("objectClass");
                if (oc != null) {
                    if (!oc.contains("javaContainer") && oc.size() > 0) {
                        element.remove("javaContainer");
                    }
                }
                resultAttributes.put(element);
            } else if (resultAttributes.get(element.getID()) == null) {
                resultAttributes.put(element);
            }
        }

        createSubcontext(name, resultAttributes);
    } else {
        createSubcontext(name, attrs);
    }
}