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 2008/12/14 00:24:19 UTC

svn commit: r726298 - in /incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util: AnnotationUtil.java ClassUtil.java WebBeansUtil.java

Author: gerdogdu
Date: Sat Dec 13 15:24:18 2008
New Revision: 726298

URL: http://svn.apache.org/viewvc?rev=726298&view=rev
Log:
Utility classes are updated.

Modified:
    incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/AnnotationUtil.java
    incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/ClassUtil.java
    incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java

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=726298&r1=726297&r2=726298&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 Sat Dec 13 15:24:18 2008
@@ -32,6 +32,8 @@
 import javax.webbeans.DuplicateBindingTypeException;
 import javax.webbeans.NonBinding;
 
+import org.apache.webbeans.xml.XMLAnnotationTypeManager;
+
 
 
 /**
@@ -662,4 +664,23 @@
 		}
 	}
 	
+	public static boolean isBindingAnnotation(Class<? extends Annotation> clazz)
+	{
+		Asserts.assertNotNull(clazz, "clazz parameter can not be null");
+		if(clazz.isAnnotationPresent(BindingType.class))
+		{
+			return true;
+		}
+		else
+		{
+			XMLAnnotationTypeManager manager = XMLAnnotationTypeManager.getInstance();
+			if(manager.isBindingTypeExist(clazz))
+			{
+				return true;
+			}
+		}
+		
+		return false;
+	}
+	
 }

Modified: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/ClassUtil.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/ClassUtil.java?rev=726298&r1=726297&r2=726298&view=diff
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/ClassUtil.java (original)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/ClassUtil.java Sat Dec 13 15:24:18 2008
@@ -27,6 +27,8 @@
 import java.lang.reflect.WildcardType;
 import java.math.BigDecimal;
 import java.math.BigInteger;
+import java.sql.Time;
+import java.sql.Timestamp;
 import java.text.DateFormat;
 import java.text.ParseException;
 import java.util.ArrayList;
@@ -40,8 +42,6 @@
 import java.util.Map;
 import java.util.Set;
 
-import javax.webbeans.AnnotationLiteral;
-
 import org.apache.webbeans.exception.WebBeansException;
 
 /**
@@ -57,6 +57,8 @@
 
 	public static Set<Class<?>> VALUE_TYPES = new HashSet<Class<?>>();
 
+	public static Set<Class<?>> PRIMITIVE_WRAPPERS = new HashSet<Class<?>>();
+	
 	public static Set<Class<?>> PRIMITIVES = new HashSet<Class<?>>();
 
 	static
@@ -80,6 +82,11 @@
 		VALUE_TYPES.add(Class.class);
 		VALUE_TYPES.add(List.class);
 		VALUE_TYPES.add(Enum.class);
+		VALUE_TYPES.add(java.sql.Date.class);
+		VALUE_TYPES.add(Time.class);
+		VALUE_TYPES.add(Timestamp.class);
+		VALUE_TYPES.add(BigDecimal.class);
+		VALUE_TYPES.add(BigInteger.class);
 
 		PRIMITIVES.add(Integer.TYPE);
 		PRIMITIVES.add(Float.TYPE);
@@ -89,6 +96,15 @@
 		PRIMITIVES.add(Byte.TYPE);
 		PRIMITIVES.add(Short.TYPE);
 		PRIMITIVES.add(Boolean.TYPE);
+		
+		PRIMITIVE_WRAPPERS.add(Integer.class);
+		PRIMITIVE_WRAPPERS.add(Float.class);
+		PRIMITIVE_WRAPPERS.add(Double.class);
+		PRIMITIVE_WRAPPERS.add(Character.class);
+		PRIMITIVE_WRAPPERS.add(Long.class);
+		PRIMITIVE_WRAPPERS.add(Byte.class);
+		PRIMITIVE_WRAPPERS.add(Short.class);
+		PRIMITIVE_WRAPPERS.add(Boolean.class);
 
 	}
 
@@ -616,28 +632,6 @@
 		return false;
 	}
 
-	public static AnnotationLiteral<Annotation> getAnnotationLiteral(final Class<? extends Annotation> clazz)
-	{
-		Asserts.nullCheckForClass(clazz);
-
-		AnnotationLiteral<Annotation> literal = new AnnotationLiteral<Annotation>()
-		{
-
-			/*
-			 * (non-Javadoc)
-			 * 
-			 * @see javax.webbeans.AnnotationLiteral#annotationType()
-			 */
-			@Override
-			public Class<? extends Annotation> annotationType()
-			{
-
-				return clazz;
-			}
-		};
-
-		return literal;
-	}
 
 	public static <T> Constructor<T>[] getConstructors(Class<T> clazz)
 	{
@@ -779,7 +773,14 @@
 		}
 
 	}
