incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r1555034 - in /sling/trunk/contrib/extensions/feature-flags/src/main/java/org/apache/sling/featureflags: ./ impl/
Date Fri, 03 Jan 2014 08:52:41 GMT
Author: cziegeler
Date: Fri Jan  3 08:52:41 2014
New Revision: 1555034

URL: http://svn.apache.org/r1555034
Log:
Take III, add Feature interface and support adapting to functionality interfaces

Added:
    sling/trunk/contrib/extensions/feature-flags/src/main/java/org/apache/sling/featureflags/ResourceTypeMapping.java
      - copied, changed from r1555031, sling/trunk/contrib/extensions/feature-flags/src/main/java/org/apache/sling/featureflags/ResourceTypeMapper.java
Removed:
    sling/trunk/contrib/extensions/feature-flags/src/main/java/org/apache/sling/featureflags/ResourceTypeMapper.java
Modified:
    sling/trunk/contrib/extensions/feature-flags/src/main/java/org/apache/sling/featureflags/Feature.java
    sling/trunk/contrib/extensions/feature-flags/src/main/java/org/apache/sling/featureflags/impl/ClientContextImpl.java
    sling/trunk/contrib/extensions/feature-flags/src/main/java/org/apache/sling/featureflags/impl/FeatureManager.java
    sling/trunk/contrib/extensions/feature-flags/src/main/java/org/apache/sling/featureflags/impl/ResourceDecoratorImpl.java

Modified: sling/trunk/contrib/extensions/feature-flags/src/main/java/org/apache/sling/featureflags/Feature.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/feature-flags/src/main/java/org/apache/sling/featureflags/Feature.java?rev=1555034&r1=1555033&r2=1555034&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/feature-flags/src/main/java/org/apache/sling/featureflags/Feature.java
(original)
+++ sling/trunk/contrib/extensions/feature-flags/src/main/java/org/apache/sling/featureflags/Feature.java
Fri Jan  3 08:52:41 2014
@@ -28,7 +28,7 @@ import aQute.bnd.annotation.ConsumerType
  * be adapted to different services, like
  * <ul>
  *   <li>{@link ResourceHiding}</li>
- *   <li>{@link ResourceTypeMapper}</li>
+ *   <li>{@link ResourceTypeMapping}</li>
  * </ul>
  */
 @ConsumerType

Copied: sling/trunk/contrib/extensions/feature-flags/src/main/java/org/apache/sling/featureflags/ResourceTypeMapping.java
(from r1555031, sling/trunk/contrib/extensions/feature-flags/src/main/java/org/apache/sling/featureflags/ResourceTypeMapper.java)
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/feature-flags/src/main/java/org/apache/sling/featureflags/ResourceTypeMapping.java?p2=sling/trunk/contrib/extensions/feature-flags/src/main/java/org/apache/sling/featureflags/ResourceTypeMapping.java&p1=sling/trunk/contrib/extensions/feature-flags/src/main/java/org/apache/sling/featureflags/ResourceTypeMapper.java&r1=1555031&r2=1555034&rev=1555034&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/feature-flags/src/main/java/org/apache/sling/featureflags/ResourceTypeMapper.java
(original)
+++ sling/trunk/contrib/extensions/feature-flags/src/main/java/org/apache/sling/featureflags/ResourceTypeMapping.java
Fri Jan  3 08:52:41 2014
@@ -27,7 +27,7 @@ import aQute.bnd.annotation.ConsumerType
  * this service interface.
  */
 @ConsumerType
