Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Watson2017-01-20 21:29:06 +0000
committerThomas Watson2017-01-20 22:10:43 +0000
commitfd327fcab66d794888abd97647d45b2fd7862745 (patch)
tree70861a1e07acfb420bab20f67a429e13ffc70d01 /bundles
parentd1a15a439a6771e579857a5302994ea40492580b (diff)
downloadrt.equinox.bundles-fd327fcab66d794888abd97647d45b2fd7862745.tar.gz
rt.equinox.bundles-fd327fcab66d794888abd97647d45b2fd7862745.tar.xz
rt.equinox.bundles-fd327fcab66d794888abd97647d45b2fd7862745.zip
Bug 510679 - Warnings in platform.doc.isv Javadoc log: missing sourcesI20170123-0830I20170123-0800I20170122-2000I20170121-2000I20170121-0950I20170120-2000
for org.apache.felix.scr Change-Id: I3cd6e36fd7295364b44f7a68e31a64e53ba24458 Signed-off-by: Thomas Watson <tjwatson@us.ibm.com>
Diffstat (limited to 'bundles')
-rw-r--r--bundles/org.eclipse.equinox.ds/META-INF/MANIFEST.MF8
-rw-r--r--bundles/org.eclipse.equinox.ds/src/org/apache/felix/scr/Component.java334
-rw-r--r--bundles/org.eclipse.equinox.ds/src/org/apache/felix/scr/Reference.java121
-rw-r--r--bundles/org.eclipse.equinox.ds/src/org/apache/felix/scr/ScrService.java85
-rw-r--r--bundles/org.eclipse.equinox.ds/src/org/apache/felix/scr/package.html15
-rw-r--r--bundles/org.eclipse.equinox.ds/src/org/eclipse/equinox/internal/ds/Activator.java33
-rw-r--r--bundles/org.eclipse.equinox.ds/src/org/eclipse/equinox/internal/ds/ScrServiceImpl.java346
7 files changed, 940 insertions, 2 deletions
diff --git a/bundles/org.eclipse.equinox.ds/META-INF/MANIFEST.MF b/bundles/org.eclipse.equinox.ds/META-INF/MANIFEST.MF
index 7ddb10403..8817efda4 100644
--- a/bundles/org.eclipse.equinox.ds/META-INF/MANIFEST.MF
+++ b/bundles/org.eclipse.equinox.ds/META-INF/MANIFEST.MF
@@ -7,12 +7,18 @@ Bundle-Vendor: %bundleVendor
Bundle-Activator: org.eclipse.equinox.internal.ds.Activator
Bundle-Description: This bundle provides support for OSGi
Declarative Services
+Export-Package: org.apache.felix.scr;version="1.6"
Import-Package:
org.eclipse.osgi.service.environment;version="1.3.0",
org.osgi.framework;version="1.8.0",
+ org.osgi.framework.dto;version="1.8.0",
org.osgi.framework.namespace;version="1.1.0",
org.osgi.framework.startlevel;version="1.0.0",
- org.osgi.framework.wiring;version="1.2.0"
+ org.osgi.framework.wiring;version="1.2.0",
+ org.osgi.service.component;version="1.3.0",
+ org.osgi.service.component.runtime;version="1.3.0",
+ org.osgi.service.component.runtime.dto;version="1.3.0",
+ org.osgi.util.tracker;version="1.5.0"
Require-Bundle: org.apache.felix.scr;bundle-version="[2.0.0,3.0.0)";visibility:=reexport
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Bundle-Localization: plugin
diff --git a/bundles/org.eclipse.equinox.ds/src/org/apache/felix/scr/Component.java b/bundles/org.eclipse.equinox.ds/src/org/apache/felix/scr/Component.java
new file mode 100644
index 000000000..ba7165cfd
--- /dev/null
+++ b/bundles/org.eclipse.equinox.ds/src/org/apache/felix/scr/Component.java
@@ -0,0 +1,334 @@
+/*
+ * 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.felix.scr;
+
+import java.util.Dictionary;
+import org.osgi.framework.Bundle;
+import org.osgi.service.component.ComponentInstance;
+
+/**
+ * The <code>Component</code> interface represents a single component managed
+ * by the Service Component Runtime. Management agents may access the Component
+ * instances through the {@link ScrService}.
+ * @deprecated * @deprecated clients should use {@link org.osgi.service.component.runtime.dto.ComponentDescriptionDTO} instead.
+ */
+@Deprecated
+public interface Component {
+
+ /**
+ * The Component has just been created and is still disabled or it has
+ * been disabled by calling the {@link #disable()} method (value is 1).
+ */
+ static final int STATE_DISABLED = 1;
+
+ /**
+ * The Component is being enabled (value is 512). After the component has
+ * been enabled it enters the {@link #STATE_UNSATISFIED} state.
+ * @since 1.2
+ */
+ static final int STATE_ENABLING = 512;
+
+ /**
+ * The Component has been enabled and is now going to be activated (value
+ * is 2).
+ * @deprecated as of version 1.2 the enabled state is collapsed into the
+ * {@link #STATE_UNSATISFIED} state. This status code is never returned
+ * from the {@link #getState()} method.
+ */
+ static final int STATE_ENABLED = 2;
+
+ /**
+ * The Component activation failed because any dependency is not satisfied
+ * (value is 4).
+ */
+ static final int STATE_UNSATISFIED = 4;
+
+ /**
+ * The Component is currently being activated either because it has been
+ * enabled or because any dependency which was previously unsatisfied has
+ * become satisfied (value is 8).
+ */
+ static final int STATE_ACTIVATING = 8;
+
+ /**
+ * The Component has successfully been activated and is fully functional
+ * (value is 16). This is the state of immediate components after
+ * successful activation. Delayed and Service Factory Components enter
+ * this state when the service instance has actually be instantiated because
+ * the service has been acquired.
+ */
+ static final int STATE_ACTIVE = 16;
+
+ /**
+ * The Component has successfully been activated but is a Delayed or Service
+ * Factory Component pending instantiation on first use (value is 32).
+ */
+ static final int STATE_REGISTERED = 32;
+
+ /**
+ * The Component is a Component Factory ready to create Component instances
+ * with the <code>ComponentFactory.newInstance(Dictionary)</code> method
+ * or (if enabled with the <code>ds.factory.enabled</code> configuration) to
+ * manage Component instances from configuration data received from the
+ * Configuration Admin Service (value is 64).
+ */
+ static final int STATE_FACTORY = 64;
+
+ /**
+ * The Component is being deactivated either because it is being disabled
+ * or because a dependency is not satisfied any more (value is 128). After
+ * deactivation the Component enters the {@link #STATE_UNSATISFIED} state.
+ */
+ static final int STATE_DEACTIVATING = 128;
+
+ /**
+ * The Component is being disabled (value is 1024). After the component has
+ * been disabled it enters the {@link #STATE_DISABLED} state.
+ * @since 1.2
+ */
+ static final int STATE_DISABLING = 1024;
+
+ /**
+ * The Component is being disposed off (value is 2048). After the component
+ * has been disposed off it enters the {@link #STATE_DESTROYED} state.
+ * @since 1.2
+ */
+ static final int STATE_DISPOSING = 2048;
+
+ /**
+ * The Component has been destroyed and cannot be used any more (value is
+ * 256). This state is only used when the bundle declaring the component
+ * is being stopped and all components have to be removed.
+ * @deprecated as of version 1.2 this constant has been renamed to
+ * {@link #STATE_DISPOSED}.
+ */
+ static final int STATE_DESTROYED = 256;
+
+ /**
+ * The Component has been disposed off and cannot be used any more (value is
+ * 256). This state is used when the bundle declaring the component
+ * is being stopped and all components have to be removed. This status is
+ * also the final status of a component after the
+ * <code>ComponentInstance.dispose()</code> method has been called.
+ * @since 1.2
+ */
+ static final int STATE_DISPOSED = 256;
+
+ /**
+ * Returns the component ID of this component. This ID is managed by the
+ * SCR. If the component is not currently enabled the ID might not be
+ * assigned to the component (yet) and this method will return -1 in this
+ * case.
+ */
+ long getId();
+
+ /**
+ * Returns the name of the component, which is also used as the service PID.
+ * This method provides access to the <code>name</code> attribute of the
+ * <code>component</code> element.
+ */
+ String getName();
+
+ /**
+ * Returns the current state of the Component, which is one of the
+ * <code>STATE_*</code> constants defined in this interface.
+ */
+ int getState();
+
+ /**
+ * Returns the <code>Bundle</code> declaring this component.
+ */
+ Bundle getBundle();
+
+ /**
+ * Returns the component factory name or <code>null</code> if this component
+ * is not defined as a component factory. This method provides access to
+ * the <code>factory</code> attribute of the <code>component</code>
+ * element.
+ */
+ String getFactory();
+
+ /**
+ * Returns <code>true</code> if this component is a service factory. This
+ * method returns the value of the <code>serviceFactory</code> attribute of
+ * the <code>service</code> element. If the component has no service
+ * element, this method returns <code>false</code>.
+ */
+ boolean isServiceFactory();
+
+ /**
+ * Returns the class name of the Component implementation. This method
+ * provides access to the <code>class</code> attribute of the
+ * <code>implementation</code> element.
+ */
+ String getClassName();
+
+ /**
+ * Returns whether the Component is declared to be enabled initially. This
+ * method provides access to the <code>enabled</code> attribute of the
+ * <code>component</code> element.
+ */
+ boolean isDefaultEnabled();
+
+ /**
+ * Returns whether the Component is an Immediate or a Delayed Component.
+ * This method provides access to the <code>immediate</code> attribute of
+ * the <code>component</code> element.
+ */
+ boolean isImmediate();
+
+ /**
+ * Returns an array of service names provided by this Component or
+ * <code>null</code> if the Component is not registered as a service. This
+ * method provides access to the <code>interface</code> attributes of the
+ * <code>provide</code> elements.
+ */
+ String[] getServices();
+
+ /**
+ * Returns the properties of the Component. The Dictionary returned is a
+ * private copy of the actual properties and contains the same entries as
+ * are used to register the Component as a service and are returned by
+ * the <code>ComponentContext.getProperties()</code> method.
+ */
+ Dictionary getProperties();
+
+ /**
+ * Returns an array of {@link Reference} instances representing the service
+ * references (or dependencies) of this Component. If the Component has no
+ * references, <code>null</code> is returned.
+ */
+ Reference[] getReferences();
+
+ /**
+ * Returns the <code>org.osgi.service.component.ComponentInstance</code>
+ * representing this component or <code>null</code> if this component
+ * is not been activated yet.
+ *
+ * @since 1.2
+ */
+ ComponentInstance getComponentInstance();
+
+ /**
+ * Returns the name of the method to be called when the component is being
+ * activated.
+ * <p>
+ * This method never returns <code>null</code>, that is, if this method is
+ * not declared in the component descriptor this method returns the
+ * default value <i>activate</i>.
+ *
+ * @since 1.2
+ */
+ String getActivate();
+
+ /**
+ * Returns <code>true</code> if the name of the method to be called on
+ * component activation (see {@link #getActivate()} is declared in the
+ * component descriptor or not.
+ * <p>
+ * For a component declared in a Declarative Services 1.0 descriptor, this
+ * method always returns <code>false</code>.
+ *
+ * @since 1.2
+ */
+ boolean isActivateDeclared();
+
+ /**
+ * Returns the name of the method to be called when the component is being
+ * deactivated.
+ * <p>
+ * This method never returns <code>null</code>, that is, if this method is
+ * not declared in the component descriptor this method returns the
+ * default value <i>deactivate</i>.
+ *
+ * @since 1.2
+ */
+ String getDeactivate();
+
+ /**
+ * Returns <code>true</code> if the name of the method to be called on
+ * component deactivation (see {@link #getDeactivate()} is declared in the
+ * component descriptor or not.
+ * <p>
+ * For a component declared in a Declarative Services 1.0 descriptor, this
+ * method always returns <code>false</code>.
+ *
+ * @since 1.2
+ */
+ boolean isDeactivateDeclared();
+
+ /**
+ * Returns the name of the method to be called when the component
+ * configuration has been updated or <code>null</code> if such a method is
+ * not declared in the component descriptor.
+ * <p>
+ * For a component declared in a Declarative Services 1.0 descriptor, this
+ * method always returns <code>null</code>.
+ *
+ * @since 1.2
+ */
+ String getModified();
+
+ /**
+ * Returns the configuration policy declared in the component descriptor.
+ * If the component descriptor is a Declarative Services 1.0 descriptor or
+ * not configuration policy has been declared, the default value
+ * <i>optional</i> is returned.
+ * <p>
+ * The returned string is one of the three policies defined in the
+ * Declarative Services specification 1.1:
+ * <dl>
+ * <dt>optional</dt>
+ * <dd>Configuration from the Configuration Admin service is supplied to
+ * the component if available. Otherwise the component is activated without
+ * Configuration Admin configuration. This is the default value reflecting
+ * the behavior of Declarative Services 1.0</dd>
+ * <dt>require</dt>
+ * <dd>Configuration is required. The component remains unsatisfied until
+ * configuration is available from the Configuration Admin service.</dd>
+ * <dt>ignore</dt>
+ * <dd>Configuration is ignored. No Configuration Admin service
+ * configuration is supplied to the component.</dd>
+ * </dl>
+ *
+ * @since 1.2
+ */
+ String getConfigurationPolicy();
+
+ /**
+ * Enables this Component if it is disabled. If the Component is not
+ * currently {@link #STATE_DISABLED disabled} this method has no effect. If
+ * the Component is {@link #STATE_DESTROYED destroyed}, this method throws
+ * an <code>IllegalStateException</code>.
+ *
+ * @throws IllegalStateException If the Component is destroyed.
+ */
+ void enable();
+
+ /**
+ * Disables this Component if it is enabled. If the Component is already
+ * {@link #STATE_DISABLED disabled} this method has no effect. If the
+ * Component is {@link #STATE_DESTROYED destroyed}, this method throws an
+ * <code>IllegalStateException</code>.
+ *
+ * @throws IllegalStateException If the Component is destroyed.
+ */
+ void disable();
+
+}
diff --git a/bundles/org.eclipse.equinox.ds/src/org/apache/felix/scr/Reference.java b/bundles/org.eclipse.equinox.ds/src/org/apache/felix/scr/Reference.java
new file mode 100644
index 000000000..6decd81df
--- /dev/null
+++ b/bundles/org.eclipse.equinox.ds/src/org/apache/felix/scr/Reference.java
@@ -0,0 +1,121 @@
+/*
+ * 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.felix.scr;
+
+import org.osgi.framework.ServiceReference;
+
+/**
+ * The <code>Reference</code> interface represents a single reference (or
+ * dependency) to a service used by a Component.
+ * @deprecated clients should use {@link org.osgi.service.component.runtime.dto.ReferenceDTO} instead.
+ */
+@Deprecated
+public interface Reference {
+
+ /**
+ * Returns the name of this Reference. This method provides access to the
+ * <code>name</code> attribute of the <code>reference</code> element.
+ */
+ String getName();
+
+ /**
+ * Returns the name of the service used by this Reference. This method
+ * provides access to the <code>interface</code> attribute of the
+ * <code>reference</code> element.
+ */
+ String getServiceName();
+
+ /**
+ * Returns an array of references to the services bound to this Reference
+ * or <code>null</code> if no services are currently bound.
+ */
+ ServiceReference[] getServiceReferences();
+
+ /**
+ * Returns whether this reference is satisfied. A {@link #isOptional() optional}
+ * component is always satisfied. Otherwise <code>true</code> is only
+ * returned if at least one service is bound.
+ */
+ boolean isSatisfied();
+
+ /**
+ * Returns whether this reference is optional. This method provides access
+ * to the lower bound of the <code>cardinality</code> attribute of the
+ * <code>reference</code> element. In other words, this method returns
+ * <code>true</code> if the cardinality is <em>0..1</em> or <em>0..n</em>.
+ */
+ boolean isOptional();
+
+ /**
+ * Returns whether this reference is multiple. This method provides access
+ * to the upper bound of the <code>cardinality</code> attribute of the
+ * <code>reference</code> element. In other words, this method returns
+ * <code>true</code> if the cardinality is <em>0..n</em> or <em>1..n</em>.
+ */
+ boolean isMultiple();
+
+ /**
+ * Returns <code>true</code> if the reference is defined with static policy.
+ * This method provides access to the <code>policy</code> element of the
+ * <code>reference</code> element. <code>true</code> is returned if the
+ * policy is defined as <em>static</em>.
+ */
+ boolean isStatic();
+
+ /**
+ * Returns the value of the target property of this reference. Initially
+ * (without overwriting configuration) this method provides access to the
+ * <code>target</code> attribute of the <code>reference</code> element. If
+ * configuration overwrites the target property, this method returns the
+ * value of the Component property whose name is derived from the
+ * {@link #getName() reference name} plus the suffix <em>.target</em>. If
+ * no target property exists this method returns <code>null</code>.
+ */
+ String getTarget();
+
+ /**
+ * Returns the name of the method called if a service is being bound to
+ * the Component or <code>null</code> if no such method is configured. This
+ * method provides access to the <code>bind</code> attribute of the
+ * <code>reference</code> element.
+ */
+ String getBindMethodName();
+
+ /**
+ * Returns the name of the method called if a service is being unbound from
+ * the Component or <code>null</code> if no such method is configured. This
+ * method provides access to the <code>unbind</code> attribute of the
+ * <code>reference</code> element.
+ */
+ String getUnbindMethodName();
+
+ /**
+ * Returns the name of the method called if a bound service updates its
+ * service registration properties or <code>null</code> if no such method
+ * is configured. This method provides access to the <code>updated</code>
+ * attribute of the <code>reference</code> element.
+ * <p>
+ * For a component declared in a Declarative Services 1.0 and 1.1
+ * descriptor, this method always returns <code>null</code>.
+ *
+ * @since 1.4
+ */
+ String getUpdatedMethodName();
+
+}
diff --git a/bundles/org.eclipse.equinox.ds/src/org/apache/felix/scr/ScrService.java b/bundles/org.eclipse.equinox.ds/src/org/apache/felix/scr/ScrService.java
new file mode 100644
index 000000000..f39661ae8
--- /dev/null
+++ b/bundles/org.eclipse.equinox.ds/src/org/apache/felix/scr/ScrService.java
@@ -0,0 +1,85 @@
+/*
+ * 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.felix.scr;
+
+import org.osgi.framework.Bundle;
+
+/**
+ * The <code>ScrService</code> represents the Declarative Services main
+ * controller also known as the Service Component Runtime or SCR for short.
+ * It provides access to the components managed the SCR.
+ * @deprecated clients should use {@link org.osgi.service.component.runtime.ServiceComponentRuntime} instead.
+ */
+@Deprecated
+public interface ScrService {
+
+ /**
+ * Returns an array of all components managed by this SCR instance. The
+ * components are returned in ascending order of their component.id. If
+ * there are no components currently managed by the SCR, <code>null</code>
+ * is returned.
+ *
+ * @return The components or <code>null</code> if there are none.
+ */
+ Component[] getComponents();
+
+ /**
+ * Returns the component whose component.id matches the given
+ * <code>componentId</code> or <code>null</code> if no component with the
+ * given id is currently managed.
+ *
+ * @param componentId The ID of the component to return
+ *
+ * @return The indicated component or <code>null</code> if no such
+ * component exists.
+ */
+ Component getComponent(long componentId);
+
+ /**
+ * Returns the components whose <code>component.name</code> matches the
+ * given <code>componentName</code> or <code>null</code> if no component
+ * with the given name is currently managed.
+ * <p>
+ * If the component name refers to a component factory component or a
+ * component configured with multiple factory configurations this method
+ * returns multiple component instances.
+ *
+ * @param componentName The name of the component to return
+ *
+ * @return The indicated components or <code>null</code> if no such
+ * component exists.
+ * @since 1.5 (Apache Felix Declarative Services 1.4.2)
+ */
+ Component[] getComponents(String componentName);
+
+ /**
+ * Returns an array of all components managed by this SCR instance on
+ * behalf of the given bundle. The components are returned in ascending
+ * order of their component.id. If there are no components managed by the
+ * SCR for the given bundle, <code>null</code> is returned.
+ *
+ * @param bundle The <code>Bundle</code> whose components are to be
+ * returned.
+ *
+ * @return The bundle's components or <code>null</code> if the bundle
+ * has none.
+ */
+ Component[] getComponents(Bundle bundle);
+
+}
diff --git a/bundles/org.eclipse.equinox.ds/src/org/apache/felix/scr/package.html b/bundles/org.eclipse.equinox.ds/src/org/apache/felix/scr/package.html
new file mode 100644
index 000000000..4efb8d91b
--- /dev/null
+++ b/bundles/org.eclipse.equinox.ds/src/org/apache/felix/scr/package.html
@@ -0,0 +1,15 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
+<html>
+<head>
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
+ <title>Package-level Javadoc</title>
+</head>
+<body>
+Provides access to the components managed by the Service Component Runtime (Declarative Services).
+<h2>
+Package Specification</h2>
+<p>
+This package specifies API for accessing to the components managed by the Service Component Runtime (Declarative Services).
+</p>
+</body>
+</html>
diff --git a/bundles/org.eclipse.equinox.ds/src/org/eclipse/equinox/internal/ds/Activator.java b/bundles/org.eclipse.equinox.ds/src/org/eclipse/equinox/internal/ds/Activator.java
index 6c8e325c1..509d77514 100644
--- a/bundles/org.eclipse.equinox.ds/src/org/eclipse/equinox/internal/ds/Activator.java
+++ b/bundles/org.eclipse.equinox.ds/src/org/eclipse/equinox/internal/ds/Activator.java
@@ -11,18 +11,26 @@
package org.eclipse.equinox.internal.ds;
import java.util.List;
+import org.apache.felix.scr.ScrService;
import org.eclipse.osgi.service.environment.EnvironmentInfo;
import org.osgi.framework.*;
import org.osgi.framework.namespace.BundleNamespace;
import org.osgi.framework.startlevel.BundleStartLevel;
import org.osgi.framework.wiring.BundleWire;
import org.osgi.framework.wiring.BundleWiring;
+import org.osgi.service.component.runtime.ServiceComponentRuntime;
+import org.osgi.util.tracker.ServiceTracker;
+import org.osgi.util.tracker.ServiceTrackerCustomizer;
-public class Activator implements BundleActivator {
+@SuppressWarnings("deprecation")
+public class Activator implements BundleActivator, ServiceTrackerCustomizer<ServiceComponentRuntime, ServiceRegistration<ScrService>> {
+ private BundleContext bc;
private Bundle scr;
+ private ServiceTracker<ServiceComponentRuntime, ServiceRegistration<ScrService>> tracker;
public void start(BundleContext context) throws Exception {
+ this.bc = context;
ServiceReference<EnvironmentInfo> envInfoRef = context.getServiceReference(EnvironmentInfo.class);
EnvironmentInfo envInfo = null;
if (envInfoRef != null) {
@@ -50,10 +58,33 @@ public class Activator implements BundleActivator {
BundleStartLevel scrStartLevel = scr.adapt(BundleStartLevel.class);
scrStartLevel.setStartLevel(equinoxSDstartLevel.getStartLevel());
scr.start(Bundle.START_TRANSIENT);
+ tracker = new ServiceTracker<ServiceComponentRuntime, ServiceRegistration<ScrService>>(context, ServiceComponentRuntime.class, this);
+ tracker.open();
}
public void stop(BundleContext context) throws Exception {
+ tracker.close();
scr.stop(Bundle.STOP_TRANSIENT);
}
+ @Override
+ public ServiceRegistration<ScrService> addingService(ServiceReference<ServiceComponentRuntime> reference) {
+ ServiceComponentRuntime scrService = bc.getService(reference);
+ if (scr != null) {
+ return bc.registerService(ScrService.class, new ScrServiceImpl(scrService, bc), null);
+ }
+ return null;
+ }
+
+ @Override
+ public void modifiedService(ServiceReference<ServiceComponentRuntime> reference, ServiceRegistration<ScrService> reg) {
+ // do nothing
+ }
+
+ @Override
+ public void removedService(ServiceReference<ServiceComponentRuntime> reference, ServiceRegistration<ScrService> reg) {
+ reg.unregister();
+ bc.ungetService(reference);
+ }
+
}
diff --git a/bundles/org.eclipse.equinox.ds/src/org/eclipse/equinox/internal/ds/ScrServiceImpl.java b/bundles/org.eclipse.equinox.ds/src/org/eclipse/equinox/internal/ds/ScrServiceImpl.java
new file mode 100644
index 000000000..7f5a97f35
--- /dev/null
+++ b/bundles/org.eclipse.equinox.ds/src/org/eclipse/equinox/internal/ds/ScrServiceImpl.java
@@ -0,0 +1,346 @@
+/*******************************************************************************
+ * Copyright (c) 2017 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.equinox.internal.ds;
+
+import java.util.*;
+import java.util.Map.Entry;
+import org.apache.felix.scr.*;
+import org.osgi.framework.*;
+import org.osgi.framework.dto.ServiceReferenceDTO;
+import org.osgi.service.component.ComponentConstants;
+import org.osgi.service.component.ComponentInstance;
+import org.osgi.service.component.runtime.ServiceComponentRuntime;
+import org.osgi.service.component.runtime.dto.*;
+
+@Deprecated
+public class ScrServiceImpl implements ScrService {
+ final ServiceComponentRuntime scr;
+ final BundleContext context;
+
+ ScrServiceImpl(ServiceComponentRuntime scr, BundleContext context) {
+ this.scr = scr;
+ this.context = context.getBundle(Constants.SYSTEM_BUNDLE_LOCATION).getBundleContext();
+ }
+
+ @Override
+ public Component[] getComponents() {
+ return toComponents(scr.getComponentDescriptionDTOs());
+ }
+
+ private Component[] toComponents(Collection<ComponentDescriptionDTO> componentDescriptionDTOs) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public Component getComponent(long componentId) {
+ for (ComponentDescriptionDTO dto : scr.getComponentDescriptionDTOs()) {
+ Long id = (Long) dto.properties.get(ComponentConstants.COMPONENT_ID);
+ if (componentId == id) {
+ return toComponent(dto);
+ }
+ }
+ return null;
+ }
+
+ private Component toComponent(ComponentDescriptionDTO dto) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public Component[] getComponents(String componentName) {
+ Collection<ComponentDescriptionDTO> dtos = new ArrayList<ComponentDescriptionDTO>();
+ for (ComponentDescriptionDTO dto : scr.getComponentDescriptionDTOs()) {
+ if (componentName.equals(dto.name)) {
+ dtos.add(dto);
+ }
+ }
+ return toComponents(dtos);
+ }
+
+ @Override
+ public Component[] getComponents(Bundle bundle) {
+ return toComponents(scr.getComponentDescriptionDTOs(bundle));
+ }
+
+ ServiceReference<?> getServiceReference(long id) {
+ try {
+ ServiceReference<?>[] refs = context.getServiceReferences((String) null, "(" + Constants.SERVICE_ID + "=" + id + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ if (refs != null && refs.length > 0) {
+ return refs[0];
+ }
+ } catch (InvalidSyntaxException e) {
+ throw new RuntimeException(e);
+ }
+ return null;
+ }
+
+ class ComponentImpl implements Component {
+ private final ComponentConfigurationDTO config;
+
+ ComponentImpl(ComponentConfigurationDTO config) {
+ this.config = config;
+ }
+
+ @Override
+ public long getId() {
+ return config.id;
+ }
+
+ @Override
+ public String getName() {
+ return config.description.name;
+ }
+
+ @Override
+ public int getState() {
+ switch (config.state) {
+ case ComponentConfigurationDTO.ACTIVE :
+ return Component.STATE_ACTIVE;
+ case ComponentConfigurationDTO.SATISFIED :
+ return Component.STATE_REGISTERED;
+ case ComponentConfigurationDTO.UNSATISFIED_CONFIGURATION :
+ return Component.STATE_UNSATISFIED;
+ case ComponentConfigurationDTO.UNSATISFIED_REFERENCE :
+ return Component.STATE_UNSATISFIED;
+ default :
+ break;
+ }
+ return Component.STATE_DISABLED;
+ }
+
+ @Override
+ public Bundle getBundle() {
+ return context.getBundle(config.description.bundle.id);
+ }
+
+ @Override
+ public String getFactory() {
+ return config.description.factory;
+ }
+
+ @Override
+ public boolean isServiceFactory() {
+ return Constants.SCOPE_BUNDLE.equals(config.description.scope);
+ }
+
+ @Override
+ public String getClassName() {
+ return config.description.implementationClass;
+ }
+
+ @Override
+ public boolean isDefaultEnabled() {
+ return config.description.defaultEnabled;
+ }
+
+ @Override
+ public boolean isImmediate() {
+ return config.description.immediate;
+ }
+
+ @Override
+ public String[] getServices() {
+ return config.description.serviceInterfaces;
+ }
+
+ @SuppressWarnings({"rawtypes", "unchecked"})
+ @Override
+ public Dictionary getProperties() {
+ return new Hashtable(config.description.properties);
+ }
+
+ @Override
+ public Reference[] getReferences() {
+ if (config.description.references.length == 0) {
+ return null;
+ }
+ Map<String, ReferenceDTO> referenceDTOs = new HashMap<String, ReferenceDTO>();
+ for (ReferenceDTO reference : config.description.references) {
+ referenceDTOs.put(reference.name, reference);
+ }
+ Map<String, SatisfiedReferenceDTO> satisfiedDTOs = new HashMap<String, SatisfiedReferenceDTO>();
+ for (SatisfiedReferenceDTO satisfied : config.satisfiedReferences) {
+ satisfiedDTOs.put(satisfied.name, satisfied);
+ }
+ Map<String, UnsatisfiedReferenceDTO> unsatisfiedDTOs = new HashMap<String, UnsatisfiedReferenceDTO>();
+ for (UnsatisfiedReferenceDTO unsatisfied : config.unsatisfiedReferences) {
+ unsatisfiedDTOs.put(unsatisfied.name, unsatisfied);
+ }
+ return toReferences(referenceDTOs, satisfiedDTOs, unsatisfiedDTOs);
+ }
+
+ private Reference[] toReferences(Map<String, ReferenceDTO> referenceDTOs, Map<String, SatisfiedReferenceDTO> satisfiedDTOs, Map<String, UnsatisfiedReferenceDTO> unsatisfiedDTOs) {
+ Collection<Reference> references = new ArrayList<Reference>();
+ for (Entry<String, SatisfiedReferenceDTO> satisfied : satisfiedDTOs.entrySet()) {
+ references.add(new SatsifiedReference(satisfied.getValue(), referenceDTOs.get(satisfied.getValue().name)));
+ }
+ for (Entry<String, UnsatisfiedReferenceDTO> unsatisfied : unsatisfiedDTOs.entrySet()) {
+ references.add(new UnsatsifiedReference(unsatisfied.getValue(), referenceDTOs.get(unsatisfied.getValue().name)));
+ }
+ return references.toArray(new Reference[0]);
+ }
+
+ @Override
+ public ComponentInstance getComponentInstance() {
+ throw new UnsupportedOperationException("Not supported."); //$NON-NLS-1$
+ }
+
+ @Override
+ public String getActivate() {
+ return config.description.activate;
+ }
+
+ @Override
+ public boolean isActivateDeclared() {
+ return config.description.activate != null;
+ }
+
+ @Override
+ public String getDeactivate() {
+ return config.description.deactivate;
+ }
+
+ @Override
+ public boolean isDeactivateDeclared() {
+ return config.description.deactivate != null;
+ }
+
+ @Override
+ public String getModified() {
+ return config.description.modified;
+ }
+
+ @Override
+ public String getConfigurationPolicy() {
+ return config.description.configurationPolicy;
+ }
+
+ @Override
+ public void enable() {
+ scr.disableComponent(config.description);
+ }
+
+ @Override
+ public void disable() {
+ scr.disableComponent(config.description);
+ }
+ }
+
+ abstract class ReferenceBase implements Reference {
+ protected final ReferenceDTO reference;
+
+ ReferenceBase(ReferenceDTO reference) {
+ this.reference = reference;
+ }
+
+ @Override
+ public String getName() {
+ return reference.name;
+ }
+
+ @Override
+ public String getServiceName() {
+ return reference.interfaceName;
+ }
+
+ @Override
+ public boolean isOptional() {
+ return reference.cardinality.startsWith("0"); //$NON-NLS-1$
+ }
+
+ @Override
+ public boolean isMultiple() {
+ return reference.cardinality.startsWith("1"); //$NON-NLS-1$
+ }
+
+ @Override
+ public boolean isStatic() {
+ return "static".equals(reference.policy); //$NON-NLS-1$
+ }
+
+ @Override
+ public String getTarget() {
+ return reference.target;
+ }
+
+ @Override
+ public String getBindMethodName() {
+ return reference.bind;
+ }
+
+ @Override
+ public String getUnbindMethodName() {
+ return reference.unbind;
+ }
+
+ @Override
+ public String getUpdatedMethodName() {
+ return reference.updated;
+ }
+ }
+
+ class SatsifiedReference extends ReferenceBase {
+ private final SatisfiedReferenceDTO satisfied;
+
+ SatsifiedReference(SatisfiedReferenceDTO satisifed, ReferenceDTO reference) {
+ super(reference);
+ this.satisfied = satisifed;
+ }
+
+ @SuppressWarnings("rawtypes")
+ @Override
+ public ServiceReference[] getServiceReferences() {
+ Collection<ServiceReference<?>> serviceReferences = new ArrayList<ServiceReference<?>>();
+ for (ServiceReferenceDTO serviceRefDTO : satisfied.boundServices) {
+ ServiceReference<?> ref = getServiceReference(serviceRefDTO.id);
+ if (ref != null) {
+ serviceReferences.add(ref);
+ }
+ }
+ return serviceReferences.isEmpty() ? null : serviceReferences.toArray(new ServiceReference[0]);
+ }
+
+ @Override
+ public boolean isSatisfied() {
+ return true;
+ }
+ }
+
+ class UnsatsifiedReference extends ReferenceBase {
+ private final UnsatisfiedReferenceDTO unsatisfied;
+
+ UnsatsifiedReference(UnsatisfiedReferenceDTO unsatisifed, ReferenceDTO reference) {
+ super(reference);
+ this.unsatisfied = unsatisifed;
+ }
+
+ @SuppressWarnings("rawtypes")
+ @Override
+ public ServiceReference[] getServiceReferences() {
+ Collection<ServiceReference<?>> serviceReferences = new ArrayList<ServiceReference<?>>();
+ for (ServiceReferenceDTO serviceRefDTO : unsatisfied.targetServices) {
+ ServiceReference<?> ref = getServiceReference(serviceRefDTO.id);
+ if (ref != null) {
+ serviceReferences.add(ref);
+ }
+ }
+ return serviceReferences.isEmpty() ? null : serviceReferences.toArray(new ServiceReference[0]);
+ }
+
+ @Override
+ public boolean isSatisfied() {
+ return false;
+ }
+ }
+
+}

Back to the top