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.transport.http.policy;
19:
20: import javax.xml.bind.JAXBException;
21:
22: import org.apache.cxf.transports.http.configuration.HTTPClientPolicy;
23: import org.apache.cxf.ws.policy.builder.jaxb.JaxbAssertion;
24: import org.apache.cxf.ws.policy.builder.jaxb.JaxbAssertionBuilder;
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 HTTPClientAssertionBuilder extends
33: JaxbAssertionBuilder<HTTPClientPolicy> {
34:
35: public HTTPClientAssertionBuilder() throws JAXBException {
36: super (HTTPClientPolicy.class,
37: PolicyUtils.HTTPCLIENTPOLICY_ASSERTION_QNAME);
38: }
39:
40: @Override
41: public Assertion buildCompatible(Assertion a, Assertion b) {
42: if (PolicyUtils.HTTPCLIENTPOLICY_ASSERTION_QNAME.equals(a
43: .getName())
44: && PolicyUtils.HTTPCLIENTPOLICY_ASSERTION_QNAME
45: .equals(b.getName())) {
46:
47: HTTPClientPolicy compatible = PolicyUtils.intersect(
48: JaxbAssertion.cast(a, HTTPClientPolicy.class)
49: .getData(), JaxbAssertion.cast(b,
50: HTTPClientPolicy.class).getData());
51: if (null == compatible) {
52: return null;
53: }
54: JaxbAssertion<HTTPClientPolicy> ca = new JaxbAssertion<HTTPClientPolicy>(
55: PolicyUtils.HTTPCLIENTPOLICY_ASSERTION_QNAME, a
56: .isOptional()
57: && b.isOptional());
58: ca.setData(compatible);
59: return ca;
60: }
61: return null;
62: }
63:
64: @Override
65: protected JaxbAssertion<HTTPClientPolicy> buildAssertion() {
66: return new HTTPClientPolicyAssertion();
67: }
68:
69: class HTTPClientPolicyAssertion extends
70: JaxbAssertion<HTTPClientPolicy> {
71: HTTPClientPolicyAssertion() {
72: super (PolicyUtils.HTTPCLIENTPOLICY_ASSERTION_QNAME, false);
73: }
74:
75: @Override
76: public boolean equal(PolicyComponent policyComponent) {
77: if (policyComponent.getType() != Constants.TYPE_ASSERTION
78: || !getName().equals(
79: ((Assertion) policyComponent).getName())) {
80: return false;
81: }
82: JaxbAssertion<HTTPClientPolicy> other = JaxbAssertion
83: .cast((Assertion) policyComponent);
84: return PolicyUtils.equals(this .getData(), other.getData());
85: }
86:
87: @Override
88: protected Assertion cloneMandatory() {
89: HTTPClientPolicyAssertion a = new HTTPClientPolicyAssertion();
90: a.setData(getData());
91: return a;
92: }
93: }
94:
95: }
|