Author: fmeschbe
Date: Fri Jul 30 08:56:45 2010
New Revision: 980686

URL: http://svn.apache.org/viewvc?rev=980686&view=rev
Log:
SLING-1193 Revert changes to the ResourceUtil implementation to not depend on 
the new Resource API. The problem as mentioned on the dev list is that 
implementations of the former Resource interface version missing the new 
methods perfectly load. But calling the new methods results in exceptions (or 
errors) being thrown. We should prevent this in the ResourceUtil class.

Modified:
    
sling/trunk/bundles/api/src/main/java/org/apache/sling/api/resource/AbstractResource.java
    
sling/trunk/bundles/api/src/main/java/org/apache/sling/api/resource/ResourceUtil.java

Modified: 
sling/trunk/bundles/api/src/main/java/org/apache/sling/api/resource/AbstractResource.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/bundles/api/src/main/java/org/apache/sling/api/resource/AbstractResource.java?rev=980686&r1=980685&r2=980686&view=diff
==============================================================================
--- 
sling/trunk/bundles/api/src/main/java/org/apache/sling/api/resource/AbstractResource.java
 (original)
+++ 
sling/trunk/bundles/api/src/main/java/org/apache/sling/api/resource/AbstractResource.java
 Fri Jul 30 08:56:45 2010
@@ -83,12 +83,15 @@ public abstract class AbstractResource i
      * calling the {...@link ResourceUtil#getParent(String)} method and then to
      * retrieve that resource from the resource resolver.
      */
+    @SuppressWarnings("deprecation")
     public Resource getParent() {
-        final String parentPath = ResourceUtil.getParent(getPath());
-        if (parentPath == null) {
-            return null;
-        }
-        return getResourceResolver().getResource(parentPath);
+        /*
+         * Implemented calling the deprecated ResourceUtil.getParent method
+         * (which actually has the implementation) to prevent problems if there
+         * are implementations of the pre-2.1.0 Resource interface in the
+         * framework.
+         */
+        return ResourceUtil.getParent(this);
     }
 
     /**
@@ -131,25 +134,12 @@ public abstract class AbstractResource i
      * methods.
      */
     public boolean isResourceType(String resourceType) {
-
-        if (resourceType == null) {
-            return false;
-        }
-
-        if (resourceType.equals(getResourceType())) {
-            return true;
-        }
-
-        String superType = ResourceUtil.findResourceSuperType(this);
-        while (superType != null) {
-            if (resourceType.equals(superType)) {
-                return true;
-            }
-            superType = ResourceUtil.getResourceSuperType(
-                getResourceResolver(), superType);
-        }
-
-        return false;
+        /*
+         * Implemented calling the ResourceUtil.isA method (which actually has
+         * the implementation) to prevent problems if there are implementations
+         * of the pre-2.1.0 Resource interface in the framework.
+         */
+        return ResourceUtil.isA(this, resourceType);
     }
 
     /**

Modified: 
sling/trunk/bundles/api/src/main/java/org/apache/sling/api/resource/ResourceUtil.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/bundles/api/src/main/java/org/apache/sling/api/resource/ResourceUtil.java?rev=980686&r1=980685&r2=980686&view=diff
==============================================================================
--- 
sling/trunk/bundles/api/src/main/java/org/apache/sling/api/resource/ResourceUtil.java
 (original)
+++ 
sling/trunk/bundles/api/src/main/java/org/apache/sling/api/resource/ResourceUtil.java
 Fri Jul 30 08:56:45 2010
@@ -154,7 +154,11 @@ public class ResourceUtil {
      * @deprecated since 2.1.0, use {...@link Resource#getParent()} instead
      */
     public static Resource getParent(Resource rsrc) {
-        return rsrc.getParent();
+        final String parentPath = ResourceUtil.getParent(rsrc.getPath());
+        if (parentPath == null) {
+            return null;
+        }
+        return rsrc.getResourceResolver().getResource(parentPath);
     }
 
     /**
@@ -164,7 +168,12 @@ public class ResourceUtil {
      * @deprecated since 2.1.0, use {...@link Resource#getName()} instead
      */
     public static String getName(Resource rsrc) {
-        return rsrc.getName();
+        /*
+         * Same as AbstractResource.getName() implementation to prevent 
problems
+         * if there are implementations of the pre-2.1.0 Resource interface in
+         * the framework.
+         */
+        return getName(rsrc.getPath());
     }
 
     /**
@@ -281,7 +290,12 @@ public class ResourceUtil {
      * @deprecated since 2.1.0, use {...@link Resource#listChildren()} instead
      */
     public static Iterator<Resource> listChildren(Resource parent) {
-        return parent.listChildren();
+        /*
+         * Same as AbstractResource.listChildren() implementation to prevent
+         * problems if there are implementations of the pre-2.1.0 Resource
+         * interface in the framework.
+         */
+        return parent.getResourceResolver().listChildren(parent);
     }
 
     /**
@@ -416,7 +430,24 @@ public class ResourceUtil {
      * @since 2.0.6
      */
     public static boolean isA(final Resource resource, String resourceType) {
-        return resource != null && resource.isResourceType(resourceType);
+        if (resource == null || resourceType == null) {
+            return false;
+        }
+
+        if (resourceType.equals(resource.getResourceType())) {
+            return true;
+        }
+
+        String superType = findResourceSuperType(resource);
+        while (superType != null) {
+            if (resourceType.equals(superType)) {
+                return true;
+            }
+            superType = getResourceSuperType(resource.getResourceResolver(),
+                superType);
+        }
+
+        return false;
     }
 
     /**


Reply via email to