-
+	
+	/**
+	 * 
+	 * @param clazz webbeans implementation class
+	 * @param methodName name of the method that is searched
+	 * @param parameterTypes parameter types of the method(it can be subtype of the actual type arguments of the method)
+	 * @return the list of method that satisfies the condition
+	 */
 	public static List<Method> getClassMethodsWithTypes(Class<?> clazz, String methodName, List<Class<?>> parameterTypes)
 	{
 		Asserts.nullCheckForClass(clazz);
@@ -810,6 +811,8 @@
 				{
 					ok = false;
 				}
+				
+				j++;
 			}
 
 			if (ok)
@@ -884,6 +887,14 @@
 
 		return clazz.isPrimitive();
 	}
+	
+	public static boolean isPrimitiveWrapper(Class<?> clazz)
+	{
+		Asserts.nullCheckForClass(clazz);
+		
+		return PRIMITIVE_WRAPPERS.contains(clazz);
+		
+	}
 
 	public static boolean isArray(Class<?> clazz)
 	{
@@ -917,46 +928,58 @@
 		return result;
 	}
 
-	public static Object isValueOkForPrimitive(Class<?> type, String value)
+	/**
+	 * Gets the primitive/wrapper value of the parsed 
+	 * {@link String} parameter.
+	 * 
+	 * @param type primitive or wrapper of the primitive type
+	 * @param value value of the type
+	 * 
+	 * @return the parse of the given {@link String} 
+	 * 		   value into the corresponding value, if
+	 * 		   any exception occurs, returns null as the 
+	 * 		   value.
+	 */
+	public static Object isValueOkForPrimitiveOrWrapper(Class<?> type, String value)
 	{
 		try
 		{
-			if (type.equals(Integer.TYPE))
+			if (type.equals(Integer.TYPE) || type.equals(Integer.class))
 			{
 				return Integer.valueOf(value);
 			}
 
-			if (type.equals(Float.TYPE))
+			if (type.equals(Float.TYPE) || type.equals(Float.class))
 			{
 				return Float.valueOf(value);
 			}
 
-			if (type.equals(Double.TYPE))
+			if (type.equals(Double.TYPE) || type.equals(Double.class))
 			{
 				return Double.valueOf(value);
 			}
 
-			if (type.equals(Character.TYPE))
+			if (type.equals(Character.TYPE) || type.equals(Character.class))
 			{
 				return value.toCharArray()[0];
 			}
 
-			if (type.equals(Long.TYPE))
+			if (type.equals(Long.TYPE) || type.equals(Long.class))
 			{
 				return Long.valueOf(value);
 			}
 
-			if (type.equals(Byte.TYPE))
+			if (type.equals(Byte.TYPE) || type.equals(Byte.class))
 			{
 				return Byte.valueOf(value);
 			}
 
-			if (type.equals(Short.TYPE))
+			if (type.equals(Short.TYPE) || type.equals(Short.class))
 			{
 				return Short.valueOf(value);
 			}
 
-			if (type.equals(Boolean.TYPE))
+			if (type.equals(Boolean.TYPE) || type.equals(Boolean.class))
 			{
 				return Boolean.valueOf(value);
 			}
@@ -990,7 +1013,6 @@
 		try
 		{
 			Asserts.assertNotNull(value, "value parameter can not be null");
-
 			return DateFormat.getDateTimeInstance().parse(value);
 		} catch (ParseException e)
 		{
@@ -998,6 +1020,34 @@
 		}
 
 	}
+	
+	public static Object isValueOkForBigDecimalOrInteger(Class<?> type, String value)
+	{
+		Asserts.assertNotNull(type);
+		Asserts.assertNotNull(value);
+		
+		try
+		{
+			if(type.equals(BigInteger.class))
+			{
+				return new BigInteger(value);
+			}
+			else if(type.equals(BigDecimal.class))
+			{
+				return new BigDecimal(value);
+			}
+			else
+			{
+				return new WebBeansException(new IllegalArgumentException("Argument is not valid"));
+			}
+			
+			
+		}catch(NumberFormatException e)
+		{
+			return null;
+		}
+		
+	}
 
 	public static boolean isParametrized(Class<?> clazz)
 	{
@@ -1128,6 +1178,20 @@
 		return true;
 	}
 	
+	public static boolean isFirstParametricTypeArgGeneric(ParameterizedType type)
+	{
+		Asserts.assertNotNull(type, "type parameter can not be null");
+		Type arg = type.getActualTypeArguments()[0];
+		
+		if((arg instanceof TypeVariable) || (arg instanceof WildcardType))
+		{
+			return true;
+		}
+		
+		return false;
+	}
+	
+	
 	public static List<Type[]> getGenericSuperInterfacesTypeArguments(Class<?> clazz)
 	{
 		Asserts.nullCheckForClass(clazz);
@@ -1226,6 +1290,5 @@
 		
 		
 		return found;
-	}
-	
+	}		
 }

