Skip to content

Commit

Permalink
Use some of these new-fangled ideas like generics
Browse files Browse the repository at this point in the history
  • Loading branch information
pmuir committed Jan 18, 2010
1 parent e5e6038 commit 39a44b4
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 91 deletions.
2 changes: 1 addition & 1 deletion impl/src/main/java/org/jboss/weld/bean/DisposalMethod.java
Expand Up @@ -213,7 +213,7 @@ private void checkDisposalMethod()
if (type instanceof Class<?>)
{
Class<?> clazz = (Class<?>) type;
if (SecureReflections.methodExists(clazz, disposalMethodInjectionPoint.getName(), disposalMethodInjectionPoint.getParameterTypesAsArray()))
if (SecureReflections.isMethodExists(clazz, disposalMethodInjectionPoint.getName(), disposalMethodInjectionPoint.getParameterTypesAsArray()))
{
methodDeclaredOnTypes = true;
continue;
Expand Down
2 changes: 1 addition & 1 deletion impl/src/main/java/org/jboss/weld/bean/ProducerMethod.java
Expand Up @@ -162,7 +162,7 @@ else if (getDeclaringBean() instanceof SessionBean<?>)
{
if (type instanceof Class<?>)
{
if (SecureReflections.methodExists((Class<?>) type, getWeldAnnotated().getName(), getWeldAnnotated().getParameterTypesAsArray()))
if (SecureReflections.isMethodExists((Class<?>) type, getWeldAnnotated().getName(), getWeldAnnotated().getParameterTypesAsArray()))
{
methodDeclaredOnTypes = true;
continue;
Expand Down
Expand Up @@ -48,7 +48,7 @@ public InterceptionHandler createFor(Class<T> clazz)
{
// this is not a managed instance - assume no-argument constructor exists
Constructor<T> constructor = (Constructor<T>) SecureReflections.getDeclaredConstructor(clazz);
T interceptorInstance = SecureReflections.ensureConstructorAccessible(constructor).newInstance();
T interceptorInstance = SecureReflections.ensureAccessible(constructor).newInstance();
// inject
manager.createInjectionTarget(manager.createAnnotatedType(clazz)).inject(interceptorInstance, creationalContext);
return new DirectClassInterceptionHandler<T>(interceptorInstance, clazz);
Expand Down
Expand Up @@ -239,7 +239,7 @@ public List<WeldParameter<?, T>> getWeldParameters(Class<? extends Annotation> a
*/
public T newInstance(Object... parameters) throws IllegalArgumentException, InstantiationException, IllegalAccessException, InvocationTargetException
{
return SecureReflections.ensureConstructorAccessible(getDelegate()).newInstance(parameters);
return SecureReflections.ensureAccessible(getDelegate()).newInstance(parameters);
}

/**
Expand Down
Expand Up @@ -91,7 +91,7 @@ public Field getDelegate()

public void set(Object instance, Object value) throws IllegalArgumentException, IllegalAccessException
{
SecureReflections.ensureFieldAccessible(field).set(instance, value);
SecureReflections.ensureAccessible(field).set(instance, value);
}

public void setOnInstance(Object instance, Object value) throws IllegalArgumentException, SecurityException, IllegalAccessException, NoSuchFieldException
Expand All @@ -104,7 +104,7 @@ public T get(Object instance)
{
try
{
return (T) SecureReflections.ensureFieldAccessible(getDelegate()).get(instance);
return (T) SecureReflections.ensureAccessible(getDelegate()).get(instance);
}
catch (Exception e)
{
Expand Down
Expand Up @@ -46,7 +46,7 @@ public JsfApiAbstraction(ResourceLoader resourceLoader)
double version = 2.0;
if (this.FACES_CONTEXT != null)
{
version = SecureReflections.methodExists(FACES_CONTEXT, "isPostback") ? 2.0 : 1.2;
version = SecureReflections.isMethodExists(FACES_CONTEXT, "isPostback") ? 2.0 : 1.2;
}
MINIMUM_API_VERSION = version;
}
Expand Down
Expand Up @@ -23,15 +23,15 @@
* Helper class for doing work in a privileged context under the
* "weld.reflection" permission
*/
abstract class SecureReflectionAccess
abstract class SecureReflectionAccess<T>
{
/**
* Performs the work and returns the result
*
* @return The value of the operation
* @throws Exception If the operation failed
*/
public Object run() throws Exception
public T run() throws Exception
{
// SecurityManager securityManager = System.getSecurityManager();
// if (securityManager != null)
Expand Down Expand Up @@ -60,7 +60,7 @@ public Object run() throws Exception
*
* @return The result of the work
*/
public Object runAndWrap()
public T runAndWrap()
{
try
{
Expand All @@ -80,7 +80,7 @@ public Object runAndWrap()
* @throws NoSuchFieldException If a field with the specified name is not
* found.
*/
public Object runAsFieldAccess() throws NoSuchFieldException
public T runAsFieldAccess() throws NoSuchFieldException
{
try
{
Expand Down Expand Up @@ -112,7 +112,7 @@ public Object runAsFieldAccess() throws NoSuchFieldException
* @throws NoSuchMethodException If a method with the specified name is not
* found.
*/
public Object runAsMethodAccess() throws NoSuchMethodException
public T runAsMethodAccess() throws NoSuchMethodException
{
try
{
Expand Down Expand Up @@ -156,7 +156,7 @@ public Object runAsMethodAccess() throws NoSuchMethodException
* @throws InvocationTargetException I the underlying method throws an
* exception.
*/
public Object runAsInvocation() throws IllegalAccessException, IllegalArgumentException, InvocationTargetException
public T runAsInvocation() throws IllegalAccessException, IllegalArgumentException, InvocationTargetException
{
try
{
Expand All @@ -180,15 +180,15 @@ else if (e.getCause() instanceof InvocationTargetException)
}
catch (IllegalAccessException e)
{
throw (IllegalAccessException) e;
throw e;
}
catch (IllegalArgumentException e)
{
throw (IllegalArgumentException) e;
throw e;
}
catch (InvocationTargetException e)
{
throw (InvocationTargetException) e;
throw e;
}
catch (Exception e)
{
Expand All @@ -209,7 +209,7 @@ else if (e.getCause() instanceof InvocationTargetException)
* the class has no nullary constructor; or if the instantiation
* fails for some other reason.
*/
public Object runAsInstantiation() throws InstantiationException, IllegalAccessException
public T runAsInstantiation() throws InstantiationException, IllegalAccessException
{
try
{
Expand All @@ -229,18 +229,18 @@ else if (e.getCause() instanceof IllegalAccessException)
}
catch (InstantiationException e)
{
throw (InstantiationException) e;
throw e;
}
catch (IllegalAccessException e)
{
throw (IllegalAccessException) e;
throw e;
}
catch (Exception e)
{
throw new RuntimeException(e);
}
}

protected abstract Object work() throws Exception;
protected abstract T work() throws Exception;

}

0 comments on commit 39a44b4

Please sign in to comment.