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.HTTPServerPolicy;
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 HTTPServerAssertionBuilder extends
33: JaxbAssertionBuilder<HTTPServerPolicy> {
34:
35: public HTTPServerAssertionBuilder() throws JAXBException {
36: super (HTTPServerPolicy.class,
37: PolicyUtils.HTTPSERVERPOLICY_ASSERTION_QNAME);
38: }
39:
40: @Override
41: public Assertion buildCompatible(Assertion a, Assertion b) {
42: if (PolicyUtils.HTTPSERVERPOLICY_ASSERTION_QNAME.equals(a
43: .getName())
44: && PolicyUtils.HTTPSERVERPOLICY_ASSERTION_QNAME
45: .equals(b.getName())) {
46:
47: HTTPServerPolicy compatible = PolicyUtils.intersect(
48: JaxbAssertion.cast(a, HTTPServerPolicy.class)
49: .getData(), JaxbAssertion.cast(b,
50: HTTPServerPolicy.class).getData());
51: if (null == compatible) {
52: return null;
53: }
54:
55: JaxbAssertion<HTTPServerPolicy> ca = buildAssertion();
56: ca.setOptional(a.isOptional() && b.isOptional());
57: ca.setData(compatible);
58: return ca;
59: }
60: return null;
61: }
62:
63: @Override
64: protected JaxbAssertion<HTTPServerPolicy> buildAssertion() {
65: return new HTTPServerPolicyAssertion();
66: }
67:
68: class HTTPServerPolicyAssertion extends
69: JaxbAssertion<HTTPServerPolicy> {
70: HTTPServerPolicyAssertion() {
71: super (PolicyUtils.HTTPSERVERPOLICY_ASSERTION_QNAME, false);
72: }
73:
74: @Override
75: public boolean equal(PolicyComponent policyComponent) {
76: if (policyComponent.getType() != Constants.TYPE_ASSERTION
77: || !getName().equals(
78: ((Assertion) policyComponent).getName())) {
79: return false;
80: }
81: JaxbAssertion<HTTPServerPolicy> other = JaxbAssertion
82: .cast((Assertion) policyComponent);
83: return PolicyUtils.equals(this .getData(), other.getData());
84: }
85:
86: @Override
87: protected Assertion cloneMandatory() {
88: HTTPServerPolicyAssertion a = new HTTPServerPolicyAssertion();
89: a.setData(getData());
90: return a;
91: }
92: }
93: }
|