Return-Path: X-Original-To: apmail-sling-commits-archive@www.apache.org Delivered-To: apmail-sling-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 306F7C91B for ; Tue, 5 Jun 2012 17:08:20 +0000 (UTC) Received: (qmail 5212 invoked by uid 500); 5 Jun 2012 17:08:20 -0000 Delivered-To: apmail-sling-commits-archive@sling.apache.org Received: (qmail 5161 invoked by uid 500); 5 Jun 2012 17:08:20 -0000 Mailing-List: contact commits-help@sling.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@sling.apache.org Delivered-To: mailing list commits@sling.apache.org Received: (qmail 5154 invoked by uid 99); 5 Jun 2012 17:08:20 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 05 Jun 2012 17:08:20 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 05 Jun 2012 17:08:16 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 70CFF2388980; Tue, 5 Jun 2012 17:07:55 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1346470 - in /sling/whiteboard/SLING-2396/resourceresolver/src: main/java/org/apache/sling/resourceresolver/impl/ResourceResolverImpl.java test/java/org/apache/sling/resourceresolver/impl/ResourceResolverImplTest.java Date: Tue, 05 Jun 2012 17:07:55 -0000 To: commits@sling.apache.org From: cziegeler@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20120605170755.70CFF2388980@eris.apache.org> Author: cziegeler Date: Tue Jun 5 17:07:54 2012 New Revision: 1346470 URL: http://svn.apache.org/viewvc?rev=1346470&view=rev Log: SLING-2396 : Add new resource provider interfaces (WiP) Modified: sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverImpl.java sling/whiteboard/SLING-2396/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/ResourceResolverImplTest.java Modified: sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverImpl.java URL: http://svn.apache.org/viewvc/sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverImpl.java?rev=1346470&r1=1346469&r2=1346470&view=diff ============================================================================== --- sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverImpl.java (original) +++ sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverImpl.java Tue Jun 5 17:07:54 2012 @@ -106,8 +106,8 @@ public class ResourceResolverImpl extend /** * @see org.apache.sling.api.resource.ResourceResolver#clone(Map) */ - public ResourceResolver clone(final Map authenticationInfo) throws LoginException { - + public ResourceResolver clone(final Map authenticationInfo) + throws LoginException { // ensure resolver is still live checkClosed(); @@ -150,8 +150,9 @@ public class ResourceResolverImpl extend * cleaned up before it is being collected by the garbage collector because * it is not referred to any more. */ - protected void finalize() { + protected void finalize() throws Throwable { close(); + super.finalize(); } /** @@ -180,6 +181,7 @@ public class ResourceResolverImpl extend * @see org.apache.sling.api.resource.ResourceResolver#getAttribute(String) */ public Object getAttribute(final String name) { + checkClosed(); if (name == null) { throw new NullPointerException("name"); } @@ -629,7 +631,8 @@ public class ResourceResolverImpl extend * @see org.apache.sling.api.resource.ResourceResolver#queryResources(java.lang.String, * java.lang.String) */ - public Iterator> queryResources(final String query, final String language) throws SlingException { + public Iterator> queryResources(final String query, final String language) + throws SlingException { checkClosed(); return this.factory.getRootProviderEntry().queryResources(this.context, query, language); @@ -725,7 +728,7 @@ public class ResourceResolverImpl extend * The (absolute) path * @return The request path string {scheme}/{host}.{port}{path}. */ - public static String getMapPath(final String scheme, final String host, int port, final String path) { + private static String getMapPath(final String scheme, final String host, int port, final String path) { if (port < 0) { port = ("https".equals(scheme)) ? 443 : 80; } @@ -876,9 +879,9 @@ public class ResourceResolverImpl extend } /** - * Creates a JcrNodeResource with the given path if existing + * Creates a resource with the given path if existing */ - protected Resource getResourceInternal(final String path) { + private Resource getResourceInternal(final String path) { final Resource resource = this.factory.getRootProviderEntry().getResource(this.context, this, path); if (resource != null) { @@ -890,11 +893,11 @@ public class ResourceResolverImpl extend return null; } - public String getProperty(final Resource res, final String propName) { + private String getProperty(final Resource res, final String propName) { return getProperty(res, propName, String.class); } - public Type getProperty(final Resource res, final String propName, final Class type) { + private Type getProperty(final Resource res, final String propName, final Class type) { // check the property in the resource itself final ValueMap props = res.adaptTo(ValueMap.class); Modified: sling/whiteboard/SLING-2396/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/ResourceResolverImplTest.java URL: http://svn.apache.org/viewvc/sling/whiteboard/SLING-2396/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/ResourceResolverImplTest.java?rev=1346470&r1=1346469&r2=1346470&view=diff ============================================================================== --- sling/whiteboard/SLING-2396/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/ResourceResolverImplTest.java (original) +++ sling/whiteboard/SLING-2396/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/ResourceResolverImplTest.java Tue Jun 5 17:07:54 2012 @@ -45,6 +45,7 @@ import org.apache.sling.api.resource.Non import org.apache.sling.api.resource.Resource; import org.apache.sling.api.resource.ResourceResolver; import org.apache.sling.api.resource.ResourceResolverFactory; +import org.apache.sling.resourceresolver.impl.helper.ResourceResolverContext; import org.junit.Before; import org.junit.Test; @@ -56,7 +57,114 @@ public class ResourceResolverImplTest { @Before public void setup() { resFac = new ResourceResolverFactoryImpl(); - resResolver = new ResourceResolverImpl(resFac, null); + resResolver = new ResourceResolverImpl(resFac, new ResourceResolverContext(false, null)); + } + + @Test public void testClose() throws Exception { + final ResourceResolver rr = new ResourceResolverImpl(resFac, new ResourceResolverContext(false, null)); + assertTrue(rr.isLive()); + rr.close(); + assertFalse(rr.isLive()); + // close is always allowed to be called + rr.close(); + assertFalse(rr.isLive()); + // now check all public method - they should all throw! + try { + rr.adaptTo(Session.class); + fail(); + } catch (final IllegalStateException ise) { + // expected + } + try { + rr.clone(null); + fail(); + } catch (final IllegalStateException ise) { + // expected + } + try { + rr.findResources("a", "b"); + fail(); + } catch (final IllegalStateException ise) { + // expected + } + try { + rr.getAttribute("a"); + fail(); + } catch (final IllegalStateException ise) { + // expected + } + try { + rr.getAttributeNames(); + fail(); + } catch (final IllegalStateException ise) { + // expected + } + try { + rr.getResource(null); + fail(); + } catch (final IllegalStateException ise) { + // expected + } + try { + rr.getResource(null, "/a"); + fail(); + } catch (final IllegalStateException ise) { + // expected + } + try { + rr.getSearchPath(); + fail(); + } catch (final IllegalStateException ise) { + // expected + } + try { + rr.getUserID(); + fail(); + } catch (final IllegalStateException ise) { + // expected + } + try { + rr.listChildren(null); + fail(); + } catch (final IllegalStateException ise) { + // expected + } + try { + rr.map("/somepath"); + fail(); + } catch (final IllegalStateException ise) { + // expected + } + try { + rr.map(null, "/somepath"); + fail(); + } catch (final IllegalStateException ise) { + // expected + } + try { + rr.queryResources("a", "b"); + fail(); + } catch (final IllegalStateException ise) { + // expected + } + try { + rr.resolve((HttpServletRequest)null); + fail(); + } catch (final IllegalStateException ise) { + // expected + } + try { + rr.resolve("/path"); + fail(); + } catch (final IllegalStateException ise) { + // expected + } + try { + rr.resolve(null, "/path"); + fail(); + } catch (final IllegalStateException ise) { + // expected + } } @SuppressWarnings("deprecation")