incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r592683 - in /incubator/sling/trunk/sling/core/src/main/java/org/apache/sling/core: ServiceLocator.java SlingException.java impl/ComponentRequestHandlerImpl.java theme/ThemeResolver.java util/ServiceLocatorImpl.java
Date Wed, 07 Nov 2007 10:16:40 GMT
Author: cziegeler
Date: Wed Nov  7 02:16:39 2007
New Revision: 592683

URL: http://svn.apache.org/viewvc?rev=592683&view=rev
Log:
Remove unused stuff and start adapting some parts to new API.

Removed:
    incubator/sling/trunk/sling/core/src/main/java/org/apache/sling/core/ServiceLocator.java
    incubator/sling/trunk/sling/core/src/main/java/org/apache/sling/core/SlingException.java
Modified:
    incubator/sling/trunk/sling/core/src/main/java/org/apache/sling/core/impl/ComponentRequestHandlerImpl.java
    incubator/sling/trunk/sling/core/src/main/java/org/apache/sling/core/theme/ThemeResolver.java
    incubator/sling/trunk/sling/core/src/main/java/org/apache/sling/core/util/ServiceLocatorImpl.java

Modified: incubator/sling/trunk/sling/core/src/main/java/org/apache/sling/core/impl/ComponentRequestHandlerImpl.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/sling/core/src/main/java/org/apache/sling/core/impl/ComponentRequestHandlerImpl.java?rev=592683&r1=592682&r2=592683&view=diff
==============================================================================
--- incubator/sling/trunk/sling/core/src/main/java/org/apache/sling/core/impl/ComponentRequestHandlerImpl.java
(original)
+++ incubator/sling/trunk/sling/core/src/main/java/org/apache/sling/core/impl/ComponentRequestHandlerImpl.java
Wed Nov  7 02:16:39 2007
@@ -33,19 +33,15 @@
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
-import org.apache.sling.component.ComponentException;
-import org.apache.sling.component.ComponentFilter;
-import org.apache.sling.component.ComponentFilterChain;
-import org.apache.sling.component.ComponentRequest;
-import org.apache.sling.component.ComponentResponse;
+import org.apache.sling.commons.mime.MimeTypeService;
 import org.apache.sling.core.impl.filter.ComponentFilterChainHelper;
 import org.apache.sling.core.resolver.ResolvedURL;
-import org.apache.sling.mime.MimeTypeService;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.Constants;
 import org.osgi.framework.ServiceReference;
 import org.osgi.framework.Version;
 import org.osgi.service.component.ComponentContext;
+import org.osgi.service.component.ComponentException;
 import org.osgi.service.http.HttpService;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -121,7 +117,7 @@
             this.service((HttpServletRequest) req, (HttpServletResponse) res);
         } else {
             throw new ServletException(
-                "Sling must be run in an HTTP Servlet Environment");
+                "Apache Sling must be run in an HTTP servlet environment.");
         }
     }
 

Modified: incubator/sling/trunk/sling/core/src/main/java/org/apache/sling/core/theme/ThemeResolver.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/sling/core/src/main/java/org/apache/sling/core/theme/ThemeResolver.java?rev=592683&r1=592682&r2=592683&view=diff
==============================================================================
--- incubator/sling/trunk/sling/core/src/main/java/org/apache/sling/core/theme/ThemeResolver.java
(original)
+++ incubator/sling/trunk/sling/core/src/main/java/org/apache/sling/core/theme/ThemeResolver.java
Wed Nov  7 02:16:39 2007
@@ -18,13 +18,13 @@
  */
 package org.apache.sling.core.theme;
 
-import org.apache.sling.component.ComponentRequest;
+import org.apache.sling.api.SlingHttpServletRequest;
 
 /**
  * The <code>ThemeResolver</code> TODO
  */
 public interface ThemeResolver {
 
-    Theme resolveTheme(ComponentRequest request);
+    Theme resolveTheme(SlingHttpServletRequest request);
 
 }

