01: /**
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing,
13: * software distributed under the License is distributed on an
14: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15: * KIND, either express or implied. See the License for the
16: * specific language governing permissions and limitations
17: * under the License.
18: */package org.apache.cxf.ws.rm.policy;
19:
20: import javax.xml.bind.JAXBException;
21:
22: import org.apache.cxf.ws.policy.builder.jaxb.JaxbAssertion;
23: import org.apache.cxf.ws.policy.builder.jaxb.JaxbAssertionBuilder;
24: import org.apache.cxf.ws.rm.RMConstants;
25: import org.apache.neethi.Assertion;
26: import org.apache.neethi.Constants;
27: import org.apache.neethi.PolicyComponent;
28:
29: /**
30: *
31: */
32: public class RMAssertionBuilder extends
33: JaxbAssertionBuilder<RMAssertion> {
34:
35: public RMAssertionBuilder() throws JAXBException {
36: super (RMAssertion.class, RMConstants.getRMAssertionQName());
37: }
38:
39: @Override
40: public Assertion buildCompatible(Assertion a, Assertion b) {
41: if (RMConstants.getRMAssertionQName().equals(a.getName())
42: && RMConstants.getRMAssertionQName()
43: .equals(b.getName())) {
44:
45: RMAssertion compatible = PolicyUtils.intersect(
46: JaxbAssertion.cast(a, RMAssertion.class).getData(),
47: JaxbAssertion.cast(b, RMAssertion.class).getData());
48: if (null == compatible) {
49: return null;
50: }
51: JaxbAssertion<RMAssertion> ca = new JaxbAssertion<RMAssertion>(
52: RMConstants.getRMAssertionQName(), a.isOptional()
53: && b.isOptional());
54: ca.setData(compatible);
55: return ca;
56: }
57: return null;
58: }
59:
60: @Override
61: protected JaxbAssertion<RMAssertion> buildAssertion() {
62: return new RMPolicyAssertion();
63: }
64:
65: class RMPolicyAssertion extends JaxbAssertion<RMAssertion> {
66: RMPolicyAssertion() {
67: super (RMConstants.getRMAssertionQName(), false);
68: }
69:
70: @Override
71: public boolean equal(PolicyComponent policyComponent) {
72: if (policyComponent.getType() != Constants.TYPE_ASSERTION
73: || !getName().equals(
74: ((Assertion) policyComponent).getName())) {
75: return false;
76: }
77: JaxbAssertion<RMAssertion> other = JaxbAssertion
78: .cast((Assertion) policyComponent);
79: return PolicyUtils.equals(this .getData(), other.getData());
80: }
81:
82: @Override
83: protected Assertion cloneMandatory() {
84: RMPolicyAssertion a = new RMPolicyAssertion();
85: a.setData(getData());
86: return a;
87: }
88: }
89:
90: }
|