SLING-4997 add new method isModelClass and deprecate the old one
authorKonrad Windszus <kwin@apache.org>
Thu, 10 Sep 2015 08:36:33 +0000 (08:36 +0000)
committerKonrad Windszus <kwin@apache.org>
Thu, 10 Sep 2015 08:36:33 +0000 (08:36 +0000)
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/bundles/extensions/models/impl@1702186 13f79535-47bb-0310-9956-ffa450edef68

src/main/java/org/apache/sling/models/impl/AdapterImplementations.java
src/main/java/org/apache/sling/models/impl/ModelAdapterFactory.java

index 0a27d04..75c2bc4 100644 (file)
@@ -185,4 +185,25 @@ final class AdapterImplementations {
         return null;
     }
 
+    /**
+     * 
+     * @param adapterType the type to check
+     * @return {@code true} in case the given type is a model (may be with a different adapter class)
+     */
+    public <ModelType> boolean isModelClass(Class<ModelType> adapterType) {
+        String key = adapterType.getName();
+        
+        // lookup in cache for models without adapter classes
+        ModelClass<ModelType> modelClass = (ModelClass<ModelType>)modelClasses.get(key);
+        if (modelClass!=null) {
+            return true;
+        }
+
+        // not found? look in cache with adapter classes
+        ConcurrentNavigableMap<String,ModelClass<?>> implementations = adapterImplementations.get(key);
+        if (implementations==null || implementations.isEmpty()) {
+            return false;
+        }
+        return true;
+    }
 }
index 6513926..20da322 100644 (file)
@@ -225,11 +225,17 @@ public class ModelAdapterFactory implements AdapterFactory, Runnable, ModelFacto
     }
 
     @Override
+    @Deprecated
     public boolean isModelClass(@Nonnull Object adaptable, @Nonnull Class<?> requestedType) {
         ModelClass<?> type = getImplementationTypeForAdapterType(requestedType, adaptable);
         return type.hasModelAnnotation();
     }
 
+    @Override
+    public boolean isModelClass(@Nonnull Class<?> type) {
+        return this.adapterImplementations.isModelClass(type);
+    }
+
     /**
      * 
      * @param type