public static void getInvocationPolicyValues()

in yoko-core/src/main/java/org/apache/yoko/orb/OB/MessageRoutingUtil.java [547:705]


    public static void getInvocationPolicyValues(
            org.apache.yoko.orb.OB.RefCountPolicyList policyList,
            org.omg.Messaging.PolicyValueSeqHolder policies) {
        //
        // TODO: We should revisit this. The spec is not very clear on
        // whether we should propogate policies that have no default values
        // and that have not been overriden by the client. For now, we
        // assume that only default or overriden policyes will be
        // propogated in the INVOCATION_POLICIES service context.
        //

        //
        // A set of flags that will indicate how to handle specific
        // policies
        // 
        boolean rebind = false;
        boolean queueOrder = false;
        boolean useRelativeRequest = false;
        boolean useRelativeRoundtrip = false;

        //
        // There is a special case we need to watch out for. The two
        // relative timeouts are actually a different way to specify the
        // request and reply end times. We don't want them to overwrite
        // each other so we wil pick the earliest values if both times
        // are supplied (e.g. RelativeRequest and RequestEnd or
        // RelativeRoundtrip and ReplyEnd)
        //
        if (policyList.relativeRequestTimeout != 0) {
            useRelativeRequest = true;
            if (org.apache.yoko.orb.OB.TimeHelper.notEqual(
                    policyList.requestEndTime,
                    org.apache.yoko.orb.OB.TimeHelper.utcMin())) {
                //
                // Compare the times and pick the earliest
                //
                org.omg.TimeBase.UtcT timeout = org.apache.yoko.orb.OB.TimeHelper
                        .utcMin();
                if (org.apache.yoko.orb.OB.TimeHelper.greaterThan(timeout,
                        policyList.requestEndTime))
                    useRelativeRequest = false;
            }
        }
        if (policyList.relativeRoundTripTimeout != 0) {
            useRelativeRoundtrip = true;
            if (org.apache.yoko.orb.OB.TimeHelper.notEqual(
                    policyList.replyEndTime, org.apache.yoko.orb.OB.TimeHelper
                            .utcMin())) {
                //
                // Compare the times and pick the earliest
                //
                org.omg.TimeBase.UtcT timeout = org.apache.yoko.orb.OB.TimeHelper
                        .utcMin();
                if (org.apache.yoko.orb.OB.TimeHelper.greaterThan(timeout,
                        policyList.replyEndTime))
                    useRelativeRequest = false;
            }
        }

        //
        // Go through all of the policies in the policy list and create the
        // appropriate PolicyValue
        //
        int numPolicies = policyList.value.length;
        for (int i = 0; i < numPolicies; ++i) {
            try {
                int type = policyList.value[i].policy_type();

                if ((type == org.omg.Messaging.RELATIVE_REQ_TIMEOUT_POLICY_TYPE.value && useRelativeRequest == false)
                        || (type == org.omg.Messaging.REQUEST_END_TIME_POLICY_TYPE.value && useRelativeRequest == true)) {
                    //
                    // This is to handle cases when both policies are set
                    //
                    continue;
                }
                if ((type == org.omg.Messaging.RELATIVE_RT_TIMEOUT_POLICY_TYPE.value && useRelativeRoundtrip == false)
                        || (type == org.omg.Messaging.REPLY_END_TIME_POLICY_TYPE.value && useRelativeRoundtrip == true)) {
                    //
                    // This is to handle cases when both policies are set
                    //
                    continue;
                }

                org.omg.Messaging.PolicyValue val = createMessagingPolicyValue(policyList.value[i]);

                //
                // We also need to watch out for rebind and queue order.
                // If they have been specified by the client, we don't need
                // to use their defaults. Flag this so we know about it
                // later
                //
                if (val.ptype == org.omg.Messaging.REBIND_POLICY_TYPE.value)
                    rebind = true;
                if (val.ptype == org.omg.Messaging.QUEUE_ORDER_POLICY_TYPE.value)
                    queueOrder = true;

                //
                // Add the policy to the supplied list of policies
                //
                int len = policies.value.length;
                org.omg.Messaging.PolicyValue[] newSeq = new org.omg.Messaging.PolicyValue[len + 1];
                System.arraycopy(policies.value, 0, newSeq, 0, len);
                policies.value = newSeq;
            } catch (org.omg.CORBA.INV_POLICY ex) {

            }
        }
        if (rebind == false) {
            //
            // We need to use the default value for the rebind policy
            //
            org.omg.Messaging.PolicyValue val = new org.omg.Messaging.PolicyValue();

            val.ptype = org.omg.Messaging.REBIND_POLICY_TYPE.value;

            org.apache.yoko.orb.OCI.Buffer buf = new org.apache.yoko.orb.OCI.Buffer();
            org.apache.yoko.orb.CORBA.OutputStream out = new org.apache.yoko.orb.CORBA.OutputStream(
                    buf);
            out._OB_writeEndian();
            org.omg.Messaging.RebindModeHelper
                    .write(out, policyList.rebindMode);
            val.pvalue = new byte[out._OB_pos()];
            System.arraycopy(buf.data(), 0, val.pvalue, 0, buf.length());

            //
            // Add the rebind policy to the list of supplied policies
            //
            int len = policies.value.length;
            org.omg.Messaging.PolicyValue[] newSeq = new org.omg.Messaging.PolicyValue[len + 1];
            System.arraycopy(policies.value, 0, newSeq, 0, len);
            newSeq[len] = val;
            policies.value = newSeq;
        }
        if (queueOrder == false) {
            //
            // We need to use the default value for the queue order policy
            //
            org.omg.Messaging.PolicyValue val = new org.omg.Messaging.PolicyValue();

            val.ptype = org.omg.Messaging.QUEUE_ORDER_POLICY_TYPE.value;

            org.apache.yoko.orb.OCI.Buffer buf = new org.apache.yoko.orb.OCI.Buffer();
            org.apache.yoko.orb.CORBA.OutputStream out = new org.apache.yoko.orb.CORBA.OutputStream(
                    buf);
            out._OB_writeEndian();
            org.omg.Messaging.OrderingHelper.write(out, policyList.queueOrder);
            val.pvalue = new byte[out._OB_pos()];
            System.arraycopy(buf.data(), 0, val.pvalue, 0, buf.length());

            //
            // Add the queue order policy to the list of supplied policies
            //
            int len = policies.value.length;
            org.omg.Messaging.PolicyValue[] newSeq = new org.omg.Messaging.PolicyValue[len + 1];
            System.arraycopy(policies.value, 0, newSeq, 0, len);
            newSeq[len] = val;
            policies.value = newSeq;
        }
    }