You are viewing a plain text version of this content. The canonical link for it is here.
Posted to axis-cvs@ws.apache.org by aj...@apache.org on 2005/05/06 08:04:23 UTC
svn commit: r168530 - in
/webservices/axis/trunk/archive/java/scratch/policy/src: ./ org/
org/apache/ org/apache/policy/ org/apache/policy/model/
org/apache/policy/parser/
Author: ajith
Date: Thu May 5 23:04:23 2005
New Revision: 168530
URL: http://svn.apache.org/viewcvs?rev=168530&view=rev
Log:
Adding the source for the policy implementation. I have made a small change to the code to make it work with the latest OM changes.
Added:
webservices/axis/trunk/archive/java/scratch/policy/src/
webservices/axis/trunk/archive/java/scratch/policy/src/org/
webservices/axis/trunk/archive/java/scratch/policy/src/org/apache/
webservices/axis/trunk/archive/java/scratch/policy/src/org/apache/policy/
webservices/axis/trunk/archive/java/scratch/policy/src/org/apache/policy/model/
webservices/axis/trunk/archive/java/scratch/policy/src/org/apache/policy/model/AndCompositeAssertion.class (with props)
webservices/axis/trunk/archive/java/scratch/policy/src/org/apache/policy/model/AndCompositeAssertion.java
webservices/axis/trunk/archive/java/scratch/policy/src/org/apache/policy/model/Assertion.class (with props)
webservices/axis/trunk/archive/java/scratch/policy/src/org/apache/policy/model/Assertion.java
webservices/axis/trunk/archive/java/scratch/policy/src/org/apache/policy/model/CompositeAssertion.class (with props)
webservices/axis/trunk/archive/java/scratch/policy/src/org/apache/policy/model/CompositeAssertion.java
webservices/axis/trunk/archive/java/scratch/policy/src/org/apache/policy/model/PrimitiveAssertion.class (with props)
webservices/axis/trunk/archive/java/scratch/policy/src/org/apache/policy/model/PrimitiveAssertion.java
webservices/axis/trunk/archive/java/scratch/policy/src/org/apache/policy/model/XORCompositeAssertion.class (with props)
webservices/axis/trunk/archive/java/scratch/policy/src/org/apache/policy/model/XORCompositeAssertion.java
webservices/axis/trunk/archive/java/scratch/policy/src/org/apache/policy/parser/
webservices/axis/trunk/archive/java/scratch/policy/src/org/apache/policy/parser/WSPConstants.class (with props)
webservices/axis/trunk/archive/java/scratch/policy/src/org/apache/policy/parser/WSPConstants.java
webservices/axis/trunk/archive/java/scratch/policy/src/org/apache/policy/parser/WSPolicyParser.class (with props)
webservices/axis/trunk/archive/java/scratch/policy/src/org/apache/policy/parser/WSPolicyParser.java
Added: webservices/axis/trunk/archive/java/scratch/policy/src/org/apache/policy/model/AndCompositeAssertion.class
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/archive/java/scratch/policy/src/org/apache/policy/model/AndCompositeAssertion.class?rev=168530&view=auto
==============================================================================
Binary file - no diff available.
Propchange: webservices/axis/trunk/archive/java/scratch/policy/src/org/apache/policy/model/AndCompositeAssertion.class
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: webservices/axis/trunk/archive/java/scratch/policy/src/org/apache/policy/model/AndCompositeAssertion.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/archive/java/scratch/policy/src/org/apache/policy/model/AndCompositeAssertion.java?rev=168530&view=auto
==============================================================================
--- webservices/axis/trunk/archive/java/scratch/policy/src/org/apache/policy/model/AndCompositeAssertion.java (added)
+++ webservices/axis/trunk/archive/java/scratch/policy/src/org/apache/policy/model/AndCompositeAssertion.java Thu May 5 23:04:23 2005
@@ -0,0 +1,288 @@
+/*
+ * 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.policy.model;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.xml.namespace.QName;
+
+/**
+ * AndCompositeAssertion represents either policy or a single policy
+ * alternative. It requires that all its terms are satisfied.
+ *
+ * @author Nilupa Bandara <ni...@gmail.com>
+ * @author Sanka Samaranayake <ss...@gmail.com>
+ */
+public class AndCompositeAssertion extends CompositeAssertion implements Assertion {
+
+ public AndCompositeAssertion() {
+ }
+
+ public Assertion intersect(Assertion assertion) {
+
+ CompositeAssertion target = (CompositeAssertion) assertion;
+
+ target = (CompositeAssertion) ((target.isNormalized()) ? target : target.normalize());
+ CompositeAssertion normalizedMe = (CompositeAssertion) ((isNormalized()) ? this : normalize());
+
+ // if (!(normalizedMe instanceof AndCompositeAssertion)) {
+ // return normalizedMe.intersect(target);
+ // }
+ // if (!(target instanceof AndCompositeAssertion)) {
+ // return target.intersect(normalizedMe);
+ // }
+
+ AndCompositeAssertion retANDterm = new AndCompositeAssertion();
+
+ if (normalizedMe.getOwner() != null && target.getOwner() != null) {
+
+ if (normalizedMe.isEmpty()) { // empty alternative
+ return target;
+
+ } else if (target.isEmpty()) {
+ return normalizedMe;
+
+ } else {
+ List primTermsA = ((size() > target.size()) ? normalizedMe.getTerms() : target.getTerms());
+ List primTermsB = ((size() > target.size()) ? target.getTerms() : normalizedMe.getTerms());
+
+ boolean match = true;
+ PrimitiveAssertion primTermA, primTermB;
+ QName qnameA, qnameB;
+
+ for (int i = 0; i < primTermsA.size(); i++) {
+ primTermA = (PrimitiveAssertion) primTermsA.get(i);
+ qnameA = primTermA.getName();
+ boolean flag = false;
+
+ for (int j = 0; j < primTermsB.size(); j++) {
+ primTermB = (PrimitiveAssertion) primTermsB.get(j);
+ qnameB = primTermB.getName();
+ if (qnameA.equals(qnameB)) {
+ flag = true;
+ break;
+ }
+ }
+ if (!flag) {
+ match = false;
+ break;
+ }
+ }
+
+ if (match) { // vocabulary matches
+ retANDterm.addTerms(primTermsA);
+ retANDterm.addTerms(primTermsB);
+ }
+ return retANDterm;
+ }
+
+ // } else if (normalizedMe.getOwner() != null && target.getOwner() != null) {
+ // XORCompositeAssertion XORterm;
+
+ // if (normalizedMe.getOwner() != null) {
+
+ // XORterm = (XORCompositeAssertion) target.getTerms().get(0);
+ // retANDterm.addTerm(XORterm.intersect(normalizedMe));
+
+ // } else {
+ // XORterm = (XORCompositeAssertion) normalizedMe.getTerms().get(0);
+ // retANDterm.addTerm(XORterm.intersect(target));
+ // }
+ // return retANDterm;
+
+ } else {
+ XORCompositeAssertion argOne = (XORCompositeAssertion) normalizedMe.getTerms().get(0),
+ argTwo = (XORCompositeAssertion) target.getTerms().get(0);
+ retANDterm.addTerm(argOne.intersect(argTwo));
+ return retANDterm;
+ }
+ }
+
+ public Assertion merge(Assertion assertion) {
+ CompositeAssertion target = (CompositeAssertion) assertion;
+
+ target = (CompositeAssertion) ((target.isNormalized()) ? target : target.normalize());
+ CompositeAssertion normalizedMe = (CompositeAssertion) ((isNormalized()) ? this : normalize());
+
+ // if (!(normalizedMe instanceof AndCompositeAssertion)) {
+ // return normalizedMe.intersect(target);
+ // }
+ // if (!(target instanceof AndCompositeAssertion)) {
+ // return target.intersect(normalizedMe);
+ // }
+
+ AndCompositeAssertion retANDterm = new AndCompositeAssertion();
+
+ if (normalizedMe.getOwner() != null && target.getOwner() != null) {
+ retANDterm.addTerms(normalizedMe.getTerms());
+ retANDterm.addTerms(target.getTerms());
+
+ } else {
+ XORCompositeAssertion argOne = (XORCompositeAssertion) normalizedMe.getTerms().get(0),
+ argTwo = (XORCompositeAssertion) target.getTerms().get(0);
+ retANDterm.addTerm(argOne.merge(argTwo));
+
+ }
+
+ return retANDterm;
+ }
+
+ public Assertion normalize() {
+ AndCompositeAssertion retANDterm = new AndCompositeAssertion();
+ XORCompositeAssertion retXORterm = new XORCompositeAssertion();
+
+ ArrayList ANDtermList = new ArrayList();
+ ArrayList XORtermList = new ArrayList();
+
+ Iterator myTerms = getTerms().iterator();
+
+ while (myTerms.hasNext()) {
+ Object term = myTerms.next();
+
+ if (term instanceof PrimitiveAssertion) {
+ retANDterm.addTerm((Assertion) term);
+
+ } else if (term instanceof CompositeAssertion) {
+ CompositeAssertion cterm = (CompositeAssertion) term;
+
+ cterm =((cterm.isNormalized()) ? cterm :(CompositeAssertion) cterm.normalize());
+
+ if (cterm instanceof AndCompositeAssertion) {
+ ANDtermList.add(cterm);
+ } else {
+ XORtermList.add(cterm);
+ }
+ }
+ }
+
+ // processing AND logic
+
+ if (! ANDtermList.isEmpty()) {
+ Iterator ANDterms = ANDtermList.iterator();
+
+ while (ANDterms.hasNext()) {
+ CompositeAssertion ANDterm = (CompositeAssertion) ANDterms.next();
+
+ /*
+ * since these CompositeAssertions are normalized,
+ * child-assertions should be primitives which adds to a single
+ * and logic
+ */
+ Iterator primTerms = ANDterm.getTerms().iterator();
+
+ while (primTerms.hasNext()) {
+ retANDterm.addTerm((Assertion) primTerms.next());
+ }
+ }
+ }
+
+ if (XORtermList.size() > 1) {
+
+ outer : for (int i = 0; i < XORtermList.size(); i++) {
+ inner : for (int j = i; j < XORtermList.size(); j++) {
+ if (i != j) {
+ XORCompositeAssertion XORtermA = (XORCompositeAssertion) XORtermList.get(i);
+ XORCompositeAssertion XORtermB = (XORCompositeAssertion) XORtermList.get(j);
+
+ // what if xor1 or xor2 is empty
+ if (XORtermA.isEmpty() || XORtermB.isEmpty()) {
+ retXORterm = new XORCompositeAssertion();
+ break outer;
+ }
+ Iterator iterA = XORtermA.getTerms().iterator();
+
+ while (iterA.hasNext()) {
+ // must be a AND
+ CompositeAssertion ANDtermA = (CompositeAssertion) iterA.next();
+ Iterator iterB = XORtermB.getTerms().iterator();
+ while (iterB.hasNext()) {
+ // must be a AND
+ CompositeAssertion ANDtermB = (CompositeAssertion) iterB.next();
+
+ AndCompositeAssertion ANDterm = new AndCompositeAssertion();
+ ANDterm.addTerms(ANDtermA.getTerms());
+ ANDterm.addTerms(ANDtermB.getTerms());
+ retXORterm.addTerm(ANDterm);
+ }
+ }
+
+ }
+ }
+ }
+
+ } else if (XORtermList.size() == 1) {
+
+ CompositeAssertion XORterm = (CompositeAssertion) XORtermList.get(0);
+ retXORterm.addTerms(XORterm.getTerms());
+ }
+
+ if (!XORtermList.isEmpty()) {
+
+ if (!retANDterm.isEmpty()) {
+
+ // get list of primitive assertions form result (AndCompositeAssertion)
+ List primTerms = retANDterm.getTerms();
+
+ // these terms should be AndCompositeAssertions
+ Iterator ANDterms = retXORterm.getTerms().iterator();
+
+ while (ANDterms.hasNext()) {
+ CompositeAssertion ANDterm = (CompositeAssertion) ANDterms.next();
+ ANDterm.addTerms(primTerms);
+ }
+ }
+
+ if (getOwner() == null) {
+
+ // self is a root .. hence we wrap the XORterm in an ANDterm
+ AndCompositeAssertion ANDterm = new AndCompositeAssertion();
+ ANDterm.addTerm(retXORterm);
+ ANDterm.isNormalized(true);
+ return ANDterm;
+ }
+
+ // if (xorLogic.isEmpty()) {
+ // xor logic is empty and self is not the root
+ // hence it should proceed as an empty Alternative
+ // AndCompositeAssertion andlogic = new AndCompositeAssertion();
+ // andLogic.isNormalized(true);
+ // return andLogic;
+ // }
+
+ retXORterm.isNormalized(true);
+ return retXORterm;
+
+ } else {
+
+ if (getOwner() == null) {
+
+ // self is a root .. hence we should wrap the ANDterm in a XORterm and then
+ // in an ANDterm
+ AndCompositeAssertion ANDterm = new AndCompositeAssertion();
+ XORCompositeAssertion XORterm = new XORCompositeAssertion();
+ XORterm.addTerm(retANDterm);
+ ANDterm.addTerm(XORterm);
+ ANDterm.isNormalized(true);
+ return ANDterm;
+ }
+ retANDterm.isNormalized(true);
+ return retANDterm;
+ }
+ }
+}
Added: webservices/axis/trunk/archive/java/scratch/policy/src/org/apache/policy/model/Assertion.class
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/archive/java/scratch/policy/src/org/apache/policy/model/Assertion.class?rev=168530&view=auto
==============================================================================
Binary file - no diff available.
Propchange: webservices/axis/trunk/archive/java/scratch/policy/src/org/apache/policy/model/Assertion.class
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: webservices/axis/trunk/archive/java/scratch/policy/src/org/apache/policy/model/Assertion.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/archive/java/scratch/policy/src/org/apache/policy/model/Assertion.java?rev=168530&view=auto
==============================================================================
--- webservices/axis/trunk/archive/java/scratch/policy/src/org/apache/policy/model/Assertion.java (added)
+++ webservices/axis/trunk/archive/java/scratch/policy/src/org/apache/policy/model/Assertion.java Thu May 5 23:04:23 2005
@@ -0,0 +1,70 @@
+/*
+ * 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.policy.model;
+
+/**
+ *
+ * @author Nilupa Bandara <ni...@gmail.com>
+ *
+ */
+public interface Assertion {
+ /** Defines the short value for Primitive Assertions */
+ public static final short PRIMITIVE_TYPE = 0x1;
+
+ /** Defines the short value for ANDCompositeAssertion */
+ public static final short COMPOSITE_AND_TYPE = 0x2;
+
+ /** Defines the short value for XORCompositeAssertion*/
+ public static final short COMPOSITE_XOR_TYPE = 0x3;
+
+ /**
+ *
+ * @return
+ */
+ public Assertion normalize() throws UnsupportedOperationException;
+
+ /**
+ *
+ * @param assertion
+ * @return
+ */
+ public Assertion intersect(Assertion assertion) throws UnsupportedOperationException;
+
+ /**
+ *
+ * @param assertion
+ * @return
+ */
+ public Assertion merge(Assertion assertion) throws UnsupportedOperationException;
+
+ /**
+ *
+ * @return
+ */
+ public boolean hasOwner();
+
+ /**
+ *
+ * @return
+ */
+ public Assertion getOwner();
+
+ /**
+ *
+ * @param parent
+ */
+ public void setOwner(Assertion parent);
+}
Added: webservices/axis/trunk/archive/java/scratch/policy/src/org/apache/policy/model/CompositeAssertion.class
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/archive/java/scratch/policy/src/org/apache/policy/model/CompositeAssertion.class?rev=168530&view=auto
==============================================================================
Binary file - no diff available.
Propchange: webservices/axis/trunk/archive/java/scratch/policy/src/org/apache/policy/model/CompositeAssertion.class
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: webservices/axis/trunk/archive/java/scratch/policy/src/org/apache/policy/model/CompositeAssertion.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/archive/java/scratch/policy/src/org/apache/policy/model/CompositeAssertion.java?rev=168530&view=auto
==============================================================================
--- webservices/axis/trunk/archive/java/scratch/policy/src/org/apache/policy/model/CompositeAssertion.java (added)
+++ webservices/axis/trunk/archive/java/scratch/policy/src/org/apache/policy/model/CompositeAssertion.java Thu May 5 23:04:23 2005
@@ -0,0 +1,100 @@
+/*
+ * 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.policy.model;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ *
+ * @author Nilupa Bandara <ni...@gmail.com>
+ * @author Sanka Samaranayake <ss...@gmail.com>
+ */
+public abstract class CompositeAssertion implements Assertion {
+
+ /** */
+ protected boolean flag = false;
+
+ /** */
+ private List list = new ArrayList();
+
+ /** */
+ private Assertion owner = null;
+
+ public void addTerm(Assertion assertion){
+ assertion.setOwner(this);
+ list.add(assertion);
+ }
+
+ public void addTerms(List assertions) {
+ Iterator items = assertions.iterator();
+
+ while (items.hasNext()) {
+ Object value = items.next();
+
+ if (!(value instanceof Assertion)) {
+ throw new IllegalArgumentException("argument contains a " +
+ "non-assertion");
+ }
+ addTerm((Assertion) value);
+ }
+ }
+
+ public List getTerms() {
+ return list;
+ }
+
+ public boolean isEmpty() {
+ return list.size() == 0;
+ }
+
+ public boolean remove(Assertion assertion) {
+ return list.remove(assertion);
+ }
+
+ public int size() {
+ return list.size();
+ }
+
+ public boolean hasOwner() {
+ return owner != null;
+ }
+
+ public Assertion getOwner() {
+ return owner;
+ }
+
+ public void setOwner(Assertion parent) {
+ this.owner = parent;
+ }
+
+ protected boolean isNormalized() {
+ return flag;
+ }
+
+ protected void isNormalized(boolean value) {
+ Iterator children = getTerms().iterator();
+
+ while (children.hasNext()) {
+ Object child = children.next();
+ if (child instanceof CompositeAssertion) {
+ ((CompositeAssertion) child).isNormalized(true);
+ }
+ }
+ flag = value;
+ }
+}
Added: webservices/axis/trunk/archive/java/scratch/policy/src/org/apache/policy/model/PrimitiveAssertion.class
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/archive/java/scratch/policy/src/org/apache/policy/model/PrimitiveAssertion.class?rev=168530&view=auto
==============================================================================
Binary file - no diff available.
Propchange: webservices/axis/trunk/archive/java/scratch/policy/src/org/apache/policy/model/PrimitiveAssertion.class
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: webservices/axis/trunk/archive/java/scratch/policy/src/org/apache/policy/model/PrimitiveAssertion.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/archive/java/scratch/policy/src/org/apache/policy/model/PrimitiveAssertion.java?rev=168530&view=auto
==============================================================================
--- webservices/axis/trunk/archive/java/scratch/policy/src/org/apache/policy/model/PrimitiveAssertion.java (added)
+++ webservices/axis/trunk/archive/java/scratch/policy/src/org/apache/policy/model/PrimitiveAssertion.java Thu May 5 23:04:23 2005
@@ -0,0 +1,70 @@
+/*
+ * 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.policy.model;
+
+import javax.xml.namespace.QName;
+
+import org.apache.axis.om.OMElement;
+
+/**
+ *
+ * @author Nilupa Bandara <ni...@gmail.com>
+ */
+public class PrimitiveAssertion implements Assertion {
+ private Assertion owner = null;
+ private QName qname;
+ private OMElement value;
+
+ public PrimitiveAssertion(OMElement value) {
+ this.value = value;
+ this.qname = new QName(value.getNamespace().getName() , value.getLocalName());
+ }
+
+ public QName getName() {
+ return qname;
+ }
+
+ public OMElement getValue() {
+ return value;
+ }
+
+ public Assertion intersect(Assertion assertion) {
+ throw new UnsupportedOperationException("intersect is not supported " +
+ "in primitive assertions");
+ }
+
+ public Assertion merge(Assertion assertion) {
+ throw new UnsupportedOperationException("merge is not supported in " +
+ "primivite assertions");
+ }
+
+ public Assertion normalize() {
+ throw new UnsupportedOperationException("normalize is not supported " +
+ "in primitive assertions");
+ }
+
+ public boolean hasOwner() {
+ return owner != null;
+ }
+
+ public Assertion getOwner() {
+ return owner;
+ }
+
+ public void setOwner(Assertion parent) {
+ this.owner = parent;
+ }
+}
Added: webservices/axis/trunk/archive/java/scratch/policy/src/org/apache/policy/model/XORCompositeAssertion.class
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/archive/java/scratch/policy/src/org/apache/policy/model/XORCompositeAssertion.class?rev=168530&view=auto
==============================================================================
Binary file - no diff available.
Propchange: webservices/axis/trunk/archive/java/scratch/policy/src/org/apache/policy/model/XORCompositeAssertion.class
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: webservices/axis/trunk/archive/java/scratch/policy/src/org/apache/policy/model/XORCompositeAssertion.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/archive/java/scratch/policy/src/org/apache/policy/model/XORCompositeAssertion.java?rev=168530&view=auto
==============================================================================
--- webservices/axis/trunk/archive/java/scratch/policy/src/org/apache/policy/model/XORCompositeAssertion.java (added)
+++ webservices/axis/trunk/archive/java/scratch/policy/src/org/apache/policy/model/XORCompositeAssertion.java Thu May 5 23:04:23 2005
@@ -0,0 +1,139 @@
+/*
+ * 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.policy.model;
+
+import java.util.Iterator;
+
+/**
+ * XORCompositeAssertion represents a bunch of policy alternatives. It requires
+ * that exactly one of its terms (policy alternative) is statisfied.
+ *
+ * @author Nilupa Bandara <ni...@gmail.com>
+ * @author Sanka Samaranayake <ss...@gmail.com>
+ */
+public class XORCompositeAssertion extends CompositeAssertion implements Assertion {
+
+ public XORCompositeAssertion() {
+ }
+
+ public Assertion normalize() {
+ XORCompositeAssertion xorLogic = new XORCompositeAssertion();
+ Iterator terms = getTerms().iterator();
+
+ while (terms.hasNext()) {
+ Assertion term = (Assertion) terms.next();
+
+ if (term instanceof PrimitiveAssertion) { // just wrap it in an AND
+ // logic and add
+ AndCompositeAssertion wrapper = new AndCompositeAssertion();
+ wrapper.addTerm(term);
+ xorLogic.addTerm(wrapper);
+ } else {
+ // must be a composite assertion
+ CompositeAssertion cterm = (CompositeAssertion) term;
+ cterm =((cterm.isNormalized()) ? cterm :(CompositeAssertion) cterm.normalize());
+
+ if (cterm instanceof XORCompositeAssertion) {
+ // just adds the child-terms to super
+ xorLogic.addTerms(cterm.getTerms());
+ } else {
+ // must be an AndCompositeAssertion with primitives
+ xorLogic.addTerm(cterm);
+ }
+ }
+ }
+ xorLogic.isNormalized(true);
+ return xorLogic;
+ }
+
+ public Assertion intersect(Assertion assertion) {
+ if (!(assertion instanceof CompositeAssertion)) {
+ throw new IllegalArgumentException("argument can't be a primitive" +
+ " assertion");
+ }
+
+ XORCompositeAssertion retXORterm = new XORCompositeAssertion();
+
+ CompositeAssertion target = (CompositeAssertion) assertion;
+ CompositeAssertion normalizedMe = (CompositeAssertion) ((isNormalized()) ? this : normalize());
+ target = (CompositeAssertion) ((target.isNormalized()) ? target : target.normalize());
+
+ Iterator children = normalizedMe.getTerms().iterator();
+
+ while (children.hasNext()) {
+ CompositeAssertion term = (CompositeAssertion) children.next();
+ CompositeAssertion iterm;
+
+ if (target instanceof AndCompositeAssertion) {
+ iterm = (CompositeAssertion) term.intersect(target);
+
+ if (!iterm.isEmpty()) {
+ retXORterm.addTerm(iterm);
+ }
+
+ } else if (target instanceof XORCompositeAssertion) {
+ Iterator ANDterms = target.getTerms().iterator();
+ Assertion ANDterm;
+
+ while (ANDterms.hasNext()) {
+ ANDterm = (Assertion) ANDterms.next();
+ iterm = (CompositeAssertion) term.intersect(ANDterm);
+
+ if (!iterm.isEmpty()) {
+ retXORterm.addTerm(iterm);
+ }
+ }
+ }
+ }
+
+ return retXORterm;
+ }
+
+ public Assertion merge(Assertion assertion) {
+
+ if (!(assertion instanceof CompositeAssertion)) {
+ throw new IllegalArgumentException("argument can't be a primitive" +
+ " assertion");
+ }
+
+ XORCompositeAssertion retXORterm = new XORCompositeAssertion();
+ CompositeAssertion target = (CompositeAssertion) assertion;
+
+ target = (CompositeAssertion) ((target.isNormalized()) ? target : target.normalize());
+ CompositeAssertion normalizedMe = (CompositeAssertion) ((isNormalized()) ? this : normalize());
+
+ Iterator myTerms = normalizedMe.getTerms().iterator();
+ while (myTerms.hasNext()) {
+ CompositeAssertion term = (CompositeAssertion) myTerms.next();
+
+ if (target instanceof AndCompositeAssertion) {
+ retXORterm.addTerm(term.merge(target));
+
+ } else if (target instanceof XORCompositeAssertion) {
+ Iterator ANDterms = target.getTerms().iterator();
+ Assertion ANDterm;
+
+ while (ANDterms.hasNext()) {
+ ANDterm = (Assertion) ANDterms.next();
+ retXORterm.addTerm(term.merge(ANDterm));
+ }
+ }
+ }
+
+ return retXORterm;
+ }
+}
Added: webservices/axis/trunk/archive/java/scratch/policy/src/org/apache/policy/parser/WSPConstants.class
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/archive/java/scratch/policy/src/org/apache/policy/parser/WSPConstants.class?rev=168530&view=auto
==============================================================================
Binary file - no diff available.
Propchange: webservices/axis/trunk/archive/java/scratch/policy/src/org/apache/policy/parser/WSPConstants.class
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: webservices/axis/trunk/archive/java/scratch/policy/src/org/apache/policy/parser/WSPConstants.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/archive/java/scratch/policy/src/org/apache/policy/parser/WSPConstants.java?rev=168530&view=auto
==============================================================================
--- webservices/axis/trunk/archive/java/scratch/policy/src/org/apache/policy/parser/WSPConstants.java (added)
+++ webservices/axis/trunk/archive/java/scratch/policy/src/org/apache/policy/parser/WSPConstants.java Thu May 5 23:04:23 2005
@@ -0,0 +1,38 @@
+/*
+ * 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.policy.parser;
+
+/**
+ * @author Nilupa Bandara <ni...@gmail.com>
+ * @author Sanka Samaranayake <ss...@gmail.com>
+ *
+ */
+public interface WSPConstants {
+
+ /** */
+ public static final String AND_COMPOSITE_ASSERTION = "All";
+
+ /** */
+ public static final String XOR_COMPOSITE_ASSERTION = "ExactlyOne";
+
+ /** */
+ public static final String WS_POLICY = "Policy";
+
+ /** */
+ public static final String WS_POLICY_NAMESPACE_URI = "http://schemas.xmlsoap.org/ws/2004/09/policy";
+
+}
Added: webservices/axis/trunk/archive/java/scratch/policy/src/org/apache/policy/parser/WSPolicyParser.class
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/archive/java/scratch/policy/src/org/apache/policy/parser/WSPolicyParser.class?rev=168530&view=auto
==============================================================================
Binary file - no diff available.
Propchange: webservices/axis/trunk/archive/java/scratch/policy/src/org/apache/policy/parser/WSPolicyParser.class
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: webservices/axis/trunk/archive/java/scratch/policy/src/org/apache/policy/parser/WSPolicyParser.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/archive/java/scratch/policy/src/org/apache/policy/parser/WSPolicyParser.java?rev=168530&view=auto
==============================================================================
--- webservices/axis/trunk/archive/java/scratch/policy/src/org/apache/policy/parser/WSPolicyParser.java (added)
+++ webservices/axis/trunk/archive/java/scratch/policy/src/org/apache/policy/parser/WSPolicyParser.java Thu May 5 23:04:23 2005
@@ -0,0 +1,124 @@
+/*
+ * 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.policy.parser;
+
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.Iterator;
+
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.axis.om.OMElement;
+import org.apache.axis.om.OMNode;
+import org.apache.axis.om.OMXMLParserWrapper;
+import org.apache.axis.om.OMAbstractFactory;
+import org.apache.axis.om.impl.llom.factory.OMXMLBuilderFactory;
+import org.apache.policy.model.AndCompositeAssertion;
+import org.apache.policy.model.Assertion;
+import org.apache.policy.model.CompositeAssertion;
+import org.apache.policy.model.PrimitiveAssertion;
+import org.apache.policy.model.XORCompositeAssertion;
+
+/**
+ * WSPolicyParser provides methods to build a Policy Model form an InputStream
+ * and to write a Policy Model to an OutputStream.
+ *
+ * @author Nilupa Bandara <ni...@gmail.com>
+ */
+public class WSPolicyParser {
+ public static WSPolicyParser self = null;
+
+ private WSPolicyParser() {
+ }
+
+ public static WSPolicyParser getInstance() {
+ if (self == null) {
+ self = new WSPolicyParser();
+ }
+ return self;
+ }
+
+ public Assertion getModel(InputStream in) {
+ Assertion model = null;
+
+ try {
+ XMLStreamReader xmlr =
+ XMLInputFactory.newInstance().createXMLStreamReader(in);
+ OMXMLParserWrapper builder =
+ OMXMLBuilderFactory.createStAXOMBuilder(OMAbstractFactory.getOMFactory(),xmlr);
+ OMElement root = builder.getDocumentElement();
+ model = getCompositeAssertion(root);
+
+ } catch (XMLStreamException ex) {
+ System.err.println(ex.getMessage()); // should I wrap it and throw a new PolicyException ??
+ }
+ return model;
+ }
+
+ public Assertion getCompositeAssertion(OMElement value) {
+ CompositeAssertion assertion = null;
+
+ if (value.getLocalName().equals(WSPConstants.WS_POLICY)) {
+ assertion = new AndCompositeAssertion();
+ } else if (value.getLocalName().equals(WSPConstants.AND_COMPOSITE_ASSERTION)) {
+ assertion = new AndCompositeAssertion();
+ } else if (value.getLocalName().equals(WSPConstants.XOR_COMPOSITE_ASSERTION)) {
+ assertion = new XORCompositeAssertion();
+ } else {
+ throw new IllegalArgumentException("cannot resolve the argument to" +
+ "a composite assertion");
+ }
+
+ Iterator children = value.getChildren();
+
+ while (children.hasNext()){
+ OMNode node = (OMNode) children.next();
+
+ if (node instanceof OMElement){
+ OMElement ome = (OMElement) node;
+
+ assertion.addTerm(
+ (isCompositeAssertion(ome))
+ ? getCompositeAssertion(ome)
+ : getPrimitiveAssertion(ome)
+ );
+ }
+ }
+ return assertion;
+ }
+
+ public Assertion getPrimitiveAssertion(OMElement value) {
+ return new PrimitiveAssertion(value);
+ }
+
+ public static boolean isCompositeAssertion(OMElement value) {
+
+ return (value.getNamespace().getName().equals(WSPConstants.WS_POLICY_NAMESPACE_URI))
+ && (value.getLocalName().equals(WSPConstants.WS_POLICY)
+ || value.getLocalName().equals(WSPConstants.AND_COMPOSITE_ASSERTION)
+ || value.getLocalName().equals(WSPConstants.XOR_COMPOSITE_ASSERTION));
+ }
+
+
+ /*
+ *
+ */
+ public void printModel(CompositeAssertion model, OutputStream out) {
+ }
+}