001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */package org.apache.cxf.ws.addressing.policy;
019:
020: import java.util.ArrayList;
021: import java.util.Collection;
022: import java.util.Collections;
023:
024: import javax.xml.namespace.QName;
025:
026: import org.w3c.dom.Attr;
027: import org.w3c.dom.Element;
028:
029: import org.apache.cxf.Bus;
030: import org.apache.cxf.ws.policy.AssertionBuilder;
031: import org.apache.cxf.ws.policy.AssertionBuilderRegistry;
032: import org.apache.cxf.ws.policy.PolicyBuilder;
033: import org.apache.cxf.ws.policy.PolicyConstants;
034: import org.apache.cxf.ws.policy.builder.primitive.NestedPrimitiveAssertion;
035: import org.apache.cxf.ws.policy.builder.primitive.NestedPrimitiveAssertionBuilder;
036: import org.apache.cxf.ws.policy.builder.primitive.PrimitiveAssertion;
037: import org.apache.cxf.ws.policy.builder.primitive.PrimitiveAssertionBuilder;
038: import org.apache.neethi.Assertion;
039:
040: /**
041: *
042: */
043: public class AddressingAssertionBuilder implements AssertionBuilder {
044:
045: private static final Collection<QName> KNOWN = new ArrayList<QName>();
046: private Bus bus;
047:
048: public AddressingAssertionBuilder(Bus b) {
049: bus = b;
050: }
051:
052: static {
053: KNOWN.add(MetadataConstants.ADDRESSING_ASSERTION_QNAME);
054: KNOWN.add(MetadataConstants.ANON_RESPONSES_ASSERTION_QNAME);
055: KNOWN.add(MetadataConstants.NON_ANON_RESPONSES_ASSERTION_QNAME);
056: }
057:
058: public Assertion build(Element elem) {
059:
060: String localName = elem.getLocalName();
061: QName qn = new QName(elem.getNamespaceURI(), localName);
062:
063: boolean optional = false;
064: PolicyConstants constants = bus
065: .getExtension(PolicyConstants.class);
066: Attr attribute = elem.getAttributeNodeNS(constants
067: .getNamespace(), constants.getOptionalAttrName());
068: if (attribute != null) {
069: optional = Boolean.valueOf(attribute.getValue());
070: }
071: if (MetadataConstants.ADDRESSING_ASSERTION_QNAME.equals(qn)) {
072: PolicyBuilder builder = bus
073: .getExtension(PolicyBuilder.class);
074: return new NestedPrimitiveAssertion(elem, builder,
075: constants);
076: } else if (MetadataConstants.ANON_RESPONSES_ASSERTION_QNAME
077: .equals(qn)) {
078: return new PrimitiveAssertion(
079: MetadataConstants.ANON_RESPONSES_ASSERTION_QNAME,
080: optional);
081: } else if (MetadataConstants.NON_ANON_RESPONSES_ASSERTION_QNAME
082: .getLocalPart().equals(localName)) {
083: return new PrimitiveAssertion(
084: MetadataConstants.NON_ANON_RESPONSES_ASSERTION_QNAME,
085: optional);
086: }
087: return null;
088: }
089:
090: public Collection<QName> getKnownElements() {
091: return KNOWN;
092: }
093:
094: public Assertion buildCompatible(Assertion a, Assertion b) {
095: QName qn = a.getName();
096: if (MetadataConstants.ADDRESSING_ASSERTION_QNAME.equals(qn)) {
097: NestedPrimitiveAssertionBuilder npab = new NestedPrimitiveAssertionBuilder();
098: npab
099: .setKnownElements(Collections
100: .singleton(MetadataConstants.ADDRESSING_ASSERTION_QNAME));
101: npab.setAssertionBuilderRegistry(bus
102: .getExtension(AssertionBuilderRegistry.class));
103: return npab.buildCompatible(a, b);
104: } else if (MetadataConstants.ANON_RESPONSES_ASSERTION_QNAME
105: .equals(qn)
106: || MetadataConstants.NON_ANON_RESPONSES_ASSERTION_QNAME
107: .equals(qn)) {
108:
109: PrimitiveAssertionBuilder pab = new PrimitiveAssertionBuilder();
110: pab.setKnownElements(Collections.singleton(qn));
111: return pab.buildCompatible(a, b);
112: }
113: return null;
114: }
115:
116: }
|