You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by cz...@apache.org on 2005/07/07 09:53:21 UTC

svn commit: r209573 - /cocoon/blocks/scratchpad/trunk/java/org/apache/cocoon/components/flow/ws/WebServiceLoader.java

Author: cziegeler
Date: Thu Jul  7 00:53:19 2005
New Revision: 209573

URL: http://svn.apache.org/viewcvs?rev=209573&view=rev
Log:
Implement Disposable and release components

Modified:
    cocoon/blocks/scratchpad/trunk/java/org/apache/cocoon/components/flow/ws/WebServiceLoader.java

Modified: cocoon/blocks/scratchpad/trunk/java/org/apache/cocoon/components/flow/ws/WebServiceLoader.java
URL: http://svn.apache.org/viewcvs/cocoon/blocks/scratchpad/trunk/java/org/apache/cocoon/components/flow/ws/WebServiceLoader.java?rev=209573&r1=209572&r2=209573&view=diff
==============================================================================
--- cocoon/blocks/scratchpad/trunk/java/org/apache/cocoon/components/flow/ws/WebServiceLoader.java (original)
+++ cocoon/blocks/scratchpad/trunk/java/org/apache/cocoon/components/flow/ws/WebServiceLoader.java Thu Jul  7 00:53:19 2005
@@ -1,5 +1,5 @@
 /*
- * Copyright 1999-2004 The Apache Software Foundation.
+ * Copyright 1999-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.
@@ -22,10 +22,11 @@
 
 import javax.wsdl.WSDLException;
 
+import org.apache.avalon.framework.activity.Disposable;
 import org.apache.avalon.framework.context.Context;
 import org.apache.avalon.framework.context.ContextException;
 import org.apache.avalon.framework.context.Contextualizable;
-import org.apache.avalon.framework.logger.AbstractLogEnabled;
+import org.apache.avalon.framework.logger.LogEnabled;
 import org.apache.avalon.framework.logger.Logger;
 import org.apache.avalon.framework.service.ServiceException;
 import org.apache.avalon.framework.service.ServiceManager;
@@ -35,27 +36,35 @@
 import org.apache.axis.wsdl.toJava.Namespaces;
 import org.apache.axis.wsdl.toJava.Utils;
 import org.apache.cocoon.Constants;
+import org.apache.excalibur.source.SourceResolver;
 import org.apache.excalibur.store.Store;
 
 /**
  * Given a WSDL URL generates and compiles client bindings for the requested
  * service endpoint.
  */
