onami-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From noctar...@apache.org
Subject svn commit: r1428001 [2/3] - in /incubator/onami/sandbox/factoryannotation: ./ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/onami/ src/main/java/org/apache/onami/factoryannotation/ src/main/java/or...
Date Wed, 02 Jan 2013 20:28:50 GMT
Added: incubator/onami/sandbox/factoryannotation/src/main/java/org/apache/onami/factoryannotation/ProvisionCacheIdentityProviderFacade.java
URL: http://svn.apache.org/viewvc/incubator/onami/sandbox/factoryannotation/src/main/java/org/apache/onami/factoryannotation/ProvisionCacheIdentityProviderFacade.java?rev=1428001&view=auto
==============================================================================
--- incubator/onami/sandbox/factoryannotation/src/main/java/org/apache/onami/factoryannotation/ProvisionCacheIdentityProviderFacade.java (added)
+++ incubator/onami/sandbox/factoryannotation/src/main/java/org/apache/onami/factoryannotation/ProvisionCacheIdentityProviderFacade.java Wed Jan  2 20:28:48 2013
@@ -0,0 +1,72 @@
+/*
+ * 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.onami.factoryannotation;
+
+import java.lang.annotation.Annotation;
+import java.util.HashMap;
+import java.util.Map;
+
+import com.google.inject.Key;
+import com.google.inject.TypeLiteral;
+
+class ProvisionCacheIdentityProviderFacade<T, A extends Annotation>
+    implements FactoryAnnotationProvider<T, A>
+{
+
+    private final Map<Key<T>, T> provisionCache = new HashMap<Key<T>, T>();
+
+    private final FactoryAnnotationProvider<T, A> factoryAnnotationProvider;
+
+    private final TypeLiteral<T> typeLiteral;
+
+    public ProvisionCacheIdentityProviderFacade( final FactoryAnnotationProvider<T, A> factoryAnnotationProvider,
+                                                 final TypeLiteral<T> typeLiteral )
+    {
+
+        this.factoryAnnotationProvider = factoryAnnotationProvider;
+        this.typeLiteral = typeLiteral;
+    }
+
+    public Class<T> getInjectionType()
+    {
+        return factoryAnnotationProvider.getInjectionType();
+    }
+
+    public T buildValue( A annotation )
+    {
+        final Key<T> key = buildCacheKey( typeLiteral, annotation );
+
+        if ( provisionCache.containsKey( key ) )
+        {
+            return provisionCache.get( key );
+        }
+
+        final T value = factoryAnnotationProvider.buildValue( annotation );
+        provisionCache.put( key, value );
+
+        return value;
+    }
+
+    private Key<T> buildCacheKey( final TypeLiteral<T> typeLiteral, final A annotation )
+    {
+
+        return Key.get( typeLiteral, annotation );
+    }
+
+}

Added: incubator/onami/sandbox/factoryannotation/src/main/java/org/apache/onami/factoryannotation/builder/BindFactoryAnnotationBindingBuilder.java
URL: http://svn.apache.org/viewvc/incubator/onami/sandbox/factoryannotation/src/main/java/org/apache/onami/factoryannotation/builder/BindFactoryAnnotationBindingBuilder.java?rev=1428001&view=auto
==============================================================================
--- incubator/onami/sandbox/factoryannotation/src/main/java/org/apache/onami/factoryannotation/builder/BindFactoryAnnotationBindingBuilder.java (added)
+++ incubator/onami/sandbox/factoryannotation/src/main/java/org/apache/onami/factoryannotation/builder/BindFactoryAnnotationBindingBuilder.java Wed Jan  2 20:28:48 2013
@@ -0,0 +1,30 @@
+/*
+ * 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.onami.factoryannotation.builder;
+
+import com.google.inject.TypeLiteral;
+
+public interface BindFactoryAnnotationBindingBuilder
+{
+
+    <T> FactoryAnnotationAnnotationBindingBuilder bindIdentity( Class<T> injectionType );
+
+    <T> FactoryAnnotationAnnotationBindingBuilder bindIdentity( TypeLiteral<T> injectionType );
+
+}

Added: incubator/onami/sandbox/factoryannotation/src/main/java/org/apache/onami/factoryannotation/builder/CombinedListenerCacheableBindingBuilder.java
URL: http://svn.apache.org/viewvc/incubator/onami/sandbox/factoryannotation/src/main/java/org/apache/onami/factoryannotation/builder/CombinedListenerCacheableBindingBuilder.java?rev=1428001&view=auto
==============================================================================
--- incubator/onami/sandbox/factoryannotation/src/main/java/org/apache/onami/factoryannotation/builder/CombinedListenerCacheableBindingBuilder.java (added)
+++ incubator/onami/sandbox/factoryannotation/src/main/java/org/apache/onami/factoryannotation/builder/CombinedListenerCacheableBindingBuilder.java Wed Jan  2 20:28:48 2013
@@ -0,0 +1,24 @@
+/*
+ * 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.onami.factoryannotation.builder;
+
+public interface CombinedListenerCacheableBindingBuilder
+    extends FactoryAnnotationProvisionListenerBindingBuilder, FactoryAnnotationCacheableBindingBuilder
+{
+}

Added: incubator/onami/sandbox/factoryannotation/src/main/java/org/apache/onami/factoryannotation/builder/FactoryAnnotationAnnotationBindingBuilder.java
URL: http://svn.apache.org/viewvc/incubator/onami/sandbox/factoryannotation/src/main/java/org/apache/onami/factoryannotation/builder/FactoryAnnotationAnnotationBindingBuilder.java?rev=1428001&view=auto
==============================================================================
--- incubator/onami/sandbox/factoryannotation/src/main/java/org/apache/onami/factoryannotation/builder/FactoryAnnotationAnnotationBindingBuilder.java (added)
+++ incubator/onami/sandbox/factoryannotation/src/main/java/org/apache/onami/factoryannotation/builder/FactoryAnnotationAnnotationBindingBuilder.java Wed Jan  2 20:28:48 2013
@@ -0,0 +1,33 @@
+/*
+ * 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.onami.factoryannotation.builder;
+
+import java.lang.annotation.Annotation;
+
+public interface FactoryAnnotationAnnotationBindingBuilder
+{
+
+    /**
+     * Binds the annotation type to the already assigned injection class type.
+     * 
+     * @param annotationType The annotation type to bind
+     */
+    <I extends Annotation> CombinedListenerCacheableBindingBuilder annotatedWith( Class<I> annotationType );
+
+}

Added: incubator/onami/sandbox/factoryannotation/src/main/java/org/apache/onami/factoryannotation/builder/FactoryAnnotationBaseProviderBindingBuilder.java
URL: http://svn.apache.org/viewvc/incubator/onami/sandbox/factoryannotation/src/main/java/org/apache/onami/factoryannotation/builder/FactoryAnnotationBaseProviderBindingBuilder.java?rev=1428001&view=auto
==============================================================================
--- incubator/onami/sandbox/factoryannotation/src/main/java/org/apache/onami/factoryannotation/builder/FactoryAnnotationBaseProviderBindingBuilder.java (added)
+++ incubator/onami/sandbox/factoryannotation/src/main/java/org/apache/onami/factoryannotation/builder/FactoryAnnotationBaseProviderBindingBuilder.java Wed Jan  2 20:28:48 2013
@@ -0,0 +1,45 @@
+/*
+ * 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.onami.factoryannotation.builder;
+
+import java.lang.annotation.Annotation;
+
+import org.apache.onami.factoryannotation.FactoryAnnotationProvider;
+
+public interface FactoryAnnotationBaseProviderBindingBuilder
+{
+
+    /**
+     * Binds an {@link FactoryAnnotationProvider} instance to handle requests of the provision for the given injection
+     * class type and annotation type.
+     * 
+     * @param factoryAnnotationProvider The {@link FactoryAnnotationProvider} instance to bind
+     */
+    <I, A extends Annotation> void toAnnotationFactory( FactoryAnnotationProvider<I, A> factoryAnnotationProvider );
+
+    /**
+     * Binds an {@link FactoryAnnotationProvider} class to handle requests of the provision for the given injection
+     * class type and annotation type. <br>
+     * <b>The used instance of the given class will be created by Guice.</b>
+     * 
+     * @param factoryAnnotationProvider The {@link FactoryAnnotationProvider} class to bind
+     */
+    <I, A extends Annotation> void toIdentityProvider( Class<FactoryAnnotationProvider<I, A>> factoryAnnotationProvider );
+
+}

