added MetaType support for factory configuration adapter
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@937901 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/dependencymanager/core/src/main/java/org/apache/felix/dm/DependencyActivatorBase.java b/dependencymanager/core/src/main/java/org/apache/felix/dm/DependencyActivatorBase.java
index 75287bc..736972c 100644
--- a/dependencymanager/core/src/main/java/org/apache/felix/dm/DependencyActivatorBase.java
+++ b/dependencymanager/core/src/main/java/org/apache/felix/dm/DependencyActivatorBase.java
@@ -225,6 +225,37 @@
return m_manager.createFactoryConfigurationAdapterService(factoryPid, update, adapterImplementation, adapterInterfaces, adapterProperties, propagate);
}
+ /**
+ * Creates a new Managed Service Factory Configuration Adapter with meta type support. For each new Config Admin factory configuration matching
+ * the factoryPid, an adapter will be created based on the adapter implementation class.
+ * The adapter will be registered with the specified interface, and with the specified adapter service properties.
+ * Depending on the <code>propagate</code> parameter, every public factory configuration properties
+ * (which don't start with ".") will be propagated along with the adapter service properties.
+ * It will also inherit all dependencies.
+ *
+ * @param factoryPid the pid matching the factory configuration
+ * @param update the adapter method name that will be notified when the factory configuration is created/updated.
+ * @param adapterInterfaces the interfaces to use when registering adapters (can be either a String, String array)
+ * @param adapterImplementation the implementation of the adapter (can be a Class or an Object instance)
+ * @param adapterProperties additional properties to use with the service registration
+ * @param propagate true if public factory configuration should be propagated to the adapter service properties
+ * @param heading The label used to display the tab name (or section) where the properties are displayed. Example: "Printer Service"
+ * @param desc A human readable description of the factory PID this configuration is associated with. Example: "Configuration for the PrinterService bundle"
+ * @param localization Points to the basename of the Properties file that can localize the Meta Type informations.
+ * The default localization base name for the properties is OSGI-INF/l10n/bundle, but can
+ * be overridden by the manifest Bundle-Localization header (see core specification, in section Localization on page 68).
+ * You can specify a specific localization basename file using this parameter (e.g. <code>"person"</code>
+ * will match person_du_NL.properties in the root bundle directory).
+ * @param propertiesMetaData Array of MetaData regarding configuration properties
+ * @return a service that acts as a factory for generating the managed service factory configuration adapter
+ */
+ public Service createFactoryConfigurationAdapterService(String factoryPid, String update, Object adapterImplementation, String[] adapterInterfaces, Dictionary adapterProperties, boolean propagate,
+ String heading, String desc, String localization, PropertyMetaData[] propertiesMetaData)
+ {
+ return m_manager.createFactoryConfigurationAdapterService(factoryPid, update, adapterImplementation, adapterInterfaces, adapterProperties, propagate,
+ heading, desc, localization, propertiesMetaData);
+ }
+
/**
* Cleans up all services and their dependencies.
*
diff --git a/dependencymanager/core/src/main/java/org/apache/felix/dm/DependencyManager.java b/dependencymanager/core/src/main/java/org/apache/felix/dm/DependencyManager.java
index 961e240..36f86b8 100644
--- a/dependencymanager/core/src/main/java/org/apache/felix/dm/DependencyManager.java
+++ b/dependencymanager/core/src/main/java/org/apache/felix/dm/DependencyManager.java
@@ -33,6 +33,7 @@
import org.apache.felix.dm.impl.AdapterImpl;
import org.apache.felix.dm.impl.AspectImpl;
import org.apache.felix.dm.impl.BundleAdapterImpl;
+import org.apache.felix.dm.impl.FactoryConfigurationAdapterMetaTypeImpl;
import org.apache.felix.dm.impl.Logger;
import org.apache.felix.dm.impl.FactoryConfigurationAdapterImpl;
import org.apache.felix.dm.impl.ResourceAdapterImpl;
@@ -370,6 +371,43 @@
}
/**
+ * Creates a new Managed Service Factory Configuration Adapter with meta type support. For each new Config Admin factory configuration matching
+ * the factoryPid, an adapter will be created based on the adapter implementation class.
+ * The adapter will be registered with the specified interface, and with the specified adapter service properties.
+ * Depending on the <code>propagate</code> parameter, every public factory configuration properties
+ * (which don't start with ".") will be propagated along with the adapter service properties.
+ * It will also inherit all dependencies.
+ *
+ * @param factoryPid the pid matching the factory configuration
+ * @param update the adapter method name that will be notified when the factory configuration is created/updated.
+ * @param adapterInterfaces the interfaces to use when registering adapters (can be either a String, String array)
+ * @param adapterImplementation the implementation of the adapter (can be a Class or an Object instance)
+ * @param adapterProperties additional properties to use with the service registration
+ * @param propagate true if public factory configuration should be propagated to the adapter service properties
+ * @param heading The label used to display the tab name (or section) where the properties are displayed. Example: "Printer Service"
+ * @param desc A human readable description of the factory PID this configuration is associated with. Example: "Configuration for the PrinterService bundle"
+ * @param localization Points to the basename of the Properties file that can localize the Meta Type informations.
+ * The default localization base name for the properties is OSGI-INF/l10n/bundle, but can
+ * be overridden by the manifest Bundle-Localization header (see core specification, in section Localization on page 68).
+ * You can specify a specific localization basename file using this parameter (e.g. <code>"person"</code>
+ * will match person_du_NL.properties in the root bundle directory).
+ * @param propertiesMetaData Array of MetaData regarding configuration properties
+ * @return a service that acts as a factory for generating the managed service factory configuration adapter
+ */
+ public Service createFactoryConfigurationAdapterService(String factoryPid, String update, Object adapterImplementation, String[] adapterInterfaces, Dictionary adapterProperties, boolean propagate,
+ String heading, String desc, String localization, PropertyMetaData[] propertiesMetaData)
+ {
+ Hashtable props = new Hashtable();
+ props.put(Constants.SERVICE_PID, factoryPid);
+ FactoryConfigurationAdapterMetaTypeImpl impl =
+ new FactoryConfigurationAdapterMetaTypeImpl(factoryPid, update, adapterImplementation, adapterInterfaces, adapterProperties, propagate,
+ m_context, m_logger, heading, desc, localization, propertiesMetaData);
+ return createService()
+ .setInterface(ManagedServiceFactory.class.getName(), props)
+ .setImplementation(impl);
+ }
+
+ /**
* Returns a list of services.
*
* @return a list of services
diff --git a/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/FactoryConfigurationAdapterImpl.java b/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/FactoryConfigurationAdapterImpl.java
index af30f09..a40b6c7 100644
--- a/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/FactoryConfigurationAdapterImpl.java
+++ b/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/FactoryConfigurationAdapterImpl.java
@@ -25,7 +25,10 @@
import java.util.List;
import org.apache.felix.dm.DependencyManager;
+import org.apache.felix.dm.dependencies.PropertyMetaData;
+import org.apache.felix.dm.impl.metatype.MetaTypeProviderImpl;
import org.apache.felix.dm.service.Service;
+import org.osgi.framework.BundleContext;
import org.osgi.service.cm.ManagedServiceFactory;
/**
@@ -34,29 +37,29 @@
public class FactoryConfigurationAdapterImpl extends AbstractDecorator implements ManagedServiceFactory
{
// The Adapter Service (we need to inherit all its dependencies).
- private volatile Service m_service;
+ protected volatile Service m_service;
// Our injected dependency manager
protected volatile DependencyManager m_dm;
// Our adapter implementation (either a Class, or an Object instance)
- private final Object m_adapterImplementation;
+ protected final Object m_adapterImplementation;
// Our adapter interface(s) (either null, a String, or a String array)
- private final Object m_adapterInterface;
+ protected final Object m_adapterInterface;
// Our adapter service properties (may be null)
- private final Dictionary m_adapterProperties;
+ protected final Dictionary m_adapterProperties;
// Our Managed Service Factory PID
- private String m_factoryPid;
+ protected String m_factoryPid;
// The adapter "update" method used to provide the configuration
- private String m_update;
+ protected String m_update;
// Tells if the CM config must be propagated along with the adapter service properties
- private boolean m_propagate;
-
+ protected boolean m_propagate;
+
/**
* Creates a new CM factory configuration adapter.
*
diff --git a/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/FactoryConfigurationAdapterMetaTypeImpl.java b/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/FactoryConfigurationAdapterMetaTypeImpl.java
new file mode 100644
index 0000000..4f4dd57
--- /dev/null
+++ b/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/FactoryConfigurationAdapterMetaTypeImpl.java
@@ -0,0 +1,52 @@
+package org.apache.felix.dm.impl;
+
+import java.util.Dictionary;
+
+import org.apache.felix.dm.dependencies.PropertyMetaData;
+import org.apache.felix.dm.impl.metatype.MetaTypeProviderImpl;
+import org.osgi.framework.BundleContext;
+import org.osgi.service.metatype.MetaTypeProvider;
+import org.osgi.service.metatype.ObjectClassDefinition;
+
+public class FactoryConfigurationAdapterMetaTypeImpl extends FactoryConfigurationAdapterImpl implements MetaTypeProvider
+{
+ // Our MetaType Provider for describing our properties metadata
+ private MetaTypeProviderImpl m_metaType;
+
+ /**
+ * Creates a new CM factory configuration adapter.
+ *
+ * @param factoryPid
+ * @param updateMethod
+ * @param adapterInterface
+ * @param adapterImplementation
+ * @param adapterProperties
+ * @param propagate
+ */
+ public FactoryConfigurationAdapterMetaTypeImpl(String factoryPid, String updateMethod, Object adapterImplementation, Object adapterInterface, Dictionary adapterProperties, boolean propagate,
+ BundleContext bctx, Logger logger, String heading, String description, String localization, PropertyMetaData[] properyMetaData)
+ {
+ super(factoryPid, updateMethod, adapterImplementation, adapterInterface, adapterProperties, propagate);
+ m_metaType = new MetaTypeProviderImpl(m_factoryPid, bctx, logger, null, this);
+ m_metaType.setName(heading);
+ m_metaType.setDescription(description);
+ if (localization != null)
+ {
+ m_metaType.setLocalization(localization);
+ }
+ for (int i = 0; i < properyMetaData.length; i ++)
+ {
+ m_metaType.add(properyMetaData[i]);
+ }
+ }
+
+ public String[] getLocales()
+ {
+ return m_metaType.getLocales();
+ }
+
+ public ObjectClassDefinition getObjectClassDefinition(String id, String locale)
+ {
+ return m_metaType.getObjectClassDefinition(id, locale);
+ }
+}