SLING-6658 - always include implementation class in adapterTypes list. Thanks to...
authorJustin Edelson <justin@apache.org>
Fri, 17 Mar 2017 13:39:06 +0000 (13:39 +0000)
committerJustin Edelson <justin@apache.org>
Fri, 17 Mar 2017 13:39:06 +0000 (13:39 +0000)
This closes #206

git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1787379 13f79535-47bb-0310-9956-ffa450edef68

src/main/java/org/apache/sling/models/impl/ModelPackageBundleListener.java

index c3404fc..5e167de 100644 (file)
@@ -26,6 +26,7 @@ import java.util.Hashtable;
 import java.util.List;
 import java.util.Map;
 
+import org.apache.commons.lang.ArrayUtils;
 import org.apache.commons.lang.StringUtils;
 import org.apache.sling.api.SlingHttpServletRequest;
 import org.apache.sling.api.adapter.AdapterFactory;
@@ -143,6 +144,8 @@ public class ModelPackageBundleListener implements BundleTrackerCustomizer {
                 Class<?>[] adapterTypes = annotation.adapters();
                 if (adapterTypes.length == 0) {
                     adapterTypes = new Class<?>[] { implType };
+                } else if (!ArrayUtils.contains(adapterTypes, implType)) {
+                    adapterTypes = (Class<?>[]) ArrayUtils.add(adapterTypes, implType);
                 }
                 // register adapter only if given adapters are valid
                 if (validateAdapterClasses(implType, adapterTypes)) {
@@ -156,7 +159,7 @@ public class ModelPackageBundleListener implements BundleTrackerCustomizer {
                     for (String resourceType : resourceTypes) {
                         if (StringUtils.isNotEmpty(resourceType)) {
                             for (Class<?> adaptable : annotation.adaptables()) {
-                                adapterImplementations.registerModelToResourceType(bundle, resourceType, adaptable, adapterTypes[0]);
+                                adapterImplementations.registerModelToResourceType(bundle, resourceType, adaptable, implType);
                                 ExportServlet.ExportedObjectAccessor accessor = null;
                                 if (adaptable == Resource.class) {
                                     accessor = ExportServlet.RESOURCE_ACCESSOR;