felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fmesc...@apache.org
Subject svn commit: r1403229 - /felix/trunk/metatype/src/main/java/org/apache/felix/metatype/internal/
Date Mon, 29 Oct 2012 10:16:31 GMT
Author: fmeschbe
Date: Mon Oct 29 10:16:31 2012
New Revision: 1403229

URL: http://svn.apache.org/viewvc?rev=1403229&view=rev
Log:
FELIX-3740 Consolidate and streamline handling of MetaTypeProvider
services and ManagedService[Factory] services implementing MetaTypeProvider

Added:
    felix/trunk/metatype/src/main/java/org/apache/felix/metatype/internal/BaseProviderHolder.java
    felix/trunk/metatype/src/main/java/org/apache/felix/metatype/internal/MetaTypeProviderHolder.java
Modified:
    felix/trunk/metatype/src/main/java/org/apache/felix/metatype/internal/Activator.java
    felix/trunk/metatype/src/main/java/org/apache/felix/metatype/internal/ManagedServiceHolder.java
    felix/trunk/metatype/src/main/java/org/apache/felix/metatype/internal/ManagedServiceTracker.java
    felix/trunk/metatype/src/main/java/org/apache/felix/metatype/internal/MetaTypeProviderTracker.java
    felix/trunk/metatype/src/main/java/org/apache/felix/metatype/internal/MetaTypeServiceImpl.java
    felix/trunk/metatype/src/main/java/org/apache/felix/metatype/internal/ServiceMetaTypeInformation.java

