You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by cz...@apache.org on 2009/02/17 22:10:57 UTC

svn commit: r745256 - in /incubator/sling/trunk/launchpad/base/src/main/java/org/apache/sling/launchpad: app/Main.java base/impl/Sling.java base/impl/SlingFelix.java base/webapp/SlingServletDelegate.java

Author: cziegeler
Date: Tue Feb 17 21:10:56 2009
New Revision: 745256

URL: http://svn.apache.org/viewvc?rev=745256&view=rev
Log:
Clean up code and javadocs

Modified:
    incubator/sling/trunk/launchpad/base/src/main/java/org/apache/sling/launchpad/app/Main.java
    incubator/sling/trunk/launchpad/base/src/main/java/org/apache/sling/launchpad/base/impl/Sling.java
    incubator/sling/trunk/launchpad/base/src/main/java/org/apache/sling/launchpad/base/impl/SlingFelix.java
    incubator/sling/trunk/launchpad/base/src/main/java/org/apache/sling/launchpad/base/webapp/SlingServletDelegate.java

Modified: incubator/sling/trunk/launchpad/base/src/main/java/org/apache/sling/launchpad/app/Main.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/launchpad/base/src/main/java/org/apache/sling/launchpad/app/Main.java?rev=745256&r1=745255&r2=745256&view=diff
==============================================================================
--- incubator/sling/trunk/launchpad/base/src/main/java/org/apache/sling/launchpad/app/Main.java (original)
+++ incubator/sling/trunk/launchpad/base/src/main/java/org/apache/sling/launchpad/app/Main.java Tue Feb 17 21:10:56 2009
@@ -16,13 +16,9 @@
  */
 package org.apache.sling.launchpad.app;
 
-import java.io.BufferedReader;
 import java.io.File;
 import java.io.IOException;
 import java.io.PrintStream;
-import java.io.PrintWriter;
-import java.io.StringReader;
-import java.io.StringWriter;
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.text.DateFormat;
@@ -44,7 +40,7 @@
  * <p>
  * This class goes into the secondary artifact with the classifier <i>app</i> to
  * be used as the main class when starting the Java Application.
- * 
+ *
  * @see <a href="http://cwiki.apache.org/SLING/the-sling-launchpad.html">The
  *      Sling Launchpad</a>
  */
@@ -120,7 +116,7 @@
      * If an <code>InputStream</code> was provided, this has been copied to a
      * temporary file, which will be used in place of the existing launcher jar
      * file.
-     * 
+     *
      * @param updateFile The temporary file to replace the existing launcher jar
      *            file. If <code>null</code> the existing launcher jar will be
      *            used again.
@@ -221,7 +217,7 @@
      * <li>Environment variable <code>SLING_HOME</code></li>
      * <li>Default value <code>sling</code></li>
      * </ol>
-     * 
+     *
      * @param args The command line arguments
      * @return The value to use for sling.home
      */
@@ -274,12 +270,12 @@
     }
 
     private static final DateFormat fmt = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss.SSS ");
