Weld SVN: r6393 - core/trunk/impl/src/main/java/org/jboss/weld/injection.
by weld-commits@lists.jboss.org
Author: pete.muir(a)jboss.org
Date: 2010-06-03 07:54:29 -0400 (Thu, 03 Jun 2010)
New Revision: 6393
Modified:
core/trunk/impl/src/main/java/org/jboss/weld/injection/ConstructorInjectionPoint.java
core/trunk/impl/src/main/java/org/jboss/weld/injection/FieldInjectionPoint.java
core/trunk/impl/src/main/java/org/jboss/weld/injection/MethodInjectionPoint.java
core/trunk/impl/src/main/java/org/jboss/weld/injection/ParameterInjectionPoint.java
Log:
minor
Modified: core/trunk/impl/src/main/java/org/jboss/weld/injection/ConstructorInjectionPoint.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/injection/ConstructorInjectionPoint.java 2010-06-03 11:46:11 UTC (rev 6392)
+++ core/trunk/impl/src/main/java/org/jboss/weld/injection/ConstructorInjectionPoint.java 2010-06-03 11:54:29 UTC (rev 6393)
@@ -99,6 +99,12 @@
}
return false;
}
+
+ @Override
+ public int hashCode()
+ {
+ return constructor.hashCode();
+ }
@Override
protected WeldConstructor<T> delegate()
Modified: core/trunk/impl/src/main/java/org/jboss/weld/injection/FieldInjectionPoint.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/injection/FieldInjectionPoint.java 2010-06-03 11:46:11 UTC (rev 6392)
+++ core/trunk/impl/src/main/java/org/jboss/weld/injection/FieldInjectionPoint.java 2010-06-03 11:54:29 UTC (rev 6393)
@@ -77,6 +77,12 @@
}
return false;
}
+
+ @Override
+ public int hashCode()
+ {
+ return field.hashCode();
+ }
@Override
protected WeldField<T, X> delegate()
Modified: core/trunk/impl/src/main/java/org/jboss/weld/injection/MethodInjectionPoint.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/injection/MethodInjectionPoint.java 2010-06-03 11:46:11 UTC (rev 6392)
+++ core/trunk/impl/src/main/java/org/jboss/weld/injection/MethodInjectionPoint.java 2010-06-03 11:54:29 UTC (rev 6393)
@@ -96,6 +96,12 @@
}
return false;
}
+
+ @Override
+ public int hashCode()
+ {
+ return method.hashCode();
+ }
@Override
protected WeldMethod<T, X> delegate()
Modified: core/trunk/impl/src/main/java/org/jboss/weld/injection/ParameterInjectionPoint.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/injection/ParameterInjectionPoint.java 2010-06-03 11:46:11 UTC (rev 6392)
+++ core/trunk/impl/src/main/java/org/jboss/weld/injection/ParameterInjectionPoint.java 2010-06-03 11:54:29 UTC (rev 6393)
@@ -79,6 +79,12 @@
}
return false;
}
+
+ @Override
+ public int hashCode()
+ {
+ return parameter.hashCode();
+ }
@Override
protected WeldParameter<T, X> delegate()
13 years, 11 months
Weld SVN: r6392 - in core/trunk/impl/src/main/java/org/jboss/weld: bootstrap and 3 other directories.
by weld-commits@lists.jboss.org
Author: pete.muir(a)jboss.org
Date: 2010-06-03 07:46:11 -0400 (Thu, 03 Jun 2010)
New Revision: 6392
Modified:
core/trunk/impl/src/main/java/org/jboss/weld/bean/AbstractClassBean.java
core/trunk/impl/src/main/java/org/jboss/weld/bean/ProducerMethod.java
core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/WeldBootstrap.java
core/trunk/impl/src/main/java/org/jboss/weld/injection/ProxyClassConstructorInjectionPointWrapper.java
core/trunk/impl/src/main/java/org/jboss/weld/introspector/jlr/WeldConstructorImpl.java
core/trunk/impl/src/main/java/org/jboss/weld/util/collections/ArraySet.java
core/trunk/impl/src/main/java/org/jboss/weld/util/collections/ImmutableArraySet.java
Log:
minor
Modified: core/trunk/impl/src/main/java/org/jboss/weld/bean/AbstractClassBean.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/bean/AbstractClassBean.java 2010-06-02 23:05:13 UTC (rev 6391)
+++ core/trunk/impl/src/main/java/org/jboss/weld/bean/AbstractClassBean.java 2010-06-03 11:46:11 UTC (rev 6392)
@@ -134,7 +134,6 @@
// Decorators
private List<Decorator<?>> decorators;
- private Class<T> proxyClassForDecorators;
// Interceptors
private boolean hasSerializationOrInvocationInterceptorMethods;
@@ -205,7 +204,7 @@
DecorationHelper.getHelperStack().push(decorationHelper);
proxy = decorationHelper.getNextDelegate(originalInjectionPoint, creationalContext);
- decorationHelper = (DecorationHelper<T>) DecorationHelper.getHelperStack().pop();
+ DecorationHelper.getHelperStack().pop();
if (proxy == null)
{
Modified: core/trunk/impl/src/main/java/org/jboss/weld/bean/ProducerMethod.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/bean/ProducerMethod.java 2010-06-02 23:05:13 UTC (rev 6391)
+++ core/trunk/impl/src/main/java/org/jboss/weld/bean/ProducerMethod.java 2010-06-03 11:46:11 UTC (rev 6392)
@@ -144,7 +144,7 @@
}
else
{
- return method.invoke(receiver, beanManager, creationalContext, CreationException.class);
+ return method.invoke(null, beanManager, creationalContext, CreationException.class);
}
}
Modified: core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/WeldBootstrap.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/WeldBootstrap.java 2010-06-02 23:05:13 UTC (rev 6391)
+++ core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/WeldBootstrap.java 2010-06-03 11:46:11 UTC (rev 6392)
@@ -108,26 +108,26 @@
*/
public class WeldBootstrap implements Bootstrap
{
-
+
private static final LocLogger log = loggerFactory().getLogger(BOOTSTRAP);
-
+
/**
*
- * A Deployment visitor which can find the transitive closure of Bean
+ * A Deployment visitor which can find the transitive closure of Bean
* Deployment Archives
*
* @author pmuir
- *
+ *
*/
private static class DeploymentVisitor
{
-
+
private final BeanManagerImpl deploymentManager;
private final Environment environment;
private final Deployment deployment;
private final Map<BeanDeploymentArchive, BeanDeployment> managerAwareBeanDeploymentArchives;
private final BeanDeploymentArchive implementationBeanDeploymentArchive;
-
+
public DeploymentVisitor(BeanManagerImpl deploymentManager, Environment environment, final Deployment deployment)
{
this.deploymentManager = deploymentManager;
@@ -136,54 +136,54 @@
this.managerAwareBeanDeploymentArchives = new ConcurrentHashMap<BeanDeploymentArchive, BeanDeployment>();
this.implementationBeanDeploymentArchive = new BeanDeploymentArchive()
{
-
- private final ServiceRegistry serviceRegistry = new SimpleServiceRegistry();
- private final Set<Class<?>> beanClasses = (deployment.getServices().contains(ServletServices.class)) ? Arrays2.<Class<?>> asSet(ConversationImpl.class, ServletConversationManager.class, NumericConversationIdGenerator.class, HttpSessionManager.class) : Collections.<Class<?>>emptySet();
-
+
+ private final ServiceRegistry serviceRegistry = new SimpleServiceRegistry();
+ private final Set<Class<?>> beanClasses = (deployment.getServices().contains(ServletServices.class)) ? Arrays2.<Class<?>> asSet(ConversationImpl.class, ServletConversationManager.class, NumericConversationIdGenerator.class, HttpSessionManager.class) : Collections.<Class<?>> emptySet();
+
public ServiceRegistry getServices()
{
return serviceRegistry;
}
-
+
public String getId()
{
return "weld";
}
-
+
public Collection<EjbDescriptor<?>> getEjbs()
{
return Collections.emptySet();
}
-
+
public Collection<URL> getBeansXml()
{
return Collections.emptySet();
}
-
+
public Collection<BeanDeploymentArchive> getBeanDeploymentArchives()
{
return Collections.emptySet();
}
-
+
public Collection<Class<?>> getBeanClasses()
{
return beanClasses;
}
};
}
-
+
public Map<BeanDeploymentArchive, BeanDeployment> visit()
{
// Add the impl beans
visit(implementationBeanDeploymentArchive, managerAwareBeanDeploymentArchives, new HashSet<BeanDeploymentArchive>(), false);
-
+
for (BeanDeploymentArchive archvive : deployment.getBeanDeploymentArchives())
{
visit(archvive, managerAwareBeanDeploymentArchives, new HashSet<BeanDeploymentArchive>(), true);
}
return managerAwareBeanDeploymentArchives;
}
-
+
private BeanDeployment visit(BeanDeploymentArchive beanDeploymentArchive, Map<BeanDeploymentArchive, BeanDeployment> managerAwareBeanDeploymentArchives, Set<BeanDeploymentArchive> seenBeanDeploymentArchives, boolean validate)
{
// Check that the required services are specified
@@ -191,13 +191,13 @@
{
verifyServices(beanDeploymentArchive.getServices(), environment.getRequiredBeanDeploymentArchiveServices());
}
-
+
// Check the id is not null
if (beanDeploymentArchive.getId() == null)
{
throw new IllegalArgumentException(DEPLOYMENT_ARCHIVE_NULL, beanDeploymentArchive);
}
-
+
BeanDeployment parent = managerAwareBeanDeploymentArchives.get(beanDeploymentArchive);
if (parent == null)
{
@@ -219,9 +219,9 @@
parent.getBeanManager().addAccessibleBeanManager(managerAwareBeanDeploymentArchives.get(implementationBeanDeploymentArchive).getBeanManager());
return parent;
}
-
+
}
-
+
static
{
loggerFactory().getLogger(VERSION).info(VersionMessage.VERSION, Names.version(WeldBootstrap.class.getPackage()));
@@ -233,7 +233,7 @@
private Environment environment;
private Deployment deployment;
private DeploymentVisitor deploymentVisitor;
-
+
public Bootstrap startContainer(Environment environment, Deployment deployment, BeanStore applicationBeanStore)
{
synchronized (this)
@@ -254,61 +254,63 @@
{
deployment.getServices().add(ProxyServices.class, new SimpleProxyServices());
}
-
+
verifyServices(deployment.getServices(), environment.getRequiredDeploymentServices());
-
+
if (!deployment.getServices().contains(TransactionServices.class))
{
log.info(JTA_UNAVAILABLE);
}
// TODO Reinstate if we can find a good way to detect.
-// if (!deployment.getServices().contains(EjbServices.class))
-// {
-// log.info("EJB services not available. Session beans will be simple beans, CDI-style injection into non-contextual EJBs, injection of remote EJBs and injection of @EJB in simple beans will not be available");
-// }
-// if (!deployment.getServices().contains(JpaInjectionServices.class))
-// {
-// log.info("JPA services not available. Injection of @PersistenceContext will not occur. Entity beans will be discovered as simple beans.");
-// }
-// if (!deployment.getServices().contains(ResourceInjectionServices.class))
-// {
-// log.info("@Resource injection not available.");
-// }
+ // if (!deployment.getServices().contains(EjbServices.class))
+ // {
+ // log.info("EJB services not available. Session beans will be simple beans, CDI-style injection into non-contextual EJBs, injection of remote EJBs and injection of @EJB in simple beans will not be available");
+ // }
+ // if (!deployment.getServices().contains(JpaInjectionServices.class))
+ // {
+ // log.info("JPA services not available. Injection of @PersistenceContext will not occur. Entity beans will be discovered as simple beans.");
+ // }
+ // if
+ // (!deployment.getServices().contains(ResourceInjectionServices.class))
+ // {
+ // log.info("@Resource injection not available.");
+ // }
if (applicationBeanStore == null)
{
throw new IllegalStateException(BEAN_STORE_MISSING);
}
-
+
this.deployment = deployment;
ServiceRegistry implementationServices = getImplementationServices(deployment.getServices().get(ResourceLoader.class));
-
+
deployment.getServices().addAll(implementationServices.entrySet());
-
+
ServiceRegistry deploymentServices = new SimpleServiceRegistry();
deploymentServices.add(ClassTransformer.class, implementationServices.get(ClassTransformer.class));
deploymentServices.add(MetaAnnotationStore.class, implementationServices.get(MetaAnnotationStore.class));
deploymentServices.add(TypeStore.class, implementationServices.get(TypeStore.class));
-
+
this.environment = environment;
this.deploymentManager = BeanManagerImpl.newRootManager("deployment", deploymentServices);
-
+
Container.initialize(deploymentManager, ServiceRegistries.unmodifiableServiceRegistry(deployment.getServices()));
Container.instance().setState(ContainerState.STARTING);
-
+
createContexts();
initializeContexts();
// Start the application context
Container.instance().services().get(ContextLifecycle.class).beginApplication(applicationBeanStore);
new ExtensionBeanDeployerEnvironment(EjbDescriptors.EMPTY, deploymentManager);
this.deploymentVisitor = new DeploymentVisitor(deploymentManager, environment, deployment);
-
- // Read the deployment structure, this will be the physical structure as caused by the presence of beans.xml
+
+ // Read the deployment structure, this will be the physical structure
+ // as caused by the presence of beans.xml
beanDeployments = deploymentVisitor.visit();
-
+
return this;
}
}
-
+
private ServiceRegistry getImplementationServices(ResourceLoader resourceLoader)
{
ServiceRegistry services = new SimpleServiceRegistry();
@@ -318,7 +320,8 @@
services.add(WSApiAbstraction.class, new WSApiAbstraction(resourceLoader));
services.add(ServletApiAbstraction.class, new ServletApiAbstraction(resourceLoader));
// Temporary workaround to provide context for building annotated class
- // TODO expose AnnotatedClass on SPI and allow container to provide impl of this via ResourceLoader
+ // TODO expose AnnotatedClass on SPI and allow container to provide impl
+ // of this via ResourceLoader
services.add(Validator.class, new Validator());
services.add(TypeStore.class, new TypeStore());
services.add(ClassTransformer.class, new ClassTransformer(services.get(TypeStore.class)));
@@ -329,7 +332,7 @@
services.add(CurrentInjectionPoint.class, new CurrentInjectionPoint());
return services;
}
-
+
public BeanManagerImpl getManager(BeanDeploymentArchive beanDeploymentArchive)
{
if (beanDeployments.containsKey(beanDeploymentArchive))
@@ -341,7 +344,7 @@
return null;
}
}
-
+
public Bootstrap startInitialization()
{
synchronized (this)
@@ -350,31 +353,36 @@
{
throw new IllegalStateException(MANAGER_NOT_INITIALIZED);
}
-
+
ExtensionBeanDeployer extensionBeanDeployer = new ExtensionBeanDeployer(deploymentManager, deployment, beanDeployments);
extensionBeanDeployer.addExtensions(deployment.getServices().get(ServiceLoaderFactory.class).load(Extension.class));
extensionBeanDeployer.deployBeans();
-
+
// Add the Deployment BeanManager Bean to the Deployment BeanManager
deploymentManager.addBean(new BeanManagerBean(deploymentManager));
-
- // Re-Read the deployment structure, this will be the physical structure, and will add in BDAs for any extensions outside a physical BDA
+
+ // Re-Read the deployment structure, this will be the physical
+ // structure, and will add in BDAs for any extensions outside a
+ // physical BDA
beanDeployments = deploymentVisitor.visit();
-
+
BeforeBeanDiscoveryImpl.fire(deploymentManager, deployment, beanDeployments);
-
- // Re-Read the deployment structure, this will be the physical structure, extensions and any classes added using addAnnotatedType outside the physical BDA
+
+ // Re-Read the deployment structure, this will be the physical
+ // structure, extensions and any classes added using addAnnotatedType
+ // outside the physical BDA
beanDeployments = deploymentVisitor.visit();
-
+
}
return this;
}
-
+
public Bootstrap deployBeans()
{
synchronized (this)
{
- // TODO keep a list of new bdas, add them all in, and deploy beans for them, then merge into existing
+ // TODO keep a list of new bdas, add them all in, and deploy beans for
+ // them, then merge into existing
for (Entry<BeanDeploymentArchive, BeanDeployment> entry : beanDeployments.entrySet())
{
entry.getValue().deployBeans(environment);
@@ -384,14 +392,16 @@
{
entry.getValue().afterBeanDiscovery(environment);
}
- // Re-read the deployment structure, this will be the physical structure, extensions, classes, and any beans added using addBean outside the physical structure
+ // Re-read the deployment structure, this will be the physical
+ // structure, extensions, classes, and any beans added using addBean
+ // outside the physical structure
beanDeployments = deploymentVisitor.visit();
Container.instance().putBeanDeployments(beanDeployments);
Container.instance().setState(ContainerState.INITIALIZED);
}
return this;
}
-
+
public Bootstrap validateBeans()
{
synchronized (this)
@@ -416,7 +426,7 @@
}
return this;
}
-
+
protected void initializeContexts()
{
Lifecycle lifecycle = deployment.getServices().get(ContextLifecycle.class);
@@ -427,7 +437,7 @@
deploymentManager.addContext(lifecycle.getApplicationContext());
deploymentManager.addContext(lifecycle.getSingletonContext());
}
-
+
protected void createContexts()
{
AbstractApplicationContext applicationContext = new ApplicationContext();
@@ -436,35 +446,38 @@
ConversationContext conversationContext = new ConversationContext();
RequestContext requestContext = new RequestContext();
DependentContext dependentContext = new DependentContext();
-
+
deployment.getServices().add(ContextLifecycle.class, new ContextLifecycle(applicationContext, singletonContext, sessionContext, conversationContext, requestContext, dependentContext));
}
-
+
public void shutdown()
{
- try
+ synchronized (this)
{
- Container.instance().services().get(ContextLifecycle.class).endApplication();
try
{
- // Create a fake application context to service this request
- Container.instance().services().get(ContextLifecycle.class).beginApplication(new HashMapBeanStore());
- BeforeShutdownImpl.fire(deploymentManager, beanDeployments);
Container.instance().services().get(ContextLifecycle.class).endApplication();
+ try
+ {
+ // Create a fake application context to service this request
+ Container.instance().services().get(ContextLifecycle.class).beginApplication(new HashMapBeanStore());
+ BeforeShutdownImpl.fire(deploymentManager, beanDeployments);
+ Container.instance().services().get(ContextLifecycle.class).endApplication();
+ }
+ finally
+ {
+
+ }
}
finally
{
-
+ Container.instance().setState(ContainerState.SHUTDOWN);
+ Container.instance().cleanup();
}
}
- finally
- {
- Container.instance().setState(ContainerState.SHUTDOWN);
- Container.instance().cleanup();
- }
}
-
- protected static void verifyServices(ServiceRegistry services, Set<Class<? extends Service>> requiredServices)
+
+ protected static void verifyServices(ServiceRegistry services, Set<Class<? extends Service>> requiredServices)
{
for (Class<? extends Service> serviceType : requiredServices)
{
Modified: core/trunk/impl/src/main/java/org/jboss/weld/injection/ProxyClassConstructorInjectionPointWrapper.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/injection/ProxyClassConstructorInjectionPointWrapper.java 2010-06-02 23:05:13 UTC (rev 6391)
+++ core/trunk/impl/src/main/java/org/jboss/weld/injection/ProxyClassConstructorInjectionPointWrapper.java 2010-06-03 11:46:11 UTC (rev 6392)
@@ -17,14 +17,12 @@
package org.jboss.weld.injection;
+import java.util.List;
+
import javax.decorator.Decorator;
-import javax.enterprise.context.spi.CreationalContext;
import javax.enterprise.inject.spi.Bean;
-import java.lang.annotation.Annotation;
-import java.util.List;
import org.jboss.weld.introspector.WeldConstructor;
-import org.jboss.weld.manager.BeanManagerImpl;
/**
* A wrapper on a {@link ConstructorInjectionPoint}, to be used if a proxy subclass is instantiated instead of the
Modified: core/trunk/impl/src/main/java/org/jboss/weld/introspector/jlr/WeldConstructorImpl.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/introspector/jlr/WeldConstructorImpl.java 2010-06-02 23:05:13 UTC (rev 6391)
+++ core/trunk/impl/src/main/java/org/jboss/weld/introspector/jlr/WeldConstructorImpl.java 2010-06-03 11:46:11 UTC (rev 6392)
@@ -159,7 +159,7 @@
{
parameterType = clazz;
}
- WeldParameter<?, T> parameter = WeldParameterImpl.of(new Annotation[0], (Class<Object>) clazz, parameterType, this, i, classTransformer);
+ WeldParameter<?, T> parameter = WeldParameterImpl.of(new Annotation[0], clazz, parameterType, this, i, classTransformer);
this.parameters.add(parameter);
}
}
@@ -185,7 +185,7 @@
}
}
}
-
+
}
this.signature = new ConstructorSignatureImpl(this);
}
@@ -268,7 +268,7 @@
public boolean equals(Object other)
{
- if (super.equals(other) && other instanceof WeldConstructor)
+ if (super.equals(other) && other instanceof WeldConstructor<?>)
{
WeldConstructor<?> that = (WeldConstructor<?>) other;
return this.getJavaMember().equals(that.getJavaMember()) && this.getWeldParameters().equals(that.getWeldParameters());
@@ -276,6 +276,15 @@
return false;
}
+ @Override
+ public int hashCode()
+ {
+ int hash = 1;
+ hash = hash * 31 + getJavaMember().hashCode();
+ hash = hash * 31 + getWeldParameters().hashCode();
+ return hash;
+ }
+
/**
* Gets a string representation of the constructor
*
@@ -294,9 +303,9 @@
public List<AnnotatedParameter<T>> getParameters()
{
- return Collections.unmodifiableList((List) parameters);
+ return Collections.<AnnotatedParameter<T>> unmodifiableList(parameters);
}
-
+
public boolean isGeneric()
{
return getJavaMember().getTypeParameters().length > 0;
Modified: core/trunk/impl/src/main/java/org/jboss/weld/util/collections/ArraySet.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/util/collections/ArraySet.java 2010-06-02 23:05:13 UTC (rev 6391)
+++ core/trunk/impl/src/main/java/org/jboss/weld/util/collections/ArraySet.java 2010-06-03 11:46:11 UTC (rev 6392)
@@ -189,6 +189,12 @@
}
return false;
}
+
+ @Override
+ public int hashCode()
+ {
+ return elements.hashCode();
+ }
@Override
public String toString()
Modified: core/trunk/impl/src/main/java/org/jboss/weld/util/collections/ImmutableArraySet.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/util/collections/ImmutableArraySet.java 2010-06-02 23:05:13 UTC (rev 6391)
+++ core/trunk/impl/src/main/java/org/jboss/weld/util/collections/ImmutableArraySet.java 2010-06-03 11:46:11 UTC (rev 6392)
@@ -237,6 +237,12 @@
}
return false;
}
+
+ @Override
+ public int hashCode()
+ {
+ return elements.hashCode();
+ }
@Override
public String toString()
13 years, 11 months
Weld SVN: r6391 - extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/query.
by weld-commits@lists.jboss.org
Author: shane.bryzak(a)jboss.com
Date: 2010-06-02 19:05:13 -0400 (Wed, 02 Jun 2010)
New Revision: 6391
Modified:
extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/query/PropertyQuery.java
Log:
javadoc
Modified: extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/query/PropertyQuery.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/query/PropertyQuery.java 2010-06-02 22:50:55 UTC (rev 6390)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/query/PropertyQuery.java 2010-06-02 23:05:13 UTC (rev 6391)
@@ -9,9 +9,16 @@
import org.jboss.weld.extensions.util.properties.Property;
/**
- * Queries a target class for properties that match certain criteria
+ * Queries a target class for properties that match certain criteria. A
+ * property may either be a private or public field, declared by the target
+ * class or inherited from a superclass, or a public method declared by the
+ * target class or inherited from any of its superclasses. For properties that
+ * are exposed via a method, the property must be a JavaBean style property, i.e.
+ * it must provide both an accessor and mutator method according to the JavaBean
+ * specification.
*
- * @see PropertyQueries
+ * This class is not thread-safe, however the result returned by the
+ * getResultList() method is.
*
* @author Shane Bryzak
*/
13 years, 11 months
Weld SVN: r6390 - extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/query.
by weld-commits@lists.jboss.org
Author: pete.muir(a)jboss.org
Date: 2010-06-02 18:50:55 -0400 (Wed, 02 Jun 2010)
New Revision: 6390
Modified:
extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/query/PropertyQueries.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/query/PropertyQuery.java
Log:
minor
Modified: extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/query/PropertyQueries.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/query/PropertyQueries.java 2010-06-02 22:49:11 UTC (rev 6389)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/query/PropertyQueries.java 2010-06-02 22:50:55 UTC (rev 6390)
@@ -5,6 +5,13 @@
private PropertyQueries() {}
+ /**
+ * Create a new {@link PropertyQuery}
+ *
+ * @param <V>
+ * @param targetClass
+ * @return
+ */
public static <V> PropertyQuery<V> createPropertyQuery(Class<?> targetClass)
{
return new PropertyQuery<V>(targetClass);
Modified: extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/query/PropertyQuery.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/query/PropertyQuery.java 2010-06-02 22:49:11 UTC (rev 6389)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/query/PropertyQuery.java 2010-06-02 22:50:55 UTC (rev 6390)
@@ -11,6 +11,8 @@
/**
* Queries a target class for properties that match certain criteria
*
+ * @see PropertyQueries
+ *
* @author Shane Bryzak
*/
public class PropertyQuery<V>
13 years, 11 months
Weld SVN: r6389 - extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/query.
by weld-commits@lists.jboss.org
Author: pete.muir(a)jboss.org
Date: 2010-06-02 18:49:11 -0400 (Wed, 02 Jun 2010)
New Revision: 6389
Added:
extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/query/PropertyQueries.java
Modified:
extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/query/PropertyQuery.java
Log:
introduce factory
Added: extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/query/PropertyQueries.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/query/PropertyQueries.java (rev 0)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/query/PropertyQueries.java 2010-06-02 22:49:11 UTC (rev 6389)
@@ -0,0 +1,13 @@
+package org.jboss.weld.extensions.util.properties.query;
+
+public class PropertyQueries
+{
+
+ private PropertyQueries() {}
+
+ public static <V> PropertyQuery<V> createPropertyQuery(Class<?> targetClass)
+ {
+ return new PropertyQuery<V>(targetClass);
+ }
+
+}
Property changes on: extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/query/PropertyQueries.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
Modified: extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/query/PropertyQuery.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/query/PropertyQuery.java 2010-06-02 22:43:33 UTC (rev 6388)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/query/PropertyQuery.java 2010-06-02 22:49:11 UTC (rev 6389)
@@ -18,7 +18,7 @@
private final Class<?> targetClass;
private final List<PropertyCriteria> criteria;
- public PropertyQuery(Class<?> targetClass)
+ PropertyQuery(Class<?> targetClass)
{
this.targetClass = targetClass;
this.criteria = new ArrayList<PropertyCriteria>();
13 years, 11 months
Weld SVN: r6388 - in extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties: query and 1 other directory.
by weld-commits@lists.jboss.org
Author: pete.muir(a)jboss.org
Date: 2010-06-02 18:43:33 -0400 (Wed, 02 Jun 2010)
New Revision: 6388
Added:
extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/query/PropertyQuery.java
Removed:
extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/query/BeanPropertyCriteria.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/query/BeanPropertyQuery.java
Modified:
extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/Property.java
Log:
rename
Modified: extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/Property.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/Property.java 2010-06-02 22:39:08 UTC (rev 6387)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/Property.java 2010-06-02 22:43:33 UTC (rev 6388)
@@ -53,6 +53,7 @@
*
* @param bean The bean to read the property from
* @return The property value
+ * @throws ClassCastException if the value is not of the type V
*/
public V getValue(Object instance);
Deleted: extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/query/BeanPropertyCriteria.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/query/BeanPropertyCriteria.java 2010-06-02 22:39:08 UTC (rev 6387)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/query/BeanPropertyCriteria.java 2010-06-02 22:43:33 UTC (rev 6388)
@@ -1,28 +0,0 @@
-package org.jboss.weld.extensions.util.properties.query;
-
-import java.lang.reflect.Field;
-import java.lang.reflect.Method;
-
-/**
- * Base interface for criteria used to locate bean properties
- *
- * @author Shane Bryzak
- */
-public interface BeanPropertyCriteria
-{
- /**
- * Tests whether the specified field matches the criteria
- *
- * @param f
- * @return true if the field matches
- */
- boolean fieldMatches(Field f);
-
- /**
- * Tests whether the specified method matches the criteria
- *
- * @param m
- * @return true if the method matches
- */
- boolean methodMatches(Method m);
-}
Deleted: extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/query/BeanPropertyQuery.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/query/BeanPropertyQuery.java 2010-06-02 22:39:08 UTC (rev 6387)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/query/BeanPropertyQuery.java 2010-06-02 22:43:33 UTC (rev 6388)
@@ -1,68 +0,0 @@
-package org.jboss.weld.extensions.util.properties.query;
-
-import java.lang.reflect.Field;
-import java.lang.reflect.Method;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.jboss.weld.extensions.util.properties.Properties;
-import org.jboss.weld.extensions.util.properties.Property;
-
-/**
- * Queries a target class for properties that match certain criteria
- *
- * @author Shane Bryzak
- */
-public class BeanPropertyQuery
-{
- private Class<?> targetClass;
- private List<BeanPropertyCriteria> criteria = new ArrayList<BeanPropertyCriteria>();
-
- public BeanPropertyQuery(Class<?> targetClass)
- {
- this.targetClass = targetClass;
- }
-
- public BeanPropertyQuery addCriteria(BeanPropertyCriteria criteria)
- {
- this.criteria.add(criteria);
- return this;
- }
-
- public List<Property<?>> getResultList()
- {
- List<Property<?>> results = new ArrayList<Property<?>>();
-
- Class<?> cls = targetClass;
- while (!cls.equals(Object.class))
- {
- // First check declared fields
- for (Field field : cls.getDeclaredFields())
- {
- for (BeanPropertyCriteria c : criteria)
- {
- if (c.fieldMatches(field))
- {
- results.add(Properties.createProperty(field));
- }
- }
- }
-
- cls = cls.getSuperclass();
- }
-
- // Then check public methods (we ignore private methods)
- for (Method method : targetClass.getMethods())
- {
- for (BeanPropertyCriteria c : criteria)
- {
- if (c.methodMatches(method))
- {
- results.add(Properties.createProperty(method));
- }
- }
- }
-
- return results;
- }
-}
Copied: extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/query/PropertyQuery.java (from rev 6386, extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/query/BeanPropertyQuery.java)
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/query/PropertyQuery.java (rev 0)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/query/PropertyQuery.java 2010-06-02 22:43:33 UTC (rev 6388)
@@ -0,0 +1,69 @@
+package org.jboss.weld.extensions.util.properties.query;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.jboss.weld.extensions.util.properties.Properties;
+import org.jboss.weld.extensions.util.properties.Property;
+
+/**
+ * Queries a target class for properties that match certain criteria
+ *
+ * @author Shane Bryzak
+ */
+public class PropertyQuery<V>
+{
+ private final Class<?> targetClass;
+ private final List<PropertyCriteria> criteria;
+
+ public PropertyQuery(Class<?> targetClass)
+ {
+ this.targetClass = targetClass;
+ this.criteria = new ArrayList<PropertyCriteria>();
+ }
+
+ public PropertyQuery<V> addCriteria(PropertyCriteria criteria)
+ {
+ this.criteria.add(criteria);
+ return this;
+ }
+
+ public List<Property<V>> getResultList()
+ {
+ List<Property<V>> results = new ArrayList<Property<V>>();
+
+ Class<?> cls = targetClass;
+ while (!cls.equals(Object.class))
+ {
+ // First check declared fields
+ for (Field field : cls.getDeclaredFields())
+ {
+ for (PropertyCriteria c : criteria)
+ {
+ if (c.fieldMatches(field))
+ {
+ results.add(Properties.<V>createProperty(field));
+ }
+ }
+ }
+
+ cls = cls.getSuperclass();
+ }
+
+ // Then check public methods (we ignore private methods)
+ for (Method method : targetClass.getMethods())
+ {
+ for (PropertyCriteria c : criteria)
+ {
+ if (c.methodMatches(method))
+ {
+ results.add(Properties.<V>createProperty(method));
+ }
+ }
+ }
+
+ return results;
+ }
+}
13 years, 11 months
Weld SVN: r6387 - extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/query.
by weld-commits@lists.jboss.org
Author: pete.muir(a)jboss.org
Date: 2010-06-02 18:39:08 -0400 (Wed, 02 Jun 2010)
New Revision: 6387
Added:
extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/query/PropertyCriteria.java
Modified:
extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/query/AnnotatedPropertyCriteria.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/query/NamedPropertyCriteria.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/query/TypedPropertyCriteria.java
Log:
minor
Modified: extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/query/AnnotatedPropertyCriteria.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/query/AnnotatedPropertyCriteria.java 2010-06-02 22:32:24 UTC (rev 6386)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/query/AnnotatedPropertyCriteria.java 2010-06-02 22:39:08 UTC (rev 6387)
@@ -9,9 +9,9 @@
*
* @author Shane Bryzak
*/
-public class AnnotatedPropertyCriteria implements BeanPropertyCriteria
+public class AnnotatedPropertyCriteria implements PropertyCriteria
{
- private Class<? extends Annotation> annotationClass;
+ private final Class<? extends Annotation> annotationClass;
public AnnotatedPropertyCriteria(Class<? extends Annotation> annotationClass)
{
Modified: extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/query/NamedPropertyCriteria.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/query/NamedPropertyCriteria.java 2010-06-02 22:32:24 UTC (rev 6386)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/query/NamedPropertyCriteria.java 2010-06-02 22:39:08 UTC (rev 6387)
@@ -9,9 +9,9 @@
*
* @author Shane Bryzak
*/
-public class NamedPropertyCriteria implements BeanPropertyCriteria
+public class NamedPropertyCriteria implements PropertyCriteria
{
- private String propertyName;
+ private final String propertyName;
public NamedPropertyCriteria(String propertyName)
{
Copied: extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/query/PropertyCriteria.java (from rev 6386, extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/query/BeanPropertyCriteria.java)
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/query/PropertyCriteria.java (rev 0)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/query/PropertyCriteria.java 2010-06-02 22:39:08 UTC (rev 6387)
@@ -0,0 +1,28 @@
+package org.jboss.weld.extensions.util.properties.query;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+
+/**
+ * Base interface for criteria used to locate bean properties
+ *
+ * @author Shane Bryzak
+ */
+public interface PropertyCriteria
+{
+ /**
+ * Tests whether the specified field matches the criteria
+ *
+ * @param f
+ * @return true if the field matches
+ */
+ boolean fieldMatches(Field f);
+
+ /**
+ * Tests whether the specified method matches the criteria
+ *
+ * @param m
+ * @return true if the method matches
+ */
+ boolean methodMatches(Method m);
+}
Modified: extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/query/TypedPropertyCriteria.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/query/TypedPropertyCriteria.java 2010-06-02 22:32:24 UTC (rev 6386)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/query/TypedPropertyCriteria.java 2010-06-02 22:39:08 UTC (rev 6387)
@@ -8,9 +8,9 @@
*
* @author Shane Bryzak
*/
-public class TypedPropertyCriteria implements BeanPropertyCriteria
+public class TypedPropertyCriteria implements PropertyCriteria
{
- private Class<?> propertyClass;
+ private final Class<?> propertyClass;
public TypedPropertyCriteria(Class<?> propertyClass)
{
13 years, 11 months
Weld SVN: r6386 - in extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties: query and 1 other directory.
by weld-commits@lists.jboss.org
Author: pete.muir(a)jboss.org
Date: 2010-06-02 18:32:24 -0400 (Wed, 02 Jun 2010)
New Revision: 6386
Added:
extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/FieldPropertyImpl.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/MethodPropertyImpl.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/query/
extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/query/AnnotatedPropertyCriteria.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/query/BeanPropertyCriteria.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/query/BeanPropertyQuery.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/query/NamedPropertyCriteria.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/query/TypedPropertyCriteria.java
Removed:
extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/AnnotatedPropertyCriteria.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/BeanPropertyCriteria.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/BeanPropertyQuery.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/NamedPropertyCriteria.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/TypedPropertyCriteria.java
Modified:
extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/FieldProperty.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/MethodProperty.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/Properties.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/Property.java
Log:
extract interfaces for MethodProperty, FieldProperty
Deleted: extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/AnnotatedPropertyCriteria.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/AnnotatedPropertyCriteria.java 2010-06-02 22:23:35 UTC (rev 6385)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/AnnotatedPropertyCriteria.java 2010-06-02 22:32:24 UTC (rev 6386)
@@ -1,31 +0,0 @@
-package org.jboss.weld.extensions.util.properties;
-
-import java.lang.annotation.Annotation;
-import java.lang.reflect.Field;
-import java.lang.reflect.Method;
-
-/**
- * A criteria that matches a property based on its annotations
- *
- * @author Shane Bryzak
- */
-public class AnnotatedPropertyCriteria implements BeanPropertyCriteria
-{
- private Class<? extends Annotation> annotationClass;
-
- public AnnotatedPropertyCriteria(Class<? extends Annotation> annotationClass)
- {
- this.annotationClass = annotationClass;
- }
-
- public boolean fieldMatches(Field f)
- {
- return f.isAnnotationPresent(annotationClass);
- }
-
- public boolean methodMatches(Method m)
- {
- return m.isAnnotationPresent(annotationClass);
- }
-
-}
Deleted: extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/BeanPropertyCriteria.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/BeanPropertyCriteria.java 2010-06-02 22:23:35 UTC (rev 6385)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/BeanPropertyCriteria.java 2010-06-02 22:32:24 UTC (rev 6386)
@@ -1,28 +0,0 @@
-package org.jboss.weld.extensions.util.properties;
-
-import java.lang.reflect.Field;
-import java.lang.reflect.Method;
-
-/**
- * Base interface for criteria used to locate bean properties
- *
- * @author Shane Bryzak
- */
-public interface BeanPropertyCriteria
-{
- /**
- * Tests whether the specified field matches the criteria
- *
- * @param f
- * @return true if the field matches
- */
- boolean fieldMatches(Field f);
-
- /**
- * Tests whether the specified method matches the criteria
- *
- * @param m
- * @return true if the method matches
- */
- boolean methodMatches(Method m);
-}
Deleted: extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/BeanPropertyQuery.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/BeanPropertyQuery.java 2010-06-02 22:23:35 UTC (rev 6385)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/BeanPropertyQuery.java 2010-06-02 22:32:24 UTC (rev 6386)
@@ -1,65 +0,0 @@
-package org.jboss.weld.extensions.util.properties;
-
-import java.lang.reflect.Field;
-import java.lang.reflect.Method;
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * Queries a target class for properties that match certain criteria
- *
- * @author Shane Bryzak
- */
-public class BeanPropertyQuery
-{
- private Class<?> targetClass;
- private List<BeanPropertyCriteria> criteria = new ArrayList<BeanPropertyCriteria>();
-
- public BeanPropertyQuery(Class<?> targetClass)
- {
- this.targetClass = targetClass;
- }
-
- public BeanPropertyQuery addCriteria(BeanPropertyCriteria criteria)
- {
- this.criteria.add(criteria);
- return this;
- }
-
- public List<Property<?>> getResultList()
- {
- List<Property<?>> results = new ArrayList<Property<?>>();
-
- Class<?> cls = targetClass;
- while (!cls.equals(Object.class))
- {
- // First check declared fields
- for (Field field : cls.getDeclaredFields())
- {
- for (BeanPropertyCriteria c : criteria)
- {
- if (c.fieldMatches(field))
- {
- results.add(Properties.createProperty(field));
- }
- }
- }
-
- cls = cls.getSuperclass();
- }
-
- // Then check public methods (we ignore private methods)
- for (Method method : targetClass.getMethods())
- {
- for (BeanPropertyCriteria c : criteria)
- {
- if (c.methodMatches(method))
- {
- results.add(Properties.createProperty(method));
- }
- }
- }
-
- return results;
- }
-}
Modified: extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/FieldProperty.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/FieldProperty.java 2010-06-02 22:23:35 UTC (rev 6385)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/FieldProperty.java 2010-06-02 22:32:24 UTC (rev 6386)
@@ -1,95 +1,11 @@
-/**
- *
- */
package org.jboss.weld.extensions.util.properties;
-import java.lang.reflect.AnnotatedElement;
import java.lang.reflect.Field;
-import java.lang.reflect.Type;
-/**
- * A bean property based on the value contained in a field
- *
- * @author Pete Muir
- * @author Shane Bryzak
- *
- */
-class FieldProperty<V> implements Property<V>
+
+public interface FieldProperty<V> extends Property<V>
{
- private static String buildGetFieldValueErrorMessage(Field field, Object obj)
- {
- return String.format("Exception reading [%s] field from object [%s].", field.getName(), obj);
- }
-
- private static String buildSetFieldValueErrorMessage(Field field, Object obj, Object value)
- {
- return String.format("Exception setting [%s] field on object [%s] to value [%s]", field.getName(), obj, value);
- }
-
- private final Field field;
- FieldProperty(Field field)
- {
- this.field = field;
- }
-
- public String getName()
- {
- return field.getName();
- }
-
- public Type getBaseType()
- {
- return field.getGenericType();
- }
-
- public AnnotatedElement getAnnotatedElement()
- {
- return field;
- }
-
- @SuppressWarnings("unchecked")
- public Class<V> getJavaClass()
- {
- return (Class<V>) field.getType();
- }
-
- public V getValue(Object instance)
- {
- field.setAccessible(true);
- try
- {
- return getJavaClass().cast(field.get(instance));
- }
- catch (IllegalAccessException e)
- {
- throw new RuntimeException(buildGetFieldValueErrorMessage(field, instance), e);
- }
- catch (NullPointerException ex)
- {
- NullPointerException ex2 = new NullPointerException(buildGetFieldValueErrorMessage(field, instance));
- ex2.initCause(ex.getCause());
- throw ex2;
- }
- }
-
- public void setValue(Object instance, V value)
- {
- field.setAccessible(true);
- try
- {
- field.set(instance, value);
- }
- catch (IllegalAccessException e)
- {
- throw new RuntimeException(buildSetFieldValueErrorMessage(field, instance, value), e);
- }
- catch (NullPointerException ex)
- {
- NullPointerException ex2 = new NullPointerException(buildSetFieldValueErrorMessage(field, instance, value));
- ex2.initCause(ex.getCause());
- throw ex2;
- }
- }
-
+ public Field getAnnotatedElement();
+
}
\ No newline at end of file
Copied: extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/FieldPropertyImpl.java (from rev 6384, extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/FieldProperty.java)
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/FieldPropertyImpl.java (rev 0)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/FieldPropertyImpl.java 2010-06-02 22:32:24 UTC (rev 6386)
@@ -0,0 +1,94 @@
+/**
+ *
+ */
+package org.jboss.weld.extensions.util.properties;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Type;
+
+/**
+ * A bean property based on the value contained in a field
+ *
+ * @author Pete Muir
+ * @author Shane Bryzak
+ *
+ */
+class FieldPropertyImpl<V> implements FieldProperty<V>
+{
+ private static String buildGetFieldValueErrorMessage(Field field, Object obj)
+ {
+ return String.format("Exception reading [%s] field from object [%s].", field.getName(), obj);
+ }
+
+ private static String buildSetFieldValueErrorMessage(Field field, Object obj, Object value)
+ {
+ return String.format("Exception setting [%s] field on object [%s] to value [%s]", field.getName(), obj, value);
+ }
+
+ private final Field field;
+
+ FieldPropertyImpl(Field field)
+ {
+ this.field = field;
+ }
+
+ public String getName()
+ {
+ return field.getName();
+ }
+
+ public Type getBaseType()
+ {
+ return field.getGenericType();
+ }
+
+ public Field getAnnotatedElement()
+ {
+ return field;
+ }
+
+ @SuppressWarnings("unchecked")
+ public Class<V> getJavaClass()
+ {
+ return (Class<V>) field.getType();
+ }
+
+ public V getValue(Object instance)
+ {
+ field.setAccessible(true);
+ try
+ {
+ return getJavaClass().cast(field.get(instance));
+ }
+ catch (IllegalAccessException e)
+ {
+ throw new RuntimeException(buildGetFieldValueErrorMessage(field, instance), e);
+ }
+ catch (NullPointerException ex)
+ {
+ NullPointerException ex2 = new NullPointerException(buildGetFieldValueErrorMessage(field, instance));
+ ex2.initCause(ex.getCause());
+ throw ex2;
+ }
+ }
+
+ public void setValue(Object instance, V value)
+ {
+ field.setAccessible(true);
+ try
+ {
+ field.set(instance, value);
+ }
+ catch (IllegalAccessException e)
+ {
+ throw new RuntimeException(buildSetFieldValueErrorMessage(field, instance, value), e);
+ }
+ catch (NullPointerException ex)
+ {
+ NullPointerException ex2 = new NullPointerException(buildSetFieldValueErrorMessage(field, instance, value));
+ ex2.initCause(ex.getCause());
+ throw ex2;
+ }
+ }
+
+}
\ No newline at end of file
Modified: extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/MethodProperty.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/MethodProperty.java 2010-06-02 22:23:35 UTC (rev 6385)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/MethodProperty.java 2010-06-02 22:32:24 UTC (rev 6386)
@@ -1,152 +1,11 @@
package org.jboss.weld.extensions.util.properties;
-import java.beans.Introspector;
-import java.lang.reflect.AnnotatedElement;
-import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
-import java.lang.reflect.Type;
-/**
- * A bean property based on the value represented by a getter/setter method pair
- *
- * @author Pete Muir
- * @author Shane Bryzak
- */
-class MethodProperty<V> implements Property<V>
-{
- private final Method getterMethod;
- private final String propertyName;
- private final Method setterMethod;
- public MethodProperty(Method method)
- {
- if (method.getName().startsWith("get"))
- {
- this.propertyName = Introspector.decapitalize(method.getName().substring(3));
- }
- else if (method.getName().startsWith("is"))
- {
- this.propertyName = Introspector.decapitalize(method.getName().substring(2));
- }
- else
- {
- throw new IllegalArgumentException("Invalid accessor method, must start with 'get' or 'is'. " + "Method: " + method);
- }
- this.getterMethod = getGetterMethod(method.getDeclaringClass(), propertyName);
- this.setterMethod = getSetterMethod(method.getDeclaringClass(), propertyName);
- }
-
- public String getName()
- {
- return propertyName;
- }
-
- @SuppressWarnings("unchecked")
- public Class<V> getJavaClass()
- {
- return (Class<V>) getterMethod.getReturnType();
- }
-
- public Type getBaseType()
- {
- return getterMethod.getGenericReturnType();
- }
-
- public AnnotatedElement getAnnotatedElement()
- {
- return getterMethod;
- }
-
- public V getValue(Object instance)
- {
- return getJavaClass().cast(invokeMethod(getterMethod, instance));
- }
-
- public void setValue(Object instance, Object value)
- {
- invokeMethod(setterMethod, instance, value);
- }
-
- private static String buildInvokeMethodErrorMessage(Method method, Object obj, Object... args)
- {
- StringBuilder message = new StringBuilder(String.format("Exception invoking method [%s] on object [%s], using arguments [", method.getName(), obj));
- if (args != null)
- for (int i = 0; i < args.length; i++)
- message.append((i > 0 ? "," : "") + args[i]);
- message.append("]");
- return message.toString();
- }
-
- private static Object invokeMethod(Method method, Object obj, Object... args)
- {
- try
- {
- return method.invoke(obj, args);
- }
- catch (IllegalAccessException ex)
- {
- throw new RuntimeException(buildInvokeMethodErrorMessage(method, obj, args), ex);
- }
- catch (IllegalArgumentException ex)
- {
- throw new IllegalArgumentException(buildInvokeMethodErrorMessage(method, obj, args), ex.getCause());
- }
- catch (InvocationTargetException ex)
- {
- throw new RuntimeException(buildInvokeMethodErrorMessage(method, obj, args), ex);
- }
- catch (NullPointerException ex)
- {
- NullPointerException ex2 = new NullPointerException(buildInvokeMethodErrorMessage(method, obj, args));
- ex2.initCause(ex.getCause());
- throw ex2;
- }
- catch (ExceptionInInitializerError e)
- {
- throw new RuntimeException(buildInvokeMethodErrorMessage(method, obj, args), e);
- }
- }
-
- private static Method getSetterMethod(Class<?> clazz, String name)
- {
- Method[] methods = clazz.getMethods();
- for (Method method : methods)
- {
- String methodName = method.getName();
- if (methodName.startsWith("set") && method.getParameterTypes().length == 1)
- {
- if (Introspector.decapitalize(methodName.substring(3)).equals(name))
- {
- return method;
- }
- }
- }
- throw new IllegalArgumentException("no such setter method: " + clazz.getName() + '.' + name);
- }
+public interface MethodProperty<V> extends Property<V>
+{
- private static Method getGetterMethod(Class<?> clazz, String name)
- {
- for (Method method : clazz.getDeclaredMethods())
- {
- String methodName = method.getName();
- if (method.getParameterTypes().length == 0)
- {
- if (methodName.startsWith("get"))
- {
- if (Introspector.decapitalize(methodName.substring(3)).equals(name))
- {
- return method;
- }
- }
- else if (methodName.startsWith("is"))
- {
- if (Introspector.decapitalize(methodName.substring(2)).equals(name))
- {
- return method;
- }
- }
- }
- }
- throw new IllegalArgumentException("no such getter method: " + clazz.getName() + '.' + name);
- }
+ public Method getAnnotatedElement();
+
}
\ No newline at end of file
Copied: extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/MethodPropertyImpl.java (from rev 6384, extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/MethodProperty.java)
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/MethodPropertyImpl.java (rev 0)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/MethodPropertyImpl.java 2010-06-02 22:32:24 UTC (rev 6386)
@@ -0,0 +1,154 @@
+/**
+ *
+ */
+package org.jboss.weld.extensions.util.properties;
+
+import java.beans.Introspector;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.lang.reflect.Type;
+
+/**
+ * A bean property based on the value represented by a getter/setter method pair
+ *
+ * @author Pete Muir
+ * @author Shane Bryzak
+ */
+class MethodPropertyImpl<V> implements MethodProperty<V>
+{
+ private final Method getterMethod;
+ private final String propertyName;
+ private final Method setterMethod;
+
+ public MethodPropertyImpl(Method method)
+ {
+ if (method.getName().startsWith("get"))
+ {
+ this.propertyName = Introspector.decapitalize(method.getName().substring(3));
+ }
+ else if (method.getName().startsWith("is"))
+ {
+ this.propertyName = Introspector.decapitalize(method.getName().substring(2));
+ }
+ else
+ {
+ throw new IllegalArgumentException("Invalid accessor method, must start with 'get' or 'is'. " + "Method: " + method);
+ }
+ this.getterMethod = getGetterMethod(method.getDeclaringClass(), propertyName);
+ this.setterMethod = getSetterMethod(method.getDeclaringClass(), propertyName);
+ }
+
+ public String getName()
+ {
+ return propertyName;
+ }
+
+ @SuppressWarnings("unchecked")
+ public Class<V> getJavaClass()
+ {
+ return (Class<V>) getterMethod.getReturnType();
+ }
+
+ public Type getBaseType()
+ {
+ return getterMethod.getGenericReturnType();
+ }
+
+ public Method getAnnotatedElement()
+ {
+ return getterMethod;
+ }
+
+ public V getValue(Object instance)
+ {
+ return getJavaClass().cast(invokeMethod(getterMethod, instance));
+ }
+
+ public void setValue(Object instance, Object value)
+ {
+ invokeMethod(setterMethod, instance, value);
+ }
+
+ private static String buildInvokeMethodErrorMessage(Method method, Object obj, Object... args)
+ {
+ StringBuilder message = new StringBuilder(String.format("Exception invoking method [%s] on object [%s], using arguments [", method.getName(), obj));
+ if (args != null)
+ for (int i = 0; i < args.length; i++)
+ message.append((i > 0 ? "," : "") + args[i]);
+ message.append("]");
+ return message.toString();
+ }
+
+ private static Object invokeMethod(Method method, Object obj, Object... args)
+ {
+ try
+ {
+ return method.invoke(obj, args);
+ }
+ catch (IllegalAccessException ex)
+ {
+ throw new RuntimeException(buildInvokeMethodErrorMessage(method, obj, args), ex);
+ }
+ catch (IllegalArgumentException ex)
+ {
+ throw new IllegalArgumentException(buildInvokeMethodErrorMessage(method, obj, args), ex.getCause());
+ }
+ catch (InvocationTargetException ex)
+ {
+ throw new RuntimeException(buildInvokeMethodErrorMessage(method, obj, args), ex);
+ }
+ catch (NullPointerException ex)
+ {
+ NullPointerException ex2 = new NullPointerException(buildInvokeMethodErrorMessage(method, obj, args));
+ ex2.initCause(ex.getCause());
+ throw ex2;
+ }
+ catch (ExceptionInInitializerError e)
+ {
+ throw new RuntimeException(buildInvokeMethodErrorMessage(method, obj, args), e);
+ }
+ }
+
+ private static Method getSetterMethod(Class<?> clazz, String name)
+ {
+ Method[] methods = clazz.getMethods();
+ for (Method method : methods)
+ {
+ String methodName = method.getName();
+ if (methodName.startsWith("set") && method.getParameterTypes().length == 1)
+ {
+ if (Introspector.decapitalize(methodName.substring(3)).equals(name))
+ {
+ return method;
+ }
+ }
+ }
+ throw new IllegalArgumentException("no such setter method: " + clazz.getName() + '.' + name);
+ }
+
+ private static Method getGetterMethod(Class<?> clazz, String name)
+ {
+ for (Method method : clazz.getDeclaredMethods())
+ {
+ String methodName = method.getName();
+ if (method.getParameterTypes().length == 0)
+ {
+ if (methodName.startsWith("get"))
+ {
+ if (Introspector.decapitalize(methodName.substring(3)).equals(name))
+ {
+ return method;
+ }
+ }
+ else if (methodName.startsWith("is"))
+ {
+ if (Introspector.decapitalize(methodName.substring(2)).equals(name))
+ {
+ return method;
+ }
+ }
+ }
+ }
+ throw new IllegalArgumentException("no such getter method: " + clazz.getName() + '.' + name);
+ }
+}
\ No newline at end of file
Deleted: extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/NamedPropertyCriteria.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/NamedPropertyCriteria.java 2010-06-02 22:23:35 UTC (rev 6385)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/NamedPropertyCriteria.java 2010-06-02 22:32:24 UTC (rev 6386)
@@ -1,31 +0,0 @@
-package org.jboss.weld.extensions.util.properties;
-
-import java.beans.Introspector;
-import java.lang.reflect.Field;
-import java.lang.reflect.Method;
-
-/**
- * A criteria that matches a property based on name
- *
- * @author Shane Bryzak
- */
-public class NamedPropertyCriteria implements BeanPropertyCriteria
-{
- private String propertyName;
-
- public NamedPropertyCriteria(String propertyName)
- {
- this.propertyName = propertyName;
- }
-
- public boolean fieldMatches(Field f)
- {
- return propertyName.equals(f.getName());
- }
-
- public boolean methodMatches(Method m)
- {
- return m.getName().startsWith("get") &&
- Introspector.decapitalize(m.getName().substring(3)).equals(propertyName);
- }
-}
Modified: extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/Properties.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/Properties.java 2010-06-02 22:23:35 UTC (rev 6385)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/Properties.java 2010-06-02 22:32:24 UTC (rev 6386)
@@ -21,9 +21,9 @@
* @param field
* @return
*/
- public static <V> Property<V> createProperty(Field field)
+ public static <V> FieldProperty<V> createProperty(Field field)
{
- return new FieldProperty<V>(field);
+ return new FieldPropertyImpl<V>(field);
}
/**
@@ -34,8 +34,8 @@
* @return
* @throws IllegalArgumentException if the method does not match JavaBean conventions
*/
- public static <V> Property<V> createProperty(Method method)
+ public static <V> MethodProperty<V> createProperty(Method method)
{
- return new MethodProperty<V>(method);
+ return new MethodPropertyImpl<V>(method);
}
}
Modified: extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/Property.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/Property.java 2010-06-02 22:23:35 UTC (rev 6385)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/Property.java 2010-06-02 22:32:24 UTC (rev 6386)
@@ -24,32 +24,37 @@
*
* @return The name of the property
*/
- String getName();
+ public String getName();
/**
* Returns the property type
*
* @return The property type
*/
- Type getBaseType();
+ public Type getBaseType();
/**
* Returns the property type
*
* @return The property type
*/
- Class<V> getJavaClass();
-
- AnnotatedElement getAnnotatedElement();
+ public Class<V> getJavaClass();
/**
+ * Get the element backing the property
+ *
+ * @return
+ */
+ public AnnotatedElement getAnnotatedElement();
+
+ /**
* Returns the property value for the specified bean. The property to be
* returned is either a field or getter method.
*
* @param bean The bean to read the property from
* @return The property value
*/
- V getValue(Object instance);
+ public V getValue(Object instance);
/**
* This method sets the property value for a specified bean to the specified
@@ -58,5 +63,5 @@
* @param bean The bean containing the property to set
* @param value The new property value
*/
- void setValue(Object instance, V value);
+ public void setValue(Object instance, V value);
}
\ No newline at end of file
Deleted: extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/TypedPropertyCriteria.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/TypedPropertyCriteria.java 2010-06-02 22:23:35 UTC (rev 6385)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/TypedPropertyCriteria.java 2010-06-02 22:32:24 UTC (rev 6386)
@@ -1,29 +0,0 @@
-package org.jboss.weld.extensions.util.properties;
-
-import java.lang.reflect.Field;
-import java.lang.reflect.Method;
-
-/**
- * A criteria that matches a property based on its type
- *
- * @author Shane Bryzak
- */
-public class TypedPropertyCriteria implements BeanPropertyCriteria
-{
- private Class<?> propertyClass;
-
- public TypedPropertyCriteria(Class<?> propertyClass)
- {
- this.propertyClass = propertyClass;
- }
-
- public boolean fieldMatches(Field f)
- {
- return propertyClass.equals(f.getType());
- }
-
- public boolean methodMatches(Method m)
- {
- return propertyClass.equals(m.getReturnType());
- }
-}
Copied: extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/query/AnnotatedPropertyCriteria.java (from rev 6384, extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/AnnotatedPropertyCriteria.java)
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/query/AnnotatedPropertyCriteria.java (rev 0)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/query/AnnotatedPropertyCriteria.java 2010-06-02 22:32:24 UTC (rev 6386)
@@ -0,0 +1,31 @@
+package org.jboss.weld.extensions.util.properties.query;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+
+/**
+ * A criteria that matches a property based on its annotations
+ *
+ * @author Shane Bryzak
+ */
+public class AnnotatedPropertyCriteria implements BeanPropertyCriteria
+{
+ private Class<? extends Annotation> annotationClass;
+
+ public AnnotatedPropertyCriteria(Class<? extends Annotation> annotationClass)
+ {
+ this.annotationClass = annotationClass;
+ }
+
+ public boolean fieldMatches(Field f)
+ {
+ return f.isAnnotationPresent(annotationClass);
+ }
+
+ public boolean methodMatches(Method m)
+ {
+ return m.isAnnotationPresent(annotationClass);
+ }
+
+}
Copied: extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/query/BeanPropertyCriteria.java (from rev 6384, extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/BeanPropertyCriteria.java)
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/query/BeanPropertyCriteria.java (rev 0)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/query/BeanPropertyCriteria.java 2010-06-02 22:32:24 UTC (rev 6386)
@@ -0,0 +1,28 @@
+package org.jboss.weld.extensions.util.properties.query;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+
+/**
+ * Base interface for criteria used to locate bean properties
+ *
+ * @author Shane Bryzak
+ */
+public interface BeanPropertyCriteria
+{
+ /**
+ * Tests whether the specified field matches the criteria
+ *
+ * @param f
+ * @return true if the field matches
+ */
+ boolean fieldMatches(Field f);
+
+ /**
+ * Tests whether the specified method matches the criteria
+ *
+ * @param m
+ * @return true if the method matches
+ */
+ boolean methodMatches(Method m);
+}
Copied: extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/query/BeanPropertyQuery.java (from rev 6384, extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/BeanPropertyQuery.java)
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/query/BeanPropertyQuery.java (rev 0)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/query/BeanPropertyQuery.java 2010-06-02 22:32:24 UTC (rev 6386)
@@ -0,0 +1,68 @@
+package org.jboss.weld.extensions.util.properties.query;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.jboss.weld.extensions.util.properties.Properties;
+import org.jboss.weld.extensions.util.properties.Property;
+
+/**
+ * Queries a target class for properties that match certain criteria
+ *
+ * @author Shane Bryzak
+ */
+public class BeanPropertyQuery
+{
+ private Class<?> targetClass;
+ private List<BeanPropertyCriteria> criteria = new ArrayList<BeanPropertyCriteria>();
+
+ public BeanPropertyQuery(Class<?> targetClass)
+ {
+ this.targetClass = targetClass;
+ }
+
+ public BeanPropertyQuery addCriteria(BeanPropertyCriteria criteria)
+ {
+ this.criteria.add(criteria);
+ return this;
+ }
+
+ public List<Property<?>> getResultList()
+ {
+ List<Property<?>> results = new ArrayList<Property<?>>();
+
+ Class<?> cls = targetClass;
+ while (!cls.equals(Object.class))
+ {
+ // First check declared fields
+ for (Field field : cls.getDeclaredFields())
+ {
+ for (BeanPropertyCriteria c : criteria)
+ {
+ if (c.fieldMatches(field))
+ {
+ results.add(Properties.createProperty(field));
+ }
+ }
+ }
+
+ cls = cls.getSuperclass();
+ }
+
+ // Then check public methods (we ignore private methods)
+ for (Method method : targetClass.getMethods())
+ {
+ for (BeanPropertyCriteria c : criteria)
+ {
+ if (c.methodMatches(method))
+ {
+ results.add(Properties.createProperty(method));
+ }
+ }
+ }
+
+ return results;
+ }
+}
Copied: extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/query/NamedPropertyCriteria.java (from rev 6384, extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/NamedPropertyCriteria.java)
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/query/NamedPropertyCriteria.java (rev 0)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/query/NamedPropertyCriteria.java 2010-06-02 22:32:24 UTC (rev 6386)
@@ -0,0 +1,31 @@
+package org.jboss.weld.extensions.util.properties.query;
+
+import java.beans.Introspector;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+
+/**
+ * A criteria that matches a property based on name
+ *
+ * @author Shane Bryzak
+ */
+public class NamedPropertyCriteria implements BeanPropertyCriteria
+{
+ private String propertyName;
+
+ public NamedPropertyCriteria(String propertyName)
+ {
+ this.propertyName = propertyName;
+ }
+
+ public boolean fieldMatches(Field f)
+ {
+ return propertyName.equals(f.getName());
+ }
+
+ public boolean methodMatches(Method m)
+ {
+ return m.getName().startsWith("get") &&
+ Introspector.decapitalize(m.getName().substring(3)).equals(propertyName);
+ }
+}
Copied: extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/query/TypedPropertyCriteria.java (from rev 6384, extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/TypedPropertyCriteria.java)
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/query/TypedPropertyCriteria.java (rev 0)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/query/TypedPropertyCriteria.java 2010-06-02 22:32:24 UTC (rev 6386)
@@ -0,0 +1,29 @@
+package org.jboss.weld.extensions.util.properties.query;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+
+/**
+ * A criteria that matches a property based on its type
+ *
+ * @author Shane Bryzak
+ */
+public class TypedPropertyCriteria implements BeanPropertyCriteria
+{
+ private Class<?> propertyClass;
+
+ public TypedPropertyCriteria(Class<?> propertyClass)
+ {
+ this.propertyClass = propertyClass;
+ }
+
+ public boolean fieldMatches(Field f)
+ {
+ return propertyClass.equals(f.getType());
+ }
+
+ public boolean methodMatches(Method m)
+ {
+ return propertyClass.equals(m.getReturnType());
+ }
+}
13 years, 11 months
Weld SVN: r6385 - extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties.
by weld-commits@lists.jboss.org
Author: shane.bryzak(a)jboss.com
Date: 2010-06-02 18:23:35 -0400 (Wed, 02 Jun 2010)
New Revision: 6385
Modified:
extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/FieldProperty.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/MethodProperty.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/Property.java
Log:
imports
Modified: extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/FieldProperty.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/FieldProperty.java 2010-06-02 22:22:02 UTC (rev 6384)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/FieldProperty.java 2010-06-02 22:23:35 UTC (rev 6385)
@@ -3,7 +3,6 @@
*/
package org.jboss.weld.extensions.util.properties;
-import java.lang.annotation.Annotation;
import java.lang.reflect.AnnotatedElement;
import java.lang.reflect.Field;
import java.lang.reflect.Type;
Modified: extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/MethodProperty.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/MethodProperty.java 2010-06-02 22:22:02 UTC (rev 6384)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/MethodProperty.java 2010-06-02 22:23:35 UTC (rev 6385)
@@ -1,10 +1,6 @@
-/**
- *
- */
package org.jboss.weld.extensions.util.properties;
import java.beans.Introspector;
-import java.lang.annotation.Annotation;
import java.lang.reflect.AnnotatedElement;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
Modified: extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/Property.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/Property.java 2010-06-02 22:22:02 UTC (rev 6384)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/Property.java 2010-06-02 22:23:35 UTC (rev 6385)
@@ -1,6 +1,5 @@
package org.jboss.weld.extensions.util.properties;
-import java.lang.annotation.Annotation;
import java.lang.reflect.AnnotatedElement;
import java.lang.reflect.Type;
13 years, 11 months
Weld SVN: r6384 - extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties.
by weld-commits@lists.jboss.org
Author: shane.bryzak(a)jboss.com
Date: 2010-06-02 18:22:02 -0400 (Wed, 02 Jun 2010)
New Revision: 6384
Modified:
extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/FieldProperty.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/MethodProperty.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/Property.java
Log:
revert getAnnotatedElement
Modified: extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/FieldProperty.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/FieldProperty.java 2010-06-02 22:20:02 UTC (rev 6383)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/FieldProperty.java 2010-06-02 22:22:02 UTC (rev 6384)
@@ -4,6 +4,7 @@
package org.jboss.weld.extensions.util.properties;
import java.lang.annotation.Annotation;
+import java.lang.reflect.AnnotatedElement;
import java.lang.reflect.Field;
import java.lang.reflect.Type;
@@ -43,9 +44,9 @@
return field.getGenericType();
}
- public <A extends Annotation> A getAnnotation(Class<A> annotationClass)
+ public AnnotatedElement getAnnotatedElement()
{
- return field.getAnnotation(annotationClass);
+ return field;
}
@SuppressWarnings("unchecked")
Modified: extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/MethodProperty.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/MethodProperty.java 2010-06-02 22:20:02 UTC (rev 6383)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/MethodProperty.java 2010-06-02 22:22:02 UTC (rev 6384)
@@ -5,6 +5,7 @@
import java.beans.Introspector;
import java.lang.annotation.Annotation;
+import java.lang.reflect.AnnotatedElement;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Type;
@@ -55,9 +56,9 @@
return getterMethod.getGenericReturnType();
}
- public <A extends Annotation> A getAnnotation(Class<A> annotationClass)
+ public AnnotatedElement getAnnotatedElement()
{
- return getterMethod.getAnnotation(annotationClass);
+ return getterMethod;
}
public V getValue(Object instance)
Modified: extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/Property.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/Property.java 2010-06-02 22:20:02 UTC (rev 6383)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/Property.java 2010-06-02 22:22:02 UTC (rev 6384)
@@ -1,6 +1,7 @@
package org.jboss.weld.extensions.util.properties;
import java.lang.annotation.Annotation;
+import java.lang.reflect.AnnotatedElement;
import java.lang.reflect.Type;
/**
@@ -39,17 +40,10 @@
* @return The property type
*/
Class<V> getJavaClass();
+
+ AnnotatedElement getAnnotatedElement();
/**
- * Returns the specified annotation, if it exists on the bean property
- *
- * @param <A>
- * @param annotationClass
- * @return
- */
- <A extends Annotation> A getAnnotation(Class<A> annotationClass);
-
- /**
* Returns the property value for the specified bean. The property to be
* returned is either a field or getter method.
*
13 years, 11 months