public void add_profiles()

in yoko-core/src/main/java/org/apache/yoko/orb/OCI/IIOP/Acceptor_impl.java [221:379]


    public void add_profiles(org.apache.yoko.orb.OCI.ProfileInfo profileInfo,
            org.apache.yoko.orb.OBPortableServer.POAPolicies policies, 
            org.omg.IOP.IORHolder ior) {
        if (port_ == 0)
            throw new RuntimeException();

        //
        // Filter components according to IIOP version
        //
        java.util.Vector components = new java.util.Vector();
        if (profileInfo.major == 1 && profileInfo.minor == 0) {
            //
            // No components for IIOP 1.0
            //
        } else {
            for (int i = 0; i < profileInfo.components.length; i++)
                components.addElement(profileInfo.components[i]);
        }

        if (profileInfo.major == 1 && profileInfo.minor == 0) {
            //
            // For IIOP 1.0, we always add one profile for each host,
            // since IIOP 1.0 doesn't support tagged components in a
            // profile
            //
            for (int i = 0; i < hosts_.length; i++) {
                org.omg.IIOP.ProfileBody_1_0 body = new org.omg.IIOP.ProfileBody_1_0();
                body.iiop_version = new org.omg.IIOP.Version(profileInfo.major,
                        profileInfo.minor);
                body.host = hosts_[i];
                // the CSIv2 policy may require zeroing the port in the IOR. 
                if (policies.zeroPortPolicy()) {
                    body.port = 0; 
                }
                else {
                    if (port_ >= 0x8000)
                        body.port = (short) (port_ - 0xffff - 1);
                    else
                        body.port = (short) port_;
                }
                body.object_key = profileInfo.key;

                int len = ior.value.profiles.length + 1;
                org.omg.IOP.TaggedProfile[] profiles = new org.omg.IOP.TaggedProfile[len];
                System.arraycopy(ior.value.profiles, 0, profiles, 0,
                        ior.value.profiles.length);
                ior.value.profiles = profiles;
                ior.value.profiles[len - 1] = new org.omg.IOP.TaggedProfile();
                ior.value.profiles[len - 1].tag = org.omg.IOP.TAG_INTERNET_IOP.value;
                org.apache.yoko.orb.OCI.Buffer buf = new org.apache.yoko.orb.OCI.Buffer();
                OutputStream out = new OutputStream(buf);
                out._OB_writeEndian();
                org.omg.IIOP.ProfileBody_1_0Helper.write(out, body);
                ior.value.profiles[len - 1].profile_data = new byte[buf
                        .length()];
                System.arraycopy(buf.data(), 0,
                        ior.value.profiles[len - 1].profile_data, 0, buf
                                .length());
            }
        } else {
            if (multiProfile_) {
                //
                // Add one profile for each host
                //

                for (int i = 0; i < hosts_.length; i++) {
                    org.omg.IIOP.ProfileBody_1_1 body = new org.omg.IIOP.ProfileBody_1_1();
                    body.iiop_version = new org.omg.IIOP.Version(
                            profileInfo.major, profileInfo.minor);
                    body.host = hosts_[i];
                    // the CSIv2 policy may require zeroing the port in the IOR. 
                    if (policies.zeroPortPolicy()) {
                        body.port = 0; 
                    }
                    else {
                        if (port_ >= 0x8000)
                            body.port = (short) (port_ - 0xffff - 1);
                        else
                            body.port = (short) port_;
                    }
                    body.object_key = profileInfo.key;
                    body.components = new org.omg.IOP.TaggedComponent[components
                            .size()];
                    components.copyInto(body.components);

                    int len = ior.value.profiles.length + 1;
                    org.omg.IOP.TaggedProfile[] profiles = new org.omg.IOP.TaggedProfile[len];
                    System.arraycopy(ior.value.profiles, 0, profiles, 0,
                            ior.value.profiles.length);
                    ior.value.profiles = profiles;
                    ior.value.profiles[len - 1] = new org.omg.IOP.TaggedProfile();
                    ior.value.profiles[len - 1].tag = org.omg.IOP.TAG_INTERNET_IOP.value;
                    org.apache.yoko.orb.OCI.Buffer buf = new org.apache.yoko.orb.OCI.Buffer();
                    OutputStream out = new OutputStream(buf);
                    out._OB_writeEndian();
                    org.omg.IIOP.ProfileBody_1_1Helper.write(out, body);
                    ior.value.profiles[len - 1].profile_data = new byte[buf
                            .length()];
                    System.arraycopy(buf.data(), 0,
                            ior.value.profiles[len - 1].profile_data, 0, buf
                                    .length());
                }
            } else {
                //
                // Add a single tagged profile. If there are additional
                // hosts, add a tagged component for each host.
                //

                org.omg.IIOP.ProfileBody_1_1 body = new org.omg.IIOP.ProfileBody_1_1();
                body.iiop_version = new org.omg.IIOP.Version(profileInfo.major,
                        profileInfo.minor);
                body.host = hosts_[0];
                if (policies.zeroPortPolicy()) {
                    body.port = 0; 
                }
                else {
                    if (port_ >= 0x8000)
                        body.port = (short) (port_ - 0xffff - 1);
                    else
                        body.port = (short) port_;
                }
                body.object_key = profileInfo.key;

                for (int i = 1; i < hosts_.length; i++) {
                    org.omg.IOP.TaggedComponent c = new org.omg.IOP.TaggedComponent();
                    c.tag = org.omg.IOP.TAG_ALTERNATE_IIOP_ADDRESS.value;
                    org.apache.yoko.orb.OCI.Buffer buf = new org.apache.yoko.orb.OCI.Buffer();
                    OutputStream out = new OutputStream(buf);
                    out._OB_writeEndian();
                    out.write_string(hosts_[i]);
                    out.write_ushort(body.port);
                    c.component_data = new byte[buf.length()];
                    System.arraycopy(buf.data(), 0, c.component_data, 0, buf
                            .length());
                    components.addElement(c);
                }
                body.components = new org.omg.IOP.TaggedComponent[components
                        .size()];
                components.copyInto(body.components);

                int len = ior.value.profiles.length + 1;
                org.omg.IOP.TaggedProfile[] profiles = new org.omg.IOP.TaggedProfile[len];
                System.arraycopy(ior.value.profiles, 0, profiles, 0,
                        ior.value.profiles.length);
                ior.value.profiles = profiles;
                ior.value.profiles[len - 1] = new org.omg.IOP.TaggedProfile();
                ior.value.profiles[len - 1].tag = org.omg.IOP.TAG_INTERNET_IOP.value;
                org.apache.yoko.orb.OCI.Buffer buf = new org.apache.yoko.orb.OCI.Buffer();
                OutputStream out = new OutputStream(buf);
                out._OB_writeEndian();
                org.omg.IIOP.ProfileBody_1_1Helper.write(out, body);
                ior.value.profiles[len - 1].profile_data = new byte[buf
                        .length()];
                System.arraycopy(buf.data(), 0,
                        ior.value.profiles[len - 1].profile_data, 0, buf
                                .length());
            }
        }
    }