Modified: felix/trunk/osgi-r7/scr/src/main/java/org/apache/felix/scr/impl/manager/SingleRefPair.java URL: http://svn.apache.org/viewvc/felix/trunk/osgi-r7/scr/src/main/java/org/apache/felix/scr/impl/manager/SingleRefPair.java?rev=1781360&r1=1781359&r2=1781360&view=diff ============================================================================== --- felix/trunk/osgi-r7/scr/src/main/java/org/apache/felix/scr/impl/manager/SingleRefPair.java (original) +++ felix/trunk/osgi-r7/scr/src/main/java/org/apache/felix/scr/impl/manager/SingleRefPair.java Thu Feb 2 09:33:47 2017 @@ -22,13 +22,12 @@ package org.apache.felix.scr.impl.manage import java.util.concurrent.atomic.AtomicReference; -import org.apache.felix.scr.impl.helper.SimpleLogger; import org.osgi.framework.BundleContext; import org.osgi.framework.ServiceReference; import org.osgi.service.log.LogService; /** - * @version $Rev:$ $Date:$ + * @version $Rev$ $Date$ */ public class SingleRefPair<S, T> extends RefPair<S, T> { @@ -39,11 +38,13 @@ public class SingleRefPair<S, T> extends super(ref); } + @Override public T getServiceObject(ComponentContextImpl<S> key) { return serviceObjectRef.get(); } + @Override public boolean setServiceObject( ComponentContextImpl<S> key, T serviceObject ) { boolean set = serviceObjectRef.compareAndSet( null, serviceObject ); @@ -53,7 +54,8 @@ public class SingleRefPair<S, T> extends } return set; } - + + @Override public T unsetServiceObject(ComponentContextImpl<S> key) { return serviceObjectRef.getAndSet( null ); @@ -66,14 +68,13 @@ public class SingleRefPair<S, T> extends } @Override - public boolean getServiceObject(ComponentContextImpl<S> key, BundleContext context, - SimpleLogger logger) + public boolean getServiceObject(ComponentContextImpl<S> key, BundleContext context) { T service = context.getService( getRef() ); if ( service == null ) { setFailed(); - logger.log( + key.getLogger().log( LogService.LOG_WARNING, "Could not get service from ref {0}", new Object[] {getRef()}, null ); return false;
Modified: felix/trunk/osgi-r7/scr/src/main/java/org/apache/felix/scr/impl/xml/XmlConstants.java URL: http://svn.apache.org/viewvc/felix/trunk/osgi-r7/scr/src/main/java/org/apache/felix/scr/impl/xml/XmlConstants.java?rev=1781360&r1=1781359&r2=1781360&view=diff ============================================================================== --- felix/trunk/osgi-r7/scr/src/main/java/org/apache/felix/scr/impl/xml/XmlConstants.java (original) +++ felix/trunk/osgi-r7/scr/src/main/java/org/apache/felix/scr/impl/xml/XmlConstants.java Thu Feb 2 09:33:47 2017 @@ -78,6 +78,7 @@ public abstract class XmlConstants public static final String ATTR_ENTRY = "entry"; public static final String ATTR_FACTORY = "factory"; public static final String ATTR_IMMEDIATE = "immediate"; + public static final String ATTR_INTERFACE = "interface"; public static final String ATTR_MODIFIED = "modified"; public static final String ATTR_NAME = "name"; public static final String ATTR_TYPE = "type"; @@ -99,6 +100,7 @@ public abstract class XmlConstants // mapping of namespace URI to namespace code public static final Map<String, DSVersion> NAMESPACE_CODE_MAP; + static { NAMESPACE_CODE_MAP = new HashMap<String, DSVersion>(); Modified: felix/trunk/osgi-r7/scr/src/main/java/org/apache/felix/scr/impl/xml/XmlHandler.java URL: http://svn.apache.org/viewvc/felix/trunk/osgi-r7/scr/src/main/java/org/apache/felix/scr/impl/xml/XmlHandler.java?rev=1781360&r1=1781359&r2=1781360&view=diff ============================================================================== --- felix/trunk/osgi-r7/scr/src/main/java/org/apache/felix/scr/impl/xml/XmlHandler.java (original) +++ felix/trunk/osgi-r7/scr/src/main/java/org/apache/felix/scr/impl/xml/XmlHandler.java Thu Feb 2 09:33:47 2017 @@ -152,9 +152,9 @@ public class XmlHandler implements KXml2 m_currentComponent = new ComponentMetadata( namespaceCode ); // name attribute is optional (since DS 1.1) - if ( attributes.getAttribute( "name" ) != null ) + if ( attributes.getAttribute( XmlConstants.ATTR_NAME ) != null ) { - m_currentComponent.setName( attributes.getAttribute( "name" ) ); + m_currentComponent.setName( attributes.getAttribute( XmlConstants.ATTR_NAME ) ); } // enabled attribute is optional @@ -253,18 +253,18 @@ public class XmlHandler implements KXml2 PropertyMetadata prop = new PropertyMetadata(); // name attribute is mandatory - prop.setName( attributes.getAttribute( "name" ) ); + prop.setName( attributes.getAttribute( XmlConstants.ATTR_NAME ) ); // type attribute is optional - if ( attributes.getAttribute( "type" ) != null ) + if ( attributes.getAttribute( XmlConstants.ATTR_TYPE ) != null ) { - prop.setType( attributes.getAttribute( "type" ) ); + prop.setType( attributes.getAttribute( XmlConstants.ATTR_TYPE ) ); } // 112.4.5: If the value attribute is specified, the body of the element is ignored. - if ( attributes.getAttribute( "value" ) != null ) + if ( attributes.getAttribute( XmlConstants.ATTR_VALUE ) != null ) { - prop.setValue( attributes.getAttribute( "value" ) ); + prop.setValue( attributes.getAttribute( XmlConstants.ATTR_VALUE ) ); m_currentComponent.addProperty( prop ); } else @@ -287,24 +287,24 @@ public class XmlHandler implements KXml2 } } - // TODO Section [...] Factory Property Elements + // 112.4.9 [...] Factory Property Element else if ( localName.equals( XmlConstants.EL_FACTORY_PROPERTY ) ) { PropertyMetadata prop = new PropertyMetadata(); // name attribute is mandatory - prop.setName( attributes.getAttribute( "name" ) ); + prop.setName( attributes.getAttribute( XmlConstants.ATTR_NAME ) ); // type attribute is optional - if ( attributes.getAttribute( "type" ) != null ) + if ( attributes.getAttribute( XmlConstants.ATTR_TYPE ) != null ) { - prop.setType( attributes.getAttribute( "type" ) ); + prop.setType( attributes.getAttribute( XmlConstants.ATTR_TYPE ) ); } // 112.4.5: If the value attribute is specified, the body of the element is ignored. - if ( attributes.getAttribute( "value" ) != null ) + if ( attributes.getAttribute( XmlConstants.ATTR_VALUE ) != null ) { - prop.setValue( attributes.getAttribute( "value" ) ); + prop.setValue( attributes.getAttribute( XmlConstants.ATTR_VALUE ) ); m_currentComponent.addFactoryProperty( prop ); } else @@ -313,7 +313,7 @@ public class XmlHandler implements KXml2 m_pendingFactoryProperty = prop; } } - // TODO Section [...] Factory Properties [...] Elements + // 112.4.9 [...] Factory Properties Element else if ( localName.equals( XmlConstants.EL_FACTORY_PROPERTIES ) ) { final Properties props = readPropertiesEntry( attributes.getAttribute( "entry" ) ); @@ -347,7 +347,7 @@ public class XmlHandler implements KXml2 } else if ( localName.equals( XmlConstants.EL_PROVIDE ) ) { - m_currentService.addProvide( attributes.getAttribute( "interface" ) ); + m_currentService.addProvide( attributes.getAttribute( XmlConstants.ATTR_INTERFACE ) ); } // 112.4.7 Reference element @@ -356,12 +356,12 @@ public class XmlHandler implements KXml2 ReferenceMetadata ref = new ReferenceMetadata(); // name attribute is optional (since DS 1.1) - if ( attributes.getAttribute( "name" ) != null ) + if ( attributes.getAttribute( XmlConstants.ATTR_NAME ) != null ) { - ref.setName( attributes.getAttribute( "name" ) ); + ref.setName( attributes.getAttribute( XmlConstants.ATTR_NAME ) ); } - ref.setInterface( attributes.getAttribute( "interface" ) ); + ref.setInterface( attributes.getAttribute( XmlConstants.ATTR_INTERFACE ) ); // Cardinality if ( attributes.getAttribute( "cardinality" ) != null ) Modified: felix/trunk/osgi-r7/scr/src/test/java/org/apache/felix/scr/impl/inject/BindMethodTest.java URL: http://svn.apache.org/viewvc/felix/trunk/osgi-r7/scr/src/test/java/org/apache/felix/scr/impl/inject/BindMethodTest.java?rev=1781360&r1=1781359&r2=1781360&view=diff ============================================================================== --- felix/trunk/osgi-r7/scr/src/test/java/org/apache/felix/scr/impl/inject/BindMethodTest.java (original) +++ felix/trunk/osgi-r7/scr/src/test/java/org/apache/felix/scr/impl/inject/BindMethodTest.java Thu Feb 2 09:33:47 2017 @@ -453,9 +453,9 @@ public class BindMethodTest extends Test FakeService.class.getName(), dsVersion, false ); RefPair refPair = new SingleRefPair( m_serviceReference ); ComponentContextImpl<T1> cc = new ComponentContextImpl(icm, new MockBundle(), null); - assertTrue( bm.getServiceObject( new BindParameters(cc, refPair), m_context, icm ) ); + assertTrue( bm.getServiceObject( new BindParameters(cc, refPair), m_context ) ); BindParameters bp = new BindParameters(cc, refPair); - bm.invoke( component, bp, null, icm ); + bm.invoke( component, bp, null ); assertEquals( expectCallPerformed, component.callPerformed ); } @@ -464,16 +464,19 @@ public class BindMethodTest extends Test final ComponentMetadata metadata = newMetadata(); ComponentContainer container = new ComponentContainer() { + @Override public BundleComponentActivator getActivator() { return null; } + @Override public ComponentMetadata getComponentMetadata() { return metadata; } + @Override public void disposed(SingleComponentManager component) { } Modified: felix/trunk/osgi-r7/scr/src/test/java/org/apache/felix/scr/impl/inject/methods/ActivateMethodTest.java URL: http://svn.apache.org/viewvc/felix/trunk/osgi-r7/scr/src/test/java/org/apache/felix/scr/impl/inject/methods/ActivateMethodTest.java?rev=1781360&r1=1781359&r2=1781360&view=diff ============================================================================== --- felix/trunk/osgi-r7/scr/src/test/java/org/apache/felix/scr/impl/inject/methods/ActivateMethodTest.java (original) +++ felix/trunk/osgi-r7/scr/src/test/java/org/apache/felix/scr/impl/inject/methods/ActivateMethodTest.java Thu Feb 2 09:33:47 2017 @@ -19,20 +19,16 @@ package org.apache.felix.scr.impl.inject.methods; +import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; -import java.util.Hashtable; import java.util.List; import java.util.Map; -import junit.framework.TestCase; - -import org.apache.felix.scr.impl.BundleComponentActivator; -import org.apache.felix.scr.impl.manager.ComponentContainer; import org.apache.felix.scr.impl.inject.ActivatorParameter; -import org.apache.felix.scr.impl.inject.ComponentMethods; import org.apache.felix.scr.impl.inject.ComponentMethodsImpl; -import org.apache.felix.scr.impl.inject.methods.ActivateMethod; -import org.apache.felix.scr.impl.inject.methods.BaseMethod; +import org.apache.felix.scr.impl.manager.ComponentActivator; +import org.apache.felix.scr.impl.manager.ComponentContainer; +import org.apache.felix.scr.impl.manager.ComponentContextImpl; import org.apache.felix.scr.impl.manager.SingleComponentManager; import org.apache.felix.scr.impl.metadata.ComponentMetadata; import org.apache.felix.scr.impl.metadata.DSVersion; @@ -41,18 +37,20 @@ import org.apache.felix.scr.impl.metadat import org.apache.felix.scr.impl.metadata.instances.Level1Object; import org.apache.felix.scr.impl.metadata.instances.Level3Object; import org.apache.felix.scr.impl.metadata.instances2.Level2Object; -import org.easymock.EasyMock; +import org.mockito.Mockito; import org.osgi.framework.Bundle; import org.osgi.framework.BundleContext; import org.osgi.service.component.ComponentContext; +import junit.framework.TestCase; + public class ActivateMethodTest extends TestCase { private static final Class ACCEPT_METHOD_CLASS = AcceptMethod.class; - private ComponentContext m_ctx; + private Bundle m_bundle; BaseObject base = new BaseObject(); @@ -62,19 +60,13 @@ public class ActivateMethodTest extends Level3Object level3 = new Level3Object(); + @Override protected void setUp() throws Exception { super.setUp(); - Bundle bundle = ( Bundle ) EasyMock.createNiceMock( Bundle.class ); - BundleContext context = ( BundleContext ) EasyMock.createNiceMock( BundleContext.class ); - EasyMock.expect( context.getBundle() ).andReturn( bundle ).anyTimes(); - - m_ctx = (ComponentContext) EasyMock.createNiceMock(ComponentContext.class); - EasyMock.expect( m_ctx.getProperties() ).andReturn( new Hashtable() ).anyTimes(); - EasyMock.expect( m_ctx.getBundleContext() ).andReturn( context ).anyTimes(); - EasyMock.replay( new Object[] - { m_ctx, context } ); - + m_bundle = Mockito.mock( Bundle.class ); + BundleContext context = Mockito.mock( BundleContext.class ); + Mockito.when(context.getBundle()).thenReturn(m_bundle); } @@ -297,7 +289,8 @@ public class ActivateMethodTest extends ComponentContainer<?> container = newContainer(); SingleComponentManager<?> icm = new SingleComponentManager( container, new ComponentMethodsImpl() ); ActivateMethod am = new ActivateMethod( methodName, methodName != null, obj.getClass(), version, false, false ); - am.invoke( obj, new ActivatorParameter( m_ctx, -1 ), null, icm ); + + am.invoke( obj, new ActivatorParameter( new ComponentContextImpl(icm, m_bundle, null), -1 ), null ); Method m = am.getMethod(); assertNotNull( m ); assertEquals( methodName, m.getName() ); @@ -310,16 +303,21 @@ public class ActivateMethodTest extends final ComponentMetadata metadata = newMetadata(); ComponentContainer container = new ComponentContainer() { - public BundleComponentActivator getActivator() + @Override + public ComponentActivator getActivator() { - return null; + final ComponentActivator ca = Mockito.mock(ComponentActivator.class); + Mockito.when(ca.getBundleContext()).thenReturn(Mockito.mock(BundleContext.class)); + return ca; } + @Override public ComponentMetadata getComponentMetadata() { return metadata; } + @Override public void disposed(SingleComponentManager component) { } @@ -328,7 +326,7 @@ public class ActivateMethodTest extends { return false; } - + }; return container; } @@ -373,7 +371,7 @@ public class ActivateMethodTest extends ComponentContainer container = newContainer(); SingleComponentManager icm = new SingleComponentManager( container, new ComponentMethodsImpl() ); ActivateMethod am = new ActivateMethod( methodName, methodName != null, obj.getClass(), version, false, false ); - am.invoke( obj, new ActivatorParameter( m_ctx, -1 ), null, icm ); + am.invoke( obj, new ActivatorParameter( new ComponentContextImpl(icm, m_bundle, null), -1 ), null ); Method m = am.getMethod(); assertNull( m ); assertNull( obj.getCalledMethod() ); @@ -387,7 +385,7 @@ public class ActivateMethodTest extends boolean accepted = BaseMethod.accept( method, acceptPrivate, acceptPackage, false ); assertEquals( expected, accepted ); } - + private static @interface Ann{} private static class Sort { @@ -400,7 +398,7 @@ public class ActivateMethodTest extends public void a(ComponentContext cc) {}; public void a(ComponentContext cc, BundleContext c) {}; public void b() {}; - + } public void testMethodSorting() throws Exception { @@ -422,10 +420,10 @@ public class ActivateMethodTest extends assertEquals(2, ms.get(6).getParameterTypes().length); assertEquals(0, ms.get(7).getParameterTypes().length); } - + public void test_13_annos() throws Exception { checkMethod(base, "activate_13_2_annotations", "activate_13_2_annotations", DSVersion.DS13 ); } - + }
