cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1508513 - in /cxf/trunk/rt: frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ rs/client/src/main/java/org/apache/cxf/jaxrs/client/spec/
Date Tue, 30 Jul 2013 16:33:22 GMT
Author: sergeyb
Date: Tue Jul 30 16:33:22 2013
New Revision: 1508513

URL: http://svn.apache.org/r1508513
Log:
[CXF-5135] Some more Configuration related coding

Modified:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ConfigurableImpl.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ConfigurationImpl.java
    cxf/trunk/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/spec/ClientConfigurableImpl.java

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ConfigurableImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ConfigurableImpl.java?rev=1508513&r1=1508512&r2=1508513&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ConfigurableImpl.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ConfigurableImpl.java
Tue Jul 30 16:33:22 2013
@@ -40,7 +40,8 @@ public class ConfigurableImpl<C extends 
     
     public ConfigurableImpl(C configurable, Class<?>[] supportedProviderClasses, Configuration
config) {
         this(configurable, supportedProviderClasses);
-        this.config = config instanceof ConfigurationImpl ? (ConfigurationImpl)config : new
ConfigurationImpl(config);
+        this.config = config instanceof ConfigurationImpl 
+            ? (ConfigurationImpl)config : new ConfigurationImpl(config, supportedProviderClasses);
     }
     
     private ConfigurableImpl(C configurable, Class<?>[] supportedProviderClasses) {
@@ -93,7 +94,8 @@ public class ConfigurableImpl<C extends 
 
     @Override
     public C register(Class<?> providerClass, int bindingPriority) {
-        return doRegister(createProvider(providerClass), bindingPriority, supportedProviderClasses);
+        return doRegister(ConfigurationImpl.createProvider(providerClass), 
+                          bindingPriority, supportedProviderClasses);
     }
 
     @Override
@@ -103,7 +105,7 @@ public class ConfigurableImpl<C extends 
 
     @Override
     public C register(Class<?> providerClass, Map<Class<?>, Integer> contracts)
{
-        return register(createProvider(providerClass), contracts);
+        return register(ConfigurationImpl.createProvider(providerClass), contracts);
     }
     
     protected C doRegister(Object provider, int bindingPriority, Class<?>... contracts)
{
@@ -113,22 +115,10 @@ public class ConfigurableImpl<C extends 
             feature.configure(new FeatureContextImpl(this));
             return configurable;
         }
-        for (Class<?> contract : contracts) {
-            if (contract.isAssignableFrom(provider.getClass())) {
-                config.register(provider, contract, bindingPriority);
-            }
-        }
+        config.register(provider, bindingPriority, contracts);
         return configurable;
     }
 
-    private static Object createProvider(Class<?> cls) {
-        try {
-            return cls.newInstance();
-        } catch (Throwable ex) {
-            throw new RuntimeException(ex); 
-        }
-    }
-    
     public static class FeatureContextImpl implements FeatureContext {
         private Configurable<?> cfg;
         public FeatureContextImpl(Configurable<?> cfg) {

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ConfigurationImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ConfigurationImpl.java?rev=1508513&r1=1508512&r2=1508513&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ConfigurationImpl.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ConfigurationImpl.java
Tue Jul 30 16:33:22 2013
@@ -29,6 +29,8 @@ import javax.ws.rs.RuntimeType;
 import javax.ws.rs.core.Configuration;
 import javax.ws.rs.core.Feature;
 
+import org.apache.cxf.jaxrs.utils.AnnotationUtils;
+
 public class ConfigurationImpl implements Configuration {
     private Map<String, Object> props = new HashMap<String, Object>();
     private RuntimeType runtimeType;
@@ -40,13 +42,29 @@ public class ConfigurationImpl implement
         this.runtimeType = rt;
     }
     
-    public ConfigurationImpl(Configuration parent) {
+    public ConfigurationImpl(Configuration parent, Class<?>[] defaultContracts) {
         if (parent != null) {
             this.props.putAll(parent.getProperties());
             this.runtimeType = parent.getRuntimeType();
+            
+            Set<Class<?>> providerClasses = new HashSet<Class<?>>(parent.getClasses());
             for (Object o : parent.getInstances()) {
-                providers.put(o, parent.getContracts(o.getClass()));
+                registerParentProvider(o, parent);
+                providerClasses.remove(o.getClass());
+            }
+            for (Class<?> cls : providerClasses) {
+                registerParentProvider(createProvider(cls), parent);
             }
+            
+        }
+    }
+    
+    private void registerParentProvider(Object o, Configuration parent) {
+        Map<Class<?>, Integer> contracts = parent.getContracts(o.getClass());
+        if (contracts != null) {
+            providers.put(o, contracts);
+        } else {
+            register(o, AnnotationUtils.getBindingPriority(o.getClass()));
         }
     }
     
@@ -136,12 +154,25 @@ public class ConfigurationImpl implement
         features.add(f);
     }
     
-    public void register(Object provider, Class<?> contract, int bindingPriority) {
+    
+    public void register(Object provider, int bindingPriority, Class<?>... contracts)
{
         Map<Class<?>, Integer> metadata = providers.get(provider);
         if (metadata == null) {
             metadata = new HashMap<Class<?>, Integer>();
             providers.put(provider, metadata);
         }
-        metadata.put(contract, bindingPriority);
+        for (Class<?> contract : contracts) {
+            if (contract.isAssignableFrom(provider.getClass())) {
+                metadata.put(contract, bindingPriority);
+            }
+        }
+    }
+    
+    public static Object createProvider(Class<?> cls) {
+        try {
+            return cls.newInstance();
+        } catch (Throwable ex) {
+            throw new RuntimeException(ex); 
+        }
     }
 }

Modified: cxf/trunk/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/spec/ClientConfigurableImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/spec/ClientConfigurableImpl.java?rev=1508513&r1=1508512&r2=1508513&view=diff
==============================================================================
--- cxf/trunk/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/spec/ClientConfigurableImpl.java
(original)
+++ cxf/trunk/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/spec/ClientConfigurableImpl.java
Tue Jul 30 16:33:22 2013
@@ -46,6 +46,7 @@ public class ClientConfigurableImpl<C ex
     }
     
     public ClientConfigurableImpl(C configurable, Configuration config) {
-        super(configurable, CLIENT_FILTER_INTERCEPTOR_CLASSES, new ConfigurationImpl(config));
+        super(configurable, CLIENT_FILTER_INTERCEPTOR_CLASSES, 
+              new ConfigurationImpl(config, CLIENT_FILTER_INTERCEPTOR_CLASSES));
     }
 }



Mime
View raw message