Modified: incubator/sling/trunk/sling/core/src/main/java/org/apache/sling/core/util/ServiceLocatorImpl.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/sling/core/src/main/java/org/apache/sling/core/util/ServiceLocatorImpl.java?rev=592683&r1=592682&r2=592683&view=diff
==============================================================================
--- incubator/sling/trunk/sling/core/src/main/java/org/apache/sling/core/util/ServiceLocatorImpl.java
(original)
+++ incubator/sling/trunk/sling/core/src/main/java/org/apache/sling/core/util/ServiceLocatorImpl.java
Wed Nov  7 02:16:39 2007
@@ -24,13 +24,15 @@
 import java.util.List;
 import java.util.Map;
 
-import org.apache.sling.core.ServiceLocator;
+import org.apache.sling.api.services.InvalidServiceFilterSyntaxException;
+import org.apache.sling.api.services.ServiceLocator;
+import org.apache.sling.api.services.ServiceNotAvailableException;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.InvalidSyntaxException;
 import org.osgi.framework.ServiceReference;
 
 /**
- * This is a default implementation of a {@link ServiceLocator].
+ * This is a default implementation of a {@link ServiceLocator}.
  *
  * We start with a simple implementation just adding all references into a list.
  */
@@ -48,48 +50,68 @@
         this.bundleContext = ctx;
     }
 
+
     /**
-     * @see org.apache.sling.core.ServiceLocator#getService(java.lang.String, java.lang.String)
+     * @see org.apache.sling.api.services.ServiceLocator#getRequiredService(java.lang.Class)
      */
-    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();
-            }
+    public <ServiceType> ServiceType getRequiredService(Class<ServiceType> type)
+    throws ServiceNotAvailableException {
+        final ServiceType service = this.getService(type);
+        if ( service == null ) {
+            throw new ServiceNotAvailableException("Service " + type.getName() + " is not
available.");
         }
-        return result;
+        return service;
     }
 
+
     /**
-     * @see org.apache.sling.core.ServiceLocator#getService(java.lang.String)
+     * @see org.apache.sling.api.services.ServiceLocator#getService(java.lang.Class)
      */
-    public Object getService(String serviceName) {
-        Object service = this.services.get(serviceName);
+    public <ServiceType> ServiceType getService(Class<ServiceType> type) {
+        ServiceType service = (ServiceType) this.services.get(type.getName());
         if ( service == null ) {
-            final ServiceReference ref = this.bundleContext.getServiceReference(serviceName);
+            final ServiceReference ref = this.bundleContext.getServiceReference(type.getName());
             if ( ref != null ) {
                 this.references.add(ref);
-                service = this.bundleContext.getService(ref);
-                this.services.put(serviceName, service);
+                service = (ServiceType) this.bundleContext.getService(ref);
+                this.services.put(type.getName(), service);
             }
         }
         return service;
     }
 
+
+    /**
+     * @see org.apache.sling.api.services.ServiceLocator#getServices(java.lang.Class, java.lang.String)
+     */
+    public <ServiceType> ServiceType[] getServices(Class<ServiceType> serviceType,
String filter)
+    throws InvalidServiceFilterSyntaxException {
+        try {
+            final ServiceReference[] refs = this.bundleContext.getServiceReferences(serviceType.getName(),
filter);
+            ServiceType[] result = null;
+            if ( refs != null ) {
+                final List<ServiceType> objects = new ArrayList<ServiceType>();
+                for(int i=0; i<refs.length; i++ ) {
+                    this.references.add(refs[i]);
+                    final ServiceType service = (ServiceType) this.bundleContext.getService(refs[i]);
+                    if ( service != null) {
+                        objects.add(service);
+                    }
+                }
+                if ( objects.size() > 0 ) {
+                    result = (ServiceType[]) objects.toArray();
+                }
+            }
+            return result;
+        } catch (InvalidSyntaxException ise) {
+            throw new InvalidServiceFilterSyntaxException("Invalid filter syntax: " + filter,
ise);
+        }
+    }
+
     public void clear() {
-        final Iterator i = this.references.iterator();
+        final Iterator<ServiceReference> i = this.references.iterator();
         while ( i.hasNext() ) {
-            final ServiceReference ref = (ServiceReference)i.next();
+            final ServiceReference ref = i.next();
             this.bundleContext.ungetService(ref);
         }
         this.references.clear();



Mime
View raw message