Author: pderop
Date: Sun Apr 25 22:25:34 2010
New Revision: 937901

URL: http://svn.apache.org/viewvc?rev=937901&view=rev
Log:
added MetaType support for factory configuration adapter

Added:
    
felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/FactoryConfigurationAdapterMetaTypeImpl.java
Modified:
    
felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/DependencyActivatorBase.java
    
felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/DependencyManager.java
    
felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/FactoryConfigurationAdapterImpl.java

Modified: 
felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/DependencyActivatorBase.java
URL: 
http://svn.apache.org/viewvc/felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/DependencyActivatorBase.java?rev=937901&r1=937900&r2=937901&view=diff
==============================================================================
--- 
felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/DependencyActivatorBase.java
 (original)
+++ 
felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/DependencyActivatorBase.java
 Sun Apr 25 22:25:34 2010
@@ -225,6 +225,37 @@ public abstract class DependencyActivato
         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.
      * 

Modified: 
felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/DependencyManager.java
URL: 
http://svn.apache.org/viewvc/felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/DependencyManager.java?rev=937901&r1=937900&r2=937901&view=diff
==============================================================================
--- 
felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/DependencyManager.java
 (original)
+++ 
felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/DependencyManager.java
 Sun Apr 25 22:25:34 2010
@@ -33,6 +33,7 @@ import org.apache.felix.dm.dependencies.
 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 @@ public class DependencyManager {
     }
 
     /**
+     * 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

Modified: 
felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/FactoryConfigurationAdapterImpl.java
URL: 
http://svn.apache.org/viewvc/felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/FactoryConfigurationAdapterImpl.java?rev=937901&r1=937900&r2=937901&view=diff
==============================================================================
--- 
felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/FactoryConfigurationAdapterImpl.java
 (original)
+++ 
felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/FactoryConfigurationAdapterImpl.java
 Sun Apr 25 22:25:34 2010
@@ -25,7 +25,10 @@ import java.util.Hashtable;
 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 @@ import org.osgi.service.cm.ManagedServic
 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.
      * 

Added: 
felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/FactoryConfigurationAdapterMetaTypeImpl.java
URL: 
http://svn.apache.org/viewvc/felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/FactoryConfigurationAdapterMetaTypeImpl.java?rev=937901&view=auto
==============================================================================
--- 
felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/FactoryConfigurationAdapterMetaTypeImpl.java
 (added)
+++ 
felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/FactoryConfigurationAdapterMetaTypeImpl.java
 Sun Apr 25 22:25:34 2010
@@ -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);
+    }
+}


Reply via email to