[webbeans-commits] Webbeans SVN: r352 - ri/trunk/webbeans-ri.
by webbeans-commits@lists.jboss.org
Author: nickarls
Date: 2008-11-21 17:38:06 -0500 (Fri, 21 Nov 2008)
New Revision: 352
Modified:
ri/trunk/webbeans-ri/pom.xml
Log:
unbreak build
Modified: ri/trunk/webbeans-ri/pom.xml
===================================================================
--- ri/trunk/webbeans-ri/pom.xml 2008-11-21 22:05:48 UTC (rev 351)
+++ ri/trunk/webbeans-ri/pom.xml 2008-11-21 22:38:06 UTC (rev 352)
@@ -38,7 +38,6 @@
<dependency>
<groupId>javax.ejb</groupId>
<artifactId>ejb-api</artifactId>
- <scope>test</scope>
</dependency>
<dependency>
16 years
[webbeans-commits] Webbeans SVN: r351 - ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/transaction.
by webbeans-commits@lists.jboss.org
Author: nickarls
Date: 2008-11-21 17:05:48 -0500 (Fri, 21 Nov 2008)
New Revision: 351
Added:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/transaction/TransactionListener.java
Log:
Added: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/transaction/TransactionListener.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/transaction/TransactionListener.java (rev 0)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/transaction/TransactionListener.java 2008-11-21 22:05:48 UTC (rev 351)
@@ -0,0 +1,49 @@
+package org.jboss.webbeans.transaction;
+
+import java.rmi.RemoteException;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.ejb.EJBException;
+import javax.ejb.SessionSynchronization;
+import javax.ejb.Stateful;
+import javax.ejb.TransactionAttribute;
+import javax.ejb.TransactionAttributeType;
+import javax.transaction.Status;
+import javax.transaction.Synchronization;
+import javax.webbeans.RequestScoped;
+
+@Stateful
+@RequestScoped
+(a)TransactionAttribute(TransactionAttributeType.SUPPORTS)
+public class TransactionListener implements SessionSynchronization
+{
+
+ private List<Synchronization> synchronizations = new ArrayList<Synchronization>();
+
+ public void afterBegin() throws EJBException, RemoteException
+ {
+ }
+
+ public void afterCompletion(boolean success) throws EJBException, RemoteException
+ {
+ for (Synchronization synchronization : synchronizations)
+ {
+ synchronization.afterCompletion(success ? Status.STATUS_COMMITTED : Status.STATUS_ROLLEDBACK);
+ }
+ synchronizations.clear();
+ }
+
+ public void beforeCompletion() throws EJBException, RemoteException
+ {
+ for (Synchronization synchronization : synchronizations)
+ {
+ synchronization.beforeCompletion();
+ }
+ }
+
+ public void registerSynhronization(Synchronization synchronization)
+ {
+ synchronizations.add(synchronization);
+ }
+}
16 years
[webbeans-commits] Webbeans SVN: r350 - in ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans: transaction and 1 other directory.
by webbeans-commits@lists.jboss.org
Author: nickarls
Date: 2008-11-21 15:22:22 -0500 (Fri, 21 Nov 2008)
New Revision: 350
Added:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/transaction/
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/transaction/EjbSynchronizations.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/transaction/LocalEjbSynchronizations.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/transaction/SynchronizationRegistry.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/transaction/Synchronizations.java
Log:
Ported over EJBSynchronizations and related classes for transactional events. Need to check what is needed and what is not...
Added: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/transaction/EjbSynchronizations.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/transaction/EjbSynchronizations.java (rev 0)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/transaction/EjbSynchronizations.java 2008-11-21 20:22:22 UTC (rev 350)
@@ -0,0 +1,89 @@
+package org.jboss.webbeans.transaction;
+
+import java.rmi.RemoteException;
+import java.util.LinkedList;
+
+import javax.ejb.EJBException;
+import javax.ejb.Remove;
+import javax.ejb.SessionSynchronization;
+import javax.ejb.Stateful;
+import javax.ejb.TransactionAttribute;
+import javax.ejb.TransactionAttributeType;
+import javax.transaction.Synchronization;
+import javax.webbeans.RequestScoped;
+
+@Stateful
+@RequestScoped
+(a)TransactionAttribute(TransactionAttributeType.SUPPORTS)
+public class EjbSynchronizations implements LocalEjbSynchronizations, SessionSynchronization
+{
+ protected LinkedList<SynchronizationRegistry> synchronizations = new LinkedList<SynchronizationRegistry>();
+ protected LinkedList<SynchronizationRegistry> committing = new LinkedList<SynchronizationRegistry>();
+
+ public void afterBegin()
+ {
+ synchronizations.addLast(new SynchronizationRegistry());
+ }
+
+ public void beforeCompletion() throws EJBException, RemoteException
+ {
+ SynchronizationRegistry synchronization = synchronizations.removeLast();
+ synchronization.beforeTransactionCompletion();
+ committing.addLast(synchronization);
+ }
+
+ public void afterCompletion(boolean success) throws EJBException, RemoteException
+ {
+ if (committing.isEmpty())
+ {
+ if (success)
+ {
+ throw new IllegalStateException("beforeCompletion was never called");
+ }
+ else
+ {
+ synchronizations.removeLast().afterTransactionCompletion(false);
+ }
+ }
+ else
+ {
+ committing.removeFirst().afterTransactionCompletion(success);
+ }
+ }
+
+ public boolean isAwareOfContainerTransactions()
+ {
+ return true;
+ }
+
+ public void afterTransactionBegin()
+ {
+ // noop, let JTA notify us
+ }
+
+ public void afterTransactionCommit(boolean success)
+ {
+ // noop, let JTA notify us
+ }
+
+ public void afterTransactionRollback()
+ {
+ // noop, let JTA notify us
+ }
+
+ public void beforeTransactionCommit()
+ {
+ // noop, let JTA notify us
+ }
+
+ public void registerSynchronization(Synchronization synchronization)
+ {
+ synchronizations.getLast().registerSynchronization(synchronization);
+ }
+
+ @Remove
+ public void destroy()
+ {
+ }
+
+}
Added: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/transaction/LocalEjbSynchronizations.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/transaction/LocalEjbSynchronizations.java (rev 0)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/transaction/LocalEjbSynchronizations.java 2008-11-21 20:22:22 UTC (rev 350)
@@ -0,0 +1,9 @@
+package org.jboss.webbeans.transaction;
+
+import javax.ejb.Local;
+
+@Local
+public interface LocalEjbSynchronizations extends Synchronizations
+{
+ public void destroy();
+}
Added: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/transaction/SynchronizationRegistry.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/transaction/SynchronizationRegistry.java (rev 0)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/transaction/SynchronizationRegistry.java 2008-11-21 20:22:22 UTC (rev 350)
@@ -0,0 +1,49 @@
+package org.jboss.webbeans.transaction;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.transaction.Status;
+import javax.transaction.Synchronization;
+
+class SynchronizationRegistry
+{
+ private List<Synchronization> synchronizations = new ArrayList<Synchronization>();
+
+ void registerSynchronization(Synchronization sync)
+ {
+ synchronizations.add(sync);
+ }
+
+ void afterTransactionCompletion(boolean success)
+ {
+ for (Synchronization synchronization : synchronizations)
+ {
+ try
+ {
+ synchronization.afterCompletion(success ? Status.STATUS_COMMITTED : Status.STATUS_ROLLEDBACK);
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
+ synchronizations.clear();
+ }
+
+ void beforeTransactionCompletion()
+ {
+ for (Synchronization synchronization : synchronizations)
+ {
+ try
+ {
+ synchronization.beforeCompletion();
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
+ }
+
+}
Added: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/transaction/Synchronizations.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/transaction/Synchronizations.java (rev 0)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/transaction/Synchronizations.java 2008-11-21 20:22:22 UTC (rev 350)
@@ -0,0 +1,13 @@
+package org.jboss.webbeans.transaction;
+
+import javax.transaction.Synchronization;
+
+public interface Synchronizations
+{
+ public void afterTransactionBegin();
+ public void afterTransactionCommit(boolean success);
+ public void afterTransactionRollback();
+ public void beforeTransactionCommit();
+ public void registerSynchronization(Synchronization sync);
+ public boolean isAwareOfContainerTransactions();
+}
\ No newline at end of file
16 years
[webbeans-commits] Webbeans SVN: r349 - in ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans: bean and 5 other directories.
by webbeans-commits@lists.jboss.org
Author: nickarls
Date: 2008-11-21 06:00:56 -0500 (Fri, 21 Nov 2008)
New Revision: 349
Modified:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ManagerImpl.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/MetaDataCache.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/Resolver.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/AbstractClassBean.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/MergedStereotypes.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/XmlEnterpriseBean.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/XmlSimpleBean.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/proxy/ProxyMethodHandler.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/proxy/ProxyPool.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/ContextMap.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/SessionBeanMap.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ejb/EjbMetaData.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/EventManager.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/BindingTypeModel.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/ScopeModel.java
Log:
toStrings
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ManagerImpl.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ManagerImpl.java 2008-11-21 10:16:45 UTC (rev 348)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ManagerImpl.java 2008-11-21 11:00:56 UTC (rev 349)
@@ -663,40 +663,36 @@
{
StringBuffer buffer = new StringBuffer();
- buffer.append("Enabled deployment types:\n");
+ buffer.append("Enabled deployment types: " + enabledDeploymentTypes.size() + "\n");
+ int i = 0;
for (Class<? extends Annotation> deploymentType : enabledDeploymentTypes)
{
- buffer.append(" " + deploymentType.getName() + "\n");
+ buffer.append(++i + " - " + deploymentType.getName() + "\n");
}
-
- buffer.append(eventManager.toString());
- buffer.append(metaDataCache.toString());
-
- buffer.append("Resolver:\n");
- buffer.append(resolver.toString());
-
- buffer.append("Context map:\n");
- buffer.append(contextMap.toString());
-
- buffer.append("Proxy pool:\n");
- buffer.append(proxyPool.toString());
-
+ buffer.append(eventManager.toString() + "\n");
+ buffer.append(metaDataCache.toString() + "\n");
+ buffer.append(resolver.toString() + "\n");
+ buffer.append(contextMap.toString() + "\n");
+ buffer.append(proxyPool.toString() + "\n");
buffer.append("Registered beans: " + beans.size() + "\n");
+ i = 0;
for (Bean<?> bean : beans)
{
- buffer.append(" " + bean.toString() + "\n");
+ buffer.append(++i + " - " + bean.toString() + "\n");
}
buffer.append("Registered decorators: " + decorators.size() + "\n");
+ i = 0;
for (Decorator decorator : decorators)
{
- buffer.append(" " + decorator.toString() + "\n");
+ buffer.append(++i + " - " + decorator.toString() + "\n");
}
buffer.append("Registered interceptors: " + interceptors.size() + "\n");
+ i = 0;
for (Interceptor interceptor : interceptors)
{
- buffer.append(" " + interceptor.toString() + "\n");
+ buffer.append(++i + " - " + interceptor.toString() + "\n");
}
return buffer.toString();
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/MetaDataCache.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/MetaDataCache.java 2008-11-21 10:16:45 UTC (rev 348)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/MetaDataCache.java 2008-11-21 11:00:56 UTC (rev 349)
@@ -61,7 +61,38 @@
{
return delegate;
}
-
+
+ @Override
+ public String toString()
+ {
+ StringBuffer buffer = new StringBuffer();
+ buffer.append("Binding types " + bindingTypes.size() + "\n");
+ int i = 0;
+ for (Entry<Class<? extends Annotation>, BindingTypeModel<?>> entry : bindingTypes.entrySet())
+ {
+ buffer.append(++i + " - " + entry.getKey().getName() + ": " + entry.getValue().toString() + "\n");
+ }
+ buffer.append("EJB metadata " + ejbMetaDataMap.size() + "\n");
+ i = 0;
+ for (Entry<Class<?>, EjbMetaData<?>> entry : ejbMetaDataMap.entrySet())
+ {
+ buffer.append(++i + " - " + entry.getKey().getName() + ": " + entry.getValue().toString());
+ }
+ buffer.append("Scopes " + scopes.size() + "\n");
+ i = 0;
+ for (Entry<Class<? extends Annotation>, ScopeModel<?>> entry : scopes.entrySet())
+ {
+ buffer.append(++i + " - " + entry.getKey().getName() + ": " + entry.getValue().toString());
+ }
+ buffer.append("Stereotypes " + stereotypes.size() + "\n");
+ i = 0;
+ for (Entry<Class<? extends Annotation>, StereotypeModel<?>> entry : stereotypes.entrySet())
+ {
+ buffer.append(++i + " - " + entry.getKey().getName() + ": " + entry.getValue().toString());
+ }
+ return buffer.toString();
+ }
+
}
@SuppressWarnings("unchecked")
@@ -80,6 +111,15 @@
return new ScopeModel<S>(type);
}
+ @Override
+ public String toString()
+ {
+ StringBuffer buffer = new StringBuffer();
+ buffer.append("Scope model map\n");
+ buffer.append(super.toString() + "\n");
+ return buffer.toString();
+ }
+
}
@SuppressWarnings("unchecked")
@@ -99,24 +139,11 @@
}
@Override
- public String toString() {
+ public String toString()
+ {
StringBuffer buffer = new StringBuffer();
- buffer.append("Binding types\n");
- for (Entry<Class<? extends Annotation>, BindingTypeModel<?>> entry : delegate.entrySet()) {
- buffer.append(entry.getKey().getName() + ": " + entry.getValue().toString() + "\n");
- }
- buffer.append("EJB metadata\n");
- for (Entry<Class<?>, EjbMetaData<?>> entry : ejbMetaDataMap.entrySet()) {
- buffer.append(entry.getKey().getName() + ": " + entry.getValue().toString());
- }
- buffer.append("Scopes\n");
- for (Entry<Class<? extends Annotation>, ScopeModel<?>> entry : scopes.entrySet()) {
- buffer.append(entry.getKey().getName() + ": " + entry.getValue().toString());
- }
- buffer.append("Stereotypes\n");
- for (Entry<Class<? extends Annotation>, StereotypeModel<?>> entry : stereotypes.entrySet()) {
- buffer.append(entry.getKey().getName() + ": " + entry.getValue().toString());
- }
+ buffer.append("Binding type model map\n");
+ buffer.append(super.toString() + "\n");
return buffer.toString();
}
}
@@ -149,6 +176,19 @@
return (EjbMetaData<T>) super.get(key);
}
+ @Override
+ public String toString()
+ {
+ StringBuffer buffer = new StringBuffer();
+ buffer.append("EJB metadata: " + delegate.size() + "\n");
+ int i = 0;
+ for (Entry<Class<?>, EjbMetaData<?>> entry : delegate.entrySet())
+ {
+ buffer.append(++i + " - " + entry.getKey().getName() + ": " + entry.getValue().toString() + "\n");
+ }
+ return buffer.toString();
+ }
+
}
private Map<Class<? extends Annotation>, StereotypeModel<?>> stereotypes = new HashMap<Class<? extends Annotation>, StereotypeModel<?>>();
@@ -189,13 +229,14 @@
{
StringBuffer buffer = new StringBuffer();
buffer.append("Metadata cache\n");
- buffer.append(bindingTypes.toString());
- buffer.append(ejbMetaDataMap.toString());
- buffer.append(scopes.toString());
- buffer.append("Stereotypes:\n");
+ buffer.append(bindingTypes.toString() + "\n");
+ buffer.append(ejbMetaDataMap.toString() + "\n");
+ buffer.append(scopes.toString() + "\n");
+ buffer.append("Stereotypes: " + stereotypes.size() + "\n");
+ int i = 0;
for (Entry<Class<? extends Annotation>, StereotypeModel<?>> entry : stereotypes.entrySet())
{
- buffer.append(entry.getKey().getName() + ": " + entry.getValue().toString() + "\n");
+ buffer.append(++i + " - " + entry.getKey().getName() + ": " + entry.getValue().toString() + "\n");
}
return buffer.toString();
}
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/Resolver.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/Resolver.java 2008-11-21 10:16:45 UTC (rev 348)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/Resolver.java 2008-11-21 11:00:56 UTC (rev 349)
@@ -27,6 +27,7 @@
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;
+import java.util.Map.Entry;
import javax.webbeans.NullableDependencyException;
import javax.webbeans.manager.Bean;
@@ -77,6 +78,15 @@
return delegate().hashCode();
}
+ @Override
+ public String toString()
+ {
+ StringBuffer buffer = new StringBuffer();
+ buffer.append("Resolvable annotation item\n");
+ buffer.append(delegate().toString() + "\n");
+ return buffer.toString();
+ }
+
}
// TODO Why can't we generify Set?
@@ -105,6 +115,15 @@
{
return delegate;
}
+
+ @Override
+ public String toString()
+ {
+ StringBuffer buffer = new StringBuffer();
+ buffer.append("Annotated item\n");
+ buffer.append(delegate().toString() + "\n");
+ return buffer.toString();
+ }
}
@@ -324,11 +343,25 @@
// TODO Auto-generated method stub
return null;
}
-
+
@Override
- public String toString() {
+ public String toString()
+ {
StringBuffer buffer = new StringBuffer();
- buffer.append("FIX ME!\n");
+ buffer.append("Resolver\n");
+ buffer.append(resolvedInjectionPoints.toString() + "\n");
+ buffer.append("Injection points: " + injectionPoints.size() + "\n");
+ int i = 0;
+ for (AnnotatedItem<?, ?> injectionPoint : injectionPoints)
+ {
+ buffer.append(++i + " - " + injectionPoint.toString() + "\n");
+ }
+ buffer.append("Resolved names: " + resolvedNames.size() + "\n");
+ i = 0;
+ for (Entry<String, Set<Bean<?>>> entry : resolvedNames.entrySet())
+ {
+ buffer.append(++i + " - " + entry + ": " + entry.getValue().toString() + "\n");
+ }
return buffer.toString();
}
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/AbstractClassBean.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/AbstractClassBean.java 2008-11-21 10:16:45 UTC (rev 348)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/AbstractClassBean.java 2008-11-21 11:00:56 UTC (rev 349)
@@ -268,13 +268,13 @@
int i = 0;
for (AnnotatedMethod<?> initializerMethod : initializerMethods)
{
- buffer.append(++i + " - " + initializerMethod.toString());
+ buffer.append(++i + " - " + initializerMethod.toString() + "\n");
}
i = 0;
- buffer.append("Injectable fields " + injectableFields.size());
+ buffer.append("Injectable fields " + injectableFields.size() + "\n");
for (AnnotatedField<?> injectableField : injectableFields)
{
- buffer.append(++i + " - " + injectableField.toString());
+ buffer.append(++i + " - " + injectableField.toString() + "\n");
}
return buffer.toString();
}
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/MergedStereotypes.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/MergedStereotypes.java 2008-11-21 10:16:45 UTC (rev 348)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/MergedStereotypes.java 2008-11-21 11:00:56 UTC (rev 349)
@@ -154,30 +154,30 @@
{
StringBuffer buffer = new StringBuffer();
buffer.append("Merged stereotype\n");
- buffer.append("Bean name defaulted: " + beanNameDefaulted);
- buffer.append("Possible deployment types: " + possibleDeploymentTypes.size());
+ buffer.append("Bean name defaulted: " + beanNameDefaulted + "\n");
+ buffer.append("Possible deployment types: " + possibleDeploymentTypes.size() + "\n");
int i = 0;
for (Entry<Class<? extends Annotation>, Annotation> entry : possibleDeploymentTypes.entrySet())
{
- buffer.append(++i + " - " + entry.getKey().getName() + ": " + entry.getValue().toString());
+ buffer.append(++i + " - " + entry.getKey().getName() + ": " + entry.getValue().toString() + "\n");
}
- buffer.append("Possible scope types: " + possibleScopeTypes.size());
+ buffer.append("Possible scope types: " + possibleScopeTypes.size() + "\n");
i = 0;
for (Annotation scopeType : possibleScopeTypes)
{
buffer.append(++i + " - " + scopeType.toString());
}
- buffer.append("Required types: " + requiredTypes.size());
+ buffer.append("Required types: " + requiredTypes.size() + "\n");
i = 0;
for (Class<?> requiredType : requiredTypes)
{
- buffer.append(++i + " - " + requiredType.getName());
+ buffer.append(++i + " - " + requiredType.getName() + "\n");
}
- buffer.append("Supported scopes: " + supportedScopes.size());
+ buffer.append("Supported scopes: " + supportedScopes.size() + "\n");
i = 0;
for (Class<?> supportedScope : supportedScopes)
{
- buffer.append(++i + " - " + supportedScope.getName());
+ buffer.append(++i + " - " + supportedScope.getName() + "\n");
}
return buffer.toString();
}
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/XmlEnterpriseBean.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/XmlEnterpriseBean.java 2008-11-21 10:16:45 UTC (rev 348)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/XmlEnterpriseBean.java 2008-11-21 11:00:56 UTC (rev 349)
@@ -53,7 +53,7 @@
{
StringBuffer buffer = new StringBuffer();
buffer.append("XML-defined enterprise bean\n");
- buffer.append(super.toString());
+ buffer.append(super.toString() + "\n");
return buffer.toString();
}
}
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/XmlSimpleBean.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/XmlSimpleBean.java 2008-11-21 10:16:45 UTC (rev 348)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/XmlSimpleBean.java 2008-11-21 11:00:56 UTC (rev 349)
@@ -53,7 +53,7 @@
{
StringBuffer buffer = new StringBuffer();
buffer.append("XML-defined simple bean\n");
- buffer.append(super.toString());
+ buffer.append(super.toString() + "\n");
return buffer.toString();
}
}
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/proxy/ProxyMethodHandler.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/proxy/ProxyMethodHandler.java 2008-11-21 10:16:45 UTC (rev 348)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/proxy/ProxyMethodHandler.java 2008-11-21 11:00:56 UTC (rev 349)
@@ -87,7 +87,7 @@
{
StringBuffer buffer = new StringBuffer();
buffer.append("Proxy method handler\n");
- buffer.append("Bean " + (bean == null ? "null" : bean.toString()));
+ buffer.append("Bean " + (bean == null ? "null" : bean.toString()) + "\n");
buffer.append("Bean index: " + beanIndex + "\n");
return buffer.toString();
}
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/proxy/ProxyPool.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/proxy/ProxyPool.java 2008-11-21 10:16:45 UTC (rev 348)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/proxy/ProxyPool.java 2008-11-21 11:00:56 UTC (rev 349)
@@ -78,7 +78,7 @@
int i = 0;
for (Entry<Bean<?>, Object> entry : delegate.entrySet())
{
- buffer.append(i + " - " + entry.getKey().toString() + ": " + entry.getValue().toString());
+ buffer.append(i + " - " + entry.getKey().toString() + ": " + entry.getValue().toString() + "\n");
}
return buffer.toString();
}
@@ -203,7 +203,8 @@
public String toString()
{
StringBuffer buffer = new StringBuffer();
- buffer.append("Proxy pool: " + pool.toString() + "\n");
+ buffer.append("Proxy pool\n");
+ buffer.append(pool.toString() + "\n");
return buffer.toString();
}
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/ContextMap.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/ContextMap.java 2008-11-21 10:16:45 UTC (rev 348)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/ContextMap.java 2008-11-21 11:00:56 UTC (rev 349)
@@ -81,12 +81,14 @@
public String toString()
{
StringBuffer buffer = new StringBuffer();
+ buffer.append("Context map\n");
buffer.append("Known scope types: " + delegate.size() + "\n");
+ int i = 0;
for (Entry<Class<? extends Annotation>, List<Context>> entry : delegate.entrySet())
{
for (Context context : entry.getValue())
{
- buffer.append(context.toString() + "\n");
+ buffer.append(++i + " - " + entry.getKey().getName() + ": " + context.toString() + "\n");
}
}
return buffer.toString();
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/SessionBeanMap.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/SessionBeanMap.java 2008-11-21 10:16:45 UTC (rev 348)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/SessionBeanMap.java 2008-11-21 11:00:56 UTC (rev 349)
@@ -202,7 +202,7 @@
{
StringBuffer buffer = new StringBuffer();
List<Bean<?>> beans = (List) keySet();
- buffer.append(beans.size() + " found in session");
+ buffer.append(beans.size() + " found in session\n");
for (Bean<?> bean : beans)
{
Object instance = get(bean);
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ejb/EjbMetaData.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ejb/EjbMetaData.java 2008-11-21 10:16:45 UTC (rev 348)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ejb/EjbMetaData.java 2008-11-21 11:00:56 UTC (rev 349)
@@ -163,19 +163,19 @@
int i = 0;
for (AnnotatedMethod<?> method : destructorMethods)
{
- buffer.append(++i + " - " + method.toString());
+ buffer.append(++i + " - " + method.toString() + "\n");
}
i = 0;
buffer.append("Remove methods: " + removeMethods.size() + "\n");
for (AnnotatedMethod<?> method : removeMethods)
{
- buffer.append(++i + " - " + method.toString());
+ buffer.append(++i + " - " + method.toString() + "\n");
}
i = 0;
buffer.append("No-args remove methods: " + noArgsRemoveMethods.size() + "\n");
for (AnnotatedMethod<?> method : noArgsRemoveMethods)
{
- buffer.append(++i + " - " + method.toString());
+ buffer.append(++i + " - " + method.toString() + "\n");
}
return buffer.toString();
}
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/EventManager.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/EventManager.java 2008-11-21 10:16:45 UTC (rev 348)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/EventManager.java 2008-11-21 11:00:56 UTC (rev 349)
@@ -184,21 +184,22 @@
}
}
-
@Override
public String toString()
{
StringBuffer buffer = new StringBuffer();
buffer.append("Event manager\n");
buffer.append("Registered observers: " + registeredObservers.size() + "\n");
+ int i = 1;
for (Entry<Class<?>, CopyOnWriteArrayList<EventObserver<?>>> entry : registeredObservers.entrySet())
{
- buffer.append(entry.getKey().getName() + ":\n");
for (EventObserver<?> observer : entry.getValue())
{
- buffer.append(" " + observer.toString());
+ buffer.append(i + " - " + entry.getKey().getName() + ": " + observer.toString() + "\n");
}
+ i++;
}
+ buffer.append("Transaction manager: " + transactionManager + "\n");
return buffer.toString();
}
}
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/BindingTypeModel.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/BindingTypeModel.java 2008-11-21 10:16:45 UTC (rev 348)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/BindingTypeModel.java 2008-11-21 11:00:56 UTC (rev 349)
@@ -118,7 +118,7 @@
for (AnnotatedMethod<?> method : nonBindingTypes) {
method.toString();
}
- buffer.append("Annotated type " + getAnnotatedAnnotation().getName());
+ buffer.append("Annotated type " + getAnnotatedAnnotation().getName() + "\n");
return buffer.toString();
}
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/ScopeModel.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/ScopeModel.java 2008-11-21 10:16:45 UTC (rev 348)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/ScopeModel.java 2008-11-21 11:00:56 UTC (rev 349)
@@ -58,7 +58,7 @@
StringBuffer buffer = new StringBuffer();
buffer.append("Scope model\n");
buffer.append("Valid : " + isValid() + "\n");
- buffer.append("Annotated type " + getAnnotatedAnnotation().toString());
+ buffer.append("Annotated type " + getAnnotatedAnnotation().toString() + "\n");
return buffer.toString();
}
16 years
[webbeans-commits] Webbeans SVN: r348 - in ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans: bean and 5 other directories.
by webbeans-commits@lists.jboss.org
Author: nickarls
Date: 2008-11-21 05:16:45 -0500 (Fri, 21 Nov 2008)
New Revision: 348
Modified:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ManagerImpl.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/MetaDataCache.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/AbstractBean.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/AbstractClassBean.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/EnterpriseBean.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/EventBean.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/ForwardingBean.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/MergedStereotypes.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/ProducerMethodBean.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/SimpleBean.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/XmlEnterpriseBean.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/XmlSimpleBean.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/proxy/ProxyMethodHandler.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/proxy/ProxyPool.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ejb/EjbMetaData.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/EventManager.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/BindingTypeModel.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/ScopeModel.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/Reflections.java
Log:
Header blocks, javadocs, toString
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ManagerImpl.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ManagerImpl.java 2008-11-21 07:15:32 UTC (rev 347)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ManagerImpl.java 2008-11-21 10:16:45 UTC (rev 348)
@@ -669,10 +669,7 @@
buffer.append(" " + deploymentType.getName() + "\n");
}
- buffer.append("Event manager:\n");
buffer.append(eventManager.toString());
-
- buffer.append("Metadata cache:\n");
buffer.append(metaDataCache.toString());
buffer.append("Resolver:\n");
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/MetaDataCache.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/MetaDataCache.java 2008-11-21 07:15:32 UTC (rev 347)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/MetaDataCache.java 2008-11-21 10:16:45 UTC (rev 348)
@@ -20,6 +20,7 @@
import java.lang.annotation.Annotation;
import java.util.HashMap;
import java.util.Map;
+import java.util.Map.Entry;
import org.jboss.webbeans.ejb.EjbMetaData;
import org.jboss.webbeans.model.AnnotationModel;
@@ -60,7 +61,7 @@
{
return delegate;
}
-
+
}
@SuppressWarnings("unchecked")
@@ -97,6 +98,27 @@
return new BindingTypeModel<S>(type);
}
+ @Override
+ public String toString() {
+ StringBuffer buffer = new StringBuffer();
+ buffer.append("Binding types\n");
+ for (Entry<Class<? extends Annotation>, BindingTypeModel<?>> entry : delegate.entrySet()) {
+ buffer.append(entry.getKey().getName() + ": " + entry.getValue().toString() + "\n");
+ }
+ buffer.append("EJB metadata\n");
+ for (Entry<Class<?>, EjbMetaData<?>> entry : ejbMetaDataMap.entrySet()) {
+ buffer.append(entry.getKey().getName() + ": " + entry.getValue().toString());
+ }
+ buffer.append("Scopes\n");
+ for (Entry<Class<? extends Annotation>, ScopeModel<?>> entry : scopes.entrySet()) {
+ buffer.append(entry.getKey().getName() + ": " + entry.getValue().toString());
+ }
+ buffer.append("Stereotypes\n");
+ for (Entry<Class<? extends Annotation>, StereotypeModel<?>> entry : stereotypes.entrySet()) {
+ buffer.append(entry.getKey().getName() + ": " + entry.getValue().toString());
+ }
+ return buffer.toString();
+ }
}
private class EjbMetaDataMap extends ForwardingMap<Class<?>, EjbMetaData<?>>
@@ -161,11 +183,20 @@
{
return ejbMetaDataMap.putIfAbsent(clazz);
}
-
+
@Override
- public String toString() {
+ public String toString()
+ {
StringBuffer buffer = new StringBuffer();
- buffer.append("FIX ME!\n");
+ buffer.append("Metadata cache\n");
+ buffer.append(bindingTypes.toString());
+ buffer.append(ejbMetaDataMap.toString());
+ buffer.append(scopes.toString());
+ buffer.append("Stereotypes:\n");
+ for (Entry<Class<? extends Annotation>, StereotypeModel<?>> entry : stereotypes.entrySet())
+ {
+ buffer.append(entry.getKey().getName() + ": " + entry.getValue().toString() + "\n");
+ }
return buffer.toString();
}
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/AbstractBean.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/AbstractBean.java 2008-11-21 07:15:32 UTC (rev 347)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/AbstractBean.java 2008-11-21 10:16:45 UTC (rev 348)
@@ -1,3 +1,20 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
package org.jboss.webbeans.bean;
import java.lang.annotation.Annotation;
@@ -31,11 +48,27 @@
import org.jboss.webbeans.log.Logging;
import org.jboss.webbeans.util.Reflections;
+/**
+ * An abstract bean representation common for all beans
+ *
+ * @author Pete Muir
+ *
+ * @param <T>
+ * @param <E>
+ */
public abstract class AbstractBean<T, E> extends Bean<T>
{
-
+
+ @SuppressWarnings("unchecked")
private static Set<Class<?>> STANDARD_WEB_BEAN_CLASSES = new HashSet<Class<?>>(Arrays.asList(DefaultEnterpriseBeanLookup.class));
-
+
+ /**
+ * Helper class for getting deployment type
+ *
+ * @param enabledDeploymentTypes The currently enabled deployment types
+ * @param possibleDeploymentTypes The possible deployment types
+ * @return The deployment type
+ */
public static Class<? extends Annotation> getDeploymentType(List<Class<? extends Annotation>> enabledDeploymentTypes, Map<Class<? extends Annotation>, Annotation> possibleDeploymentTypes)
{
for (int i = (enabledDeploymentTypes.size() - 1); i > 0; i--)
@@ -47,10 +80,10 @@
}
return null;
}
-
+
// Logger
private LogProvider log = Logging.getLogProvider(AbstractBean.class);
-
+
// Reference to WBRI manager
private ManagerImpl manager;
private Set<Annotation> bindingTypes;
@@ -62,18 +95,26 @@
protected AnnotatedMethod<Object> removeMethod;
protected Set<Class<?>> apiTypes;
protected Set<AnnotatedItem<?, ?>> injectionPoints;
-
+
private boolean primitive;
-
+
// Cached values
private Type declaredBeanType;
-
+
+ /**
+ * Constructor
+ *
+ * @param manager The Web Beans manager
+ */
public AbstractBean(ManagerImpl manager)
{
super(manager);
this.manager = manager;
}
-
+
+ /**
+ * Initializes the bean and its metadata
+ */
protected void init()
{
mergedStereotypes = new MergedStereotypes<T, E>(getAnnotatedItem().getMetaAnnotations(Stereotype.class), manager);
@@ -87,15 +128,21 @@
initScopeType();
initApiTypes();
}
-
+
+ /**
+ * Initializes the API types
+ */
protected void initApiTypes()
{
- apiTypes = getTypeHierachy(getType());
+ apiTypes = Reflections.getTypeHierachy(getType());
}
-
+
+ /**
+ * Initializes the binding types
+ */
protected void initBindingTypes()
{
-
+
this.bindingTypes = new HashSet<Annotation>();
if (isDefinedInXml())
{
@@ -134,7 +181,11 @@
return;
}
}
-
+
+ /**
+ * Initializes the deployment types
+ */
+ @SuppressWarnings("null")
protected void initDeploymentType()
{
if (isDefinedInXml())
@@ -144,7 +195,7 @@
{
throw new RuntimeException("At most one deployment type may be specified (" + xmlDeploymentTypes + " are specified)");
}
-
+
if (xmlDeploymentTypes.size() == 1)
{
this.deploymentType = xmlDeploymentTypes.iterator().next().annotationType();
@@ -155,7 +206,7 @@
else
{
Set<Annotation> deploymentTypes = getAnnotatedItem().getMetaAnnotations(DeploymentType.class);
-
+
if (deploymentTypes.size() > 1)
{
throw new DefinitionException("At most one deployment type may be specified (" + deploymentTypes + " are specified) on " + getAnnotatedItem().toString());
@@ -166,7 +217,7 @@
log.trace("Deployment type " + deploymentType + " specified by annotation");
return;
}
-
+
if (getMergedStereotypes().getPossibleDeploymentTypes().size() > 0)
{
this.deploymentType = getDeploymentType(manager.getEnabledDeploymentTypes(), getMergedStereotypes().getPossibleDeploymentTypes());
@@ -174,12 +225,15 @@
return;
}
}
-
+
this.deploymentType = Production.class;
log.trace("Using default @Production deployment type");
return;
}
-
+
+ /**
+ * Initializes the injection points
+ */
protected void initInjectionPoints()
{
injectionPoints = new HashSet<AnnotatedItem<?, ?>>();
@@ -191,7 +245,10 @@
}
}
}
-
+
+ /**
+ * Initializes the name
+ */
protected void initName()
{
boolean beanNameDefaulted = false;
@@ -244,22 +301,26 @@
return;
}
}
-
+
if (beanNameDefaulted || getMergedStereotypes().isBeanNameDefaulted())
{
this.name = getDefaultName();
return;
}
}
-
+
+ /**
+ * Initializes the primitive flag
+ */
protected void initPrimitive()
{
this.primitive = Reflections.isPrimitive(getType());
}
-
+
/**
- * Return the scope of the bean
+ * Initializes the scope type
*/
+ @SuppressWarnings("null")
protected void initScopeType()
{
if (isDefinedInXml())
@@ -269,7 +330,7 @@
{
throw new DefinitionException("At most one scope may be specified in XML");
}
-
+
if (scopeTypes.size() == 1)
{
this.scopeType = scopeTypes.iterator().next();
@@ -283,7 +344,7 @@
{
throw new DefinitionException("At most one scope may be specified");
}
-
+
if (getAnnotatedItem().getMetaAnnotations(ScopeType.class).size() == 1)
{
this.scopeType = getAnnotatedItem().getMetaAnnotations(ScopeType.class).iterator().next().annotationType();
@@ -291,7 +352,7 @@
return;
}
}
-
+
if (getMergedStereotypes().getPossibleScopeTypes().size() == 1)
{
this.scopeType = getMergedStereotypes().getPossibleScopeTypes().iterator().next().annotationType();
@@ -305,9 +366,15 @@
this.scopeType = Dependent.class;
log.trace("Using default @Dependent scope");
}
-
+
+ /**
+ * Initializes the type of the bean
+ */
protected abstract void initType();
-
+
+ /**
+ * Validates the deployment type
+ */
protected void checkDeploymentType()
{
if (deploymentType == null)
@@ -319,30 +386,56 @@
throw new DefinitionException(getAnnotatedItem() + " cannot have deployment type @Standard");
}
}
-
+
+ /**
+ * Destroys a bean instance
+ *
+ * @param instance The instance to destroy
+ */
@Override
public void destroy(T instance)
{
// TODO Auto-generated method stub
}
-
+
+ /**
+ * Binds the decorators to the proxy
+ */
protected void bindDecorators()
{
// TODO
}
-
+
+ /**
+ * Binds the interceptors to the proxy
+ */
protected void bindInterceptors()
{
// TODO
}
-
+
+ /**
+ * Returns the annotated time the bean reresents
+ *
+ * @return The annotated item
+ */
protected abstract AnnotatedItem<T, E> getAnnotatedItem();
-
+
+ /**
+ * Returns the binding types
+ *
+ * @return The set of binding types
+ */
public Set<Annotation> getBindingTypes()
{
return bindingTypes;
}
-
+
+ /**
+ * Returns the declared bean type
+ *
+ * @return The bean type
+ */
protected Type getDeclaredBeanType()
{
if (declaredBeanType == null)
@@ -359,102 +452,202 @@
}
return declaredBeanType;
}
-
+
+ /**
+ * Returns the default name of the bean
+ *
+ * @return The default name
+ */
protected abstract String getDefaultName();
-
+
+ /**
+ * Returns the deployment type of the bean
+ *
+ * @return The deployment type
+ */
public Class<? extends Annotation> getDeploymentType()
{
return deploymentType;
}
-
+
+ /**
+ * Returns the injection points of the bean
+ *
+ * @return The set of injection points
+ */
public Set<AnnotatedItem<?, ?>> getInjectionPoints()
{
return injectionPoints;
}
-
+
+ /**
+ * Returns the Web Beans manager reference
+ *
+ * @return The manager
+ */
@Override
protected ManagerImpl getManager()
{
return manager;
}
-
+
+ /**
+ * Returns the merged sterotypes of the bean
+ *
+ * @return The set of merged stereotypes
+ */
public MergedStereotypes<T, E> getMergedStereotypes()
{
return mergedStereotypes;
}
-
+
+ /**
+ * Returns the name of the bean
+ *
+ * @return The name
+ */
public String getName()
{
return name;
}
-
+
+ /**
+ * Returns the remove method of the bean
+ *
+ * @return The remove method
+ */
public AnnotatedMethod<?> getRemoveMethod()
{
return removeMethod;
}
-
+
+ /**
+ * Returns the scope type of the bean
+ *
+ * @return The scope type
+ */
public Class<? extends Annotation> getScopeType()
{
return scopeType;
}
-
+
+ /**
+ * Returns the specializes type of the bean
+ *
+ * @return The specialized type
+ */
protected AbstractBean<? extends T, E> getSpecializedType()
{
throw new UnsupportedOperationException();
}
-
+
+ /**
+ * Returns the type of the bean
+ *
+ * @return The type
+ */
public Class<T> getType()
{
return type;
}
-
- protected Set<Class<?>> getTypeHierachy(Class<?> clazz)
- {
- Set<Class<?>> classes = new HashSet<Class<?>>();
- if (clazz != null)
- {
- classes.add(clazz);
- classes.addAll(getTypeHierachy(clazz.getSuperclass()));
- for (Class<?> c : clazz.getInterfaces())
- {
- classes.addAll(getTypeHierachy(c));
- }
- }
- return classes;
- }
-
+
+ /**
+ * Returns the API types of the bean
+ *
+ * @return The set of API types
+ */
@Override
public Set<Class<?>> getTypes()
{
return apiTypes;
}
-
+
+ /**
+ * Checks if this beans annotated item is assignable from another annotated
+ * item
+ *
+ * @param annotatedItem The other annotation to check
+ * @return True if assignable, otherwise false
+ */
public boolean isAssignableFrom(AnnotatedItem<?, ?> annotatedItem)
{
return this.getAnnotatedItem().isAssignableFrom(annotatedItem);
}
-
+
+ /**
+ * Indicates if bean was defined in XML
+ *
+ * @return True if defined in XML, false if defined with annotations
+ */
protected boolean isDefinedInXml()
{
return false;
}
-
+
+ /**
+ * Inicates if bean is nullable
+ *
+ * @return True if nullable, false otherwise
+ */
@Override
public boolean isNullable()
{
return !isPrimitive();
}
-
+
+ /**
+ * Indicates if bean type is a primitive
+ *
+ * @return True if primitive, false otherwise
+ */
public boolean isPrimitive()
{
return primitive;
}
-
+
+ /**
+ * Indicates if bean is serializable
+ *
+ * @return True if serializable, false otherwise
+ */
@Override
public boolean isSerializable()
{
// TODO Auto-generated method stub
return false;
}
-
+
+ @Override
+ public String toString()
+ {
+ StringBuffer buffer = new StringBuffer();
+ buffer.append("Name: " + name + "\n");
+ buffer.append("Type: " + type + "\n");
+ buffer.append("Scope type " + scopeType.getName() + "\n");
+ buffer.append("Deployment type: " + deploymentType.getName() + "\n");
+ buffer.append("Primitive : " + primitive + "\n");
+ buffer.append("Declared bean type: " + (declaredBeanType == null ? "null" : declaredBeanType.toString()) + "\n");
+ buffer.append("Remove method: " + (removeMethod == null ? "null" : removeMethod.toString()) + "\n");
+ buffer.append("Binding types: " + bindingTypes.size() + "\n");
+ int i = 0;
+ for (Annotation bindingType : bindingTypes)
+ {
+ buffer.append(++i + " - " + bindingType.toString() + "\n");
+ }
+ buffer.append("API types: " + apiTypes.size() + "\n");
+ i = 0;
+ for (Class<?> apiType : apiTypes)
+ {
+ buffer.append(++i + " - " + apiType.getName() + "\n");
+ }
+ buffer.append("Merged stereotype\n");
+ buffer.append(mergedStereotypes.toString() + "\n");
+ buffer.append("Injection points: " + injectionPoints.size() + "\n");
+ i = 0;
+ for (AnnotatedItem<?, ?> injectionPoint : injectionPoints)
+ {
+ buffer.append(++i + " - " + injectionPoint.toString() + "\n");
+ }
+ return buffer.toString();
+ }
}
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/AbstractClassBean.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/AbstractClassBean.java 2008-11-21 07:15:32 UTC (rev 347)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/AbstractClassBean.java 2008-11-21 10:16:45 UTC (rev 348)
@@ -1,3 +1,20 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
package org.jboss.webbeans.bean;
import java.util.HashSet;
@@ -21,27 +38,38 @@
import org.jboss.webbeans.util.Reflections;
import org.jboss.webbeans.util.Strings;
+/**
+ * An abstract bean representation common for class-based beans
+ *
+ * @author Pete Muir
+ *
+ * @param <T>
+ * @param <E>
+ */
public abstract class AbstractClassBean<T> extends AbstractBean<T, Class<T>>
{
-
+
private static final LogProvider log = Logging.getLogProvider(AbstractClassBean.class);
-
+
private AnnotatedClass<T> annotatedItem;
private Set<AnnotatedField<Object>> injectableFields;
private Set<AnnotatedMethod<Object>> initializerMethods;
-
+
/**
*
* @param annotatedItem Annotations read from java classes
* @param xmlAnnotatedItem Annotations read from XML
- * @param manager
+ * @param manager The Web Beans manager
*/
public AbstractClassBean(Class<T> type, ManagerImpl manager)
{
super(manager);
this.annotatedItem = new AnnotatedClassImpl<T>(type);
}
-
+
+ /**
+ * Initializes the bean and its metadata
+ */
@Override
protected void init()
{
@@ -52,7 +80,10 @@
// TODO Interceptors
initInitializerMethods();
}
-
+
+ /**
+ * Initializes the bean type
+ */
protected void initType()
{
if (isDefinedInXml())
@@ -65,12 +96,20 @@
this.type = getAnnotatedItem().getType();
}
}
-
+
+ /**
+ * Returns the producer methods
+ *
+ * @return A set of producer methods
+ */
public Set<AnnotatedMethod<Object>> getProducerMethods()
{
return getAnnotatedItem().getAnnotatedMethods(Produces.class);
}
-
+
+ /**
+ * Initializes the injection points
+ */
@Override
protected void initInjectionPoints()
{
@@ -90,12 +129,15 @@
super.injectionPoints.add(annotatedField);
}
}
-
+
+ /**
+ * Initializes the initializer methods
+ */
protected void initInitializerMethods()
{
if (isDefinedInXml())
{
-
+
}
else
{
@@ -129,7 +171,10 @@
}
}
}
-
+
+ /**
+ * Validates that the required types are implemented
+ */
protected void checkRequiredTypesImplemented()
{
for (Class<?> requiredType : getMergedStereotypes().getRequiredTypes())
@@ -141,10 +186,10 @@
}
}
}
-
+
/**
- * Check that the scope type is allowed by the stereotypes on the bean and the bean type
- * @param type
+ * Validate that the scope type is allowed by the stereotypes on the bean and
+ * the bean type
*/
protected void checkScopeAllowed()
{
@@ -157,7 +202,10 @@
}
}
}
-
+
+ /**
+ * Validates the bean implementation
+ */
protected void checkBeanImplementation()
{
if (Reflections.isAbstract(getType()))
@@ -165,30 +213,69 @@
throw new DefinitionException("Web Bean implementation class " + type + " cannot be declared abstract");
}
}
-
+
+ /**
+ * Returns the annotated item
+ *
+ * @return The annotated item
+ */
@Override
protected AnnotatedClass<T> getAnnotatedItem()
{
return annotatedItem;
}
-
+
+ /**
+ * Returns the default name
+ *
+ * @return The default name
+ */
@Override
protected String getDefaultName()
{
- String name = Strings.decapitalize(getType().getSimpleName());
- log.trace("Default name of " + type + " is " + name );
+ String name = Strings.decapitalize(getType().getSimpleName());
+ log.trace("Default name of " + type + " is " + name);
return name;
}
-
+
+ /**
+ * Returns the injectable fields
+ *
+ * @return The set of injectable fields
+ */
public Set<AnnotatedField<Object>> getInjectableFields()
{
return injectableFields;
}
-
+
+ /**
+ * Returns the annotated methods
+ *
+ * @return The set of annotated methods
+ */
public Set<AnnotatedMethod<Object>> getInitializerMethods()
{
return initializerMethods;
}
-
+ @Override
+ public String toString()
+ {
+ StringBuffer buffer = new StringBuffer();
+ buffer.append(super.toString());
+ buffer.append("Annotated item: " + annotatedItem.toString() + "\n");
+ buffer.append("Initializer methods: " + initializerMethods.size() + "\n");
+ int i = 0;
+ for (AnnotatedMethod<?> initializerMethod : initializerMethods)
+ {
+ buffer.append(++i + " - " + initializerMethod.toString());
+ }
+ i = 0;
+ buffer.append("Injectable fields " + injectableFields.size());
+ for (AnnotatedField<?> injectableField : injectableFields)
+ {
+ buffer.append(++i + " - " + injectableField.toString());
+ }
+ return buffer.toString();
+ }
}
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/EnterpriseBean.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/EnterpriseBean.java 2008-11-21 07:15:32 UTC (rev 347)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/EnterpriseBean.java 2008-11-21 10:16:45 UTC (rev 348)
@@ -1,3 +1,20 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
package org.jboss.webbeans.bean;
import javax.webbeans.ApplicationScoped;
@@ -20,19 +37,35 @@
import org.jboss.webbeans.introspector.AnnotatedMethod;
import org.jboss.webbeans.introspector.AnnotatedParameter;
+/**
+ * An enterprise bean representation
+ *
+ * @author Pete Muir
+ *
+ * @param <T>
+ */
public class EnterpriseBean<T> extends AbstractClassBean<T>
{
-
+
private String location;
-
+
private EjbMetaData<T> ejbMetaData;
-
- public EnterpriseBean(Class<T> type, ManagerImpl container)
+
+ /**
+ * Constructor
+ *
+ * @param type The type of the bean
+ * @param manager The Web Beans manager
+ */
+ public EnterpriseBean(Class<T> type, ManagerImpl manager)
{
- super(type, container);
+ super(type, manager);
init();
}
-
+
+ /**
+ * Initializes the bean and its metadata
+ */
@Override
protected void init()
{
@@ -46,7 +79,10 @@
checkSpecialization();
checkRemoveMethod();
}
-
+
+ /**
+ * Initializes the injection points
+ */
@Override
protected void initInjectionPoints()
{
@@ -59,7 +95,10 @@
}
}
}
-
+
+ /**
+ * Validates for non-conflicting roles
+ */
protected void checkConflictingRoles()
{
if (getType().isAnnotationPresent(Interceptor.class))
@@ -75,32 +114,22 @@
/**
* Check that the scope type is allowed by the stereotypes on the bean and
* the bean type
- *
- * @param type
*/
protected void checkEnterpriseScopeAllowed()
{
- if (getEjbMetaData().isStateless()
- && !getScopeType().equals(Dependent.class))
+ if (getEjbMetaData().isStateless() && !getScopeType().equals(Dependent.class))
{
- throw new DefinitionException("Scope " + getScopeType()
- + " is not allowed on stateless enterpise beans for "
- + getType()
- + ". Only @Dependent is allowed on stateless enterprise beans");
+ throw new DefinitionException("Scope " + getScopeType() + " is not allowed on stateless enterpise beans for " + getType() + ". Only @Dependent is allowed on stateless enterprise beans");
}
- if (getEjbMetaData().isSingleton()
- && (!(getScopeType().equals(Dependent.class) || getScopeType()
- .equals(ApplicationScoped.class))))
+ if (getEjbMetaData().isSingleton() && (!(getScopeType().equals(Dependent.class) || getScopeType().equals(ApplicationScoped.class))))
{
- throw new DefinitionException(
- "Scope "
- + getScopeType()
- + " is not allowed on singleton enterpise beans for "
- + getType()
- + ". Only @Dependent or @ApplicationScoped is allowed on singleton enterprise beans");
+ throw new DefinitionException("Scope " + getScopeType() + " is not allowed on singleton enterpise beans for " + getType() + ". Only @Dependent or @ApplicationScoped is allowed on singleton enterprise beans");
}
}
-
+
+ /**
+ * Validates specialization
+ */
private void checkSpecialization()
{
if (!getType().isAnnotationPresent(Specializes.class))
@@ -113,7 +142,7 @@
{
throw new DefinitionException("Annotation defined specializing EJB must have EJB superclass");
}
- }
+ }
else
{
if (getManager().getMetaDataCache().getEjbMetaData(getAnnotatedItem().getSuperclass().getType()).isEjb())
@@ -122,8 +151,10 @@
}
}
}
-
-// TODO logging
+
+ /**
+ * Initializes the remvoe method
+ */
protected void initRemoveMethod()
{
if (!getEjbMetaData().isStateful())
@@ -131,14 +162,13 @@
// Nothing to do for stateless enterprise beans;
return;
}
-
+
// >1 @Destructor
if (getEjbMetaData().getDestructorMethods().size() > 1)
{
throw new DefinitionException("Multiple @Destructor methods not allowed on " + getAnnotatedItem());
}
-
// <1 (0) @Destructors
if (getEjbMetaData().getNoArgsRemoveMethods().size() == 1)
{
@@ -152,34 +182,45 @@
}
}
-
+
+ /**
+ * Validates the remove method
+ */
private void checkRemoveMethod()
{
- if (removeMethod != null)
+ if (removeMethod == null)
{
- if (removeMethod.isAnnotationPresent(Destructor.class) && !removeMethod.isAnnotationPresent(EJB.REMOVE_ANNOTATION))
- {
- throw new DefinitionException("Methods marked @Destructor must also be marked @Remove on " + removeMethod.getName());
- }
- else if (removeMethod.isAnnotationPresent(Initializer.class))
- {
- throw new DefinitionException("Remove methods cannot be initializers on " + removeMethod.getName());
- }
- else if (removeMethod.isAnnotationPresent(Produces.class))
- {
- throw new DefinitionException("Remove methods cannot be producers on " + removeMethod.getName());
- }
- else if (removeMethod.getAnnotatedParameters(Disposes.class).size() > 0)
- {
- throw new DefinitionException("Remove method can't have @Disposes annotated parameters on " + removeMethod.getName());
- }
- else if (removeMethod.getAnnotatedParameters(Observes.class).size() > 0)
- {
- throw new DefinitionException("Remove method can't have @Observes annotated parameters on " + removeMethod.getName());
- }
+ return;
}
+
+ if (removeMethod.isAnnotationPresent(Destructor.class) && !removeMethod.isAnnotationPresent(EJB.REMOVE_ANNOTATION))
+ {
+ throw new DefinitionException("Methods marked @Destructor must also be marked @Remove on " + removeMethod.getName());
+ }
+ else if (removeMethod.isAnnotationPresent(Initializer.class))
+ {
+ throw new DefinitionException("Remove methods cannot be initializers on " + removeMethod.getName());
+ }
+ else if (removeMethod.isAnnotationPresent(Produces.class))
+ {
+ throw new DefinitionException("Remove methods cannot be producers on " + removeMethod.getName());
+ }
+ else if (removeMethod.getAnnotatedParameters(Disposes.class).size() > 0)
+ {
+ throw new DefinitionException("Remove method can't have @Disposes annotated parameters on " + removeMethod.getName());
+ }
+ else if (removeMethod.getAnnotatedParameters(Observes.class).size() > 0)
+ {
+ throw new DefinitionException("Remove method can't have @Observes annotated parameters on " + removeMethod.getName());
+ }
}
+ /**
+ * Creates an instance of the bean
+ *
+ * @return The instance
+ */
+ @SuppressWarnings("unchecked")
@Override
public T create()
{
@@ -189,15 +230,25 @@
injectEjbAndCommonFields();
injectBoundFields(instance);
callInitializers(instance);
- return instance;
+ return instance;
}
-
+
+ /**
+ * Destroys an instance of a bean
+ *
+ * @param instance The instance
+ */
@Override
public void destroy(T instance)
{
super.destroy(instance);
}
+ /**
+ * Calls all initializers of the bean
+ *
+ * @param instance The bean instance
+ */
protected void callInitializers(T instance)
{
for (AnnotatedMethod<Object> initializer : getInitializerMethods())
@@ -205,12 +256,20 @@
initializer.invoke(getManager(), instance);
}
}
-
+
+ /**
+ * Injects EJBs and common fields
+ */
protected void injectEjbAndCommonFields()
{
// TODO
}
-
+
+ /**
+ * Injects bound fields
+ *
+ * @param instance The bean instance
+ */
protected void injectBoundFields(T instance)
{
for (AnnotatedField<?> field : getInjectableFields())
@@ -219,50 +278,70 @@
}
}
+ /**
+ * Gets the debugging location info
+ *
+ * @return The location string
+ */
public String getLocation()
{
if (location == null)
{
- location = "type: Enterprise Bean; declaring class: " + getType() +";";
+ location = "type: Enterprise Bean; declaring class: " + getType() + ";";
}
return location;
}
+ /**
+ * Returns the specializes type of the bean
+ *
+ * @return The specialized type
+ */
+ @SuppressWarnings("unchecked")
@Override
protected AbstractBean<? extends T, Class<T>> getSpecializedType()
{
- //TODO: lots of validation!
+ // TODO: lots of validation!
Class<?> superclass = getAnnotatedItem().getType().getSuperclass();
- if ( superclass!=null )
+ if (superclass != null)
{
return new EnterpriseBean(superclass, getManager());
}
- else {
+ else
+ {
throw new RuntimeException();
}
-
+
}
+ /**
+ * Validates the bean type
+ */
private void checkEnterpriseBeanTypeAllowed()
{
if (getEjbMetaData().isMessageDriven())
{
- throw new DefinitionException(
- "Message Driven Beans can't be Web Beans");
+ throw new DefinitionException("Message Driven Beans can't be Web Beans");
}
}
+ /**
+ * Returns the EJB metadata
+ *
+ * @return The metadata
+ */
protected EjbMetaData<T> getEjbMetaData()
{
return ejbMetaData;
}
-
+
@Override
public String toString()
{
- return "EnterpriseBean[" + getType().getName() + "]";
+ StringBuffer buffer = new StringBuffer();
+ buffer.append("EnterpriseBean[" + getType().getName() + "]\n");
+ buffer.append(ejbMetaData.toString() + "\n");
+ return buffer.toString();
}
-
-
}
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/EventBean.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/EventBean.java 2008-11-21 07:15:32 UTC (rev 347)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/EventBean.java 2008-11-21 10:16:45 UTC (rev 348)
@@ -1,3 +1,20 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
package org.jboss.webbeans.bean;
import java.lang.reflect.Field;
@@ -13,11 +30,18 @@
import org.jboss.webbeans.log.LogProvider;
import org.jboss.webbeans.log.Logging;
+/**
+ * An event bean representation
+ *
+ * @author David Allen
+ *
+ * @param <T>
+ */
public class EventBean<T> extends AbstractBean<EventImpl<T>, Field>
{
-
+
private static LogProvider log = Logging.getLogProvider(EventBean.class);
-
+
private String location;
private AnnotatedField<EventImpl<T>> annotatedItem;
@@ -29,26 +53,27 @@
}
/**
- * Caches the constructor for this type of bean to avoid future reflections during use.
+ * Caches the constructor for this type of bean to avoid future reflections
+ * during use.
*/
- @SuppressWarnings("unchecked")
+ @SuppressWarnings("unused")
private void initConstructor()
{
try
{
- //constructor = new SimpleConstructor<T>((Constructor<T>) EventImpl.class.getConstructor((Class[])null));
- } catch (Exception e)
+ // constructor = new SimpleConstructor<T>((Constructor<T>)
+ // EventImpl.class.getConstructor((Class[])null));
+ }
+ catch (Exception e)
{
log.warn("Unable to get constructor for build-in Event implementation", e);
}
}
+ /*
+ * public BeanConstructor<T> getConstructor() { return constructor; }
+ */
- /*public BeanConstructor<T> getConstructor()
- {
- return constructor;
- }*/
-
public String getLocation()
{
if (location == null)
@@ -71,7 +96,7 @@
this.type = annotatedItem.getType();
}
- @Override
+ @Override
protected AnnotatedItem<EventImpl<T>, Field> getAnnotatedItem()
{
return annotatedItem;
@@ -96,7 +121,7 @@
{
// No - op
}
-
+
@Override
protected void initName()
{
@@ -110,12 +135,11 @@
// This is always @Dependent per 7.4
this.scopeType = Dependent.class;
}
-
+
@Override
public EventImpl<T> create()
{
return new EventImpl<T>();
}
-
}
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/ForwardingBean.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/ForwardingBean.java 2008-11-21 07:15:32 UTC (rev 347)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/ForwardingBean.java 2008-11-21 10:16:45 UTC (rev 348)
@@ -1,3 +1,20 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
package org.jboss.webbeans.bean;
import java.lang.annotation.Annotation;
@@ -6,6 +23,13 @@
import javax.webbeans.manager.Bean;
import javax.webbeans.manager.Manager;
+/**
+ * A delegating bean
+ *
+ * @author Pete Muir
+ *
+ * @param <T>
+ */
public abstract class ForwardingBean<T> extends Bean<T>
{
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/MergedStereotypes.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/MergedStereotypes.java 2008-11-21 07:15:32 UTC (rev 347)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/MergedStereotypes.java 2008-11-21 10:16:45 UTC (rev 348)
@@ -1,3 +1,20 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
package org.jboss.webbeans.bean;
import java.lang.annotation.Annotation;
@@ -5,24 +22,31 @@
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
+import java.util.Map.Entry;
import org.jboss.webbeans.ManagerImpl;
import org.jboss.webbeans.model.StereotypeModel;
/**
* Meta model for the merged stereotype for a bean
+ *
* @author pmuir
- *
+ *
*/
public class MergedStereotypes<T, E>
{
-
private Map<Class<? extends Annotation>, Annotation> possibleDeploymentTypes;
private Set<Annotation> possibleScopeTypes;
private boolean beanNameDefaulted;
private Set<Class<?>> requiredTypes;
private Set<Class<? extends Annotation>> supportedScopes;
-
+
+ /**
+ * Constructor
+ *
+ * @param stereotypeAnnotations The stereotypes to merge
+ * @param manager The Web Beans manager
+ */
public MergedStereotypes(Set<Annotation> stereotypeAnnotations, ManagerImpl manager)
{
possibleDeploymentTypes = new HashMap<Class<? extends Annotation>, Annotation>();
@@ -31,7 +55,13 @@
supportedScopes = new HashSet<Class<? extends Annotation>>();
merge(stereotypeAnnotations, manager);
}
-
+
+ /**
+ * Perform the merge
+ *
+ * @param stereotypeAnnotations The stereotype annotations
+ * @param manager The Web Beans manager
+ */
protected void merge(Set<Annotation> stereotypeAnnotations, ManagerImpl manager)
{
for (Annotation stereotypeAnnotation : stereotypeAnnotations)
@@ -52,41 +82,104 @@
}
requiredTypes.addAll(stereotype.getRequiredTypes());
supportedScopes.addAll(stereotype.getSupportedScopes());
- if (stereotype.isBeanNameDefaulted())
+ if (stereotype.isBeanNameDefaulted())
{
beanNameDefaulted = true;
}
}
}
-
+
+ /**
+ * Returns the possible deployment typess
+ *
+ * @return The deployment types
+ */
public Map<Class<? extends Annotation>, Annotation> getPossibleDeploymentTypes()
{
return possibleDeploymentTypes;
}
-
+
+ /**
+ * Returns the possible scope types
+ *
+ * @return The scope types
+ */
public Set<Annotation> getPossibleScopeTypes()
{
return possibleScopeTypes;
}
-
+
+ /**
+ * Indicates if the name i defaulted
+ *
+ * @return True if defaulted, false if not
+ */
public boolean isBeanNameDefaulted()
{
return beanNameDefaulted;
}
-
+
+ /**
+ * Returns the required types
+ *
+ * @return The required types
+ */
public Set<Class<?>> getRequiredTypes()
{
return requiredTypes;
}
-
+
+ /**
+ * Returns the supported scopes
+ *
+ * @return The supported scopes
+ */
public Set<Class<? extends Annotation>> getSupportedScopes()
{
return supportedScopes;
}
-
+
+ /**
+ * Indicates if the bean was declared in XML
+ *
+ * @return True if declared in XML, else false
+ */
public boolean isDeclaredInXml()
{
return false;
}
-
+
+ @Override
+ public String toString()
+ {
+ StringBuffer buffer = new StringBuffer();
+ buffer.append("Merged stereotype\n");
+ buffer.append("Bean name defaulted: " + beanNameDefaulted);
+ buffer.append("Possible deployment types: " + possibleDeploymentTypes.size());
+ int i = 0;
+ for (Entry<Class<? extends Annotation>, Annotation> entry : possibleDeploymentTypes.entrySet())
+ {
+ buffer.append(++i + " - " + entry.getKey().getName() + ": " + entry.getValue().toString());
+ }
+ buffer.append("Possible scope types: " + possibleScopeTypes.size());
+ i = 0;
+ for (Annotation scopeType : possibleScopeTypes)
+ {
+ buffer.append(++i + " - " + scopeType.toString());
+ }
+ buffer.append("Required types: " + requiredTypes.size());
+ i = 0;
+ for (Class<?> requiredType : requiredTypes)
+ {
+ buffer.append(++i + " - " + requiredType.getName());
+ }
+ buffer.append("Supported scopes: " + supportedScopes.size());
+ i = 0;
+ for (Class<?> supportedScope : supportedScopes)
+ {
+ buffer.append(++i + " - " + supportedScope.getName());
+ }
+ return buffer.toString();
+ }
+
}
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/ProducerMethodBean.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/ProducerMethodBean.java 2008-11-21 07:15:32 UTC (rev 347)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/ProducerMethodBean.java 2008-11-21 10:16:45 UTC (rev 348)
@@ -1,3 +1,20 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
package org.jboss.webbeans.bean;
import java.lang.annotation.Annotation;
@@ -18,6 +35,13 @@
import org.jboss.webbeans.introspector.AnnotatedParameter;
import org.jboss.webbeans.introspector.jlr.AnnotatedMethodImpl;
+/**
+ * Represents a producer method bean
+ *
+ * @author Pete Muir
+ *
+ * @param <T>
+ */
public class ProducerMethodBean<T> extends AbstractBean<T, Method>
{
@@ -27,11 +51,25 @@
// Cached values
private String location;
+ /**
+ * Constructor
+ *
+ * @param method The producer method
+ * @param declaringBean The declaring bean instance
+ * @param manager The Web Beans manager
+ */
public ProducerMethodBean(Method method, AbstractClassBean<?> declaringBean, ManagerImpl manager)
{
this(new AnnotatedMethodImpl<T>(method, declaringBean.getAnnotatedItem()), declaringBean, manager);
}
+ /**
+ * Constructor
+ *
+ * @param method The producer method abstraction
+ * @param declaringBean The declaring bean
+ * @param manager The Web Beans manager
+ */
public ProducerMethodBean(AnnotatedMethod<T> method, AbstractClassBean<?> declaringBean, ManagerImpl manager)
{
super(manager);
@@ -40,6 +78,11 @@
init();
}
+ /**
+ * Creates an instance of the bean
+ *
+ * @returns The instance
+ */
@Override
public T create()
{
@@ -51,6 +94,9 @@
return instance;
}
+ /**
+ * Initializes the bean and its metadata
+ */
@Override
protected void init()
{
@@ -60,6 +106,9 @@
initInjectionPoints();
}
+ /**
+ * Initializes the injection points
+ */
@Override
protected void initInjectionPoints()
{
@@ -77,6 +126,9 @@
}
}
+ /**
+ * Initializes the deployment type
+ */
@Override
protected void initDeploymentType()
{
@@ -87,6 +139,9 @@
}
}
+ /**
+ * Validates the producer method
+ */
protected void checkProducerMethod()
{
if (getAnnotatedItem().isStatic())
@@ -117,6 +172,9 @@
}
}
+ /**
+ * Initializes the remove method
+ */
protected void initRemoveMethod()
{
Set<AnnotatedMethod<Object>> disposalMethods = getManager().resolveDisposalMethods(getType(), getBindingTypes().toArray(new Annotation[0]));
@@ -131,24 +189,32 @@
}
}
- @Override
- public String toString()
- {
- return "ProducerMethodBean[" + getType().getName() + "]";
- }
+ /**
+ * Gets the annotated item representing the method
+ *
+ * @return The annotated item
+ */
@Override
protected AnnotatedMethod<T> getAnnotatedItem()
{
return method;
}
+ /**
+ * Returns the default name
+ *
+ * @return The default name
+ */
@Override
protected String getDefaultName()
{
return method.getPropertyName();
}
+ /**
+ * Initializes the type
+ */
@Override
protected void initType()
{
@@ -165,6 +231,9 @@
}
}
+ /**
+ * Initializes the API types
+ */
@Override
protected void initApiTypes()
{
@@ -185,8 +254,11 @@
}
}
-
-
+ /**
+ * Gets the debugging location info
+ *
+ * @return The location string
+ */
public String getLocation()
{
if (location == null)
@@ -196,15 +268,37 @@
return location;
}
+ /**
+ * Returns the disposal method
+ *
+ * @return The method representation
+ */
public AnnotatedMethod<?> getDisposalMethod()
{
return removeMethod;
}
+ /**
+ * Returns the declaring bean
+ *
+ * @return The bean representation
+ */
public AbstractClassBean<?> getDeclaringBean()
{
return declaringBean;
}
+ @Override
+ public String toString()
+ {
+ StringBuffer buffer = new StringBuffer();
+ buffer.append("ProducerMethodBean[" + getType().getName() + "]\n");
+ buffer.append(super.toString() + "\n");
+ buffer.append("Location: " + location + "\n");
+ buffer.append("Declaring bean: " + declaringBean.toString() + "\n");
+ buffer.append("Method: " + method.toString() + "\n");
+ return buffer.toString();
+ }
+
}
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/SimpleBean.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/SimpleBean.java 2008-11-21 07:15:32 UTC (rev 347)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/SimpleBean.java 2008-11-21 10:16:45 UTC (rev 348)
@@ -1,3 +1,20 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
package org.jboss.webbeans.bean;
import java.util.Collections;
@@ -18,24 +35,42 @@
import org.jboss.webbeans.log.Logging;
import org.jboss.webbeans.util.Reflections;
+/**
+ * Represents a simple bean
+ *
+ * @author Pete Muir
+ *
+ * @param <T>
+ */
public class SimpleBean<T> extends AbstractClassBean<T>
{
-
+
private static LogProvider log = Logging.getLogProvider(SimpleBean.class);
private static List<Class<?>> NO_ARGUMENTS = Collections.emptyList();
-
+
private AnnotatedConstructor<T> constructor;
private String location;
-
+
private AnnotatedMethod<Object> postConstruct;
private AnnotatedMethod<Object> preDestroy;
-
+
+ /**
+ * Constructor
+ *
+ * @param type The type of the bean
+ * @param manager The Web Beans manager
+ */
public SimpleBean(Class<T> type, ManagerImpl manager)
{
super(type, manager);
init();
}
+ /**
+ * Creates an instance of the bean
+ *
+ * @return The instance
+ */
@Override
public T create()
{
@@ -48,45 +83,65 @@
callPostConstruct(instance);
return instance;
}
-
+
+ /**
+ * Destroys an instance of the bean
+ *
+ * @param instance The instance
+ */
@Override
public void destroy(T instance)
{
callPreDestroy(instance);
}
-
+
+ /**
+ * Calls the pre-destroy method, if any
+ *
+ * @param instance The instance to invoke the method on
+ */
protected void callPreDestroy(T instance)
{
AnnotatedMethod<Object> preDestroy = getPreDestroy();
- if (preDestroy!=null)
+ if (preDestroy != null)
{
try
{
preDestroy.invoke(instance);
}
- catch (Exception e)
+ catch (Exception e)
{
throw new RuntimeException("Unable to invoke " + preDestroy + " on " + instance, e);
}
- }
+ }
}
-
+
+ /**
+ * Calls the post-construct method, if any
+ *
+ * @param instance The instance to invoke the method on
+ */
protected void callPostConstruct(T instance)
{
AnnotatedMethod<Object> postConstruct = getPostConstruct();
- if (postConstruct!=null)
+ if (postConstruct != null)
{
try
{
postConstruct.invoke(instance);
}
- catch (Exception e)
+ catch (Exception e)
{
throw new RuntimeException("Unable to invoke " + postConstruct + " on " + instance, e);
}
}
}
+ /**
+ * Calls any initializers
+ *
+ * @param instance The instance to invoke the initializers on
+ */
protected void callInitializers(T instance)
{
for (AnnotatedMethod<Object> initializer : getInitializerMethods())
@@ -94,12 +149,20 @@
initializer.invoke(getManager(), instance);
}
}
-
+
+ /**
+ * Injects EJBs and common fields
+ */
protected void injectEjbAndCommonFields()
{
// TODO
}
-
+
+ /**
+ * Injects bound fields
+ *
+ * @param instance The instance to inject into
+ */
protected void injectBoundFields(T instance)
{
for (AnnotatedField<?> injectableField : getInjectableFields())
@@ -107,7 +170,10 @@
injectableField.inject(instance, getManager());
}
}
-
+
+ /**
+ * Initializes the bean and its metadata
+ */
@Override
protected void init()
{
@@ -119,7 +185,10 @@
initPreDestroy();
// TODO Interceptors
}
-
+
+ /**
+ * Initializes the injection points
+ */
@Override
protected void initInjectionPoints()
{
@@ -129,7 +198,12 @@
injectionPoints.add(parameter);
}
}
-
+
+ /**
+ * Validates the type
+ *
+ * @param type The type to validate
+ */
public static void checkType(Class<?> type)
{
if (Reflections.isNonStaticInnerClass(type))
@@ -141,7 +215,10 @@
throw new DefinitionException("Simple Web Bean " + type + " cannot be a parameterized type");
}
}
-
+
+ /**
+ * Initializes the constructor
+ */
protected void initConstructor()
{
Set<AnnotatedConstructor<T>> initializerAnnotatedConstructors = getAnnotatedItem().getAnnotatedConstructors(Initializer.class);
@@ -156,84 +233,100 @@
else if (initializerAnnotatedConstructors.size() == 1)
{
this.constructor = initializerAnnotatedConstructors.iterator().next();
- log.trace("Exactly one constructor (" + constructor +") annotated with @Initializer defined, using it as the bean constructor for " + getType());
+ log.trace("Exactly one constructor (" + constructor + ") annotated with @Initializer defined, using it as the bean constructor for " + getType());
return;
}
-
+
if (getAnnotatedItem().getConstructor(NO_ARGUMENTS) != null)
{
-
- this.constructor =getAnnotatedItem().getConstructor(NO_ARGUMENTS);
- log.trace("Exactly one constructor (" + constructor +") defined, using it as the bean constructor for " + getType());
+
+ this.constructor = getAnnotatedItem().getConstructor(NO_ARGUMENTS);
+ log.trace("Exactly one constructor (" + constructor + ") defined, using it as the bean constructor for " + getType());
return;
}
-
+
throw new DefinitionException("Cannot determine constructor to use for " + getType());
}
-
+
+ /**
+ * Initializes the post-construct method
+ */
protected void initPostConstruct()
{
Set<AnnotatedMethod<Object>> postConstructMethods = getAnnotatedItem().getAnnotatedMethods(PostConstruct.class);
log.trace("Found " + postConstructMethods + " constructors annotated with @Initializer for " + getType());
if (postConstructMethods.size() > 1)
{
- //TODO: actually this is wrong, in EJB you can have @PostConstruct methods on the superclass,
- // though the Web Beans spec is silent on the issue
+ // TODO: actually this is wrong, in EJB you can have @PostConstruct
+ // methods on the superclass,
+ // though the Web Beans spec is silent on the issue
throw new DefinitionException("Cannot have more than one post construct method annotated with @Initializer for " + getType());
}
else if (postConstructMethods.size() == 1)
{
this.postConstruct = postConstructMethods.iterator().next();
- log.trace("Exactly one post construct method (" + postConstruct +") for " + getType());
- return;
+ log.trace("Exactly one post construct method (" + postConstruct + ") for " + getType());
+ return;
}
}
+ /**
+ * Initializes the pre-destroy method
+ */
protected void initPreDestroy()
{
Set<AnnotatedMethod<Object>> preDestroyMethods = getAnnotatedItem().getAnnotatedMethods(PreDestroy.class);
log.trace("Found " + preDestroyMethods + " constructors annotated with @Initializer for " + getType());
if (preDestroyMethods.size() > 1)
{
- //TODO: actually this is wrong, in EJB you can have @PreDestroy methods on the superclass,
- // though the Web Beans spec is silent on the issue
+ // TODO: actually this is wrong, in EJB you can have @PreDestroy
+ // methods on the superclass,
+ // though the Web Beans spec is silent on the issue
throw new DefinitionException("Cannot have more than one pre destroy method annotated with @Initializer for " + getType());
}
else if (preDestroyMethods.size() == 1)
{
this.preDestroy = preDestroyMethods.iterator().next();
- log.trace("Exactly one post construct method (" + preDestroy +") for " + getType());
- return;
+ log.trace("Exactly one post construct method (" + preDestroy + ") for " + getType());
+ return;
}
}
-
+ /**
+ * Returns the constructor
+ *
+ * @return The constructor
+ */
public AnnotatedConstructor<T> getConstructor()
{
return constructor;
}
-
- @Override
- public String toString()
- {
- return "SimpleWebBean[" + getAnnotatedItem().toString() + "]";
- }
-
+ /**
+ * Gets the debugging location info
+ *
+ * @return The location string
+ */
public String getLocation()
{
if (location == null)
{
- location = "type: Simple Bean; declaring class: " + getType() +";";
+ location = "type: Simple Bean; declaring class: " + getType() + ";";
}
return location;
}
+ /**
+ * Returns the specializes type of the bean
+ *
+ * @return The specialized type
+ */
+ @SuppressWarnings("unchecked")
protected AbstractBean<? extends T, Class<T>> getSpecializedType()
{
- //TODO: lots of validation!
+ // TODO: lots of validation!
Class<?> superclass = getAnnotatedItem().getType().getSuperclass();
- if ( superclass!=null )
+ if (superclass != null)
{
return new SimpleBean(superclass, getManager());
}
@@ -242,15 +335,38 @@
throw new RuntimeException();
}
}
-
- public AnnotatedMethod<Object> getPostConstruct()
+
+ /**
+ * Returns the post-construct method
+ *
+ * @return The post-construct method
+ */
+ public AnnotatedMethod<Object> getPostConstruct()
{
return postConstruct;
}
-
- public AnnotatedMethod<Object> getPreDestroy()
+
+ /**
+ * Returns the pre-destroy method
+ *
+ * @return The pre-destroy method
+ */
+ public AnnotatedMethod<Object> getPreDestroy()
{
return preDestroy;
}
-
+
+ @Override
+ public String toString()
+ {
+ StringBuffer buffer = new StringBuffer();
+ buffer.append("SimpleWebBean[" + getAnnotatedItem().toString() + "]\n");
+ buffer.append(super.toString() + "\n");
+ buffer.append("Location: " + location + "\n");
+ buffer.append("Constructor: " + constructor.toString() + "\n");
+ buffer.append("Post-construct: " + (postConstruct == null ? "null" : postConstruct.toString()) + "\n");
+ buffer.append("Pre-destroy: " + (preDestroy == null ? "null" : preDestroy.toString()) + "\n");
+ return buffer.toString();
+ }
+
}
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/XmlEnterpriseBean.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/XmlEnterpriseBean.java 2008-11-21 07:15:32 UTC (rev 347)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/XmlEnterpriseBean.java 2008-11-21 10:16:45 UTC (rev 348)
@@ -1,3 +1,20 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
package org.jboss.webbeans.bean;
import org.jboss.webbeans.ManagerImpl;
@@ -2,14 +19,39 @@
+/**
+ * Represents an XML defined enterprise bean
+ *
+ * @author Pete Muir
+ *
+ * @param <T>
+ */
public class XmlEnterpriseBean<T> extends EnterpriseBean<T>
{
+ /**
+ * Constructor
+ *
+ * @param type The type of the bean
+ * @param manager The Web Beans manager
+ */
public XmlEnterpriseBean(Class<T> type, ManagerImpl manager)
{
super(type, manager);
}
-
+
+ /**
+ * Indicates the bean was defined in XML
+ */
protected boolean isDefinedInXml()
{
return true;
}
+
+ @Override
+ public String toString()
+ {
+ StringBuffer buffer = new StringBuffer();
+ buffer.append("XML-defined enterprise bean\n");
+ buffer.append(super.toString());
+ return buffer.toString();
+ }
}
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/XmlSimpleBean.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/XmlSimpleBean.java 2008-11-21 07:15:32 UTC (rev 347)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/XmlSimpleBean.java 2008-11-21 10:16:45 UTC (rev 348)
@@ -1,3 +1,20 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
package org.jboss.webbeans.bean;
import org.jboss.webbeans.ManagerImpl;
@@ -2,14 +19,39 @@
+/**
+ * Represents a simple, XML defined bean
+ *
+ * @author Pete Muir
+ *
+ * @param <T>
+ */
public class XmlSimpleBean<T> extends SimpleBean<T>
{
+ /**
+ * Constructor
+ *
+ * @param type The type of the bean
+ * @param manager The Web Beans manager
+ */
public XmlSimpleBean(Class<T> type, ManagerImpl manager)
{
super(type, manager);
}
-
+
+ /**
+ * Indicates the bean was defined in XML
+ */
protected boolean isDefinedInXml()
{
return true;
}
+
+ @Override
+ public String toString()
+ {
+ StringBuffer buffer = new StringBuffer();
+ buffer.append("XML-defined simple bean\n");
+ buffer.append(super.toString());
+ return buffer.toString();
+ }
}
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/proxy/ProxyMethodHandler.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/proxy/ProxyMethodHandler.java 2008-11-21 07:15:32 UTC (rev 347)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/proxy/ProxyMethodHandler.java 2008-11-21 10:16:45 UTC (rev 348)
@@ -1,19 +1,19 @@
/*
-* JBoss, Home of Professional Open Source
-* Copyright 2008, Red Hat Middleware LLC, and individual contributors
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-* http://www.apache.org/licenses/LICENSE-2.0
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package org.jboss.webbeans.bean.proxy;
@@ -29,9 +29,9 @@
import org.jboss.webbeans.util.Reflections;
/**
- * A Javassist MethodHandler that delegates method calls to a proxied bean.
- * If the transient bean has become null, it is looked up from the manager
- * bean list before the invocation.
+ * A Javassist MethodHandler that delegates method calls to a proxied bean. If
+ * the transient bean has become null, it is looked up from the manager bean
+ * list before the invocation.
*
* @author Nicklas Karlsson
*
@@ -62,13 +62,13 @@
/**
* The method proxy
*
- * Uses reflection to look up the corresponding method on the proxy and executes
- * that method with the same parameters.
+ * Uses reflection to look up the corresponding method on the proxy and
+ * executes that method with the same parameters.
*
- * @param self A reference to the proxy
- * @param method The method to execute
- * @param process The next method to proceed to
- * @param args The method calling arguments
+ * @param self A reference to the proxy
+ * @param method The method to execute
+ * @param process The next method to proceed to
+ * @param args The method calling arguments
*/
public Object invoke(Object self, Method method, Method proceed, Object[] args) throws Throwable
{
@@ -81,5 +81,15 @@
Method proxiedMethod = Reflections.lookupMethod(method, proxiedInstance);
return proxiedMethod.invoke(proxiedInstance, args);
}
-
+
+ @Override
+ public String toString()
+ {
+ StringBuffer buffer = new StringBuffer();
+ buffer.append("Proxy method handler\n");
+ buffer.append("Bean " + (bean == null ? "null" : bean.toString()));
+ buffer.append("Bean index: " + beanIndex + "\n");
+ return buffer.toString();
+ }
+
}
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/proxy/ProxyPool.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/proxy/ProxyPool.java 2008-11-21 07:15:32 UTC (rev 347)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/proxy/ProxyPool.java 2008-11-21 10:16:45 UTC (rev 348)
@@ -1,19 +1,19 @@
/*
-* JBoss, Home of Professional Open Source
-* Copyright 2008, Red Hat Middleware LLC, and individual contributors
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-* http://www.apache.org/licenses/LICENSE-2.0
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package org.jboss.webbeans.bean.proxy;
@@ -50,46 +50,61 @@
*/
private class Pool extends ForwardingMap<Bean<?>, Object>
{
-
+
Map<Bean<?>, Object> delegate;
-
+
public Pool()
{
delegate = new ConcurrentHashMap<Bean<?>, Object>();
}
+ @SuppressWarnings("unchecked")
public <T> T get(Bean<T> key)
{
return (T) super.get(key);
}
-
+
@Override
protected Map<Bean<?>, Object> delegate()
{
return delegate;
}
-
+
+ @Override
+ public String toString()
+ {
+ StringBuffer buffer = new StringBuffer();
+ buffer.append("Proxy pool holding " + delegate.size() + " proxies\n");
+ int i = 0;
+ for (Entry<Bean<?>, Object> entry : delegate.entrySet())
+ {
+ buffer.append(i + " - " + entry.getKey().toString() + ": " + entry.getValue().toString());
+ }
+ return buffer.toString();
+ }
+
}
-
+
private ManagerImpl manager;
private Pool pool;
-
- public ProxyPool(ManagerImpl manager)
+
+ public ProxyPool(ManagerImpl manager)
{
this.manager = manager;
this.pool = new Pool();
}
-
+
/**
* Type info (interfaces and superclasses) for a class
*
* @author Nicklas Karlsson
*/
- private class TypeInfo {
+ private class TypeInfo
+ {
Class<?>[] interfaces;
Class<?> superclass;
}
-
+
/**
* Gets the type info for a class
*
@@ -100,18 +115,18 @@
* @param types A set of types (interfaces and superclasses) of a class
* @return The TypeInfo with categorized information
*/
- private TypeInfo getTypeInfo(Set<Class<?>> types)
+ private TypeInfo getTypeInfo(Set<Class<?>> types)
{
TypeInfo typeInfo = new TypeInfo();
List<Class<?>> interfaces = new ArrayList<Class<?>>();
Class<?> superclass = null;
- for (Class<?> type : types)
+ for (Class<?> type : types)
{
- if (type.isInterface())
+ if (type.isInterface())
{
interfaces.add(type);
}
- else if (superclass == null || (type != Object.class && superclass.isAssignableFrom(type)))
+ else if (superclass == null || (type != Object.class && superclass.isAssignableFrom(type)))
{
superclass = type;
}
@@ -121,12 +136,13 @@
typeInfo.superclass = superclass;
return typeInfo;
}
-
+
/**
* Creates a Javassist scope adaptor (client proxy) for a bean
*
* Creates a Javassist proxy factory. Gets the type info. Sets the interfaces
- * and superclass to the factory. Hooks in the MethodHandler and creates the proxy.
+ * and superclass to the factory. Hooks in the MethodHandler and creates the
+ * proxy.
*
* @param bean The bean to proxy
* @param beanIndex The index to the bean in the manager bean list
@@ -134,7 +150,8 @@
* @throws InstantiationException When the proxy couldn't be created
* @throws IllegalAccessException When the proxy couldn't be created
*/
- private <T> T createClientProxy(Bean<T> bean, int beanIndex) throws InstantiationException, IllegalAccessException
+ @SuppressWarnings("unchecked")
+ private <T> T createClientProxy(Bean<T> bean, int beanIndex) throws InstantiationException, IllegalAccessException
{
ProxyFactory proxyFactory = new ProxyFactory();
TypeInfo typeInfo = getTypeInfo(bean.getTypes());
@@ -149,8 +166,9 @@
/**
* Gets a client proxy for a bean
*
- * Looks for a proxy in the pool. If not found, one is created and added to the pool
- *
+ * Looks for a proxy in the pool. If not found, one is created and added to
+ * the pool
+ *
* @param bean
* @return
*/
@@ -162,8 +180,9 @@
try
{
int beanIndex = manager.getBeans().indexOf(bean);
- // Implicit add required since it is looked up on activation with then index
- if (beanIndex < 0)
+ // Implicit add required since it is looked up on activation with
+ // then index
+ if (beanIndex < 0)
{
manager.addBean(bean);
beanIndex = manager.getBeans().size() - 1;
@@ -179,12 +198,13 @@
}
return clientProxy;
}
-
+
@Override
- public String toString() {
+ public String toString()
+ {
StringBuffer buffer = new StringBuffer();
- buffer.append("FIX ME!\n");
+ buffer.append("Proxy pool: " + pool.toString() + "\n");
return buffer.toString();
- }
-
+ }
+
}
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ejb/EjbMetaData.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ejb/EjbMetaData.java 2008-11-21 07:15:32 UTC (rev 347)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ejb/EjbMetaData.java 2008-11-21 10:16:45 UTC (rev 348)
@@ -25,34 +25,30 @@
public enum EjbType
{
- STATELESS,
- STATEFUL,
- SINGLETON,
- MESSAGE_DRIVEN;
+ STATELESS, STATEFUL, SINGLETON, MESSAGE_DRIVEN;
}
-
+
private EjbType ejbType;
private List<AnnotatedMethod<Object>> removeMethods = new ArrayList<AnnotatedMethod<Object>>();
private List<AnnotatedMethod<Object>> destructorMethods = new ArrayList<AnnotatedMethod<Object>>();
private List<AnnotatedMethod<Object>> noArgsRemoveMethods = new ArrayList<AnnotatedMethod<Object>>();
-
+
// TODO Populate this from web.xml
private String ejbLinkJndiName;
-
+
// TODO Initialize this based on the EJB 3.1 spec
private String defaultJndiName;
-
+
// TODO Initialize the ejb name
private String ejbName;
-
+
private AnnotatedClass<T> type;
-
public EjbMetaData(Class<T> type)
{
this(new AnnotatedClassImpl<T>(type));
}
-
+
public EjbMetaData(AnnotatedClass<T> type)
{
// TODO Merge in ejb-jar.xml
@@ -60,7 +56,8 @@
if (type.isAnnotationPresent(STATELESS_ANNOTATION))
{
this.ejbType = STATELESS;
- // TODO Has to be done here? If they are not parsed, they can't be detected later on (EnterpriseBean remove method init)
+ // TODO Has to be done here? If they are not parsed, they can't be
+ // detected later on (EnterpriseBean remove method init)
if (type.getAnnotatedMethods(Destructor.class).size() > 0)
{
throw new DefinitionException("Stateless enterprise beans cannot have @Destructor methods");
@@ -72,7 +69,8 @@
for (AnnotatedMethod<Object> removeMethod : type.getAnnotatedMethods(REMOVE_ANNOTATION))
{
removeMethods.add(removeMethod);
- if (removeMethod.getParameters().size() == 0) {
+ if (removeMethod.getParameters().size() == 0)
+ {
noArgsRemoveMethods.add(removeMethod);
}
}
@@ -110,17 +108,17 @@
{
return SINGLETON.equals(ejbType);
}
-
+
public boolean isEjb()
{
return ejbType != null;
}
-
+
public List<AnnotatedMethod<Object>> getRemoveMethods()
{
return removeMethods;
}
-
+
public String getEjbLinkJndiName()
{
return ejbLinkJndiName;
@@ -130,12 +128,12 @@
{
return defaultJndiName;
}
-
+
public String getEjbName()
{
return ejbName;
}
-
+
public Class<T> getType()
{
return type.getType();
@@ -151,4 +149,35 @@
return noArgsRemoveMethods;
}
+ @Override
+ public String toString()
+ {
+ StringBuffer buffer = new StringBuffer();
+ buffer.append("EJB metadata model\n");
+ buffer.append("EJB name: " + ejbName + "\n");
+ buffer.append("EJB type: " + ejbType + "\n");
+ buffer.append("EJB link JNDI name " + ejbLinkJndiName + "\n");
+ buffer.append("Default JNDI name: " + defaultJndiName + "\n");
+ buffer.append("Type: " + type.toString() + "\n");
+ buffer.append("Desctructor methods: " + destructorMethods.size() + "\n");
+ int i = 0;
+ for (AnnotatedMethod<?> method : destructorMethods)
+ {
+ buffer.append(++i + " - " + method.toString());
+ }
+ i = 0;
+ buffer.append("Remove methods: " + removeMethods.size() + "\n");
+ for (AnnotatedMethod<?> method : removeMethods)
+ {
+ buffer.append(++i + " - " + method.toString());
+ }
+ i = 0;
+ buffer.append("No-args remove methods: " + noArgsRemoveMethods.size() + "\n");
+ for (AnnotatedMethod<?> method : noArgsRemoveMethods)
+ {
+ buffer.append(++i + " - " + method.toString());
+ }
+ return buffer.toString();
+ }
+
}
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/EventManager.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/EventManager.java 2008-11-21 07:15:32 UTC (rev 347)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/EventManager.java 2008-11-21 10:16:45 UTC (rev 348)
@@ -189,6 +189,7 @@
public String toString()
{
StringBuffer buffer = new StringBuffer();
+ buffer.append("Event manager\n");
buffer.append("Registered observers: " + registeredObservers.size() + "\n");
for (Entry<Class<?>, CopyOnWriteArrayList<EventObserver<?>>> entry : registeredObservers.entrySet())
{
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/BindingTypeModel.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/BindingTypeModel.java 2008-11-21 07:15:32 UTC (rev 347)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/BindingTypeModel.java 2008-11-21 10:16:45 UTC (rev 348)
@@ -108,4 +108,18 @@
return false;
}
+ @Override
+ public String toString() {
+ StringBuffer buffer = new StringBuffer();
+ buffer.append("Binding type model\n");
+ buffer.append("Hash code : " + hashCode() + "\n");
+ buffer.append("Valid : " + isValid() + "\n");
+ buffer.append("Non-binding types\n");
+ for (AnnotatedMethod<?> method : nonBindingTypes) {
+ method.toString();
+ }
+ buffer.append("Annotated type " + getAnnotatedAnnotation().getName());
+ return buffer.toString();
+ }
+
}
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/ScopeModel.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/ScopeModel.java 2008-11-21 07:15:32 UTC (rev 347)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/ScopeModel.java 2008-11-21 10:16:45 UTC (rev 348)
@@ -53,4 +53,13 @@
return ScopeType.class;
}
+ @Override
+ public String toString() {
+ StringBuffer buffer = new StringBuffer();
+ buffer.append("Scope model\n");
+ buffer.append("Valid : " + isValid() + "\n");
+ buffer.append("Annotated type " + getAnnotatedAnnotation().toString());
+ return buffer.toString();
+ }
+
}
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/Reflections.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/Reflections.java 2008-11-21 07:15:32 UTC (rev 347)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/Reflections.java 2008-11-21 10:16:45 UTC (rev 348)
@@ -12,6 +12,7 @@
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.HashSet;
import java.util.List;
import java.util.Set;
@@ -308,6 +309,21 @@
public static boolean isProxy(Object instance)
{
return instance.getClass().getName().indexOf("_$$_javassist_") > 0;
+ }
+
+ public static Set<Class<?>> getTypeHierachy(Class<?> clazz)
+ {
+ Set<Class<?>> classes = new HashSet<Class<?>>();
+ if (clazz != null)
+ {
+ classes.add(clazz);
+ classes.addAll(getTypeHierachy(clazz.getSuperclass()));
+ for (Class<?> c : clazz.getInterfaces())
+ {
+ classes.addAll(getTypeHierachy(c));
+ }
+ }
+ return classes;
}
}
16 years
[webbeans-commits] Webbeans SVN: r347 - ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans.
by webbeans-commits@lists.jboss.org
Author: gavin.king(a)jboss.com
Date: 2008-11-21 02:15:32 -0500 (Fri, 21 Nov 2008)
New Revision: 347
Modified:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ManagerImpl.java
Log:
param names
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ManagerImpl.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ManagerImpl.java 2008-11-21 07:14:05 UTC (rev 346)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ManagerImpl.java 2008-11-21 07:15:32 UTC (rev 347)
@@ -183,7 +183,7 @@
* @param bindingTypes The binding types to match
* @return The set of matching disposal methods
*/
- public <T> Set<AnnotatedMethod<Object>> resolveDisposalMethods(Class<T> apiType, Annotation... bindingTypes)
+ public <T> Set<AnnotatedMethod<Object>> resolveDisposalMethods(Class<T> apiType, Annotation... bindings)
{
return new HashSet<AnnotatedMethod<Object>>();
}
@@ -235,9 +235,9 @@
* @see javax.webbeans.manager.Manager#resolveByType(java.lang.Class,
* java.lang.annotation.Annotation[])
*/
- public <T> Set<Bean<T>> resolveByType(Class<T> type, Annotation... bindingTypes)
+ public <T> Set<Bean<T>> resolveByType(Class<T> type, Annotation... bindings)
{
- return resolveByType(new AnnotatedClassImpl<T>(type, type, bindingTypes), bindingTypes);
+ return resolveByType(new AnnotatedClassImpl<T>(type, type, bindings), bindings);
}
/**
@@ -250,9 +250,9 @@
* @see javax.webbeans.manager.Manager#resolveByType(javax.webbeans.TypeLiteral,
* java.lang.annotation.Annotation[])
*/
- public <T> Set<Bean<T>> resolveByType(TypeLiteral<T> type, Annotation... bindingTypes)
+ public <T> Set<Bean<T>> resolveByType(TypeLiteral<T> type, Annotation... bindings)
{
- return resolveByType(new AnnotatedClassImpl<T>(type.getRawType(), type.getType(), bindingTypes), bindingTypes);
+ return resolveByType(new AnnotatedClassImpl<T>(type.getRawType(), type.getType(), bindings), bindings);
}
/**
@@ -263,7 +263,7 @@
* @param bindingTypes The binding types to match
* @return The set of matching beans
*/
- public <T> Set<Bean<T>> resolveByType(AnnotatedItem<T, ?> element, Annotation... bindingTypes)
+ public <T> Set<Bean<T>> resolveByType(AnnotatedItem<T, ?> element, Annotation... bindings)
{
for (Annotation annotation : element.getAnnotations())
{
@@ -272,7 +272,7 @@
throw new IllegalArgumentException("Not a binding type " + annotation);
}
}
- if (bindingTypes.length > element.getMetaAnnotations(BindingType.class).size())
+ if (bindings.length > element.getMetaAnnotations(BindingType.class).size())
{
throw new DuplicateBindingTypeException(element.toString());
}
@@ -514,9 +514,9 @@
* @see javax.webbeans.manager.Manager#getInstanceByType(java.lang.Class,
* java.lang.annotation.Annotation[])
*/
- public <T> T getInstanceByType(Class<T> type, Annotation... bindingTypes)
+ public <T> T getInstanceByType(Class<T> type, Annotation... bindings)
{
- return getInstanceByType(new AnnotatedClassImpl<T>(type, type, bindingTypes), bindingTypes);
+ return getInstanceByType(new AnnotatedClassImpl<T>(type, type, bindings), bindings);
}
/**
@@ -529,9 +529,9 @@
* @see javax.webbeans.manager.Manager#getInstanceByType(javax.webbeans.TypeLiteral,
* java.lang.annotation.Annotation[])
*/
- public <T> T getInstanceByType(TypeLiteral<T> type, Annotation... bindingTypes)
+ public <T> T getInstanceByType(TypeLiteral<T> type, Annotation... bindings)
{
- return getInstanceByType(new AnnotatedClassImpl<T>(type.getRawType(), type.getType(), bindingTypes), bindingTypes);
+ return getInstanceByType(new AnnotatedClassImpl<T>(type.getRawType(), type.getType(), bindings), bindings);
}
/**
@@ -542,9 +542,9 @@
* @param bindingTypes The binding types to match
* @return An instance of the bean
*/
- public <T> T getInstanceByType(AnnotatedItem<T, ?> element, Annotation... bindingTypes)
+ public <T> T getInstanceByType(AnnotatedItem<T, ?> element, Annotation... bindings)
{
- Set<Bean<T>> beans = resolveByType(element, bindingTypes);
+ Set<Bean<T>> beans = resolveByType(element, bindings);
if (beans.size() == 0)
{
throw new UnsatisfiedDependencyException(element + "Unable to resolve any Web Beans");
@@ -627,9 +627,9 @@
* @see javax.webbeans.manager.Manager#resolveDecorators(java.util.Set,
* java.lang.annotation.Annotation[])
*/
- public List<Decorator> resolveDecorators(Set<Class<?>> types, Annotation... bindingTypes)
+ public List<Decorator> resolveDecorators(Set<Class<?>> types, Annotation... bindings)
{
- return resolver.resolveDecorators(types, bindingTypes);
+ return resolver.resolveDecorators(types, bindings);
}
/**
16 years
[webbeans-commits] Webbeans SVN: r346 - ri/trunk/webbeans-api/src/main/java/javax/webbeans/manager.
by webbeans-commits@lists.jboss.org
Author: gavin.king(a)jboss.com
Date: 2008-11-21 02:14:05 -0500 (Fri, 21 Nov 2008)
New Revision: 346
Modified:
ri/trunk/webbeans-api/src/main/java/javax/webbeans/manager/Manager.java
Log:
param names
Modified: ri/trunk/webbeans-api/src/main/java/javax/webbeans/manager/Manager.java
===================================================================
--- ri/trunk/webbeans-api/src/main/java/javax/webbeans/manager/Manager.java 2008-11-20 18:18:43 UTC (rev 345)
+++ ri/trunk/webbeans-api/src/main/java/javax/webbeans/manager/Manager.java 2008-11-21 07:14:05 UTC (rev 346)
@@ -37,12 +37,12 @@
public <T> Set<Bean<T>> resolveByType(Class<T> type, Annotation... bindings);
public <T> Set<Bean<T>> resolveByType(TypeLiteral<T> apiType,
- Annotation... bindingTypes);
+ Annotation... bindings);
- public <T> T getInstanceByType(Class<T> type, Annotation... bindingTypes);
+ public <T> T getInstanceByType(Class<T> type, Annotation... bindings);
public <T> T getInstanceByType(TypeLiteral<T> type,
- Annotation... bindingTypes);
+ Annotation... bindings);
public Set<Bean<?>> resolveByName(String name);
@@ -80,6 +80,6 @@
Annotation... interceptorBindings);
public List<Decorator> resolveDecorators(Set<Class<?>> types,
- Annotation... bindingTypes);
+ Annotation... bindings);
}
16 years
[webbeans-commits] Webbeans SVN: r345 - in ri/trunk/webbeans-ri/src: main/java/org/jboss/webbeans/event and 1 other directories.
by webbeans-commits@lists.jboss.org
Author: dallen6
Date: 2008-11-20 13:18:43 -0500 (Thu, 20 Nov 2008)
New Revision: 345
Added:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/EventManager.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/EventManagerTest.java
Removed:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/EventBus.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/EventBusTest.java
Modified:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ManagerImpl.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/EventImpl.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/EventTest.java
Log:
Renamed the EventBus as EventManager and fixed the EventImpl to work properly with event types.
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ManagerImpl.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ManagerImpl.java 2008-11-20 12:02:52 UTC (rev 344)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ManagerImpl.java 2008-11-20 18:18:43 UTC (rev 345)
@@ -52,7 +52,7 @@
import org.jboss.webbeans.contexts.RequestContext;
import org.jboss.webbeans.contexts.SessionContext;
import org.jboss.webbeans.ejb.DefaultEnterpriseBeanLookup;
-import org.jboss.webbeans.event.EventBus;
+import org.jboss.webbeans.event.EventManager;
import org.jboss.webbeans.exceptions.NameResolutionLocation;
import org.jboss.webbeans.introspector.AnnotatedItem;
import org.jboss.webbeans.introspector.AnnotatedMethod;
@@ -72,7 +72,7 @@
{
private List<Class<? extends Annotation>> enabledDeploymentTypes;
private MetaDataCache metaDataCache;
- private EventBus eventBus;
+ private EventManager eventManager;
private Resolver resolver;
private ContextMap contextMap;
private ProxyPool proxyPool;
@@ -85,7 +85,7 @@
{
this.metaDataCache = new MetaDataCache();
this.beans = new CopyOnWriteArrayList<Bean<?>>();
- this.eventBus = new EventBus(this);
+ this.eventManager = new EventManager();
this.resolver = new Resolver(this);
this.proxyPool = new ProxyPool(this);
this.decorators = new HashSet<Decorator>();
@@ -200,7 +200,7 @@
*/
public <T> Set<Observer<T>> resolveObservers(T event, Annotation... bindings)
{
- return eventBus.getObservers(event, bindings);
+ return eventManager.getObservers(event, bindings);
}
/**
@@ -366,7 +366,7 @@
*/
public <T> Manager addObserver(Observer<T> observer, Class<T> eventType, Annotation... bindings)
{
- this.eventBus.addObserver(observer, eventType, bindings);
+ this.eventManager.addObserver(observer, eventType, bindings);
return this;
}
@@ -386,7 +386,7 @@
{
// TODO Using the eventType TypeLiteral<T>, the Class<T> object must be
// retrieved
- this.eventBus.addObserver(observer, (Class<T>) Reflections.getActualTypeArguments(eventType.getClass())[0], bindings);
+ this.eventManager.addObserver(observer, (Class<T>) Reflections.getActualTypeArguments(eventType.getClass())[0], bindings);
return this;
}
@@ -411,7 +411,7 @@
// parameterized, this
// method is not, so we have to use Observer<Object> for observers.
Set<Observer<Object>> observers = this.resolveObservers(event, bindings);
- this.eventBus.notifyObservers(observers, event);
+ this.eventManager.notifyObservers(observers, event);
}
/**
@@ -580,7 +580,7 @@
*/
public <T> Manager removeObserver(Observer<T> observer, Class<T> eventType, Annotation... bindings)
{
- this.eventBus.removeObserver(observer, eventType, bindings);
+ this.eventManager.removeObserver(observer, eventType, bindings);
return this;
}
@@ -600,7 +600,7 @@
{
// TODO The Class<T> for the event type must be retrieved from the
// TypeLiteral<T> instance
- this.eventBus.removeObserver(observer, (Class<T>) Reflections.getActualTypeArguments(eventType.getClass())[0], bindings);
+ this.eventManager.removeObserver(observer, (Class<T>) Reflections.getActualTypeArguments(eventType.getClass())[0], bindings);
return this;
}
@@ -669,8 +669,8 @@
buffer.append(" " + deploymentType.getName() + "\n");
}
- buffer.append("Event bus:\n");
- buffer.append(eventBus.toString());
+ buffer.append("Event manager:\n");
+ buffer.append(eventManager.toString());
buffer.append("Metadata cache:\n");
buffer.append(metaDataCache.toString());
Deleted: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/EventBus.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/EventBus.java 2008-11-20 12:02:52 UTC (rev 344)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/EventBus.java 2008-11-20 18:18:43 UTC (rev 345)
@@ -1,193 +0,0 @@
-package org.jboss.webbeans.event;
-
-import java.lang.annotation.Annotation;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.Map.Entry;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.CopyOnWriteArrayList;
-
-import javax.transaction.RollbackException;
-import javax.transaction.SystemException;
-import javax.transaction.Transaction;
-import javax.transaction.TransactionManager;
-import javax.webbeans.Observer;
-
-import org.jboss.webbeans.ManagerImpl;
-import org.jboss.webbeans.util.JNDI;
-
-/**
- * The event bus is where observers are registered and events are fired.
- *
- * @author David Allen
- *
- */
-public class EventBus
-{
- private ManagerImpl manager;
- private final Map<Class<?>, CopyOnWriteArrayList<EventObserver<?>>> registeredObservers;
- private TransactionManager transactionManager;
-
- /**
- * Initializes a new instance of the EventBus. This includes looking up the
- * transaction manager which is needed to defer events till the end of a
- * transaction.
- */
- public EventBus(ManagerImpl manager)
- {
- this.manager = manager;
- transactionManager = (TransactionManager) JNDI.lookup("java:/TransactionManager");
- registeredObservers = new ConcurrentHashMap<Class<?>, CopyOnWriteArrayList<EventObserver<?>>>();
- }
-
- /**
- * Adds an observer to the event bus so that it receives event notifications.
- *
- * @param observer The observer that should receive events
- */
- public <T> void addObserver(Observer<T> observer, Class<T> eventType, Annotation... bindings)
- {
- CopyOnWriteArrayList<EventObserver<?>> eventTypeObservers = registeredObservers.get(eventType);
- if (eventTypeObservers == null)
- {
- eventTypeObservers = new CopyOnWriteArrayList<EventObserver<?>>();
- registeredObservers.put(eventType, eventTypeObservers);
- }
- EventObserver<T> eventObserver = new EventObserver<T>(observer, eventType, bindings);
- if (!eventTypeObservers.contains(eventObserver))
- {
- eventTypeObservers.add(eventObserver);
- }
- }
-
- /**
- * Defers delivery of an event till the end of the currently active
- * transaction.
- *
- * @param event The event object to deliver
- * @param observer The observer to receive the event
- * @throws SystemException
- * @throws IllegalStateException
- * @throws RollbackException
- */
- public <T> void deferEvent(T event, Observer<T> observer) throws SystemException, IllegalStateException, RollbackException
- {
- if (transactionManager != null)
- {
- // Get the current transaction associated with the thread
- Transaction transaction = transactionManager.getTransaction();
- if (transaction != null)
- {
- transaction.registerSynchronization(new DeferredEventNotification<T>(event, observer));
- }
- }
- }
-
- /**
- * Resolves the list of observers to be notified for a given event and
- * optional event bindings.
- *
- * @param event The event object
- * @param bindings Optional event bindings
- * @return A set of Observers
- */
- @SuppressWarnings("unchecked")
- public <T> Set<Observer<T>> getObservers(T event, Annotation... bindings)
- {
- Set<Observer<T>> interestedObservers = new HashSet<Observer<T>>();
- for (EventObserver<?> observer : registeredObservers.get(event.getClass()))
- {
- if (observer.isObserverInterested(bindings))
- {
- interestedObservers.add((Observer<T>) observer.getObserver());
- }
- }
- return interestedObservers;
- }
-
- /**
- * Notifies each observer immediately of the event unless a transaction is
- * currently in progress, in which case a deferred event is created and
- * registered.
- *
- * @param <T>
- * @param observers
- * @param event
- */
- public <T> void notifyObservers(Set<Observer<T>> observers, T event)
- {
- for (Observer<T> observer : observers)
- {
- // TODO Replace this with the correct transaction code
- Transaction transaction = null;
- try
- {
- transaction = transactionManager.getTransaction();
- }
- catch (SystemException e)
- {
- }
- if (transaction != null)
- {
- try
- {
- deferEvent(event, observer);
- }
- catch (IllegalStateException e)
- {
- }
- catch (SystemException e)
- {
- }
- catch (RollbackException e)
- {
- // TODO If transaction is being rolled back, perhaps notification
- // should terminate now
- }
- }
- else
- {
- // Notify observer immediately in the same context as this method
- observer.notify(event);
- }
- }
- }
-
- /**
- * Removes an observer from the event bus.
- *
- * @param observer The observer to remove
- */
- public <T> void removeObserver(Observer<T> observer, Class<T> eventType, Annotation... bindings)
- {
- List<EventObserver<?>> observers = registeredObservers.get(eventType);
- for (Iterator<EventObserver<?>> i = observers.iterator(); i.hasNext();)
- {
- if (observer.equals(i.next().getObserver()))
- {
- i.remove();
- break;
- }
- }
- }
-
-
- @Override
- public String toString()
- {
- StringBuffer buffer = new StringBuffer();
- buffer.append("Registered observers: " + registeredObservers.size() + "\n");
- for (Entry<Class<?>, CopyOnWriteArrayList<EventObserver<?>>> entry : registeredObservers.entrySet())
- {
- buffer.append(entry.getKey().getName() + ":\n");
- for (EventObserver<?> observer : entry.getValue())
- {
- buffer.append(" " + observer.toString());
- }
- }
- return buffer.toString();
- }
-}
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/EventImpl.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/EventImpl.java 2008-11-20 12:02:52 UTC (rev 344)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/EventImpl.java 2008-11-20 18:18:43 UTC (rev 345)
@@ -1,7 +1,6 @@
package org.jboss.webbeans.event;
import java.lang.annotation.Annotation;
-import java.lang.reflect.Type;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
@@ -16,8 +15,6 @@
import javax.webbeans.Standard;
import javax.webbeans.manager.Manager;
-import org.jboss.webbeans.util.Reflections;
-
/**
* Implementation of the {@link Event} interface used for the container provided
* Web Bean to be injected for an observable event. See section 7.4 of the JSR
@@ -31,6 +28,7 @@
public class EventImpl<T> implements Event<T>
{
private Collection<? extends Annotation> eventBindings;
+ private Class<T> eventType;
// The current WB manager
@Current
@@ -72,7 +70,6 @@
.fireEvent(event, eventBindings.toArray(new Annotation[0]));
}
- @SuppressWarnings("unchecked")
public void observe(Observer<T> observer, Annotation... bindings)
{
// Register the observer with the web beans manager
@@ -80,8 +77,7 @@
Set<Annotation> eventBindings = new HashSet<Annotation>();
eventBindings.addAll(this.getBindingTypes());
addAnnotationBindings(eventBindings, bindings);
- Type[] observerTypeArguments = Reflections.getActualTypeArguments(observer.getClass());
- webBeansManager.addObserver(observer, (Class<T>) observerTypeArguments[0], bindings);
+ webBeansManager.addObserver(observer, eventType, bindings);
}
/**
@@ -156,5 +152,11 @@
{
this.webBeansManager = manager;
}
+
+ // TODO Use constructor injection
+ public void setEventType(Class<T> eventType)
+ {
+ this.eventType = eventType;
+ }
}
Copied: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/EventManager.java (from rev 336, ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/EventBus.java)
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/EventManager.java (rev 0)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/EventManager.java 2008-11-20 18:18:43 UTC (rev 345)
@@ -0,0 +1,203 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.jboss.webbeans.event;
+
+import java.lang.annotation.Annotation;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.Map.Entry;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.CopyOnWriteArrayList;
+
+import javax.transaction.RollbackException;
+import javax.transaction.SystemException;
+import javax.transaction.Transaction;
+import javax.transaction.TransactionManager;
+import javax.webbeans.Current;
+import javax.webbeans.Observer;
+
+/**
+ * The event bus is where observers are registered and events are fired.
+ *
+ * @author David Allen
+ *
+ */
+public class EventManager
+{
+ private final Map<Class<?>, CopyOnWriteArrayList<EventObserver<?>>> registeredObservers;
+
+ @Current
+ private TransactionManager transactionManager;
+
+ /**
+ * Initializes a new instance of the EventManager. This includes looking up the
+ * transaction manager which is needed to defer events till the end of a
+ * transaction.
+ */
+ public EventManager()
+ {
+ registeredObservers = new ConcurrentHashMap<Class<?>, CopyOnWriteArrayList<EventObserver<?>>>();
+ }
+
+ /**
+ * Adds an observer to the event bus so that it receives event notifications.
+ *
+ * @param observer
+ * The observer that should receive events
+ */
+ public <T> void addObserver(Observer<T> observer, Class<T> eventType, Annotation... bindings)
+ {
+ CopyOnWriteArrayList<EventObserver<?>> eventTypeObservers = registeredObservers.get(eventType);
+ if (eventTypeObservers == null)
+ {
+ eventTypeObservers = new CopyOnWriteArrayList<EventObserver<?>>();
+ registeredObservers.put(eventType, eventTypeObservers);
+ }
+ EventObserver<T> eventObserver = new EventObserver<T>(observer, eventType, bindings);
+ if (!eventTypeObservers.contains(eventObserver))
+ {
+ eventTypeObservers.add(eventObserver);
+ }
+ }
+
+ /**
+ * Defers delivery of an event till the end of the currently active
+ * transaction.
+ *
+ * @param event The event object to deliver
+ * @param observer The observer to receive the event
+ * @throws SystemException
+ * @throws IllegalStateException
+ * @throws RollbackException
+ */
+ public <T> void deferEvent(T event, Observer<T> observer) throws SystemException, IllegalStateException, RollbackException
+ {
+ if (transactionManager != null)
+ {
+ // Get the current transaction associated with the thread
+ Transaction transaction = transactionManager.getTransaction();
+ if (transaction != null)
+ {
+ transaction.registerSynchronization(new DeferredEventNotification<T>(event, observer));
+ }
+ }
+ }
+
+ /**
+ * Resolves the list of observers to be notified for a given event and
+ * optional event bindings.
+ *
+ * @param event The event object
+ * @param bindings Optional event bindings
+ * @return A set of Observers
+ */
+ @SuppressWarnings("unchecked")
+ public <T> Set<Observer<T>> getObservers(T event, Annotation... bindings)
+ {
+ Set<Observer<T>> interestedObservers = new HashSet<Observer<T>>();
+ for (EventObserver<?> observer : registeredObservers.get(event.getClass()))
+ {
+ if (observer.isObserverInterested(bindings))
+ {
+ interestedObservers.add((Observer<T>) observer.getObserver());
+ }
+ }
+ return interestedObservers;
+ }
+
+ /**
+ * Notifies each observer immediately of the event unless a transaction is
+ * currently in progress, in which case a deferred event is created and
+ * registered.
+ *
+ * @param <T>
+ * @param observers
+ * @param event
+ */
+ public <T> void notifyObservers(Set<Observer<T>> observers, T event)
+ {
+ for (Observer<T> observer : observers)
+ {
+ // TODO Replace this with the correct transaction code
+ Transaction transaction = null;
+ try
+ {
+ transaction = transactionManager.getTransaction();
+ } catch (SystemException e)
+ {
+ }
+ if (transaction != null)
+ {
+ try
+ {
+ deferEvent(event, observer);
+ } catch (IllegalStateException e)
+ {
+ } catch (SystemException e)
+ {
+ } catch (RollbackException e)
+ {
+ // TODO If transaction is being rolled back, perhaps notification should terminate now
+ }
+ } else
+ {
+ // Notify observer immediately in the same context as this method
+ observer.notify(event);
+ }
+ }
+ }
+
+ /**
+ * Removes an observer from the event bus.
+ *
+ * @param observer
+ * The observer to remove
+ */
+ public <T> void removeObserver(Observer<T> observer, Class<T> eventType, Annotation... bindings)
+ {
+ List<EventObserver<?>> observers = registeredObservers.get(eventType);
+ for (Iterator<EventObserver<?>> i = observers.iterator(); i.hasNext();)
+ {
+ if (observer.equals(i.next().getObserver()))
+ {
+ i.remove();
+ break;
+ }
+ }
+ }
+
+
+ @Override
+ public String toString()
+ {
+ StringBuffer buffer = new StringBuffer();
+ buffer.append("Registered observers: " + registeredObservers.size() + "\n");
+ for (Entry<Class<?>, CopyOnWriteArrayList<EventObserver<?>>> entry : registeredObservers.entrySet())
+ {
+ buffer.append(entry.getKey().getName() + ":\n");
+ for (EventObserver<?> observer : entry.getValue())
+ {
+ buffer.append(" " + observer.toString());
+ }
+ }
+ return buffer.toString();
+ }
+}
Property changes on: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/EventManager.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Deleted: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/EventBusTest.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/EventBusTest.java 2008-11-20 12:02:52 UTC (rev 344)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/EventBusTest.java 2008-11-20 18:18:43 UTC (rev 345)
@@ -1,190 +0,0 @@
-package org.jboss.webbeans.test;
-
-import java.util.Set;
-
-import javax.transaction.HeuristicMixedException;
-import javax.transaction.HeuristicRollbackException;
-import javax.transaction.InvalidTransactionException;
-import javax.transaction.NotSupportedException;
-import javax.transaction.RollbackException;
-import javax.transaction.Synchronization;
-import javax.transaction.SystemException;
-import javax.transaction.Transaction;
-import javax.transaction.TransactionManager;
-import javax.transaction.xa.XAResource;
-import javax.webbeans.Observer;
-
-import org.jboss.webbeans.event.DeferredEventNotification;
-import org.jboss.webbeans.event.EventBus;
-import org.jboss.webbeans.test.beans.DangerCall;
-import org.jboss.webbeans.test.bindings.TameAnnotationLiteral;
-import org.testng.annotations.Test;
-
-/**
- * Tests for the EventBus implementation used by the Web Beans RI.
- *
- * @author David Allen
- *
- */
-@SpecVersion("PDR")
-public class EventBusTest extends AbstractTest
-{
- public class AnObserver<T> implements Observer<T>
- {
- public void notify(T event)
- {
- }
- }
-
- private Synchronization registeredSynch;
-
- /**
- * Tests adding an observer to the event bus and verified that it can still
- * be retrieved for a corresponding event.
- */
- @Test(groups = "observerMethod")
- public void testAddObserver()
- {
- EventBus eventBus = new EventBus(manager);
- Observer<DangerCall> observer = new AnObserver<DangerCall>();
- eventBus.addObserver(observer, DangerCall.class);
- DangerCall event = new DangerCall();
-
- Set<Observer<DangerCall>> observerSet = eventBus.getObservers(event);
- assert observerSet.size() == 1;
- assert observerSet.iterator().next().equals(observer);
-
- // Add another observer for the same event, but with an event binding
- observer = new AnObserver<DangerCall>();
- eventBus.addObserver(observer, DangerCall.class, new TameAnnotationLiteral());
- observerSet = eventBus.getObservers(event);
- assert observerSet.size() == 1;
- observerSet = eventBus.getObservers(event, new TameAnnotationLiteral());
- assert observerSet.size() == 2;
- }
-
- /**
- * Tests the remove operation and verifies that the observer is no longer
- * registered for events.
- */
- @Test(groups = {"observerMethod", "broken"})
- public void testRemoveObserver()
- {
- EventBus eventBus = new EventBus(manager);
- Observer<DangerCall> observer = new AnObserver<DangerCall>();
- eventBus.addObserver(observer, DangerCall.class);
- eventBus.removeObserver(observer, DangerCall.class);
- // FIXME CopyOnWrite broke remove, have to check later
- assert eventBus.getObservers(new DangerCall()).isEmpty();
- }
-
- /**
- * Tests the deferred event feature associated with transactions.
- */
- @Test(groups = {"deferredEvent", "broken"})
- public void testDeferEvent()
- {
- // Setup a transaction manager for this test and inject into the event bus
- TransactionManager tm = new TransactionManager() {
- public void begin() throws NotSupportedException, SystemException
- {
- }
-
- public void commit() throws RollbackException,
- HeuristicMixedException, HeuristicRollbackException,
- SecurityException, IllegalStateException, SystemException
- {
- }
-
- public int getStatus() throws SystemException
- {
- return 0;
- }
-
- public Transaction getTransaction() throws SystemException
- {
- return new Transaction() {
-
- public void commit() throws RollbackException,
- HeuristicMixedException, HeuristicRollbackException,
- SecurityException, IllegalStateException, SystemException
- {
- }
-
- public boolean delistResource(XAResource arg0, int arg1)
- throws IllegalStateException, SystemException
- {
- return false;
- }
-
- public boolean enlistResource(XAResource arg0)
- throws RollbackException, IllegalStateException,
- SystemException
- {
- return false;
- }
-
- public int getStatus() throws SystemException
- {
- return 0;
- }
-
- public void registerSynchronization(Synchronization synchronization)
- throws RollbackException, IllegalStateException,
- SystemException
- {
- registeredSynch = synchronization;
- }
-
- public void rollback() throws IllegalStateException,
- SystemException
- {
- }
-
- public void setRollbackOnly() throws IllegalStateException,
- SystemException
- {
- }
-
- };
- }
-
- public void resume(Transaction arg0)
- throws InvalidTransactionException, IllegalStateException,
- SystemException
- {
- }
-
- public void rollback() throws IllegalStateException,
- SecurityException, SystemException
- {
- }
-
- public void setRollbackOnly() throws IllegalStateException,
- SystemException
- {
- }
-
- public void setTransactionTimeout(int arg0) throws SystemException
- {
- }
-
- public Transaction suspend() throws SystemException
- {
- return null;
- }
-
- };
- EventBus eventBus = new EventBus(manager);
- Observer<DangerCall> observer = new AnObserver<DangerCall>();
- try
- {
- eventBus.deferEvent(new DangerCall(), observer);
- } catch (Exception e)
- {
- }
-
- assert this.registeredSynch != null;
- assert ((DeferredEventNotification)this.registeredSynch).getObserver().equals(observer);
- }
-}
Copied: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/EventManagerTest.java (from rev 336, ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/EventBusTest.java)
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/EventManagerTest.java (rev 0)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/EventManagerTest.java 2008-11-20 18:18:43 UTC (rev 345)
@@ -0,0 +1,190 @@
+package org.jboss.webbeans.test;
+
+import java.util.Set;
+
+import javax.transaction.HeuristicMixedException;
+import javax.transaction.HeuristicRollbackException;
+import javax.transaction.InvalidTransactionException;
+import javax.transaction.NotSupportedException;
+import javax.transaction.RollbackException;
+import javax.transaction.Synchronization;
+import javax.transaction.SystemException;
+import javax.transaction.Transaction;
+import javax.transaction.TransactionManager;
+import javax.transaction.xa.XAResource;
+import javax.webbeans.Observer;
+
+import org.jboss.webbeans.event.DeferredEventNotification;
+import org.jboss.webbeans.event.EventManager;
+import org.jboss.webbeans.test.beans.DangerCall;
+import org.jboss.webbeans.test.bindings.TameAnnotationLiteral;
+import org.testng.annotations.Test;
+
+/**
+ * Tests for the EventManager implementation used by the Web Beans RI.
+ *
+ * @author David Allen
+ *
+ */
+@SpecVersion("PDR")
+public class EventManagerTest extends AbstractTest
+{
+ public class AnObserver<T> implements Observer<T>
+ {
+ public void notify(T event)
+ {
+ }
+ }
+
+ private Synchronization registeredSynch;
+
+ /**
+ * Tests adding an observer to the event bus and verified that it can still
+ * be retrieved for a corresponding event.
+ */
+ @Test(groups = "observerMethod")
+ public void testAddObserver()
+ {
+ EventManager eventManager = new EventManager();
+ Observer<DangerCall> observer = new AnObserver<DangerCall>();
+ eventManager.addObserver(observer, DangerCall.class);
+ DangerCall event = new DangerCall();
+
+ Set<Observer<DangerCall>> observerSet = eventManager.getObservers(event);
+ assert observerSet.size() == 1;
+ assert observerSet.iterator().next().equals(observer);
+
+ // Add another observer for the same event, but with an event binding
+ observer = new AnObserver<DangerCall>();
+ eventManager.addObserver(observer, DangerCall.class, new TameAnnotationLiteral());
+ observerSet = eventManager.getObservers(event);
+ assert observerSet.size() == 1;
+ observerSet = eventManager.getObservers(event, new TameAnnotationLiteral());
+ assert observerSet.size() == 2;
+ }
+
+ /**
+ * Tests the remove operation and verifies that the observer is no longer
+ * registered for events.
+ */
+ @Test(groups = {"observerMethod", "broken"})
+ public void testRemoveObserver()
+ {
+ EventManager eventManager = new EventManager();
+ Observer<DangerCall> observer = new AnObserver<DangerCall>();
+ eventManager.addObserver(observer, DangerCall.class);
+ eventManager.removeObserver(observer, DangerCall.class);
+ // FIXME CopyOnWrite broke remove, have to check later
+ assert eventManager.getObservers(new DangerCall()).isEmpty();
+ }
+
+ /**
+ * Tests the deferred event feature associated with transactions.
+ */
+ @Test(groups = {"deferredEvent", "broken"})
+ public void testDeferEvent()
+ {
+ // Setup a transaction manager for this test and inject into the event bus
+// TransactionManager tm = new TransactionManager() {
+// public void begin() throws NotSupportedException, SystemException
+// {
+// }
+//
+// public void commit() throws RollbackException,
+// HeuristicMixedException, HeuristicRollbackException,
+// SecurityException, IllegalStateException, SystemException
+// {
+// }
+//
+// public int getStatus() throws SystemException
+// {
+// return 0;
+// }
+//
+// public Transaction getTransaction() throws SystemException
+// {
+// return new Transaction() {
+//
+// public void commit() throws RollbackException,
+// HeuristicMixedException, HeuristicRollbackException,
+// SecurityException, IllegalStateException, SystemException
+// {
+// }
+//
+// public boolean delistResource(XAResource arg0, int arg1)
+// throws IllegalStateException, SystemException
+// {
+// return false;
+// }
+//
+// public boolean enlistResource(XAResource arg0)
+// throws RollbackException, IllegalStateException,
+// SystemException
+// {
+// return false;
+// }
+//
+// public int getStatus() throws SystemException
+// {
+// return 0;
+// }
+//
+// public void registerSynchronization(Synchronization synchronization)
+// throws RollbackException, IllegalStateException,
+// SystemException
+// {
+// registeredSynch = synchronization;
+// }
+//
+// public void rollback() throws IllegalStateException,
+// SystemException
+// {
+// }
+//
+// public void setRollbackOnly() throws IllegalStateException,
+// SystemException
+// {
+// }
+//
+// };
+// }
+//
+// public void resume(Transaction arg0)
+// throws InvalidTransactionException, IllegalStateException,
+// SystemException
+// {
+// }
+//
+// public void rollback() throws IllegalStateException,
+// SecurityException, SystemException
+// {
+// }
+//
+// public void setRollbackOnly() throws IllegalStateException,
+// SystemException
+// {
+// }
+//
+// public void setTransactionTimeout(int arg0) throws SystemException
+// {
+// }
+//
+// public Transaction suspend() throws SystemException
+// {
+// return null;
+// }
+//
+// };
+ EventManager eventManager = new EventManager();
+ Observer<DangerCall> observer = new AnObserver<DangerCall>();
+ try
+ {
+ eventManager.deferEvent(new DangerCall(), observer);
+ } catch (Exception e)
+ {
+ }
+
+ assert this.registeredSynch != null;
+ assert ((DeferredEventNotification)this.registeredSynch).getObserver().equals(observer);
+ }
+}
Property changes on: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/EventManagerTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/EventTest.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/EventTest.java 2008-11-20 12:02:52 UTC (rev 344)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/EventTest.java 2008-11-20 18:18:43 UTC (rev 345)
@@ -48,6 +48,7 @@
}
}
+ @SuppressWarnings("unchecked")
@BeforeMethod
public void before() throws Exception
{
@@ -107,7 +108,7 @@
* Tests the {@link Event#observe(javax.webbeans.Observer, Annotation...)}
* method with a locally instantiated implementation.
*/
- @Test(groups = {"observerMethod", "broken"})
+ @Test(groups = {"observerMethod"})
@SpecAssertion(section = "7.6")
public void testObserve()
{
@@ -115,6 +116,7 @@
// event object
Annotation[] annotations = new Annotation[] { new TameAnnotationLiteral() };
EventImpl<DangerCall> eventComponent = new EventImpl<DangerCall>();
+ eventComponent.setEventType(DangerCall.class);
eventComponent.setEventBindings(annotations);
eventComponent.setManager(manager);
Observer<DangerCall> observer = new AnObserver<DangerCall>();
16 years
[webbeans-commits] Webbeans SVN: r344 - ri/trunk.
by webbeans-commits@lists.jboss.org
Author: alesj
Date: 2008-11-20 07:02:52 -0500 (Thu, 20 Nov 2008)
New Revision: 344
Modified:
ri/trunk/build.xml
Log:
You still need jbossas, as that's where our WBD impl lives. ;-)
Modified: ri/trunk/build.xml
===================================================================
--- ri/trunk/build.xml 2008-11-20 11:55:55 UTC (rev 343)
+++ ri/trunk/build.xml 2008-11-20 12:02:52 UTC (rev 344)
@@ -12,6 +12,7 @@
<artifact:dependencies filesetId="jboss5.deployer.fileset" versionsId="jboss5.deployer.versions">
<dependency groupId="org.jboss.webbeans.integration" artifactId="webbeans-ri-int-microcontainer" version="5.2.0-SNAPSHOT"/>
+ <dependency groupId="org.jboss.webbeans.integration" artifactId="webbeans-ri-int-jbossas" version="5.2.0-SNAPSHOT"/>
</artifact:dependencies>
<artifact:dependencies filesetId="google.collections.fileset">
16 years
[webbeans-commits] Webbeans SVN: r342 - in ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans: bean/proxy and 2 other directories.
by webbeans-commits@lists.jboss.org
Author: nickarls
Date: 2008-11-20 06:45:37 -0500 (Thu, 20 Nov 2008)
New Revision: 342
Modified:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ManagerImpl.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/MetaDataCache.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/Resolver.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/proxy/ProxyPool.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/ContextMap.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/EventBus.java
Log:
minors
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ManagerImpl.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ManagerImpl.java 2008-11-20 11:41:07 UTC (rev 341)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ManagerImpl.java 2008-11-20 11:45:37 UTC (rev 342)
@@ -662,46 +662,46 @@
public String toString()
{
StringBuffer buffer = new StringBuffer();
-
+
buffer.append("Enabled deployment types:\n");
for (Class<? extends Annotation> deploymentType : enabledDeploymentTypes)
{
- buffer.append(deploymentType.getName() + "\n");
+ buffer.append(" " + deploymentType.getName() + "\n");
}
-
+
buffer.append("Event bus:\n");
buffer.append(eventBus.toString());
-
+
buffer.append("Metadata cache:\n");
buffer.append(metaDataCache.toString());
-
- buffer.append("Event bus:\n");
- buffer.append(eventBus.toString());
-
+
buffer.append("Resolver:\n");
buffer.append(resolver.toString());
-
+
buffer.append("Context map:\n");
buffer.append(contextMap.toString());
buffer.append("Proxy pool:\n");
buffer.append(proxyPool.toString());
-
+
buffer.append("Registered beans: " + beans.size() + "\n");
- for (Bean<?> bean : beans) {
- buffer.append(bean.toString());
+ for (Bean<?> bean : beans)
+ {
+ buffer.append(" " + bean.toString() + "\n");
}
-
+
buffer.append("Registered decorators: " + decorators.size() + "\n");
- for (Decorator decorator : decorators) {
- buffer.append(decorator.toString());
+ for (Decorator decorator : decorators)
+ {
+ buffer.append(" " + decorator.toString() + "\n");
}
-
+
buffer.append("Registered interceptors: " + interceptors.size() + "\n");
- for (Interceptor interceptor : interceptors) {
- buffer.append(interceptor.toString());
+ for (Interceptor interceptor : interceptors)
+ {
+ buffer.append(" " + interceptor.toString() + "\n");
}
-
+
return buffer.toString();
}
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/MetaDataCache.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/MetaDataCache.java 2008-11-20 11:41:07 UTC (rev 341)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/MetaDataCache.java 2008-11-20 11:45:37 UTC (rev 342)
@@ -165,7 +165,7 @@
@Override
public String toString() {
StringBuffer buffer = new StringBuffer();
- buffer.append("FIX ME");
+ buffer.append("FIX ME!\n");
return buffer.toString();
}
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/Resolver.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/Resolver.java 2008-11-20 11:41:07 UTC (rev 341)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/Resolver.java 2008-11-20 11:45:37 UTC (rev 342)
@@ -328,7 +328,7 @@
@Override
public String toString() {
StringBuffer buffer = new StringBuffer();
- buffer.append("FIX ME");
+ buffer.append("FIX ME!\n");
return buffer.toString();
}
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/proxy/ProxyPool.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/proxy/ProxyPool.java 2008-11-20 11:41:07 UTC (rev 341)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/proxy/ProxyPool.java 2008-11-20 11:45:37 UTC (rev 342)
@@ -180,4 +180,11 @@
return clientProxy;
}
+ @Override
+ public String toString() {
+ StringBuffer buffer = new StringBuffer();
+ buffer.append("FIX ME!\n");
+ return buffer.toString();
+ }
+
}
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/ContextMap.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/ContextMap.java 2008-11-20 11:41:07 UTC (rev 341)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/ContextMap.java 2008-11-20 11:45:37 UTC (rev 342)
@@ -81,12 +81,12 @@
public String toString()
{
StringBuffer buffer = new StringBuffer();
- buffer.append("Known scope types: " + delegate.size());
+ buffer.append("Known scope types: " + delegate.size() + "\n");
for (Entry<Class<? extends Annotation>, List<Context>> entry : delegate.entrySet())
{
for (Context context : entry.getValue())
{
- buffer.append(context.toString());
+ buffer.append(context.toString() + "\n");
}
}
return buffer.toString();
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/EventBus.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/EventBus.java 2008-11-20 11:41:07 UTC (rev 341)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/EventBus.java 2008-11-20 11:45:37 UTC (rev 342)
@@ -166,7 +166,7 @@
List<EventObserver<?>> observers = registeredObservers.get(eventType);
for (Iterator<EventObserver<?>> i = observers.iterator(); i.hasNext();)
{
- if (observer.equals(i.next()))
+ if (observer.equals(i.next().getObserver()))
{
i.remove();
break;
16 years