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.policy.builder.primitive;
19:
20: import org.w3c.dom.Element;
21:
22: import org.apache.cxf.ws.policy.AssertionBuilderRegistry;
23: import org.apache.cxf.ws.policy.Intersector;
24: import org.apache.cxf.ws.policy.PolicyBuilder;
25: import org.apache.neethi.Assertion;
26: import org.apache.neethi.Policy;
27:
28: public class NestedPrimitiveAssertionBuilder extends
29: PrimitiveAssertionBuilder {
30:
31: private PolicyBuilder builder;
32: private AssertionBuilderRegistry assertionBuilderRegistry;
33:
34: public void setPolicyBuilder(PolicyBuilder b) {
35: builder = b;
36: }
37:
38: public void setAssertionBuilderRegistry(AssertionBuilderRegistry abr) {
39: assertionBuilderRegistry = abr;
40: }
41:
42: @Override
43: public Assertion build(Element elem) {
44: return new NestedPrimitiveAssertion(elem, builder,
45: getPolicyConstants());
46: }
47:
48: @Override
49: /**
50: * If the nested policies in both assertions are empty, the compatible policy
51: * .
52: * The compatible policy is optional iff both assertions are optional.
53: */
54: public Assertion buildCompatible(Assertion a, Assertion b) {
55: if (!getKnownElements().contains(a.getName())
56: || !a.getName().equals(b.getName())) {
57: return null;
58: }
59:
60: if (null == assertionBuilderRegistry) {
61: return null;
62: }
63:
64: NestedPrimitiveAssertion na = (NestedPrimitiveAssertion) a;
65: NestedPrimitiveAssertion nb = (NestedPrimitiveAssertion) b;
66:
67: Intersector intersector = new Intersector(
68: assertionBuilderRegistry);
69:
70: Policy nested = intersector.intersect(na.getNested(), nb
71: .getNested());
72: if (null == nested) {
73: return null;
74: }
75:
76: NestedPrimitiveAssertion compatible = new NestedPrimitiveAssertion(
77: a.getName(), a.isOptional() && b.isOptional());
78: compatible.setNested(nested);
79:
80: return compatible;
81: }
82:
83: }
|