Author: nickarls
Date: 2008-11-24 05:27:52 -0500 (Mon, 24 Nov 2008)
New Revision: 359
Modified:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/MetaDataCache.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/AbstractBean.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/ProducerMethodBean.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/Reflections.java
Log:
minor docs + RuntimeException -> DefinitionException
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/MetaDataCache.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/MetaDataCache.java 2008-11-24
09:54:56 UTC (rev 358)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/MetaDataCache.java 2008-11-24
10:27:52 UTC (rev 359)
@@ -66,29 +66,29 @@
public String toString()
{
StringBuffer buffer = new StringBuffer();
- buffer.append("Binding types " + bindingTypes.size() +
"\n");
+ buffer.append("Binding types: " + bindingTypes.size() +
"\n");
int i = 0;
for (Entry<Class<? extends Annotation>, BindingTypeModel<?>>
entry : bindingTypes.entrySet())
{
buffer.append(++i + " - " + entry.getKey().getName() + ":
" + entry.getValue().toString() + "\n");
}
- buffer.append("EJB metadata " + ejbMetaDataMap.size() +
"\n");
+ buffer.append("EJB metadata: " + ejbMetaDataMap.size() +
"\n");
i = 0;
for (Entry<Class<?>, EjbMetaData<?>> entry :
ejbMetaDataMap.entrySet())
{
- buffer.append(++i + " - " + entry.getKey().getName() + ":
" + entry.getValue().toString());
+ buffer.append(++i + " - " + entry.getKey().getName() + ":
" + entry.getValue().toString() + "\n");
}
- buffer.append("Scopes " + scopes.size() + "\n");
+ buffer.append("Scopes: " + scopes.size() + "\n");
i = 0;
for (Entry<Class<? extends Annotation>, ScopeModel<?>> entry :
scopes.entrySet())
{
- buffer.append(++i + " - " + entry.getKey().getName() + ":
" + entry.getValue().toString());
+ buffer.append(++i + " - " + entry.getKey().getName() + ":
" + entry.getValue().toString() + "\n");
}
- buffer.append("Stereotypes " + stereotypes.size() + "\n");
+ buffer.append("Stereotypes: " + stereotypes.size() + "\n");
i = 0;
for (Entry<Class<? extends Annotation>, StereotypeModel<?>>
entry : stereotypes.entrySet())
{
- buffer.append(++i + " - " + entry.getKey().getName() + ":
" + entry.getValue().toString());
+ buffer.append(++i + " - " + entry.getKey().getName() + ":
" + entry.getValue().toString() + "\n");
}
return buffer.toString();
}
@@ -116,6 +116,7 @@
{
StringBuffer buffer = new StringBuffer();
buffer.append("Scope model map\n");
+ buffer.append("--------------------\n");
buffer.append(super.toString() + "\n");
return buffer.toString();
}
@@ -143,6 +144,7 @@
{
StringBuffer buffer = new StringBuffer();
buffer.append("Binding type model map\n");
+ buffer.append("--------------------\n");
buffer.append(super.toString() + "\n");
return buffer.toString();
}
@@ -181,6 +183,7 @@
{
StringBuffer buffer = new StringBuffer();
buffer.append("EJB metadata: " + delegate.size() + "\n");
+ buffer.append("--------------------\n");
int i = 0;
for (Entry<Class<?>, EjbMetaData<?>> entry :
delegate.entrySet())
{
@@ -228,7 +231,9 @@
public String toString()
{
StringBuffer buffer = new StringBuffer();
+ buffer.append("====================\n");
buffer.append("Metadata cache\n");
+ buffer.append("====================\n");
buffer.append(bindingTypes.toString() + "\n");
buffer.append(ejbMetaDataMap.toString() + "\n");
buffer.append(scopes.toString() + "\n");
@@ -238,6 +243,7 @@
{
buffer.append(++i + " - " + entry.getKey().getName() + ": "
+ entry.getValue().toString() + "\n");
}
+ buffer.append("====================\n");
return buffer.toString();
}
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/AbstractBean.java
===================================================================
---
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/AbstractBean.java 2008-11-24
09:54:56 UTC (rev 358)
+++
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/AbstractBean.java 2008-11-24
10:27:52 UTC (rev 359)
@@ -65,6 +65,10 @@
/**
* Helper class for getting deployment type
*
+ * Loops through the enabled deployment types (backwards) and returns the first one
+ * present in the possible deployments type, resulting in the deployment type of
+ * highest priority
+ *
* @param enabledDeploymentTypes The currently enabled deployment types
* @param possibleDeploymentTypes The possible deployment types
* @return The deployment type
@@ -193,7 +197,7 @@
Set<Annotation> xmlDeploymentTypes = null;
if (xmlDeploymentTypes.size() > 1)
{
- throw new RuntimeException("At most one deployment type may be specified
(" + xmlDeploymentTypes + " are specified)");
+ throw new DefinitionException ("At most one deployment type may be
specified (" + xmlDeploymentTypes + " are specified)");
}
if (xmlDeploymentTypes.size() == 1)
@@ -361,7 +365,7 @@
}
else if (getMergedStereotypes().getPossibleScopeTypes().size() > 1)
{
- throw new RuntimeException("All stereotypes must specify the same scope OR
a scope must be specified on the bean");
+ throw new DefinitionException ("All stereotypes must specify the same scope
OR a scope must be specified on the bean");
}
this.scopeType = Dependent.class;
log.trace("Using default @Dependent scope");
@@ -379,7 +383,7 @@
{
if (deploymentType == null)
{
- throw new RuntimeException("type: " + getType() + " must specify
a deployment type");
+ throw new DefinitionException ("type: " + getType() + " must
specify a deployment type");
}
else if (deploymentType.equals(Standard.class) &&
!STANDARD_WEB_BEAN_CLASSES.contains(getAnnotatedItem().getType()))
{
Modified:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/ProducerMethodBean.java
===================================================================
---
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/ProducerMethodBean.java 2008-11-24
09:54:56 UTC (rev 358)
+++
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/ProducerMethodBean.java 2008-11-24
10:27:52 UTC (rev 359)
@@ -185,7 +185,7 @@
else if (disposalMethods.size() > 1)
{
// TODO List out found disposal methods
- throw new RuntimeException(getLocation() + "Cannot declare multiple
disposal methods for this producer method");
+ throw new DefinitionException (getLocation() + "Cannot declare multiple
disposal methods for this producer method");
}
}
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/Reflections.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/Reflections.java 2008-11-24
09:54:56 UTC (rev 358)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/Reflections.java 2008-11-24
10:27:52 UTC (rev 359)
@@ -18,13 +18,12 @@
import javax.webbeans.ExecutionException;
-
public class Reflections
{
-
+
public static Class<?> classForName(String name) throws ClassNotFoundException
{
- try
+ try
{
return Thread.currentThread().getContextClassLoader().loadClass(name);
}
@@ -33,35 +32,35 @@
return Class.forName(name);
}
}
-
+
public static String getPropertyName(Method method)
{
String methodName = method.getName();
- if ( methodName.matches("^(get).*") &&
method.getParameterTypes().length==0 )
+ if (methodName.matches("^(get).*") &&
method.getParameterTypes().length == 0)
{
- return Introspector.decapitalize( methodName.substring(3) );
+ return Introspector.decapitalize(methodName.substring(3));
}
- else if (methodName.matches("^(is).*") &&
method.getParameterTypes().length==0 )
+ else if (methodName.matches("^(is).*") &&
method.getParameterTypes().length == 0)
{
- return Introspector.decapitalize( methodName.substring(2) );
+ return Introspector.decapitalize(methodName.substring(2));
}
else
{
return null;
}
-
+
}
public static boolean isFinal(Class<?> clazz)
{
return Modifier.isFinal(clazz.getModifiers());
}
-
+
public static boolean isFinal(Member member)
{
return Modifier.isFinal(member.getModifiers());
}
-
+
public static boolean isTypeOrAnyMethodFinal(Class<?> type)
{
if (isFinal(type))
@@ -77,44 +76,44 @@
}
return false;
}
-
+
public static boolean isPrimitive(Class<?> type)
{
return type.isPrimitive();
}
-
+
public static boolean isStatic(Class<?> type)
{
return Modifier.isStatic(type.getModifiers());
}
-
+
public static boolean isStatic(Member member)
{
return Modifier.isStatic(member.getModifiers());
}
-
+
public static boolean isAbstract(Class<?> clazz)
{
return Modifier.isAbstract(clazz.getModifiers());
}
-
+
public static boolean isStaticInnerClass(Class<?> clazz)
{
return clazz.isMemberClass() && isStatic(clazz);
}
-
+
public static boolean isNonStaticInnerClass(Class<?> clazz)
{
return clazz.isMemberClass() && !isStatic(clazz);
}
-
+
public static <T> Constructor<T> getConstructor(Class<T> clazz,
Class<?>... parameterTypes)
{
try
{
return clazz.getConstructor(parameterTypes);
}
- catch (NoSuchMethodException e)
+ catch (NoSuchMethodException e)
{
return null;
}
@@ -123,8 +122,8 @@
throw new RuntimeException("Error accessing constructor (with parameters
" + parameterTypes + ") of " + clazz, e);
}
}
-
- public static List<Method> getMethods(Class<?> clazz, Class<? extends
Annotation> annotationType)
+
+ public static List<Method> getMethods(Class<?> clazz, Class<? extends
Annotation> annotationType)
{
List<Method> methods = new ArrayList<Method>();
for (Method method : clazz.getMethods())
@@ -136,9 +135,9 @@
}
return methods;
}
-
+
@SuppressWarnings("unchecked")
- public static <T> List<Constructor<T>>
getAnnotatedConstructors(Class<? extends T> clazz, Class<? extends Annotation>
annotationType)
+ public static <T> List<Constructor<T>>
getAnnotatedConstructors(Class<? extends T> clazz, Class<? extends Annotation>
annotationType)
{
List<Constructor<T>> constructors = new
ArrayList<Constructor<T>>();
for (Constructor<?> constructor : clazz.getConstructors())
@@ -150,9 +149,9 @@
}
return constructors;
}
-
+
@SuppressWarnings("unchecked")
- public static <T> List<Constructor<T>>
getConstructorsForAnnotatedParameter(Class<? extends T> clazz, Class<? extends
Annotation> parameterAnnotationType)
+ public static <T> List<Constructor<T>>
getConstructorsForAnnotatedParameter(Class<? extends T> clazz, Class<? extends
Annotation> parameterAnnotationType)
{
List<Constructor<T>> constructors = new
ArrayList<Constructor<T>>();
for (Constructor<?> constructor : clazz.getConstructors())
@@ -170,9 +169,9 @@
}
return constructors;
}
-
+
@SuppressWarnings("unchecked")
- public static <T> List<Constructor<T>>
getConstructorsForMetaAnnotatedParameter(Class<? extends T> clazz, Class<?
extends Annotation> metaAnnotationType)
+ public static <T> List<Constructor<T>>
getConstructorsForMetaAnnotatedParameter(Class<? extends T> clazz, Class<?
extends Annotation> metaAnnotationType)
{
List<Constructor<T>> constructors = new
ArrayList<Constructor<T>>();
for (Constructor<?> constructor : clazz.getConstructors())
@@ -226,12 +225,12 @@
}
return annotationTypeList.size() == 0;
}
-
+
public static Type[] getActualTypeArguments(Class<?> clazz)
{
if (clazz.getGenericSuperclass() instanceof ParameterizedType)
{
- return ((ParameterizedType)
clazz.getGenericSuperclass()).getActualTypeArguments();
+ return ((ParameterizedType)
clazz.getGenericSuperclass()).getActualTypeArguments();
}
else
{
@@ -248,7 +247,7 @@
{
return type.getTypeParameters().length > 0;
}
-
+
public static Object invokeAndWrap(Method method, Object instance, Object...
parameters)
{
try
@@ -268,7 +267,7 @@
throw new ExecutionException("Error invoking method " +
method.getName() + " on " + method.getDeclaringClass(), e);
}
}
-
+
public static void setAndWrap(Field field, Object target, Object value)
{
try
@@ -284,33 +283,44 @@
throw new ExecutionException("Error setting field " + field.getName()
+ " on " + field.getDeclaringClass(), e);
}
}
-
+
public static Method lookupMethod(Method method, Object instance)
{
for (Class<? extends Object> clazz = instance.getClass(); clazz !=
Object.class; clazz = clazz.getSuperclass())
{
try
{
- Method targetMethod = clazz.getDeclaredMethod(method.getName(),
- method.getParameterTypes());
+ Method targetMethod = clazz.getDeclaredMethod(method.getName(),
method.getParameterTypes());
if (!targetMethod.isAccessible())
{
targetMethod.setAccessible(true);
}
return targetMethod;
- } catch (NoSuchMethodException nsme)
+ }
+ catch (NoSuchMethodException nsme)
{
// Expected, nothing to see here.
}
}
throw new IllegalArgumentException("Method " + method.getName() + "
not implemented by instance");
- }
-
- public static boolean isProxy(Object instance)
+ }
+
+ public static boolean isProxy(Object instance)
{
return instance.getClass().getName().indexOf("_$$_javassist_") > 0;
}
-
+
+ /**
+ * Gets the type hierarchy for a class
+ *
+ * A recursive function that adds the class to the set of type and then calls
+ * itself with the suprerclass as paramater until the top of the hierarchy is
+ * reached. For each steps, adds all interfaces of the class to the set.
+ * Since the data structure is a set, duplications are eliminated
+ *
+ * @param clazz The class to examine
+ * @return The set of classes and interfaces in the hierarchy
+ */
public static Set<Class<?>> getTypeHierachy(Class<?> clazz)
{
Set<Class<?>> classes = new HashSet<Class<?>>();
@@ -324,6 +334,6 @@
}
}
return classes;
- }
-
+ }
+
}