-public interface ResourceTypeMapper {
+public interface ResourceTypeMapping {
 
     /**
      * Returns the resource type mapping for a feature.

Modified: sling/trunk/contrib/extensions/feature-flags/src/main/java/org/apache/sling/featureflags/impl/ClientContextImpl.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/feature-flags/src/main/java/org/apache/sling/featureflags/impl/ClientContextImpl.java?rev=1555034&r1=1555033&r2=1555034&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/feature-flags/src/main/java/org/apache/sling/featureflags/impl/ClientContextImpl.java
(original)
+++ sling/trunk/contrib/extensions/feature-flags/src/main/java/org/apache/sling/featureflags/impl/ClientContextImpl.java
Fri Jan  3 08:52:41 2014
@@ -21,14 +21,15 @@ package org.apache.sling.featureflags.im
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
-import java.util.Comparator;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 import org.apache.sling.featureflags.ClientContext;
 import org.apache.sling.featureflags.Feature;
 import org.apache.sling.featureflags.ProviderContext;
 import org.apache.sling.featureflags.ResourceHiding;
-import org.apache.sling.featureflags.ResourceTypeMapper;
+import org.apache.sling.featureflags.ResourceTypeMapping;
 
 /**
  * Implementation of the client context
@@ -41,32 +42,23 @@ public class ClientContextImpl implement
 
     private final List<ResourceHiding> hidingFeatures;
 
-    private final List<ResourceTypeMapper> mapperFeatures;
+    private final Map<String, String> mapperFeatures = new HashMap<String, String>();
 
     public ClientContextImpl(final ProviderContext featureContext, final List<Feature>
features) {
-        Collections.sort(features, new Comparator<Feature>() {
-
-            @Override
-            public int compare(final Feature arg0, final Feature arg1) {
-                return arg0.getName().compareTo(arg1.getName());
-            }
-
-        });
         this.enabledFeatures = Collections.unmodifiableList(features);
         final List<ResourceHiding> hiding = new ArrayList<ResourceHiding>();
-        final List<ResourceTypeMapper> mapping = new ArrayList<ResourceTypeMapper>();
         for(final Feature f : this.enabledFeatures) {
             final ResourceHiding rh = f.adaptTo(ResourceHiding.class);
             if ( rh != null ) {
                 hiding.add(rh);
             }
-            final ResourceTypeMapper rm = f.adaptTo(ResourceTypeMapper.class);
+            final ResourceTypeMapping rm = f.adaptTo(ResourceTypeMapping.class);
             if ( rm != null ) {
-                mapping.add(rm);
+                final Map<String, String> mapping = rm.getResourceTypeMapping();
+                mapperFeatures.putAll(mapping);
             }
         }
         this.hidingFeatures = hiding;
-        this.mapperFeatures = mapping;
         this.featureContext = featureContext;
     }
 
@@ -93,7 +85,7 @@ public class ClientContextImpl implement
         return this.hidingFeatures;
     }
 
-    public Collection<ResourceTypeMapper> getMappingFeatures() {
+    public Map<String, String> getResourceTypeMapping() {
         return this.mapperFeatures;
     }
 }

Modified: sling/trunk/contrib/extensions/feature-flags/src/main/java/org/apache/sling/featureflags/impl/FeatureManager.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/feature-flags/src/main/java/org/apache/sling/featureflags/impl/FeatureManager.java?rev=1555034&r1=1555033&r2=1555034&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/feature-flags/src/main/java/org/apache/sling/featureflags/impl/FeatureManager.java
(original)
+++ sling/trunk/contrib/extensions/feature-flags/src/main/java/org/apache/sling/featureflags/impl/FeatureManager.java
Fri Jan  3 08:52:41 2014
@@ -23,6 +23,7 @@ import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.TreeMap;
 
 import org.apache.felix.scr.annotations.Component;
 import org.apache.felix.scr.annotations.Reference;
@@ -54,7 +55,7 @@ public class FeatureManager implements F
 
     private final Map<String, List<FeatureProviderDescription>> providers = new
HashMap<String, List<FeatureProviderDescription>>();
 
-    private Map<String, FeatureDescription> activeProviders = new HashMap<String,
FeatureDescription>();
+    private Map<String, FeatureDescription> activeProviders = new TreeMap<String,
FeatureDescription>();
 
     /**
      * Bind a new feature provider
@@ -113,7 +114,7 @@ public class FeatureManager implements F
     }
 
     private void calculateActiveProviders() {
-        final Map<String, FeatureDescription> activeMap = new HashMap<String, FeatureDescription>();
+        final Map<String, FeatureDescription> activeMap = new TreeMap<String, FeatureDescription>();
         for(final Map.Entry<String, List<FeatureProviderDescription>> entry :
this.providers.entrySet()) {
             final FeatureProviderDescription desc = entry.getValue().get(0);
             final FeatureDescription info = new FeatureDescription();

Modified: sling/trunk/contrib/extensions/feature-flags/src/main/java/org/apache/sling/featureflags/impl/ResourceDecoratorImpl.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/feature-flags/src/main/java/org/apache/sling/featureflags/impl/ResourceDecoratorImpl.java?rev=1555034&r1=1555033&r2=1555034&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/feature-flags/src/main/java/org/apache/sling/featureflags/impl/ResourceDecoratorImpl.java
(original)
+++ sling/trunk/contrib/extensions/feature-flags/src/main/java/org/apache/sling/featureflags/impl/ResourceDecoratorImpl.java
Fri Jan  3 08:52:41 2014
@@ -27,7 +27,6 @@ import org.apache.sling.api.resource.Res
 import org.apache.sling.api.resource.ResourceDecorator;
 import org.apache.sling.api.resource.ResourceWrapper;
 import org.apache.sling.featureflags.ClientContext;
-import org.apache.sling.featureflags.ResourceTypeMapper;
 
 /**
  * Resource decorator implementing the resource type mapping
@@ -43,24 +42,21 @@ public class ResourceDecoratorImpl imple
     public Resource decorate(final Resource resource) {
         final ClientContext info = manager.getCurrentClientContext();
         if ( info != null ) {
-            for(final ResourceTypeMapper f : ((ClientContextImpl)info).getMappingFeatures()
) {
-
-                final String resourceType = resource.getResourceType();
-                final String overwriteType = f.getResourceTypeMapping().get(resourceType);
-                if ( overwriteType != null ) {
-                    return new ResourceWrapper(resource) {
-
-                        @Override
-                        public String getResourceType() {
-                            return overwriteType;
-                        }
-
-                        @Override
-                        public String getResourceSuperType() {
-                            return resourceType;
-                        }
-                    };
-                }
+            final String resourceType = resource.getResourceType();
+            final String overwriteType = ((ClientContextImpl)info).getResourceTypeMapping().get(resourceType);
+            if ( overwriteType != null ) {
+                return new ResourceWrapper(resource) {
+
+                    @Override
+                    public String getResourceType() {
+                        return overwriteType;
+                    }
+
+                    @Override
+                    public String getResourceSuperType() {
+                        return resourceType;
+                    }
+                };
             }
         }
         return resource;



Mime
View raw message