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/12/20 15:51:36 UTC
svn commit: r605947 - in /incubator/sling/trunk/sling: event/
event/src/main/java/org/apache/sling/event/impl/
event/src/test/java/org/apache/sling/event/impl/ scheduler/
scheduler/src/main/java/org/apache/sling/scheduler/impl/
Author: cziegeler
Date: Thu Dec 20 06:51:34 2007
New Revision: 605947
URL: http://svn.apache.org/viewvc?rev=605947&view=rev
Log:
Remove dependencies to sling core by copying relevant stuff.
Added:
incubator/sling/trunk/sling/scheduler/src/main/java/org/apache/sling/scheduler/impl/ServiceLocatorImpl.java (with props)
Modified:
incubator/sling/trunk/sling/event/pom.xml
incubator/sling/trunk/sling/event/src/main/java/org/apache/sling/event/impl/AbstractRepositoryEventHandler.java
incubator/sling/trunk/sling/event/src/test/java/org/apache/sling/event/impl/AbstractRepositoryEventHandlerTest.java
incubator/sling/trunk/sling/scheduler/pom.xml
incubator/sling/trunk/sling/scheduler/src/main/java/org/apache/sling/scheduler/impl/QuartzJobExecutor.java
Modified: incubator/sling/trunk/sling/event/pom.xml
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/sling/event/pom.xml?rev=605947&r1=605946&r2=605947&view=diff
==============================================================================
--- incubator/sling/trunk/sling/event/pom.xml (original)
+++ incubator/sling/trunk/sling/event/pom.xml Thu Dec 20 06:51:34 2007
@@ -97,7 +97,7 @@
</dependency>
<dependency>
<groupId>org.apache.sling</groupId>
- <artifactId>org.apache.sling.core</artifactId>
+ <artifactId>org.apache.sling.api</artifactId>
<version>2.0.0-incubator-SNAPSHOT</version>
</dependency>
<dependency>
Modified: incubator/sling/trunk/sling/event/src/main/java/org/apache/sling/event/impl/AbstractRepositoryEventHandler.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/sling/event/src/main/java/org/apache/sling/event/impl/AbstractRepositoryEventHandler.java?rev=605947&r1=605946&r2=605947&view=diff
==============================================================================
--- incubator/sling/trunk/sling/event/src/main/java/org/apache/sling/event/impl/AbstractRepositoryEventHandler.java (original)
+++ incubator/sling/trunk/sling/event/src/main/java/org/apache/sling/event/impl/AbstractRepositoryEventHandler.java Thu Dec 20 06:51:34 2007
@@ -36,7 +36,6 @@
import javax.jcr.observation.EventListener;
import org.apache.jackrabbit.JcrConstants;
-import org.apache.sling.core.CoreConstants;
import org.apache.sling.event.EventUtil;
import org.apache.sling.jcr.api.SlingRepository;
import org.osgi.service.component.ComponentContext;
@@ -60,6 +59,12 @@
public abstract class AbstractRepositoryEventHandler
implements EventHandler, EventListener, Runnable {
+ /** FIXME - This is a copy from the sling core constants to avoid
+ * a dependency just for the constant. We will move this into an
+ * OSGi helper bundle
+ */
+ public static final String SLING_ID = "sling.id";
+
/** Default log. */
protected final Logger logger = LoggerFactory.getLogger(this.getClass());
@@ -100,7 +105,7 @@
*/
protected void activate(final ComponentContext context)
throws RepositoryException {
- this.applicationId = context.getBundleContext().getProperty(CoreConstants.SLING_ID);
+ this.applicationId = context.getBundleContext().getProperty(SLING_ID);
this.repositoryPath = (String)context.getProperties().get(CONFIG_PROPERTY_REPO_PATH);
final Integer i = (Integer)context.getProperties().get(CONFIG_PROPERTY_CLEANUP_PERIOD);
if ( i != null ) {
Modified: incubator/sling/trunk/sling/event/src/test/java/org/apache/sling/event/impl/AbstractRepositoryEventHandlerTest.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/sling/event/src/test/java/org/apache/sling/event/impl/AbstractRepositoryEventHandlerTest.java?rev=605947&r1=605946&r2=605947&view=diff
==============================================================================
--- incubator/sling/trunk/sling/event/src/test/java/org/apache/sling/event/impl/AbstractRepositoryEventHandlerTest.java (original)
+++ incubator/sling/trunk/sling/event/src/test/java/org/apache/sling/event/impl/AbstractRepositoryEventHandlerTest.java Thu Dec 20 06:51:34 2007
@@ -29,7 +29,6 @@
import javax.jcr.Session;
import javax.jcr.observation.EventListenerIterator;
-import org.apache.sling.core.CoreConstants;
import org.apache.sling.jcr.api.SlingRepository;
import org.jmock.Expectations;
import org.jmock.Mockery;
@@ -86,7 +85,7 @@
// lets set up the bundle context with the sling id
final BundleContext bundleContext = this.getMockery().mock(BundleContext.class);
this.getMockery().checking(new Expectations() {{
- allowing(bundleContext).getProperty(CoreConstants.SLING_ID);
+ allowing(bundleContext).getProperty(AbstractRepositoryEventHandler.SLING_ID);
will(returnValue(SLING_ID));
}});
Modified: incubator/sling/trunk/sling/scheduler/pom.xml
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/sling/scheduler/pom.xml?rev=605947&r1=605946&r2=605947&view=diff
==============================================================================
--- incubator/sling/trunk/sling/scheduler/pom.xml (original)
+++ incubator/sling/trunk/sling/scheduler/pom.xml Thu Dec 20 06:51:34 2007
@@ -101,8 +101,12 @@
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ </dependency>
+ <dependency>
<groupId>org.apache.sling</groupId>
- <artifactId>org.apache.sling.core</artifactId>
+ <artifactId>org.apache.sling.api</artifactId>
<version>2.0.0-incubator-SNAPSHOT</version>
</dependency>
<!-- The following dependencies will be replaced by using the quartz wrapper bundle -->
Modified: incubator/sling/trunk/sling/scheduler/src/main/java/org/apache/sling/scheduler/impl/QuartzJobExecutor.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/sling/scheduler/src/main/java/org/apache/sling/scheduler/impl/QuartzJobExecutor.java?rev=605947&r1=605946&r2=605947&view=diff
==============================================================================
--- incubator/sling/trunk/sling/scheduler/src/main/java/org/apache/sling/scheduler/impl/QuartzJobExecutor.java (original)
+++ incubator/sling/trunk/sling/scheduler/src/main/java/org/apache/sling/scheduler/impl/QuartzJobExecutor.java Thu Dec 20 06:51:34 2007
@@ -20,7 +20,6 @@
import java.util.Map;
import org.apache.sling.api.services.ServiceLocator;
-import org.apache.sling.core.impl.services.ServiceLocatorImpl;
import org.apache.sling.scheduler.JobContext;
import org.osgi.framework.BundleContext;
import org.quartz.Job;
Added: incubator/sling/trunk/sling/scheduler/src/main/java/org/apache/sling/scheduler/impl/ServiceLocatorImpl.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/sling/scheduler/src/main/java/org/apache/sling/scheduler/impl/ServiceLocatorImpl.java?rev=605947&view=auto
==============================================================================
--- incubator/sling/trunk/sling/scheduler/src/main/java/org/apache/sling/scheduler/impl/ServiceLocatorImpl.java (added)
+++ incubator/sling/trunk/sling/scheduler/src/main/java/org/apache/sling/scheduler/impl/ServiceLocatorImpl.java Thu Dec 20 06:51:34 2007
@@ -0,0 +1,126 @@
+/*
+ * 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.scheduler.impl;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+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}. 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.api.services.ServiceLocator#getRequiredService(java.lang.Class)
+ */
+ 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 service;
+ }
+
+ /**
+ * @see org.apache.sling.api.services.ServiceLocator#getService(java.lang.Class)
+ */
+ @SuppressWarnings("unchecked")
+ public <ServiceType> ServiceType getService(Class<ServiceType> type) {
+ ServiceType service = (ServiceType) this.services.get(type.getName());
+ if (service == null) {
+ final ServiceReference ref = this.bundleContext.getServiceReference(type.getName());
+ if (ref != null) {
+ this.references.add(ref);
+ 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)
+ */
+ @SuppressWarnings("unchecked")
+ 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 dispose() {
+ final Iterator<ServiceReference> i = this.references.iterator();
+ while (i.hasNext()) {
+ final ServiceReference ref = i.next();
+ this.bundleContext.ungetService(ref);
+ }
+ this.references.clear();
+ this.services.clear();
+ }
+}
Propchange: incubator/sling/trunk/sling/scheduler/src/main/java/org/apache/sling/scheduler/impl/ServiceLocatorImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/sling/trunk/sling/scheduler/src/main/java/org/apache/sling/scheduler/impl/ServiceLocatorImpl.java
------------------------------------------------------------------------------
svn:keywords = author date id revision url