Author: dkulp
Date: Mon Feb 14 21:47:42 2011
New Revision: 1070680
URL: http://svn.apache.org/viewvc?rev=1070680&view=rev
Log:
Start integrating neethi into CXF. Needed to make some
stuff protected and easier to subclass, but also needed
to add support for the interem Policy 1.5 namespace.
Modified:
webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/Constants.java
webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/builders/PolicyContainingPrimitiveAssertion.java
webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/builders/PrimitiveAssertion.java
webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/builders/xml/XMLPrimitiveAssertionBuilder.java
Modified:
webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/Constants.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/Constants.java?rev=1070680&r1=1070679&r2=1070680&view=diff
==============================================================================
---
webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/Constants.java
(original)
+++
webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/Constants.java
Mon Feb 14 21:47:42 2011
@@ -39,8 +39,8 @@ public final class Constants {
public static final String ATTR_WSU = "wsu";
public static final String ATTR_URI = "URI";
-
public static final String URI_POLICY_NS =
"http://schemas.xmlsoap.org/ws/2004/09/policy";
+ public static final String URI_POLICY_15_DEPRECATED_NS =
"http://www.w3.org/2006/07/ws-policy";
public static final String URI_POLICY_15_NS =
"http://www.w3.org/ns/ws-policy";
public static final String URI_WSU_NS
@@ -87,11 +87,13 @@ public final class Constants {
public static boolean isInPolicyNS(QName q) {
String ns = q.getNamespaceURI();
- return URI_POLICY_NS.equals(ns)
+ return URI_POLICY_NS.equals(ns)
+ || URI_POLICY_15_DEPRECATED_NS.equals(ns)
|| URI_POLICY_15_NS.equals(ns);
}
public static boolean isPolicyElement(String ns, String local) {
return (URI_POLICY_NS.equals(ns)
+ || URI_POLICY_15_DEPRECATED_NS.equals(ns)
|| URI_POLICY_15_NS.equals(ns)) && ELEM_POLICY.equals(local);
}
public static boolean isPolicyElement(QName q) {
@@ -107,6 +109,9 @@ public final class Constants {
public static String findPolicyNamespace(XMLStreamWriter writer) throws
XMLStreamException {
String prefix = writer.getPrefix(Constants.URI_POLICY_15_NS);
if (prefix == null || "".equals(prefix)) {
+ prefix = writer.getPrefix(Constants.URI_POLICY_15_DEPRECATED_NS);
+ }
+ if (prefix == null || "".equals(prefix)) {
return Constants.URI_POLICY_NS;
}
return Constants.URI_POLICY_15_NS;
Modified:
webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/builders/PolicyContainingPrimitiveAssertion.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/builders/PolicyContainingPrimitiveAssertion.java?rev=1070680&r1=1070679&r2=1070680&view=diff
==============================================================================
---
webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/builders/PolicyContainingPrimitiveAssertion.java
(original)
+++
webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/builders/PolicyContainingPrimitiveAssertion.java
Mon Feb 14 21:47:42 2011
@@ -45,9 +45,12 @@ public class PolicyContainingPrimitiveAs
extends PrimitiveAssertion
implements PolicyContainingAssertion {
- private Policy nested;
+ protected Policy nested;
- public PolicyContainingPrimitiveAssertion(QName name, boolean optional,
boolean ignorable, Policy p) {
+ public PolicyContainingPrimitiveAssertion(QName name,
+ boolean optional,
+ boolean ignorable,
+ Policy p) {
super(name, optional, ignorable);
this.nested = p;
}
@@ -68,8 +71,7 @@ public class PolicyContainingPrimitiveAs
All all = new All();
List<PolicyComponent> alternative = alternatives.next();
Policy n = new Policy(nested.getPolicyRegistry(),
nested.getNamespace());
- PolicyContainingPrimitiveAssertion a
- = new PolicyContainingPrimitiveAssertion(getName(), false,
ignorable, n);
+ Assertion a = clone(false, n);
ExactlyOne nea = new ExactlyOne();
n.addPolicyComponent(nea);
All na = new All();
@@ -80,7 +82,10 @@ public class PolicyContainingPrimitiveAs
}
return p;
}
-
+ protected Assertion clone(boolean optional, Policy n) {
+ return new PolicyContainingPrimitiveAssertion(name, optional,
ignorable, n);
+ }
+
public boolean equal(PolicyComponent policyComponent) {
if (!super.equal(policyComponent)) {
return false;
@@ -132,9 +137,6 @@ public class PolicyContainingPrimitiveAs
PolicyContainingPrimitiveAssertion p2 =
(PolicyContainingPrimitiveAssertion)assertion;
Policy p = new PolicyIntersector(strict).intersect(nested, p2.nested);
- return new PolicyContainingPrimitiveAssertion(getName(),
- isOptional() &&
assertion.isOptional(),
- false,
- p);
+ return clone(isOptional() && assertion.isOptional(), p);
}
}
Modified:
webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/builders/PrimitiveAssertion.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/builders/PrimitiveAssertion.java?rev=1070680&r1=1070679&r2=1070680&view=diff
==============================================================================
---
webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/builders/PrimitiveAssertion.java
(original)
+++
webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/builders/PrimitiveAssertion.java
Mon Feb 14 21:47:42 2011
@@ -101,7 +101,7 @@ public class PrimitiveAssertion implemen
ExactlyOne exactlyOne = new ExactlyOne();
All all = new All();
- all.addPolicyComponent(cloneMandatory());
+ all.addPolicyComponent(clone(false));
exactlyOne.addPolicyComponent(all);
exactlyOne.addPolicyComponent(new All());
policy.addPolicyComponent(exactlyOne);
@@ -109,7 +109,7 @@ public class PrimitiveAssertion implemen
return policy;
}
- return cloneMandatory();
+ return clone(false);
}
public void serialize(XMLStreamWriter writer) throws XMLStreamException {
@@ -136,8 +136,8 @@ public class PrimitiveAssertion implemen
writer.writeEndElement();
}
- protected Assertion cloneMandatory() {
- return new PrimitiveAssertion(name, false, ignorable);
+ protected Assertion clone(boolean optional) {
+ return new PrimitiveAssertion(name, optional, ignorable);
}
public boolean isCompatible(Assertion assertion, boolean strict) {
@@ -151,7 +151,7 @@ public class PrimitiveAssertion implemen
if (isOptional() == assertion.isOptional()) {
return assertion;
}
- return new PrimitiveAssertion(getName(), isOptional() &&
assertion.isOptional());
+ return clone(isOptional() && assertion.isOptional());
}
}
\ No newline at end of file
Modified:
webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/builders/xml/XMLPrimitiveAssertionBuilder.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/builders/xml/XMLPrimitiveAssertionBuilder.java?rev=1070680&r1=1070679&r2=1070680&view=diff
==============================================================================
---
webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/builders/xml/XMLPrimitiveAssertionBuilder.java
(original)
+++
webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/builders/xml/XMLPrimitiveAssertionBuilder.java
Mon Feb 14 21:47:42 2011
@@ -28,6 +28,7 @@ import org.w3c.dom.Node;
import org.apache.neethi.Assertion;
import org.apache.neethi.AssertionBuilderFactory;
import org.apache.neethi.Constants;
+import org.apache.neethi.Policy;
import org.apache.neethi.builders.AssertionBuilder;
import org.apache.neethi.builders.PolicyContainingPrimitiveAssertion;
import org.apache.neethi.builders.PrimitiveAssertion;
@@ -53,28 +54,41 @@ public class XMLPrimitiveAssertionBuilde
nd = nd.getNextSibling();
}
if (count == 0) {
- return new PrimitiveAssertion(new QName(element.getNamespaceURI(),
element.getLocalName()),
- isOptional(element),
isIgnorable(element));
-
+ return newPrimitiveAssertion(element);
} else if (policyCount == 1 && count == 1) {
- return new PolicyContainingPrimitiveAssertion(new
QName(element.getNamespaceURI(),
-
element.getLocalName()),
- isOptional(element),
isIgnorable(element),
-
factory.getPolicyEngine().getPolicy(policyEl));
+ Policy policy = factory.getPolicyEngine().getPolicy(policyEl);
+ return newPolicyContainingAssertion(element, policy);
}
return new XmlPrimitiveAssertion(element);
}
- private boolean isOptional(Element el) {
+ public Assertion newPrimitiveAssertion(Element element) {
+ return new PrimitiveAssertion(new QName(element.getNamespaceURI(),
element.getLocalName()),
+ isOptional(element),
isIgnorable(element));
+ }
+ public Assertion newPolicyContainingAssertion(Element element, Policy
policy) {
+ return new PolicyContainingPrimitiveAssertion(new
QName(element.getNamespaceURI(),
+
element.getLocalName()),
+ isOptional(element),
isIgnorable(element),
+ policy);
+ }
+
+ public static boolean isOptional(Element el) {
Attr optional = el.getAttributeNodeNS(Constants.URI_POLICY_NS,
Constants.ATTR_OPTIONAL);
if (optional == null) {
optional = el.getAttributeNodeNS(Constants.URI_POLICY_15_NS,
Constants.ATTR_OPTIONAL);
}
+ if (optional == null) {
+ optional =
el.getAttributeNodeNS(Constants.URI_POLICY_15_DEPRECATED_NS,
Constants.ATTR_OPTIONAL);
+ }
return optional == null ? false :
Boolean.parseBoolean(optional.getValue());
}
- private boolean isIgnorable(Element el) {
+ public static boolean isIgnorable(Element el) {
Attr ignorable = el.getAttributeNodeNS(Constants.URI_POLICY_15_NS,
Constants.ATTR_IGNORABLE);
+ if (ignorable == null) {
+ ignorable =
el.getAttributeNodeNS(Constants.URI_POLICY_15_DEPRECATED_NS,
Constants.ATTR_IGNORABLE);
+ }
return ignorable == null ? false :
Boolean.parseBoolean(ignorable.getValue());
}