Skip to content

Commit

Permalink
WBRI-105 and tidy up simple bean a bit
Browse files Browse the repository at this point in the history
git-svn-id: http://anonsvn.jboss.org/repos/weld/ri/trunk@1100 1c488680-804c-0410-94cd-c6b725194a0e
  • Loading branch information
pmuir committed Jan 19, 2009
1 parent 61115f4 commit a2f44ec
Show file tree
Hide file tree
Showing 10 changed files with 85 additions and 5 deletions.
22 changes: 19 additions & 3 deletions webbeans-ri/src/main/java/org/jboss/webbeans/bean/SimpleBean.java
Expand Up @@ -305,13 +305,13 @@ protected void initInjectionPoints()
/**
* Validates the type
*/
private void checkType()
protected void checkType()
{
if (Reflections.isNonStaticInnerClass(type))
if (getAnnotatedItem().isNonStaticMemberClass())
{
throw new DefinitionException("Simple Web Bean " + type + " cannot be a non-static inner class");
}
if (Reflections.isParameterizedType(type))
if (getAnnotatedItem().isParameterizedType())
{
throw new DefinitionException("Simple Web Bean " + type + " cannot be a parameterized type");
}
Expand All @@ -321,6 +321,22 @@ private void checkType()
throw new DefinitionException("Simple Web Beans declaring a passivating scope must have a serializable implementation class");
}
}

@Override
protected void checkBeanImplementation()
{
super.checkBeanImplementation();
if (!scopeType.equals(Dependent.class))
{
for (AnnotatedField<?> field : getAnnotatedItem().getFields())
{
if (field.isPublic() && !field.isStatic())
{
throw new DefinitionException("Normal scoped Web Bean implementation class has a public field " + getAnnotatedItem());
}
}
}
}

/**
* Initializes the constructor
Expand Down
Expand Up @@ -142,5 +142,14 @@ public interface AnnotatedClass<T> extends AnnotatedType<T>
* @return The abstracted superclass, null if there is no superclass
*/
public AnnotatedClass<?> getSuperclass();

/**
* Determine if this is a non-static member class
*
* @return true if this is a non-static member
*/
public boolean isNonStaticMemberClass();

public boolean isParameterizedType();

}
Expand Up @@ -166,6 +166,13 @@ public interface AnnotatedItem<T, S>
* @return True if proxyable, false otherwise
*/
public boolean isProxyable();

/**
* Indicates if this annotated item is public
*
* @return if public, returns true
*/
public boolean isPublic();

