All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.addc.jndi.ecn.ECNBindingEnumeration Maven / Gradle / Ivy

package com.addc.jndi.ecn;

import java.util.Arrays;
import java.util.Hashtable;

import javax.naming.Binding;
import javax.naming.CannotProceedException;
import javax.naming.Name;
import javax.naming.NamingException;
import javax.naming.spi.NamingManager;

import org.omg.CORBA.portable.ObjectImpl;
import org.omg.CosNaming.NamingContext;
import org.omg.CosNaming.NamingContextPackage.CannotProceed;
import org.omg.CosNaming.NamingContextPackage.InvalidName;
import org.omg.CosNaming.NamingContextPackage.NotFound;
import org.omg.CosNaming.NamingContextPackage.NotFoundReason;

/**
 * The ECNBindingEnumeration class supplies a naming enumeration implementation
 * for COS naming that returns javax.naming.Binding instances.
 * 
 */
@SuppressWarnings({ "PMD.LooseCoupling", "PMD.PreserveStackTrace" })
public class ECNBindingEnumeration extends AbstractECNEnum {
    private final NamingContext context;
    private final ECNNameParser parser;

    /**
     * Create a new ECNBindingEnumeration.
     * 
     * @param context
     *            The COS Naming Context to use
     * @param env
     *            The Naming Environment
     * @param parser
     *            The parser to use
     */
    public ECNBindingEnumeration(NamingContext context, Hashtable env, ECNNameParser parser) {
        super(getBatchSize(env), context);
        this.context= context;
        this.parser= parser;
    }

    @Override
    protected Binding mapBinding(org.omg.CosNaming.Binding binding) throws NamingException {
        Object obj= null;
        try {
            obj= context.resolve(binding.binding_name);
        } catch (CannotProceed | InvalidName e) {
            NamingException ne= new NamingException(e.getMessage());
            ne.setRootCause(e);
            throw ne;
        } catch (NotFound e) {
            if (e.why.value() != NotFoundReason._not_object) {
                NamingException ne= new NamingException(e.getMessage());
                ne.setRootCause(e);
                throw ne;
            }
        }
        StringBuilder sb= new StringBuilder("");
        if (obj == null) {
            sb.append("Empty Balanced Group");
        } else {
            try {
                obj= NamingManager.getObjectInstance(obj, null, null, null);
            } catch (Exception e) {
                CannotProceedException ne= new CannotProceedException(e.getMessage());
                ne.setRootCause(e);
                throw ne;
            }
            if (obj instanceof org.omg.CORBA.Object) {
                sb.append(Arrays.asList(((ObjectImpl) obj)._ids()));
            } else {
                sb.append(obj);
            }
        }
        Name name= parser.toName(binding.binding_name);
        return new Binding(name.toString(), sb.toString(), obj);
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy