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.mtom;
19:
20: import java.util.ArrayList;
21: import java.util.Collection;
22: import java.util.Collections;
23:
24: import javax.xml.namespace.QName;
25:
26: import org.w3c.dom.Attr;
27: import org.w3c.dom.Element;
28:
29: import org.apache.cxf.Bus;
30: import org.apache.cxf.ws.policy.AssertionBuilder;
31: import org.apache.cxf.ws.policy.PolicyConstants;
32: import org.apache.cxf.ws.policy.builder.primitive.PrimitiveAssertion;
33: import org.apache.cxf.ws.policy.builder.primitive.PrimitiveAssertionBuilder;
34: import org.apache.neethi.Assertion;
35:
36: public class MTOMAssertionBuilder implements AssertionBuilder {
37: private static final Collection<QName> KNOWN = new ArrayList<QName>();
38: private Bus bus;
39: static {
40: KNOWN.add(MetadataConstants.MTOM_ASSERTION_QNAME);
41: }
42:
43: public void setBus(Bus b) {
44: bus = b;
45: }
46:
47: public Assertion build(Element elem) {
48: String localName = elem.getLocalName();
49: QName qn = new QName(elem.getNamespaceURI(), localName);
50:
51: boolean optional = false;
52: PolicyConstants constants = null;
53: if (null != bus) {
54: constants = bus.getExtension(PolicyConstants.class);
55: }
56: if (null == constants) {
57: constants = new PolicyConstants();
58: }
59: Attr attribute = elem.getAttributeNodeNS(constants
60: .getNamespace(), constants.getOptionalAttrName());
61: if (attribute != null) {
62: optional = Boolean.valueOf(attribute.getValue());
63: }
64:
65: if (MetadataConstants.MTOM_ASSERTION_QNAME.equals(qn)) {
66: return new PrimitiveAssertion(
67: MetadataConstants.MTOM_ASSERTION_QNAME, optional);
68: }
69:
70: return null;
71: }
72:
73: public Collection<QName> getKnownElements() {
74: return KNOWN;
75: }
76:
77: public Assertion buildCompatible(Assertion a, Assertion b) {
78: QName qn = a.getName();
79: if (MetadataConstants.MTOM_ASSERTION_QNAME.equals(qn)) {
80: PrimitiveAssertionBuilder pab = new PrimitiveAssertionBuilder();
81: pab.setKnownElements(Collections.singleton(qn));
82: return pab.buildCompatible(a, b);
83: }
84:
85: return null;
86: }
87: }
|