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/04/29 10:59:28 UTC

svn commit: r769722 - in /incubator/sling/whiteboard/rewriter/src/main/java/org/apache/sling/rewriter/impl: FactoryCache.java ProcessorConfigurationImpl.java ProcessorManagerImpl.java

Author: cziegeler
Date: Wed Apr 29 08:59:26 2009
New Revision: 769722

URL: http://svn.apache.org/viewvc?rev=769722&view=rev
Log:
Change handling of default configuration.

Modified:
    incubator/sling/whiteboard/rewriter/src/main/java/org/apache/sling/rewriter/impl/FactoryCache.java
    incubator/sling/whiteboard/rewriter/src/main/java/org/apache/sling/rewriter/impl/ProcessorConfigurationImpl.java
    incubator/sling/whiteboard/rewriter/src/main/java/org/apache/sling/rewriter/impl/ProcessorManagerImpl.java

Modified: incubator/sling/whiteboard/rewriter/src/main/java/org/apache/sling/rewriter/impl/FactoryCache.java
URL: http://svn.apache.org/viewvc/incubator/sling/whiteboard/rewriter/src/main/java/org/apache/sling/rewriter/impl/FactoryCache.java?rev=769722&r1=769721&r2=769722&view=diff
==============================================================================
--- incubator/sling/whiteboard/rewriter/src/main/java/org/apache/sling/rewriter/impl/FactoryCache.java (original)
+++ incubator/sling/whiteboard/rewriter/src/main/java/org/apache/sling/rewriter/impl/FactoryCache.java Wed Apr 29 08:59:26 2009
@@ -45,22 +45,22 @@
 public class FactoryCache {
 
     /** The logger. */
-    private static final Logger LOGGER = LoggerFactory.getLogger(FactoryCache.class);
+    protected static final Logger LOGGER = LoggerFactory.getLogger(FactoryCache.class);
 
     /** The tracker for generator factories. */
-    private final HashingServiceTrackerCustomizer generatorTracker;
+    protected final HashingServiceTrackerCustomizer generatorTracker;
 
     /** The tracker for serializers factories. */
-    private final HashingServiceTrackerCustomizer serializerTracker;
+    protected final HashingServiceTrackerCustomizer serializerTracker;
 
     /** The tracker for transformer factories. */
-    private final HashingServiceTrackerCustomizer transformerTracker;
+    protected final HashingServiceTrackerCustomizer transformerTracker;
 
     /** The tracker for rewriting transformer factories. */
-    private final RewriterTransformerFactoryServiceTracker rewritingTransformerTracker;
+    protected final RewriterTransformerFactoryServiceTracker rewritingTransformerTracker;
 
     /** The tracker for processor factories. */
-    private final HashingServiceTrackerCustomizer processorTracker;
+    protected final HashingServiceTrackerCustomizer processorTracker;
 
     public FactoryCache(final BundleContext context)
     throws InvalidSyntaxException {
@@ -100,10 +100,10 @@
     /**
      * Lookup a factory component.
      */
-    private <ComponentType> ComponentType getComponent(final List<ComponentInstance> instanceList,
-                                                       final Class<ComponentType> typeClass,
-                                                       final String type,
-                                                       final HashingServiceTrackerCustomizer customizer) {
+    protected <ComponentType> ComponentType getComponent(final List<ComponentInstance> instanceList,
+                                                         final Class<ComponentType> typeClass,
+                                                         final String type,
+                                                         final HashingServiceTrackerCustomizer customizer) {
         // get factory
         final ComponentFactory factory = customizer.get(type);
         if ( factory == null ) {
@@ -177,7 +177,7 @@
     /**
      * This service tracker stores all services into a hash map.
      */
-    private final class HashingServiceTrackerCustomizer extends ServiceTracker {
+    protected final class HashingServiceTrackerCustomizer extends ServiceTracker {
 
         private final Map<String, ComponentFactory> services = new HashMap<String, ComponentFactory>();
 
@@ -228,10 +228,10 @@
         }
     }
 
-    private static final class RewriterTransformerFactoryServiceTracker extends ServiceTracker {
+    protected static final class RewriterTransformerFactoryServiceTracker extends ServiceTracker {
 
-        private static final RewriterTransformerFactory[] EMPTY_ARRAY = new RewriterTransformerFactory[0];
-        private static final RewriterTransformerFactory[][] EMPTY_DOUBLE_ARRAY = new RewriterTransformerFactory[][] {EMPTY_ARRAY, EMPTY_ARRAY};
+        public static final RewriterTransformerFactory[] EMPTY_ARRAY = new RewriterTransformerFactory[0];
+        public static final RewriterTransformerFactory[][] EMPTY_DOUBLE_ARRAY = new RewriterTransformerFactory[][] {EMPTY_ARRAY, EMPTY_ARRAY};
 
         private RewriterTransformerFactory[][] cached = EMPTY_DOUBLE_ARRAY;
 
@@ -257,6 +257,10 @@
             super.removedService(reference, service);
         }
 
+        public boolean isCacheValid() {
+            return this.cacheIsValid;
+        }
+
         private RewriterTransformerFactory[][] getTransformerFactories() {
             if ( !this.cacheIsValid ) {
                 synchronized ( this ) {
@@ -336,7 +340,7 @@
     /**
      * Comparator for service references.
      */
-    private static final class ServiceReferenceComparator implements Comparator<ServiceReference> {
+    protected static final class ServiceReferenceComparator implements Comparator<ServiceReference> {
         public static ServiceReferenceComparator INSTANCE = new ServiceReferenceComparator();
 
         public int compare(ServiceReference o1, ServiceReference o2) {
@@ -344,8 +348,7 @@
             Long id = (Long) o1.getProperty(Constants.SERVICE_ID);
             Long otherId = (Long) o2.getProperty(Constants.SERVICE_ID);
 
-            if (id.equals(otherId))
-            {
+            if (id.equals(otherId)) {
                 return 0; // same service
             }
 
@@ -363,12 +366,9 @@
                 ? new Integer(0) : (Integer) otherRankObj;
 
             // Sort by rank in ascending order.
-            if (rank.compareTo(otherRank) < 0)
-            {
+            if (rank.compareTo(otherRank) < 0) {
                 return -1; // lower rank
-            }
-            else if (rank.compareTo(otherRank) > 0)
-            {
+            } else if (rank.compareTo(otherRank) > 0) {
                 return 1; // higher rank
             }
 

Modified: incubator/sling/whiteboard/rewriter/src/main/java/org/apache/sling/rewriter/impl/ProcessorConfigurationImpl.java
URL: http://svn.apache.org/viewvc/incubator/sling/whiteboard/rewriter/src/main/java/org/apache/sling/rewriter/impl/ProcessorConfigurationImpl.java?rev=769722&r1=769721&r2=769722&view=diff
==============================================================================
--- incubator/sling/whiteboard/rewriter/src/main/java/org/apache/sling/rewriter/impl/ProcessorConfigurationImpl.java (original)
+++ incubator/sling/whiteboard/rewriter/src/main/java/org/apache/sling/rewriter/impl/ProcessorConfigurationImpl.java Wed Apr 29 08:59:26 2009
@@ -55,8 +55,6 @@
     private static final String PROPERTY_PROCESS_ERROR = "processError";
 
 
-    private static final String MIME_TYPE_HTML = "text/html";
-
     /** For which content types should this processor be applied. */
     private final String[] contentTypes;
 
@@ -93,21 +91,28 @@
     private final boolean processErrorResponse;
 
     /**
-     * This is the default pipeline.
+     * This is the constructor for a pipeline
      */
-    public ProcessorConfigurationImpl() {
-        this.contentTypes = new String[] {MIME_TYPE_HTML};
-        this.paths = null; // for all paths
-        this.extensions = null; // for all extensions
-        this.order = -1; // fallback
-        this.generatorConfiguration = new ProcessingComponentConfigurationImpl("html-parser", null);
-        this.serializerConfiguration = new ProcessingComponentConfigurationImpl("html-serializer", null);
-        this.transformerConfigurations = null;
+    public ProcessorConfigurationImpl(String[] contentTypes,
+                                      String[] paths,
+                                      String[] extensions,
+                                      int      order,
+                                      ProcessingComponentConfiguration generatorConfig,
+                                      ProcessingComponentConfiguration[] transformerConfigs,
+                                      ProcessingComponentConfiguration serializerConfig,
+                                      boolean processErrorResponse) {
+        this.contentTypes = contentTypes;
+        this.paths = paths;
+        this.extensions = extensions;
+        this.order = order;
+        this.generatorConfiguration = generatorConfig;
+        this.transformerConfigurations = transformerConfigs;
+        this.serializerConfiguration = serializerConfig;
         this.processorConfig = null;
         this.isActive = true;
         this.isValid = true;
         this.isPipeline = true;
-        this.processErrorResponse = true;
+        this.processErrorResponse = processErrorResponse;
     }
 
     /**
@@ -199,7 +204,7 @@
         String contentType = processContext.getContentType();
         // if no content type is supplied, we assume html
         if ( contentType == null ) {
-            contentType = MIME_TYPE_HTML;
+            contentType = ProcessorManagerImpl.MIME_TYPE_HTML;
         } else {
             final int idx = contentType.indexOf(';');
             if (idx != -1) {

Modified: incubator/sling/whiteboard/rewriter/src/main/java/org/apache/sling/rewriter/impl/ProcessorManagerImpl.java
URL: http://svn.apache.org/viewvc/incubator/sling/whiteboard/rewriter/src/main/java/org/apache/sling/rewriter/impl/ProcessorManagerImpl.java?rev=769722&r1=769721&r2=769722&view=diff
==============================================================================
--- incubator/sling/whiteboard/rewriter/src/main/java/org/apache/sling/rewriter/impl/ProcessorManagerImpl.java (original)
+++ incubator/sling/whiteboard/rewriter/src/main/java/org/apache/sling/rewriter/impl/ProcessorManagerImpl.java Wed Apr 29 08:59:26 2009
@@ -60,6 +60,8 @@
     private static final String CONFIG_REL_PATH = "config/rewriter";
     private static final String CONFIG_PATH = "/" + CONFIG_REL_PATH;
 
+    protected static final String MIME_TYPE_HTML = "text/html";
+
     /** The logger */
     private final Logger log = LoggerFactory.getLogger(this.getClass());
 
@@ -100,7 +102,7 @@
     protected void activate(final ComponentContext ctx)
     throws RepositoryException, InvalidSyntaxException {
         this.bundleContext = ctx.getBundleContext();
-        this.factoryCache = new FactoryCache(this.bundleContext);
+        this.factoryCache = this.getFactoryCache(this.bundleContext);
         this.adminSession = this.repository.loginAdministrative(null);
 
         // create array of search paths for actions and constraints
@@ -128,12 +130,36 @@
 
         this.initProcessors();
 
-        // add default pipeline for html
-        this.addProcessor("*", "", new ProcessorConfigurationImpl());
+        this.addDefaultProcessors();
         this.factoryCache.start();
     }
 
     /**
+     * Get the factory cache
+     */
+    protected FactoryCache getFactoryCache(BundleContext bc)
+    throws InvalidSyntaxException {
+        return new FactoryCache(bc);
+    }
+
+    /**
+     * Add the default configurations.
+     */
+    protected void addDefaultProcessors() {
+        // add default pipeline for html
+        this.addProcessor("*", "", new ProcessorConfigurationImpl(
+                new String[] {MIME_TYPE_HTML}, // content types
+                null, // paths,
+                null, // extension
+                -1,   // order
+                new ProcessingComponentConfigurationImpl("html-generator", null), // generator config
+                null, // transformer config
+                new ProcessingComponentConfigurationImpl("html-serializer", null), // serializer config
+                true  // process error response
+                ));
+    }
+
+    /**
      * Deactivate this component.
      * @param ctx
      */
@@ -203,7 +229,7 @@
     /**
      * adds a processor configuration
      */
-    private void addProcessor(final String key, final String configPath, final ProcessorConfigurationImpl config) {
+    protected void addProcessor(final String key, final String configPath, final ProcessorConfigurationImpl config) {
         ConfigEntry[] configs = this.processors.get(key);
         if ( configs == null ) {
             configs = new ConfigEntry[1];