You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@onami.apache.org by no...@apache.org on 2013/01/02 21:28:50 UTC

svn commit: r1428001 [3/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...

Added: incubator/onami/sandbox/factoryannotation/src/test/java/org/apache/onami/factoryannotation/impl/InjectedUserValueInjector.java
URL: http://svn.apache.org/viewvc/incubator/onami/sandbox/factoryannotation/src/test/java/org/apache/onami/factoryannotation/impl/InjectedUserValueInjector.java?rev=1428001&view=auto
==============================================================================
--- incubator/onami/sandbox/factoryannotation/src/test/java/org/apache/onami/factoryannotation/impl/InjectedUserValueInjector.java (added)
+++ incubator/onami/sandbox/factoryannotation/src/test/java/org/apache/onami/factoryannotation/impl/InjectedUserValueInjector.java Wed Jan  2 20:28:48 2013
@@ -0,0 +1,59 @@
+/*
+ * 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.User;
+
+import com.google.inject.Inject;
+import com.google.inject.name.Named;
+
+public class InjectedUserValueInjector
+    implements FactoryAnnotationProvider<UserEntity, User>
+{
+
+    @Inject
+    @Named( "test1" )
+    private UserEntity userEntity1;
+
+    @Inject
+    @Named( "test2" )
+    private UserEntity userEntity2;
+
+    public Class<UserEntity> getInjectionType()
+    {
+        return UserEntity.class;
+    }
+
+    public UserEntity buildValue( final User annotation )
+    {
+        if ( annotation.byId() == 1 )
+        {
+            return userEntity1;
+        }
+
+        if ( annotation.byId() == 2 )
+        {
+            return userEntity2;
+        }
+
+        return null;
+    }
+
+}

Added: incubator/onami/sandbox/factoryannotation/src/test/java/org/apache/onami/factoryannotation/impl/MessageEntity.java
URL: http://svn.apache.org/viewvc/incubator/onami/sandbox/factoryannotation/src/test/java/org/apache/onami/factoryannotation/impl/MessageEntity.java?rev=1428001&view=auto
==============================================================================
--- incubator/onami/sandbox/factoryannotation/src/test/java/org/apache/onami/factoryannotation/impl/MessageEntity.java (added)
+++ incubator/onami/sandbox/factoryannotation/src/test/java/org/apache/onami/factoryannotation/impl/MessageEntity.java Wed Jan  2 20:28:48 2013
@@ -0,0 +1,43 @@
+/*
+ * 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;
+
+public class MessageEntity
+{
+    private final String message;
+
+    private final int id;
+
+    MessageEntity( final String message, final int id )
+    {
+        this.message = message;
+        this.id = id;
+    }
+
+    public String getMessage()
+    {
+        return message;
+    }
+
+    public int getId()
+    {
+        return id;
+    }
+
+}

Added: incubator/onami/sandbox/factoryannotation/src/test/java/org/apache/onami/factoryannotation/impl/MessageValueInjector.java
URL: http://svn.apache.org/viewvc/incubator/onami/sandbox/factoryannotation/src/test/java/org/apache/onami/factoryannotation/impl/MessageValueInjector.java?rev=1428001&view=auto
==============================================================================
--- incubator/onami/sandbox/factoryannotation/src/test/java/org/apache/onami/factoryannotation/impl/MessageValueInjector.java (added)
+++ incubator/onami/sandbox/factoryannotation/src/test/java/org/apache/onami/factoryannotation/impl/MessageValueInjector.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.Message;
+
+public class MessageValueInjector
+    implements FactoryAnnotationProvider<MessageEntity, Message>
+{
+
+    public MessageEntity buildValue( final Message annotation )
+    {
+        switch ( annotation.byId() )
+        {
+            case 100:
+                return new MessageEntity( "MessageTest100", 100 );
+
+            case 200:
+                return new MessageEntity( "MessageTest200", 200 );
+        }
+
+        throw new IllegalArgumentException( "No message found for Id " + annotation.byId() );
+    }
+
+    public Class<MessageEntity> getInjectionType()
+    {
+        return MessageEntity.class;
+    }
+
+}

Added: incubator/onami/sandbox/factoryannotation/src/test/java/org/apache/onami/factoryannotation/impl/SecondLayerEntity.java
URL: http://svn.apache.org/viewvc/incubator/onami/sandbox/factoryannotation/src/test/java/org/apache/onami/factoryannotation/impl/SecondLayerEntity.java?rev=1428001&view=auto
==============================================================================
--- incubator/onami/sandbox/factoryannotation/src/test/java/org/apache/onami/factoryannotation/impl/SecondLayerEntity.java (added)
+++ incubator/onami/sandbox/factoryannotation/src/test/java/org/apache/onami/factoryannotation/impl/SecondLayerEntity.java Wed Jan  2 20:28:48 2013
@@ -0,0 +1,28 @@
+/*
+ * 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;
+
+public interface SecondLayerEntity
+{
+
+    String getValue();
+
+    int getId();
+
+}

Added: incubator/onami/sandbox/factoryannotation/src/test/java/org/apache/onami/factoryannotation/impl/SecondLayerIdentityProvider.java
URL: http://svn.apache.org/viewvc/incubator/onami/sandbox/factoryannotation/src/test/java/org/apache/onami/factoryannotation/impl/SecondLayerIdentityProvider.java?rev=1428001&view=auto
==============================================================================
--- incubator/onami/sandbox/factoryannotation/src/test/java/org/apache/onami/factoryannotation/impl/SecondLayerIdentityProvider.java (added)
+++ incubator/onami/sandbox/factoryannotation/src/test/java/org/apache/onami/factoryannotation/impl/SecondLayerIdentityProvider.java Wed Jan  2 20:28:48 2013
@@ -0,0 +1,98 @@
+/*
+ * 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.SecondLayer;
+import org.apache.onami.factoryannotation.annotations.User;
+
+public class SecondLayerIdentityProvider
+    implements FactoryAnnotationProvider<SecondLayerEntity, SecondLayer>
+{
+
+    public Class<SecondLayerEntity> getInjectionType()
+    {
+        return SecondLayerEntity.class;
+    }
+
+    public SecondLayerEntity buildValue( final SecondLayer annotation )
+    {
+        switch ( annotation.byId() )
+        {
+            case 1:
+                return new SecondLayerEntity()
+                {
+
+                    public String getValue()
+                    {
+                        return "SecondLayerEntity1";
+                    }
+
+                    public int getId()
+                    {
+                        return 1;
+                    }
+                };
+
+            case 2:
+                return new SecondLayerEntity()
+                {
+
+                    public String getValue()
+                    {
+                        return "SecondLayerEntity2";
+                    }
+
+                    public int getId()
+                    {
+                        return 2;
+                    }
+                };
+
+            case 3:
+                return new InjectableSecondLayerEntity();
+        }
+
+        return null;
+    }
+
+    public static class InjectableSecondLayerEntity
+        implements SecondLayerEntity
+    {
+
+        @User( byId = 1 )
+        private UserEntity userEntity;
+
+        public String getValue()
+        {
+            return "SecondLayerEntity3_" + userEntity.getName();
+        }
+
+        public int getId()
+        {
+            return 3;
+        }
+
+        public UserEntity getUserEntity()
+        {
+            return userEntity;
+        }
+    }
+
+}

Added: incubator/onami/sandbox/factoryannotation/src/test/java/org/apache/onami/factoryannotation/impl/UserEntity.java
URL: http://svn.apache.org/viewvc/incubator/onami/sandbox/factoryannotation/src/test/java/org/apache/onami/factoryannotation/impl/UserEntity.java?rev=1428001&view=auto
==============================================================================
--- incubator/onami/sandbox/factoryannotation/src/test/java/org/apache/onami/factoryannotation/impl/UserEntity.java (added)
+++ incubator/onami/sandbox/factoryannotation/src/test/java/org/apache/onami/factoryannotation/impl/UserEntity.java Wed Jan  2 20:28:48 2013
@@ -0,0 +1,80 @@
+/*
+ * 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;
+
+public class UserEntity
+{
+    private final String name;
+
+    private final int id;
+
+    UserEntity( final String name, final int id )
+    {
+        this.name = name;
+        this.id = id;
+    }
+
+    public String getName()
+    {
+        return name;
+    }
+
+    public int getId()
+    {
+        return id;
+    }
+
+    public static UserEntity build( final String name, final int id )
+    {
+        return new UserEntity( name, id );
+    }
+
+    @Override
+    public int hashCode()
+    {
+        final int prime = 31;
+        int result = 1;
+        result = prime * result + id;
+        result = prime * result + ( ( name == null ) ? 0 : name.hashCode() );
+        return result;
+    }
+
+    @Override
+    public boolean equals( Object obj )
+    {
+        if ( this == obj )
+            return true;
+        if ( obj == null )
+            return false;
+        if ( getClass() != obj.getClass() )
+            return false;
+        UserEntity other = (UserEntity) obj;
+        if ( id != other.id )
+            return false;
+        if ( name == null )
+        {
+            if ( other.name != null )
+                return false;
+        }
+        else if ( !name.equals( other.name ) )
+            return false;
+        return true;
+    }
+
+}

Added: incubator/onami/sandbox/factoryannotation/src/test/java/org/apache/onami/factoryannotation/impl/UserValueInjector.java
URL: http://svn.apache.org/viewvc/incubator/onami/sandbox/factoryannotation/src/test/java/org/apache/onami/factoryannotation/impl/UserValueInjector.java?rev=1428001&view=auto
==============================================================================
--- incubator/onami/sandbox/factoryannotation/src/test/java/org/apache/onami/factoryannotation/impl/UserValueInjector.java (added)
+++ incubator/onami/sandbox/factoryannotation/src/test/java/org/apache/onami/factoryannotation/impl/UserValueInjector.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.User;
+
+public class UserValueInjector
+    implements FactoryAnnotationProvider<UserEntity, User>
+{
+
+    public UserEntity buildValue( final User 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;
+    }
+
+}