Added: incubator/onami/sandbox/factoryannotation/src/main/java/org/apache/onami/factoryannotation/builder/FactoryAnnotationCacheableBindingBuilder.java
URL: http://svn.apache.org/viewvc/incubator/onami/sandbox/factoryannotation/src/main/java/org/apache/onami/factoryannotation/builder/FactoryAnnotationCacheableBindingBuilder.java?rev=1428001&view=auto
==============================================================================
--- incubator/onami/sandbox/factoryannotation/src/main/java/org/apache/onami/factoryannotation/builder/FactoryAnnotationCacheableBindingBuilder.java (added)
+++ incubator/onami/sandbox/factoryannotation/src/main/java/org/apache/onami/factoryannotation/builder/FactoryAnnotationCacheableBindingBuilder.java Wed Jan  2 20:28:48 2013
@@ -0,0 +1,51 @@
+/*
+ * 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.onami.factoryannotation.builder;
+
+import java.lang.annotation.Annotation;
+
+import org.apache.onami.factoryannotation.FactoryAnnotationCacheable;
+
+public interface FactoryAnnotationCacheableBindingBuilder
+    extends FactoryAnnotationBaseProviderBindingBuilder
+{
+
+    /**
+     * <p>
+     * Defines the value as cacheable.
+     * </p>
+     * <p>
+     * Configures or overrides the {@literal @}{@link FactoryAnnotationCacheable} annotated value. Default value of
+     * cacheable on non annotated annotations is <b>false</b>.
+     * </p>
+     */
+    <I, A extends Annotation> CombinedListenerCacheableBindingBuilder cacheable();
+
+    /**
+     * <p>
+     * Defines the value as <b>non</b> cacheable.
+     * </p>
+     * <p>
+     * Configures or overrides the {@literal @}{@link FactoryAnnotationCacheable} annotated value. Default value of
+     * cacheable on non annotated annotations is <b>false</b>.
+     * </p>
+     */
+    <I, A extends Annotation> CombinedListenerCacheableBindingBuilder nonCacheable();
+
+}

Added: incubator/onami/sandbox/factoryannotation/src/main/java/org/apache/onami/factoryannotation/builder/FactoryAnnotationProvisionListenerBindingBuilder.java
URL: http://svn.apache.org/viewvc/incubator/onami/sandbox/factoryannotation/src/main/java/org/apache/onami/factoryannotation/builder/FactoryAnnotationProvisionListenerBindingBuilder.java?rev=1428001&view=auto
==============================================================================
--- incubator/onami/sandbox/factoryannotation/src/main/java/org/apache/onami/factoryannotation/builder/FactoryAnnotationProvisionListenerBindingBuilder.java (added)
+++ incubator/onami/sandbox/factoryannotation/src/main/java/org/apache/onami/factoryannotation/builder/FactoryAnnotationProvisionListenerBindingBuilder.java Wed Jan  2 20:28:48 2013
@@ -0,0 +1,37 @@
+/*
+ * 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.onami.factoryannotation.builder;
+
+import java.lang.annotation.Annotation;
+
+import org.apache.onami.factoryannotation.FactoryAnnotationProvisionListener;
+
+public interface FactoryAnnotationProvisionListenerBindingBuilder
+    extends FactoryAnnotationBaseProviderBindingBuilder
+{
+
+    /**
+     * Binds a {@link FactoryAnnotationProvisionListener} instance to the given injection class type and annotation
+     * type.
+     * 
+     * @param provisionListener The {@link FactoryAnnotationProvisionListener} instance to bind.
+     */
+    <I, A extends Annotation> FactoryAnnotationBaseProviderBindingBuilder applyListener( FactoryAnnotationProvisionListener<I, A> provisionListener );
+
+}

