001: /*
002: * The contents of this file are subject to the terms
003: * of the Common Development and Distribution License
004: * (the License). You may not use this file except in
005: * compliance with the License.
006: *
007: * You can obtain a copy of the license at
008: * https://glassfish.dev.java.net/public/CDDLv1.0.html.
009: * See the License for the specific language governing
010: * permissions and limitations under the License.
011: *
012: * When distributing Covered Code, include this CDDL
013: * Header Notice in each file and include the License file
014: * at https://glassfish.dev.java.net/public/CDDLv1.0.html.
015: * If applicable, add the following below the CDDL Header,
016: * with the fields enclosed by brackets [] replaced by
017: * you own identifying information:
018: * "Portions Copyrighted [year] [name of copyright owner]"
019: *
020: * Copyright 2006 Sun Microsystems Inc. All Rights Reserved
021: */
022:
023: package com.sun.xml.wss.impl.policy.mls;
024:
025: import com.sun.xml.wss.impl.PolicyTypeUtil;
026: import java.util.ArrayList;
027: import java.util.List;
028:
029: /**
030: * Represents mandatory header elements that need to present in the message.
031: * @author K.Venugopal@sun.com
032: */
033: public class MandatoryTargetPolicy extends WSSPolicy {
034:
035: /** Creates a new instance of MandatoryTargetPolicy */
036: public MandatoryTargetPolicy() {
037: }
038:
039: /**
040: *
041: * @return clone
042: */
043: public Object clone() {
044: MandatoryTargetPolicy mp = new MandatoryTargetPolicy();
045: WSSPolicy wp = (WSSPolicy) getFeatureBinding();
046: if (wp != null) {
047: WSSPolicy nwp = (WSSPolicy) wp.clone();
048: mp.setFeatureBinding(nwp);
049: }
050: return mp;
051: }
052:
053: /**
054: *
055: * @param policy
056: * @return true of policy is equal to this policy
057: */
058: public boolean equals(WSSPolicy policy) {
059: if (policy.getType() == PolicyTypeUtil.MANDATORY_TARGET_POLICY_TYPE) {
060: WSSPolicy p1 = (WSSPolicy) policy.getFeatureBinding();
061: if (p1 == null || getFeatureBinding() == null) {
062: return false;
063: }
064: return p1.equals(getFeatureBinding());
065: }
066: return false;
067: }
068:
069: /**
070: *
071: * @param policy
072: * @return true if argument policy is equal to this policy ignoring targets
073: */
074: public boolean equalsIgnoreTargets(WSSPolicy policy) {
075: throw new UnsupportedOperationException();
076: }
077:
078: /**
079: *
080: * @return the type of the policy
081: */
082: public String getType() {
083: return PolicyTypeUtil.MANDATORY_TARGET_POLICY_TYPE;
084: }
085:
086: public static class FeatureBinding extends WSSPolicy {
087: private List<Target> targets = new ArrayList<Target>();
088:
089: /**
090: * adds the Target representing the Header element that must be present in the message.
091: * Will by default set enforce flag on Target element to true.
092: * @param target
093: */
094: public void addTargetBinding(Target target) {
095: targets.add(target);
096: target.setEnforce(true);
097: }
098:
099: /**
100: *
101: * @return list of Target elements
102: */
103: public List<Target> getTargetBindings() {
104: return targets;
105: }
106:
107: /**
108: *
109: * @return clone
110: */
111: public Object clone() {
112: FeatureBinding binding = new FeatureBinding();
113: for (Target t : targets) {
114: binding.addTargetBinding(t);
115: }
116: return binding;
117: }
118:
119: /**
120: *
121: * @param policy
122: * @return true if this policy is equal to the argument policy
123: */
124: public boolean equals(WSSPolicy policy) {
125: boolean retVal = false;
126: if (policy.getType() == PolicyTypeUtil.MANDATORY_TARGET_FEATUREBINDING_TYPE) {
127: List<Target> tList = ((MandatoryTargetPolicy.FeatureBinding) policy)
128: .getTargetBindings();
129: for (Target t : tList) {
130: if (!targets.contains(t)) {
131: break;
132: }
133: }
134: retVal = true;
135: }
136: return retVal;
137: }
138:
139: /**
140: *
141: * @param policy
142: * @return true if this policy is equal to the argument policy ignoring targets
143: */
144: public boolean equalsIgnoreTargets(WSSPolicy policy) {
145: throw new UnsupportedOperationException();
146: }
147:
148: /**
149: *
150: * @return type of the policy
151: */
152: public String getType() {
153: return PolicyTypeUtil.MANDATORY_TARGET_FEATUREBINDING_TYPE;
154: }
155:
156: }
157:
158: }
|