Modified: felix/trunk/metatype/src/main/java/org/apache/felix/metatype/internal/Activator.java
URL: http://svn.apache.org/viewvc/felix/trunk/metatype/src/main/java/org/apache/felix/metatype/internal/Activator.java?rev=1403229&r1=1403228&r2=1403229&view=diff
==============================================================================
--- felix/trunk/metatype/src/main/java/org/apache/felix/metatype/internal/Activator.java (original)
+++ felix/trunk/metatype/src/main/java/org/apache/felix/metatype/internal/Activator.java Mon
Oct 29 10:16:31 2012
@@ -193,7 +193,7 @@ public class Activator implements Bundle
         if ( sr != null )
         {
             final String name;
-            String[] pids = ServiceMetaTypeInformation.getServicePids( sr );
+            String[] pids = BaseProviderHolder.getServicePids( sr );
             if ( pids != null )
             {
                 name = pids[0];

Added: felix/trunk/metatype/src/main/java/org/apache/felix/metatype/internal/BaseProviderHolder.java
URL: http://svn.apache.org/viewvc/felix/trunk/metatype/src/main/java/org/apache/felix/metatype/internal/BaseProviderHolder.java?rev=1403229&view=auto
==============================================================================
--- felix/trunk/metatype/src/main/java/org/apache/felix/metatype/internal/BaseProviderHolder.java
(added)
+++ felix/trunk/metatype/src/main/java/org/apache/felix/metatype/internal/BaseProviderHolder.java
Mon Oct 29 10:16:31 2012
@@ -0,0 +1,101 @@
+/*
+ * 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.metatype.internal;
+
+
+import java.util.Arrays;
+import java.util.Collection;
+
+import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.metatype.MetaTypeProvider;
+
+
+public class BaseProviderHolder
+{
+
+    private final ServiceReference reference;
+    private final MetaTypeProvider provider;
+
+
+    BaseProviderHolder( final ServiceReference reference, final MetaTypeProvider provider
)
+    {
+        this.reference = reference;
+        this.provider = provider;
+    }
+
+
+    public ServiceReference getReference()
+    {
+        return reference;
+    }
+
+
+    public MetaTypeProvider getProvider()
+    {
+        return provider;
+    }
+
+
+    static String[] getServicePids( final ServiceReference ref )
+    {
+        return getStringPlus( ref, Constants.SERVICE_PID );
+    }
+
+
+    static String[] getStringPlus( final ServiceReference ref, final String propertyName
)
+    {
+        final String[] res;
+        Object prop = ref.getProperty( propertyName );
+        if ( prop == null )
+        {
+            res = null;
+        }
+        else if ( prop instanceof String )
+        {
+            res = new String[]
+                { ( String ) prop };
+        }
+        else if ( prop instanceof Collection )
+        {
+            final Object[] col = ( ( Collection ) prop ).toArray();
+            res = new String[col.length];
+            for ( int i = 0; i < res.length; i++ )
+            {
+                res[i] = String.valueOf( col[i] );
+            }
+        }
+        else if ( prop.getClass().isArray() && String.class.equals( prop.getClass().getComponentType()
) )
+        {
+            res = ( String[] ) prop;
+        }
+        else
+        {
+            // unsupported type of property
+            res = null;
+        }
+
+        if ( res != null )
+        {
+            Arrays.sort( res );
+        }
+
+        return res;
+    }
+}

Modified: felix/trunk/metatype/src/main/java/org/apache/felix/metatype/internal/ManagedServiceHolder.java
URL: http://svn.apache.org/viewvc/felix/trunk/metatype/src/main/java/org/apache/felix/metatype/internal/ManagedServiceHolder.java?rev=1403229&r1=1403228&r2=1403229&view=diff
==============================================================================
--- felix/trunk/metatype/src/main/java/org/apache/felix/metatype/internal/ManagedServiceHolder.java
(original)
+++ felix/trunk/metatype/src/main/java/org/apache/felix/metatype/internal/ManagedServiceHolder.java
Mon Oct 29 10:16:31 2012
@@ -1,71 +1,60 @@
-/*************************************************************************
-*
-* ADOBE CONFIDENTIAL
-* ___________________
-*
-*  Copyright 2012 Adobe Systems Incorporated
-*  All Rights Reserved.
-*
-* NOTICE:  All information contained herein is, and remains
-* the property of Adobe Systems Incorporated and its suppliers,
-* if any.  The intellectual and technical concepts contained
-* herein are proprietary to Adobe Systems Incorporated and its
-* suppliers and are protected by trade secret or copyright law.
-* Dissemination of this information or reproduction of this material
-* is strictly forbidden unless prior written permission is obtained
-* from Adobe Systems Incorporated.
-**************************************************************************/
+/*
+ * 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.metatype.internal;
 
+
 import java.util.Arrays;
 
+import org.osgi.framework.Constants;
 import org.osgi.framework.ServiceReference;
 import org.osgi.service.metatype.MetaTypeProvider;
 
-class ManagedServiceHolder
+
+class ManagedServiceHolder extends BaseProviderHolder
 {
-    private final ServiceReference ref;
-    private final MetaTypeProvider provider;
     private String[] pids;
     private boolean isSingleton;
     private boolean isFactory;
 
 
-    ManagedServiceHolder( final ServiceReference ref, final MetaTypeProvider provider )
-    {
-        this.ref = ref;
-        this.provider = provider;
-        this.pids = ServiceMetaTypeInformation.getServicePids( ref );
-        this.isSingleton = ServiceMetaTypeInformation.isService( ref, ManagedServiceTracker.MANAGED_SERVICE
);
-        this.isFactory = ServiceMetaTypeInformation.isService( ref, ManagedServiceTracker.MANAGED_SERVICE_FACTORY
);
-    }
-
-
-    public ServiceReference getRef()
-    {
-        return ref;
-    }
-
-
-    public MetaTypeProvider getProvider()
+    ManagedServiceHolder( final ServiceReference reference, final MetaTypeProvider provider
)
     {
-        return provider;
+        super( reference, provider );
+        this.pids = BaseProviderHolder.getServicePids( reference );
+        this.isSingleton = ManagedServiceHolder.isService( reference, ManagedServiceTracker.MANAGED_SERVICE
);
+        this.isFactory = ManagedServiceHolder.isService( reference, ManagedServiceTracker.MANAGED_SERVICE_FACTORY
);
     }
 
 
-    public String[] getPids()
+    String[] getPids()
     {
         return pids;
     }
 
 
-    public boolean isSingleton()
+    boolean isSingleton()
     {
         return isSingleton;
     }
 
 
-    public boolean isFactory()
+    boolean isFactory()
     {
         return isFactory;
     }
@@ -73,7 +62,7 @@ class ManagedServiceHolder
 
     void update( final MetaTypeServiceImpl mts )
     {
-        final String[] newPids = ServiceMetaTypeInformation.getServicePids( getRef() );
+        final String[] newPids = BaseProviderHolder.getServicePids( getReference() );
         if ( !Arrays.equals( this.getPids(), newPids ) )
         {
             mts.removeService( this );
@@ -81,4 +70,21 @@ class ManagedServiceHolder
             mts.addService( this );
         }
     }
+
+
+    private static boolean isService( final ServiceReference ref, final String type )
+    {
+        String[] oc = ( String[] ) ref.getProperty( Constants.OBJECTCLASS );
+        if ( oc != null )
+        {
+            for ( int i = 0; i < oc.length; i++ )
+            {
+                if ( oc[i].equals( type ) )
+                {
+                    return true;
+                }
+            }
+        }
+        return false;
+    }
 }
\ No newline at end of file

Modified: felix/trunk/metatype/src/main/java/org/apache/felix/metatype/internal/ManagedServiceTracker.java
URL: http://svn.apache.org/viewvc/felix/trunk/metatype/src/main/java/org/apache/felix/metatype/internal/ManagedServiceTracker.java?rev=1403229&r1=1403228&r2=1403229&view=diff
==============================================================================
--- felix/trunk/metatype/src/main/java/org/apache/felix/metatype/internal/ManagedServiceTracker.java
(original)
+++ felix/trunk/metatype/src/main/java/org/apache/felix/metatype/internal/ManagedServiceTracker.java
Mon Oct 29 10:16:31 2012
@@ -19,7 +19,6 @@
 package org.apache.felix.metatype.internal;
 
 
-
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.InvalidSyntaxException;
 import org.osgi.framework.ServiceReference;
@@ -27,11 +26,6 @@ import org.osgi.service.metatype.MetaTyp
 import org.osgi.util.tracker.ServiceTracker;
 
 
-/**
- * The {@code ManagedServiceTracker} tracks ManagedService and
- * ManagedServiceFactory services on behalf of MetaTypeInformation
- * implementations not being based on a metatype descriptor.
- */
 public class ManagedServiceTracker extends ServiceTracker
 {
 
@@ -39,29 +33,12 @@ public class ManagedServiceTracker exten
 
     static final String MANAGED_SERVICE_FACTORY = "org.osgi.service.cm.ManagedServiceFactory";
 
-    /**
-     * The filter specification to find <code>ManagedService</code>s and
-     * <code>ManagedServiceFactory</code>s as well as to register a service
-     * listener for those services (value is
-     * "(|(objectClass=org.osgi.service.cm.ManagedService)(objectClass=org.osgi.service.cm.ManagedServiceFactory))").
-     * We use the hard coded class name here to not create a dependency on the
-     * ConfigurationAdmin service, which may not be available.
-     */
     private static final String FILTER = "(|(objectClass=" + MANAGED_SERVICE + ")(objectClass="
         + MANAGED_SERVICE_FACTORY + "))";
 
     private final MetaTypeServiceImpl mts;
 
 
-    /**
-     * Creates an instance of this class handling services of the given
-     * <code>bundle</code>.
-     *
-     * @param bundleContext The <code>BundleContext</code> used to get and
-     *            unget services.
-     * @param bundle The <code>Bundle</code> whose services are handled by
-     *            this class.
-     */
     public ManagedServiceTracker( BundleContext bundleContext, MetaTypeServiceImpl mts )
throws InvalidSyntaxException
     {
         super( bundleContext, bundleContext.createFilter( FILTER ), null );
@@ -83,7 +60,6 @@ public class ManagedServiceTracker exten
         // not a MetaTypeProvider implementation, don't track
         this.context.ungetService( reference );
         return null;
-
     }
 
 
@@ -95,8 +71,7 @@ public class ManagedServiceTracker exten
 
     public void removedService( ServiceReference reference, Object service )
     {
-        final ManagedServiceHolder holder = ( ManagedServiceHolder ) service;
-        mts.removeService( holder );
+        mts.removeService( ( ManagedServiceHolder ) service );
         this.context.ungetService( reference );
     }
 }

Added: felix/trunk/metatype/src/main/java/org/apache/felix/metatype/internal/MetaTypeProviderHolder.java
URL: http://svn.apache.org/viewvc/felix/trunk/metatype/src/main/java/org/apache/felix/metatype/internal/MetaTypeProviderHolder.java?rev=1403229&view=auto
==============================================================================
--- felix/trunk/metatype/src/main/java/org/apache/felix/metatype/internal/MetaTypeProviderHolder.java
(added)
+++ felix/trunk/metatype/src/main/java/org/apache/felix/metatype/internal/MetaTypeProviderHolder.java
Mon Oct 29 10:16:31 2012
@@ -0,0 +1,69 @@
+/*
+ * 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.metatype.internal;
+
+
+import java.util.Arrays;
+
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.metatype.MetaTypeProvider;
+
+
+class MetaTypeProviderHolder extends BaseProviderHolder
+{
+    private String[] pids;
+    private String[] factoryPids;
+
+
+    MetaTypeProviderHolder( final ServiceReference reference, final MetaTypeProvider provider
)
+    {
+        super( reference, provider );
+
+        this.pids = BaseProviderHolder.getStringPlus( reference, MetaTypeProvider.METATYPE_PID
);
+        this.factoryPids = BaseProviderHolder.getStringPlus( reference, MetaTypeProvider.METATYPE_FACTORY_PID
);
+    }
+
+
+    String[] getPids()
+    {
+        return pids;
+    }
+
+
+    String[] getFactoryPids()
+    {
+        return factoryPids;
+    }
+
+
+    void update( final MetaTypeServiceImpl mti )
+    {
+        String[] pids = BaseProviderHolder.getStringPlus( this.getReference(), MetaTypeProvider.METATYPE_PID
);
+        String[] factoryPids = BaseProviderHolder.getStringPlus( this.getReference(),
+            MetaTypeProvider.METATYPE_FACTORY_PID );
+
+        if ( !Arrays.equals( pids, this.pids ) || !Arrays.equals( factoryPids, this.factoryPids
) )
+        {
+            mti.removeService( this );
+            this.pids = pids;
+            this.factoryPids = factoryPids;
+            mti.addService( this );
+        }
+    }
+}
\ No newline at end of file

Modified: felix/trunk/metatype/src/main/java/org/apache/felix/metatype/internal/MetaTypeProviderTracker.java
URL: http://svn.apache.org/viewvc/felix/trunk/metatype/src/main/java/org/apache/felix/metatype/internal/MetaTypeProviderTracker.java?rev=1403229&r1=1403228&r2=1403229&view=diff
==============================================================================
--- felix/trunk/metatype/src/main/java/org/apache/felix/metatype/internal/MetaTypeProviderTracker.java
(original)
+++ felix/trunk/metatype/src/main/java/org/apache/felix/metatype/internal/MetaTypeProviderTracker.java
Mon Oct 29 10:16:31 2012
@@ -19,7 +19,6 @@
 package org.apache.felix.metatype.internal;
 
 
-import java.util.Arrays;
 
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.ServiceReference;
@@ -33,123 +32,31 @@ public class MetaTypeProviderTracker ext
     final MetaTypeServiceImpl mti;
 
 
-    public MetaTypeProviderTracker( BundleContext context, final String serviceType, final
MetaTypeServiceImpl mti )
+    public MetaTypeProviderTracker( BundleContext context, final MetaTypeServiceImpl mti
)
     {
-        super( context, serviceType, null );
+        super( context, MetaTypeProvider.class.getName(), null );
         this.mti = mti;
     }
 
 
     public Object addingService( ServiceReference reference )
     {
-        final Object service = this.context.getService( reference );
-        final RegistrationPropertyHolder rph;
-        if ( service instanceof MetaTypeProvider )
-        {
-            rph = new RegistrationPropertyHolder( reference, ( MetaTypeProvider ) service
);
-            rph.addMetaTypeProvider( this.mti );
-        }
-        else
-        {
-            rph = null;
-        }
-
-        return rph;
+        final MetaTypeProvider provider = ( MetaTypeProvider ) this.context.getService( reference
);
+        final MetaTypeProviderHolder holder = new MetaTypeProviderHolder( reference, provider
);
+        mti.addService( holder );
+        return holder;
     }
 
 
     public void modifiedService( ServiceReference reference, Object service )
     {
-        ( ( RegistrationPropertyHolder ) service ).update( this.mti );
+        ( ( MetaTypeProviderHolder ) service ).update( this.mti );
     }
 
 
     public void removedService( ServiceReference reference, Object service )
     {
-        ( ( RegistrationPropertyHolder ) service ).removeMetaTypeProvider( this.mti );
+        mti.removeService( ( MetaTypeProviderHolder ) service );
         this.context.ungetService( reference );
     }
-
-
-    static class RegistrationPropertyHolder
-    {
-        private String[] pids;
-        private String[] factoryPids;
-
-        private final ServiceReference reference;
-        private final MetaTypeProvider provider;
-
-
-        RegistrationPropertyHolder( final ServiceReference reference, final MetaTypeProvider
provider )
-        {
-            this.pids = ServiceMetaTypeInformation.getStringPlus( reference, MetaTypeProvider.METATYPE_PID
);
-            this.factoryPids = ServiceMetaTypeInformation.getStringPlus( reference,
-                MetaTypeProvider.METATYPE_FACTORY_PID );
-
-            this.reference = reference;
-            this.provider = provider;
-        }
-
-
-        MetaTypeProvider getProvider()
-        {
-            return provider;
-        }
-
-
-        String[] getPids()
-        {
-            return pids;
-        }
-
-
-        String[] getFactoryPids()
-        {
-            return factoryPids;
-        }
-
-
-        void addMetaTypeProvider( final MetaTypeServiceImpl mti )
-        {
-            if ( pids != null )
-            {
-                mti.addSingletonMetaTypeProvider( reference.getBundle(), pids, provider );
-            }
-
-            if ( factoryPids != null )
-            {
-                mti.addFactoryMetaTypeProvider( reference.getBundle(), factoryPids, provider
);
-            }
-        }
-
-
-        void removeMetaTypeProvider( final MetaTypeServiceImpl mti )
-        {
-            if ( pids != null )
-            {
-                mti.removeSingletonMetaTypeProvider( reference.getBundle(), pids );
-            }
-
-            if ( factoryPids != null )
-            {
-                mti.removeFactoryMetaTypeProvider( reference.getBundle(), factoryPids );
-            }
-        }
-
-
-        void update( final MetaTypeServiceImpl mti )
-        {
-            String[] pids = ServiceMetaTypeInformation.getStringPlus( this.reference, MetaTypeProvider.METATYPE_PID
);
-            String[] factoryPids = ServiceMetaTypeInformation.getStringPlus( this.reference,
-                MetaTypeProvider.METATYPE_FACTORY_PID );
-
-            if ( !Arrays.equals( pids, this.pids ) || !Arrays.equals( factoryPids, this.factoryPids
) )
-            {
-                removeMetaTypeProvider( mti );
-                this.pids = pids;
-                this.factoryPids = factoryPids;
-                addMetaTypeProvider( mti );
-            }
-        }
-    }
 }

Modified: felix/trunk/metatype/src/main/java/org/apache/felix/metatype/internal/MetaTypeServiceImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/metatype/src/main/java/org/apache/felix/metatype/internal/MetaTypeServiceImpl.java?rev=1403229&r1=1403228&r2=1403229&view=diff
==============================================================================
--- felix/trunk/metatype/src/main/java/org/apache/felix/metatype/internal/MetaTypeServiceImpl.java
(original)
+++ felix/trunk/metatype/src/main/java/org/apache/felix/metatype/internal/MetaTypeServiceImpl.java
Mon Oct 29 10:16:31 2012
@@ -28,7 +28,6 @@ import java.util.concurrent.ConcurrentHa
 
 import org.apache.felix.metatype.MetaData;
 import org.apache.felix.metatype.MetaDataReader;
-import org.apache.felix.metatype.internal.MetaTypeProviderTracker.RegistrationPropertyHolder;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.BundleEvent;
@@ -82,7 +81,7 @@ class MetaTypeServiceImpl implements Met
         }
         this.managedServiceTracker = mst;
 
-        this.providerTracker = new MetaTypeProviderTracker( bundleContext, MetaTypeProvider.class.getName(),
this );
+        this.providerTracker = new MetaTypeProviderTracker( bundleContext, this );
         this.providerTracker.open();
     }
 
@@ -195,45 +194,39 @@ class MetaTypeServiceImpl implements Met
 
     //-- register and unregister MetaTypeProvider services
 
-    protected void addSingletonMetaTypeProvider( final Bundle bundle, final String[] pids,
MetaTypeProvider mtp )
+    protected void addService( final MetaTypeProviderHolder holder )
     {
-        MetaTypeInformationImpl mti = getMetaTypeInformationInternal( bundle );
+        MetaTypeInformationImpl mti = getMetaTypeInformationInternal( holder.getReference().getBundle()
);
         if ( mti != null )
         {
-            mti.addSingletonMetaTypeProvider( pids, mtp );
-        }
-    }
-
+            if ( holder.getPids() != null )
+            {
+                mti.addSingletonMetaTypeProvider( holder.getPids(), holder.getProvider()
);
+            }
 
-    protected void addFactoryMetaTypeProvider( final Bundle bundle, final String[] factoryPids,
MetaTypeProvider mtp )
-    {
-        MetaTypeInformationImpl mti = getMetaTypeInformationInternal( bundle );
-        if ( mti != null )
-        {
-            mti.addFactoryMetaTypeProvider( factoryPids, mtp );
+            if ( holder.getFactoryPids() != null )
+            {
+                mti.addFactoryMetaTypeProvider( holder.getFactoryPids(), holder.getProvider()
);
+            }
         }
     }
 
 
-    protected boolean removeSingletonMetaTypeProvider( final Bundle bundle, final String[]
pids )
+    protected void removeService( final MetaTypeProviderHolder holder )
     {
-        MetaTypeInformationImpl mti = getMetaTypeInformationInternal( bundle );
+        MetaTypeInformationImpl mti = getMetaTypeInformationInternal( holder.getReference().getBundle()
);
         if ( mti != null )
         {
-            return mti.removeSingletonMetaTypeProvider( pids );
-        }
-        return false;
-    }
-
+            if ( holder.getPids() != null )
+            {
+                mti.removeSingletonMetaTypeProvider( holder.getPids() );
+            }
 
-    protected boolean removeFactoryMetaTypeProvider( final Bundle bundle, final String[]
factoryPids )
-    {
-        MetaTypeInformationImpl mti = getMetaTypeInformationInternal( bundle );
-        if ( mti != null )
-        {
-            return mti.removeFactoryMetaTypeProvider( factoryPids );
+            if ( holder.getFactoryPids() != null )
+            {
+                mti.removeFactoryMetaTypeProvider( holder.getFactoryPids() );
+            }
         }
-        return false;
     }
 
 
@@ -241,7 +234,7 @@ class MetaTypeServiceImpl implements Met
 
     protected void addService( final ManagedServiceHolder holder )
     {
-        MetaTypeInformationImpl mti = getMetaTypeInformationInternal( holder.getRef().getBundle()
);
+        MetaTypeInformationImpl mti = getMetaTypeInformationInternal( holder.getReference().getBundle()
);
         if ( mti != null )
         {
             mti.addService( holder.getPids(), holder.isSingleton(), holder.isFactory(), holder.getProvider()
);
@@ -251,7 +244,7 @@ class MetaTypeServiceImpl implements Met
 
     protected void removeService( final ManagedServiceHolder holder )
     {
-        MetaTypeInformationImpl mti = getMetaTypeInformationInternal( holder.getRef().getBundle()
);
+        MetaTypeInformationImpl mti = getMetaTypeInformationInternal( holder.getReference().getBundle()
);
         if ( mti != null )
         {
             mti.removeService( holder.getPids(), holder.isSingleton(), holder.isFactory()
);
@@ -285,7 +278,7 @@ class MetaTypeServiceImpl implements Met
                 ServiceReference ref = refs[i];
                 if ( bundle.equals( ref.getBundle() ) )
                 {
-                    final MetaTypeProviderTracker.RegistrationPropertyHolder holder = ( RegistrationPropertyHolder
) this.providerTracker
+                    final MetaTypeProviderHolder holder = ( MetaTypeProviderHolder ) this.providerTracker
                         .getService( ref );
                     if ( holder.getPids() != null )
                     {

Modified: felix/trunk/metatype/src/main/java/org/apache/felix/metatype/internal/ServiceMetaTypeInformation.java
URL: http://svn.apache.org/viewvc/felix/trunk/metatype/src/main/java/org/apache/felix/metatype/internal/ServiceMetaTypeInformation.java?rev=1403229&r1=1403228&r2=1403229&view=diff
==============================================================================
--- felix/trunk/metatype/src/main/java/org/apache/felix/metatype/internal/ServiceMetaTypeInformation.java
(original)
+++ felix/trunk/metatype/src/main/java/org/apache/felix/metatype/internal/ServiceMetaTypeInformation.java
Mon Oct 29 10:16:31 2012
@@ -19,51 +19,19 @@
 package org.apache.felix.metatype.internal;
 
 
-import java.util.Arrays;
-import java.util.Collection;
 import org.osgi.framework.Bundle;
-import org.osgi.framework.Constants;
-import org.osgi.framework.ServiceReference;
 import org.osgi.service.metatype.MetaTypeProvider;
 
 
-/**
- * The <code>ServiceMetaTypeInformation</code> extends the
- * {@link MetaTypeInformationImpl} adding support to register and unregister
- * <code>ManagedService</code>s and <code>ManagedServiceFactory</code>s
- * also implementing the <code>MetaTypeProvider</code> interface.
- *
- * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
- */
 public class ServiceMetaTypeInformation extends MetaTypeInformationImpl
 {
 
-    /**
-     * Creates an instance of this class handling services of the given
-     * <code>bundle</code>.
-     *
-     * @param bundle The <code>Bundle</code> whose services are handled by
-     *            this class.
-     */
     public ServiceMetaTypeInformation( Bundle bundle )
     {
         super( bundle );
     }
 
 
-    /**
-     * Registers the service described by the <code>serviceRef</code> with
-     * this instance if the service is a <code>MetaTypeProvider</code>
-     * instance and either a <code>service.factoryPid</code> or
-     * <code>service.pid</code> property is set in the service registration
-     * properties.
-     * <p>
-     * If the service is registered, this bundle keeps a reference, which is
-     * ungot when the service is unregistered or this bundle is stopped.
-     *
-     * @param serviceRef The <code>ServiceReference</code> describing the
-     *            service to be checked and handled.
-     */
     protected void addService( String[] pids, boolean isSingleton, boolean isFactory, MetaTypeProvider
mtp )
     {
         if ( pids != null )
@@ -81,20 +49,6 @@ public class ServiceMetaTypeInformation 
     }
 
 
-    /**
-     * Unregisters the service described by the <code>serviceRef</code> from
-     * this instance. Unregistration just checks for the
-     * <code>service.factoryPid</code> and <code>service.pid</code>
service
-     * properties but does not care whether the service implements the
-     * <code>MetaTypeProvider</code> interface. If the service is registered
-     * it is simply unregistered.
-     * <p>
-     * If the service is actually unregistered the reference retrieved by the
-     * registration method is ungotten.
-     *
-     * @param serviceRef The <code>ServiceReference</code> describing the
-     *            service to be unregistered.
-     */
     protected void removeService( String[] pids, boolean isSingleton, boolean isFactory )
     {
         if ( pids != null )
@@ -110,68 +64,4 @@ public class ServiceMetaTypeInformation 
             }
         }
     }
-
-
-    static String[] getServicePids( final ServiceReference ref )
-    {
-        return getStringPlus( ref, Constants.SERVICE_PID );
-    }
-
-
-    static String[] getStringPlus( final ServiceReference ref, final String propertyName
)
-    {
-        final String[] res;
-        Object prop = ref.getProperty( propertyName );
-        if ( prop == null )
-        {
-            res = null;
-        }
-        else if ( prop instanceof String )
-        {
-            res = new String[]
-                { ( String ) prop };
-        }
-        else if ( prop instanceof Collection )
-        {
-            final Object[] col = ( ( Collection ) prop ).toArray();
-            res = new String[col.length];
-            for ( int i = 0; i < res.length; i++ )
-            {
-                res[i] = String.valueOf( col[i] );
-            }
-        }
-        else if ( prop.getClass().isArray() && String.class.equals( prop.getClass().getComponentType()
) )
-        {
-            res = ( String[] ) prop;
-        }
-        else
-        {
-            // unsupported type of property
-            res = null;
-        }
-
-        if ( res != null )
-        {
-            Arrays.sort( res );
-        }
-
-        return res;
-    }
-
-
-    static boolean isService( final ServiceReference ref, final String type )
-    {
-        String[] oc = ( String[] ) ref.getProperty( Constants.OBJECTCLASS );
-        if ( oc != null )
-        {
-            for ( int i = 0; i < oc.length; i++ )
-            {
-                if ( oc[i].equals( type ) )
-                {
-                    return true;
-                }
-            }
-        }
-        return false;
-    }
 }



Mime
View raw message