-    
+
     // helper method to format the message on the correct output channel
     // the throwable if not-null is also prefixed line by line with the prefix
     private static void log(PrintStream out, String prefix, String message,
             Throwable t) {
-        
+
         final StringBuilder linePrefixBuilder = new StringBuilder();
         synchronized (fmt) {
             linePrefixBuilder.append(fmt.format(new Date()));
@@ -289,7 +285,7 @@
         linePrefixBuilder.append(Thread.currentThread().getName());
         linePrefixBuilder.append("] ");
         final String linePrefix = linePrefixBuilder.toString();
-        
+
         out.print(linePrefix);
         out.println(message);
         if (t != null) {

Modified: incubator/sling/trunk/launchpad/base/src/main/java/org/apache/sling/launchpad/base/impl/Sling.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/launchpad/base/src/main/java/org/apache/sling/launchpad/base/impl/Sling.java?rev=745256&r1=745255&r2=745256&view=diff
==============================================================================
--- incubator/sling/trunk/launchpad/base/src/main/java/org/apache/sling/launchpad/base/impl/Sling.java (original)
+++ incubator/sling/trunk/launchpad/base/src/main/java/org/apache/sling/launchpad/base/impl/Sling.java Tue Feb 17 21:10:56 2009
@@ -52,7 +52,7 @@
 /**
  * The <code>Sling</code> serves as the starting point for Sling.
  * <ul>
- * <li>The {@link #Sling(Logger, ResourceProvider, Map)} method launches Apache
+ * <li>The {@link #Sling(Notifiable, Logger, ResourceProvider, Map)} method launches Apache
  * <code>Felix</code> as the OSGi framework implementation we use.
  * </ul>
  * <p>
@@ -107,10 +107,10 @@
      * <code>new File(${sling.home}).toURI().toString()</code> before
      * resolving the property variables.
      *
-     * @see #SLING_HOME
+     * @see SharedConstants#SLING_HOME
      */
     public static final String SLING_HOME_URL = "sling.home.url";
-    
+
     /**
      * The name of the configuration property defining the JCR home directory
      * (value is "sling.repository.home").
@@ -121,7 +121,7 @@
      * Default value to #SLING_HOME/repository_name
      */
     public static final String JCR_REPO_HOME = "sling.repository.home";
-    
+
     /**
      * The name of the configuration property defining the URL of an existing
      * repository config file (repository.xml).
@@ -206,7 +206,7 @@
     public Sling(Notifiable notifiable, Logger logger,
             ResourceProvider resourceProvider, Map<String, String> propOverwrite)
             throws BundleException {
-    	
+
         this.logger = logger;
         this.resourceProvider = resourceProvider;
 
@@ -265,26 +265,26 @@
             if (myFelix != null) {
                 logger.log(Logger.LOG_INFO, "Shutting down Sling");
                 try {
-                    
+
                     myFelix.stop();
                     myFelix.waitForStop(0);
-                    
+
                 } catch (BundleException be) {
-                    
+
                     // may be thrown by stop, log but continue
                     logger.log(Logger.LOG_ERROR,
                         "Failure initiating Framework Shutdown", be);
-                    
+
                 } catch (InterruptedException ie) {
-                
+
                     // may be thrown by waitForStop, log but continue
                     logger.log(
                         Logger.LOG_ERROR,
                         "Interrupted while waiting for the Framework Termination",
                         ie);
-                    
+
                 }
-                
+
                 logger.log(Logger.LOG_INFO, "Sling stopped");
             }
         }
@@ -397,7 +397,7 @@
         migrateProp(staticProps, "felix.startlevel.framework", Constants.FRAMEWORK_BEGINNING_STARTLEVEL);
         migrateProp(staticProps, "sling.osgi-core-packages", "osgi-core-packages");
         migrateProp(staticProps, "sling.osgi-compendium-services", "osgi-compendium-services");
-        
+
         // create a copy of the properties to perform variable substitution
         final Map<String, String> runtimeProps = new HashMap<String, String>();
         runtimeProps.putAll(staticProps);
@@ -586,7 +586,7 @@
      * <code>newName</code> key. If both properties <code>oldName</code> and
      * <code>newName</code> exist, the property <code>newName</code> is replaced
      * with the value of the property <code>oldName</code>.
-     * 
+     *
      * @param props The map of properties containing the property to rename
      * @param oldName The old key of the property value
      * @param newName The new key of the property value
@@ -635,7 +635,7 @@
      * <code>org.osgi.framework.executionenvironment</code> property already set
      * and ensures the older settings are included. If the property is not set
      * yet, it is fully constructed by this method.
-     * 
+     *
      * @param props The configuration properties to check and optionally ammend.
      */
     private void setExecutionEnvironment(Map<String, String> props) {
@@ -644,7 +644,7 @@
         if (ee == null) {
             ee = System.getProperty(Constants.FRAMEWORK_EXECUTIONENVIRONMENT);
         }
-        
+
         // prepare for building the new property value
         StringBuilder eebuilder = new StringBuilder();
         if (ee != null) {

Modified: incubator/sling/trunk/launchpad/base/src/main/java/org/apache/sling/launchpad/base/impl/SlingFelix.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/launchpad/base/src/main/java/org/apache/sling/launchpad/base/impl/SlingFelix.java?rev=745256&r1=745255&r2=745256&view=diff
==============================================================================
--- incubator/sling/trunk/launchpad/base/src/main/java/org/apache/sling/launchpad/base/impl/SlingFelix.java (original)
+++ incubator/sling/trunk/launchpad/base/src/main/java/org/apache/sling/launchpad/base/impl/SlingFelix.java Tue Feb 17 21:10:56 2009
@@ -21,21 +21,20 @@
 import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
-import java.util.List;
 import java.util.Map;
 
 import org.apache.felix.framework.Felix;
-import org.apache.felix.framework.Logger;
 import org.apache.sling.launchpad.base.shared.Loader;
 import org.apache.sling.launchpad.base.shared.Notifiable;
 import org.osgi.framework.BundleException;
 
+
 public class SlingFelix extends Felix {
 
     private final Notifiable notifiable;
-    
+
     private Notifier notifierThread;
-    
+
     public SlingFelix(Notifiable notifiable, Map<?, ?> props) throws Exception {
         super(props);
         this.notifiable = notifiable;
@@ -45,16 +44,16 @@
     public void update() throws BundleException {
         update(null);
     }
-    
+
     @Override
     public void update(InputStream is) throws BundleException {
         // get the update file
         startNotifier(true, is);
-        
+
         // just stop the framework now
         super.stop();
     }
-    
+
     @Override
     public void stop() throws BundleException {
         startNotifier(false, null);
@@ -65,7 +64,7 @@
         startNotifier(false, null);
         super.stop(status);
     }
-    
+
     private synchronized void startNotifier(boolean restart, InputStream ins) {
         if (notifierThread == null) {
             notifierThread = new Notifier(restart, ins);
@@ -73,17 +72,17 @@
             notifierThread.start();
         }
     }
-    
+
     private class Notifier extends Thread {
 
         private final boolean restart;
-        
+
         private final File updateFile;
-        
+
         private Notifier(boolean restart, InputStream ins) {
             super("Sling Notifier");
             this.restart = restart;
-            
+
             if (ins != null) {
                 File tmpFile;
                 try {
@@ -98,7 +97,7 @@
                 updateFile = null;
             }
         }
-        
+
         @Override
         public void run() {
 
@@ -107,7 +106,7 @@
             } catch (InterruptedException ie) {
                 // TODO: log
             }
-            
+
             if (restart) {
                 notifiable.updated(updateFile);
             } else {

Modified: incubator/sling/trunk/launchpad/base/src/main/java/org/apache/sling/launchpad/base/webapp/SlingServletDelegate.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/launchpad/base/src/main/java/org/apache/sling/launchpad/base/webapp/SlingServletDelegate.java?rev=745256&r1=745255&r2=745256&view=diff
==============================================================================
--- incubator/sling/trunk/launchpad/base/src/main/java/org/apache/sling/launchpad/base/webapp/SlingServletDelegate.java (original)
+++ incubator/sling/trunk/launchpad/base/src/main/java/org/apache/sling/launchpad/base/webapp/SlingServletDelegate.java Tue Feb 17 21:10:56 2009
@@ -45,6 +45,7 @@
 import org.apache.sling.launchpad.base.shared.SharedConstants;
 import org.eclipse.equinox.http.servlet.HttpServiceServlet;
 import org.osgi.framework.BundleException;
+import org.osgi.framework.ServiceEvent;
 import org.osgi.framework.ServiceReference;
 
 /**
@@ -79,7 +80,7 @@
  * <li>The <code>sling.properties</code> is read
  * from the servlet class path. This properties file contains default settings.</li>
  * <li>Extensions of this servlet may provide additional properties to be
- * loaded overwriting the {@link #loadConfigProperties()} method.
+ * loaded overwriting the {@link #loadConfigProperties(String)} method.
  * <li>Finally, web application init parameters are added to the properties and
  * may overwrite existing properties of the same name(s).
  * </ol>
@@ -123,7 +124,7 @@
      * The name of the configuration property defining the obr repository.
      */
     private static final String OBR_REPOSITORY_URL = "obr.repository.url";
-    
+
     /**
      * Flag set by the {@link #destroy()} method to indicate the servlet has
      * been destroyed. This flag is used by the {@link #startSling(String)}
@@ -131,7 +132,7 @@
      * was starting up.
      */
     private boolean servletDestroyed = false;
-    
+
     /**
      * The <code>Felix</code> instance loaded on {@link #init()} and stopped
      * on {@link #destroy()}.
@@ -152,7 +153,7 @@
     private Notifiable notifiable;
 
     private String slingHome;
-    
+
     public void setNotifiable(Notifiable notifiable) {
         this.notifiable = notifiable;
     }
@@ -164,7 +165,7 @@
     public void setSlingHome(String slingHome) {
         this.slingHome = slingHome;
     }
-    
+
     public boolean start() {
         // might want to log, why we don't start !
         return false;
@@ -187,14 +188,14 @@
         // disposal in case of setup errors
         SlingBridge tmpSling = null;
         Servlet tmpDelegatee = null;
-        
+
         try {
-            
+
             log("Starting Sling in " + slingHome);
 
             // read the default parameters
             Map<String, String> props = loadConfigProperties(slingHome);
-    
+
             Logger logger = new ServletContextLogger(getServletContext());
             ResourceProvider rp = new ServletContextResourceProvider(
                 getServletContext());
@@ -203,42 +204,42 @@
             // set up the OSGi HttpService proxy servlet
             tmpDelegatee = new HttpServiceServlet();
             tmpDelegatee.init(getServletConfig());
-            
+
             // set the fields only if the SlingServletDelegate has no been destroyed
             // while Sling has been starting up. Otherwise we do not set the
             // fields and leave the temporary variables assigned to have
             // them destroyed in the finally clause.
             if (servletDestroyed) {
-                
+
                 log("SlingServletDelegate destroyed while starting Sling, shutting Sling down");
-                
+
             } else {
-                
+
                 // set the fields now
                 sling = tmpSling;
                 delegatee = tmpDelegatee;
-                
+
                 // reset temporary holders to prevent destroyal
                 tmpSling = null;
                 tmpDelegatee = null;
-                
+
                 log("Sling successfully started in " + slingHome);
             }
-            
+
         } catch (BundleException be) {
-            
+
             throw new ServletException("Failed to start Sling in " + slingHome, be);
-            
+
         } catch (ServletException se) {
-            
+
             throw new ServletException("Failed to start bridge servlet for Sling", se);
-            
+
         } catch (Throwable t) {
-            
+
             throw new ServletException("Uncaught Failure starting Sling", t);
-            
+
         } finally {
-            
+
             // clean up temporary fields
             if (tmpDelegatee != null) {
                 tmpDelegatee.destroy();
@@ -258,7 +259,7 @@
      *            client's request
      * @param res the <code>ServletResponse</code> object that will contain
      *            the servlet's response
-     * @throws UnavailableException if the no delegatee servlet is currently
+     * @throws javax.servlet.UnavailableException if the no delegatee servlet is currently
      *             available
      * @throws ServletException if an exception occurs that interferes with the
      *             servlet's normal operation occurred
@@ -285,7 +286,7 @@
         // set the destroyed flag to signal to the startSling method
         // that Sling should be terminated immediately
         servletDestroyed = true;
-        
+
         // destroy the delegatee
         if (delegatee != null) {
             delegatee.destroy();
@@ -320,7 +321,7 @@
      * The precise file from which to load configuration properties can be set
      * by initializing the "<tt>felix.config.properties</tt>" system
      * property to an arbitrary URL.
-     * 
+     *
      * @param slingHome The value to be used as the "sling.home" property in the
      *            returned map. This parameter is expected to be non-<code>null</code>.
      * @return A <tt>Properties</tt> instance.
@@ -343,14 +344,15 @@
 
         // copy context init parameters
         @SuppressWarnings("unchecked")
-        Enumeration<String> pe = getServletContext().getInitParameterNames();
-        while (pe.hasMoreElements()) {
-            String name = pe.nextElement();
+        Enumeration<String> cpe = getServletContext().getInitParameterNames();
+        while (cpe.hasMoreElements()) {
+            String name = cpe.nextElement();
             props.put(name, getServletContext().getInitParameter(name));
         }
 
         // copy servlet init parameters
-        pe = getInitParameterNames();
+        @SuppressWarnings("unchecked")
+        Enumeration<String> pe = getInitParameterNames();
         while (pe.hasMoreElements()) {
             String name = pe.nextElement();
             props.put(name, getInitParameter(name));
@@ -369,10 +371,10 @@
             if (url != null)
                 props.put(OBR_REPOSITORY_URL, url.toExternalForm());
         }
-        
+
         // set sling home
         props.put(SharedConstants.SLING_HOME, slingHome);
-        
+
         return props;
     }
 
@@ -394,11 +396,11 @@
             props.put(LOG_LEVEL_PROP, String.valueOf(logLevel));
         }
     }
-    
+
     private boolean insideWebapp(String path) {
         return path != null && path.indexOf(":/") < 1 && path.startsWith("/");
     }
-    
+
     private URL getUrl(String path) {
         try {
             return getServletContext().getResource(path);
@@ -457,7 +459,7 @@
         private static final String WEB_INF = "/WEB-INF";
 
         private ServletContext servletContext;
-        
+
         private ServletContextResourceProvider(ServletContext servletContext) {
             super(SlingServletDelegate.class.getClassLoader());
             this.servletContext = servletContext;
@@ -480,7 +482,7 @@
             if ( resources == null || resources.isEmpty() ) {
                 // fall back to the class path
                 resourceIterator = super.getChildren(path);
-                
+
                 if(resourceIterator.hasNext()) {
                     return resourceIterator;
                 }
@@ -492,7 +494,7 @@
                     return resourceIterator;
                 }
             }
-            
+
             if ( resources == null ) {
                 return Collections.EMPTY_LIST.iterator();
             }
@@ -522,7 +524,7 @@
                 if(resource != null) {
                     return resource;
                 }
-                
+
                 // try classpath
                 resource = super.getResource(path);
                 if(resource != null) {