[jboss-cvs] jboss-seam/src/main/org/jboss/seam/init ...
Gavin King
gavin.king at jboss.com
Sun Feb 4 02:57:19 EST 2007
User: gavin
Date: 07/02/04 02:57:19
Modified: src/main/org/jboss/seam/init Initialization.java
Log:
move event mappings into components.xml
Revision Changes Path
1.143 +82 -8 jboss-seam/src/main/org/jboss/seam/init/Initialization.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: Initialization.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/init/Initialization.java,v
retrieving revision 1.142
retrieving revision 1.143
diff -u -b -r1.142 -r1.143
--- Initialization.java 2 Feb 2007 14:51:58 -0000 1.142
+++ Initialization.java 4 Feb 2007 07:57:19 -0000 1.143
@@ -34,6 +34,7 @@
import org.jboss.seam.contexts.Context;
import org.jboss.seam.contexts.Contexts;
import org.jboss.seam.contexts.Lifecycle;
+import org.jboss.seam.core.Expressions;
import org.jboss.seam.core.Init;
import org.jboss.seam.core.Jbpm;
import org.jboss.seam.core.PojoCache;
@@ -52,7 +53,7 @@
/**
* @author Gavin King
* @author <a href="mailto:theute at jboss.org">Thomas Heute</a>
- * @version $Revision: 1.142 $
+ * @version $Revision: 1.143 $
*/
public class Initialization
{
@@ -65,7 +66,8 @@
private List<FactoryDescriptor> factoryDescriptors = new ArrayList<FactoryDescriptor>();
private Set<Class> installedComponents = new HashSet<Class>();
private Set<String> importedPackages = new HashSet<String>();
- private Map<String, NamespaceInfo> namespaceMap = new HashMap<String, NamespaceInfo>();
+ private Map<String, NamespaceDescriptor> namespaceMap = new HashMap<String, NamespaceDescriptor>();
+ private final Map<String, EventListenerDescriptor> eventListenerDescriptors = new HashMap<String, EventListenerDescriptor>();
public Initialization(ServletContext servletContext)
{
@@ -169,10 +171,16 @@
installFactoryFromXmlElement(factory);
}
+ List<Element> elements = rootElement.elements("event");
+ for (Element event: elements)
+ {
+ installEventListenerFromXmlElement(event);
+ }
+
for (Element elem : (List<Element>) rootElement.elements())
{
String ns = elem.getNamespace().getURI();
- NamespaceInfo nsInfo = namespaceMap.get(ns);
+ NamespaceDescriptor nsInfo = namespaceMap.get(ns);
if (nsInfo != null)
{
String name = elem.attributeValue("name");
@@ -205,6 +213,32 @@
}
}
+ private void installEventListenerFromXmlElement(Element event)
+ {
+ String type = event.attributeValue("type");
+ if (type==null)
+ {
+ throw new IllegalArgumentException("must specify type for <event/> declaration");
+ }
+ EventListenerDescriptor eventListener = eventListenerDescriptors.get(type);
+ if (eventListener==null)
+ {
+ eventListener = new EventListenerDescriptor(type);
+ eventListenerDescriptors.put(type, eventListener);
+ }
+
+ List<Element> actions = event.elements("action");
+ for (Element action: actions)
+ {
+ String actionExpression = action.attributeValue("expression");
+ if (actionExpression==null)
+ {
+ throw new IllegalArgumentException("must specify expression for <action/> declaration");
+ }
+ eventListener.getListenerMethodBindings().add(actionExpression);
+ }
+ }
+
private void installFactoryFromXmlElement(Element factory)
{
String scopeName = factory.attributeValue("scope");
@@ -524,7 +558,7 @@
if (ns != null)
{
log.info("Namespace: " + ns.value() + ", package: " + pkg.getName() + ", prefix: " + ns.prefix());
- namespaceMap.put(ns.value(), new NamespaceInfo(ns, pkg));
+ namespaceMap.put(ns.value(), new NamespaceDescriptor(ns, pkg));
}
}
}
@@ -687,6 +721,14 @@
init.addAutocreateVariable(factoryDescriptor.getName());
}
}
+
+ for (EventListenerDescriptor listenerDescriptor: eventListenerDescriptors.values())
+ {
+ for (String expression: listenerDescriptor.getListenerMethodBindings())
+ {
+ init.addObserverMethodBinding( listenerDescriptor.getType(), Expressions.instance().createMethodBinding(expression) );
+ }
+ }
}
protected boolean dependenciesMet(Context context, ComponentDescriptor descriptor)
@@ -777,7 +819,7 @@
private String value;
private boolean autoCreate;
- public FactoryDescriptor(String name, ScopeType scope, String method, String value,
+ FactoryDescriptor(String name, ScopeType scope, String method, String value,
boolean autoCreate)
{
super();
@@ -825,12 +867,12 @@
}
}
- private static class NamespaceInfo
+ private static class NamespaceDescriptor
{
private Namespace namespace;
private Package pkg;
- public NamespaceInfo(Namespace namespace, Package pkg)
+ NamespaceDescriptor(Namespace namespace, Package pkg)
{
this.namespace = namespace;
this.pkg = pkg;
@@ -846,6 +888,38 @@
return pkg;
}
+ @Override
+ public String toString()
+ {
+ return "EventListenerDescriptor(" + namespace + ')';
+ }
+ }
+
+ private static class EventListenerDescriptor
+ {
+ private String type;
+ private List<String> listenerMethodBindings = new ArrayList<String>();
+
+ EventListenerDescriptor(String type)
+ {
+ this.type = type;
+ }
+
+ public String getType()
+ {
+ return type;
+ }
+
+ public List<String> getListenerMethodBindings()
+ {
+ return listenerMethodBindings;
+ }
+
+ @Override
+ public String toString()
+ {
+ return "EventListenerDescriptor(" + type + ')';
+ }
}
private static class ComponentDescriptor
@@ -861,7 +935,7 @@
/**
* For components.xml
*/
- public ComponentDescriptor(String name, Class<?> componentClass, ScopeType scope,
+ ComponentDescriptor(String name, Class<?> componentClass, ScopeType scope,
boolean autoCreate, String jndiName, Boolean installed, Integer precedence)
{
this.name = name;
More information about the jboss-cvs-commits
mailing list