You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ws.apache.org by we...@apache.org on 2005/12/05 16:05:54 UTC

svn commit: r354081 - /webservices/commons/trunk/policy/src/examples/SimplePolicyExample.java

Author: werner
Date: Mon Dec  5 07:05:52 2005
New Revision: 354081

URL: http://svn.apache.org/viewcvs?rev=354081&view=rev
Log:
First very simple example used to test the basic features.

Added:
    webservices/commons/trunk/policy/src/examples/SimplePolicyExample.java

Added: webservices/commons/trunk/policy/src/examples/SimplePolicyExample.java
URL: http://svn.apache.org/viewcvs/webservices/commons/trunk/policy/src/examples/SimplePolicyExample.java?rev=354081&view=auto
==============================================================================
--- webservices/commons/trunk/policy/src/examples/SimplePolicyExample.java (added)
+++ webservices/commons/trunk/policy/src/examples/SimplePolicyExample.java Mon Dec  5 07:05:52 2005
@@ -0,0 +1,55 @@
+/*
+ * Copyright 2004,2005 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 examples;
+
+import java.io.ByteArrayOutputStream;
+import java.io.FileInputStream;
+
+import org.apache.ws.policy.model.Policy;
+import org.apache.ws.policy.util.PolicyFactory;
+import org.apache.ws.policy.util.PolicyReader;
+import org.apache.ws.policy.util.PolicyWriter;
+
+/**
+ * @author Werner Dittmann (werner@apache.org)
+ */
+
+public class SimplePolicyExample {
+
+	public static void main(String[] args) throws Exception {
+
+		FileInputStream fis = null;
+		if (args.length > 0) {
+			fis = new FileInputStream(args[0]);			
+		}
+		else {
+			fis = new FileInputStream("policy/src/examples/policy2.xml");
+		}
+
+		PolicyReader prdr = PolicyFactory.getInstance().getPolicyReader();
+	    PolicyWriter pwrt = PolicyFactory.getInstance().getPolicyWriter();
+	    
+	    Policy argOne = prdr.readPolicy(fis);
+	    Policy norm  = (Policy)argOne.normalize();
+	    
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        pwrt.writePolicy(norm, baos);
+
+		System.out.println(baos.toString());
+	}
+}
+