Return-Path: Delivered-To: apmail-sling-commits-archive@www.apache.org Received: (qmail 26572 invoked from network); 1 Sep 2010 10:12:25 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 1 Sep 2010 10:12:25 -0000 Received: (qmail 7569 invoked by uid 500); 1 Sep 2010 10:12:25 -0000 Delivered-To: apmail-sling-commits-archive@sling.apache.org Received: (qmail 7504 invoked by uid 500); 1 Sep 2010 10:12:23 -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 7497 invoked by uid 99); 1 Sep 2010 10:12:23 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 01 Sep 2010 10:12:23 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.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; Wed, 01 Sep 2010 10:12:21 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 8E2792388A40; Wed, 1 Sep 2010 10:11:03 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r991494 - in /sling/trunk: bundles/api/ bundles/api/src/main/java/org/apache/sling/api/adapter/ bundles/api/src/main/java/org/apache/sling/api/resource/ bundles/extensions/adapter/ bundles/extensions/adapter/src/main/java/org/apache/sling/a... Date: Wed, 01 Sep 2010 10:11:03 -0000 To: commits@sling.apache.org From: cziegeler@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20100901101103.8E2792388A40@eris.apache.org> Author: cziegeler Date: Wed Sep 1 10:11:02 2010 New Revision: 991494 URL: http://svn.apache.org/viewvc?rev=991494&view=rev Log: SLING-1711 : Move SlingAdaptable from adapter bundle to api Added: sling/trunk/bundles/api/src/main/java/org/apache/sling/api/adapter/SlingAdaptable.java (with props) Modified: sling/trunk/bundles/api/pom.xml sling/trunk/bundles/api/src/main/java/org/apache/sling/api/resource/AbstractResource.java sling/trunk/bundles/extensions/adapter/pom.xml sling/trunk/bundles/extensions/adapter/src/main/java/org/apache/sling/adapter/SlingAdaptable.java sling/trunk/bundles/extensions/adapter/src/main/java/org/apache/sling/adapter/internal/AdapterManagerImpl.java sling/trunk/bundles/extensions/adapter/src/test/java/org/apache/sling/adapter/internal/AdapterManagerTest.java sling/trunk/launchpad/builder/src/main/bundles/list.xml Modified: sling/trunk/bundles/api/pom.xml URL: http://svn.apache.org/viewvc/sling/trunk/bundles/api/pom.xml?rev=991494&r1=991493&r2=991494&view=diff ============================================================================== --- sling/trunk/bundles/api/pom.xml (original) +++ sling/trunk/bundles/api/pom.xml Wed Sep 1 10:11:02 2010 @@ -88,8 +88,8 @@ http://sling.apache.org/site/sling-api.html - org.apache.sling.api;version=2.1, - org.apache.sling.api.adapter;version=2.1, + org.apache.sling.api;version=2.1, + org.apache.sling.api.adapter;version=2.2, org.apache.sling.api.auth;version=1.0, org.apache.sling.api.request;version=2.1, org.apache.sling.api.resource;version=2.1, Added: sling/trunk/bundles/api/src/main/java/org/apache/sling/api/adapter/SlingAdaptable.java URL: http://svn.apache.org/viewvc/sling/trunk/bundles/api/src/main/java/org/apache/sling/api/adapter/SlingAdaptable.java?rev=991494&view=auto ============================================================================== --- sling/trunk/bundles/api/src/main/java/org/apache/sling/api/adapter/SlingAdaptable.java (added) +++ sling/trunk/bundles/api/src/main/java/org/apache/sling/api/adapter/SlingAdaptable.java Wed Sep 1 10:11:02 2010 @@ -0,0 +1,93 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.sling.api.adapter; + +import java.util.HashMap; +import java.util.Map; + +/** + * The SlingAdaptable class is an (abstract) default + * implementation of the Adaptable interface. It just uses the + * default {@link org.apache.sling.api.adapter.AdapterManager} implemented + * to adapt itself to the requested type. + *

