You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwebbeans.apache.org by ge...@apache.org on 2009/06/18 22:13:46 UTC

svn commit: r786237 - in /incubator/openwebbeans/trunk/webbeans-impl/src: main/java/org/apache/webbeans/annotation/ main/java/org/apache/webbeans/config/ main/java/org/apache/webbeans/util/ test/java/org/apache/webbeans/test/component/binding/ test/jav...

Author: gerdogdu
Date: Thu Jun 18 20:13:46 2009
New Revision: 786237

URL: http://svn.apache.org/viewvc?rev=786237&view=rev
Log:
Adding @Any support.

Added:
    incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/annotation/AnyScopeLiteral.java   (with props)
    incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/binding/AnyBindingComponent.java   (with props)
    incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/binding/DefaultAnyBinding.java   (with props)
    incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/binding/NonAnyBindingComponent.java   (with props)
    incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/binding/AnyBindingTest.java   (with props)
Modified:
    incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/DefinitionUtil.java
    incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/AnnotationUtil.java

Added: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/annotation/AnyScopeLiteral.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/annotation/AnyScopeLiteral.java?rev=786237&view=auto
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/annotation/AnyScopeLiteral.java (added)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/annotation/AnyScopeLiteral.java Thu Jun 18 20:13:46 2009
@@ -0,0 +1,21 @@
+/*
+ * 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.webbeans.annotation;
+
+import javax.enterprise.inject.AnnotationLiteral;
+import javax.enterprise.inject.Any;
+
+public class AnyScopeLiteral extends AnnotationLiteral<Any> implements Any{
+
+}

Propchange: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/annotation/AnyScopeLiteral.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/DefinitionUtil.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/DefinitionUtil.java?rev=786237&r1=786236&r2=786237&view=diff
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/DefinitionUtil.java (original)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/DefinitionUtil.java Thu Jun 18 20:13:46 2009
@@ -27,7 +27,6 @@
 import java.util.Set;
 
 import javax.decorator.Decorates;
-import javax.enterprise.context.Dependent;
 import javax.enterprise.context.ScopeType;
 import javax.enterprise.event.Observes;
 import javax.enterprise.inject.Current;
@@ -46,6 +45,7 @@
 import javax.inject.Obtains;
 import javax.inject.Realizes;
 
+import org.apache.webbeans.annotation.AnyScopeLiteral;
 import org.apache.webbeans.annotation.CurrentLiteral;
 import org.apache.webbeans.annotation.DependentScopeLiteral;
 import org.apache.webbeans.annotation.ProductionLiteral;
@@ -261,7 +261,13 @@
         {
             component.addBindingType(new CurrentLiteral());
         }
-
+        
+        //Add @Any support
+        if(!AnnotationUtil.isAnyBindingExist(component))
+        {
+        	component.addBindingType(new AnyScopeLiteral());
+        }
+        	 
     }
 
     /**

Modified: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/AnnotationUtil.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/AnnotationUtil.java?rev=786237&r1=786236&r2=786237&view=diff
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/AnnotationUtil.java (original)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/AnnotationUtil.java Thu Jun 18 20:13:46 2009
@@ -27,8 +27,10 @@
 
 import javax.annotation.Resource;
 import javax.ejb.EJB;
+import javax.enterprise.inject.Any;
 import javax.enterprise.inject.BindingType;
 import javax.enterprise.inject.NonBinding;
+import javax.enterprise.inject.spi.Bean;
 import javax.enterprise.inject.stereotype.Stereotype;
 import javax.xml.ws.WebServiceRef;
 
@@ -750,6 +752,29 @@
 
         return false;
     }
+    
+    
+    /**
+     * Returns true if any binding exist
+     * 
+     * @param bean bean
+     * @return true if any binding exist
+     */
+    public static boolean isAnyBindingExist(Bean<?> bean)
+    {
+    	Asserts.assertNotNull(bean, "bean parameter can not be null");
+    	Set<Annotation> bindings = bean.getBindings();
+    	
+    	for(Annotation ann : bindings)
+    	{
+    		if(ann.annotationType().equals(Any.class))
+    		{
+    			return true;
+    		}
+    	}
+    	
+    	return false;
+    }
 
     /**
      * check if any of the given resources is a resource annotation

Added: incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/binding/AnyBindingComponent.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/binding/AnyBindingComponent.java?rev=786237&view=auto
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/binding/AnyBindingComponent.java (added)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/binding/AnyBindingComponent.java Thu Jun 18 20:13:46 2009
@@ -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.webbeans.test.component.binding;
+
+import javax.enterprise.inject.Any;
+
+import org.apache.webbeans.test.annotation.binding.ParameterBinding1;
+
+@Any
+@ParameterBinding1
+public class AnyBindingComponent {
+
+}

Propchange: incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/binding/AnyBindingComponent.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/binding/DefaultAnyBinding.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/binding/DefaultAnyBinding.java?rev=786237&view=auto
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/binding/DefaultAnyBinding.java (added)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/binding/DefaultAnyBinding.java Thu Jun 18 20:13:46 2009
@@ -0,0 +1,18 @@
+/*
+ * 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.webbeans.test.component.binding;
+
+public class DefaultAnyBinding {
+
+}

Propchange: incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/binding/DefaultAnyBinding.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/binding/NonAnyBindingComponent.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/binding/NonAnyBindingComponent.java?rev=786237&view=auto
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/binding/NonAnyBindingComponent.java (added)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/binding/NonAnyBindingComponent.java Thu Jun 18 20:13:46 2009
@@ -0,0 +1,27 @@
+/*
+ * 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.webbeans.test.component.binding;
+
+
+import org.apache.webbeans.test.annotation.binding.ParameterBinding1;
+import org.apache.webbeans.test.annotation.binding.ParameterBinding2;
+import org.apache.webbeans.test.annotation.binding.ParameterBinding3;
+
+
+@ParameterBinding1
+@ParameterBinding2
+@ParameterBinding3
+public class NonAnyBindingComponent {
+
+}

Propchange: incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/binding/NonAnyBindingComponent.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/binding/AnyBindingTest.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/binding/AnyBindingTest.java?rev=786237&view=auto
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/binding/AnyBindingTest.java (added)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/binding/AnyBindingTest.java Thu Jun 18 20:13:46 2009
@@ -0,0 +1,63 @@
+/*
+ * 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.webbeans.test.unittests.binding;
+
+
+import java.lang.annotation.Annotation;
+import java.util.Set;
+
+import org.apache.webbeans.component.AbstractComponent;
+import org.apache.webbeans.test.component.binding.AnyBindingComponent;
+import org.apache.webbeans.test.component.binding.DefaultAnyBinding;
+import org.apache.webbeans.test.component.binding.NonAnyBindingComponent;
+import org.apache.webbeans.test.servlet.TestContext;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+public class AnyBindingTest extends TestContext{
+
+	public AnyBindingTest()
+	{
+		super(AnyBindingTest.class.getName());
+	}
+	
+	@Before
+	public void init()
+	{
+		initDefaultDeploymentTypes();
+	}
+	
+	@Test
+	public void testAny()
+	{
+		AbstractComponent<AnyBindingComponent> comp1 = defineSimpleWebBean(AnyBindingComponent.class);
+		Set<Annotation> bindings = comp1.getBindings();
+		
+		Assert.assertEquals(2, bindings.size());
+		
+		AbstractComponent<NonAnyBindingComponent> comp2 = defineSimpleWebBean(NonAnyBindingComponent.class);
+		bindings = comp2.getBindings();
+		
+		Assert.assertEquals(4, bindings.size());
+		
+
+		AbstractComponent<DefaultAnyBinding> comp3 = defineSimpleWebBean(DefaultAnyBinding.class);
+		bindings = comp3.getBindings();
+		
+		Assert.assertEquals(2, bindings.size());
+
+		
+	}
+}

Propchange: incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/binding/AnyBindingTest.java
------------------------------------------------------------------------------
    svn:eol-style = native