Author: shane.bryzak(a)jboss.com
Date: 2009-12-23 05:22:55 -0500 (Wed, 23 Dec 2009)
New Revision: 11875
Modified:
modules/remoting/trunk/examples/helloworld/src/main/webapp/helloworld.xhtml
modules/remoting/trunk/src/main/java/org/jboss/seam/remoting/InterfaceGenerator.java
modules/remoting/trunk/src/main/resources/org/jboss/seam/remoting/remote.js
Log:
dynamic component definition
Modified: modules/remoting/trunk/examples/helloworld/src/main/webapp/helloworld.xhtml
===================================================================
--- modules/remoting/trunk/examples/helloworld/src/main/webapp/helloworld.xhtml 2009-12-22
09:21:03 UTC (rev 11874)
+++ modules/remoting/trunk/examples/helloworld/src/main/webapp/helloworld.xhtml 2009-12-23
10:22:55 UTC (rev 11875)
@@ -42,6 +42,8 @@
<script type="text/javascript">
//<![CDATA[
+ Seam.debug = true;
+
function getRadioValue(options)
{
for (var i = 0; i < options.length; i++)
Modified:
modules/remoting/trunk/src/main/java/org/jboss/seam/remoting/InterfaceGenerator.java
===================================================================
---
modules/remoting/trunk/src/main/java/org/jboss/seam/remoting/InterfaceGenerator.java 2009-12-22
09:21:03 UTC (rev 11874)
+++
modules/remoting/trunk/src/main/java/org/jboss/seam/remoting/InterfaceGenerator.java 2009-12-23
10:22:55 UTC (rev 11875)
@@ -22,7 +22,6 @@
import javax.enterprise.inject.spi.Bean;
import javax.enterprise.inject.spi.BeanManager;
import javax.inject.Inject;
-import javax.inject.Named;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@@ -286,8 +285,6 @@
private void appendBeanSource(OutputStream out, Class<?> beanClass,
Set<Type> types)
throws IOException
{
- StringBuilder componentSrc = new StringBuilder();
-
Set<Class<?>> componentTypes = new HashSet<Class<?>>();
// Check if any of the methods are annotated with @WebRemote, and if so
@@ -325,19 +322,7 @@
String name = beanManager.getBeans(beanClass).iterator().next().getName();
String beanName = name != null ? name : beanClass.getName();
- if (beanName.contains("."))
- {
- componentSrc.append("Seam.createNamespace('");
- componentSrc.append(beanName.substring(0, beanName.lastIndexOf('.')));
- componentSrc.append("');\n");
- }
-
- componentSrc.append("Seam.type.");
- componentSrc.append(beanName);
- componentSrc.append(" = function() {\n");
- componentSrc.append(" this.__callback = new Object();\n");
-
for (Class<?> type : componentTypes)
{
if (types.contains(type))
@@ -348,68 +333,42 @@
{
types.add(type);
+ // Build the bean stub
+ StringBuilder componentSrc = new StringBuilder();
+ componentSrc.append("Seam.registerBean(\"");
+ componentSrc.append(beanName);
+ componentSrc.append("\", null, {");
+
+ boolean first = true;
for (Method m : type.getDeclaredMethods())
{
if (m.getAnnotation(WebRemote.class) == null)
continue;
+ if (!first)
+ {
+ componentSrc.append(", ");
+ }
+ else
+ {
+ first = false;
+ }
+
// Append the return type to the source block
appendTypeSource(out, m.getGenericReturnType(), types);
-
- componentSrc.append(" Seam.type.");
- componentSrc.append(beanName);
- componentSrc.append(".prototype.");
+
componentSrc.append(m.getName());
- componentSrc.append(" = function(");
+ componentSrc.append(": ");
+ componentSrc.append(m.getGenericParameterTypes().length);
- // Insert parameters p0..pN
for (int i = 0; i < m.getGenericParameterTypes().length; i++)
{
appendTypeSource(out, m.getGenericParameterTypes()[i], types);
-
- if (i > 0)
- {
- componentSrc.append(", ");
- }
- componentSrc.append("p");
- componentSrc.append(i);
- }
-
- if (m.getGenericParameterTypes().length > 0)
- componentSrc.append(", ");
-
- componentSrc.append("callback, exceptionHandler) {\n");
- componentSrc.append(" return Seam.execute(this, \"");
- componentSrc.append(m.getName());
- componentSrc.append("\", [");
-
- for (int i = 0; i < m.getParameterTypes().length; i++)
- {
- if (i > 0)
- componentSrc.append(", ");
- componentSrc.append("p");
- componentSrc.append(i);
- }
-
- componentSrc.append("], callback, exceptionHandler);\n");
- componentSrc.append(" }\n");
+ }
}
+ componentSrc.append("});\n");
+ out.write(componentSrc.toString().getBytes());
}
- componentSrc.append("}\n");
-
- // Set the component name
- componentSrc.append("Seam.type.");
- componentSrc.append(beanName);
- componentSrc.append(".__name = \"");
- componentSrc.append(beanName);
- componentSrc.append("\";\n\n");
-
- // Register the component
- componentSrc.append("Seam.registerBean(Seam.type.");
- componentSrc.append(beanName);
- componentSrc.append(");\n\n");
-
- out.write(componentSrc.toString().getBytes());
}
}
@@ -477,25 +436,12 @@
return;
}
- StringBuilder typeSource = new StringBuilder();
-
- // Determine whether this class is a component; if so, use its name
- // otherwise use its class name.
Bean<?> bean = beanManager.getBeans(classType).iterator().next();
String componentName = bean.getName();
if (componentName == null)
componentName = classType.getName();
- String typeName = componentName.replace('.', '$');
-
- typeSource.append("Seam.type.");
- typeSource.append(typeName);
- typeSource.append(" = function() {\n");
-
- StringBuilder fields = new StringBuilder();
- StringBuilder accessors = new StringBuilder();
- StringBuilder mutators = new StringBuilder();
Map<String, String> metadata = new HashMap<String, String>();
String getMethodName = null;
@@ -606,78 +552,28 @@
if (getMethodName != null || setMethodName != null)
{
metadata.put(propertyName, getFieldType(propertyType));
-
- fields.append(" this.");
- fields.append(propertyName);
- fields.append(" = undefined;\n");
-
- if (getMethodName != null)
- {
- accessors.append(" Seam.type.");
- accessors.append(typeName);
- accessors.append(".prototype.");
- accessors.append(getMethodName);
- accessors.append(" = function() { return this.");
- accessors.append(propertyName);
- accessors.append("; }\n");
- }
-
- if (setMethodName != null)
- {
- mutators.append(" Seam.type.");
- mutators.append(typeName);
- mutators.append(".prototype.");
- mutators.append(setMethodName);
- mutators.append(" = function(");
- mutators.append(propertyName);
- mutators.append(") { this.");
- mutators.append(propertyName);
- mutators.append(" = ");
- mutators.append(propertyName);
- mutators.append("; }\n");
- }
}
}
- typeSource.append(fields);
- typeSource.append(accessors);
- typeSource.append(mutators);
-
- typeSource.append("}\n\n");
-
- // Append the type name
- typeSource.append("Seam.type.");
- typeSource.append(typeName);
- typeSource.append(".__name = \"");
+ StringBuilder typeSource = new StringBuilder();
+ typeSource.append("Seam.registerBean(\"");
typeSource.append(componentName);
- typeSource.append("\";\n");
+ typeSource.append("\", {");
- // Append the metadata
- typeSource.append("Seam.type.");
- typeSource.append(typeName);
- typeSource.append(".__metadata = [\n");
-
boolean first = true;
-
for (String key : metadata.keySet())
{
if (!first)
- typeSource.append(",\n");
-
- typeSource.append(" {field: \"");
+ typeSource.append(", ");
typeSource.append(key);
- typeSource.append("\", type: \"");
+ typeSource.append(": \"");
typeSource.append(metadata.get(key));
- typeSource.append("\"}");
-
+ typeSource.append("\"");
first = false;
- }
+ }
+
+ typeSource.append("});\n");
- typeSource.append("];\n\n");
- typeSource.append("Seam.registerBean(Seam.type.");
- typeSource.append(typeName);
- typeSource.append(");\n\n");
-
out.write(typeSource.toString().getBytes());
}
Modified: modules/remoting/trunk/src/main/resources/org/jboss/seam/remoting/remote.js
===================================================================
--- modules/remoting/trunk/src/main/resources/org/jboss/seam/remoting/remote.js 2009-12-22
09:21:03 UTC (rev 11874)
+++ modules/remoting/trunk/src/main/resources/org/jboss/seam/remoting/remote.js 2009-12-23
10:22:55 UTC (rev 11875)
@@ -1,5 +1,4 @@
var Seam = {
- type: {},
beans: new Array(),
debug: false,
debugWindow: null,
@@ -39,15 +38,43 @@
return t ? t.__name : undefined;
}
-Seam.registerBean = function(bean) {
+Seam.registerBean = function(name, metadata, methods) {
+ var t = function() {};
+ t.__name = name;
+
+ if (metadata) {
+ var m = new Array();
+ for (var f in metadata) {
+ var s = f.substring(0,1).toUpperCase() + f.substring(1);
+ t.prototype["set" + s] = function(value) { this[f] = value; };
+ t.prototype["get" + s] = function() { return this[f]; };
+ m.push({field:f, type:metadata[f]});
+ }
+ t.__metadata = m;
+ }
+ else {
+ for (var m in methods) {
+ var pc = methods[m];
+ t.prototype[m] = function() {
+ var p = new Array();
+ for (var i=0; i<pc; i++) {
+ p[i] = arguments[i];
+ }
+ var c = (arguments.length > pc) ? arguments[pc] : undefined;
+ var eh = (arguments.length > (pc + 1)) ? arguments[pc + 1] : undefined;
+ return Seam.execute(this, m, p, c, eh);
+ };
+ }
+ }
+
var b = Seam.beans;
for (var i=0; i<b.length; i++) {
- if (b[i].__name == bean.__name) {
- b[i] = bean;
+ if (b[i].__name == name) {
+ b[i] = t;
return;
}
}
- b.push(bean);
+ b.push(t);
}
Seam.isBeanRegistered = function(name) {
@@ -106,15 +133,6 @@
}
}
-Seam.createNamespace = function(namespace) {
- var p = namespace.split(".");
- var b = Seam.type;
- for(var i=0; i<p.length; i++) {
- if (typeof b[p[i]] == "undefined") b[p[i]] = new Object();
- b = b[p[i]];
- }
-}
-
Seam.Context = function() {
this.conversationId = null;
Seam.Context.prototype.setConversationId = function(conversationId) {