You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by fm...@apache.org on 2009/07/31 16:17:51 UTC
svn commit: r799618 - in /felix/trunk/scr/src:
main/java/org/apache/felix/scr/impl/manager/
test/java/org/apache/felix/scr/impl/manager/
Author: fmeschbe
Date: Fri Jul 31 14:17:51 2009
New Revision: 799618
URL: http://svn.apache.org/viewvc?rev=799618&view=rev
Log:
FELIX-1232 Apply modified patch by Alin Dreghiciu (thanks). The service
properties for service registration or update are now retrieved using
a new getServiceProperties() method which in turns calls the new copyTo
method taking a new allProps flag indicating that only public properties
are to be copied.
Added:
felix/trunk/scr/src/test/java/org/apache/felix/scr/impl/manager/AbstractComponentManagerTest.java (with props)
Modified:
felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/AbstractComponentManager.java
felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/ImmediateComponentManager.java
Modified: felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/AbstractComponentManager.java
URL: http://svn.apache.org/viewvc/felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/AbstractComponentManager.java?rev=799618&r1=799617&r2=799618&view=diff
==============================================================================
--- felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/AbstractComponentManager.java (original)
+++ felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/AbstractComponentManager.java Fri Jul 31 14:17:51 2009
@@ -723,7 +723,7 @@
log( LogService.LOG_DEBUG, "registering services", m_componentMetadata, null );
// get a copy of the component properties as service properties
- Dictionary serviceProperties = copyTo( null, getProperties() );
+ final Dictionary serviceProperties = getServiceProperties();
return getActivator().getBundleContext().registerService(
getComponentMetadata().getServiceMetadata().getProvides(),
@@ -925,6 +925,17 @@
public abstract Dictionary getProperties();
/**
+ * Returns the subset of component properties to be used as service
+ * properties. These properties are all component properties where property
+ * name does not start with dot (.), properties which are considered
+ * private.
+ */
+ public Dictionary getServiceProperties()
+ {
+ return copyTo( null, getProperties(), false);
+ }
+
+ /**
* Copies the properties from the <code>source</code> <code>Dictionary</code>
* into the <code>target</code> <code>Dictionary</code>.
*
@@ -938,7 +949,31 @@
* <code>source</code> is <code>null</code> or empty and
* <code>target</code> was <code>null</code>.
*/
- protected Dictionary copyTo( Dictionary target, Dictionary source )
+ protected static Dictionary copyTo( Dictionary target, Dictionary source )
+ {
+ return copyTo( target, source, true );
+ }
+
+ /**
+ * Copies the properties from the <code>source</code> <code>Dictionary</code>
+ * into the <code>target</code> <code>Dictionary</code> except for private
+ * properties (whose name has a leading dot) which are only copied if the
+ * <code>allProps</code> parameter is <code>true</code>.
+ *
+ * @param target The <code>Dictionary</code> into which to copy the
+ * properties. If <code>null</code> a new <code>Hashtable</code> is
+ * created.
+ * @param source The <code>Dictionary</code> providing the properties to
+ * copy. If <code>null</code> or empty, nothing is copied.
+ * @param allProps Whether all properties (<code>true</code>) or only the
+ * public properties (<code>false</code>) are to be copied.
+ *
+ * @return The <code>target</code> is returned, which may be empty if
+ * <code>source</code> is <code>null</code> or empty and
+ * <code>target</code> was <code>null</code> or all properties are
+ * private and had not to be copied
+ */
+ protected static Dictionary copyTo( Dictionary target, final Dictionary source, final boolean allProps )
{
if ( target == null )
{
@@ -949,14 +984,19 @@
{
for ( Enumeration ce = source.keys(); ce.hasMoreElements(); )
{
- Object key = ce.nextElement();
- target.put( key, source.get( key ) );
+ // cast is save, because key must be a string as per the spec
+ String key = ( String ) ce.nextElement();
+ if ( allProps || key.charAt( 0 ) != '.' )
+ {
+ target.put( key, source.get( key ) );
+ }
}
}
return target;
}
+
/**
*
*/
Modified: felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/ImmediateComponentManager.java
URL: http://svn.apache.org/viewvc/felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/ImmediateComponentManager.java?rev=799618&r1=799617&r2=799618&view=diff
==============================================================================
--- felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/ImmediateComponentManager.java (original)
+++ felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/ImmediateComponentManager.java Fri Jul 31 14:17:51 2009
@@ -440,7 +440,7 @@
{
try
{
- final Dictionary regProps = copyTo( null, props );
+ final Dictionary regProps = getServiceProperties();
sr.setProperties( regProps );
}
catch ( IllegalStateException ise )
Added: felix/trunk/scr/src/test/java/org/apache/felix/scr/impl/manager/AbstractComponentManagerTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/scr/src/test/java/org/apache/felix/scr/impl/manager/AbstractComponentManagerTest.java?rev=799618&view=auto
==============================================================================
--- felix/trunk/scr/src/test/java/org/apache/felix/scr/impl/manager/AbstractComponentManagerTest.java (added)
+++ felix/trunk/scr/src/test/java/org/apache/felix/scr/impl/manager/AbstractComponentManagerTest.java Fri Jul 31 14:17:51 2009
@@ -0,0 +1,54 @@
+/*
+ * 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.impl.manager;
+
+import java.util.Hashtable;
+import junit.framework.TestCase;
+
+public class AbstractComponentManagerTest extends TestCase
+{
+
+ public void test_copyTo_withoutExclusions()
+ {
+ final Hashtable ht = new Hashtable();
+ ht.put( "p1", "v1" );
+ ht.put( "p.2", "v2" );
+ ht.put( ".p3", "v3" );
+ final Hashtable dict = (Hashtable) AbstractComponentManager.copyTo( null, ht, true );
+ assertNotNull( "Copy result is not null", dict );
+ assertEquals( "Number of items", 3, dict.size() );
+ assertEquals( "Value for key p1", "v1", dict.get( "p1" ) );
+ assertEquals( "Value for key p.2", "v2", dict.get( "p.2" ) );
+ assertEquals( "Value for key .p3", "v3", dict.get( ".p3" ) );
+ }
+
+ public void test_copyTo_excludingStartingWithDot()
+ {
+ final Hashtable ht = new Hashtable();
+ ht.put( "p1", "v1" );
+ ht.put( "p.2", "v2" );
+ ht.put( ".p3", "v3" );
+ final Hashtable dict = (Hashtable) AbstractComponentManager.copyTo( null, ht, false );
+ assertNotNull( "Copy result is not null", dict );
+ assertEquals( "Number of items", 2, dict.size() );
+ assertEquals( "Value for key p1", "v1", dict.get( "p1" ) );
+ assertEquals( "Value for key p.2", "v2", dict.get( "p.2" ) );
+ }
+
+}
Propchange: felix/trunk/scr/src/test/java/org/apache/felix/scr/impl/manager/AbstractComponentManagerTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: felix/trunk/scr/src/test/java/org/apache/felix/scr/impl/manager/AbstractComponentManagerTest.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision Rev Url