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 java.util.ArrayList;
21: import java.util.Collection;
22:
23: import javax.xml.namespace.QName;
24:
25: import org.w3c.dom.Element;
26:
27: import org.apache.cxf.Bus;
28: import org.apache.cxf.ws.policy.AssertionBuilder;
29: import org.apache.cxf.ws.policy.PolicyConstants;
30: import org.apache.neethi.Assertion;
31:
32: public class PrimitiveAssertionBuilder implements AssertionBuilder {
33:
34: protected Bus bus;
35: private Collection<QName> knownElements = new ArrayList<QName>();
36:
37: public void setBus(Bus b) {
38: bus = b;
39: }
40:
41: public Assertion build(Element element) {
42: return new PrimitiveAssertion(element, getPolicyConstants());
43: }
44:
45: public Collection<QName> getKnownElements() {
46: return knownElements;
47: }
48:
49: public void setKnownElements(Collection<QName> k) {
50: knownElements = k;
51: }
52:
53: /**
54: * If the two assertions are equal, they are also compatible.
55: * The compatible policy is optional iff both assertions are optional.
56: */
57: public Assertion buildCompatible(Assertion a, Assertion b) {
58: if (knownElements.contains(a.getName())
59: && a.getName().equals(b.getName())) {
60: return new PrimitiveAssertion(a.getName(), a.isOptional()
61: && b.isOptional());
62: }
63: return null;
64: }
65:
66: protected PolicyConstants getPolicyConstants() {
67: PolicyConstants constants = null;
68: if (null != bus) {
69: constants = bus.getExtension(PolicyConstants.class);
70: }
71: if (null == constants) {
72: constants = new PolicyConstants();
73: }
74: return constants;
75:
76: }
77: }
|