You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by cz...@apache.org on 2007/09/25 14:09:05 UTC
svn commit: r579215 - in /incubator/sling/trunk/core: pom.xml
src/main/java/org/apache/sling/core/impl/filter/ServiceLocatorFilter.java
src/main/java/org/apache/sling/core/util/
src/main/java/org/apache/sling/core/util/ServiceLocatorImpl.java
Author: cziegeler
Date: Tue Sep 25 05:09:04 2007
New Revision: 579215
URL: http://svn.apache.org/viewvc?rev=579215&view=rev
Log:
Move implementation of service locator to util package to make it available for other bundles.
Added:
incubator/sling/trunk/core/src/main/java/org/apache/sling/core/util/
incubator/sling/trunk/core/src/main/java/org/apache/sling/core/util/ServiceLocatorImpl.java (with props)
Modified:
incubator/sling/trunk/core/pom.xml
incubator/sling/trunk/core/src/main/java/org/apache/sling/core/impl/filter/ServiceLocatorFilter.java
Modified: incubator/sling/trunk/core/pom.xml
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/core/pom.xml?rev=579215&r1=579214&r2=579215&view=diff
==============================================================================
--- incubator/sling/trunk/core/pom.xml (original)
+++ incubator/sling/trunk/core/pom.xml Tue Sep 25 05:09:04 2007
@@ -81,7 +81,8 @@
org.apache.sling.core.filter,
org.apache.sling.core.locale,
org.apache.sling.core.mapper,
- org.apache.sling.core.theme
+ org.apache.sling.core.theme,
+ org.apache.sling.core.util
</Export-Package>
<Private-Package>
org.apache.sling.core.impl,
Modified: incubator/sling/trunk/core/src/main/java/org/apache/sling/core/impl/filter/ServiceLocatorFilter.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/core/src/main/java/org/apache/sling/core/impl/filter/ServiceLocatorFilter.java?rev=579215&r1=579214&r2=579215&view=diff
==============================================================================
--- incubator/sling/trunk/core/src/main/java/org/apache/sling/core/impl/filter/ServiceLocatorFilter.java (original)
+++ incubator/sling/trunk/core/src/main/java/org/apache/sling/core/impl/filter/ServiceLocatorFilter.java Tue Sep 25 05:09:04 2007
@@ -19,15 +19,6 @@
package org.apache.sling.core.impl.filter;
import java.io.IOException;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.InvalidSyntaxException;
-import org.osgi.framework.ServiceReference;
import org.apache.sling.component.ComponentContext;
import org.apache.sling.component.ComponentException;
@@ -36,6 +27,8 @@
import org.apache.sling.component.ComponentRequest;
import org.apache.sling.component.ComponentResponse;
import org.apache.sling.core.ServiceLocator;
+import org.apache.sling.core.util.ServiceLocatorImpl;
+import org.osgi.framework.BundleContext;
/**
* The <code>ServiceLocatorFilter</code> adds the service locator to the request
@@ -90,71 +83,5 @@
*/
public void destroy() {
// nothing to do
- }
-
- /**
- * We start with a simple implementation just adding all references into a list.
- */
- protected static final class ServiceLocatorImpl implements ServiceLocator {
-
- protected final BundleContext bundleContext;
-
- /** The list of references - we don't need to synchronize this as we are running in one single request. */
- protected final List references = new ArrayList();
-
- /** A map of found services. */
- protected final Map services = new HashMap();
-
- public ServiceLocatorImpl(BundleContext ctx) {
- this.bundleContext = ctx;
- }
-
- /**
- * @see org.apache.sling.core.ServiceLocator#getService(java.lang.String, java.lang.String)
- */
- public Object[] getService(String serviceName, String filter) throws InvalidSyntaxException {
- final ServiceReference[] refs = this.bundleContext.getServiceReferences(serviceName, filter);
- Object[] result = null;
- if ( refs != null ) {
- final List objects = new ArrayList();
- for(int i=0; i<refs.length; i++ ) {
- this.references.add(refs[i]);
- final Object service = this.bundleContext.getService(refs[i]);
- if ( service != null) {
- objects.add(service);
- }
- }
- if ( objects.size() > 0 ) {
- result = objects.toArray();
- }
- }
- return result;
- }
-
- /**
- * @see org.apache.sling.core.ServiceLocator#getService(java.lang.String)
- */
- public Object getService(String serviceName) {
- Object service = this.services.get(serviceName);
- if ( service == null ) {
- final ServiceReference ref = this.bundleContext.getServiceReference(serviceName);
- if ( ref != null ) {
- this.references.add(ref);
- service = this.bundleContext.getService(ref);
- this.services.put(serviceName, service);
- }
- }
- return service;
- }
-
- public void clear() {
- final Iterator i = this.references.iterator();
- while ( i.hasNext() ) {
- final ServiceReference ref = (ServiceReference)i.next();
- this.bundleContext.ungetService(ref);
- }
- this.references.clear();
- this.services.clear();
- }
}
}
Added: incubator/sling/trunk/core/src/main/java/org/apache/sling/core/util/ServiceLocatorImpl.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/core/src/main/java/org/apache/sling/core/util/ServiceLocatorImpl.java?rev=579215&view=auto
==============================================================================
--- incubator/sling/trunk/core/src/main/java/org/apache/sling/core/util/ServiceLocatorImpl.java (added)
+++ incubator/sling/trunk/core/src/main/java/org/apache/sling/core/util/ServiceLocatorImpl.java Tue Sep 25 05:09:04 2007
@@ -0,0 +1,98 @@
+/*
+ * 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.core.util;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.sling.core.ServiceLocator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceReference;
+
+/**
+ * This is a default implementation of a {@link ServiceLocator].
+ *
+ * We start with a simple implementation just adding all references into a list.
+ */
+public class ServiceLocatorImpl implements ServiceLocator {
+
+ protected final BundleContext bundleContext;
+
+ /** The list of references - we don't need to synchronize this as we are running in one single request. */
+ protected final List<ServiceReference> references = new ArrayList<ServiceReference>();
+
+ /** A map of found services. */
+ protected final Map<String, Object> services = new HashMap<String, Object>();
+
+ public ServiceLocatorImpl(BundleContext ctx) {
+ this.bundleContext = ctx;
+ }
+
+ /**
+ * @see org.apache.sling.core.ServiceLocator#getService(java.lang.String, java.lang.String)
+ */
+ public Object[] getService(String serviceName, String filter) throws InvalidSyntaxException {
+ final ServiceReference[] refs = this.bundleContext.getServiceReferences(serviceName, filter);
+ Object[] result = null;
+ if ( refs != null ) {
+ final List<Object> objects = new ArrayList<Object>();
+ for(int i=0; i<refs.length; i++ ) {
+ this.references.add(refs[i]);
+ final Object service = this.bundleContext.getService(refs[i]);
+ if ( service != null) {
+ objects.add(service);
+ }
+ }
+ if ( objects.size() > 0 ) {
+ result = objects.toArray();
+ }
+ }
+ return result;
+ }
+
+ /**
+ * @see org.apache.sling.core.ServiceLocator#getService(java.lang.String)
+ */
+ public Object getService(String serviceName) {
+ Object service = this.services.get(serviceName);
+ if ( service == null ) {
+ final ServiceReference ref = this.bundleContext.getServiceReference(serviceName);
+ if ( ref != null ) {
+ this.references.add(ref);
+ service = this.bundleContext.getService(ref);
+ this.services.put(serviceName, service);
+ }
+ }
+ return service;
+ }
+
+ public void clear() {
+ final Iterator i = this.references.iterator();
+ while ( i.hasNext() ) {
+ final ServiceReference ref = (ServiceReference)i.next();
+ this.bundleContext.ungetService(ref);
+ }
+ this.references.clear();
+ this.services.clear();
+ }
+}
Propchange: incubator/sling/trunk/core/src/main/java/org/apache/sling/core/util/ServiceLocatorImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/sling/trunk/core/src/main/java/org/apache/sling/core/util/ServiceLocatorImpl.java
------------------------------------------------------------------------------
svn:keywords = author date id revision url