Modified: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java?rev=726298&r1=726297&r2=726298&view=diff
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java (original)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java Sat Dec 13 15:24:18 2008
@@ -77,6 +77,7 @@
 import org.apache.webbeans.annotation.RequestedScopeLiteral;
 import org.apache.webbeans.annotation.StandardLiteral;
 import org.apache.webbeans.component.AbstractComponent;
+import org.apache.webbeans.component.ComponentImpl;
 import org.apache.webbeans.component.ConversationComponent;
 import org.apache.webbeans.component.ManagerComponentImpl;
 import org.apache.webbeans.component.NewComponentImpl;
@@ -86,6 +87,9 @@
 import org.apache.webbeans.config.EJBWebBeansConfigurator;
 import org.apache.webbeans.config.SimpleWebBeansConfigurator;
 import org.apache.webbeans.container.ManagerImpl;
+import org.apache.webbeans.decorator.DecoratorUtil;
+import org.apache.webbeans.decorator.DecoratorsManager;
+import org.apache.webbeans.decorator.WebBeansDecoratorConfig;
 import org.apache.webbeans.deployment.DeploymentTypeManager;
 import org.apache.webbeans.deployment.StereoTypeManager;
 import org.apache.webbeans.deployment.StereoTypeModel;
@@ -97,6 +101,9 @@
 import org.apache.webbeans.intercept.InterceptorData;
 import org.apache.webbeans.intercept.InterceptorDataImpl;
 import org.apache.webbeans.intercept.InterceptorType;
+import org.apache.webbeans.intercept.InterceptorUtil;
+import org.apache.webbeans.intercept.InterceptorsManager;
+import org.apache.webbeans.intercept.WebBeansInterceptorConfig;
 
 /**
  * Contains some utility methods used in the all project.
@@ -199,6 +206,7 @@
 		boolean inAnnotation = false;
 		int j = 0;
 
+		/*Check for @Initializer*/
 		for (Constructor<T> constructor : constructors)
 		{
 			j++;
@@ -207,7 +215,8 @@
 				if (inAnnotation == true)// duplicate @In
 				{
 					throw new WebBeansConfigurationException("There are more than one Constrcutor with Initializer annotation in class " + clazz.getName());
-				} else
+				} 
+				else
 				{
 					inAnnotation = true;
 					result = constructor;
@@ -916,7 +925,7 @@
 			}
 		}
 		
-		//This does not defined in the Specification. Default deploymentType of the implementation class not defined in xML.
+		
 		if(result == null)
 		{
 			return new ProductionLiteral();
@@ -1223,4 +1232,37 @@
 		}		
 	}
 	
+	public static <T> void defineSimpleWebBeansInterceptors(Class<T> clazz)
+	{
+		if(InterceptorsManager.getInstance().isInterceptorEnabled(clazz))
+		{
+			ComponentImpl<T> component = null;
+			
+			InterceptorUtil.checkInterceptorConditions(clazz);
+			component = SimpleWebBeansConfigurator.define(clazz, WebBeansType.INTERCEPTOR);
+			
+			if(component != null)
+			{
+				WebBeansInterceptorConfig.configureInterceptorClass((ComponentImpl<Object>)component);	
+			}			
+		}
+		
+	}
+	
+	public static <T> void defineSimpleWebBeansDecorators(Class<T> clazz)
+	{
+		if(DecoratorsManager.getInstance().isDecoratorEnabled(clazz))
+		{
+			ComponentImpl<T> component = null;
+			
+			DecoratorUtil.checkDecoratorConditions(clazz);
+			component = SimpleWebBeansConfigurator.define(clazz, WebBeansType.DECORATOR);
+			
+			if(component != null)
+			{
+				WebBeansDecoratorConfig.configureDecoratorClass((ComponentImpl<Object>)component);
+			}			
+		}		
+		
+	}
 }
\ No newline at end of file