Author: werner
Date: Fri Dec  9 06:45:56 2005
New Revision: 355504

URL: http://svn.apache.org/viewcvs?rev=355504&view=rev
Log:
Add Loader class from WSS4J, use real "on-the-fly" class
loading in PolicyFactory to enable real plug-in and be
independent of specifc XML parser.

Modified:
    
webservices/commons/trunk/policy/src/org/apache/ws/policy/util/PolicyFactory.java

Modified: 
webservices/commons/trunk/policy/src/org/apache/ws/policy/util/PolicyFactory.java
URL: 
http://svn.apache.org/viewcvs/webservices/commons/trunk/policy/src/org/apache/ws/policy/util/PolicyFactory.java?rev=355504&r1=355503&r2=355504&view=diff
==============================================================================
--- 
webservices/commons/trunk/policy/src/org/apache/ws/policy/util/PolicyFactory.java
 (original)
+++ 
webservices/commons/trunk/policy/src/org/apache/ws/policy/util/PolicyFactory.java
 Fri Dec  9 06:45:56 2005
@@ -27,18 +27,46 @@
     
     
     public static PolicyReader getPolicyReader(int type) {
+       String name = null;
         switch (type) {
         case DOM_POLICY_READER:
-            return new DOMPolicyReader();
+               name = "org.apache.ws.policy.util.DOMPolicyReader";
+               break;
         case OM_POLICY_READER:
-            return new OMPolicyReader();
+               name = "org.apache.ws.policy.util.OMPolicyReader";
+               break;
         default: 
-            throw new IllegalArgumentException("Unknow PolicyReader type ..");
+            throw new IllegalArgumentException("Unknown PolicyReader type ..");
         }
+        try {
+                       return 
(PolicyReader)Loader.loadClass(name).newInstance();
+               } catch (InstantiationException e) {
+            throw new IllegalArgumentException("Cannot load PolicyReader type 
..");
+               } catch (IllegalAccessException e) {
+            throw new IllegalArgumentException("Cannot load PolicyReader type 
..");
+               } catch (ClassNotFoundException e) {
+            throw new IllegalArgumentException("Cannot load PolicyReader type 
..");
+               }
     }
     
-    public static PolicyWriter getPolicyWriter() {
-        return new StAXPolicyWriter();
+    public static PolicyWriter getPolicyWriter(int type) {
+       String name = null;
+        switch (type) {
+        case StAX_POLICY_WRITER:
+               name = "org.apache.ws.policy.util.StAXPolicyWriter";
+               break;
+        default: 
+            throw new IllegalArgumentException("Unknown PolicyWriter type ..");
+        }
+        try {
+                       return 
(PolicyWriter)Loader.loadClass(name).newInstance();
+               } catch (InstantiationException e) {
+            throw new IllegalArgumentException("Cannot load PolicyWriter type 
..");
+               } catch (IllegalAccessException e) {
+            throw new IllegalArgumentException("Cannot load PolicyWriter type 
..");
+               } catch (ClassNotFoundException e) {
+            throw new IllegalArgumentException("Cannot load PolicyWriter type 
..");
+               }
     }
     
 }


Reply via email to