You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commons-dev@ws.apache.org by sa...@apache.org on 2006/07/20 11:34:08 UTC
svn commit: r423853 - in /webservices/commons/trunk/modules/neethi:
src/org/apache/neethi/ test3/org/apache/neethi/ test3/org/apache/neethi/util/
Author: sanka
Date: Thu Jul 20 02:34:07 2006
New Revision: 423853
URL: http://svn.apache.org/viewvc?rev=423853&view=rev
Log:
Renamed the PolicyManager to PolicyEngine.
Removed the PrimitiveAssertion interface.
Added some comments to the existing codebase.
Added:
webservices/commons/trunk/modules/neethi/src/org/apache/neethi/PolicyEngine.java
Removed:
webservices/commons/trunk/modules/neethi/src/org/apache/neethi/PolicyManager.java
webservices/commons/trunk/modules/neethi/src/org/apache/neethi/PrimitiveAssertion.java
Modified:
webservices/commons/trunk/modules/neethi/src/org/apache/neethi/AbstractPolicyOperator.java
webservices/commons/trunk/modules/neethi/src/org/apache/neethi/Assertion.java
webservices/commons/trunk/modules/neethi/src/org/apache/neethi/PolicyComponent.java
webservices/commons/trunk/modules/neethi/src/org/apache/neethi/XmlPrimtiveAssertion.java
webservices/commons/trunk/modules/neethi/test3/org/apache/neethi/NormalizeTest.java
webservices/commons/trunk/modules/neethi/test3/org/apache/neethi/util/PolicyComparator.java
Modified: webservices/commons/trunk/modules/neethi/src/org/apache/neethi/AbstractPolicyOperator.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/neethi/src/org/apache/neethi/AbstractPolicyOperator.java?rev=423853&r1=423852&r2=423853&view=diff
==============================================================================
--- webservices/commons/trunk/modules/neethi/src/org/apache/neethi/AbstractPolicyOperator.java (original)
+++ webservices/commons/trunk/modules/neethi/src/org/apache/neethi/AbstractPolicyOperator.java Thu Jul 20 02:34:07 2006
@@ -111,12 +111,12 @@
boolean found;
for (; L.hasNext();) {
- Lq = ((PrimitiveAssertion) L.next()).getName();
+ Lq = ((Assertion) L.next()).getName();
found = false;
for (; S.hasNext();) {
- Sq = ((PrimitiveAssertion) S.next()).getName();
+ Sq = ((Assertion) S.next()).getName();
if (Lq.equals(Sq)) {
found = true;
Modified: webservices/commons/trunk/modules/neethi/src/org/apache/neethi/Assertion.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/neethi/src/org/apache/neethi/Assertion.java?rev=423853&r1=423852&r2=423853&view=diff
==============================================================================
--- webservices/commons/trunk/modules/neethi/src/org/apache/neethi/Assertion.java (original)
+++ webservices/commons/trunk/modules/neethi/src/org/apache/neethi/Assertion.java Thu Jul 20 02:34:07 2006
@@ -15,14 +15,17 @@
*/
package org.apache.neethi;
+import javax.xml.namespace.QName;
import javax.xml.stream.XMLStreamWriter;
public interface Assertion extends PolicyComponent {
-
- public PolicyComponent normalize();
- public PolicyComponent normalize(PolicyRegistry registry);
+ public QName getName();
+
+ public boolean isOptional();
+ public PolicyComponent normalize();
+
public void serialize(XMLStreamWriter writer);
}
Modified: webservices/commons/trunk/modules/neethi/src/org/apache/neethi/PolicyComponent.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/neethi/src/org/apache/neethi/PolicyComponent.java?rev=423853&r1=423852&r2=423853&view=diff
==============================================================================
--- webservices/commons/trunk/modules/neethi/src/org/apache/neethi/PolicyComponent.java (original)
+++ webservices/commons/trunk/modules/neethi/src/org/apache/neethi/PolicyComponent.java Thu Jul 20 02:34:07 2006
@@ -18,19 +18,40 @@
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;
+/**
+ * This is an interface which any component of the frame must implement.
+ *
+ */
public interface PolicyComponent {
-
+
public static final short POLICY = 0x1;
-
+
public static final short EXACTLYONE = 0x2;
-
+
public static final short ALL = 0x3;
-
+
public static final short ASSERTION = 0x4;
-
-
-
+
+ /**
+ * Serializes the PolicyComponent using an XMLStreamWriter.
+ *
+ * @param writer
+ * the writer that the component should write itself
+ * @throws XMLStreamException
+ * if an errors in the process of serialization of the
+ * PolicyComponent.
+ */
public void serialize(XMLStreamWriter writer) throws XMLStreamException;
-
+
+ /**
+ * Returns a short value which uniquely identify the type of the
+ * PolicyComponent.
+ *
+ * @return PolicyComponent.POLICY for Policy type PolicyComponent
+ * PolicyComponent.EXACTLYONE for ExactlyOne type PolicyComponent
+ * PolicyComponent.All for All type PolicyComponent
+ * PolicyComponent.ASSERTION for Assertion type PolicyComponent
+ *
+ */
public short getType();
}
Added: webservices/commons/trunk/modules/neethi/src/org/apache/neethi/PolicyEngine.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/neethi/src/org/apache/neethi/PolicyEngine.java?rev=423853&view=auto
==============================================================================
--- webservices/commons/trunk/modules/neethi/src/org/apache/neethi/PolicyEngine.java (added)
+++ webservices/commons/trunk/modules/neethi/src/org/apache/neethi/PolicyEngine.java Thu Jul 20 02:34:07 2006
@@ -0,0 +1,146 @@
+/*
+ * Copyright 2001-2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.neethi;
+
+import java.io.InputStream;
+import java.util.Iterator;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLInputFactory;
+
+import org.apache.axiom.om.OMAbstractFactory;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.impl.llom.factory.OMXMLBuilderFactory;
+import org.apache.neethi.builders.AssertionBuilder;
+
+/**
+ * PolicyEngine provides set of methods to create a Policy object from an
+ * InputStream, OMElement, .. etc. It maintains a registry of AssertionBuilder
+ * instances which can create a Domain Assertion out of an OMElement.
+ * AssertionBuilder instances are used when a Policy object is constructed by
+ * the PolicyEngine.
+ *
+ */
+public class PolicyEngine {
+
+ public static final String POLICY_NAMESPACE = "http://schemas.xmlsoap.org/ws/2004/09/policy";
+
+ public static final String POLICY = "Policy";
+
+ public static final String EXACTLY_ONE = "ExactlyOne";
+
+ public static final String ALL = "All";
+
+ private static AssertionBuilderFactory factory = new AssertionBuilderFactory();
+
+ /**
+ * Registers an AssertionBuilder instances and associates it with a QName. PolicyManager
+ * or other AssertionBuilders instances can use this AssertionBuilder instance to process
+ * and build an Assertion from a OMElement with the specified QName.
+ *
+ * @param qname
+ * @param builder
+ */
+ public static void registerBuilder(QName qname, AssertionBuilder builder) {
+ factory.registerBuilder(qname, builder);
+ }
+
+ /**
+ * Creates a Policy object from an InputStream.
+ *
+ * @param inputStream
+ * @return
+ */
+ public static Policy getPolicy(InputStream inputStream) {
+ try {
+ OMElement element = OMXMLBuilderFactory.createStAXOMBuilder(
+ OMAbstractFactory.getOMFactory(),
+ XMLInputFactory.newInstance().createXMLStreamReader(
+ inputStream)).getDocumentElement();
+ return getPolicy(element);
+
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ return null;
+ }
+
+ /**
+ * Creates a Policy object from an OMElement.
+ *
+ * @param element
+ * @return
+ */
+ public static Policy getPolicy(OMElement element) {
+ return getPolicyOperator(element);
+ }
+
+ public static Policy getPolicyOperator(OMElement element) {
+ return (Policy) processOperationElement(element, new Policy());
+ }
+
+ public static ExactlyOne getExactlyOneOperator(OMElement element) {
+ return (ExactlyOne) processOperationElement(element, new ExactlyOne());
+ }
+
+ public static All getAllOperator(OMElement element) {
+ return (All) processOperationElement(element, new All());
+ }
+
+ private static PolicyOperator processOperationElement(
+ OMElement operationElement, PolicyOperator operator) {
+
+ OMElement childElement;
+
+ for (Iterator iterator = operationElement.getChildElements(); iterator
+ .hasNext();) {
+ childElement = (OMElement) iterator.next();
+
+ if (PolicyOperator.NAMESPACE.equals(childElement.getNamespace()
+ .getName())) {
+
+ if (PolicyOperator.POLICY.equals(childElement.getLocalName())) {
+ operator
+ .addPolicyComponent(getPolicyOperator(childElement));
+
+ } else if (PolicyOperator.EXACTLYONE.equals(childElement
+ .getLocalName())) {
+ operator
+ .addPolicyComponent(getExactlyOneOperator(childElement));
+
+ } else if (PolicyOperator.ALL.equals(childElement
+ .getLocalName())) {
+ operator.addPolicyComponent(getAllOperator(childElement));
+ }
+ } else {
+
+ AssertionBuilder builder = factory.getBuilder(childElement
+ .getNamespace().getName());
+
+ if (builder == null) {
+ XmlPrimtiveAssertion xmlPrimtiveAssertion = new XmlPrimtiveAssertion(
+ childElement);
+ operator.addPolicyComponent(xmlPrimtiveAssertion);
+
+ } else {
+ operator.addPolicyComponent(builder.build(childElement,
+ factory));
+ }
+ }
+ }
+ return operator;
+ }
+}
Modified: webservices/commons/trunk/modules/neethi/src/org/apache/neethi/XmlPrimtiveAssertion.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/neethi/src/org/apache/neethi/XmlPrimtiveAssertion.java?rev=423853&r1=423852&r2=423853&view=diff
==============================================================================
--- webservices/commons/trunk/modules/neethi/src/org/apache/neethi/XmlPrimtiveAssertion.java (original)
+++ webservices/commons/trunk/modules/neethi/src/org/apache/neethi/XmlPrimtiveAssertion.java Thu Jul 20 02:34:07 2006
@@ -22,7 +22,7 @@
import org.apache.axiom.om.OMAttribute;
import org.apache.axiom.om.OMElement;
-public class XmlPrimtiveAssertion implements PrimitiveAssertion {
+public class XmlPrimtiveAssertion implements Assertion {
OMElement element;
boolean isOptional;
Modified: webservices/commons/trunk/modules/neethi/test3/org/apache/neethi/NormalizeTest.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/neethi/test3/org/apache/neethi/NormalizeTest.java?rev=423853&r1=423852&r2=423853&view=diff
==============================================================================
--- webservices/commons/trunk/modules/neethi/test3/org/apache/neethi/NormalizeTest.java (original)
+++ webservices/commons/trunk/modules/neethi/test3/org/apache/neethi/NormalizeTest.java Thu Jul 20 02:34:07 2006
@@ -24,7 +24,7 @@
public class NormalizeTest extends PolicyTestCase {
- PolicyManager mgr;
+ PolicyEngine mgr;
public NormalizeTest() {
super("NormalizeTest");
@@ -39,10 +39,10 @@
r1 = "samples" + File.separator + "test" + i + ".xml";
r2 = "normalized" + File.separator + "test" + i + ".xml";
- p1 = PolicyManager.getPolicy(getResource(r1));
+ p1 = PolicyEngine.getPolicy(getResource(r1));
test = p1;
p1 = (Policy) p1.normalize(true);
- p2 = PolicyManager.getPolicy(getResource(r2));
+ p2 = PolicyEngine.getPolicy(getResource(r2));
if (!PolicyComparator.compare(p1, p2)) {
XMLStreamWriter writer;
Modified: webservices/commons/trunk/modules/neethi/test3/org/apache/neethi/util/PolicyComparator.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/neethi/test3/org/apache/neethi/util/PolicyComparator.java?rev=423853&r1=423852&r2=423853&view=diff
==============================================================================
--- webservices/commons/trunk/modules/neethi/test3/org/apache/neethi/util/PolicyComparator.java (original)
+++ webservices/commons/trunk/modules/neethi/test3/org/apache/neethi/util/PolicyComparator.java Thu Jul 20 02:34:07 2006
@@ -19,10 +19,10 @@
import java.util.List;
import org.apache.neethi.All;
+import org.apache.neethi.Assertion;
import org.apache.neethi.ExactlyOne;
import org.apache.neethi.Policy;
import org.apache.neethi.PolicyComponent;
-import org.apache.neethi.PrimitiveAssertion;
public class PolicyComparator {
@@ -45,8 +45,8 @@
return compare((ExactlyOne) arg1,
(ExactlyOne) arg2);
- } else if (arg1 instanceof PrimitiveAssertion) {
- return compare((PrimitiveAssertion) arg1, (PrimitiveAssertion) arg2);
+ } else if (arg1 instanceof Assertion) {
+ return compare((Assertion) arg1, (Assertion) arg2);
} else {
// TODO should I throw an exception ..
@@ -65,8 +65,8 @@
return compare(arg1.getPolicyComponents(), arg2.getPolicyComponents());
}
- public static boolean compare(PrimitiveAssertion arg1,
- PrimitiveAssertion arg2) {
+ public static boolean compare(Assertion arg1,
+ Assertion arg2) {
if (!(arg1.getName().equals(arg2.getName()))) {
return false;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: commons-dev-help@ws.apache.org