Author: richard.opalka(a)jboss.com
Date: 2009-05-05 07:58:55 -0400 (Tue, 05 May 2009)
New Revision: 9956
Added:
common/trunk/src/main/java/org/jboss/wsf/common/injection/
common/trunk/src/main/java/org/jboss/wsf/common/injection/InjectionException.java
common/trunk/src/main/java/org/jboss/wsf/common/injection/InjectionHelper.java
common/trunk/src/main/java/org/jboss/wsf/common/injection/PreDestroyHolder.java
common/trunk/src/main/java/org/jboss/wsf/common/injection/finders/
common/trunk/src/main/java/org/jboss/wsf/common/injection/finders/AbstractPostConstructPreDestroyAnnotatedMethodFinder.java
common/trunk/src/main/java/org/jboss/wsf/common/injection/finders/EJBFieldFinder.java
common/trunk/src/main/java/org/jboss/wsf/common/injection/finders/EJBMethodFinder.java
common/trunk/src/main/java/org/jboss/wsf/common/injection/finders/InjectionFieldFinder.java
common/trunk/src/main/java/org/jboss/wsf/common/injection/finders/InjectionMethodFinder.java
common/trunk/src/main/java/org/jboss/wsf/common/injection/finders/PostConstructMethodFinder.java
common/trunk/src/main/java/org/jboss/wsf/common/injection/finders/PreDestroyMethodFinder.java
common/trunk/src/main/java/org/jboss/wsf/common/injection/finders/ReflectionUtils.java
common/trunk/src/main/java/org/jboss/wsf/common/injection/finders/ResourceFieldFinder.java
common/trunk/src/main/java/org/jboss/wsf/common/injection/finders/ResourceMethodFinder.java
common/trunk/src/main/java/org/jboss/wsf/common/injection/resolvers/
common/trunk/src/main/java/org/jboss/wsf/common/injection/resolvers/AbstractReferenceResolver.java
common/trunk/src/main/java/org/jboss/wsf/common/injection/resolvers/ResourceReferenceResolver.java
Removed:
common/trunk/src/main/java/org/jboss/wsf/common/javax/
Log:
[JBWS-2074][JBWS-2634] refactoring momma
Added: common/trunk/src/main/java/org/jboss/wsf/common/injection/InjectionException.java
===================================================================
--- common/trunk/src/main/java/org/jboss/wsf/common/injection/InjectionException.java
(rev 0)
+++
common/trunk/src/main/java/org/jboss/wsf/common/injection/InjectionException.java 2009-05-05
11:58:55 UTC (rev 9956)
@@ -0,0 +1,109 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.wsf.common.injection;
+
+import org.jboss.logging.Logger;
+
+/**
+ * Represents generic injection error.
+ *
+ * @author <a href="mailto:richard.opalka@jboss.org">Richard
Opalka</a>
+ */
+public class InjectionException extends RuntimeException
+{
+
+ /**
+ * Serial version UID.
+ */
+ private static final long serialVersionUID = 1L;
+ /**
+ * Logger.
+ */
+ private static final Logger LOG = Logger.getLogger(InjectionException.class);
+
+ /**
+ * Constructor.
+ */
+ public InjectionException()
+ {
+ super();
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param message
+ */
+ public InjectionException(String message)
+ {
+ super(message);
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param cause
+ */
+ public InjectionException(Throwable cause)
+ {
+ super(cause);
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param message
+ * @param cause
+ */
+ public InjectionException(String message, Throwable cause)
+ {
+ super(message, cause);
+ }
+
+ /**
+ * Rethrows Injection exception that will wrap passed reason.
+ *
+ * @param reason to wrap.
+ */
+ public static void rethrow(final Exception reason)
+ {
+ rethrow(null, reason);
+ }
+
+ /**
+ * Rethrows Injection exception that will wrap passed reason.
+ *
+ * @param message custom message
+ * @param reason to wrap.
+ */
+ public static void rethrow(final String message, final Exception reason)
+ {
+ if (reason == null)
+ {
+ throw new IllegalArgumentException("Reason expected");
+ }
+
+ LOG.error(message == null ? reason.getMessage() : message, reason);
+ throw new InjectionException(message, reason);
+ }
+
+}
Added: common/trunk/src/main/java/org/jboss/wsf/common/injection/InjectionHelper.java
===================================================================
--- common/trunk/src/main/java/org/jboss/wsf/common/injection/InjectionHelper.java
(rev 0)
+++
common/trunk/src/main/java/org/jboss/wsf/common/injection/InjectionHelper.java 2009-05-05
11:58:55 UTC (rev 9956)
@@ -0,0 +1,522 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.wsf.common.injection;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.util.Collection;
+
+import javax.annotation.Resource;
+import javax.ejb.EJB;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import javax.xml.ws.WebServiceContext;
+
+import org.jboss.logging.Logger;
+import org.jboss.wsf.common.injection.finders.EJBFieldFinder;
+import org.jboss.wsf.common.injection.finders.EJBMethodFinder;
+import org.jboss.wsf.common.injection.finders.InjectionFieldFinder;
+import org.jboss.wsf.common.injection.finders.InjectionMethodFinder;
+import org.jboss.wsf.common.injection.finders.PostConstructMethodFinder;
+import org.jboss.wsf.common.injection.finders.PreDestroyMethodFinder;
+import org.jboss.wsf.common.injection.finders.ResourceFieldFinder;
+import org.jboss.wsf.common.injection.finders.ResourceMethodFinder;
+import org.jboss.wsf.common.reflection.ClassProcessor;
+import org.jboss.wsf.spi.metadata.injection.InjectionMetaData;
+import org.jboss.wsf.spi.metadata.injection.InjectionsMetaData;
+import org.jboss.wsf.spi.metadata.injection.ReferenceResolver;
+
+/**
+ * An injection helper class for <b>javax.*</b> annotations.
+ *
+ * @author <a href="mailto:richard.opalka@jboss.org">Richard
Opalka</a>
+ */
+public final class InjectionHelper
+{
+
+ private static final Logger LOG = Logger.getLogger(InjectionHelper.class);
+ private static final String POJO_JNDI_PREFIX = "java:comp/env/";
+
+ private static final ClassProcessor<Method> POST_CONSTRUCT_METHOD_FINDER = new
PostConstructMethodFinder();
+ private static final ClassProcessor<Method> PRE_DESTROY_METHOD_FINDER = new
PreDestroyMethodFinder();
+ private static final ClassProcessor<Method> RESOURCE_METHOD_FINDER = new
ResourceMethodFinder(WebServiceContext.class, false);
+ private static final ClassProcessor<Field> RESOURCE_FIELD_FINDER = new
ResourceFieldFinder(WebServiceContext.class, false);
+ private static final ClassProcessor<Method> EJB_METHOD_FINDER = new
EJBMethodFinder();
+ private static final ClassProcessor<Field> EJB_FIELD_FINDER = new
EJBFieldFinder();
+ private static final ClassProcessor<Method> WEB_SERVICE_CONTEXT_METHOD_FINDER =
new ResourceMethodFinder(WebServiceContext.class, true);
+ private static final ClassProcessor<Field> WEB_SERVICE_CONTEXT_FIELD_FINDER =
new ResourceFieldFinder(WebServiceContext.class, true);
+
+ /**
+ * Forbidden constructor.
+ */
+ private InjectionHelper()
+ {
+ super();
+ }
+
+ /**
+ * The resource annotations mark resources that are needed by the application. These
annotations may be applied
+ * to an application component class, or to fields or methods of the component class.
When the annotation is
+ * applied to a field or method, the container will inject an instance of the
requested resource into the
+ * application component when the component is initialized. If the annotation is
applied to the component class,
+ * the annotation declares a resource that the application will look up at runtime.
+ *
+ * This method handles the following injection types:
+ * <ul>
+ * <li>Descriptor specified injections</li>
+ * <li>@Resource annotated methods and fields</li>
+ * <li>@EJB annotated methods and fields</li>
+ * </ul>
+ *
+ * @param instance to inject resources on
+ * @param injections injections metadata
+ * @see javax.annotation.Resource
+ * @see javax.ejb.EJB
+ */
+ public static void injectResources(final Object instance, final InjectionsMetaData
injections)
+ {
+ if (instance == null)
+ throw new IllegalArgumentException("Object instance cannot be null");
+
+ if (injections == null)
+ return;
+
+ final Context ctx = getContext(injections);
+
+ // inject descriptor driven annotations
+ final Collection<InjectionMetaData> injectionMDs =
injections.getInjectionsMetaData(instance.getClass());
+ for (InjectionMetaData injectionMD : injectionMDs)
+ {
+ injectDescriptorAnnotatedAccessibleObjects(instance, ctx, injectionMD);
+ }
+
+ // inject @Resource annotated methods and fields
+ injectResourceAnnotatedAccessibleObjects(instance, ctx, injections);
+
+ // inject @EJB annotated methods and fields
+ injectEJBAnnotatedAccessibleObjects(instance, ctx, injections);
+ }
+
+ /**
+ * Injects @Resource annotated accessible objects referencing WebServiceContext.
+ *
+ * @param instance to operate on
+ * @param ctx current web service context
+ */
+ public static void injectWebServiceContext(final Object instance, final
WebServiceContext ctx)
+ {
+ final Class<?> instanceClass = instance.getClass();
+
+ // inject @Resource annotated methods accepting WebServiceContext parameter
+ Collection<Method> resourceAnnotatedMethods =
WEB_SERVICE_CONTEXT_METHOD_FINDER.process(instanceClass);
+ for(Method method : resourceAnnotatedMethods)
+ {
+ try
+ {
+ invokeMethod(instance, method, new Object[] {ctx});
+ }
+ catch (Exception e)
+ {
+ final String message = "Cannot inject @Resource annotated method: "
+ method;
+ InjectionException.rethrow(message, e);
+ }
+ }
+
+ // inject @Resource annotated fields of WebServiceContext type
+ final Collection<Field> resourceAnnotatedFields =
WEB_SERVICE_CONTEXT_FIELD_FINDER.process(instanceClass);
+ for (Field field : resourceAnnotatedFields)
+ {
+ try
+ {
+ setField(instance, field, ctx);
+ }
+ catch (Exception e)
+ {
+ final String message = "Cannot inject @Resource annotated field: "
+ field;
+ InjectionException.rethrow(message, e);
+ }
+ }
+ }
+
+ /**
+ * Calls @PostConstruct annotated method if exists.
+ *
+ * @param instance to invoke @PostConstruct annotated method on
+ * @see org.jboss.wsf.common.injection.finders.PostConstructMethodFinder
+ * @see javax.annotation.PostConstruct
+ */
+ public static void callPostConstructMethod(final Object instance)
+ {
+ if (instance == null)
+ throw new IllegalArgumentException("Object instance cannot be null");
+
+ Collection<Method> methods =
POST_CONSTRUCT_METHOD_FINDER.process(instance.getClass());
+
+ if (methods.size() > 0)
+ {
+ Method method = methods.iterator().next();
+ LOG.debug("Calling @PostConstruct annotated method: " + method);
+ try
+ {
+ invokeMethod(instance, method, null);
+ }
+ catch (Exception e)
+ {
+ final String message = "Calling of @PostConstruct annotated method
failed: " + method;
+ InjectionException.rethrow(message, e);
+ }
+ }
+ }
+
+ /**
+ * Calls @PreDestroy annotated method if exists.
+ *
+ * @param instance to invoke @PreDestroy annotated method on
+ * @see org.jboss.wsf.common.injection.finders.PreDestroyMethodFinder
+ * @see javax.annotation.PreDestroy
+ */
+ public static void callPreDestroyMethod(final Object instance)
+ {
+ if (instance == null)
+ throw new IllegalArgumentException("Object instance cannot be null");
+
+ Collection<Method> methods =
PRE_DESTROY_METHOD_FINDER.process(instance.getClass());
+
+ if (methods.size() > 0)
+ {
+ Method method = methods.iterator().next();
+ LOG.debug("Calling @PreDestroy annotated method: " + method);
+ try
+ {
+ invokeMethod(instance, method, null);
+ }
+ catch (Exception e)
+ {
+ final String message = "Calling of @PreDestroy annotated method failed:
" + method;
+ InjectionException.rethrow(message, e);
+ }
+ }
+ }
+
+ /**
+ * Gets JNDI context.
+ *
+ * @param injections injection metadata to get context from.
+ * @return JNDI context
+ */
+ private static Context getContext(final InjectionsMetaData injections)
+ {
+ final Context ctx = injections.getContext();
+ if (ctx == null)
+ {
+ try
+ {
+ return (Context)new InitialContext().lookup(POJO_JNDI_PREFIX);
+ }
+ catch (NamingException ne)
+ {
+ InjectionException.rethrow("Cannot lookup JNDI context: " +
POJO_JNDI_PREFIX, ne);
+ }
+ }
+
+ return ctx;
+ }
+
+ /**
+ * Performs descriptor driven injections.
+ *
+ * @param instance to operate on
+ * @param ctx JNDI context
+ * @param injectionMD injections metadata
+ */
+ private static void injectDescriptorAnnotatedAccessibleObjects(final Object instance,
final Context ctx, final InjectionMetaData injectionMD)
+ {
+ final Method method = getMethod(injectionMD, instance.getClass());
+ if (method != null)
+ {
+ try
+ {
+ inject(instance, method, injectionMD.getEnvEntryName(), ctx);
+ }
+ catch (Exception e)
+ {
+ final String message = "Cannot inject method (descriptor driven
injection): " + injectionMD;
+ InjectionException.rethrow(message, e);
+ }
+ }
+ else
+ {
+ final Field field = getField(injectionMD, instance.getClass());
+ if (field != null)
+ {
+ try
+ {
+ inject(instance, field, injectionMD.getEnvEntryName(), ctx);
+ }
+ catch (Exception e)
+ {
+ final String message = "Cannot inject field (descriptor driven
injection): " + injectionMD;
+ InjectionException.rethrow(message, e);
+ }
+ }
+ else
+ {
+ final String message = "Cannot find injection target for: " +
injectionMD;
+ throw new InjectionException(message);
+ }
+ }
+ }
+
+ /**
+ * Injects @Resource annotated accessible objects.
+ *
+ * @param instance to operate on
+ * @param ctx JNDI context
+ * @param injections injections meta data
+ */
+ private static void injectResourceAnnotatedAccessibleObjects(final Object instance,
final Context ctx, final InjectionsMetaData injections)
+ {
+ final ReferenceResolver referenceResolver =
injections.getResolver(Resource.class);
+
+ // Inject @Resource annotated fields
+ final Collection<Field> resourceAnnotatedFields =
RESOURCE_FIELD_FINDER.process(instance.getClass());
+ for (Field field : resourceAnnotatedFields)
+ {
+ try
+ {
+ final String jndiName = referenceResolver.resolve(field);
+ inject(instance, field, jndiName, ctx);
+ }
+ catch (Exception e)
+ {
+ final String message = "Cannot inject field annotated with @Resource
annotation: " + field;
+ InjectionException.rethrow(message, e);
+ }
+ }
+
+ // Inject @Resource annotated methods
+ final Collection<Method> resourceAnnotatedMethods =
RESOURCE_METHOD_FINDER.process(instance.getClass());
+ for(Method method : resourceAnnotatedMethods)
+ {
+ try
+ {
+ final String jndiName = referenceResolver.resolve(method);
+ inject(instance, method, jndiName, ctx);
+ }
+ catch (Exception e)
+ {
+ final String message = "Cannot inject method annotated with @Resource
annotation: " + method;
+ InjectionException.rethrow(message, e);
+ }
+ }
+ }
+
+ /**
+ * Injects @EJB annotated accessible objects.
+ *
+ * @param instance to operate on
+ * @param ctx JNDI context
+ * @param injections injections meta data
+ */
+ private static void injectEJBAnnotatedAccessibleObjects(final Object instance, final
Context ctx, final InjectionsMetaData injections)
+ {
+ final ReferenceResolver referenceResolver = injections.getResolver(EJB.class);
+
+ // Inject @EJB annotated fields
+ final Collection<Field> ejbAnnotatedFields =
EJB_FIELD_FINDER.process(instance.getClass());
+ for (Field field : ejbAnnotatedFields)
+ {
+ try
+ {
+ final String jndiName = referenceResolver.resolve(field);
+ inject(instance, field, jndiName, ctx);
+ }
+ catch (Exception e)
+ {
+ final String message = "Cannot inject field annotated with @EJB
annotation: " + field;
+ InjectionException.rethrow(message, e);
+ }
+ }
+
+ // Inject @EJB annotated methods
+ final Collection<Method> ejbAnnotatedMethods =
EJB_METHOD_FINDER.process(instance.getClass());
+ for(Method method : ejbAnnotatedMethods)
+ {
+ try
+ {
+ final String jndiName = referenceResolver.resolve(method);
+ inject(instance, method, jndiName, ctx);
+ }
+ catch (Exception e)
+ {
+ final String message = "Cannot inject method annotated with @EJB
annotation: " + method;
+ InjectionException.rethrow(message, e);
+ }
+ }
+ }
+
+ /**
+ * Injects @Resource annotated method.
+ *
+ * @param instance to invoke method on
+ * @param method to invoke
+ * @param resourceName resource name
+ * @param cxt JNDI context
+ * @see org.jboss.wsf.common.injection.finders.ResourceMethodFinder
+ */
+ private static void inject(final Object instance, final Method method, final String
jndiName, final Context ctx)
+ {
+ final Object value = lookup(jndiName, ctx);
+ LOG.debug("Injecting method: " + method);
+ invokeMethod(instance, method, new Object[] {value});
+ }
+
+ /**
+ * Injects @Resource annotated field.
+ *
+ * @param field to set
+ * @param instance to modify field on
+ * @param resourceName resource name
+ * @param cxt JNDI context
+ * @see org.jboss.wsf.common.injection.finders.ResourceFieldFinder
+ */
+ private static void inject(final Object instance, final Field field, final String
jndiName, final Context ctx)
+ {
+ final Object value = lookup(jndiName, ctx);
+ LOG.debug("Injecting field: " + field);
+ setField(instance, field, value);
+ }
+
+ /**
+ * Lookups object in JNDI namespace.
+ *
+ * @param jndiName jndi name
+ * @param ctx context to use
+ * @return Object if found
+ */
+ private static Object lookup(final String jndiName, final Context ctx)
+ {
+ Object value = null;
+ try
+ {
+ value = ctx.lookup(jndiName);
+ }
+ catch (NamingException ne)
+ {
+ try
+ {
+ value = new InitialContext().lookup(jndiName);
+ }
+ catch (Exception e)
+ {
+ final String message = "Resource '" + jndiName + "'
not found";
+ InjectionException.rethrow(message, e);
+ }
+ }
+
+ return value;
+ }
+
+ /**
+ * Invokes method on object with specified arguments.
+ *
+ * @param instance to invoke method on
+ * @param method method to invoke
+ * @param args arguments to pass
+ */
+ private static void invokeMethod(final Object instance, final Method method, final
Object[] args)
+ {
+ boolean accessability = method.isAccessible();
+
+ try
+ {
+ method.setAccessible(true);
+ method.invoke(instance, args);
+ }
+ catch (Exception e)
+ {
+ InjectionException.rethrow(e);
+ }
+ finally
+ {
+ method.setAccessible(accessability);
+ }
+ }
+
+ /**
+ * Sets field on object with specified value.
+ *
+ * @param instance to set field on
+ * @param field to set
+ * @param value to be set
+ */
+ private static void setField(final Object instance, final Field field, final Object
value)
+ {
+ boolean accessability = field.isAccessible();
+
+ try
+ {
+ field.setAccessible(true);
+ field.set(instance, value);
+ }
+ catch (Exception e)
+ {
+ InjectionException.rethrow(e);
+ }
+ finally
+ {
+ field.setAccessible(accessability);
+ }
+ }
+
+ /**
+ * Returns method that matches the descriptor injection metadata or null if not
found.
+ *
+ * @param injectionMD descriptor injection metadata
+ * @param clazz to process
+ * @return method that matches the criteria or null if not found
+ * @see org.jboss.wsf.common.injection.finders.InjectionMethodFinder
+ */
+ private static Method getMethod(final InjectionMetaData injectionMD, final
Class<?> clazz)
+ {
+ final Collection<Method> result = new
InjectionMethodFinder(injectionMD).process(clazz);
+
+ return result.isEmpty() ? null : result.iterator().next();
+ }
+
+ /**
+ * Returns field that matches the descriptor injection metadata or null if not found.
+ *
+ * @param injectionMD descriptor injection metadata
+ * @param clazz to process
+ * @return field that matches the criteria or null if not found
+ * @see org.jboss.wsf.common.injection.finders.InjectionFieldFinder
+ */
+ private static Field getField(final InjectionMetaData injectionMD, final
Class<?> clazz)
+ {
+ final Collection<Field> result = new
InjectionFieldFinder(injectionMD).process(clazz);
+
+ return result.isEmpty() ? null : result.iterator().next();
+ }
+
+}
Added: common/trunk/src/main/java/org/jboss/wsf/common/injection/PreDestroyHolder.java
===================================================================
--- common/trunk/src/main/java/org/jboss/wsf/common/injection/PreDestroyHolder.java
(rev 0)
+++
common/trunk/src/main/java/org/jboss/wsf/common/injection/PreDestroyHolder.java 2009-05-05
11:58:55 UTC (rev 9956)
@@ -0,0 +1,61 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.wsf.common.injection;
+
+/**
+ * Utility class for pre destroy registration.
+ *
+ * @author <a href="mailto:richard.opalka@jboss.org">Richard
Opalka</a>
+ */
+public final class PreDestroyHolder
+{
+ private final Object object;
+ private final int hashCode;
+
+ public PreDestroyHolder(Object object)
+ {
+ super();
+ this.hashCode = System.identityHashCode(object);
+ this.object = object;
+ }
+
+ public final Object getObject()
+ {
+ return this.object;
+ }
+
+ public final boolean equals(Object o)
+ {
+ if (o instanceof PreDestroyHolder)
+ {
+ return ((PreDestroyHolder)o).hashCode == this.hashCode;
+ }
+
+ return false;
+ }
+
+ public final int hashCode()
+ {
+ return this.hashCode;
+ }
+
+}
\ No newline at end of file
Added:
common/trunk/src/main/java/org/jboss/wsf/common/injection/finders/AbstractPostConstructPreDestroyAnnotatedMethodFinder.java
===================================================================
---
common/trunk/src/main/java/org/jboss/wsf/common/injection/finders/AbstractPostConstructPreDestroyAnnotatedMethodFinder.java
(rev 0)
+++
common/trunk/src/main/java/org/jboss/wsf/common/injection/finders/AbstractPostConstructPreDestroyAnnotatedMethodFinder.java 2009-05-05
11:58:55 UTC (rev 9956)
@@ -0,0 +1,71 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.wsf.common.injection.finders;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Method;
+import java.util.Collection;
+
+import org.jboss.wsf.common.reflection.AnnotatedMethodFinder;
+
+/**
+ * Abstract @PostConstruct and @PreDestroy annotations method finder.
+ *
+ * @author <a href="mailto:richard.opalka@jboss.org">Richard
Opalka</a>
+ */
+abstract class AbstractPostConstructPreDestroyAnnotatedMethodFinder<A extends
Annotation>
+extends AnnotatedMethodFinder<A>
+{
+
+ /**
+ * Constructor.
+ *
+ * @param annotationClass annotation.
+ */
+ AbstractPostConstructPreDestroyAnnotatedMethodFinder(final Class<A>
annotationClass)
+ {
+ super(annotationClass);
+ }
+
+ @Override
+ public void validate(final Collection<Method> methods)
+ {
+ super.validate(methods);
+
+ // Ensure all methods preconditions
+ ReflectionUtils.assertOnlyOneMethod(methods, getAnnotation());
+ }
+
+ @Override
+ public void validate(final Method method)
+ {
+ super.validate(method);
+
+ // Ensure all method preconditions
+ Class<A> annotation = getAnnotation();
+ ReflectionUtils.assertNoParameters(method, annotation);
+ ReflectionUtils.assertVoidReturnType(method, annotation);
+ ReflectionUtils.assertNoCheckedExceptionsAreThrown(method, annotation);
+ ReflectionUtils.assertNotStatic(method, annotation);
+ }
+
+}
Added:
common/trunk/src/main/java/org/jboss/wsf/common/injection/finders/EJBFieldFinder.java
===================================================================
--- common/trunk/src/main/java/org/jboss/wsf/common/injection/finders/EJBFieldFinder.java
(rev 0)
+++
common/trunk/src/main/java/org/jboss/wsf/common/injection/finders/EJBFieldFinder.java 2009-05-05
11:58:55 UTC (rev 9956)
@@ -0,0 +1,60 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.wsf.common.injection.finders;
+
+import java.lang.reflect.Field;
+
+import javax.ejb.EJB;
+
+import org.jboss.wsf.common.reflection.AnnotatedFieldFinder;
+
+/**
+ * Field based EJB injection.
+ *
+ * @author <a href="mailto:richard.opalka@jboss.org">Richard
Opalka</a>
+ */
+public final class EJBFieldFinder
+extends AnnotatedFieldFinder<EJB>
+{
+
+ /**
+ * Constructor.
+ */
+ public EJBFieldFinder()
+ {
+ super(EJB.class);
+ }
+
+ @Override
+ public void validate(Field field)
+ {
+ super.validate(field);
+
+ // Ensure all method preconditions
+ Class<EJB> annotation = getAnnotation();
+ ReflectionUtils.assertNotVoidType(field, annotation);
+ ReflectionUtils.assertNotStatic(field, annotation);
+ ReflectionUtils.assertNotFinal(field, annotation);
+ ReflectionUtils.assertNotPrimitiveType(field, annotation);
+ }
+
+}
Added:
common/trunk/src/main/java/org/jboss/wsf/common/injection/finders/EJBMethodFinder.java
===================================================================
---
common/trunk/src/main/java/org/jboss/wsf/common/injection/finders/EJBMethodFinder.java
(rev 0)
+++
common/trunk/src/main/java/org/jboss/wsf/common/injection/finders/EJBMethodFinder.java 2009-05-05
11:58:55 UTC (rev 9956)
@@ -0,0 +1,62 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.wsf.common.injection.finders;
+
+import java.lang.reflect.Method;
+
+import javax.ejb.EJB;
+
+import org.jboss.wsf.common.reflection.AnnotatedMethodFinder;
+
+/**
+ * Setter based EJB injection.
+ *
+ * @author <a href="mailto:richard.opalka@jboss.org">Richard
Opalka</a>
+ */
+public final class EJBMethodFinder
+extends AnnotatedMethodFinder<EJB>
+{
+
+ /**
+ * Constructor.
+ */
+ public EJBMethodFinder()
+ {
+ super(EJB.class);
+ }
+
+ @Override
+ public void validate(Method method)
+ {
+ super.validate(method);
+
+ // Ensure all method preconditions
+ Class<EJB> annotation = getAnnotation();
+ ReflectionUtils.assertVoidReturnType(method, annotation);
+ ReflectionUtils.assertOneParameter(method, annotation);
+ ReflectionUtils.assertNoPrimitiveParameters(method, annotation);
+ ReflectionUtils.assertValidSetterName(method, annotation);
+ ReflectionUtils.assertNoCheckedExceptionsAreThrown(method, annotation);
+ ReflectionUtils.assertNotStatic(method, annotation);
+ }
+
+}
Added:
common/trunk/src/main/java/org/jboss/wsf/common/injection/finders/InjectionFieldFinder.java
===================================================================
---
common/trunk/src/main/java/org/jboss/wsf/common/injection/finders/InjectionFieldFinder.java
(rev 0)
+++
common/trunk/src/main/java/org/jboss/wsf/common/injection/finders/InjectionFieldFinder.java 2009-05-05
11:58:55 UTC (rev 9956)
@@ -0,0 +1,101 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.wsf.common.injection.finders;
+
+import java.lang.reflect.Field;
+import java.util.Collection;
+
+import org.jboss.wsf.common.injection.InjectionException;
+import org.jboss.wsf.common.reflection.FieldFinder;
+import org.jboss.wsf.spi.metadata.injection.InjectionMetaData;
+
+/**
+ * Lookups field that matches descriptor specified injection metadata.
+ *
+ * @author <a href="mailto:richard.opalka@jboss.org">Richard
Opalka</a>
+ */
+public final class InjectionFieldFinder
+extends FieldFinder
+{
+
+ /**
+ * Descriptor injection metadata.
+ */
+ private final InjectionMetaData injectionMD;
+
+ /**
+ * Constructor.
+ *
+ * @param injectionMD descriptor injection metadata
+ */
+ public InjectionFieldFinder(final InjectionMetaData injectionMD)
+ {
+ if (injectionMD == null)
+ throw new IllegalArgumentException("Injection metadata cannot be
null");
+
+ this.injectionMD = injectionMD;
+ }
+
+ @Override
+ public boolean matches(final Field field)
+ {
+ if (field.getName().equals(injectionMD.getTargetName()))
+ {
+ if (injectionMD.getValueClass() != null)
+ {
+ final Class<?> expectedClass = injectionMD.getValueClass();
+ final Class<?> fieldClass = field.getType();
+
+ return expectedClass.equals(fieldClass);
+ }
+ else
+ {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ @Override
+ public void validate(final Collection<Field> fields)
+ {
+ super.validate(fields);
+
+ if (fields.size() > 2)
+ {
+ throw new InjectionException("More than one field found matching the
criteria: " + injectionMD);
+ }
+ }
+
+ @Override
+ public void validate(final Field field)
+ {
+ super.validate(field);
+
+ ReflectionUtils.assertNotVoidType(field);
+ ReflectionUtils.assertNotStatic(field);
+ ReflectionUtils.assertNotFinal(field);
+ ReflectionUtils.assertNotPrimitiveType(field);
+ }
+
+}
Added:
common/trunk/src/main/java/org/jboss/wsf/common/injection/finders/InjectionMethodFinder.java
===================================================================
---
common/trunk/src/main/java/org/jboss/wsf/common/injection/finders/InjectionMethodFinder.java
(rev 0)
+++
common/trunk/src/main/java/org/jboss/wsf/common/injection/finders/InjectionMethodFinder.java 2009-05-05
11:58:55 UTC (rev 9956)
@@ -0,0 +1,109 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.wsf.common.injection.finders;
+
+import java.lang.reflect.Method;
+import java.util.Collection;
+
+import org.jboss.wsf.common.injection.InjectionException;
+import org.jboss.wsf.common.reflection.MethodFinder;
+import org.jboss.wsf.spi.metadata.injection.InjectionMetaData;
+
+/**
+ * Lookups method that matches descriptor specified injection metadata.
+ *
+ * @author <a href="mailto:richard.opalka@jboss.org">Richard
Opalka</a>
+ */
+public final class InjectionMethodFinder
+extends MethodFinder
+{
+
+ /**
+ * Descriptor injection metadata.
+ */
+ private final InjectionMetaData injectionMD;
+
+ /**
+ * Constructor.
+ *
+ * @param injectionMD descriptor injection metadata
+ */
+ public InjectionMethodFinder(final InjectionMetaData injectionMD)
+ {
+ if (injectionMD == null)
+ throw new IllegalArgumentException("Injection metadata cannot be
null");
+
+ this.injectionMD = injectionMD;
+ }
+
+ @Override
+ public boolean matches(final Method method)
+ {
+ if (method.getName().equals(injectionMD.getTargetName()))
+ {
+ if (injectionMD.getValueClass() != null)
+ {
+ if (method.getParameterTypes().length == 1)
+ {
+ final Class<?> expectedClass = injectionMD.getValueClass();
+ final Class<?> parameterClass = method.getParameterTypes()[0];
+
+ return expectedClass.equals(parameterClass);
+ }
+ }
+ else
+ {
+ if (method.getParameterTypes().length == 1)
+ {
+ return true;
+ }
+ }
+ }
+
+ return false;
+ }
+
+ @Override
+ public void validate(final Collection<Method> methods)
+ {
+ super.validate(methods);
+
+ if (methods.size() > 2)
+ {
+ throw new InjectionException("More than one method found matching the
criteria: " + injectionMD);
+ }
+ }
+
+ @Override
+ public void validate(final Method method)
+ {
+ super.validate(method);
+
+ ReflectionUtils.assertVoidReturnType(method);
+ ReflectionUtils.assertOneParameter(method);
+ ReflectionUtils.assertNoPrimitiveParameters(method);
+ ReflectionUtils.assertValidSetterName(method);
+ ReflectionUtils.assertNoCheckedExceptionsAreThrown(method);
+ ReflectionUtils.assertNotStatic(method);
+ }
+
+}
Added:
common/trunk/src/main/java/org/jboss/wsf/common/injection/finders/PostConstructMethodFinder.java
===================================================================
---
common/trunk/src/main/java/org/jboss/wsf/common/injection/finders/PostConstructMethodFinder.java
(rev 0)
+++
common/trunk/src/main/java/org/jboss/wsf/common/injection/finders/PostConstructMethodFinder.java 2009-05-05
11:58:55 UTC (rev 9956)
@@ -0,0 +1,58 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.wsf.common.injection.finders;
+
+import javax.annotation.PostConstruct;
+
+/**
+ * @PostConstruct method finder.
+ *
+ * The PostConstruct annotation is used on a method that needs to be executed after
dependency injection is done
+ * to perform any initialization. This method MUST be invoked before the class is put
into service. This annotation
+ * MUST be supported on all classes that support dependency injection. The method
annotated with PostConstruct MUST
+ * be invoked even if the class does not request any resources to be injected. Only one
method can be annotated with
+ * this annotation. The method on which the PostConstruct annotation is applied MUST
fulfill all of the following criteria:
+ * <ul>
+ * <li>The method MUST NOT have any parameters.
+ * <li>The return type of the method MUST be void.
+ * <li>The method MUST NOT throw a checked exception.
+ * <li>The method on which PostConstruct is applied MAY be public, protected,
package private or private.
+ * <li>The method MUST NOT be static.
+ * <li>The method MAY be final.
+ * <li>If the method throws an unchecked exception the class MUST NOT be put into
service.
+ * </ul>
+ *
+ * @author <a href="mailto:richard.opalka@jboss.org">Richard
Opalka</a>
+ */
+public final class PostConstructMethodFinder
+extends AbstractPostConstructPreDestroyAnnotatedMethodFinder<PostConstruct>
+{
+
+ /**
+ * Constructor.
+ */
+ public PostConstructMethodFinder()
+ {
+ super(PostConstruct.class);
+ }
+
+}
Added:
common/trunk/src/main/java/org/jboss/wsf/common/injection/finders/PreDestroyMethodFinder.java
===================================================================
---
common/trunk/src/main/java/org/jboss/wsf/common/injection/finders/PreDestroyMethodFinder.java
(rev 0)
+++
common/trunk/src/main/java/org/jboss/wsf/common/injection/finders/PreDestroyMethodFinder.java 2009-05-05
11:58:55 UTC (rev 9956)
@@ -0,0 +1,58 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.wsf.common.injection.finders;
+
+import javax.annotation.PreDestroy;
+
+/**
+ * @PreDestroy method finder.
+ *
+ * The PreDestroy annotation is used on methods as a callback notification to signal that
the instance
+ * is in the process of being removed by the container. The method annotated with
PreDestroy is typically
+ * used to release resources that it has been holding. This annotation MUST be supported
by all container
+ * managed objects that support PostConstruct except the application client container in
Java EE 5.
+ * The method on which the PreDestroy annotation is applied MUST fulfill all of the
following criteria:
+ * <ul>
+ * <li>The method MUST NOT have any parameters.
+ * <li>The return type of the method MUST be void.
+ * <li>The method MUST NOT throw a checked exception.
+ * <li>The method on which PreDestroy is applied MAY be public, protected,
package private or private.
+ * <li>The method MUST NOT be static.
+ * <li>The method MAY be final.
+ * <li>If the method throws an unchecked exception it is ignored.
+ * </ul>
+ *
+ * @author <a href="mailto:richard.opalka@jboss.org">Richard
Opalka</a>
+ */
+public final class PreDestroyMethodFinder
+extends AbstractPostConstructPreDestroyAnnotatedMethodFinder<PreDestroy>
+{
+
+ /**
+ * Constructor.
+ */
+ public PreDestroyMethodFinder()
+ {
+ super(PreDestroy.class);
+ }
+
+}
Added:
common/trunk/src/main/java/org/jboss/wsf/common/injection/finders/ReflectionUtils.java
===================================================================
---
common/trunk/src/main/java/org/jboss/wsf/common/injection/finders/ReflectionUtils.java
(rev 0)
+++
common/trunk/src/main/java/org/jboss/wsf/common/injection/finders/ReflectionUtils.java 2009-05-05
11:58:55 UTC (rev 9956)
@@ -0,0 +1,360 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.wsf.common.injection.finders;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.util.Collection;
+
+import org.jboss.wsf.common.injection.InjectionException;
+
+/**
+ * Reflection utility class.
+ *
+ * @author <a href="mailto:richard.opalka@jboss.org">Richard
Opalka</a>
+ */
+final class ReflectionUtils
+{
+
+ /**
+ * Constructor.
+ */
+ private ReflectionUtils()
+ {
+ super();
+ }
+
+ /**
+ * Asserts method don't declare primitive parameters.
+ *
+ * @param method to validate
+ * @param annotation annotation to propagate in exception message
+ */
+ public static void assertNoPrimitiveParameters(final Method method, Class<? extends
Annotation> annotation)
+ {
+ for (Class<?> type : method.getParameterTypes())
+ {
+ if (type.isPrimitive())
+ {
+ throw new InjectionException("Method " +
getAnnotationMessage(annotation) + "can't declare primitive parameters: " +
method);
+ }
+ }
+ }
+
+ /**
+ * Asserts method don't declare primitive parameters.
+ *
+ * @param method to validate
+ */
+ public static void assertNoPrimitiveParameters(final Method method)
+ {
+ assertNoPrimitiveParameters(method, null);
+ }
+
+ /**
+ * Asserts field is not of primitive type.
+ *
+ * @param method to validate
+ * @param annotation annotation to propagate in exception message
+ */
+ public static void assertNotPrimitiveType(final Field field, Class<? extends
Annotation> annotation)
+ {
+ if (field.getType().isPrimitive())
+ {
+ throw new InjectionException("Field " +
getAnnotationMessage(annotation) + "can't be of primitive type: " + field);
+ }
+ }
+
+ /**
+ * Asserts field is not of primitive type.
+ *
+ * @param method to validate
+ */
+ public static void assertNotPrimitiveType(final Field field)
+ {
+ assertNotPrimitiveType(field, null);
+ }
+
+ /**
+ * Asserts method have no parameters.
+ *
+ * @param method to validate
+ * @param annotation annotation to propagate in exception message
+ */
+ public static void assertNoParameters(final Method method, Class<? extends
Annotation> annotation)
+ {
+ if (method.getParameterTypes().length != 0)
+ {
+ throw new InjectionException("Method " +
getAnnotationMessage(annotation) + "have to have no parameters: " + method);
+ }
+ }
+
+ /**
+ * Asserts method have no parameters.
+ *
+ * @param method to validate
+ */
+ public static void assertNoParameters(final Method method)
+ {
+ assertNoParameters(method, null);
+ }
+
+ /**
+ * Asserts method return void.
+ *
+ * @param method to validate
+ * @param annotation annotation to propagate in exception message
+ */
+ public static void assertVoidReturnType(final Method method, Class<? extends
Annotation> annotation)
+ {
+ if ((!method.getReturnType().equals(Void.class)) &&
(!method.getReturnType().equals(Void.TYPE)))
+ {
+ throw new InjectionException("Method " +
getAnnotationMessage(annotation) + "have to return void: " + method);
+ }
+ }
+
+ /**
+ * Asserts method return void.
+ *
+ * @param method to validate
+ */
+ public static void assertVoidReturnType(final Method method)
+ {
+ assertVoidReturnType(method, null);
+ }
+
+ /**
+ * Asserts field isn't of void type.
+ *
+ * @param field to validate
+ * @param annotation annotation to propagate in exception message
+ */
+ public static void assertNotVoidType(final Field field, Class<? extends
Annotation> annotation)
+ {
+ if ((field.getClass().equals(Void.class)) &&
(field.getClass().equals(Void.TYPE)))
+ {
+ throw new InjectionException("Field " +
getAnnotationMessage(annotation) + "cannot be of void type: " + field);
+ }
+ }
+
+ /**
+ * Asserts field isn't of void type.
+ *
+ * @param field to validate
+ */
+ public static void assertNotVoidType(final Field field)
+ {
+ assertNotVoidType(field, null);
+ }
+
+ /**
+ * Asserts method don't throw checked exceptions.
+ *
+ * @param method to validate
+ * @param annotation annotation to propagate in exception message
+ */
+ public static void assertNoCheckedExceptionsAreThrown(final Method method, Class<?
extends Annotation> annotation)
+ {
+ Class<?>[] declaredExceptions = method.getExceptionTypes();
+ for (int i = 0; i < declaredExceptions.length; i++)
+ {
+ Class<?> exception = declaredExceptions[i];
+ if (!exception.isAssignableFrom(RuntimeException.class))
+ {
+ throw new InjectionException("Method " +
getAnnotationMessage(annotation) + "cannot throw checked exceptions: " +
method);
+ }
+ }
+ }
+
+ /**
+ * Asserts method don't throw checked exceptions.
+ *
+ * @param method to validate
+ */
+ public static void assertNoCheckedExceptionsAreThrown(final Method method)
+ {
+ assertNoCheckedExceptionsAreThrown(method, null);
+ }
+
+ /**
+ * Asserts method is not static.
+ *
+ * @param method to validate
+ * @param annotation annotation to propagate in exception message
+ */
+ public static void assertNotStatic(final Method method, Class<? extends
Annotation> annotation)
+ {
+ if (Modifier.isStatic(method.getModifiers()))
+ {
+ throw new InjectionException("Method " +
getAnnotationMessage(annotation) + "cannot be static: " + method);
+ }
+ }
+
+ /**
+ * Asserts method is not static.
+ *
+ * @param method to validate
+ */
+ public static void assertNotStatic(final Method method)
+ {
+ assertNotStatic(method, null);
+ }
+
+ /**
+ * Asserts field is not static.
+ *
+ * @param field to validate
+ * @param annotation annotation to propagate in exception message
+ */
+ public static void assertNotStatic(final Field field, Class<? extends
Annotation> annotation)
+ {
+ if (Modifier.isStatic(field.getModifiers()))
+ {
+ throw new InjectionException("Field " +
getAnnotationMessage(annotation) + "cannot be static: " + field);
+ }
+ }
+
+ /**
+ * Asserts field is not static.
+ *
+ * @param field to validate
+ */
+ public static void assertNotStatic(final Field field)
+ {
+ assertNotStatic(field, null);
+ }
+
+ /**
+ * Asserts field is not final.
+ *
+ * @param field to validate
+ * @param annotation annotation to propagate in exception message
+ */
+ public static void assertNotFinal(final Field field, Class<? extends Annotation>
annotation)
+ {
+ if (Modifier.isFinal(field.getModifiers()))
+ {
+ throw new InjectionException("Field " +
getAnnotationMessage(annotation) + "cannot be final: " + field);
+ }
+ }
+
+ /**
+ * Asserts field is not final.
+ *
+ * @param field to validate
+ */
+ public static void assertNotFinal(final Field field)
+ {
+ assertNotFinal(field, null);
+ }
+
+ /**
+ * Asserts method have exactly one parameter.
+ *
+ * @param method to validate
+ * @param annotation annotation to propagate in exception message
+ */
+ public static void assertOneParameter(final Method method, Class<? extends
Annotation> annotation)
+ {
+ if (method.getParameterTypes().length != 1)
+ {
+ throw new InjectionException("Method " +
getAnnotationMessage(annotation) + "have to declare exactly one parameter: " +
method);
+ }
+ }
+
+ /**
+ * Asserts method have exactly one parameter.
+ *
+ * @param method to validate
+ */
+ public static void assertOneParameter(final Method method)
+ {
+ assertOneParameter(method, null);
+ }
+
+ /**
+ * Asserts valid Java Beans setter method name.
+ *
+ * @param method to validate
+ * @param annotation annotation to propagate in exception message
+ */
+ public static void assertValidSetterName(final Method method, Class<? extends
Annotation> annotation)
+ {
+ final String methodName = method.getName();
+ final boolean correctMethodNameLength = methodName.length() > 3;
+ final boolean isSetterMethodName = methodName.startsWith("set");
+ final boolean isUpperCasedPropertyName = correctMethodNameLength ?
Character.isUpperCase(methodName.charAt(3)) : false;
+
+ if (!correctMethodNameLength || !isSetterMethodName || !isUpperCasedPropertyName)
+ {
+ throw new InjectionException("Method " +
getAnnotationMessage(annotation) + "doesn't follow Java Beans setter method name:
" + method);
+ }
+ }
+
+ /**
+ * Asserts valid Java Beans setter method name.
+ *
+ * @param method to validate
+ */
+ public static void assertValidSetterName(final Method method)
+ {
+ assertValidSetterName(method, null);
+ }
+
+ /**
+ * Asserts only one method is annotated with annotation.
+ *
+ * @param method collection of methods to validate
+ * @param annotation annotation to propagate in exception message
+ */
+ public static void assertOnlyOneMethod(final Collection<Method> methods,
Class<? extends Annotation> annotation)
+ {
+ if (methods.size() > 1)
+ {
+ throw new InjectionException("Only one method " +
getAnnotationMessage(annotation) + "can exist");
+ }
+ }
+
+ /**
+ * Asserts only one method is annotated with annotation.
+ *
+ * @param method collection of methods to validate
+ */
+ public static void assertOnlyOneMethod(final Collection<Method> methods)
+ {
+ assertOnlyOneMethod(methods, null);
+ }
+
+ /**
+ * Constructs annotation message. If annotation class is null it returns empty
string.
+ *
+ * @param annotation to construct message for
+ * @return annotation message or empty string
+ */
+ private static String getAnnotationMessage(Class<? extends Annotation>
annotation)
+ {
+ return annotation == null ? "" : "annotated with @" +
annotation + " annotation ";
+ }
+
+}
Added:
common/trunk/src/main/java/org/jboss/wsf/common/injection/finders/ResourceFieldFinder.java
===================================================================
---
common/trunk/src/main/java/org/jboss/wsf/common/injection/finders/ResourceFieldFinder.java
(rev 0)
+++
common/trunk/src/main/java/org/jboss/wsf/common/injection/finders/ResourceFieldFinder.java 2009-05-05
11:58:55 UTC (rev 9956)
@@ -0,0 +1,111 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.wsf.common.injection.finders;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+
+import javax.annotation.Resource;
+import javax.xml.ws.WebServiceContext;
+
+import org.jboss.wsf.common.reflection.AnnotatedFieldFinder;
+
+/**
+ * Field based resource injection.
+ *
+ * To access a resource a developer declares a setter method and annotates it as being a
+ * resource reference. The name and type of resource maybe inferred by inspecting the
+ * method declaration if necessary. The name of the resource, if not declared, is the
+ * name of the JavaBeans property as determined starting from the name of the setter
+ * method in question. The setter method must follow the standard JavaBeans
+ * convention - name starts with a “set”, void return type and only one parameter.
+ * Additionally, the type of the parameter must be compatible with the type specified
+ * as a property of the Resource if present.
+ *
+ * @author <a href="mailto:richard.opalka@jboss.org">Richard
Opalka</a>
+ */
+public final class ResourceFieldFinder
+extends AnnotatedFieldFinder<Resource>
+{
+
+ /**
+ * Parameter type to accept/ignore.
+ */
+ private final Class<?> accept;
+ /**
+ * If <b>accept</b> field is not null then:
+ * <ul>
+ * <li><b>true</b> means include only methods with
<b>accept</b> parameter,
+ * <li><b>false</b> means exclude all methods with
<b>accept</b> parameter
+ * </ul>
+ */
+ private final boolean include;
+
+ /**
+ * Constructor.
+ *
+ * @param accept filtering class
+ * @param include whether include/exclude filtering class
+ */
+ public ResourceFieldFinder(final Class<?> accept, boolean include)
+ {
+ super(Resource.class);
+
+ this.accept = accept;
+ this.include = include;
+ }
+
+ @Override
+ public void validate(Field field)
+ {
+ super.validate(field);
+
+ // Ensure all method preconditions
+ Class<Resource> annotation = getAnnotation();
+ ReflectionUtils.assertNotVoidType(field, annotation);
+ ReflectionUtils.assertNotStatic(field, annotation);
+ ReflectionUtils.assertNotFinal(field, annotation);
+ ReflectionUtils.assertNotPrimitiveType(field, annotation);
+ }
+
+ @Override
+ public boolean matches(Field field)
+ {
+ final boolean matches = super.matches(field);
+
+ if (matches)
+ {
+ // processing @Resource annotated method
+ if (this.accept != null)
+ {
+ // filtering
+ final Class<?> fieldType = field.getType();
+ final boolean parameterMatch = this.accept.equals(fieldType);
+ // include/exclude filtering
+ return this.include ? parameterMatch : !parameterMatch;
+ }
+ }
+
+ return matches;
+ }
+
+}
Added:
common/trunk/src/main/java/org/jboss/wsf/common/injection/finders/ResourceMethodFinder.java
===================================================================
---
common/trunk/src/main/java/org/jboss/wsf/common/injection/finders/ResourceMethodFinder.java
(rev 0)
+++
common/trunk/src/main/java/org/jboss/wsf/common/injection/finders/ResourceMethodFinder.java 2009-05-05
11:58:55 UTC (rev 9956)
@@ -0,0 +1,115 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.wsf.common.injection.finders;
+
+import java.lang.reflect.Method;
+
+import javax.annotation.Resource;
+import javax.xml.ws.WebServiceContext;
+
+import org.jboss.wsf.common.reflection.AnnotatedMethodFinder;
+
+/**
+ * Setter based resource injection.
+ *
+ * To access a resource a developer declares a setter method and annotates it as being a
+ * resource reference. The name and type of resource maybe inferred by inspecting the
+ * method declaration if necessary. The name of the resource, if not declared, is the
+ * name of the JavaBeans property as determined starting from the name of the setter
+ * method in question. The setter method must follow the standard JavaBeans
+ * convention - name starts with a “set”, void return type and only one parameter.
+ * Additionally, the type of the parameter must be compatible with the type specified
+ * as a property of the Resource if present.
+ *
+ * @author <a href="mailto:richard.opalka@jboss.org">Richard
Opalka</a>
+ */
+public final class ResourceMethodFinder
+extends AnnotatedMethodFinder<Resource>
+{
+
+ /**
+ * Parameter type to accept/ignore.
+ */
+ private final Class<?> accept;
+ /**
+ * If <b>accept</b> field is not null then:
+ * <ul>
+ * <li><b>true</b> means include only methods with
<b>accept</b> parameter,
+ * <li><b>false</b> means exclude all methods with
<b>accept</b> parameter
+ * </ul>
+ */
+ private final boolean include;
+
+ /**
+ * Constructor.
+ *
+ * @param accept filtering class
+ * @param include whether include/exclude filtering class
+ */
+ public ResourceMethodFinder(final Class<?> accept, boolean include)
+ {
+ super(Resource.class);
+
+ this.accept = accept;
+ this.include = include;
+ }
+
+ @Override
+ public void validate(Method method)
+ {
+ super.validate(method);
+
+ // Ensure all method preconditions
+ Class<Resource> annotation = getAnnotation();
+ ReflectionUtils.assertVoidReturnType(method, annotation);
+ ReflectionUtils.assertOneParameter(method, annotation);
+ ReflectionUtils.assertNoPrimitiveParameters(method, annotation);
+ ReflectionUtils.assertValidSetterName(method, annotation);
+ ReflectionUtils.assertNoCheckedExceptionsAreThrown(method, annotation);
+ ReflectionUtils.assertNotStatic(method, annotation);
+ }
+
+ @Override
+ public boolean matches(Method method)
+ {
+ final boolean matches = super.matches(method);
+
+ if (matches)
+ {
+ // processing @Resource annotated method
+ if (this.accept != null)
+ {
+ // filtering
+ if (method.getParameterTypes().length == 1)
+ {
+ final Class<?> param = method.getParameterTypes()[0];
+ final boolean parameterMatch = this.accept.equals(param);
+ // include/exclude filtering
+ return this.include ? parameterMatch : !parameterMatch;
+ }
+ }
+ }
+
+ return matches;
+ }
+
+}
Added:
common/trunk/src/main/java/org/jboss/wsf/common/injection/resolvers/AbstractReferenceResolver.java
===================================================================
---
common/trunk/src/main/java/org/jboss/wsf/common/injection/resolvers/AbstractReferenceResolver.java
(rev 0)
+++
common/trunk/src/main/java/org/jboss/wsf/common/injection/resolvers/AbstractReferenceResolver.java 2009-05-05
11:58:55 UTC (rev 9956)
@@ -0,0 +1,127 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.wsf.common.injection.resolvers;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.AccessibleObject;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+
+import org.jboss.wsf.spi.metadata.injection.ReferenceResolver;
+
+/**
+ * This class adds support for notion of annotated fields and methods.
+ * It also ensures passed methods and fields are non null references
+ * plus it implements some common logic that would otherwise be
+ * implemented in all subclasses. It is highly recommended that all
+ * reference resolvers extend this base class for high code reuse.
+ *
+ * @author <a href="mailto:richard.opalka@jboss.org">Richard
Opalka</a>
+ */
+public abstract class AbstractReferenceResolver<A extends Annotation>
+implements ReferenceResolver
+{
+
+ /**
+ * Resolved annotation.
+ */
+ private final Class<A> annotationClass;
+
+ /**
+ * Constructor.
+ */
+ public AbstractReferenceResolver(final Class<A> annotationClass)
+ {
+ super();
+
+ if (annotationClass == null)
+ {
+ throw new IllegalArgumentException("Annotation class cannot be
null");
+ }
+
+ this.annotationClass = annotationClass;
+ }
+
+ /* (non-Javadoc)
+ * @see
org.jboss.wsf.spi.metadata.injection.ReferenceResolver#resolve(java.lang.reflect.Method)
+ */
+ public final String resolve(final AccessibleObject accessibleObject)
+ {
+ if (!this.canResolve(accessibleObject))
+ {
+ throw new IllegalArgumentException("Cannot resolve: " +
accessibleObject);
+ }
+
+ if (accessibleObject.getClass().equals(Method.class))
+ {
+ return this.resolveMethod((Method)accessibleObject);
+ }
+ else
+ {
+ return this.resolveField((Field)accessibleObject);
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see
org.jboss.wsf.spi.metadata.injection.ReferenceResolver#canResolve(java.lang.reflect.AccessibleObject)
+ */
+ public final boolean canResolve(final AccessibleObject accessibleObject)
+ {
+ this.assertNotNull(accessibleObject);
+
+ final boolean isField = accessibleObject.getClass().equals(Field.class);
+ final boolean isMethod = accessibleObject.getClass().equals(Method.class);
+ final boolean hasAnnotation = accessibleObject.getAnnotation(this.annotationClass)
!= null;
+
+ return (isField || isMethod) && hasAnnotation;
+ }
+
+ /**
+ * All subclasses have to implement this template method.
+ *
+ * @param Method method
+ * @return JNDI name
+ */
+ protected abstract String resolveMethod(Method method);
+
+ /**
+ * All subclasses have to implement this template method.
+ *
+ * @param Field field
+ * @return JNDI name
+ */
+ protected abstract String resolveField(Field field);
+
+ /**
+ * Asserts passed object is not null
+ *
+ * @param accessibleObject to validate
+ */
+ private void assertNotNull(final AccessibleObject accessibleObject)
+ {
+ if (accessibleObject == null)
+ {
+ throw new IllegalArgumentException("AccessibleObject cannot be
null");
+ }
+ }
+
+}
Added:
common/trunk/src/main/java/org/jboss/wsf/common/injection/resolvers/ResourceReferenceResolver.java
===================================================================
---
common/trunk/src/main/java/org/jboss/wsf/common/injection/resolvers/ResourceReferenceResolver.java
(rev 0)
+++
common/trunk/src/main/java/org/jboss/wsf/common/injection/resolvers/ResourceReferenceResolver.java 2009-05-05
11:58:55 UTC (rev 9956)
@@ -0,0 +1,93 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.wsf.common.injection.resolvers;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+
+import javax.annotation.Resource;
+
+/**
+ * JNDI reference resolver for @Resource annotated methods and fields.
+ *
+ * @author <a href="mailto:richard.opalka@jboss.org">Richard
Opalka</a>
+ * @see org.jboss.wsf.spi.metadata.injection.ReferenceResolver
+ */
+public final class ResourceReferenceResolver extends
AbstractReferenceResolver<Resource>
+{
+
+ /**
+ * Constructor.
+ */
+ public ResourceReferenceResolver()
+ {
+ super(Resource.class);
+ }
+
+ /* (non-Javadoc)
+ * @see
org.jboss.wsf.common.injection.resolvers.AbstractReferenceResolver#resolveField(java.lang.reflect.Field)
+ */
+ @Override
+ protected String resolveField(Field field)
+ {
+ final String fallBackName = field.getName();
+ final String resourceName = field.getAnnotation(Resource.class).name();
+
+ return getName(resourceName, fallBackName);
+ }
+
+ /* (non-Javadoc)
+ * @see
org.jboss.wsf.common.injection.resolvers.AbstractReferenceResolver#resolveMethod(java.lang.reflect.Method)
+ */
+ @Override
+ protected String resolveMethod(Method method)
+ {
+ final String fallBackName = convertToBeanName(method.getName());
+ final String resourceName = method.getAnnotation(Resource.class).name();
+
+ return getName(resourceName, fallBackName);
+ }
+
+ /**
+ * Returns JNDI resource name.
+ *
+ * @param resourceName to use if specified
+ * @param fallBackName fall back bean name otherwise
+ * @return JNDI resource name
+ */
+ private static String getName(final String resourceName, final String fallBackName)
+ {
+ return resourceName.length() > 0 ? resourceName : fallBackName;
+ }
+
+ /**
+ * Translates "setBeanName" to "beanName" string.
+ *
+ * @param methodName to translate
+ * @return bean name
+ */
+ private static String convertToBeanName(final String methodName)
+ {
+ return Character.toLowerCase(methodName.charAt(3)) + methodName.substring(4);
+ }
+
+}