-public class WebServiceLoader extends AbstractLogEnabled implements
-        Contextualizable, ThreadSafe, Serviceable {
+public class WebServiceLoader
+implements Contextualizable, ThreadSafe, Serviceable, Disposable, LogEnabled {
 
     protected Logger logger;
-    protected Context context;
     protected ServiceManager serviceManager;
     // protected CompilingClassLoader classLoader;
     // protected MyClassRepository javaClassRepository = new MyClassRepository();
     protected String sourcePath;
+    protected SourceResolver resolver;
+    private Store endpointCache;
 
-    private Store endpointCache = null;
 
     /**
-     * Loads a SOAP endpoint using the first service definition with a SOAP
-     * binding found in the referenced WSDL document.
+     * @see org.apache.avalon.framework.logger.LogEnabled#enableLogging(org.apache.avalon.framework.logger.Logger)
+     */
+    public void enableLogging(Logger logger) {
+        this.logger = logger;
+    }
+
+    /**
+     * Loads a SOAP endpoint using the first service definition with a SOAP binding found in the referenced WSDL
+     * document.
      *
      * @param wsdlURL
      * @return @throws
@@ -63,8 +72,7 @@
      * @throws InvalidServiceException
      * @throws LoadException
      */
-    public Remote load(String wsdlURL) throws Exception,
-            InvalidServiceException, LoadException {
+    public Remote load(String wsdlURL) throws Exception, LoadException {
         return load(wsdlURL, null, null);
     }
 
@@ -78,8 +86,7 @@
      * @return @throws
      *         LoadException
      */
-    public Remote load(String wsdlURL, String serviceName, String portName)
-            throws LoadException {
+    public Remote load(String wsdlURL, String serviceName, String portName) throws LoadException {
         // return endpoint proxy from cache if we have it, should check every so
         // often to see if
         // WSDL has been modifed and regenerate bindings if required
@@ -131,10 +138,8 @@
      * @param wsdlURL
      * @param serviceName
      * @param portName
-     * @return
      */
-    private String makeEndpointKey(String wsdlURL, String serviceName,
-            String portName) {
+    private String makeEndpointKey(String wsdlURL, String serviceName, String portName) {
         String key = wsdlURL;
         if (serviceName != null) {
             key += serviceName;
@@ -152,8 +157,7 @@
      * @param serviceName
      * @param portName
      * @param namespaceURI
-     * @return @throws
-     *         LoadException
+     * @throws LoadException
      */
     private Remote getServiceEndPoint(String serviceName, String portName,
             String namespaceURI) throws LoadException {
@@ -178,7 +182,6 @@
      *
      * @param targetNamespace
      * @param serviceName
-     * @return
      */
     private String getServiceLocatorClassName(String targetNamespace,
             String serviceName) {
@@ -189,8 +192,7 @@
         } else {
             packageName = packageName + ".";
         }
-        String serviceLocatorClassName = packageName + serviceNameCaps
-                + "Locator";
+        String serviceLocatorClassName = packageName + serviceNameCaps + "Locator";
         return serviceLocatorClassName;
     }
 
@@ -199,10 +201,9 @@
      *
      * @param serviceLocatorClass
      * @param portName
-     * @return
      */
     private String getPortAccessorName(Class serviceLocatorClass,
-            String portName) throws SecurityException, NoSuchMethodException {
+            String portName) throws SecurityException {
         String portAccessorName = "get"
                 + Utils.capitalizeFirstChar(JavaUtils.xmlNameToJava(portName));
         return portAccessorName;
@@ -210,18 +211,14 @@
 
     /**
      * @param wsdlURL
-     * @throws LoadException
      */
-    private void generateClientBindings(String wsdlURL) throws LoadException {
+    private void generateClientBindings(String wsdlURL) {
         ClientBindingGenerator cbg = new ClientBindingGenerator();
         cbg.generate(wsdlURL, this.sourcePath);
     }
 
     /**
      * Tests if client bindings have been generated for the WSDL.
-     *
-     * @param wsdlURL
-     * @return
      */
     private boolean bindingsAreGenerated(String namespace, String serviceName) {
         try {
@@ -237,21 +234,16 @@
         return false;
     }
 
-    /*
-     * (non-Javadoc)
-     *
+    /**
      * @see org.apache.avalon.framework.context.Contextualizable#contextualize(org.apache.avalon.framework.context.Context)
      */
     public void contextualize(final Context context) throws ContextException {
-        this.context = context;
         final File workDir = (File) context.get(Constants.CONTEXT_WORK_DIR);
         this.sourcePath = workDir.getAbsolutePath() + File.separator + "axis";
 
     }
 
-    /*
-     * (non-Javadoc)
-     *
+    /**
      * @see org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager)
      */
     public void service(ServiceManager serviceManager) throws ServiceException {
@@ -265,13 +257,18 @@
         }
     }
 
-    /*
-     * (non-Javadoc)
-     *
-     * @see org.apache.avalon.framework.logger.LogEnabled#enableLogging(org.apache.avalon.framework.logger.Logger)
+    /**
+     * @see org.apache.avalon.framework.activity.Disposable#dispose()
      */
-    public void enableLogging(Logger logger) {
-        this.logger = logger;
+    public void dispose() {
+        if ( this.serviceManager != null ) {
+            //this.classLoader = null;
+            this.serviceManager.release(this.endpointCache);
+            this.endpointCache = null;
+            this.serviceManager.release(this.resolver);
+            this.resolver = null;
+            this.serviceManager = null;
+        }
     }
 
     private ClassLoader getClassLoader() throws Exception {
@@ -282,10 +279,10 @@
     private ClassLoader getClassLoader() throws Exception {
         synchronized (this.javaClassRepository) {
             if (this.classLoader == null) {
+                resolver = (SourceResolver) this.serviceManager.lookup(SourceResolver.ROLE);
                 this.classLoader = new CompilingClassLoader(Thread
                         .currentThread().getContextClassLoader(),
-                        (SourceResolver) WebServiceLoader.this.serviceManager
-                                .lookup(SourceResolver.ROLE),
+                        resolver,
                         this.javaClassRepository);
                 this.classLoader
                         .addSourceListener(new CompilingClassLoader.SourceListener() {
@@ -340,48 +337,51 @@
         }
 
         public synchronized boolean upToDateCheck() throws Exception {
-            SourceResolver sourceResolver = (SourceResolver) WebServiceLoader.this.serviceManager
-                    .lookup(SourceResolver.ROLE);
-            Iterator iter = javaSource.entrySet().iterator();
-            List invalid = new LinkedList();
-            while (iter.hasNext()) {
-                Map.Entry e = (Map.Entry) iter.next();
-                String uri = (String) e.getKey();
-                SourceValidity validity = (SourceValidity) e.getValue();
-                int valid = validity.isValid();
-                if (valid == SourceValidity.UNKNOWN) {
-                    Source newSrc = null;
-                    try {
-                        newSrc = sourceResolver.resolveURI(uri);
-                        valid = newSrc.getValidity().isValid(validity);
-                    } catch (Exception ignored) {
-                    } finally {
-                        if (newSrc != null) {
-                            sourceResolver.release(newSrc);
+            SourceResolver sourceResolver = (SourceResolver) WebServiceLoader.this.serviceManager.lookup(SourceResolver.ROLE);
+            try {
+                Iterator iter = javaSource.entrySet().iterator();
+                List invalid = new LinkedList();
+                while (iter.hasNext()) {
+                    Map.Entry e = (Map.Entry) iter.next();
+                    String uri = (String) e.getKey();
+                    SourceValidity validity = (SourceValidity) e.getValue();
+                    int valid = validity.isValid();
+                    if (valid == SourceValidity.UNKNOWN) {
+                        Source newSrc = null;
+                        try {
+                            newSrc = sourceResolver.resolveURI(uri);
+                            valid = newSrc.getValidity().isValid(validity);
+                        } catch (Exception ignored) {
+                                // ignore
+                        } finally {
+                            if (newSrc != null) {
+                                sourceResolver.release(newSrc);
+                            }
                         }
                     }
+                    if (valid != SourceValidity.VALID) {
+                        invalid.add(uri);
+                    }
                 }
-                if (valid != SourceValidity.VALID) {
-                    invalid.add(uri);
-                }
-            }
-            iter = invalid.iterator();
-            while (iter.hasNext()) {
-                String uri = (String) iter.next();
-                Set set = (Set) sourceToClass.get(uri);
-                Iterator ii = set.iterator();
-                while (ii.hasNext()) {
-                    String className = (String) ii.next();
-                    sourceToClass.remove(className);
-                    javaClass.remove(className);
-                    classToSource.remove(className);
+                iter = invalid.iterator();
+                while (iter.hasNext()) {
+                    String uri = (String) iter.next();
+                    Set set = (Set) sourceToClass.get(uri);
+                    Iterator ii = set.iterator();
+                    while (ii.hasNext()) {
+                        String className = (String) ii.next();
+                        sourceToClass.remove(className);
+                        javaClass.remove(className);
+                        classToSource.remove(className);
+                    }
+                    set.clear();
+                    javaSource.remove(uri);
                 }
-                set.clear();
-                javaSource.remove(uri);
+                return invalid.size() == 0;
+            } finally {
+                WebServiceLoader.this.serviceManager.release(sourceResolver);
             }
-            return invalid.size() == 0;
         }
     }
     */
-
 }