axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ntha...@apache.org
Subject svn commit: r498794 - in /webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message: databinding/ClassFinder.java databinding/JAXBUtils.java databinding/impl/ClassFinderImpl.java factory/ClassFinderFactory.java
Date Mon, 22 Jan 2007 20:50:45 GMT
Author: nthaker
Date: Mon Jan 22 12:50:44 2007
New Revision: 498794

URL: http://svn.apache.org/viewvc?view=rev&rev=498794
Log:
AXIS2-1989
Adding ClassFinder interface to read JAXB Classes from a jar file.

Added:
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/ClassFinder.java
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/impl/ClassFinderImpl.java
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/factory/ClassFinderFactory.java
Modified:
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/JAXBUtils.java

Added: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/ClassFinder.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/ClassFinder.java?view=auto&rev=498794
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/ClassFinder.java
(added)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/ClassFinder.java
Mon Jan 22 12:50:44 2007
@@ -0,0 +1,37 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ * Copyright 2006 International Business Machines Corp.
+ *
+ * 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.axis2.jaxws.message.databinding;
+
+import java.util.ArrayList;
+/*
+ * ClassFinder will be used to find classes within a given package. The given 
+ * package can be found in a Directory or in a jar file. ClassFinder will use the 
+ * ClassLoader to get the classes from the jar files. 
+ */
+
+public interface ClassFinder {
+	
+	
+	/** This method reads all the classes from given package in a jar file. 
+	 * It uses ClassLoader to find the given package in a jar file that is located
+	 * in classpath. 
+	 * @param pkg
+	 * @param cl
+	 * @return
+	 */
+	ArrayList<Class> getClassesFromJarFile(String pkg, ClassLoader cl)throws ClassNotFoundException;
+}

Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/JAXBUtils.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/JAXBUtils.java?view=diff&rev=498794&r1=498793&r2=498794
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/JAXBUtils.java
(original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/JAXBUtils.java
Mon Jan 22 12:50:44 2007
@@ -41,6 +41,7 @@
 import javax.xml.bind.Unmarshaller;
 
 import org.apache.axis2.jaxws.i18n.Messages;
+import org.apache.axis2.jaxws.message.factory.ClassFinderFactory;
 import org.apache.axis2.jaxws.util.ClassUtils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -454,8 +455,12 @@
         	 e.printStackTrace();            
         }
         try {
-            //This will load classes from jar file.
-            classes.addAll(getClassesFromJarFile(pkg, cl));
+           //If Calsses not found in directory then look for jar that has these classes
+        	if(classes.size() <=0){
+        		//This will load classes from jar file.
+	        	ClassFinder cf = ClassFinderFactory.getClassFinder();
+	            classes.addAll(cf.getClassesFromJarFile(pkg, cl));
+        	}
         } catch (ClassNotFoundException e) {
         	 if(log.isDebugEnabled()){
                  log.debug("getClassesFromJarFile failed to get Classes");
@@ -545,68 +550,6 @@
         return classes;
     }
     
-    private static ArrayList<Class> getClassesFromJarFile(String pkg, ClassLoader cl)throws
ClassNotFoundException{
-        try {
-    	ArrayList<Class> classes = new ArrayList<Class>();
-    	URLClassLoader ucl = (URLClassLoader)cl;
-        URL[] srcURL = ucl.getURLs();
-        String path = pkg.replace('.', '/');
-        //Read resources as URL from class loader.
-        for(URL url:srcURL){
-        	if("file".equals(url.getProtocol())){
-        		File f = new File(url.getPath());
-        		//If file is not of type directory then its a jar file
-        		if(f.exists() && !f.isDirectory()){
-        			try{
-	        			JarFile jf = new JarFile(f);
-	        			Enumeration<JarEntry> entries = jf.entries();
-	        			//read all entries in jar file
-	        			while(entries.hasMoreElements()){
-	        				JarEntry je = entries.nextElement();
-	        				String clazzName = je.getName();
-	        				if(clazzName!=null && clazzName.endsWith(".class")){
-		        				//Add to class list here.
-		        				clazzName = clazzName.substring (0, clazzName.length() - 6);
-		        	            clazzName = clazzName.replace ('/', '.').replace ('\\', '.').replace
(':', '.');
-		        	            //We are only going to add the class that belong to the provided package.
-		        				if(clazzName.startsWith(pkg)){
-	        						 try {
-	        	                            Class clazz = Class.forName(clazzName, 
-	        	                                    false, 
-	        	                                    Thread.currentThread().getContextClassLoader());
-	        	                            // Don't add any interfaces or JAXWS specific classes.
 
-	        	                            // Only classes that represent data and can be marshalled

-	        	                            // by JAXB should be added.
-	        	                            if(!clazz.isInterface()
-	        	                                    && ClassUtils.getDefaultPublicConstructor(clazz)
!= null
-	        	                                    && !ClassUtils.isJAXWSClass(clazz)){
-	        	                                if (log.isDebugEnabled()) {
-	        	                                    log.debug("Adding class: " + clazzName);
-	        	                                }
-	        	                                classes.add(clazz);
-	        	                                
-	        	                            }
-	        	                        } catch (Exception e) {
-	        	                            if (log.isDebugEnabled()) {
-	        	                                log.debug("Tried to load class " + clazzName +
" while constructing a JAXBContext.  This class will be skipped.  Processing Continues." );
-	        	                                log.debug("  The reason that class could not be
loaded:" + e.toString());
-	        	                            }
-	        	                            e.printStackTrace();
-	        	                        }
-	        					}
-	        				}
-	        			}
-        			}catch(IOException e){
-        				throw new ClassNotFoundException(Messages.getMessage("ClassUtilsErr4"));
-        			}
-        		}
-        	}
-        }
-    	return classes;
-        } catch (Exception e) {
-            throw new ClassNotFoundException(e.getMessage());
-        }
-    }
     private static  String[] commonArrayClasses = new String[] { 
         // primitives
         "boolean[]",

Added: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/impl/ClassFinderImpl.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/impl/ClassFinderImpl.java?view=auto&rev=498794
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/impl/ClassFinderImpl.java
(added)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/impl/ClassFinderImpl.java
Mon Jan 22 12:50:44 2007
@@ -0,0 +1,106 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ * Copyright 2006 International Business Machines Corp.
+ *
+ * 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.axis2.jaxws.message.databinding.impl;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.net.URLDecoder;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.jar.JarEntry;
+import java.util.jar.JarFile;
+
+import org.apache.axis2.jaxws.i18n.Messages;
+import org.apache.axis2.jaxws.message.databinding.ClassFinder;
+import org.apache.axis2.jaxws.util.ClassUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+
+public class ClassFinderImpl implements ClassFinder {
+	private static final Log log = LogFactory.getLog(ClassFinderImpl.class);
+	/* (non-Javadoc)
+	 * @see org.apache.axis2.jaxws.message.databinding.ClassFinder#getClassesFromJarFile(java.lang.String,
java.lang.ClassLoader)
+	 */
+	public ArrayList<Class> getClassesFromJarFile(String pkg, ClassLoader cl) throws ClassNotFoundException
{
+		try {
+	    	ArrayList<Class> classes = new ArrayList<Class>();
+	    	URLClassLoader ucl = (URLClassLoader)cl;
+	        URL[] srcURL = ucl.getURLs();
+	        String path = pkg.replace('.', '/');
+	        //Read resources as URL from class loader.
+	        for(URL url:srcURL){
+	        	if("file".equals(url.getProtocol())){
+	        		File f = new File(url.getPath());
+	        		//If file is not of type directory then its a jar file
+	        		if(f.exists() && !f.isDirectory()){
+	        			try{
+		        			JarFile jf = new JarFile(f);
+		        			Enumeration<JarEntry> entries = jf.entries();
+		        			//read all entries in jar file
+		        			while(entries.hasMoreElements()){
+		        				JarEntry je = entries.nextElement();
+		        				String clazzName = je.getName();
+		        				if(clazzName!=null && clazzName.endsWith(".class")){
+			        				//Add to class list here.
+			        				clazzName = clazzName.substring (0, clazzName.length() - 6);
+			        	            clazzName = clazzName.replace ('/', '.').replace ('\\', '.').replace
(':', '.');
+			        	            //We are only going to add the class that belong to the provided
package.
+			        				if(clazzName.startsWith(pkg)){
+			        					try {
+		        							 Class clazz = Class.forName(clazzName, 
+		        	                                    false, 
+		        	                                    Thread.currentThread().getContextClassLoader());
+		        	                            // Don't add any interfaces or JAXWS specific classes.
 
+		        	                            // Only classes that represent data and can be marshalled

+		        	                            // by JAXB should be added.
+		        	                         if(!clazz.isInterface()
+		        	                                 && ClassUtils.getDefaultPublicConstructor(clazz)
!= null
+		        	                                 && !ClassUtils.isJAXWSClass(clazz)){
+		        	                             if (log.isDebugEnabled()) {
+		        	                                 log.debug("Adding class: " + clazzName);
+		        	                             }
+		        	                             classes.add(clazz);
+		        	                             
+		        	                         }
+		        	                       }catch (Exception e) {
+		        	                         if (log.isDebugEnabled()) {
+		        	                             log.debug("Tried to load class " + clazzName + "
while constructing a JAXBContext.  This class will be skipped.  Processing Continues." );
+		        	                             log.debug("  The reason that class could not be loaded:"
+ e.toString());
+		        	                         }
+		        	                         e.printStackTrace();
+		        	                       }
+		        					}
+		        				}
+		        			}
+	        			}catch(IOException e){
+	        				throw new ClassNotFoundException(Messages.getMessage("ClassUtilsErr4"));
+	        			}
+	        		}
+	        	}
+	        }
+	        return classes;
+	    } catch (Exception e) {
+	           throw new ClassNotFoundException(e.getMessage());
+	    }
+	   
+	}
+
+}

Added: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/factory/ClassFinderFactory.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/factory/ClassFinderFactory.java?view=auto&rev=498794
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/factory/ClassFinderFactory.java
(added)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/factory/ClassFinderFactory.java
Mon Jan 22 12:50:44 2007
@@ -0,0 +1,30 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ * Copyright 2006 International Business Machines Corp.
+ *
+ * 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.axis2.jaxws.message.factory;
+
+import org.apache.axis2.jaxws.message.databinding.ClassFinder;
+import org.apache.axis2.jaxws.message.databinding.impl.ClassFinderImpl;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+
+public class ClassFinderFactory {
+	private static final Log log = LogFactory.getLog(ClassFinderFactory.class);
+	public static ClassFinder getClassFinder(){
+		return new ClassFinderImpl();
+	}
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org


Mime
View raw message