+ * Extensions of this class may overwrite the {@link #adaptTo(Class)} method + * using their own knowledge of adapters and may call this base class + * implementation to fall back to an extended adapters. + * + * @since 2.2 + */ +public abstract class SlingAdaptable implements Adaptable { + + /** The adapter manager used for adapting the synthetic resource. */ + private static volatile AdapterManager ADAPTER_MANAGER; + + /** + * Set the adapter manager to be used by a synthetic resource. A bundle + * implementing the adapter manager can set the manager through this method. + * The set adapter manager will be used in the {@link #adaptTo(Class)} + * method of a synthetic resource. + * + * @param adapterMgr The adapter manager. + */ + public static void setAdapterManager(final AdapterManager adapterMgr) { + ADAPTER_MANAGER = adapterMgr; + } + + /** + * Unset an adapter manager previously set with + * {@link #setAdapterManager(AdapterManager)}. If this method is called with + * an AdapterManager different from the currently set one it + * has no effect. + * + * @param adapterMgr The adapter manager + */ + public static void unsetAdapterManager(final AdapterManager adapterMgr) { + if (ADAPTER_MANAGER == adapterMgr) { + ADAPTER_MANAGER = null; + } + } + + /** Cache */ + private Map, Object> adaptersCache; + + /** + * @see org.apache.sling.api.adapter.Adaptable#adaptTo(java.lang.Class) + */ + @SuppressWarnings("unchecked") + public AdapterType adaptTo(Class type) { + AdapterType result = null; + synchronized ( this ) { + if ( adaptersCache != null ) { + result = (AdapterType) adaptersCache.get(type); + } + if ( result == null ) { + final AdapterManager mgr = ADAPTER_MANAGER; + result = (mgr == null ? null : mgr.getAdapter(this, type)); + if ( result != null ) { + if ( adaptersCache == null ) { + adaptersCache = new HashMap, Object>(); + } + adaptersCache.put(type, result); + } + } + } + return result; + } +} Propchange: sling/trunk/bundles/api/src/main/java/org/apache/sling/api/adapter/SlingAdaptable.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: sling/trunk/bundles/api/src/main/java/org/apache/sling/api/adapter/SlingAdaptable.java ------------------------------------------------------------------------------ svn:keywords = author date id revision rev url Propchange: sling/trunk/bundles/api/src/main/java/org/apache/sling/api/adapter/SlingAdaptable.java ------------------------------------------------------------------------------ svn:mime-type = text/plain 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=991494&r1=991493&r2=991494&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 Wed Sep 1 10:11:02 2010 @@ -20,7 +20,7 @@ package org.apache.sling.api.resource; import java.util.Iterator; -import org.apache.sling.api.adapter.AdapterManager; +import org.apache.sling.api.adapter.SlingAdaptable; /** * The AbstractResource is an abstract implementation of the @@ -34,36 +34,9 @@ import org.apache.sling.api.adapter.Adap * * @since 2.1.0 */ -public abstract class AbstractResource implements Resource { - - /** The adapter manager used for adapting the synthetic resource. */ - private static volatile AdapterManager ADAPTER_MANAGER; - - /** - * Set the adapter manager to be used by a synthetic resource. A bundle - * implementing the adapter manager can set the manager through this method. - * The set adapter manager will be used in the {@link #adaptTo(Class)} - * method of a synthetic resource. - * - * @param adapterMgr The adapter manager. - */ - public static void setAdapterManager(final AdapterManager adapterMgr) { - ADAPTER_MANAGER = adapterMgr; - } - - /** - * Unset an adapter manager previously set with - * {@link #setAdapterManager(AdapterManager)}. If this method is called with - * an AdapterManager different from the currently set one it - * has no effect. - * - * @param adapterMgr The adapter manager - */ - public static void unsetAdapterManager(final AdapterManager adapterMgr) { - if (ADAPTER_MANAGER == adapterMgr) { - ADAPTER_MANAGER = null; - } - } +public abstract class AbstractResource + extends SlingAdaptable + implements Resource { /** * Returns the name of this resource. @@ -85,12 +58,12 @@ public abstract class AbstractResource i */ @SuppressWarnings("deprecation") public Resource getParent() { - /* - * 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. - */ + // + // 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); } @@ -134,31 +107,11 @@ public abstract class AbstractResource i * methods. */ public boolean isResourceType(String resourceType) { - /* - * 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. - */ + // + // 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); } - - /** - * If a adapter manager has been set through - * {@link #setAdapterManager(AdapterManager)} this adapter manager is used - * to adapt the resource to the given type. Otherwise this method returns - * null. - *

- * This default base implementation is intended to be overwritten by - * extensions. Overwriting implementations are are encouraged to call this - * base class implementation if they themselves cannot adapt to the - * requested type. - */ - public Type adaptTo(Class type) { - final AdapterManager adapterMgr = ADAPTER_MANAGER; - if (adapterMgr != null) { - return adapterMgr.getAdapter(this, type); - } - return null; - } - } Modified: sling/trunk/bundles/extensions/adapter/pom.xml URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/adapter/pom.xml?rev=991494&r1=991493&r2=991494&view=diff ============================================================================== --- sling/trunk/bundles/extensions/adapter/pom.xml (original) +++ sling/trunk/bundles/extensions/adapter/pom.xml Wed Sep 1 10:11:02 2010 @@ -68,7 +68,7 @@ org.apache.sling.adapter.internal - org.apache.sling.api.adapter;version="[2.0,2.3)", + org.apache.sling.api.adapter;version="[2.2,2.3)", * @@ -93,7 +93,7 @@ org.apache.sling org.apache.sling.api - 2.0.8 + 2.1.1-SNAPSHOT provided Modified: sling/trunk/bundles/extensions/adapter/src/main/java/org/apache/sling/adapter/SlingAdaptable.java URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/adapter/src/main/java/org/apache/sling/adapter/SlingAdaptable.java?rev=991494&r1=991493&r2=991494&view=diff ============================================================================== --- sling/trunk/bundles/extensions/adapter/src/main/java/org/apache/sling/adapter/SlingAdaptable.java (original) +++ sling/trunk/bundles/extensions/adapter/src/main/java/org/apache/sling/adapter/SlingAdaptable.java Wed Sep 1 10:11:02 2010 @@ -18,49 +18,19 @@ */ package org.apache.sling.adapter; -import java.util.HashMap; -import java.util.Map; - -import org.apache.sling.adapter.internal.AdapterManagerImpl; -import org.apache.sling.api.adapter.Adaptable; -import org.apache.sling.api.adapter.AdapterManager; /** * The SlingAdaptable class is an (abstract) default * implementation of the Adaptable interface. It just uses the - * default {@link org.apache.sling.api.adapter.AdapterManager} implemented in this bundle to adapt the itself - * to the requested type. + * default {@link org.apache.sling.api.adapter.AdapterManager} implemented + * in this bundle to adapt the itself to the requested type. *

* Extensions of this class may overwrite the {@link #adaptTo(Class)} method * using their own knowledge of adapters and may call this base class * implementation to fall back to an extended adapters. + * @deprecated Use the {@link org.apache.sling.api.adapter.SlingAdaptable} instead */ -public abstract class SlingAdaptable implements Adaptable { - - /** Cache */ - private Map, Object> adaptersCache; +@Deprecated +public abstract class SlingAdaptable extends org.apache.sling.api.adapter.SlingAdaptable { - /** - * @see org.apache.sling.api.adapter.Adaptable#adaptTo(java.lang.Class) - */ - @SuppressWarnings("unchecked") - public AdapterType adaptTo(Class type) { - AdapterType result = null; - synchronized ( this ) { - if ( adaptersCache != null ) { - result = (AdapterType) adaptersCache.get(type); - } - if ( result == null ) { - final AdapterManager mgr = AdapterManagerImpl.getInstance(); - result = (mgr == null ? null : mgr.getAdapter(this, type)); - if ( result != null ) { - if ( adaptersCache == null ) { - adaptersCache = new HashMap, Object>(); - } - adaptersCache.put(type, result); - } - } - } - return result; - } } Modified: sling/trunk/bundles/extensions/adapter/src/main/java/org/apache/sling/adapter/internal/AdapterManagerImpl.java URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/adapter/src/main/java/org/apache/sling/adapter/internal/AdapterManagerImpl.java?rev=991494&r1=991493&r2=991494&view=diff ============================================================================== --- sling/trunk/bundles/extensions/adapter/src/main/java/org/apache/sling/adapter/internal/AdapterManagerImpl.java (original) +++ sling/trunk/bundles/extensions/adapter/src/main/java/org/apache/sling/adapter/internal/AdapterManagerImpl.java Wed Sep 1 10:11:02 2010 @@ -55,26 +55,6 @@ import org.osgi.service.log.LogService; */ public class AdapterManagerImpl implements AdapterManager { - /** - * The singleton instance of this manager. This field is set when the - * instance is {@link #activate(ComponentContext) activated} and cleared - * when the instance is {@link #deactivate(ComponentContext) deactivated}. - * - * This field is set to public to make it easier for testing to provide - * an own adapter manager implementation which can be used together - * with {@link org.apache.sling.adapter.SlingAdaptable}s. (see SLING-1195). - * As this class is private this field is not accessible in an OSGi environment! - */ - public static AdapterManager INSTANCE; - - /** - * Returns the instance of this class or null if no activate - * yet. - */ - public static AdapterManager getInstance() { - return INSTANCE; - } - /** @scr.reference cardinality="0..1" policy="dynamic" */ private LogService log; @@ -171,15 +151,6 @@ public class AdapterManagerImpl implemen } // final "enable" this manager by setting the instance - // do not overwrite the field if already set (this is unexpected - // actually) - if (AdapterManagerImpl.INSTANCE == null) { - AdapterManagerImpl.INSTANCE = this; - } else { - log(LogService.LOG_WARNING, - "Not setting Instance field: Set to another manager " - + AdapterManagerImpl.INSTANCE, null); - } SyntheticResource.setAdapterManager(this); } @@ -188,15 +159,6 @@ public class AdapterManagerImpl implemen */ protected void deactivate(ComponentContext context) { SyntheticResource.unsetAdapterManager(this); - // "disable" the manager by clearing the instance - // do not clear the field if not set to this instance - if (AdapterManagerImpl.INSTANCE == this) { - AdapterManagerImpl.INSTANCE = null; - } else { - log(LogService.LOG_WARNING, - "Not clearing instance field: Set to another manager " - + AdapterManagerImpl.INSTANCE, null); - } this.context = null; } Modified: sling/trunk/bundles/extensions/adapter/src/test/java/org/apache/sling/adapter/internal/AdapterManagerTest.java URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/adapter/src/test/java/org/apache/sling/adapter/internal/AdapterManagerTest.java?rev=991494&r1=991493&r2=991494&view=diff ============================================================================== --- sling/trunk/bundles/extensions/adapter/src/test/java/org/apache/sling/adapter/internal/AdapterManagerTest.java (original) +++ sling/trunk/bundles/extensions/adapter/src/test/java/org/apache/sling/adapter/internal/AdapterManagerTest.java Wed Sep 1 10:11:02 2010 @@ -25,9 +25,9 @@ import static org.junit.Assert.assertTru import java.util.Map; -import org.apache.sling.adapter.SlingAdaptable; import org.apache.sling.adapter.mock.MockAdapterFactory; import org.apache.sling.api.adapter.AdapterFactory; +import org.apache.sling.api.adapter.SlingAdaptable; import org.jmock.Expectations; import org.jmock.Mockery; import org.jmock.integration.junit4.JMock; @@ -53,9 +53,7 @@ public class AdapterManagerTest { } @org.junit.After public void tearDown() { - if (AdapterManagerImpl.getInstance() == am) { - am.deactivate(null); // not correct, but argument unused - } + am.deactivate(null); // not correct, but argument unused } /** Modified: sling/trunk/launchpad/builder/src/main/bundles/list.xml URL: http://svn.apache.org/viewvc/sling/trunk/launchpad/builder/src/main/bundles/list.xml?rev=991494&r1=991493&r2=991494&view=diff ============================================================================== --- sling/trunk/launchpad/builder/src/main/bundles/list.xml (original) +++ sling/trunk/launchpad/builder/src/main/bundles/list.xml Wed Sep 1 10:11:02 2010 @@ -41,7 +41,7 @@ org.apache.sling org.apache.sling.api - 2.1.0 + 2.1.1-SNAPSHOT org.apache.sling @@ -76,7 +76,7 @@ org.apache.sling org.apache.sling.adapter - 2.0.6 + 2.0.7-SNAPSHOT org.apache.sling