Added: incubator/onami/sandbox/factoryannotation/src/test/java/org/apache/onami/factoryannotation/CacheableProviderTestCase.java
URL: http://svn.apache.org/viewvc/incubator/onami/sandbox/factoryannotation/src/test/java/org/apache/onami/factoryannotation/CacheableProviderTestCase.java?rev=1428001&view=auto
==============================================================================
--- incubator/onami/sandbox/factoryannotation/src/test/java/org/apache/onami/factoryannotation/CacheableProviderTestCase.java (added)
+++ incubator/onami/sandbox/factoryannotation/src/test/java/org/apache/onami/factoryannotation/CacheableProviderTestCase.java Wed Jan  2 20:28:48 2013
@@ -0,0 +1,167 @@
+/*
+ * 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.onami.factoryannotation;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotSame;
+
+import org.apache.onami.factoryannotation.annotations.CacheableUser;
+import org.apache.onami.factoryannotation.annotations.User;
+import org.apache.onami.factoryannotation.impl.CacheableUserValueInjector;
+import org.apache.onami.factoryannotation.impl.UserEntity;
+import org.apache.onami.factoryannotation.impl.UserValueInjector;
+import org.junit.Test;
+
+import com.google.inject.Guice;
+import com.google.inject.Injector;
+
+public class CacheableProviderTestCase
+{
+
+    @Test
+    public void testIdentityCacheableAnnotation()
+    {
+        final Injector injector = Guice.createInjector( new FactoryAnnotationModule()
+        {
+            @Override
+            protected void configure()
+            {
+                bindType( UserEntity.class ).annotatedWith( CacheableUser.class ).toAnnotationFactory( new CacheableUserValueInjector() );
+            }
+        } );
+
+        final UserInjectable1 injectable = new UserInjectable1();
+        injector.injectMembers( injectable );
+
+        assertEquals( "User1", injectable.user1.getName() );
+        assertEquals( 1, injectable.user1.getId() );
+        assertEquals( "User2", injectable.user2.getName() );
+        assertEquals( 2, injectable.user2.getId() );
+        assertEquals( "User1", injectable.user3.getName() );
+        assertEquals( 1, injectable.user3.getId() );
+
+        assertEquals( injectable.user1, injectable.user3 );
+    }
+
+    @Test
+    public void testCacheableFluentAnnotation()
+    {
+        final Injector injector = Guice.createInjector( new FactoryAnnotationModule()
+        {
+            @Override
+            protected void configure()
+            {
+                bindType( UserEntity.class ).annotatedWith( User.class ).cacheable().toAnnotationFactory( new UserValueInjector() );
+            }
+        } );
+
+        final UserInjectable2 injectable = new UserInjectable2();
+        injector.injectMembers( injectable );
+
+        assertEquals( "User1", injectable.user1.getName() );
+        assertEquals( 1, injectable.user1.getId() );
+        assertEquals( "User2", injectable.user2.getName() );
+        assertEquals( 2, injectable.user2.getId() );
+        assertEquals( "User1", injectable.user3.getName() );
+        assertEquals( 1, injectable.user3.getId() );
+
+        assertNotSame( injectable.user1, injectable.user2 );
+        assertNotSame( injectable.user2, injectable.user3 );
+        assertEquals( injectable.user1, injectable.user3 );
+    }
+
+    @Test
+    public void testExplicitNonCacheableFluentAnnotation()
+    {
+        final Injector injector = Guice.createInjector( new FactoryAnnotationModule()
+        {
+            @Override
+            protected void configure()
+            {
+                bindType( UserEntity.class ).annotatedWith( User.class ).nonCacheable().toAnnotationFactory( new UserValueInjector() );
+            }
+        } );
+
+        final UserInjectable2 injectable = new UserInjectable2();
+        injector.injectMembers( injectable );
+
+        assertEquals( "User1", injectable.user1.getName() );
+        assertEquals( 1, injectable.user1.getId() );
+        assertEquals( "User2", injectable.user2.getName() );
+        assertEquals( 2, injectable.user2.getId() );
+        assertEquals( "User1", injectable.user3.getName() );
+        assertEquals( 1, injectable.user3.getId() );
+
+        assertNotSame( injectable.user1, injectable.user2 );
+        assertNotSame( injectable.user2, injectable.user3 );
+        assertNotSame( injectable.user1, injectable.user3 );
+    }
+
+    @Test
+    public void testStandardNonCacheableFluentAnnotation()
+    {
+        final Injector injector = Guice.createInjector( new FactoryAnnotationModule()
+        {
+            @Override
+            protected void configure()
+            {
+                bindType( UserEntity.class ).annotatedWith( User.class ).toAnnotationFactory( new UserValueInjector() );
+            }
+        } );
+
+        final UserInjectable2 injectable = new UserInjectable2();
+        injector.injectMembers( injectable );
+
+        assertEquals( "User1", injectable.user1.getName() );
+        assertEquals( 1, injectable.user1.getId() );
+        assertEquals( "User2", injectable.user2.getName() );
+        assertEquals( 2, injectable.user2.getId() );
+        assertEquals( "User1", injectable.user3.getName() );
+        assertEquals( 1, injectable.user3.getId() );
+
+        assertNotSame( injectable.user1, injectable.user2 );
+        assertNotSame( injectable.user2, injectable.user3 );
+        assertNotSame( injectable.user1, injectable.user3 );
+    }
+
+    public class UserInjectable1
+    {
+        @CacheableUser( byId = 1 )
+        private UserEntity user1;
+
+        @CacheableUser( byId = 2 )
+        private UserEntity user2;
+
+        @CacheableUser( byId = 1 )
+        private UserEntity user3;
+    }
+
+    public class UserInjectable2
+    {
+        @User( byId = 1 )
+        private UserEntity user1;
+
+        @User( byId = 2 )
+        private UserEntity user2;
+
+        @User( byId = 1 )
+        private UserEntity user3;
+    }
+
+}

Added: incubator/onami/sandbox/factoryannotation/src/test/java/org/apache/onami/factoryannotation/DeepInjectionTestCase.java
URL: http://svn.apache.org/viewvc/incubator/onami/sandbox/factoryannotation/src/test/java/org/apache/onami/factoryannotation/DeepInjectionTestCase.java?rev=1428001&view=auto
==============================================================================
--- incubator/onami/sandbox/factoryannotation/src/test/java/org/apache/onami/factoryannotation/DeepInjectionTestCase.java (added)
+++ incubator/onami/sandbox/factoryannotation/src/test/java/org/apache/onami/factoryannotation/DeepInjectionTestCase.java Wed Jan  2 20:28:48 2013
@@ -0,0 +1,90 @@
+/*
+ * 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.onami.factoryannotation;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import org.apache.onami.factoryannotation.annotations.SecondLayer;
+import org.apache.onami.factoryannotation.annotations.User;
+import org.apache.onami.factoryannotation.impl.SecondLayerEntity;
+import org.apache.onami.factoryannotation.impl.SecondLayerIdentityProvider;
+import org.apache.onami.factoryannotation.impl.SecondLayerIdentityProvider.InjectableSecondLayerEntity;
+import org.apache.onami.factoryannotation.impl.UserEntity;
+import org.apache.onami.factoryannotation.impl.UserValueInjector;
+import org.junit.Test;
+
+import com.google.inject.Guice;
+import com.google.inject.Injector;
+
+public class DeepInjectionTestCase
+{
+
+    @Test
+    public void testDeepInjection()
+    {
+        final Injector injector = Guice.createInjector( new FactoryAnnotationModule()
+        {
+            @Override
+            protected void configure()
+            {
+                bindType( SecondLayerEntity.class ).annotatedWith( SecondLayer.class ).toAnnotationFactory( new SecondLayerIdentityProvider() );
+
+                bindType( UserEntity.class ).annotatedWith( User.class ).toAnnotationFactory( new UserValueInjector() );
+            }
+        } );
+
+        final Layer injectable = new Layer();
+        injector.injectMembers( injectable );
+
+        assertEquals( "User1", injectable.userEntity.getName() );
+        assertEquals( 1, injectable.userEntity.getId() );
+
+        assertEquals( "SecondLayerEntity1", injectable.layerEntity1.getValue() );
+        assertEquals( 1, injectable.layerEntity1.getId() );
+        assertEquals( "SecondLayerEntity1", injectable.layerEntity1.getValue() );
+        assertEquals( 1, injectable.layerEntity1.getId() );
+
+        assertTrue( injectable.layerEntity2 instanceof InjectableSecondLayerEntity );
+
+        InjectableSecondLayerEntity entity = (InjectableSecondLayerEntity) injectable.layerEntity2;
+
+        assertNotNull( entity.getUserEntity() );
+
+        assertEquals( "SecondLayerEntity3_User1", injectable.layerEntity2.getValue() );
+        assertEquals( 3, injectable.layerEntity2.getId() );
+
+        assertEquals( "User1", entity.getUserEntity().getName() );
+        assertEquals( 1, entity.getUserEntity().getId() );
+    }
+
+    public static class Layer
+    {
+        @User( byId = 1 )
+        private UserEntity userEntity;
+
+        @SecondLayer( byId = 1 )
+        private SecondLayerEntity layerEntity1;
+
+        @SecondLayer( byId = 3 )
+        private SecondLayerEntity layerEntity2;
+    }
+
+}

Added: incubator/onami/sandbox/factoryannotation/src/test/java/org/apache/onami/factoryannotation/FactoryAnnotationProviderTestCase.java
URL: http://svn.apache.org/viewvc/incubator/onami/sandbox/factoryannotation/src/test/java/org/apache/onami/factoryannotation/FactoryAnnotationProviderTestCase.java?rev=1428001&view=auto
==============================================================================
--- incubator/onami/sandbox/factoryannotation/src/test/java/org/apache/onami/factoryannotation/FactoryAnnotationProviderTestCase.java (added)
+++ incubator/onami/sandbox/factoryannotation/src/test/java/org/apache/onami/factoryannotation/FactoryAnnotationProviderTestCase.java Wed Jan  2 20:28:48 2013
@@ -0,0 +1,452 @@
+/*
+ * 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.onami.factoryannotation;
+
+import static org.junit.Assert.assertEquals;
+
+import org.apache.onami.factoryannotation.annotations.Message;
+import org.apache.onami.factoryannotation.annotations.User;
+import org.apache.onami.factoryannotation.impl.MessageEntity;
+import org.apache.onami.factoryannotation.impl.MessageValueInjector;
+import org.apache.onami.factoryannotation.impl.UserEntity;
+import org.apache.onami.factoryannotation.impl.UserValueInjector;
+import org.junit.Test;
+
+import com.google.inject.AbstractModule;
+import com.google.inject.Guice;
+import com.google.inject.Inject;
+import com.google.inject.Injector;
+import com.google.inject.ProvisionException;
+
+public class FactoryAnnotationProviderTestCase
+{
+
+    @Test
+    public void testInjectAndUserAnnotationInjection()
+    {
+        final Injector injector = Guice.createInjector( new FactoryAnnotationModule()
+        {
+            @Override
+            protected void configure()
+            {
+                bindType( UserEntity.class ).annotatedWith( User.class ).toAnnotationFactory( new UserValueInjector() );
+            }
+        } );
+
+        final InjectAnnotationUserInjectable injectable = new InjectAnnotationUserInjectable();
+        injector.injectMembers( injectable );
+
+        assertEquals( "User1", injectable.user1.getName() );
+        assertEquals( 1, injectable.user1.getId() );
+        assertEquals( "User2", injectable.user2.getName() );
+        assertEquals( 2, injectable.user2.getId() );
+    }
+
+    @Test
+    public void testUserAnnotationInjection1()
+    {
+        final Injector injector = Guice.createInjector( new FactoryAnnotationModule()
+        {
+            @Override
+            protected void configure()
+            {
+                bindType( UserEntity.class ).annotatedWith( User.class ).toAnnotationFactory( new UserValueInjector() );
+            }
+        } );
+
+        final UserInjectable injectable = new UserInjectable();
+        injector.injectMembers( injectable );
+
+        assertEquals( "User1", injectable.user1.getName() );
+        assertEquals( 1, injectable.user1.getId() );
+        assertEquals( "User2", injectable.user2.getName() );
+        assertEquals( 2, injectable.user2.getId() );
+    }
+
+    @Test
+    public void testUserAnnotationInjection2()
+    {
+        final Injector injector = Guice.createInjector( new FactoryAnnotationModule()
+        {
+            @Override
+            protected void configure()
+            {
+                bindType( UserEntity.class ).annotatedWith( User.class ).toAnnotationFactory( new UserValueInjector() );
+            }
+        }, new AbstractModule()
+        {
+            @Override
+            protected void configure()
+            {
+                bind( UserInjectable.class );
+            }
+        } );
+
+        final UserInjectable injectable = injector.getInstance( UserInjectable.class );
+
+        assertEquals( "User1", injectable.user1.getName() );
+        assertEquals( 1, injectable.user1.getId() );
+        assertEquals( "User2", injectable.user2.getName() );
+        assertEquals( 2, injectable.user2.getId() );
+    }
+
+    @Test
+    public void testMessageAnnotationInjection1()
+    {
+        final Injector injector = Guice.createInjector( new FactoryAnnotationModule()
+        {
+            @Override
+            protected void configure()
+            {
+                bindType( MessageEntity.class ).annotatedWith( Message.class ).toAnnotationFactory( new MessageValueInjector() );
+            }
+        } );
+
+        final MessageInjectable injectable = new MessageInjectable();
+        injector.injectMembers( injectable );
+
+        assertEquals( "MessageTest100", injectable.message100.getMessage() );
+        assertEquals( 100, injectable.message100.getId() );
+        assertEquals( "MessageTest200", injectable.message200.getMessage() );
+        assertEquals( 200, injectable.message200.getId() );
+    }
+
+    @Test
+    public void testMessageAnnotationInjection2()
+    {
+        final Injector injector = Guice.createInjector( new FactoryAnnotationModule()
+        {
+            @Override
+            protected void configure()
+            {
+                bindType( MessageEntity.class ).annotatedWith( Message.class ).toAnnotationFactory( new MessageValueInjector() );
+            }
+        }, new AbstractModule()
+        {
+            @Override
+            protected void configure()
+            {
+                bind( MessageInjectable.class );
+            }
+        } );
+
+        final MessageInjectable injectable = injector.getInstance( MessageInjectable.class );
+
+        assertEquals( "MessageTest100", injectable.message100.getMessage() );
+        assertEquals( 100, injectable.message100.getId() );
+        assertEquals( "MessageTest200", injectable.message200.getMessage() );
+        assertEquals( 200, injectable.message200.getId() );
+    }
+
+    @Test
+    public void testCombinedAnnotationInjection()
+    {
+        final Injector injector = Guice.createInjector( new FactoryAnnotationModule()
+        {
+            @Override
+            protected void configure()
+            {
+                bindType( UserEntity.class ).annotatedWith( User.class ).toAnnotationFactory( new UserValueInjector() );
+
+                bindType( MessageEntity.class ).annotatedWith( Message.class ).toAnnotationFactory( new MessageValueInjector() );
+            }
+        } );
+
+        final MessageInjectable injectable = new MessageInjectable();
+        injector.injectMembers( injectable );
+
+        final UserInjectable injectable2 = new UserInjectable();
+        injector.injectMembers( injectable2 );
+
+        assertEquals( "MessageTest100", injectable.message100.getMessage() );
+        assertEquals( 100, injectable.message100.getId() );
+        assertEquals( "MessageTest200", injectable.message200.getMessage() );
+        assertEquals( 200, injectable.message200.getId() );
+
+        assertEquals( "User1", injectable2.user1.getName() );
+        assertEquals( 1, injectable2.user1.getId() );
+        assertEquals( "User2", injectable2.user2.getName() );
+        assertEquals( 2, injectable2.user2.getId() );
+    }
+
+    @Test( expected = ProvisionException.class )
+    public void testFailedInjection1()
+    {
+        final Injector injector = Guice.createInjector( new FactoryAnnotationModule()
+        {
+            @Override
+            protected void configure()
+            {
+                bindType( UserEntity.class ).annotatedWith( User.class ).toAnnotationFactory( new UserValueInjector() );
+            }
+        } );
+
+        injector.injectMembers( new UserInjectableFailing() );
+    }
+
+    @Test( expected = ProvisionException.class )
+    public void testFailedInjection2()
+    {
+        final Injector injector = Guice.createInjector( new FactoryAnnotationModule()
+        {
+            @Override
+            protected void configure()
+            {
+                bindType( UserEntity.class ).annotatedWith( User.class ).toAnnotationFactory( new UserValueInjector() );
+            }
+        }, new AbstractModule()
+        {
+            @Override
+            protected void configure()
+            {
+                bind( UserInjectableFailing.class );
+            }
+        } );
+
+        injector.getInstance( UserInjectableFailing.class );
+    }
+
+    @Test
+    public void testConstructorInjection1()
+    {
+        final Injector injector = Guice.createInjector( new FactoryAnnotationModule()
+        {
+            @Override
+            protected void configure()
+            {
+                bindType( MessageEntity.class ).annotatedWith( Message.class ).toAnnotationFactory( new MessageValueInjector() );
+            }
+        }, new AbstractModule()
+        {
+            @Override
+            protected void configure()
+            {
+                bind( ConstructorInjectable1.class );
+            }
+        } );
+
+        final ConstructorInjectable1 injectable = injector.getInstance( ConstructorInjectable1.class );
+
+        assertEquals( "MessageTest100", injectable.message1.getMessage() );
+        assertEquals( 100, injectable.message1.getId() );
+    }
+
+    @Test
+    public void testConstructorInjection2()
+    {
+        final Injector injector = Guice.createInjector( new FactoryAnnotationModule()
+        {
+            @Override
+            protected void configure()
+            {
+                bindType( MessageEntity.class ).annotatedWith( Message.class ).toAnnotationFactory( new MessageValueInjector() );
+            }
+        }, new AbstractModule()
+        {
+            @Override
+            protected void configure()
+            {
+                bind( ConstructorInjectable2.class );
+            }
+        } );
+
+        final ConstructorInjectable2 injectable = injector.getInstance( ConstructorInjectable2.class );
+
+        assertEquals( "MessageTest100", injectable.message1.getMessage() );
+        assertEquals( 100, injectable.message1.getId() );
+        assertEquals( "MessageTest200", injectable.message2.getMessage() );
+        assertEquals( 200, injectable.message2.getId() );
+    }
+
+    @Test
+    public void testConstructorInjection3()
+    {
+        final Injector injector = Guice.createInjector( new FactoryAnnotationModule()
+        {
+            @Override
+            protected void configure()
+            {
+                bindType( MessageEntity.class ).annotatedWith( Message.class ).toAnnotationFactory( new MessageValueInjector() );
+
+                bindType( UserEntity.class ).annotatedWith( User.class ).toAnnotationFactory( new UserValueInjector() );
+            }
+        }, new AbstractModule()
+        {
+            @Override
+            protected void configure()
+            {
+                bind( ConstructorInjectable3.class );
+            }
+        } );
+
+        final ConstructorInjectable3 injectable = injector.getInstance( ConstructorInjectable3.class );
+
+        assertEquals( "MessageTest100", injectable.message1.getMessage() );
+        assertEquals( 100, injectable.message1.getId() );
+        assertEquals( "MessageTest200", injectable.message2.getMessage() );
+        assertEquals( 200, injectable.message2.getId() );
+        assertEquals( "User1", injectable.user1.getName() );
+        assertEquals( 1, injectable.user1.getId() );
+    }
+
+    @Test
+    public void testConstructorInjection4()
+    {
+        final Injector injector = Guice.createInjector( new FactoryAnnotationModule()
+        {
+            @Override
+            protected void configure()
+            {
+                bindType( MessageEntity.class ).annotatedWith( Message.class ).toAnnotationFactory( new MessageValueInjector() );
+
+                bindType( UserEntity.class ).annotatedWith( User.class ).toAnnotationFactory( new UserValueInjector() );
+            }
+        }, new AbstractModule()
+        {
+            @Override
+            protected void configure()
+            {
+                bind( ConstructorInjectable4.class );
+            }
+        } );
+
+        final ConstructorInjectable4 injectable = injector.getInstance( ConstructorInjectable4.class );
+
+        assertEquals( "MessageTest100", injectable.message1.getMessage() );
+        assertEquals( 100, injectable.message1.getId() );
+        assertEquals( "MessageTest200", injectable.message2.getMessage() );
+        assertEquals( 200, injectable.message2.getId() );
+        assertEquals( "User1", injectable.user1.getName() );
+        assertEquals( 1, injectable.user1.getId() );
+        assertEquals( "User2", injectable.user2.getName() );
+        assertEquals( 2, injectable.user2.getId() );
+    }
+
+    public static class UserInjectable
+    {
+        @User( byId = 1 )
+        private UserEntity user1;
+
+        @User( byId = 2 )
+        private UserEntity user2;
+    }
+
+    public static class InjectAnnotationUserInjectable
+    {
+        @Inject
+        @User( byId = 1 )
+        private UserEntity user1;
+
+        @Inject
+        @User( byId = 2 )
+        private UserEntity user2;
+    }
+
+    public static class UserInjectableFailing
+    {
+        @User( byId = 3 )
+        private UserEntity user1;
+    }
+
+    public static class MessageInjectable
+    {
+        @Message( byId = 100 )
+        private MessageEntity message100;
+
+        @Message( byId = 200 )
+        private MessageEntity message200;
+    }
+
+    public static class ConstructorInjectable1
+    {
+        private final MessageEntity message1;
+
+        @Inject
+        public ConstructorInjectable1( @Message( byId = 100 )
+        final MessageEntity message1 )
+        {
+
+            this.message1 = message1;
+        }
+    }
+
+    public static class ConstructorInjectable2
+    {
+        private final MessageEntity message1;
+
+        private final MessageEntity message2;
+
+        @Inject
+        public ConstructorInjectable2( @Message( byId = 100 )
+        final MessageEntity message1, @Message( byId = 200 )
+        final MessageEntity message2 )
+        {
+
+            this.message1 = message1;
+            this.message2 = message2;
+        }
+    }
+
+    public static class ConstructorInjectable3
+    {
+        private final MessageEntity message1;
+
+        private final MessageEntity message2;
+
+        private final UserEntity user1;
+
+        @Inject
+        public ConstructorInjectable3( @Message( byId = 100 )
+        final MessageEntity message1, @Message( byId = 200 )
+        final MessageEntity message2, @User( byId = 1 )
+        final UserEntity user1 )
+        {
+
+            this.message1 = message1;
+            this.message2 = message2;
+            this.user1 = user1;
+        }
+    }
+
+    public static class ConstructorInjectable4
+    {
+        private final MessageEntity message1;
+
+        private final MessageEntity message2;
+
+        private final UserEntity user1;
+
+        private final UserEntity user2;
+
+        @Inject
+        public ConstructorInjectable4( @Message( byId = 100 )
+        final MessageEntity message1, @Message( byId = 200 )
+        final MessageEntity message2, @User( byId = 1 )
+        final UserEntity user1, @User( byId = 2 )
+        final UserEntity user2 )
+        {
+
+            this.message1 = message1;
+            this.message2 = message2;
+            this.user1 = user1;
+            this.user2 = user2;
+        }
+    }
+
+}

Added: incubator/onami/sandbox/factoryannotation/src/test/java/org/apache/onami/factoryannotation/InjectedValueProviderTestCase.java
URL: http://svn.apache.org/viewvc/incubator/onami/sandbox/factoryannotation/src/test/java/org/apache/onami/factoryannotation/InjectedValueProviderTestCase.java?rev=1428001&view=auto
==============================================================================
--- incubator/onami/sandbox/factoryannotation/src/test/java/org/apache/onami/factoryannotation/InjectedValueProviderTestCase.java (added)
+++ incubator/onami/sandbox/factoryannotation/src/test/java/org/apache/onami/factoryannotation/InjectedValueProviderTestCase.java Wed Jan  2 20:28:48 2013
@@ -0,0 +1,77 @@
+/*
+ * 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.onami.factoryannotation;
+
+import static org.junit.Assert.assertEquals;
+
+import org.apache.onami.factoryannotation.annotations.User;
+import org.apache.onami.factoryannotation.impl.InjectedUserValueInjector;
+import org.apache.onami.factoryannotation.impl.UserEntity;
+import org.junit.Test;
+
+import com.google.inject.AbstractModule;
+import com.google.inject.Guice;
+import com.google.inject.Injector;
+import com.google.inject.name.Names;
+
+public class InjectedValueProviderTestCase
+{
+
+    @Test
+    public void testInjectedValueProvider()
+    {
+        final Injector injector = Guice.createInjector( new FactoryAnnotationModule()
+        {
+            @Override
+            protected void configure()
+            {
+                bindType( UserEntity.class ).annotatedWith( User.class ).toAnnotationFactory( new InjectedUserValueInjector() );
+            }
+        }, new AbstractModule()
+        {
+            @Override
+            protected void configure()
+            {
+                bind( UserEntity.class ).annotatedWith( Names.named( "test1" ) ).toInstance( UserEntity.build( "User1",
+                                                                                                               1 ) );
+
+                bind( UserEntity.class ).annotatedWith( Names.named( "test2" ) ).toInstance( UserEntity.build( "User2",
+                                                                                                               2 ) );
+            }
+        } );
+
+        final UserInjectable injectable = new UserInjectable();
+        injector.injectMembers( injectable );
+
+        assertEquals( "User1", injectable.user1.getName() );
+        assertEquals( 1, injectable.user1.getId() );
+        assertEquals( "User2", injectable.user2.getName() );
+        assertEquals( 2, injectable.user2.getId() );
+    }
+
+    public class UserInjectable
+    {
+        @User( byId = 1 )
+        private UserEntity user1;
+
+        @User( byId = 2 )
+        private UserEntity user2;
+    }
+
+}

Added: incubator/onami/sandbox/factoryannotation/src/test/java/org/apache/onami/factoryannotation/InterfaceTestCase.java
URL: http://svn.apache.org/viewvc/incubator/onami/sandbox/factoryannotation/src/test/java/org/apache/onami/factoryannotation/InterfaceTestCase.java?rev=1428001&view=auto
==============================================================================
--- incubator/onami/sandbox/factoryannotation/src/test/java/org/apache/onami/factoryannotation/InterfaceTestCase.java (added)
+++ incubator/onami/sandbox/factoryannotation/src/test/java/org/apache/onami/factoryannotation/InterfaceTestCase.java Wed Jan  2 20:28:48 2013
@@ -0,0 +1,64 @@
+/*
+ * 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.onami.factoryannotation;
+
+import static org.junit.Assert.assertEquals;
+
+import org.apache.onami.factoryannotation.annotations.SecondLayer;
+import org.apache.onami.factoryannotation.impl.SecondLayerEntity;
+import org.apache.onami.factoryannotation.impl.SecondLayerIdentityProvider;
+import org.junit.Test;
+
+import com.google.inject.Guice;
+import com.google.inject.Injector;
+
+public class InterfaceTestCase
+{
+
+    @Test
+    public void testInterfaceValueProvider()
+    {
+        final Injector injector = Guice.createInjector( new FactoryAnnotationModule()
+        {
+            @Override
+            protected void configure()
+            {
+                bindType( SecondLayerEntity.class ).annotatedWith( SecondLayer.class ).toAnnotationFactory( new SecondLayerIdentityProvider() );
+            }
+        } );
+
+        final SecondLayerInjectable injectable = new SecondLayerInjectable();
+        injector.injectMembers( injectable );
+
+        assertEquals( "SecondLayerEntity1", injectable.layerEntity1.getValue() );
+        assertEquals( 1, injectable.layerEntity1.getId() );
+        assertEquals( "SecondLayerEntity2", injectable.layerEntity2.getValue() );
+        assertEquals( 2, injectable.layerEntity2.getId() );
+    }
+
+    public class SecondLayerInjectable
+    {
+        @SecondLayer( byId = 1 )
+        private SecondLayerEntity layerEntity1;
+
+        @SecondLayer( byId = 2 )
+        private SecondLayerEntity layerEntity2;
+    }
+
+}

Added: incubator/onami/sandbox/factoryannotation/src/test/java/org/apache/onami/factoryannotation/ListenerMultiInjectionTestCase.java
URL: http://svn.apache.org/viewvc/incubator/onami/sandbox/factoryannotation/src/test/java/org/apache/onami/factoryannotation/ListenerMultiInjectionTestCase.java?rev=1428001&view=auto
==============================================================================
--- incubator/onami/sandbox/factoryannotation/src/test/java/org/apache/onami/factoryannotation/ListenerMultiInjectionTestCase.java (added)
+++ incubator/onami/sandbox/factoryannotation/src/test/java/org/apache/onami/factoryannotation/ListenerMultiInjectionTestCase.java Wed Jan  2 20:28:48 2013
@@ -0,0 +1,298 @@
+/*
+ * 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.onami.factoryannotation;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import org.apache.onami.factoryannotation.annotations.User;
+import org.apache.onami.factoryannotation.impl.UserEntity;
+import org.apache.onami.factoryannotation.impl.UserValueInjector;
+import org.junit.Test;
+
+import com.google.inject.AbstractModule;
+import com.google.inject.Guice;
+import com.google.inject.Inject;
+import com.google.inject.Injector;
+
+public class ListenerMultiInjectionTestCase
+{
+
+    @Test
+    public void testInjectionListenerValueProvider1()
+    {
+        final Listener listener = new Listener();
+
+        final Injector injector = Guice.createInjector( new FactoryAnnotationModule()
+        {
+            @Override
+            protected void configure()
+            {
+                bindType( UserEntity.class ).annotatedWith( User.class ).applyListener( listener ).toAnnotationFactory( new UserValueInjector() );
+            }
+        } );
+
+        final UserInjectable1 injectable = new UserInjectable1();
+        injector.injectMembers( injectable );
+
+        assertEquals( "User1", injectable.user1.getName() );
+        assertEquals( 1, injectable.user1.getId() );
+        assertEquals( "User2", injectable.user2.getName() );
+        assertEquals( 2, injectable.user2.getId() );
+
+        assertTrue( listener.executed[0] );
+        assertTrue( listener.executed[1] );
+        assertTrue( listener.executed[2] );
+        assertTrue( listener.executed[3] );
+
+        assertEquals( "before0", listener.orderOfExecution[0] );
+        assertEquals( "after0", listener.orderOfExecution[1] );
+        assertEquals( "before1", listener.orderOfExecution[2] );
+        assertEquals( "after1", listener.orderOfExecution[3] );
+    }
+
+    @Test
+    public void testInjectionListenerValueProvider2()
+    {
+        final Listener listener = new Listener();
+
+        final Injector injector = Guice.createInjector( new FactoryAnnotationModule()
+        {
+            @Override
+            protected void configure()
+            {
+                bindType( UserEntity.class ).annotatedWith( User.class ).applyListener( listener ).toAnnotationFactory( new UserValueInjector() );
+            }
+        }, new AbstractModule()
+        {
+            @Override
+            protected void configure()
+            {
+                bind( UserInjectable2.class );
+            }
+        } );
+
+        final UserInjectable2 injectable = injector.getInstance( UserInjectable2.class );
+
+        assertEquals( "User1", injectable.user1.getName() );
+        assertEquals( 1, injectable.user1.getId() );
+        assertEquals( "User2", injectable.user2.getName() );
+        assertEquals( 2, injectable.user2.getId() );
+
+        assertTrue( listener.executed[0] );
+        assertTrue( listener.executed[1] );
+        assertTrue( listener.executed[2] );
+        assertTrue( listener.executed[3] );
+
+        assertEquals( "before0", listener.orderOfExecution[0] );
+        assertEquals( "after0", listener.orderOfExecution[1] );
+        assertEquals( "before1", listener.orderOfExecution[2] );
+        assertEquals( "after1", listener.orderOfExecution[3] );
+    }
+
+    @Test
+    public void testInjectionListenerValueProvider3()
+    {
+        final Listener listener = new Listener();
+
+        final Injector injector = Guice.createInjector( new FactoryAnnotationModule()
+        {
+            @Override
+            protected void configure()
+            {
+                bindType( UserEntity.class ).annotatedWith( User.class ).applyListener( listener ).toAnnotationFactory( new UserValueInjector() );
+            }
+        }, new AbstractModule()
+        {
+            @Override
+            protected void configure()
+            {
+                bind( UserInjectable3.class );
+            }
+        } );
+
+        final UserInjectable3 injectable = injector.getInstance( UserInjectable3.class );
+
+        assertEquals( "User1", injectable.user1.getName() );
+        assertEquals( 1, injectable.user1.getId() );
+        assertEquals( "User2", injectable.user2.getName() );
+        assertEquals( 2, injectable.user2.getId() );
+
+        assertTrue( listener.executed[0] );
+        assertTrue( listener.executed[1] );
+        assertTrue( listener.executed[2] );
+        assertTrue( listener.executed[3] );
+
+        assertEquals( "before1", listener.orderOfExecution[0] );
+        assertEquals( "after2", listener.orderOfExecution[1] );
+        assertEquals( "before3", listener.orderOfExecution[2] );
+        assertEquals( "after4", listener.orderOfExecution[3] );
+    }
+
+    @Test
+    public void testInjectionListenerValueProvider4()
+    {
+        final Listener listener = new Listener();
+
+        final Injector injector = Guice.createInjector( new FactoryAnnotationModule()
+        {
+            @Override
+            protected void configure()
+            {
+                bindType( UserEntity.class ).annotatedWith( User.class ).applyListener( listener ).toAnnotationFactory( new UserValueInjector() );
+            }
+        } );
+
+        final UserInjectable4 injectable = new UserInjectable4();
+        injector.injectMembers( injectable );
+
+        assertEquals( "User1", injectable.user1.getName() );
+        assertEquals( 1, injectable.user1.getId() );
+        assertEquals( "User2", injectable.user2.getName() );
+        assertEquals( 2, injectable.user2.getId() );
+
+        assertTrue( listener.executed[0] );
+        assertTrue( listener.executed[1] );
+        assertTrue( listener.executed[2] );
+        assertTrue( listener.executed[3] );
+
+        assertEquals( "before1", listener.orderOfExecution[0] );
+        assertEquals( "after2", listener.orderOfExecution[1] );
+        assertEquals( "before3", listener.orderOfExecution[2] );
+        assertEquals( "after4", listener.orderOfExecution[3] );
+    }
+
+    public static class UserInjectable1
+    {
+        private UserEntity user1;
+
+        private UserEntity user2;
+
+        @Inject
+        public void user( @User( byId = 1 )
+        final UserEntity user1, @User( byId = 2 )
+        final UserEntity user2 )
+        {
+
+            this.user1 = user1;
+            this.user2 = user2;
+        }
+    }
+
+    public static class UserInjectable2
+    {
+        private final UserEntity user1;
+
+        private final UserEntity user2;
+
+        @Inject
+        public UserInjectable2( @User( byId = 1 )
+        final UserEntity user1, @User( byId = 2 )
+        final UserEntity user2 )
+        {
+
+            this.user1 = user1;
+            this.user2 = user2;
+        }
+    }
+
+    public static class UserInjectable3
+    {
+        @Inject
+        @User( byId = 1 )
+        private UserEntity user1;
+
+        @Inject
+        @User( byId = 2 )
+        private UserEntity user2;
+    }
+
+    public static class UserInjectable4
+    {
+        @User( byId = 1 )
+        private UserEntity user1;
+
+        @User( byId = 2 )
+        private UserEntity user2;
+    }
+
+    public static class Listener
+        implements FactoryAnnotationProvisionListener<UserEntity, User>
+    {
+
+        private final boolean[] executed = new boolean[4];
+
+        private final String[] orderOfExecution = new String[4];
+
+        private int count = 0;
+
+        public void beforeInjection( final FactoryAnnotationProvision<UserEntity, User> identityProvision,
+                                     final User provisionAnnotation )
+        {
+
+            final int position = identityProvision.getParameterPosition();
+
+            executed[count++] = true;
+
+            for ( int i = 0; i < 4; i++ )
+            {
+                if ( orderOfExecution[i] == null )
+                {
+                    if ( position == -1 )
+                    {
+                        orderOfExecution[i] = "before" + count;
+
+                    }
+                    else
+                    {
+                        orderOfExecution[i] = "before" + position;
+                    }
+                    break;
+                }
+            }
+        }
+
+        public void afterInjection( final FactoryAnnotationProvision<UserEntity, User> identityProvision,
+                                    final User provisionAnnotation, final UserEntity value )
+        {
+
+            final int position = identityProvision.getParameterPosition();
+
+            executed[count++] = true;
+
+            for ( int i = 0; i < 4; i++ )
+            {
+                if ( orderOfExecution[i] == null )
+                {
+                    if ( position == -1 )
+                    {
+                        orderOfExecution[i] = "after" + count;
+
+                    }
+                    else
+                    {
+                        orderOfExecution[i] = "after" + position;
+                    }
+                    break;
+                }
+            }
+        }
+    }
+
+}

Added: incubator/onami/sandbox/factoryannotation/src/test/java/org/apache/onami/factoryannotation/ListenerSingleInjectionTestCase.java
URL: http://svn.apache.org/viewvc/incubator/onami/sandbox/factoryannotation/src/test/java/org/apache/onami/factoryannotation/ListenerSingleInjectionTestCase.java?rev=1428001&view=auto
==============================================================================
--- incubator/onami/sandbox/factoryannotation/src/test/java/org/apache/onami/factoryannotation/ListenerSingleInjectionTestCase.java (added)
+++ incubator/onami/sandbox/factoryannotation/src/test/java/org/apache/onami/factoryannotation/ListenerSingleInjectionTestCase.java Wed Jan  2 20:28:48 2013
@@ -0,0 +1,237 @@
+/*
+ * 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.onami.factoryannotation;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import org.apache.onami.factoryannotation.annotations.User;
+import org.apache.onami.factoryannotation.impl.UserEntity;
+import org.apache.onami.factoryannotation.impl.UserValueInjector;
+import org.junit.Test;
+
+import com.google.inject.AbstractModule;
+import com.google.inject.Guice;
+import com.google.inject.Inject;
+import com.google.inject.Injector;
+
+public class ListenerSingleInjectionTestCase
+{
+
+    @Test
+    public void testInjectionListenerValueProvider1()
+    {
+        final Listener listener = new Listener();
+
+        final Injector injector = Guice.createInjector( new FactoryAnnotationModule()
+        {
+            @Override
+            protected void configure()
+            {
+                bindType( UserEntity.class ).annotatedWith( User.class ).applyListener( listener ).toAnnotationFactory( new UserValueInjector() );
+            }
+        } );
+
+        final UserInjectable1 injectable = new UserInjectable1();
+        injector.injectMembers( injectable );
+
+        assertEquals( "User1", injectable.user1.getName() );
+        assertEquals( 1, injectable.user1.getId() );
+
+        assertTrue( listener.executed[0] );
+        assertTrue( listener.executed[1] );
+
+        assertEquals( "before", listener.orderOfExecution[0] );
+        assertEquals( "after", listener.orderOfExecution[1] );
+    }
+
+    @Test
+    public void testInjectionListenerValueProvider2()
+    {
+        final Listener listener = new Listener();
+
+        final Injector injector = Guice.createInjector( new FactoryAnnotationModule()
+        {
+            @Override
+            protected void configure()
+            {
+                bindType( UserEntity.class ).annotatedWith( User.class ).applyListener( listener ).toAnnotationFactory( new UserValueInjector() );
+            }
+        }, new AbstractModule()
+        {
+            @Override
+            protected void configure()
+            {
+                bind( UserInjectable2.class );
+            }
+        } );
+
+        final UserInjectable2 injectable = injector.getInstance( UserInjectable2.class );
+
+        assertEquals( "User1", injectable.user1.getName() );
+        assertEquals( 1, injectable.user1.getId() );
+
+        assertTrue( listener.executed[0] );
+        assertTrue( listener.executed[1] );
+
+        assertEquals( "before", listener.orderOfExecution[0] );
+        assertEquals( "after", listener.orderOfExecution[1] );
+    }
+
+    @Test
+    public void testInjectionListenerValueProvider3()
+    {
+        final Listener listener = new Listener();
+
+        final Injector injector = Guice.createInjector( new FactoryAnnotationModule()
+        {
+            @Override
+            protected void configure()
+            {
+                bindType( UserEntity.class ).annotatedWith( User.class ).applyListener( listener ).toAnnotationFactory( new UserValueInjector() );
+            }
+        }, new AbstractModule()
+        {
+            @Override
+            protected void configure()
+            {
+                bind( UserInjectable3.class );
+            }
+        } );
+
+        final UserInjectable3 injectable = injector.getInstance( UserInjectable3.class );
+
+        assertEquals( "User1", injectable.user1.getName() );
+        assertEquals( 1, injectable.user1.getId() );
+
+        assertTrue( listener.executed[0] );
+        assertTrue( listener.executed[1] );
+
+        assertEquals( "before", listener.orderOfExecution[0] );
+        assertEquals( "after", listener.orderOfExecution[1] );
+    }
+
+    @Test
+    public void testInjectionListenerValueProvider4()
+    {
+        final Listener listener = new Listener();
+
+        final Injector injector = Guice.createInjector( new FactoryAnnotationModule()
+        {
+            @Override
+            protected void configure()
+            {
+                bindType( UserEntity.class ).annotatedWith( User.class ).applyListener( listener ).toAnnotationFactory( new UserValueInjector() );
+            }
+        } );
+
+        final UserInjectable4 injectable = new UserInjectable4();
+        injector.injectMembers( injectable );
+
+        assertEquals( "User1", injectable.user1.getName() );
+        assertEquals( 1, injectable.user1.getId() );
+
+        assertTrue( listener.executed[0] );
+        assertTrue( listener.executed[1] );
+
+        assertEquals( "before", listener.orderOfExecution[0] );
+        assertEquals( "after", listener.orderOfExecution[1] );
+    }
+
+    public static class UserInjectable1
+    {
+        private UserEntity user1;
+
+        @Inject
+        public void user( @User( byId = 1 )
+        final UserEntity user1 )
+        {
+            this.user1 = user1;
+        }
+    }
+
+    public static class UserInjectable2
+    {
+        private final UserEntity user1;
+
+        @Inject
+        public UserInjectable2( @User( byId = 1 )
+        final UserEntity user1 )
+        {
+            this.user1 = user1;
+        }
+    }
+
+    public static class UserInjectable3
+    {
+        @Inject
+        @User( byId = 1 )
+        private UserEntity user1;
+    }
+
+    public static class UserInjectable4
+    {
+        @User( byId = 1 )
+        private UserEntity user1;
+    }
+
+    public static class Listener
+        implements FactoryAnnotationProvisionListener<UserEntity, User>
+    {
+
+        private final boolean[] executed = new boolean[2];
+
+        private final String[] orderOfExecution = new String[2];
+
+        public void beforeInjection( final FactoryAnnotationProvision<UserEntity, User> identityProvision,
+                                     final User provisionAnnotation )
+        {
+
+            executed[0] = true;
+
+            if ( orderOfExecution[0] == null )
+            {
+                orderOfExecution[0] = "before";
+
+            }
+            else
+            {
+                orderOfExecution[1] = "before";
+            }
+        }
+
+        public void afterInjection( final FactoryAnnotationProvision<UserEntity, User> identityProvision,
+                                    final User provisionAnnotation, final UserEntity value )
+        {
+
+            executed[1] = true;
+
+            if ( orderOfExecution[0] == null )
+            {
+                orderOfExecution[0] = "after";
+
+            }
+            else
+            {
+                orderOfExecution[1] = "after";
+            }
+        }
+    }
+
+}

Added: incubator/onami/sandbox/factoryannotation/src/test/java/org/apache/onami/factoryannotation/MethodInjectionTestCase.java
URL: http://svn.apache.org/viewvc/incubator/onami/sandbox/factoryannotation/src/test/java/org/apache/onami/factoryannotation/MethodInjectionTestCase.java?rev=1428001&view=auto
==============================================================================
--- incubator/onami/sandbox/factoryannotation/src/test/java/org/apache/onami/factoryannotation/MethodInjectionTestCase.java (added)
+++ incubator/onami/sandbox/factoryannotation/src/test/java/org/apache/onami/factoryannotation/MethodInjectionTestCase.java Wed Jan  2 20:28:48 2013
@@ -0,0 +1,146 @@
+/*
+ * 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.onami.factoryannotation;
+
+import static org.junit.Assert.assertEquals;
+
+import org.apache.onami.factoryannotation.annotations.User;
+import org.apache.onami.factoryannotation.impl.UserEntity;
+import org.apache.onami.factoryannotation.impl.UserValueInjector;
+import org.junit.Test;
+
+import com.google.inject.Guice;
+import com.google.inject.Inject;
+import com.google.inject.Injector;
+
+public class MethodInjectionTestCase
+{
+
+    @Test
+    public void testMethodInjectionValueProvider1()
+    {
+        final Injector injector = Guice.createInjector( new FactoryAnnotationModule()
+        {
+            @Override
+            protected void configure()
+            {
+                bindType( UserEntity.class ).annotatedWith( User.class ).toAnnotationFactory( new UserValueInjector() );
+            }
+        } );
+
+        final UserInjectable1 injectable = new UserInjectable1();
+        injector.injectMembers( injectable );
+
+        assertEquals( "User1", injectable.user1.getName() );
+        assertEquals( 1, injectable.user1.getId() );
+    }
+
+    @Test
+    public void testMethodInjectionValueProvider2()
+    {
+        final Injector injector = Guice.createInjector( new FactoryAnnotationModule()
+        {
+            @Override
+            protected void configure()
+            {
+                bindType( UserEntity.class ).annotatedWith( User.class ).toAnnotationFactory( new UserValueInjector() );
+            }
+        } );
+
+        final UserInjectable2 injectable = new UserInjectable2();
+        injector.injectMembers( injectable );
+
+        assertEquals( "User1", injectable.user1.getName() );
+        assertEquals( 1, injectable.user1.getId() );
+        assertEquals( "User2", injectable.user2.getName() );
+        assertEquals( 2, injectable.user2.getId() );
+    }
+
+    @Test
+    public void testMethodInjectionValueProvider3()
+    {
+        final Injector injector = Guice.createInjector( new FactoryAnnotationModule()
+        {
+            @Override
+            protected void configure()
+            {
+                bindType( UserEntity.class ).annotatedWith( User.class ).toAnnotationFactory( new UserValueInjector() );
+            }
+        } );
+
+        final UserInjectable3 injectable = new UserInjectable3();
+        injector.injectMembers( injectable );
+
+        assertEquals( "User1", injectable.user1.getName() );
+        assertEquals( 1, injectable.user1.getId() );
+        assertEquals( "User2", injectable.user2.getName() );
+        assertEquals( 2, injectable.user2.getId() );
+    }
+
+    public static class UserInjectable1
+    {
+        private UserEntity user1;
+
+        @Inject
+        public void user( @User( byId = 1 )
+        final UserEntity user1 )
+        {
+            this.user1 = user1;
+        }
+    }
+
+    public static class UserInjectable2
+    {
+        private UserEntity user1;
+
+        private UserEntity user2;
+
+        @Inject
+        public void user( @User( byId = 1 )
+        final UserEntity user1, @User( byId = 2 )
+        final UserEntity user2 )
+        {
+
+            this.user1 = user1;
+            this.user2 = user2;
+        }
+    }
+
+    public static class UserInjectable3
+    {
+        private UserEntity user1;
+
+        private UserEntity user2;
+
+        @Inject
+        public void user1( @User( byId = 1 )
+        final UserEntity user1 )
+        {
+            this.user1 = user1;
+        }
+
+        @Inject
+        public void user2( @User( byId = 2 )
+        final UserEntity user2 )
+        {
+            this.user2 = user2;
+        }
+    }
+
+}

Added: incubator/onami/sandbox/factoryannotation/src/test/java/org/apache/onami/factoryannotation/TypeLiteralTestCase.java
URL: http://svn.apache.org/viewvc/incubator/onami/sandbox/factoryannotation/src/test/java/org/apache/onami/factoryannotation/TypeLiteralTestCase.java?rev=1428001&view=auto
==============================================================================
--- incubator/onami/sandbox/factoryannotation/src/test/java/org/apache/onami/factoryannotation/TypeLiteralTestCase.java (added)
+++ incubator/onami/sandbox/factoryannotation/src/test/java/org/apache/onami/factoryannotation/TypeLiteralTestCase.java Wed Jan  2 20:28:48 2013
@@ -0,0 +1,65 @@
+/*
+ * 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.onami.factoryannotation;
+
+import static org.junit.Assert.assertEquals;
+
+import org.apache.onami.factoryannotation.annotations.SecondLayer;
+import org.apache.onami.factoryannotation.impl.SecondLayerEntity;
+import org.apache.onami.factoryannotation.impl.SecondLayerIdentityProvider;
+import org.junit.Test;
+
+import com.google.inject.Guice;
+import com.google.inject.Injector;
+import com.google.inject.TypeLiteral;
+
+public class TypeLiteralTestCase
+{
+
+    @Test
+    public void testTypeLiteralValueProvider()
+    {
+        final Injector injector = Guice.createInjector( new FactoryAnnotationModule()
+        {
+            @Override
+            protected void configure()
+            {
+                bindIdentity( TypeLiteral.get( SecondLayerEntity.class ) ).annotatedWith( SecondLayer.class ).toAnnotationFactory( new SecondLayerIdentityProvider() );
+            }
+        } );
+
+        final SecondLayerInjectable injectable = new SecondLayerInjectable();
+        injector.injectMembers( injectable );
+
+        assertEquals( "SecondLayerEntity1", injectable.layerEntity1.getValue() );
+        assertEquals( 1, injectable.layerEntity1.getId() );
+        assertEquals( "SecondLayerEntity2", injectable.layerEntity2.getValue() );
+        assertEquals( 2, injectable.layerEntity2.getId() );
+    }
+
+    public class SecondLayerInjectable
+    {
+        @SecondLayer( byId = 1 )
+        private SecondLayerEntity layerEntity1;
+
+        @SecondLayer( byId = 2 )
+        private SecondLayerEntity layerEntity2;
+    }
+
+}

Added: incubator/onami/sandbox/factoryannotation/src/test/java/org/apache/onami/factoryannotation/annotations/CacheableUser.java
URL: http://svn.apache.org/viewvc/incubator/onami/sandbox/factoryannotation/src/test/java/org/apache/onami/factoryannotation/annotations/CacheableUser.java?rev=1428001&view=auto
==============================================================================
--- incubator/onami/sandbox/factoryannotation/src/test/java/org/apache/onami/factoryannotation/annotations/CacheableUser.java (added)
+++ incubator/onami/sandbox/factoryannotation/src/test/java/org/apache/onami/factoryannotation/annotations/CacheableUser.java Wed Jan  2 20:28:48 2013
@@ -0,0 +1,39 @@
+/*
+ * 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.onami.factoryannotation.annotations;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+import org.apache.onami.factoryannotation.FactoryAnnotationCacheable;
+
+import com.google.inject.BindingAnnotation;
+
+@FactoryAnnotationCacheable
+@BindingAnnotation
+@Retention( RetentionPolicy.RUNTIME )
+@Target( { ElementType.FIELD, ElementType.PARAMETER } )
+public @interface CacheableUser
+{
+
+    int byId();
+
+}

Added: incubator/onami/sandbox/factoryannotation/src/test/java/org/apache/onami/factoryannotation/annotations/Message.java
URL: http://svn.apache.org/viewvc/incubator/onami/sandbox/factoryannotation/src/test/java/org/apache/onami/factoryannotation/annotations/Message.java?rev=1428001&view=auto
==============================================================================
--- incubator/onami/sandbox/factoryannotation/src/test/java/org/apache/onami/factoryannotation/annotations/Message.java (added)
+++ incubator/onami/sandbox/factoryannotation/src/test/java/org/apache/onami/factoryannotation/annotations/Message.java Wed Jan  2 20:28:48 2013
@@ -0,0 +1,36 @@
+/*
+ * 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.onami.factoryannotation.annotations;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+import com.google.inject.BindingAnnotation;
+
+@BindingAnnotation
+@Retention( RetentionPolicy.RUNTIME )
+@Target( { ElementType.FIELD, ElementType.PARAMETER } )
+public @interface Message
+{
+
+    int byId();
+
+}

Added: incubator/onami/sandbox/factoryannotation/src/test/java/org/apache/onami/factoryannotation/annotations/SecondLayer.java
URL: http://svn.apache.org/viewvc/incubator/onami/sandbox/factoryannotation/src/test/java/org/apache/onami/factoryannotation/annotations/SecondLayer.java?rev=1428001&view=auto
==============================================================================
--- incubator/onami/sandbox/factoryannotation/src/test/java/org/apache/onami/factoryannotation/annotations/SecondLayer.java (added)
+++ incubator/onami/sandbox/factoryannotation/src/test/java/org/apache/onami/factoryannotation/annotations/SecondLayer.java Wed Jan  2 20:28:48 2013
@@ -0,0 +1,36 @@
+/*
+ * 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.onami.factoryannotation.annotations;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+import com.google.inject.BindingAnnotation;
+
+@BindingAnnotation
+@Retention( RetentionPolicy.RUNTIME )
+@Target( { ElementType.FIELD, ElementType.PARAMETER } )
+public @interface SecondLayer
+{
+
+    int byId();
+
+}

Added: incubator/onami/sandbox/factoryannotation/src/test/java/org/apache/onami/factoryannotation/annotations/User.java
URL: http://svn.apache.org/viewvc/incubator/onami/sandbox/factoryannotation/src/test/java/org/apache/onami/factoryannotation/annotations/User.java?rev=1428001&view=auto
==============================================================================
--- incubator/onami/sandbox/factoryannotation/src/test/java/org/apache/onami/factoryannotation/annotations/User.java (added)
+++ incubator/onami/sandbox/factoryannotation/src/test/java/org/apache/onami/factoryannotation/annotations/User.java Wed Jan  2 20:28:48 2013
@@ -0,0 +1,36 @@
+/*
+ * 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.onami.factoryannotation.annotations;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+import com.google.inject.BindingAnnotation;
+
+@BindingAnnotation
+@Retention( RetentionPolicy.RUNTIME )
+@Target( { ElementType.FIELD, ElementType.PARAMETER } )
+public @interface User
+{
+
+    int byId();
+
+}

Added: incubator/onami/sandbox/factoryannotation/src/test/java/org/apache/onami/factoryannotation/impl/CacheableUserValueInjector.java
URL: http://svn.apache.org/viewvc/incubator/onami/sandbox/factoryannotation/src/test/java/org/apache/onami/factoryannotation/impl/CacheableUserValueInjector.java?rev=1428001&view=auto
==============================================================================
--- incubator/onami/sandbox/factoryannotation/src/test/java/org/apache/onami/factoryannotation/impl/CacheableUserValueInjector.java (added)
+++ incubator/onami/sandbox/factoryannotation/src/test/java/org/apache/onami/factoryannotation/impl/CacheableUserValueInjector.java Wed Jan  2 20:28:48 2013
@@ -0,0 +1,47 @@
+/*
+ * 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.onami.factoryannotation.impl;
+
+import org.apache.onami.factoryannotation.FactoryAnnotationProvider;
+import org.apache.onami.factoryannotation.annotations.CacheableUser;
+
+public class CacheableUserValueInjector
+    implements FactoryAnnotationProvider<UserEntity, CacheableUser>
+{
+
+    public UserEntity buildValue( final CacheableUser annotation )
+    {
+        switch ( annotation.byId() )
+        {
+            case 1:
+                return new UserEntity( "User1", 1 );
+
+            case 2:
+                return new UserEntity( "User2", 2 );
+        }
+
+        throw new IllegalArgumentException( "No user found for Id " + annotation.byId() );
+    }
+
+    public Class<UserEntity> getInjectionType()
+    {
+        return UserEntity.class;
+    }
+
+}



Mime
View raw message