/**
* Gets the name of this AnnotatedItem
Expand Down
Expand Up @@ -151,6 +151,11 @@ public boolean isProxyable()
{
return delegate().isProxyable();
}

public boolean isPublic()
{
return delegate().isPublic();
}

/**
* Overridden method into delegate
Expand Down
Expand Up @@ -19,6 +19,7 @@

import java.lang.annotation.Annotation;
import java.lang.reflect.Member;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
Expand Down Expand Up @@ -98,6 +99,8 @@ public List<AnnotatedParameter<?>> get(Object key)

// Cached string representation
private String toString;

private final boolean _public;

/**
* Constructor
Expand All @@ -108,6 +111,7 @@ public AbstractAnnotatedMember(AnnotationMap annotationMap, AnnotationMap declar
{
super(annotationMap, declaredAnnotationMap);
name = member.getName();
_public = Modifier.isPublic(member.getModifiers());
}

/**
Expand Down Expand Up @@ -138,6 +142,11 @@ public boolean isTransient()
{
return Reflections.isTransient(getDelegate());
}

public boolean isPublic()
{
return _public;
}

/**
* Gets the current value of the member
Expand Down
Expand Up @@ -17,6 +17,8 @@

package org.jboss.webbeans.introspector.jlr;

import java.lang.reflect.Modifier;

import org.jboss.webbeans.introspector.AnnotatedClass;
import org.jboss.webbeans.util.Reflections;

Expand All @@ -38,6 +40,7 @@ public abstract class AbstractAnnotatedType<T> extends AbstractAnnotatedItem<T,

// Cached string representation
private String toString;
private final boolean _public;

/**
* Constructor
Expand All @@ -56,6 +59,7 @@ public AbstractAnnotatedType(AnnotationMap annotationMap, AnnotationMap declared
{
this.superclass = null;
}
this._public = Modifier.isFinal(type.getModifiers());
}

public AbstractAnnotatedType(AnnotationMap annotationMap, Class<T> type)
Expand Down Expand Up @@ -86,6 +90,11 @@ public boolean isFinal()
{
return Reflections.isFinal(getDelegate());
}

public boolean isPublic()
{
return _public;
}

/**
* Gets the name of the type
Expand Down
Expand Up @@ -38,6 +38,7 @@
import org.jboss.webbeans.introspector.AnnotatedField;
import org.jboss.webbeans.introspector.AnnotatedMethod;
import org.jboss.webbeans.util.Names;
import org.jboss.webbeans.util.Reflections;
import org.jboss.webbeans.util.Strings;

import com.google.common.collect.ForwardingMap;
Expand Down Expand Up @@ -255,6 +256,9 @@ public String toString()
// Cached string representation
private String toString;

private final boolean _nonStaticMemberClass;
private final boolean _parameterizedType;

public static <T> AnnotatedClass<T> of(Class<T> clazz)
{
return new AnnotatedClassImpl<T>(clazz, clazz, clazz.getAnnotations(), clazz.getDeclaredAnnotations());
Expand Down Expand Up @@ -293,6 +297,8 @@ private AnnotatedClassImpl(Class<T> rawType, Type type, Annotation[] annotations
this.declaredFields = new HashSet<AnnotatedField<?>>();
this.declaredAnnotatedFields = new AnnotatedFieldMap();
this.declaredMetaAnnotatedFields = new AnnotatedFieldMap();
this._nonStaticMemberClass = Reflections.isNonMemberInnerClass(rawType);
this._parameterizedType = Reflections.isParameterizedType(rawType);
for (Class<?> c = clazz; c != Object.class && c != null; c = c.getSuperclass())
{
for (Field field : c.getDeclaredFields())
Expand Down Expand Up @@ -493,6 +499,16 @@ public Class<T> getType()
return clazz;
}

public boolean isNonStaticMemberClass()
{
return _nonStaticMemberClass;
}

public boolean isParameterizedType()
{
return _parameterizedType;
}

/**
* Gets the actual type arguments
*
Expand Down
Expand Up @@ -45,6 +45,7 @@ public class AnnotatedParameterImpl<T> extends AbstractAnnotatedItem<T, Object>
private final boolean _final = false;
// The static state
private final boolean _static = false;
private final boolean _public = false;
private final AnnotatedMember<?, ?> declaringMember;

// Cached string representation
Expand Down Expand Up @@ -127,6 +128,11 @@ public boolean isStatic()
{
return _static;
}

public boolean isPublic()
{
return _public;
}

/**
* Gets the current value
Expand Down
Expand Up @@ -197,7 +197,7 @@ public static boolean isStaticInnerClass(Class<?> clazz)
* @param clazz Class to Check
* @return True if static, false otherwise
*/
public static boolean isNonStaticInnerClass(Class<?> clazz)
public static boolean isNonMemberInnerClass(Class<?> clazz)
{
return clazz.isMemberClass() && !isStatic(clazz);
}
Expand Down
Expand Up @@ -10,6 +10,7 @@
import org.jboss.webbeans.bean.EnterpriseBean;
import org.jboss.webbeans.bean.ProducerMethodBean;
import org.jboss.webbeans.bean.SimpleBean;
import org.jboss.webbeans.test.mock.MockBootstrap;
import org.jboss.webbeans.test.unit.AbstractTest;
import org.testng.annotations.Test;

Expand Down Expand Up @@ -201,7 +202,9 @@ public void testRegisterMultipleEnterpriseAndSimpleBean()
@Test(groups="bootstrap", expectedExceptions=IllegalStateException.class)
public void testDiscoverFails()
{
deployBeans();
MockBootstrap bootstrap = new MockBootstrap();
bootstrap.setWebBeanDiscovery(null);
bootstrap.boot();
}

@Test(groups="bootstrap")
Expand Down

0 comments on commit a2f44ec

Please sign in to comment.