Seam SVN: r11810 - in branches/community/Seam_2_2/examples/restbay/src/org/jboss/seam/example/restbay: resteasy/subresource and 1 other directories.
by seam-commits@lists.jboss.org
Author: jharting
Date: 2009-12-11 08:18:27 -0500 (Fri, 11 Dec 2009)
New Revision: 11810
Added:
branches/community/Seam_2_2/examples/restbay/src/org/jboss/seam/example/restbay/resteasy/subresource/
branches/community/Seam_2_2/examples/restbay/src/org/jboss/seam/example/restbay/resteasy/subresource/Garage.java
branches/community/Seam_2_2/examples/restbay/src/org/jboss/seam/example/restbay/resteasy/subresource/Vehicle.java
branches/community/Seam_2_2/examples/restbay/src/org/jboss/seam/example/restbay/test/SubresourceTest.java
Modified:
branches/community/Seam_2_2/examples/restbay/src/org/jboss/seam/example/restbay/test/testng.xml
Log:
Testcase for JBSEAM-4039
Added: branches/community/Seam_2_2/examples/restbay/src/org/jboss/seam/example/restbay/resteasy/subresource/Garage.java
===================================================================
--- branches/community/Seam_2_2/examples/restbay/src/org/jboss/seam/example/restbay/resteasy/subresource/Garage.java (rev 0)
+++ branches/community/Seam_2_2/examples/restbay/src/org/jboss/seam/example/restbay/resteasy/subresource/Garage.java 2009-12-11 13:18:27 UTC (rev 11810)
@@ -0,0 +1,24 @@
+package org.jboss.seam.example.restbay.resteasy.subresource;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+
+import org.jboss.seam.Component;
+import org.jboss.seam.annotations.Name;
+
+@Path("/garage")
+@Produces("text/plain")
+@Name("garage")
+public class Garage
+{
+ @GET
+ public String getInfo() {
+ return "garage";
+ }
+
+ @Path("/1")
+ public Vehicle getVehicle() {
+ return (Vehicle) Component.getInstance(Vehicle.class);
+ }
+}
Added: branches/community/Seam_2_2/examples/restbay/src/org/jboss/seam/example/restbay/resteasy/subresource/Vehicle.java
===================================================================
--- branches/community/Seam_2_2/examples/restbay/src/org/jboss/seam/example/restbay/resteasy/subresource/Vehicle.java (rev 0)
+++ branches/community/Seam_2_2/examples/restbay/src/org/jboss/seam/example/restbay/resteasy/subresource/Vehicle.java 2009-12-11 13:18:27 UTC (rev 11810)
@@ -0,0 +1,16 @@
+package org.jboss.seam.example.restbay.resteasy.subresource;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Produces;
+
+import org.jboss.seam.annotations.Name;
+
+@Name("vehicle")
+@Produces("text/plain")
+public class Vehicle
+{
+ @GET
+ public String getInfo() {
+ return "Honda";
+ }
+}
Added: branches/community/Seam_2_2/examples/restbay/src/org/jboss/seam/example/restbay/test/SubresourceTest.java
===================================================================
--- branches/community/Seam_2_2/examples/restbay/src/org/jboss/seam/example/restbay/test/SubresourceTest.java (rev 0)
+++ branches/community/Seam_2_2/examples/restbay/src/org/jboss/seam/example/restbay/test/SubresourceTest.java 2009-12-11 13:18:27 UTC (rev 11810)
@@ -0,0 +1,39 @@
+package org.jboss.seam.example.restbay.test;
+
+import static org.testng.Assert.assertEquals;
+
+import org.jboss.seam.mock.EnhancedMockHttpServletRequest;
+import org.jboss.seam.mock.EnhancedMockHttpServletResponse;
+import org.jboss.seam.mock.ResourceRequestEnvironment;
+import org.jboss.seam.mock.SeamTest;
+import org.jboss.seam.mock.ResourceRequestEnvironment.Method;
+import org.jboss.seam.mock.ResourceRequestEnvironment.ResourceRequest;
+import org.testng.annotations.Test;
+
+public class SubresourceTest extends SeamTest
+{
+ @Test
+ public void testResourceHomeRead() throws Exception
+ {
+ final String path = "/restv1/garage/1";
+
+ new ResourceRequest(new ResourceRequestEnvironment(this), Method.GET, path)
+ {
+
+ @Override
+ protected void prepareRequest(EnhancedMockHttpServletRequest request)
+ {
+ super.prepareRequest(request);
+ request.addHeader("Accept", "text/plain");
+ }
+
+ @Override
+ protected void onResponse(EnhancedMockHttpServletResponse response)
+ {
+ assertEquals(response.getStatus(), 200, "Unexpected response code.");
+ assertEquals(response.getContentAsString(), "Honda", "Unexpected response.");
+ }
+
+ }.run();
+ }
+}
Modified: branches/community/Seam_2_2/examples/restbay/src/org/jboss/seam/example/restbay/test/testng.xml
===================================================================
--- branches/community/Seam_2_2/examples/restbay/src/org/jboss/seam/example/restbay/test/testng.xml 2009-12-11 11:25:57 UTC (rev 11809)
+++ branches/community/Seam_2_2/examples/restbay/src/org/jboss/seam/example/restbay/test/testng.xml 2009-12-11 13:18:27 UTC (rev 11810)
@@ -31,6 +31,14 @@
<class name="org.jboss.seam.example.restbay.test.SecurityTest"/>
</classes>
</test>
+
+ <!-- JBSEAM-4039
+ <test name="RestBay Subresources">
+ <classes>
+ <class name="org.jboss.seam.example.restbay.test.SubresourceTest"/>
+ </classes>
+ </test>
+ -->
<test name="RestBay DBUnit Integration">
15 years
Seam SVN: r11809 - in modules/remoting/trunk: src/main/java/org/jboss/seam/remoting and 2 other directories.
by seam-commits@lists.jboss.org
Author: shane.bryzak(a)jboss.com
Date: 2009-12-11 06:25:57 -0500 (Fri, 11 Dec 2009)
New Revision: 11809
Modified:
modules/remoting/trunk/examples/model/src/main/webapp/model.html
modules/remoting/trunk/src/main/java/org/jboss/seam/remoting/MarshalUtils.java
modules/remoting/trunk/src/main/java/org/jboss/seam/remoting/model/Model.java
modules/remoting/trunk/src/main/java/org/jboss/seam/remoting/model/ModelHandler.java
modules/remoting/trunk/src/main/resources/org/jboss/seam/remoting/remote.js
Log:
got end to end model fetch request working... yay!
Modified: modules/remoting/trunk/examples/model/src/main/webapp/model.html
===================================================================
--- modules/remoting/trunk/examples/model/src/main/webapp/model.html 2009-12-11 04:03:15 UTC (rev 11808)
+++ modules/remoting/trunk/examples/model/src/main/webapp/model.html 2009-12-11 11:25:57 UTC (rev 11809)
@@ -21,12 +21,12 @@
function loadCustomer() {
var customerId = document.getElementById("customerId").value;
- var model = new Seam.Remoting.Model();
+ var model = new Seam.Model();
var callback = function(model) { alert(model.getValue("customer").getFirstName()); };
model.addBean("customer", "org.jboss.seam.remoting.examples.model.CustomerAction", "customer");
- model.fetch(new Seam.Remoting.Action()
+ model.fetch(new Seam.Action()
.setBeanType("org.jboss.seam.remoting.examples.model.CustomerAction")
.setMethod("editCustomer")
.addParam(customerId), callback);
Modified: modules/remoting/trunk/src/main/java/org/jboss/seam/remoting/MarshalUtils.java
===================================================================
--- modules/remoting/trunk/src/main/java/org/jboss/seam/remoting/MarshalUtils.java 2009-12-11 04:03:15 UTC (rev 11808)
+++ modules/remoting/trunk/src/main/java/org/jboss/seam/remoting/MarshalUtils.java 2009-12-11 11:25:57 UTC (rev 11809)
@@ -85,6 +85,13 @@
{
out.write(MODEL_TAG_OPEN_START);
out.write(model.getId().getBytes());
+
+ if (model.getCallId() != null)
+ {
+ out.write("\" callId=\"".getBytes());
+ out.write(model.getCallId().getBytes());
+ }
+
out.write(MODEL_TAG_OPEN_END);
for (String alias : model.getBeanProperties().keySet())
Modified: modules/remoting/trunk/src/main/java/org/jboss/seam/remoting/model/Model.java
===================================================================
--- modules/remoting/trunk/src/main/java/org/jboss/seam/remoting/model/Model.java 2009-12-11 04:03:15 UTC (rev 11808)
+++ modules/remoting/trunk/src/main/java/org/jboss/seam/remoting/model/Model.java 2009-12-11 11:25:57 UTC (rev 11809)
@@ -28,10 +28,13 @@
private BeanManager beanManager;
private String id;
+ private String callId;
private CallContext callContext;
- public class BeanProperty
+ public class BeanProperty implements Serializable
{
+ private static final long serialVersionUID = 540993772239615536L;
+
private Bean<?> bean;
private String propertyName;
private Object value;
@@ -115,6 +118,16 @@
beanProperties = new HashMap<String, BeanProperty>();
}
+ public void setCallId(String callId)
+ {
+ this.callId = callId;
+ }
+
+ public String getCallId()
+ {
+ return callId;
+ }
+
/**
* Evaluate each of the model's bean properties, expressions, etc and
* store the values in the BeanProperty map.
Modified: modules/remoting/trunk/src/main/java/org/jboss/seam/remoting/model/ModelHandler.java
===================================================================
--- modules/remoting/trunk/src/main/java/org/jboss/seam/remoting/model/ModelHandler.java 2009-12-11 04:03:15 UTC (rev 11808)
+++ modules/remoting/trunk/src/main/java/org/jboss/seam/remoting/model/ModelHandler.java 2009-12-11 11:25:57 UTC (rev 11809)
@@ -4,8 +4,10 @@
import java.io.IOException;
import java.io.OutputStream;
import java.io.StringReader;
+import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
+import java.util.Map;
import java.util.Set;
import javax.enterprise.context.Conversation;
@@ -94,6 +96,7 @@
{
Model model = registry.createModel();
models.add(model);
+ model.setCallId(callId);
if (modelElement.elements("action").size() > 0)
{
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-11 04:03:15 UTC (rev 11808)
+++ modules/remoting/trunk/src/main/resources/org/jboss/seam/remoting/remote.js 2009-12-11 11:25:57 UTC (rev 11809)
@@ -1,5 +1,5 @@
var Seam = {
- type: new Object(),
+ type: {},
beans: new Array(),
debug: false,
debugWindow: null,
@@ -415,6 +415,7 @@
}
catch (ex) {
try {
+ Seam.log(ex.message + " : " + ex.stack);
// Try it the IE way first...
var doc = new ActiveXObject("Microsoft.XMLDOM");
doc.async = "false";
@@ -463,9 +464,16 @@
Seam.context.setConversationId(context.getConversationId());
}
}
- if (bodyNode) {
+ if (bodyNode) {
var n = Seam.Xml.childNode(bodyNode, "result");
if (n) Seam.processResult(n, context);
+ var cn = Seam.Xml.childNodes(bodyNode, "model");
+ for (var i=0; i<cn.length; i++) {
+ var callId = cn[i].getAttribute("callId");
+ var call = Seam.pendingCalls.get(callId);
+ Seam.pendingCalls.remove(callId);
+ if (call.model) call.model.processFetchResponse(cn[i]);
+ }
}
}
@@ -501,7 +509,7 @@
var cn = Seam.Xml.childNodes(refsNode, "ref");
for (var i=0; i<cn.length; i++) {
var refId = parseInt(cn[i].getAttribute("id"));
- var valueNode = refNode.firstChild;
+ var valueNode = cn[i].firstChild;
if (valueNode.tagName == "bean") {
var name = valueNode.getAttribute("type");
var obj = Seam.isBeanRegistered(name) ? Seam.createBean(name) : null;
@@ -673,7 +681,7 @@
var r = this.createFetchRequest(action);
var env = Seam.createEnvelope(Seam.createHeader(), r.data);
Seam.pendingCalls.put(r.id, r);
- Seam.sendAjaxRequest(env, Seam.PATH_MODEL, this.processFetchResponse, false);
+ Seam.sendAjaxRequest(env, Seam.PATH_MODEL, Seam.processResponse, false);
}
Seam.Model.prototype.createFetchRequest = function(a) { // a = action
@@ -727,62 +735,19 @@
}
}
d += "</model>";
- return {data: d, id: callId};
+ return {data:d, id:callId, model:this};
}
- Seam.Model.prototype.processFetchResponse = function(doc) {
- var headerNode;
- var bodyNode;
- var inScope = typeof(Seam) == "undefined" ? false : true;
- if (!inScope) return;
- var context = new Seam.Context;
- if (doc.documentElement) {
- for (var i=0; i<doc.documentElement.childNodes.length; i++) {
- var node = doc.documentElement.childNodes.item(i);
- if (node.tagName == "header")
- headerNode = node;
- else if (node.tagName == "body")
- bodyNode = node;
- }
- }
- if (headerNode) {
- var contextNode;
- for (var i=0; i<headerNode.childNodes.length; i++) {
- var node = headerNode.childNodes.item(i);
- if (node.tagName == "context") {
- contextNode = node;
- break;
- }
- }
- if (contextNode && context) {
- Seam.unmarshalContext(contextNode, context);
- if (context.getConversationId() && Seam.context.getConversationId() == null)
- Seam.context.setConversationId(context.getConversationId());
- }
- }
- if (bodyNode) {
- for (var i=0; i<bodyNode.childNodes.length; i++) {
- var n = bodyNode.childNodes.item(i);
- if (n.tagName == "model") {
- var valueNodes = new Array();
- var refsNode = null;
- for (var j=0; j<n.childNodes.length; j++) {
- var cn = n.childNodes.item(j);
- if (cn.tagName == "value")
- valueNodes.push({node:cn.firstChild,alias:cn.getAttribute("alias")});
- else if (cn.tagName == "refs")
- refsNode = n.childNodes.item(j);
- }
- var refs = new Array();
- if (refsNode) Seam.unmarshalRefs(refsNode, refs);
- for (var j=0; j<valueNodes.length; j++) {
- var value = Seam.unmarshalValue(valueNodes[j].node, refs);
- this.values.push({alias:valueNodes[j].alias, value:value});
- }
- }
- }
- }
- if (this.callback) callback(this);
+ Seam.Model.prototype.processFetchResponse = function(modelNode) {
+ var valueNodes = Seam.Xml.childNodes(modelNode, "value");
+ var refsNode = Seam.Xml.childNode(modelNode, "refs");
+ var refs = new Array();
+ if (refsNode) Seam.unmarshalRefs(refsNode, refs);
+ for (var i=0; i<valueNodes.length; i++) {
+ var value = Seam.unmarshalValue(valueNodes[i].firstChild,refs);
+ this.values.push({alias:valueNodes[i].getAttribute("alias"),value:value});
+ }
+ if (this.callback) this.callback(this);
}
Seam.Model.prototype.applyUpdates = function(action) {
15 years
Seam SVN: r11808 - modules/remoting/trunk/src/main/resources/org/jboss/seam/remoting.
by seam-commits@lists.jboss.org
Author: shane.bryzak(a)jboss.com
Date: 2009-12-10 23:03:15 -0500 (Thu, 10 Dec 2009)
New Revision: 11808
Modified:
modules/remoting/trunk/src/main/resources/org/jboss/seam/remoting/remote.js
Log:
optimized and compacted code
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-11 00:27:46 UTC (rev 11807)
+++ modules/remoting/trunk/src/main/resources/org/jboss/seam/remoting/remote.js 2009-12-11 04:03:15 UTC (rev 11808)
@@ -1,8 +1,13 @@
-var Seam = new Object();
-Seam.type = new Object();
-Seam.beans = new Array();
-Seam.debug = false;
-Seam.debugWindow = null;
+var Seam = {
+ type: new Object(),
+ beans: new Array(),
+ debug: false,
+ debugWindow: null,
+ PATH_EXECUTE: "/execute",
+ PATH_SUBSCRIPTION: "/subscription",
+ PATH_MODEL: "/model",
+ PATH_POLL: "/poll",
+}
Seam.createBean = function(name) {
var b = Seam.beans;
@@ -59,6 +64,21 @@
return b ? b.__metadata : undefined;
}
+Seam.Xml = {
+ childNode: function(e, tag) {
+ for (var i=0; i<e.childNodes.length; i++) {
+ if (e.childNodes.item(i).tagName == tag) return e.childNodes.item(i);
+ }
+ },
+ childNodes: function(e, tag) {
+ var n = new Array();
+ for (var i=0; i<e.childNodes.length;i++) {
+ if (e.childNodes.item(i).tagName == tag) n.push(e.childNodes.item(i));
+ }
+ return n;
+ }
+}
+
Seam.extractEncodedSessionId = function(url) {
if (url.indexOf(';jsessionid=') >= 0) {
var qpos = url.indexOf('?');
@@ -67,11 +87,6 @@
return null;
}
-Seam.PATH_EXECUTE = "/execute";
-Seam.PATH_SUBSCRIPTION = "/subscription";
-Seam.PATH_MODEL = "/model";
-Seam.PATH_POLL = "/poll";
-
Seam.encodedSessionId = Seam.extractEncodedSessionId(window.location.href);
Seam.log = function(msg) {
@@ -434,43 +449,23 @@
component.__callback[methodName] = callback;
}
-Seam.processResponse = function(doc) {
- var headerNode;
- var bodyNode;
- var inScope = typeof(Seam) == "undefined" ? false : true;
- if (!inScope) return;
+Seam.processResponse = function(doc) {
+ if (typeof(Seam) == "undefined") return;
+ if (!doc.documentElement) return;
var context = new Seam.Context;
- if (doc.documentElement) {
- for (var i=0; i<doc.documentElement.childNodes.length; i++) {
- var node = doc.documentElement.childNodes.item(i);
- if (node.tagName == "header")
- headerNode = node;
- else if (node.tagName == "body")
- bodyNode = node;
- }
- }
-
+ var headerNode = Seam.Xml.childNode(doc.documentElement, "header");
+ var bodyNode = Seam.Xml.childNode(doc.documentElement, "body");
if (headerNode) {
- var contextNode;
- for (var i=0; i<headerNode.childNodes.length; i++) {
- var node = headerNode.childNodes.item(i);
- if (node.tagName == "context") {
- contextNode = node;
- break;
- }
- }
+ var contextNode = Seam.Xml.childNode(headerNode, "context");
if (contextNode && context) {
Seam.unmarshalContext(contextNode, context);
if (context.getConversationId() && Seam.context.getConversationId() == null)
Seam.context.setConversationId(context.getConversationId());
}
}
-
if (bodyNode) {
- for (var i=0; i<bodyNode.childNodes.length; i++) {
- var n = bodyNode.childNodes.item(i);
- if (n.tagName == "result") Seam.processResult(n, context);
- }
+ var n = Seam.Xml.childNode(bodyNode, "result");
+ if (n) Seam.processResult(n, context);
}
}
@@ -479,30 +474,13 @@
var call = Seam.pendingCalls.get(callId);
Seam.pendingCalls.remove(callId);
if (call && (call.callback || call.exceptionHandler)) {
- var valueNode = null;
- var refsNode = null;
- var exceptionNode = null;
- var c = result.childNodes;
- for (var i=0; i<c.length; i++) {
- var tag = c.item(i).tagName;
- if (tag == "value")
- valueNode = c.item(i);
- else if (tag == "refs")
- refsNode = c.item(i);
- else if (tag == "exception")
- exceptionNode = c.item(i);
- }
+ var valueNode = Seam.Xml.childNode(result, "value");
+ var refsNode = Seam.Xml.childNode(result, "refs");
+ var exceptionNode = Seam.Xml.childNode(result, "exception");
if (exceptionNode != null) {
- var msgNode = null;
- var c = exceptionNode.childNodes;
- for (var i=0; i<c.length; i++) {
- var tag = c.item(i).tagName;
- if (tag == "message")
- msgNode = c.item(i);
- }
+ var msgNode = Seam.Xml.childNode(exceptionNode, "message");
var msg = Seam.unmarshalValue(msgNode.firstChild);
- var ex = new Seam.Exception(msg);
- call.exceptionHandler(ex);
+ call.exceptionHandler(new Seam.Exception(msg));
}
else {
var refs = new Array();
@@ -514,35 +492,31 @@
}
Seam.unmarshalContext = function(ctxNode, context) {
- for (var i=0; i<ctxNode.childNodes.length; i++) {
- var tag = ctxNode.childNodes.item(i).tagName;
- if (tag == "conversationId") context.setConversationId(ctxNode.childNodes.item(i).firstChild.nodeValue);
- }
+ var c = Seam.Xml.childNode(ctxNode, "conversationId");
+ if (c) context.setConversationId(c.firstChild.nodeValue);
}
Seam.unmarshalRefs = function(refsNode, refs) {
var objs = new Array();
- for (var i = 0; i < refsNode.childNodes.length; i++) {
- if (refsNode.childNodes.item(i).tagName == "ref") {
- var refNode = refsNode.childNodes.item(i);
- var refId = parseInt(refNode.getAttribute("id"));
- var valueNode = refNode.firstChild;
- if (valueNode.tagName == "bean") {
- var typeName = valueNode.getAttribute("type");
- var obj = Seam.isBeanRegistered(typeName) ? Seam.createBean(typeName) : null;
- if (obj) {
- refs[refId] = obj;
- objs[objs.length] = {obj: obj, node: valueNode};
- }
+ var cn = Seam.Xml.childNodes(refsNode, "ref");
+ for (var i=0; i<cn.length; i++) {
+ var refId = parseInt(cn[i].getAttribute("id"));
+ var valueNode = refNode.firstChild;
+ if (valueNode.tagName == "bean") {
+ var name = valueNode.getAttribute("type");
+ var obj = Seam.isBeanRegistered(name) ? Seam.createBean(name) : null;
+ if (obj) {
+ refs[refId] = obj;
+ objs.push({obj: obj, node: valueNode});
}
- }
- }
+ }
+ }
for (var i=0; i<objs.length; i++) {
- for (var j=0; j<objs[i].node.childNodes.length; j++) {
- var child = objs[i].node.childNodes.item(j);
- if (child.tagName == "member") {
- var name = child.getAttribute("name");
- objs[i].obj[name] = Seam.unmarshalValue(child.firstChild, refs);
+ var cn = Seam.Xml.childNodes(objs[i].node, "member");
+ for (var j=0; j<cn.length; j++) {
+ if (cn[j].tagName == "member") {
+ var name = cn[j].getAttribute("name");
+ objs[i].obj[name] = Seam.unmarshalValue(cn[j].firstChild, refs);
}
}
}
@@ -566,26 +540,18 @@
case "ref": return refs[parseInt(element.getAttribute("id"))];
case "bag":
var value = new Array();
- for (var i=0; i<element.childNodes.length; i++) {
- if (element.childNodes.item(i).tagName == "element")
- value[value.length] = Seam.unmarshalValue(element.childNodes.item(i).firstChild, refs);
+ var cn = Seam.Xml.childNodes(element, "element");
+ for (var i=0; i<cn.length; i++) {
+ value.push(Seam.unmarshalValue(cn[i].firstChild, refs));
}
return value;
case "map":
var m = new Seam.Map();
- for (var i = 0; i < element.childNodes.length; i++) {
- var childNode = element.childNodes.item(i);
- if (childNode.tagName == "element") {
- var key = null
- var value = null;
- for (var j = 0; j < childNode.childNodes.length; j++) {
- if (key == null && childNode.childNodes.item(j).tagName == "k")
- key = Seam.unmarshalValue(childNode.childNodes.item(j).firstChild, refs);
- else if (value == null && childNode.childNodes.item(j).tagName == "v")
- value = Seam.unmarshalValue(childNode.childNodes.item(j).firstChild, refs);
- }
- if (key != null) m.put(key, value);
- }
+ var cn = Seam.Xml.childNodes(element, "element");
+ for (var i=0; i<cn.length; i++) {
+ var k = Seam.unmarshalValue(Seam.Xml.childNode(cn[i], "k").firstChild, refs);
+ var v = Seam.unmarshalValue(Seam.Xml.childNode(cn[i], "v").firstChild, refs);
+ if (k != null) m.put(k, v);
}
return m;
case "date": return Seam.deserializeDate(element.firstChild.nodeValue);
15 years
Seam SVN: r11807 - in modules/remoting/trunk: examples/helloworld/src/main/webapp and 6 other directories.
by seam-commits@lists.jboss.org
Author: shane.bryzak(a)jboss.com
Date: 2009-12-10 19:27:46 -0500 (Thu, 10 Dec 2009)
New Revision: 11807
Modified:
modules/remoting/trunk/examples/helloworld/pom.xml
modules/remoting/trunk/examples/helloworld/src/main/webapp/helloworld.xhtml
modules/remoting/trunk/examples/model/pom.xml
modules/remoting/trunk/examples/model/src/main/resources/META-INF/persistence.xml
modules/remoting/trunk/examples/model/src/main/webapp/model.html
modules/remoting/trunk/src/main/java/org/jboss/seam/remoting/InterfaceGenerator.java
modules/remoting/trunk/src/main/java/org/jboss/seam/remoting/Remoting.java
modules/remoting/trunk/src/main/java/org/jboss/seam/remoting/model/ModelHandler.java
modules/remoting/trunk/src/main/resources/org/jboss/seam/remoting/remote.js
Log:
start JS API refactoring, condensed code, general cleanup
Modified: modules/remoting/trunk/examples/helloworld/pom.xml
===================================================================
--- modules/remoting/trunk/examples/helloworld/pom.xml 2009-12-10 13:38:14 UTC (rev 11806)
+++ modules/remoting/trunk/examples/helloworld/pom.xml 2009-12-11 00:27:46 UTC (rev 11807)
@@ -13,17 +13,7 @@
<packaging>war</packaging>
<version>1.0.0-SNAPSHOT</version>
<name>Seam Remoting Examples: Helloworld</name>
-
- <pluginRepositories>
- <pluginRepository>
- <id>codehaus snapshot repository</id>
- <url>http://snapshots.repository.codehaus.org/</url>
- <releases>
- <enabled>true</enabled>
- </releases>
- </pluginRepository>
- </pluginRepositories>
-
+
<dependencies>
<!--dependency>
<groupId>org.testng</groupId>
@@ -45,14 +35,33 @@
<scope>provided</scope>
<version>2.0.1-FCS</version>
</dependency>
-
+
<dependency>
<groupId>org.jboss.seam</groupId>
<artifactId>seam-remoting</artifactId>
<version>3.0.0-SNAPSHOT</version>
- </dependency>
-
+ </dependency>
</dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <source>1.5</source>
+ <target>1.5</target>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-war-plugin</artifactId>
+ <version>2.0</version>
+ <configuration>
+ <warName>${pom.artifactId}</warName>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
</project>
Modified: modules/remoting/trunk/examples/helloworld/src/main/webapp/helloworld.xhtml
===================================================================
--- modules/remoting/trunk/examples/helloworld/src/main/webapp/helloworld.xhtml 2009-12-10 13:38:14 UTC (rev 11806)
+++ modules/remoting/trunk/examples/helloworld/src/main/webapp/helloworld.xhtml 2009-12-11 00:27:46 UTC (rev 11807)
@@ -68,7 +68,7 @@
var callback = function(result) { alert(result); };
// Get a reference to the HelloAction bean and invoke the sayHello() method
- Seam.Remoting.instance("org.jboss.seam.remoting.examples.helloworld.HelloAction", qualifiers).sayHello(name, callback);
+ Seam.createBean("org.jboss.seam.remoting.examples.helloworld.HelloAction", qualifiers).sayHello(name, callback);
// ]]>
}
Modified: modules/remoting/trunk/examples/model/pom.xml
===================================================================
--- modules/remoting/trunk/examples/model/pom.xml 2009-12-10 13:38:14 UTC (rev 11806)
+++ modules/remoting/trunk/examples/model/pom.xml 2009-12-11 00:27:46 UTC (rev 11807)
@@ -35,7 +35,6 @@
<version>1.0</version>
<scope>provided</scope>
</dependency>
-
</dependencies>
<build>
Modified: modules/remoting/trunk/examples/model/src/main/resources/META-INF/persistence.xml
===================================================================
--- modules/remoting/trunk/examples/model/src/main/resources/META-INF/persistence.xml 2009-12-10 13:38:14 UTC (rev 11806)
+++ modules/remoting/trunk/examples/model/src/main/resources/META-INF/persistence.xml 2009-12-11 00:27:46 UTC (rev 11807)
@@ -4,14 +4,11 @@
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
version="1.0">
<persistence-unit name="model">
- <provider>org.hibernate.ejb.HibernatePersistence</provider>
- <class>org.jboss.seam.remoting.examples.model.Customer</class>
<jta-data-source>modelDatasource</jta-data-source>
+ <class>org.jboss.seam.remoting.examples.model.Customer</class>
<properties>
<property name="hibernate.hbm2ddl.auto" value="create-drop"/>
<property name="hibernate.show_sql" value="true"/>
- <!-- These are the default for JBoss EJB 3, but not for Hibernate EntityManager -->
- <property name="hibernate.cache.provider_class" value="org.hibernate.cache.HashtableCacheProvider"/>
<property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.JBossTransactionManagerLookup"/>
</properties>
</persistence-unit>
Modified: modules/remoting/trunk/examples/model/src/main/webapp/model.html
===================================================================
--- modules/remoting/trunk/examples/model/src/main/webapp/model.html 2009-12-10 13:38:14 UTC (rev 11806)
+++ modules/remoting/trunk/examples/model/src/main/webapp/model.html 2009-12-11 00:27:46 UTC (rev 11807)
@@ -1,8 +1,5 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml"
- xmlns:ui="http://java.sun.com/jsf/facelets"
- xmlns:h="http://java.sun.com/jsf/html"
- xmlns:s="http://jboss.com/products/seam/taglib">
+<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
@@ -14,26 +11,28 @@
<h1>Seam Remoting - Model Example</h1>
<script type="text/javascript" src="seam/resource/remoting/resource/remote.js"></script>
+ <script type="text/javascript" src="seam/resource/remoting/interface.js?org.jboss.seam.remoting.examples.model.Customer"></script>
<script type="text/javascript">
//<![CDATA[
- Seam.Remoting.setDebug(true);
-
- function loadCustomer() {
- var customerId = document.getElementById("customerId").value;
-
- var callback = function(result) { alert("got result: " + result); };
- var model = new Seam.Remoting.Model();
-
- model.addBean("customer", "org.jboss.seam.remoting.examples.model.CustomerAction", "customer");
- model.fetch(new Seam.Remoting.Action()
- .setBeanType("org.jboss.seam.remoting.examples.model.CustomerAction")
- .setMethod("editCustomer")
- .addParam(customerId));
- }
+ Seam.debug = true;
+
+ function loadCustomer() {
+ var customerId = document.getElementById("customerId").value;
+
+ var model = new Seam.Remoting.Model();
- // ]]>
+ var callback = function(model) { alert(model.getValue("customer").getFirstName()); };
+
+ model.addBean("customer", "org.jboss.seam.remoting.examples.model.CustomerAction", "customer");
+ model.fetch(new Seam.Remoting.Action()
+ .setBeanType("org.jboss.seam.remoting.examples.model.CustomerAction")
+ .setMethod("editCustomer")
+ .addParam(customerId), callback);
+ }
+
+ // ]]>
</script>
<label for="customerId">Customer ID</label><input type="text" id="customerId" value="1"/>
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-10 13:38:14 UTC (rev 11806)
+++ modules/remoting/trunk/src/main/java/org/jboss/seam/remoting/InterfaceGenerator.java 2009-12-11 00:27:46 UTC (rev 11807)
@@ -327,13 +327,13 @@
String beanName = name != null ? name : beanClass.getName();
if (beanName.contains("."))
{
- componentSrc.append("Seam.Remoting.createNamespace('");
+ componentSrc.append("Seam.createNamespace('");
componentSrc.append(beanName.substring(0, beanName.lastIndexOf('.')));
componentSrc.append("');\n");
}
- componentSrc.append("Seam.Remoting.type.");
+ componentSrc.append("Seam.type.");
componentSrc.append(beanName);
componentSrc.append(" = function() {\n");
componentSrc.append(" this.__callback = new Object();\n");
@@ -356,7 +356,7 @@
// Append the return type to the source block
appendTypeSource(out, m.getGenericReturnType(), types);
- componentSrc.append(" Seam.Remoting.type.");
+ componentSrc.append(" Seam.type.");
componentSrc.append(beanName);
componentSrc.append(".prototype.");
componentSrc.append(m.getName());
@@ -379,7 +379,7 @@
componentSrc.append(", ");
componentSrc.append("callback, exceptionHandler) {\n");
- componentSrc.append(" return Seam.Remoting.execute(this, \"");
+ componentSrc.append(" return Seam.execute(this, \"");
componentSrc.append(m.getName());
componentSrc.append("\", [");
@@ -398,14 +398,14 @@
componentSrc.append("}\n");
// Set the component name
- componentSrc.append("Seam.Remoting.type.");
+ componentSrc.append("Seam.type.");
componentSrc.append(beanName);
componentSrc.append(".__name = \"");
componentSrc.append(beanName);
componentSrc.append("\";\n\n");
// Register the component
- componentSrc.append("Seam.Remoting.registerBean(Seam.Remoting.type.");
+ componentSrc.append("Seam.registerBean(Seam.type.");
componentSrc.append(beanName);
componentSrc.append(");\n\n");
@@ -489,7 +489,7 @@
String typeName = componentName.replace('.', '$');
- typeSource.append("Seam.Remoting.type.");
+ typeSource.append("Seam.type.");
typeSource.append(typeName);
typeSource.append(" = function() {\n");
@@ -613,7 +613,7 @@
if (getMethodName != null)
{
- accessors.append(" Seam.Remoting.type.");
+ accessors.append(" Seam.type.");
accessors.append(typeName);
accessors.append(".prototype.");
accessors.append(getMethodName);
@@ -624,7 +624,7 @@
if (setMethodName != null)
{
- mutators.append(" Seam.Remoting.type.");
+ mutators.append(" Seam.type.");
mutators.append(typeName);
mutators.append(".prototype.");
mutators.append(setMethodName);
@@ -646,14 +646,14 @@
typeSource.append("}\n\n");
// Append the type name
- typeSource.append("Seam.Remoting.type.");
+ typeSource.append("Seam.type.");
typeSource.append(typeName);
typeSource.append(".__name = \"");
typeSource.append(componentName);
typeSource.append("\";\n");
// Append the metadata
- typeSource.append("Seam.Remoting.type.");
+ typeSource.append("Seam.type.");
typeSource.append(typeName);
typeSource.append(".__metadata = [\n");
@@ -674,20 +674,7 @@
}
typeSource.append("];\n\n");
-
- // Register the type under Seam.Component if it is a component, otherwise
- // register it under Seam.Remoting
-
- // TODO fix this - a bean might not be named
- if (classType.isAnnotationPresent(Named.class))
- {
- typeSource.append("Seam.Remoting.registerBean(Seam.Remoting.type.");
- }
- else
- {
- typeSource.append("Seam.Remoting.registerType(Seam.Remoting.type.");
- }
-
+ typeSource.append("Seam.registerBean(Seam.type.");
typeSource.append(typeName);
typeSource.append(");\n\n");
Modified: modules/remoting/trunk/src/main/java/org/jboss/seam/remoting/Remoting.java
===================================================================
--- modules/remoting/trunk/src/main/java/org/jboss/seam/remoting/Remoting.java 2009-12-10 13:38:14 UTC (rev 11806)
+++ modules/remoting/trunk/src/main/java/org/jboss/seam/remoting/Remoting.java 2009-12-11 00:27:46 UTC (rev 11807)
@@ -69,20 +69,20 @@
if (!cachedConfig.containsKey(contextPath))
{
StringBuilder sb = new StringBuilder();
- sb.append("\nSeam.Remoting.resourcePath = \"");
+ sb.append("\nSeam.resourcePath = \"");
sb.append(contextPath);
sb.append(request.getServletPath());
sb.append(servletConfig.getServletContext().getContextPath());
sb.append("\";");
- sb.append("\nSeam.Remoting.debug = ");
+ sb.append("\nSeam.debug = ");
sb.append(getDebug() ? "true" : "false");
sb.append(";");
- sb.append("\nSeam.Remoting.pollInterval = ");
+ /*sb.append("\nSeam.pollInterval = ");
sb.append(getPollInterval());
sb.append(";");
- sb.append("\nSeam.Remoting.pollTimeout = ");
+ sb.append("\nSeam.pollTimeout = ");
sb.append(getPollTimeout());
- sb.append(";");
+ sb.append(";");*/
cachedConfig.put(contextPath, sb.toString().getBytes());
}
Modified: modules/remoting/trunk/src/main/java/org/jboss/seam/remoting/model/ModelHandler.java
===================================================================
--- modules/remoting/trunk/src/main/java/org/jboss/seam/remoting/model/ModelHandler.java 2009-12-10 13:38:14 UTC (rev 11806)
+++ modules/remoting/trunk/src/main/java/org/jboss/seam/remoting/model/ModelHandler.java 2009-12-11 00:27:46 UTC (rev 11807)
@@ -1,7 +1,5 @@
package org.jboss.seam.remoting.model;
-import static org.jboss.weld.jsf.JsfHelper.getHttpSession;
-
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
@@ -15,7 +13,6 @@
import javax.inject.Inject;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
-import javax.servlet.http.HttpSession;
import org.dom4j.Document;
import org.dom4j.Element;
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-10 13:38:14 UTC (rev 11806)
+++ modules/remoting/trunk/src/main/resources/org/jboss/seam/remoting/remote.js 2009-12-11 00:27:46 UTC (rev 11807)
@@ -1,15 +1,17 @@
var Seam = new Object();
-Seam.Remoting = new Object();
-Seam.Remoting.beans = new Array();
+Seam.type = new Object();
+Seam.beans = new Array();
+Seam.debug = false;
+Seam.debugWindow = null;
-Seam.Remoting.instance = function(name) {
- var b = Seam.Remoting.beans;
- for (var i = 0; i < b.length; i++) {
+Seam.createBean = function(name) {
+ var b = Seam.beans;
+ for (var i=0; i<b.length; i++) {
if (b[i].__name == name) {
var v = new b[i];
if (arguments.length > 1) {
v.__qualifiers = new Array();
- for (var j = 1; j < arguments.length; j++) {
+ for (var j=1; j<arguments.length; j++) {
v.__qualifiers.push(arguments[j]);
}
}
@@ -19,22 +21,22 @@
return null;
}
-Seam.Remoting.getBeanType = function(obj) {
- var b = Seam.Remoting.beans;
- for (var i = 0; i < b.length; i++) {
+Seam.getBeanType = function(obj) {
+ var b = Seam.beans;
+ for (var i=0; i<b.length; i++) {
if (obj instanceof b[i]) return b[i];
}
- return null;
+ return undefined;
}
-Seam.Remoting.getBeanName = function(obj) {
- var t = Seam.Remoting.getBeanType(obj);
- return t ? t.__name : null;
+Seam.getBeanName = function(obj) {
+ var t = Seam.getBeanType(obj);
+ return t ? t.__name : undefined;
}
-Seam.Remoting.registerBean = function(bean) {
- var b = Seam.Remoting.beans;
- for (var i = 0; i < b.length; i++) {
+Seam.registerBean = function(bean) {
+ var b = Seam.beans;
+ for (var i=0; i<b.length; i++) {
if (b[i].__name == bean.__name) {
b[i] = bean;
return;
@@ -43,138 +45,116 @@
b.push(bean);
}
-Seam.Remoting.isBeanRegistered = function(name) {
- var b = Seam.Remoting.beans;
- for (var i = 0; i < b.length; i++) {
+Seam.isBeanRegistered = function(name) {
+ var b = Seam.beans;
+ for (var i=0; i<b.length; i++) {
if (b[i].__name == name)
return true;
}
return false;
}
-Seam.Remoting.getBeanMetadata = function(obj) {
- var b = Seam.Remoting.beans;
- for (var i = 0; i < b.length; i++) {
- if (obj instanceof b[i]) return b[i].__metadata;
- }
- return null;
+Seam.getBeanMetadata = function(obj) {
+ var b = Seam.getBeanType(obj);
+ return b ? b.__metadata : undefined;
}
-Seam.Remoting.extractEncodedSessionId = function(url) {
- var sid = null;
+Seam.extractEncodedSessionId = function(url) {
if (url.indexOf(';jsessionid=') >= 0) {
var qpos = url.indexOf('?');
- sid = url.substring(url.indexOf(';jsessionid=') + 12, qpos >= 0 ? qpos : url.length);
+ return url.substring(url.indexOf(';jsessionid=') + 12, qpos >= 0 ? qpos : url.length);
}
- return sid;
+ return null;
}
-Seam.Remoting.PATH_EXECUTE = "/execute";
-Seam.Remoting.PATH_SUBSCRIPTION = "/subscription";
-Seam.Remoting.PATH_MODEL = "/model";
-Seam.Remoting.PATH_POLL = "/poll";
+Seam.PATH_EXECUTE = "/execute";
+Seam.PATH_SUBSCRIPTION = "/subscription";
+Seam.PATH_MODEL = "/model";
+Seam.PATH_POLL = "/poll";
-Seam.Remoting.encodedSessionId = Seam.Remoting.extractEncodedSessionId(window.location.href);
+Seam.encodedSessionId = Seam.extractEncodedSessionId(window.location.href);
-Seam.Remoting.type = new Object(); // namespace
-Seam.Remoting.types = new Array();
-
-Seam.Remoting.debug = false;
-Seam.Remoting.debugWindow = null;
-
-Seam.Remoting.setDebug = function(val) {
- Seam.Remoting.debug = val;
-}
-
-Seam.Remoting.log = function(msg) {
- if (!Seam.Remoting.debug) return;
-
- if (!Seam.Remoting.debugWindow || Seam.Remoting.debugWindow.document == null) {
+Seam.log = function(msg) {
+ if (!Seam.debug) return;
+ if (!Seam.debugWindow || Seam.debugWindow.document == null) {
var attr = "left=400,top=400,resizable=yes,scrollbars=yes,width=400,height=400";
- Seam.Remoting.debugWindow = window.open("", "__seamDebugWindow", attr);
- if (Seam.Remoting.debugWindow) {
- Seam.Remoting.debugWindow.document.write("<html><head><title>Seam Debug Window</title></head><body></body></html>");
- var t = Seam.Remoting.debugWindow.document.getElementsByTagName("body").item(0);
+ Seam.debugWindow = window.open("", "__seamDebugWindow", attr);
+ if (Seam.debugWindow) {
+ Seam.debugWindow.document.write("<html><head><title>Seam Debug Window</title></head><body></body></html>");
+ var t = Seam.debugWindow.document.getElementsByTagName("body").item(0);
t.style.fontFamily = "arial";
t.style.fontSize = "8pt";
}
}
-
- if (Seam.Remoting.debugWindow) {
- Seam.Remoting.debugWindow.document.write("<pre>" + (new Date()) + ": " + msg.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">") + "</pre><br/>");
+ if (Seam.debugWindow) {
+ Seam.debugWindow.document.write("<pre>" + (new Date()) + ": " + msg.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">") + "</pre><br/>");
}
}
-Seam.Remoting.createNamespace = function(namespace) {
+Seam.createNamespace = function(namespace) {
var p = namespace.split(".");
- var b = Seam.Remoting.type;
-
- for(var i = 0; i < p.length; i++) {
+ 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.Remoting.__Context = function() {
+Seam.Context = function() {
this.conversationId = null;
- Seam.Remoting.__Context.prototype.setConversationId = function(conversationId) {
+ Seam.Context.prototype.setConversationId = function(conversationId) {
this.conversationId = conversationId;
}
- Seam.Remoting.__Context.prototype.getConversationId = function() {
+ Seam.Context.prototype.getConversationId = function() {
return this.conversationId;
}
}
+Seam.context = new Seam.Context();
-Seam.Remoting.Exception = function(msg) {
+Seam.Exception = function(msg) {
this.message = msg;
- Seam.Remoting.Exception.prototype.getMessage = function() {
+ Seam.Exception.prototype.getMessage = function() {
return this.message;
}
}
-Seam.Remoting.context = new Seam.Remoting.__Context();
-
-Seam.Remoting.getContext = function() {
- return Seam.Remoting.context;
-}
-
-Seam.Remoting.Map = function() {
+Seam.Map = function() {
this.elements = new Array();
- Seam.Remoting.Map.prototype.size = function() {
+ Seam.Map.prototype.size = function() {
return this.elements.length;
}
- Seam.Remoting.Map.prototype.isEmpty = function() {
+ Seam.Map.prototype.isEmpty = function() {
return this.elements.length == 0;
}
- Seam.Remoting.Map.prototype.keySet = function() {
+ Seam.Map.prototype.keySet = function() {
var keySet = new Array();
- for (var i = 0; i < this.elements.length; i++) {
+ for (var i=0; i<this.elements.length; i++) {
keySet[keySet.length] = this.elements[i].key;
}
return keySet;
}
- Seam.Remoting.Map.prototype.values = function() {
- var values = new Array();
- for (var i = 0; i < this.elements.length; i++) {
- values[values.length] = this.elements[i].value;
+ Seam.Map.prototype.values = function() {
+ var vals = new Array();
+ for (var i=0; i<this.elements.length; i++) {
+ vals.push(this.elements[i].value);
}
- return values;
+ return vals;
}
- Seam.Remoting.Map.prototype.get = function(key) {
- for (var i = 0; i < this.elements.length; i++) {
+ Seam.Map.prototype.get = function(key) {
+ for (var i=0; i<this.elements.length; i++) {
if (this.elements[i].key == key) return this.elements[i].value;
}
return null;
}
- Seam.Remoting.Map.prototype.put = function(key, value) {
- for (var i = 0; i < this.elements.length; i++) {
+ Seam.Map.prototype.put = function(key, value) {
+ for (var i=0; i<this.elements.length; i++) {
if (this.elements[i].key == key) {
this.elements[i].value = value;
return;
@@ -183,131 +163,85 @@
this.elements.push({key:key,value:value});
}
- Seam.Remoting.Map.prototype.remove = function(key) {
- for (var i = 0; i < this.elements.length; i++) {
+ Seam.Map.prototype.remove = function(key) {
+ for (var i=0; i<this.elements.length; i++) {
if (this.elements[i].key == key)
this.elements.splice(i, 1);
}
}
- Seam.Remoting.Map.prototype.contains = function(key) {
- for (var i = 0; i < this.elements.length; i++) {
+ Seam.Map.prototype.contains = function(key) {
+ for (var i=0; i<this.elements.length; i++) {
if (this.elements[i].key == key) return true;
}
return false;
}
}
-Seam.Remoting.registerType = function(type) {
- for (var i = 0; i < Seam.Remoting.types.length; i++) {
- if (Seam.Remoting.types[i].__name == type.__name) {
- Seam.Remoting.types[i] = type;
- return;
- }
- }
- Seam.Remoting.types.push(type);
-}
-
-Seam.Remoting.createType = function(name) {
- for (var i = 0; i < Seam.Remoting.types.length; i++) {
- if (Seam.Remoting.types[i].__name == name)
- return new Seam.Remoting.types[i];
- }
-}
-
-Seam.Remoting.getType = function(obj) {
- for (var i = 0; i < Seam.Remoting.types.length; i++) {
- if (obj instanceof Seam.Remoting.types[i]) return Seam.Remoting.types[i];
- }
- return null;
-}
-
-Seam.Remoting.getTypeName = function(obj) {
- var type = Seam.Remoting.getType(obj);
- return type ? type.__name : null;
-}
-
-Seam.Remoting.getMetadata = function(obj) {
- for (var i = 0; i < Seam.Remoting.types.length; i++) {
- if (obj instanceof Seam.Remoting.types[i])
- return Seam.Remoting.types[i].__metadata;
- }
- return null;
-}
-
-Seam.Remoting.serializeValue = function(value, type, refs) {
- if (value == null) {
- return "<null/>";
- }
- else if (type) {
+Seam.serializeValue = function(v, type, refs) {
+ if (v == null) return "<null/>";
+ if (type) {
switch (type) {
- case "bool": return "<bool>" + (value ? "true" : "false") + "</bool>";
- case "number": return "<number>" + value + "</number>";
- case "date": return Seam.Remoting.serializeDate(value);
- case "bean": return Seam.Remoting.getTypeRef(value, refs);
- case "bag": return Seam.Remoting.serializeBag(value, refs);
- case "map": return Seam.Remoting.serializeMap(value, refs);
- default: return "<str>" + encodeURIComponent(value) + "</str>";
+ case "bool": return "<bool>" + (v ? "true" : "false") + "</bool>";
+ case "number": return "<number>" + v + "</number>";
+ case "date": return Seam.serializeDate(v);
+ case "bean": return Seam.getTypeRef(v, refs);
+ case "bag": return Seam.serializeBag(v, refs);
+ case "map": return Seam.serializeMap(v, refs);
+ default: return "<str>" + encodeURIComponent(v) + "</str>";
}
}
else {
- switch (typeof(value)) {
+ switch (typeof(v)) {
case "number":
- return "<number>" + value + "</number>";
+ return "<number>" + v + "</number>";
case "boolean":
- return "<bool>" + (value ? "true" : "false") + "</bool>";
+ return "<bool>" + (v ? "true" : "false") + "</bool>";
case "object":
- if (value instanceof Array)
- return Seam.Remoting.serializeBag(value, refs);
- else if (value instanceof Date)
- return Seam.Remoting.serializeDate(value);
- else if (value instanceof Seam.Remoting.Map)
- return Seam.Remoting.serializeMap(value, refs);
+ if (v instanceof Array)
+ return Seam.serializeBag(v, refs);
+ else if (v instanceof Date)
+ return Seam.serializeDate(v);
+ else if (v instanceof Seam.Map)
+ return Seam.serializeMap(v, refs);
else
- return Seam.Remoting.getTypeRef(value, refs);
+ return Seam.getTypeRef(v, refs);
default:
- return "<str>" + encodeURIComponent(value) + "</str>";
+ return "<str>" + encodeURIComponent(v) + "</str>";
}
}
}
-Seam.Remoting.serializeBag = function(value, refs) {
+Seam.serializeBag = function(v, refs) {
var d = "<bag>";
- for (var i = 0; i < value.length; i++) {
- d += "<element>";
- d += Seam.Remoting.serializeValue(value[i], null, refs);
- d += "</element>";
+ for (var i=0; i<v.length; i++) {
+ d += "<element>" + Seam.serializeValue(v[i], null, refs) + "</element>";
}
d += "</bag>";
return d;
}
-Seam.Remoting.serializeMap = function(value, refs) {
+Seam.serializeMap = function(v, refs) {
var d = "<map>";
- var keyset = value.keySet();
- for (var i = 0; i < keyset.length; i++) {
- d += "<element><k>";
- d += Seam.Remoting.serializeValue(keyset[i], null, refs);
- d += "</k><v>";
- d += Seam.Remoting.serializeValue(value.get(keyset[i]), null, refs);
- d += "</v></element>";
+ var keyset = v.keySet();
+ for (var i=0; i<keyset.length; i++) {
+ d += "<element><k>" + Seam.serializeValue(keyset[i], null, refs) + "</k><v>" +
+ Seam.serializeValue(v.get(keyset[i]), null, refs) + "</v></element>";
}
-
d += "</map>";
return d;
}
-Seam.Remoting.serializeDate = function(value) {
+Seam.serializeDate = function(v) {
var zeroPad = function(val, digits) { while (("" + val).length < digits) val = "0" + val; return val; };
-
- return "<date>" + value.getFullYear() + zeroPad(value.getMonth() + 1, 2) + zeroPad(value.getDate(), 2) +
- zeroPad(value.getHours(), 2) + zeroPad(value.getMinutes(), 2) + zeroPad(value.getSeconds(), 2) +
- zeroPad(value.getMilliseconds(), 3) +"</date>";
+ return "<date>" + v.getFullYear() + zeroPad(v.getMonth() + 1, 2) + zeroPad(v.getDate(), 2) +
+ zeroPad(v.getHours(), 2) + zeroPad(v.getMinutes(), 2) + zeroPad(v.getSeconds(), 2) +
+ zeroPad(v.getMilliseconds(), 3) +"</date>";
}
-Seam.Remoting.getTypeRef = function(obj, refs) {
+Seam.getTypeRef = function(obj, refs) {
var refId = -1;
- for (var i = 0; i < refs.length; i++) {
+ for (var i=0; i<refs.length; i++) {
if (refs[i] == obj) {
refId = i;
break;
@@ -320,87 +254,58 @@
return "<ref id=\"" + refId + "\"/>";
}
-Seam.Remoting.serializeType = function(obj, refs) {
- var d = "<bean type=\"";
- var t = Seam.Remoting.getBeanType(obj);
- var isComponent = t != null;
- if (!isComponent) t = Seam.Remoting.getType(obj);
-
+Seam.serializeType = function(obj, refs) {
+ var t = Seam.getBeanType(obj);
if (!t) {
alert("Unknown Type error.");
return null;
}
-
- d += t.__name;
- d += "\">\n";
-
- var meta = isComponent ? Seam.Remoting.getBeanMetadata(obj) : Seam.Remoting.getMetadata(obj);
- for (var i = 0; i < meta.length; i++) {
- d += "<member name=\"";
- d += meta[i].field;
- d += "\">";
- d += Seam.Remoting.serializeValue(obj[meta[i].field], meta[i].type, refs);
- d += "</member>\n";
+ var d = "<bean type=\"" + t.__name + "\">\n";
+ var meta = Seam.getBeanMetadata(obj);
+ for (var i=0; i<meta.length; i++) {
+ d += "<member name=\"" + meta[i].field + "\">" +
+ Seam.serializeValue(obj[meta[i].field], meta[i].type, refs) + "</member>\n";
}
-
d += "</bean>";
-
return d;
}
-Seam.Remoting.__callId = 0;
-
-Seam.Remoting.createCall = function(component, methodName, params, callback, exceptionHandler) {
- var callId = "" + Seam.Remoting.__callId++;
+Seam.createCall = function(component, methodName, params, callback, exceptionHandler) {
+ var callId = "" + Seam.__callId++;
if (!callback) callback = component.__callback[methodName];
-
- var d = "<call id=\"" + callId + "\">\n";
- d += "<target>" + Seam.Remoting.getBeanType(component).__name + "</target>";
-
+ var d = "<call id=\"" + callId + "\">\n" +
+ "<target>" + Seam.getBeanType(component).__name + "</target>";
if (component.__qualifiers != null) {
d += "<qualifiers>";
- for (var i = 0; i < component.__qualifiers.length; i++) {
+ for (var i=0; i<component.__qualifiers.length; i++) {
d += component.__qualifiers[i];
if (i < component.__qualifiers.length - 1) data += ",";
}
d += "</qualifiers>";
}
-
- d += "<method>" + methodName + "</method>";
- d += "<params>";
-
+ d += "<method>" + methodName + "</method>" + "<params>";
var refs = new Array();
for (var i = 0; i < params.length; i++) {
- d += "<param>";
- d += Seam.Remoting.serializeValue(params[i], null, refs);
- d += "</param>";
+ d += "<param>" + Seam.serializeValue(params[i], null, refs) + "</param>";
}
-
- d += "</params>";
- d += "<refs>";
+ d += "</params><refs>";
for (var i = 0; i < refs.length; i++) {
- d += "<ref id=\"" + i + "\">";
- d += Seam.Remoting.serializeType(refs[i], refs);
- d += "</ref>";
+ d += "<ref id=\"" + i + "\">" + Seam.serializeType(refs[i], refs) + "</ref>";
}
- d += "</refs>";
- d += "</call>";
-
+ d += "</refs></call>";
return {data: d, id: callId, callback: callback, exceptionHandler: exceptionHandler};
}
-Seam.Remoting.createHeader = function() {
+Seam.createHeader = function() {
var h = "<context>";
- if (Seam.Remoting.getContext().getConversationId()) {
- h += "<conversationId>";
- h += Seam.Remoting.getContext().getConversationId();
- h += "</conversationId>";
+ if (Seam.context.getConversationId()) {
+ h += "<conversationId>" + Seam.context.getConversationId() + "</conversationId>";
}
h += "</context>";
return h;
}
-Seam.Remoting.createEnvelope = function(header, body) {
+Seam.createEnvelope = function(header, body) {
var d = "<envelope>";
if (header) d += "<header>" + header + "</header>";
if (body) d += "<body>" + body + "</body>";
@@ -408,42 +313,41 @@
return d;
}
-Seam.Remoting.pendingCalls = new Seam.Remoting.Map();
-Seam.Remoting.inBatch = false;
-Seam.Remoting.batchedCalls = new Array();
+Seam.__callId = 0;
+Seam.pendingCalls = new Seam.Map();
+Seam.inBatch = false;
+Seam.batchedCalls = new Array();
-Seam.Remoting.startBatch = function() {
- Seam.Remoting.inBatch = true;
- Seam.Remoting.batchedCalls.length = 0;
+Seam.startBatch = function() {
+ Seam.inBatch = true;
+ Seam.batchedCalls.length = 0;
}
-Seam.Remoting.executeBatch = function() {
- if (!Seam.Remoting.inBatch) return;
-
+Seam.executeBatch = function() {
+ if (!Seam.inBatch) return;
var d = "";
- for (var i = 0; i < Seam.Remoting.batchedCalls.length; i++) {
- Seam.Remoting.pendingCalls.put(Seam.Remoting.batchedCalls[i].id, Seam.Remoting.batchedCalls[i]);
- d += Seam.Remoting.batchedCalls[i].data;
+ for (var i=0; i<Seam.batchedCalls.length; i++) {
+ Seam.pendingCalls.put(Seam.batchedCalls[i].id, Seam.batchedCalls[i]);
+ d += Seam.batchedCalls[i].data;
}
-
- var envelope = Seam.Remoting.createEnvelope(Seam.Remoting.createHeader(), d);
- Seam.Remoting.batchAsyncReq = Seam.Remoting.sendAjaxRequest(envelope, Seam.Remoting.PATH_EXECUTE,
- Seam.Remoting.processResponse, false);
- Seam.Remoting.inBatch = false;
+ var envelope = Seam.createEnvelope(Seam.createHeader(), d);
+ Seam.batchAsyncReq = Seam.sendAjaxRequest(envelope, Seam.PATH_EXECUTE,
+ Seam.processResponse, false);
+ Seam.inBatch = false;
}
-Seam.Remoting.cancelBatch = function() {
- Seam.Remoting.inBatch = false;
- for (var i = 0; i < Seam.Remoting.batchedCalls.length; i++) {
- Seam.Remoting.pendingCalls.remove(Seam.Remoting.batchedCalls[i].id);
+Seam.cancelBatch = function() {
+ Seam.inBatch = false;
+ for (var i=0; i<Seam.batchedCalls.length; i++) {
+ Seam.pendingCalls.remove(Seam.batchedCalls[i].id);
}
}
-Seam.Remoting.cancelCall = function(callId) {
- var c = Seam.Remoting.pendingCalls.get(callId);
- Seam.Remoting.pendingCalls.remove(callId);
+Seam.cancelCall = function(callId) {
+ var c = Seam.pendingCalls.get(callId);
+ Seam.pendingCalls.remove(callId);
if (c && c.asyncReq) {
- if (Seam.Remoting.pendingCalls.isEmpty()) Seam.Remoting.hideLoadingMessage();
+ if (Seam.pendingCalls.isEmpty()) Seam.hideLoadingMessage();
window.setTimeout(function() {
c.asyncReq.onreadystatechange = function() {};
}, 0);
@@ -451,23 +355,22 @@
}
}
-Seam.Remoting.execute = function(component, methodName, params, callback, exceptionHandler) {
- var c = Seam.Remoting.createCall(component, methodName, params, callback, exceptionHandler);
- if (Seam.Remoting.inBatch) {
- Seam.Remoting.batchedCalls[Seam.Remoting.batchedCalls.length] = c;
+Seam.execute = function(component, methodName, params, callback, exceptionHandler) {
+ var c = Seam.createCall(component, methodName, params, callback, exceptionHandler);
+ if (Seam.inBatch) {
+ Seam.batchedCalls[Seam.batchedCalls.length] = c;
}
else {
- var envelope = Seam.Remoting.createEnvelope(Seam.Remoting.createHeader(), c.data);
- Seam.Remoting.pendingCalls.put(c.id, c);
- Seam.Remoting.sendAjaxRequest(envelope, Seam.Remoting.PATH_EXECUTE, Seam.Remoting.processResponse, false);
+ var envelope = Seam.createEnvelope(Seam.createHeader(), c.data);
+ Seam.pendingCalls.put(c.id, c);
+ Seam.sendAjaxRequest(envelope, Seam.PATH_EXECUTE, Seam.processResponse, false);
}
return c;
}
-Seam.Remoting.sendAjaxRequest = function(envelope, path, callback, silent)
-{
- Seam.Remoting.log("Request packet:\n" + envelope);
- if (!silent) Seam.Remoting.displayLoadingMessage();
+Seam.sendAjaxRequest = function(env, path, callback, silent) {
+ Seam.log("Request packet:\n" + env);
+ if (!silent) Seam.displayLoadingMessage();
var r;
if (window.XMLHttpRequest) {
r = new XMLHttpRequest();
@@ -480,16 +383,14 @@
r.onreadystatechange = function() {
if (r.readyState == 4) {
var inScope = typeof(Seam) == "undefined" ? false : true;
- if (inScope) Seam.Remoting.hideLoadingMessage();
+ if (inScope) Seam.hideLoadingMessage();
if (r.status == 200) {
// We do this to avoid a memory leak
window.setTimeout(function() {
r.onreadystatechange = function() {};
}, 0);
-
- if (inScope) Seam.Remoting.log("Response packet:\n" + r.responseText);
-
+ if (inScope) Seam.log("Response packet:\n" + r.responseText);
if (callback) {
// The following code deals with a Firefox security issue. It reparses the XML
// response if accessing the documentElement throws an exception
@@ -514,37 +415,33 @@
}
}
else {
- Seam.Remoting.displayError(r.status);
+ Seam.displayError(r.status);
}
}
}
-
- if (Seam.Remoting.encodedSessionId) {
- path += ';jsessionid=' + Seam.Remoting.encodedSessionId;
+ if (Seam.encodedSessionId) {
+ path += ';jsessionid=' + Seam.encodedSessionId;
}
-
- r.open("POST", Seam.Remoting.resourcePath + path, true);
- r.send(envelope);
+ r.open("POST", Seam.resourcePath + path, true);
+ r.send(env);
}
-Seam.Remoting.displayError = function(code) {
+Seam.displayError = function(code) {
alert("There was an error processing your request. Error code: " + code);
}
-Seam.Remoting.setCallback = function(component, methodName, callback) {
+Seam.setCallback = function(component, methodName, callback) {
component.__callback[methodName] = callback;
}
-Seam.Remoting.processResponse = function(doc) {
+Seam.processResponse = function(doc) {
var headerNode;
var bodyNode;
var inScope = typeof(Seam) == "undefined" ? false : true;
if (!inScope) return;
-
- var context = new Seam.Remoting.__Context;
-
+ var context = new Seam.Context;
if (doc.documentElement) {
- for (var i = 0; i < doc.documentElement.childNodes.length; i++) {
+ for (var i=0; i<doc.documentElement.childNodes.length; i++) {
var node = doc.documentElement.childNodes.item(i);
if (node.tagName == "header")
headerNode = node;
@@ -555,7 +452,7 @@
if (headerNode) {
var contextNode;
- for (var i = 0; i < headerNode.childNodes.length; i++) {
+ for (var i=0; i<headerNode.childNodes.length; i++) {
var node = headerNode.childNodes.item(i);
if (node.tagName == "context") {
contextNode = node;
@@ -563,32 +460,30 @@
}
}
if (contextNode && context) {
- Seam.Remoting.unmarshalContext(contextNode, context);
- if (context.getConversationId() && Seam.Remoting.getContext().getConversationId() == null)
- Seam.Remoting.getContext().setConversationId(context.getConversationId());
+ Seam.unmarshalContext(contextNode, context);
+ if (context.getConversationId() && Seam.context.getConversationId() == null)
+ Seam.context.setConversationId(context.getConversationId());
}
}
if (bodyNode) {
- for (var i = 0; i < bodyNode.childNodes.length; i++) {
+ for (var i=0; i<bodyNode.childNodes.length; i++) {
var n = bodyNode.childNodes.item(i);
- if (n.tagName == "result") Seam.Remoting.processResult(n, context);
+ if (n.tagName == "result") Seam.processResult(n, context);
}
}
}
-Seam.Remoting.processResult = function(result, context) {
+Seam.processResult = function(result, context) {
var callId = result.getAttribute("id");
- var call = Seam.Remoting.pendingCalls.get(callId);
- Seam.Remoting.pendingCalls.remove(callId);
-
+ var call = Seam.pendingCalls.get(callId);
+ Seam.pendingCalls.remove(callId);
if (call && (call.callback || call.exceptionHandler)) {
var valueNode = null;
var refsNode = null;
var exceptionNode = null;
-
var c = result.childNodes;
- for (var i = 0; i < c.length; i++) {
+ for (var i=0; i<c.length; i++) {
var tag = c.item(i).tagName;
if (tag == "value")
valueNode = c.item(i);
@@ -597,52 +492,44 @@
else if (tag == "exception")
exceptionNode = c.item(i);
}
-
if (exceptionNode != null) {
var msgNode = null;
var c = exceptionNode.childNodes;
- for (var i = 0; i < c.length; i++) {
+ for (var i=0; i<c.length; i++) {
var tag = c.item(i).tagName;
if (tag == "message")
msgNode = c.item(i);
}
-
- var msg = Seam.Remoting.unmarshalValue(msgNode.firstChild);
- var ex = new Seam.Remoting.Exception(msg);
+ var msg = Seam.unmarshalValue(msgNode.firstChild);
+ var ex = new Seam.Exception(msg);
call.exceptionHandler(ex);
}
else {
var refs = new Array();
- if (refsNode) Seam.Remoting.unmarshalRefs(refsNode, refs);
- var value = Seam.Remoting.unmarshalValue(valueNode.firstChild, refs);
+ if (refsNode) Seam.unmarshalRefs(refsNode, refs);
+ var value = Seam.unmarshalValue(valueNode.firstChild, refs);
call.callback(value, context, callId);
}
}
}
-Seam.Remoting.unmarshalContext = function(ctxNode, context) {
- for (var i = 0; i < ctxNode.childNodes.length; i++) {
+Seam.unmarshalContext = function(ctxNode, context) {
+ for (var i=0; i<ctxNode.childNodes.length; i++) {
var tag = ctxNode.childNodes.item(i).tagName;
if (tag == "conversationId") context.setConversationId(ctxNode.childNodes.item(i).firstChild.nodeValue);
}
}
-Seam.Remoting.unmarshalRefs = function(refsNode, refs) {
+Seam.unmarshalRefs = function(refsNode, refs) {
var objs = new Array();
-
for (var i = 0; i < refsNode.childNodes.length; i++) {
if (refsNode.childNodes.item(i).tagName == "ref") {
var refNode = refsNode.childNodes.item(i);
var refId = parseInt(refNode.getAttribute("id"));
-
var valueNode = refNode.firstChild;
if (valueNode.tagName == "bean") {
- var obj = null;
var typeName = valueNode.getAttribute("type");
- if (Seam.Remoting.isBeanRegistered(typeName))
- obj = Seam.Remoting.instance(typeName);
- else
- obj = Seam.Remoting.createType(typeName);
+ var obj = Seam.isBeanRegistered(typeName) ? Seam.createBean(typeName) : null;
if (obj) {
refs[refId] = obj;
objs[objs.length] = {obj: obj, node: valueNode};
@@ -650,22 +537,19 @@
}
}
}
-
- for (var i = 0; i < objs.length; i++) {
- for (var j = 0; j < objs[i].node.childNodes.length; j++) {
+ for (var i=0; i<objs.length; i++) {
+ for (var j=0; j<objs[i].node.childNodes.length; j++) {
var child = objs[i].node.childNodes.item(j);
if (child.tagName == "member") {
var name = child.getAttribute("name");
- objs[i].obj[name] = Seam.Remoting.unmarshalValue(child.firstChild, refs);
+ objs[i].obj[name] = Seam.unmarshalValue(child.firstChild, refs);
}
}
}
}
-Seam.Remoting.unmarshalValue = function(element, refs) {
- var tag = element.tagName;
-
- switch (tag) {
+Seam.unmarshalValue = function(element, refs) {
+ switch (element.tagName) {
case "bool": return element.firstChild.nodeValue == "true";
case "number":
if (element.firstChild.nodeValue.indexOf(".") == -1)
@@ -674,7 +558,7 @@
return parseFloat(element.firstChild.nodeValue);
case "str":
var data = "";
- for (var i = 0; i < element.childNodes.length; i++) {
+ for (var i=0; i<element.childNodes.length; i++) {
if (element.childNodes[i].nodeType == 3)
data += element.childNodes[i].nodeValue;
}
@@ -682,53 +566,52 @@
case "ref": return refs[parseInt(element.getAttribute("id"))];
case "bag":
var value = new Array();
- for (var i = 0; i < element.childNodes.length; i++) {
+ for (var i=0; i<element.childNodes.length; i++) {
if (element.childNodes.item(i).tagName == "element")
- value[value.length] = Seam.Remoting.unmarshalValue(element.childNodes.item(i).firstChild, refs);
+ value[value.length] = Seam.unmarshalValue(element.childNodes.item(i).firstChild, refs);
}
return value;
case "map":
- var map = new Seam.Remoting.Map();
+ var m = new Seam.Map();
for (var i = 0; i < element.childNodes.length; i++) {
var childNode = element.childNodes.item(i);
if (childNode.tagName == "element") {
var key = null
var value = null;
-
for (var j = 0; j < childNode.childNodes.length; j++) {
if (key == null && childNode.childNodes.item(j).tagName == "k")
- key = Seam.Remoting.unmarshalValue(childNode.childNodes.item(j).firstChild, refs);
+ key = Seam.unmarshalValue(childNode.childNodes.item(j).firstChild, refs);
else if (value == null && childNode.childNodes.item(j).tagName == "v")
- value = Seam.Remoting.unmarshalValue(childNode.childNodes.item(j).firstChild, refs);
+ value = Seam.unmarshalValue(childNode.childNodes.item(j).firstChild, refs);
}
-
- if (key != null) map.put(key, value);
+ if (key != null) m.put(key, value);
}
}
- return map;
- case "date": return Seam.Remoting.deserializeDate(element.firstChild.nodeValue);
+ return m;
+ case "date": return Seam.deserializeDate(element.firstChild.nodeValue);
default: return null;
}
}
-Seam.Remoting.deserializeDate = function(val) {
- var dte = new Date();
- dte.setFullYear(parseInt(val.substring(0,4), 10),
- parseInt(val.substring(4,6), 10) - 1,
- parseInt(val.substring(6,8), 10));
- dte.setHours(parseInt(val.substring(8,10), 10));
- dte.setMinutes(parseInt(val.substring(10,12), 10));
- dte.setSeconds(parseInt(val.substring(12,14), 10));
- dte.setMilliseconds(parseInt(val.substring(14,17), 10));
- return dte;
+Seam.deserializeDate = function(val) {
+ var d = new Date();
+ d.setFullYear(parseInt(val.substring(0,4), 10),
+ parseInt(val.substring(4,6), 10) - 1,
+ parseInt(val.substring(6,8), 10));
+ d.setHours(parseInt(val.substring(8,10), 10));
+ d.setMinutes(parseInt(val.substring(10,12), 10));
+ d.setSeconds(parseInt(val.substring(12,14), 10));
+ d.setMilliseconds(parseInt(val.substring(14,17), 10));
+ return d;
}
-Seam.Remoting.loadingMsgDiv = null;
-Seam.Remoting.loadingMessage = "Please wait...";
-Seam.Remoting.displayLoadingMessage = function() {
- if (!Seam.Remoting.loadingMsgDiv) {
- Seam.Remoting.loadingMsgDiv = document.createElement('div');
- var d = Seam.Remoting.loadingMsgDiv;
+Seam.loadingMsgDiv = null;
+Seam.loadingMessage = "Please wait...";
+
+Seam.displayLoadingMessage = function() {
+ if (!Seam.loadingMsgDiv) {
+ Seam.loadingMsgDiv = document.createElement('div');
+ var d = Seam.loadingMsgDiv;
d.setAttribute('id', 'loadingMsg');
d.style.position = "absolute";
d.style.top = "0px";
@@ -739,133 +622,98 @@
d.style.fontSize = "small";
d.style.padding = "2px";
d.style.border = "1px solid black";
-
document.body.appendChild(d);
-
- var text = document.createTextNode(Seam.Remoting.loadingMessage);
+ var text = document.createTextNode(Seam.loadingMessage);
d.appendChild(text);
}
else {
- Seam.Remoting.loadingMsgDiv.innerHTML = Seam.Remoting.loadingMessage;
- Seam.Remoting.loadingMsgDiv.style.visibility = 'visible';
+ Seam.loadingMsgDiv.innerHTML = Seam.loadingMessage;
+ Seam.loadingMsgDiv.style.visibility = 'visible';
}
}
-Seam.Remoting.hideLoadingMessage = function() {
- if (Seam.Remoting.loadingMsgDiv)
- Seam.Remoting.loadingMsgDiv.style.visibility = 'hidden';
+Seam.hideLoadingMessage = function() {
+ if (Seam.loadingMsgDiv)
+ Seam.loadingMsgDiv.style.visibility = 'hidden';
}
/* Remote Model API */
-Seam.Remoting.Action = function() {
- this.beanType = null;
- this.qualifiers = null;
- this.method = null;
- this.params = new Array();
- this.expression = null;
+Seam.Action = function() {
+ this.beanType = null;
+ this.qualifiers = null;
+ this.method = null;
+ this.params = new Array();
+ this.expression = null;
- Seam.Remoting.Action.prototype.setBeanType = function(beanType) {
- this.beanType = beanType;
- return this;
+ Seam.Action.prototype.setBeanType = function(beanType) {
+ this.beanType = beanType;
+ return this;
}
- Seam.Remoting.Action.prototype.setQualifiers = function(qualifiers) {
- this.qualifiers = qualifiers;
- return this;
+ Seam.Action.prototype.setQualifiers = function(qualifiers) {
+ this.qualifiers = qualifiers;
+ return this;
}
- Seam.Remoting.Action.prototype.setMethod = function(method) {
- this.method = method;
- return this;
+ Seam.Action.prototype.setMethod = function(method) {
+ this.method = method;
+ return this;
}
- Seam.Remoting.Action.prototype.addParam = function(param) {
- this.params.push(param);
- return this;
+ Seam.Action.prototype.addParam = function(param) {
+ this.params.push(param);
+ return this;
}
- Seam.Remoting.Action.prototype.setExpression = function(expr) {
- this.expression = expr;
+ Seam.Action.prototype.setExpression = function(expr) {
+ this.expression = expr;
return this;
}
}
-Seam.Remoting.processModelResponse = function(doc) {
- var headerNode;
- var bodyNode;
- var inScope = typeof(Seam) == "undefined" ? false : true;
- if (!inScope) return;
-
- var context = new Seam.Remoting.__Context;
-
- if (doc.documentElement) {
- for (var i = 0; i < doc.documentElement.childNodes.length; i++) {
- var node = doc.documentElement.childNodes.item(i);
- if (node.tagName == "header")
- headerNode = node;
- else if (node.tagName == "body")
- bodyNode = node;
- }
- }
- if (headerNode) {
- var contextNode;
- for (var i = 0; i < headerNode.childNodes.length; i++) {
- var node = headerNode.childNodes.item(i);
- if (node.tagName == "context") {
- contextNode = node;
- break;
- }
- }
- if (contextNode && context) {
- Seam.Remoting.unmarshalContext(contextNode, context);
- if (context.getConversationId() && Seam.Remoting.getContext().getConversationId() == null)
- Seam.Remoting.getContext().setConversationId(context.getConversationId());
- }
- }
- if (bodyNode) {
- for (var i = 0; i < bodyNode.childNodes.length; i++) {
- var n = bodyNode.childNodes.item(i);
- if (n.tagName == "model") Seam.Remoting.processModel(n, context);
- }
- }
-}
-
-Seam.Remoting.processModel = function(n, ctx) {
-
-}
-
-Seam.Remoting.Model = function() {
+Seam.Model = function() {
this.expressions = new Array();
this.beans = new Array();
+ this.values = new Array();
+ this.callback = null;
- Seam.Remoting.Model.prototype.addExpression = function(alias, expr) {
- this.expressions.push({alias: alias, expr: expr});
+ Seam.Model.prototype.addExpression = function(alias, expr) {
+ this.expressions.push({alias: alias, expr: expr});
}
+
+ Seam.Model.prototype.getValue = function(alias) {
+ for (var i = 0; i < this.values.length; i++) {
+ if (this.values[i].alias == alias) {
+ return this.values[i].value;
+ }
+ }
+ return null;
+ }
- Seam.Remoting.Model.prototype.addBean = function(alias, bean, property) {
+ Seam.Model.prototype.addBean = function(alias, bean, property) {
var q = null;
if (arguments.length > 3) {
- q = new Array();
- for (var i = 3; i < arguments.length; i++) {
- q.push(arguments[i]);
- }
- }
- this.beans.push({alias: alias, bean: bean, property: property, qualifiers: q});
+ q = new Array();
+ for (var i = 3; i < arguments.length; i++) {
+ q.push(arguments[i]);
+ }
+ }
+ this.beans.push({alias: alias, bean: bean, property: property, qualifiers: q});
}
- Seam.Remoting.Model.prototype.fetch = function(action) {
- var r = this.createFetchRequest(action);
- var env = Seam.Remoting.createEnvelope(Seam.Remoting.createHeader(), r.data);
- Seam.Remoting.pendingCalls.put(r.id, r);
- Seam.Remoting.sendAjaxRequest(env, Seam.Remoting.PATH_MODEL, Seam.Remoting.processModelResponse, false);
+ Seam.Model.prototype.fetch = function(action, callback) {
+ this.callback = callback;
+ var r = this.createFetchRequest(action);
+ var env = Seam.createEnvelope(Seam.createHeader(), r.data);
+ Seam.pendingCalls.put(r.id, r);
+ Seam.sendAjaxRequest(env, Seam.PATH_MODEL, this.processFetchResponse, false);
}
- Seam.Remoting.Model.prototype.createFetchRequest = function(a) { // a = action
- var callId = "" + Seam.Remoting.__callId++;
+ Seam.Model.prototype.createFetchRequest = function(a) { // a = action
+ var callId = "" + Seam.__callId++;
var d = "<model operation=\"fetch\" callId=\"" + callId + "\">";
var refs = new Array();
-
if (a) {
d += "<action>";
if (a.beanType) {
@@ -874,17 +722,15 @@
if (a.method) d += "<method>" + a.method + "</method>";
if (a.params.length > 0) {
d += "<params>";
- for (var i = 0; i < a.params.length; i++) {
- d += "<param>" + Seam.Remoting.serializeValue(a.params[i], null, refs) + "</param>";
+ for (var i=0; i<a.params.length; i++) {
+ d += "<param>" + Seam.serializeValue(a.params[i], null, refs) + "</param>";
}
d += "</params>";
}
if (refs.length > 0) {
d += "<refs>";
- for (var i = 0; i < refs.length; i++) {
- d += "<ref id=\"" + i + "\">";
- d += Seam.Remoting.serializeType(refs[i], refs);
- d += "</ref>";
+ for (var i=0; i<refs.length; i++) {
+ d += "<ref id=\"" + i + "\">" + Seam.serializeType(refs[i], refs) + "</ref>";
}
d += "</refs>";
}
@@ -900,7 +746,7 @@
d += "<bean alias=\"" + b.alias + "\"><name>" + b.bean + "</name>";
if (b.qualifiers && b.qualifiers.length > 0) {
d += "<qualifiers>";
- for (var j = 0; j < b.qualifiers.length; j++) {
+ for (var j=0; j<b.qualifiers.length; j++) {
d += (j > 0 ? "," : "") + b.qualifiers[j];
}
d += "</qualifiers>";
@@ -909,227 +755,71 @@
}
}
if (this.expressions.length > 0) {
- for (var i = 0; i < this.expressions.length; i++) {
+ for (var i=0; i<this.expressions.length; i++) {
var e = this.expressions[i];
d += "<expression alias=\"" + e.alias + "\">" + e.expr + "</expression>";
}
}
d += "</model>";
-
return {data: d, id: callId};
}
- Seam.Remoting.Model.prototype.processFetchResponse = function(doc) {
-
- }
-
- Seam.Remoting.Model.prototype.applyUpdates = function(action) {
-
- }
-
-
-}
-
-/* Messaging API */
-
-Seam.Remoting.pollInterval = 10; // Default poll interval of 10 seconds
-Seam.Remoting.pollTimeout = 0; // Default timeout of 0 seconds
-Seam.Remoting.polling = false;
-
-Seam.Remoting.setPollInterval = function(interval) {
- Seam.Remoting.pollInterval = interval;
-}
-
-Seam.Remoting.setPollTimeout = function(timeout) {
- Seam.Remoting.pollTimeout = timeout;
-}
-
-Seam.Remoting.subscriptionRegistry = new Array();
-
-Seam.Remoting.subscribe = function(topicName, callback) {
- for (var i = 0; i < Seam.Remoting.subscriptionRegistry.length; i++) {
- if (Seam.Remoting.subscriptionRegistry[i].topic == topicName)
- return;
- }
-
- var body = "<subscribe topic=\"" + topicName + "\"/>";
- var env = Seam.Remoting.createEnvelope(null, body);
- Seam.Remoting.subscriptionRegistry.push({topic:topicName, callback:callback});
- Seam.Remoting.sendAjaxRequest(env, Seam.Remoting.PATH_SUBSCRIPTION, Seam.Remoting.subscriptionCallback, false);
-}
-
-Seam.Remoting.unsubscribe = function(topicName) {
- var token = null;
-
- for (var i = 0; i < Seam.Remoting.subscriptionRegistry.length; i++) {
- if (Seam.Remoting.subscriptionRegistry[i].topic == topicName) {
- token = Seam.Remoting.subscriptionRegistry[i].token;
- Seam.Remoting.subscriptionRegistry.splice(i, 1);
+ Seam.Model.prototype.processFetchResponse = function(doc) {
+ var headerNode;
+ var bodyNode;
+ var inScope = typeof(Seam) == "undefined" ? false : true;
+ if (!inScope) return;
+ var context = new Seam.Context;
+ if (doc.documentElement) {
+ for (var i=0; i<doc.documentElement.childNodes.length; i++) {
+ var node = doc.documentElement.childNodes.item(i);
+ if (node.tagName == "header")
+ headerNode = node;
+ else if (node.tagName == "body")
+ bodyNode = node;
+ }
}
- }
-
- if (token) {
- var body = "<unsubscribe token=\"" + token + "\"/>";
- var env = Seam.Remoting.createEnvelope(null, body);
- Seam.Remoting.sendAjaxRequest(env, Seam.Remoting.PATH_SUBSCRIPTION, null, false);
- }
-}
-
-Seam.Remoting.subscriptionCallback = function(doc) {
- var body = doc.documentElement.firstChild;
- for (var i = 0; i < body.childNodes.length; i++) {
- var node = body.childNodes.item(i);
- if (node.tagName == "subscription") {
- var topic = node.getAttribute("topic");
- var token = node.getAttribute("token");
- for (var i = 0; i < Seam.Remoting.subscriptionRegistry.length; i++) {
- if (Seam.Remoting.subscriptionRegistry[i].topic == topic) {
- Seam.Remoting.subscriptionRegistry[i].token = token;
- Seam.Remoting.poll();
+ if (headerNode) {
+ var contextNode;
+ for (var i=0; i<headerNode.childNodes.length; i++) {
+ var node = headerNode.childNodes.item(i);
+ if (node.tagName == "context") {
+ contextNode = node;
break;
}
}
+ if (contextNode && context) {
+ Seam.unmarshalContext(contextNode, context);
+ if (context.getConversationId() && Seam.context.getConversationId() == null)
+ Seam.context.setConversationId(context.getConversationId());
+ }
}
- }
-}
-
-Seam.Remoting.pollTimeoutFunction = null;
-
-Seam.Remoting.poll = function() {
- if (Seam.Remoting.polling) return;
-
- Seam.Remoting.polling = true;
- clearTimeout(Seam.Remoting.pollTimeoutFunction);
-
- var body = "";
-
- if (Seam.Remoting.subscriptionRegistry.length == 0) {
- Seam.Remoting.polling = false;
- return;
- }
-
- for (var i = 0; i < Seam.Remoting.subscriptionRegistry.length; i++) {
- body += "<poll token=\"" + Seam.Remoting.subscriptionRegistry[i].token + "\" ";
- body += "timeout=\"" + Seam.Remoting.pollTimeout + "\"/>";
- }
-
- var env = Seam.Remoting.createEnvelope(null, body);
- Seam.Remoting.sendAjaxRequest(env, Seam.Remoting.PATH_POLL, Seam.Remoting.pollCallback, true);
-}
-
-Seam.Remoting.pollCallback = function(doc) {
- Seam.Remoting.polling = false;
-
- var body = doc.documentElement.firstChild;
- for (var i = 0; i < body.childNodes.length; i++) {
- var node = body.childNodes.item(i);
- if (node.tagName == "messages")
- Seam.Remoting.processMessages(node);
- else if (node.tagName == "errors")
- Seam.Remoting.processPollErrors(node);
- }
-
- Seam.Remoting.pollTimeoutFunction = setTimeout("Seam.Remoting.poll()", Math.max(Seam.Remoting.pollInterval * 1000, 1000));
-}
-
-Seam.Remoting.processMessages = function(messages) {
- var token = messages.getAttribute("token");
-
- var callback = null;
- for (var i = 0; i < Seam.Remoting.subscriptionRegistry.length; i++) {
- if (Seam.Remoting.subscriptionRegistry[i].token == token)
- {
- callback = Seam.Remoting.subscriptionRegistry[i].callback;
- break;
- }
- }
-
- if (callback != null) {
- var m = null;
- var c = messages.childNodes;
- for (var i = 0; i < c.length; i++) {
- if (c.item(i).tagName == "message")
- {
- m = c.item(i);
- var messageType = m.getAttribute("type");
-
- var valueNode = null;
- var refsNode = null;
- for (var j = 0; j < m.childNodes.length; j++) {
- var node = m.childNodes.item(j);
- if (node.tagName == "value")
- valueNode = node;
- else if (node.tagName == "refs")
- refsNode = node;
+ if (bodyNode) {
+ for (var i=0; i<bodyNode.childNodes.length; i++) {
+ var n = bodyNode.childNodes.item(i);
+ if (n.tagName == "model") {
+ var valueNodes = new Array();
+ var refsNode = null;
+ for (var j=0; j<n.childNodes.length; j++) {
+ var cn = n.childNodes.item(j);
+ if (cn.tagName == "value")
+ valueNodes.push({node:cn.firstChild,alias:cn.getAttribute("alias")});
+ else if (cn.tagName == "refs")
+ refsNode = n.childNodes.item(j);
+ }
+ var refs = new Array();
+ if (refsNode) Seam.unmarshalRefs(refsNode, refs);
+ for (var j=0; j<valueNodes.length; j++) {
+ var value = Seam.unmarshalValue(valueNodes[j].node, refs);
+ this.values.push({alias:valueNodes[j].alias, value:value});
+ }
}
-
- var refs = new Array();
- if (refsNode) Seam.Remoting.unmarshalRefs(refsNode, refs);
- var v = Seam.Remoting.unmarshalValue(valueNode.firstChild, refs);
- callback(Seam.Remoting.createMessage(messageType, v));
}
}
+ if (this.callback) callback(this);
}
-}
-Seam.Remoting.processErrors = function(errors) {
- var t = errors.getAttribute("token");
+ Seam.Model.prototype.applyUpdates = function(action) {
- for (var i = 0; i < Seam.Remoting.subscriptionRegistry.length; i++) {
- if (Seam.Remoting.subscriptionRegistry[i].token == t) {
- Seam.Remoting.subscriptionRegistry.splice(i, 1);
- break;
- }
}
-
- for (var i = 0; i < errors.childNodes.length; i++) {
- if (errors.childNodes.item(i).tagName == "error") {
- var errorNode = errors.childNodes.item(i);
- var code = errorNode.getAttribute("code");
- var message = errorNode.firstChild.nodeValue;
-
- if (Seam.Remoting.onPollError)
- Seam.Remoting.onPollError(code, message);
- else
- alert("A polling error occurred: " + code + " " + message);
- }
- }
-}
-
-Seam.Remoting.ObjectMessage = function() {
- this.value = null;
-
- Seam.Remoting.ObjectMessage.prototype.getValue = function() {
- return this.value;
- }
-
- Seam.Remoting.ObjectMessage.prototype.setValue = function(value) {
- this.value = value;
- }
-}
-
-Seam.Remoting.TextMessage = function() {
- this.text = null;
-
- Seam.Remoting.TextMessage.prototype.getText = function() {
- return this.text;
- }
-
- Seam.Remoting.TextMessage.prototype.setText = function(text) {
- this.text = text;
- }
-}
-
-Seam.Remoting.createMessage = function(messageType, value) {
- switch (messageType) {
- case "object":
- var msg = new Seam.Remoting.ObjectMessage();
- msg.setValue(value);
- return msg;
- case "text":
- var msg = new Seam.Remoting.TextMessage();
- msg.setText(value);
- return msg;
- }
- return null;
-}
+}
\ No newline at end of file
15 years
Seam SVN: r11806 - in branches/enterprise/JBPAPP_4_3_FP01/examples/itext: src/org/jboss/seam/example/pdf and 1 other directory.
by seam-commits@lists.jboss.org
Author: manaRH
Date: 2009-12-10 08:38:14 -0500 (Thu, 10 Dec 2009)
New Revision: 11806
Modified:
branches/enterprise/JBPAPP_4_3_FP01/examples/itext/extra/PDFRenderKit.java
branches/enterprise/JBPAPP_4_3_FP01/examples/itext/extra/PDFResponseWriter.java
branches/enterprise/JBPAPP_4_3_FP01/examples/itext/extra/SeamFaceletViewHandler.java
branches/enterprise/JBPAPP_4_3_FP01/examples/itext/extra/TextRenderer.java
branches/enterprise/JBPAPP_4_3_FP01/examples/itext/src/org/jboss/seam/example/pdf/DynamicChart.java
branches/enterprise/JBPAPP_4_3_FP01/examples/itext/src/org/jboss/seam/example/pdf/SwingComponent.java
Log:
JBPAPP-3185
Modified: branches/enterprise/JBPAPP_4_3_FP01/examples/itext/extra/PDFRenderKit.java
===================================================================
--- branches/enterprise/JBPAPP_4_3_FP01/examples/itext/extra/PDFRenderKit.java 2009-12-10 10:56:24 UTC (rev 11805)
+++ branches/enterprise/JBPAPP_4_3_FP01/examples/itext/extra/PDFRenderKit.java 2009-12-10 13:38:14 UTC (rev 11806)
@@ -18,7 +18,7 @@
Map<String,Renderer> renderers = new HashMap<String,Renderer>();
public ResponseStream createResponseStream(OutputStream stream) {
- System.out.println("RESPONSE STREAM!");
+// System.out.println("RESPONSE STREAM!");
return null;
}
@@ -32,17 +32,17 @@
}
public ResponseStateManager getResponseStateManager() {
- System.out.println("GET RESPONSE STATE MANAGER");
+// System.out.println("GET RESPONSE STATE MANAGER");
return null;
}
public Renderer getRenderer(String family, String rendererType) {
- System.out.println("GET RENDERER: " + family + "/" + rendererType);
+// System.out.println("GET RENDERER: " + family + "/" + rendererType);
return renderers.get(key(family,rendererType));
}
public void addRenderer(String family, String rendererType, Renderer renderer) {
- System.out.println("ADD RENDER " + family + "/" + rendererType + ":" + renderer);
+// System.out.println("ADD RENDER " + family + "/" + rendererType + ":" + renderer);
renderers.put(key(family,rendererType), renderer);
}
Modified: branches/enterprise/JBPAPP_4_3_FP01/examples/itext/extra/PDFResponseWriter.java
===================================================================
--- branches/enterprise/JBPAPP_4_3_FP01/examples/itext/extra/PDFResponseWriter.java 2009-12-10 10:56:24 UTC (rev 11805)
+++ branches/enterprise/JBPAPP_4_3_FP01/examples/itext/extra/PDFResponseWriter.java 2009-12-10 13:38:14 UTC (rev 11806)
@@ -22,7 +22,6 @@
public PDFResponseWriter(FacesContext context, Writer writer)
{
- System.out.println("Context is " + context);
this.writer = writer;
this.context = context;
}
Modified: branches/enterprise/JBPAPP_4_3_FP01/examples/itext/extra/SeamFaceletViewHandler.java
===================================================================
--- branches/enterprise/JBPAPP_4_3_FP01/examples/itext/extra/SeamFaceletViewHandler.java 2009-12-10 10:56:24 UTC (rev 11805)
+++ branches/enterprise/JBPAPP_4_3_FP01/examples/itext/extra/SeamFaceletViewHandler.java 2009-12-10 13:38:14 UTC (rev 11806)
@@ -63,9 +63,9 @@
{
initialize(context); // shouldn't have to do this
- System.out.println("Building: " + viewToRender + " -> " + viewToRender.getChildCount());
+// System.out.println("Building: " + viewToRender + " -> " + viewToRender.getChildCount());
buildView(context, viewToRender);
- System.out.println("Built: " + viewToRender + " -> " + viewToRender.getChildCount());
+// System.out.println("Built: " + viewToRender + " -> " + viewToRender.getChildCount());
}
}
Modified: branches/enterprise/JBPAPP_4_3_FP01/examples/itext/extra/TextRenderer.java
===================================================================
--- branches/enterprise/JBPAPP_4_3_FP01/examples/itext/extra/TextRenderer.java 2009-12-10 10:56:24 UTC (rev 11805)
+++ branches/enterprise/JBPAPP_4_3_FP01/examples/itext/extra/TextRenderer.java 2009-12-10 13:38:14 UTC (rev 11806)
@@ -21,18 +21,18 @@
UIComponent component)
throws IOException
{
- System.out.println("BEGIN RENDER " + component);
+// System.out.println("BEGIN RENDER " + component);
}
public void encodeEnd(FacesContext context,
UIComponent component)
throws IOException
{
- System.out.println("END RENDER " + component);
+// System.out.println("END RENDER " + component);
if (component instanceof ValueHolder) {
ValueHolder holder = (ValueHolder) component;
Object value = holder.getValue();
- System.out.println("*VALUE IS " + value);
+// System.out.println("*VALUE IS " + value);
if (value != null) {
Chunk c = new Chunk(value.toString());
Modified: branches/enterprise/JBPAPP_4_3_FP01/examples/itext/src/org/jboss/seam/example/pdf/DynamicChart.java
===================================================================
--- branches/enterprise/JBPAPP_4_3_FP01/examples/itext/src/org/jboss/seam/example/pdf/DynamicChart.java 2009-12-10 10:56:24 UTC (rev 11805)
+++ branches/enterprise/JBPAPP_4_3_FP01/examples/itext/src/org/jboss/seam/example/pdf/DynamicChart.java 2009-12-10 13:38:14 UTC (rev 11806)
@@ -307,12 +307,11 @@
}
public void removeSeries(String id) {
- System.out.println("REMOVE: " + id);
+ //System.out.println("REMOVE: " + id);
}
public void newSeries() {
String newId = findUniqueSeriesId();
- System.out.println("** series " + newId);
Data set = new Data();
set.setId(newId);
Modified: branches/enterprise/JBPAPP_4_3_FP01/examples/itext/src/org/jboss/seam/example/pdf/SwingComponent.java
===================================================================
--- branches/enterprise/JBPAPP_4_3_FP01/examples/itext/src/org/jboss/seam/example/pdf/SwingComponent.java 2009-12-10 10:56:24 UTC (rev 11805)
+++ branches/enterprise/JBPAPP_4_3_FP01/examples/itext/src/org/jboss/seam/example/pdf/SwingComponent.java 2009-12-10 13:38:14 UTC (rev 11806)
@@ -4,20 +4,24 @@
import javax.swing.*;
import org.jboss.seam.annotations.Create;
+import org.jboss.seam.annotations.Logger;
import org.jboss.seam.annotations.Name;
+import org.jboss.seam.log.Log;
@Name("swing")
public class SwingComponent
{
+
+ @Logger
+ private Log log;
+
@Create
public void init() {
try {
UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
} catch(Exception e) {
- System.out.println("Error setting Java LAF: " + e);
- }
-
- System.out.println("** " + UIManager.getLookAndFeel());
+ log.error("Error setting Java LAF: " + e);
+ }
}
public Component getButton() {
15 years
Seam SVN: r11805 - in modules/remoting/trunk/src/main/java/org/jboss/seam/remoting: model and 1 other directory.
by seam-commits@lists.jboss.org
Author: shane.bryzak(a)jboss.com
Date: 2009-12-10 05:56:24 -0500 (Thu, 10 Dec 2009)
New Revision: 11805
Modified:
modules/remoting/trunk/src/main/java/org/jboss/seam/remoting/Call.java
modules/remoting/trunk/src/main/java/org/jboss/seam/remoting/MarshalUtils.java
modules/remoting/trunk/src/main/java/org/jboss/seam/remoting/model/Model.java
modules/remoting/trunk/src/main/java/org/jboss/seam/remoting/model/ModelHandler.java
Log:
fix model fetch response
Modified: modules/remoting/trunk/src/main/java/org/jboss/seam/remoting/Call.java
===================================================================
--- modules/remoting/trunk/src/main/java/org/jboss/seam/remoting/Call.java 2009-12-10 10:55:30 UTC (rev 11804)
+++ modules/remoting/trunk/src/main/java/org/jboss/seam/remoting/Call.java 2009-12-10 10:56:24 UTC (rev 11805)
@@ -174,8 +174,8 @@
{
CreationalContext ctx = beanManager.createCreationalContext(targetBean);
- // Create an instance of the component
- Object instance = targetBean.create(ctx);
+ // Get an instance of the component
+ Object instance = beanManager.getReference(targetBean, targetBean.getBeanClass(), ctx);;
if (instance == null)
{
Modified: modules/remoting/trunk/src/main/java/org/jboss/seam/remoting/MarshalUtils.java
===================================================================
--- modules/remoting/trunk/src/main/java/org/jboss/seam/remoting/MarshalUtils.java 2009-12-10 10:55:30 UTC (rev 11804)
+++ modules/remoting/trunk/src/main/java/org/jboss/seam/remoting/MarshalUtils.java 2009-12-10 10:56:24 UTC (rev 11805)
@@ -26,6 +26,10 @@
private static final byte[] VALUE_TAG_OPEN = "<value>".getBytes();
private static final byte[] VALUE_TAG_CLOSE = "</value>".getBytes();
+
+ private static final byte[] ALIASED_VALUE_TAG_OPEN_START = "<value alias=\"".getBytes();
+ private static final byte[] ALIASED_VALUE_TAG_OPEN_END = "\">".getBytes();
+ private static final byte[] ALIASED_VALUE_TAG_CLOSE = "</value>".getBytes();
private static final byte[] EXCEPTION_TAG_OPEN = "<exception>".getBytes();
private static final byte[] EXCEPTION_TAG_CLOSE = "</exception>".getBytes();
@@ -87,10 +91,12 @@
{
Model.BeanProperty property = model.getBeanProperties().get(alias);
- out.write(VALUE_TAG_OPEN);
+ out.write(ALIASED_VALUE_TAG_OPEN_START);
+ out.write(alias.getBytes());
+ out.write(ALIASED_VALUE_TAG_OPEN_END);
model.getCallContext().createWrapperFromObject(property.getValue(), "")
.marshal(out);
- out.write(VALUE_TAG_CLOSE);
+ out.write(ALIASED_VALUE_TAG_CLOSE);
}
out.write(RequestHandler.REFS_TAG_OPEN);
Modified: modules/remoting/trunk/src/main/java/org/jboss/seam/remoting/model/Model.java
===================================================================
--- modules/remoting/trunk/src/main/java/org/jboss/seam/remoting/model/Model.java 2009-12-10 10:55:30 UTC (rev 11804)
+++ modules/remoting/trunk/src/main/java/org/jboss/seam/remoting/model/Model.java 2009-12-10 10:56:24 UTC (rev 11805)
@@ -49,8 +49,8 @@
@SuppressWarnings("unchecked")
public void evaluate(CreationalContext ctx)
- {
- Object instance = bean.create(ctx);
+ {
+ Object instance = beanManager.getReference(bean, bean.getBeanClass(), ctx);
if (propertyName != null)
{
@@ -120,8 +120,7 @@
* store the values in the BeanProperty map.
*/
public void evaluate()
- {
-
+ {
for (String alias : beanProperties.keySet())
{
BeanProperty property = beanProperties.get(alias);
Modified: modules/remoting/trunk/src/main/java/org/jboss/seam/remoting/model/ModelHandler.java
===================================================================
--- modules/remoting/trunk/src/main/java/org/jboss/seam/remoting/model/ModelHandler.java 2009-12-10 10:55:30 UTC (rev 11804)
+++ modules/remoting/trunk/src/main/java/org/jboss/seam/remoting/model/ModelHandler.java 2009-12-10 10:56:24 UTC (rev 11805)
@@ -1,5 +1,7 @@
package org.jboss.seam.remoting.model;
+import static org.jboss.weld.jsf.JsfHelper.getHttpSession;
+
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
@@ -13,6 +15,7 @@
import javax.inject.Inject;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpSession;
import org.dom4j.Document;
import org.dom4j.Element;
@@ -22,7 +25,11 @@
import org.jboss.seam.remoting.RequestContext;
import org.jboss.seam.remoting.RequestHandler;
import org.jboss.seam.remoting.wrapper.Wrapper;
+import org.jboss.weld.Container;
+import org.jboss.weld.context.ContextLifecycle;
+import org.jboss.weld.context.ConversationContext;
import org.jboss.weld.conversation.ConversationManager;
+import org.jboss.weld.servlet.ConversationBeanStore;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -63,11 +70,20 @@
Document doc = xmlReader.read(new StringReader(requestData));
final Element env = doc.getRootElement();
final RequestContext ctx = new RequestContext(env.element("header"));
+
+ // Initialize the conversation context
+ ConversationContext conversationContext = Container.instance().deploymentServices().get(ContextLifecycle.class).getConversationContext();
+ conversationContext.setBeanStore(new ConversationBeanStore(request.getSession(), ctx.getConversationId()));
+ conversationContext.setActive(true);
if (ctx.getConversationId() != null && !ctx.getConversationId().isEmpty())
{
conversationManager.beginOrRestoreConversation(ctx.getConversationId());
}
+ else
+ {
+ conversationManager.beginOrRestoreConversation(null);
+ }
Set<Model> models = new HashSet<Model>();
Call action = null;
@@ -154,6 +170,11 @@
}
else
{
+ for (Model model : models)
+ {
+ model.evaluate();
+ }
+
ctx.setConversationId(conversation.getId());
marshalResponse(models, ctx, response.getOutputStream());
}
15 years
Seam SVN: r11804 - in modules/remoting/trunk/examples/model: src/main/java/org/jboss/seam/remoting/examples/model and 3 other directories.
by seam-commits@lists.jboss.org
Author: shane.bryzak(a)jboss.com
Date: 2009-12-10 05:55:30 -0500 (Thu, 10 Dec 2009)
New Revision: 11804
Modified:
modules/remoting/trunk/examples/model/pom.xml
modules/remoting/trunk/examples/model/src/main/java/org/jboss/seam/remoting/examples/model/Customer.java
modules/remoting/trunk/examples/model/src/main/resources/META-INF/persistence.xml
modules/remoting/trunk/examples/model/src/main/resources/import.sql
modules/remoting/trunk/examples/model/src/main/webapp/model.html
Log:
workaround deployment problem
Modified: modules/remoting/trunk/examples/model/pom.xml
===================================================================
--- modules/remoting/trunk/examples/model/pom.xml 2009-12-09 10:49:22 UTC (rev 11803)
+++ modules/remoting/trunk/examples/model/pom.xml 2009-12-10 10:55:30 UTC (rev 11804)
@@ -2,28 +2,12 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
- <parent>
- <groupId>org.jboss.seam.examples</groupId>
- <artifactId>seam-examples-parent</artifactId>
- <version>3.0.0-SNAPSHOT</version>
- </parent>
-
<groupId>org.jboss.seam.remoting.examples</groupId>
<artifactId>remoting-model</artifactId>
<packaging>war</packaging>
<version>1.0.0-SNAPSHOT</version>
- <name>Seam Remoting Examples: Model</name>
+ <name>Seam Remoting Model Example</name>
- <pluginRepositories>
- <pluginRepository>
- <id>codehaus snapshot repository</id>
- <url>http://snapshots.repository.codehaus.org/</url>
- <releases>
- <enabled>true</enabled>
- </releases>
- </pluginRepository>
- </pluginRepositories>
-
<dependencies>
<!--dependency>
<groupId>org.testng</groupId>
@@ -52,9 +36,29 @@
<scope>provided</scope>
</dependency>
-
-
</dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <source>1.5</source>
+ <target>1.5</target>
+ </configuration>
+ </plugin>
+
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-war-plugin</artifactId>
+ <version>2.0</version>
+ <configuration>
+ <warName>${pom.artifactId}</warName>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
</project>
Modified: modules/remoting/trunk/examples/model/src/main/java/org/jboss/seam/remoting/examples/model/Customer.java
===================================================================
--- modules/remoting/trunk/examples/model/src/main/java/org/jboss/seam/remoting/examples/model/Customer.java 2009-12-09 10:49:22 UTC (rev 11803)
+++ modules/remoting/trunk/examples/model/src/main/java/org/jboss/seam/remoting/examples/model/Customer.java 2009-12-10 10:55:30 UTC (rev 11804)
@@ -4,10 +4,11 @@
import java.util.Date;
import javax.persistence.Entity;
-import javax.persistence.EnumType;
-import javax.persistence.Enumerated;
+//import javax.persistence.EnumType;
+//import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
+import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
@@ -18,25 +19,26 @@
* @author Shane Bryzak
*/
@Entity
+@Table(name = "customer")
public class Customer implements Serializable
{
private static final long serialVersionUID = 4289723352398788625L;
- public static enum Gender { male, female }
+// public static enum Gender { male, female }
- @Id @GeneratedValue
+
private Integer customerId;
private String firstName;
private String lastName;
- @Temporal(TemporalType.DATE)
+
private Date dateOfBirth;
- @Enumerated(EnumType.STRING)
- private Gender gender;
+ //(a)Enumerated(EnumType.STRING)
+ //private Gender gender;
-
+ @Id @GeneratedValue
public Integer getCustomerId()
{
return customerId;
@@ -46,7 +48,7 @@
{
this.customerId = customerId;
}
-
+
public String getFirstName()
{
return firstName;
@@ -67,6 +69,7 @@
this.lastName = lastName;
}
+ @Temporal(TemporalType.DATE)
public Date getDateOfBirth()
{
return dateOfBirth;
@@ -77,7 +80,7 @@
this.dateOfBirth = dateOfBirth;
}
- public Gender getGender()
+/* public Gender getGender()
{
return gender;
}
@@ -85,5 +88,5 @@
public void setGender(Gender gender)
{
this.gender = gender;
- }
+ }*/
}
Modified: modules/remoting/trunk/examples/model/src/main/resources/META-INF/persistence.xml
===================================================================
--- modules/remoting/trunk/examples/model/src/main/resources/META-INF/persistence.xml 2009-12-09 10:49:22 UTC (rev 11803)
+++ modules/remoting/trunk/examples/model/src/main/resources/META-INF/persistence.xml 2009-12-10 10:55:30 UTC (rev 11804)
@@ -5,6 +5,7 @@
version="1.0">
<persistence-unit name="model">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
+ <class>org.jboss.seam.remoting.examples.model.Customer</class>
<jta-data-source>modelDatasource</jta-data-source>
<properties>
<property name="hibernate.hbm2ddl.auto" value="create-drop"/>
Modified: modules/remoting/trunk/examples/model/src/main/resources/import.sql
===================================================================
--- modules/remoting/trunk/examples/model/src/main/resources/import.sql 2009-12-09 10:49:22 UTC (rev 11803)
+++ modules/remoting/trunk/examples/model/src/main/resources/import.sql 2009-12-10 10:55:30 UTC (rev 11804)
@@ -1,3 +1,3 @@
-insert into customer (customerid, firstname, lastname, dateofbirth, gender) values (1, 'Shane', 'Bryzak', '19010101', 1);
+insert into customer (customerid, firstname, lastname, dateofbirth) values (1, 'Shane', 'Bryzak', '1901-01-01');
Modified: modules/remoting/trunk/examples/model/src/main/webapp/model.html
===================================================================
--- modules/remoting/trunk/examples/model/src/main/webapp/model.html 2009-12-09 10:49:22 UTC (rev 11803)
+++ modules/remoting/trunk/examples/model/src/main/webapp/model.html 2009-12-10 10:55:30 UTC (rev 11804)
@@ -18,6 +18,8 @@
<script type="text/javascript">
//<![CDATA[
+ Seam.Remoting.setDebug(true);
+
function loadCustomer() {
var customerId = document.getElementById("customerId").value;
15 years
Seam SVN: r11803 - branches/community/Seam_2_2/doc/Seam_Reference_Guide/en-US.
by seam-commits@lists.jboss.org
Author: jharting
Date: 2009-12-09 05:49:22 -0500 (Wed, 09 Dec 2009)
New Revision: 11803
Modified:
branches/community/Seam_2_2/doc/Seam_Reference_Guide/en-US/Author_Group.xml
branches/community/Seam_2_2/doc/Seam_Reference_Guide/en-US/Webservices.xml
Log:
Docs for ResourceHome and ResourceQuery.
Modified: branches/community/Seam_2_2/doc/Seam_Reference_Guide/en-US/Author_Group.xml
===================================================================
--- branches/community/Seam_2_2/doc/Seam_Reference_Guide/en-US/Author_Group.xml 2009-12-09 10:01:36 UTC (rev 11802)
+++ branches/community/Seam_2_2/doc/Seam_Reference_Guide/en-US/Author_Group.xml 2009-12-09 10:49:22 UTC (rev 11803)
@@ -71,6 +71,10 @@
<firstname>Marek</firstname>
<surname>Novotny</surname>
</author>
+ <author>
+ <firstname>Jozef</firstname>
+ <surname>Hartinger</surname>
+ </author>
<othercredit>
<firstname>James</firstname>
<surname>Cobb</surname>
Modified: branches/community/Seam_2_2/doc/Seam_Reference_Guide/en-US/Webservices.xml
===================================================================
--- branches/community/Seam_2_2/doc/Seam_Reference_Guide/en-US/Webservices.xml 2009-12-09 10:01:36 UTC (rev 11802)
+++ branches/community/Seam_2_2/doc/Seam_Reference_Guide/en-US/Webservices.xml 2009-12-09 10:49:22 UTC (rev 11803)
@@ -603,6 +603,207 @@
</sect2>
<sect2>
+ <title>Exposing entities via RESTful API</title>
+
+ <para>
+ Seam makes it really easy to use RESTful approach for accessing application data. One of the improvements that
+ Seam introduces is an ability to expose parts of your relational-database for remote use via plain HTTP calls.
+ For this purpose, Seam-RESTEasy integration module provides two components: <literal>ResourceHome</literal> and
+ <literal>ResourceQuery</literal>, which benefit from the API provided by the Seam Application Framework (<xref linkend="framework"/>)
+ and bind it to the REST API.
+ </para>
+
+ <sect3>
+
+ <title>ResourceQuery</title>
+
+ <para>
+ ResourceQuery allows querying capabilities to be exposed as a RESTful web service. By default, a simple
+ underlying Query component, which returns a list of instances of a given entity class, is created automatically.
+ Alternatively, the ResourceQuery component can be attached to an existing Query component in more sophisticated
+ cases. The following example demonstrates how easily ResourceQuery can be configured:
+ </para>
+
+ <programlisting role="XML"><![CDATA[<resteasy:resource-query path="/user" name="userResourceQuery"
+entity-class="com.example.User"/>]]></programlisting>
+
+ <para>
+ With this single XML element, a ResourceQuery component is set up. The configuration is straightforward:
+ </para>
+
+ <itemizedlist>
+ <listitem>
+ <para>
+ The component will return a list of <literal>com.example.User</literal> instances.
+ </para>
+ </listitem>
+ <listitem>
+ <para>
+ The component will listen on <literal>/user</literal> URI.
+ </para>
+ </listitem>
+ <listitem>
+ <para>
+ The component will by default marshall the result into XML or JSON (based on client's preference).
+ The set of supported mime types can be altered by using <literal>media-types</literal> attribute for example:
+ </para>
+
+ </listitem>
+ </itemizedlist>
+
+ <programlisting role="XML"><![CDATA[<resteasy:resource-query path="/user" name="userResourceQuery"
+entity-class="com.example.User" media-types="application/fastinfoset"/>]]></programlisting>
+
+ <para>
+ Alternatively, if you do not like configuring components using XML, you can set up the component by extension:
+ </para>
+
+ <programlisting role="JAVA"><![CDATA[@Name("userResourceQuery")
+@Path("user")
+public class UserResourceQuery extends ResourceQuery<User>
+{
+}]]></programlisting>
+
+ <para>
+ Since queries are read-only operations, the resource only responds to GET requests. Furthermore, ResourceQuery allows clients
+ of a web service to manipulate the result of a query using the following path parameters:
+ </para>
+
+ <informaltable>
+ <tgroup cols='3'>
+ <thead>
+ <row>
+ <entry>Parameter name</entry>
+ <entry>Example</entry>
+ <entry>Description</entry>
+ </row>
+ </thead>
+ <tbody>
+ <row>
+ <entry>start</entry>
+ <entry>/user?start=20</entry>
+ <entry>Returns a subset of a database query result starting with the 20th entry.</entry>
+ </row>
+ <row>
+ <entry>show</entry>
+ <entry>/user?show=10</entry>
+ <entry>Returns a subset of the database query result limited to 10 entries.</entry>
+ </row>
+ </tbody>
+ </tgroup>
+ </informaltable>
+
+ <para>
+ For example, you can send an HTTP GET request to <literal>/user?start=30&show=10</literal> to get a list of entries representing 10 rows starting with row 30.
+ </para>
+
+ <note>
+ <para>
+ RESTEasy uses JAXB to marshall entities. Thus, in order to be able to transfer them over the wire, you need to annotate entity classes with <literal>@XMLRootElement</literal>.
+ </para>
+ </note>
+
+ </sect3>
+
+ <sect3>
+
+ <title>ResourceHome</title>
+
+ <para>
+ Just as ResourceQuery makes Query's API available for remote access, so does ResourceHome for the Home component. The following table describes
+ how the two APIs (HTTP and Home) are bound together.
+ </para>
+
+ <table>
+ <tgroup cols='4'>
+ <thead>
+ <row>
+ <entry>HTTP method</entry>
+ <entry>Path</entry>
+ <entry>Function</entry>
+ <entry>ResourceHome method</entry>
+ </row>
+ </thead>
+ <tbody>
+ <row>
+ <entry>GET</entry>
+ <entry>{path}/{id}</entry>
+ <entry>Read</entry>
+ <entry>getResource()</entry>
+ </row>
+ <row>
+ <entry>POST</entry>
+ <entry>{path}</entry>
+ <entry>Create</entry>
+ <entry>postResource()</entry>
+ </row>
+ <row>
+ <entry>PUT</entry>
+ <entry>{path}/{id}</entry>
+ <entry>Update</entry>
+ <entry>putResource()</entry>
+ </row>
+ <row>
+ <entry>DELETE</entry>
+ <entry>{path}/{id}</entry>
+ <entry>Delete</entry>
+ <entry>deleteResource()</entry>
+ </row>
+ </tbody>
+ </tgroup>
+ </table>
+
+ <itemizedlist>
+ <listitem>
+ <para>
+ You can GET, PUT, and DELETE a particular user instance by sending HTTP requests to /user/{userId}
+ </para>
+ </listitem>
+ <listitem>
+ <para>
+ Sending a POST request to <literal>/user</literal> creates a new user entity instance and persists it. Usually, you leave it
+ up to the persistence layer to provide the entity instance with an identifier and thus an URI. Therefore, the URI
+ is sent back to the client in the <literal>Location</literal> header of the HTTP response.
+ </para>
+ </listitem>
+ </itemizedlist>
+
+ <para>
+ The configuration of ResourceHome is very similar to ResourceQuery except that you need to explicitly specify the underlying
+ Home component and a Java type of the entity identifier.
+ </para>
+
+ <programlisting role="XML"><![CDATA[<resteasy:resource-home path="/user" name="userResourceHome"
+entity-home="#{userHome}" entity-id-class="java.lang.Integer"/>]]></programlisting>
+
+ <para>Again, you can write a subclass of ResourceHome instead of writting any XML code.</para>
+
+ <programlisting role="JAVA"><![CDATA[@Name("userResourceHome")
+@Path("user")
+public class UserResourceHome extends ResourceHome<User, Integer>
+{
+
+ @In
+ private EntityHome<User> userHome;
+
+ @Override
+ public Home<?, User> getEntityHome()
+ {
+ return userHome;
+ }
+}]]></programlisting>
+
+ <para>
+ For more examples of how ResourceHome and ResourceQuery components can be used, take a look at the Seam Tasks sample application, which
+ demonstrates how Seam-RESTEasy integration can be used together with a jQuery client. In addition, you can find more code samples
+ in the Restbay example, which is used mainly for testing purposes.
+ </para>
+
+ </sect3>
+
+ </sect2>
+
+ <sect2>
<title>Testing resources and providers</title>
<para>
15 years
Seam SVN: r11802 - in branches/community/Seam_2_2/examples/tasks: view and 1 other directory.
by seam-commits@lists.jboss.org
Author: jharting
Date: 2009-12-09 05:01:36 -0500 (Wed, 09 Dec 2009)
New Revision: 11802
Modified:
branches/community/Seam_2_2/examples/tasks/src/main/org/jboss/seam/example/tasks/resource/ResolvedTaskResourceQuery.java
branches/community/Seam_2_2/examples/tasks/src/main/org/jboss/seam/example/tasks/resource/UserResourceHome.java
branches/community/Seam_2_2/examples/tasks/view/template.xhtml
Log:
minor
Modified: branches/community/Seam_2_2/examples/tasks/src/main/org/jboss/seam/example/tasks/resource/ResolvedTaskResourceQuery.java
===================================================================
--- branches/community/Seam_2_2/examples/tasks/src/main/org/jboss/seam/example/tasks/resource/ResolvedTaskResourceQuery.java 2009-12-09 09:40:45 UTC (rev 11801)
+++ branches/community/Seam_2_2/examples/tasks/src/main/org/jboss/seam/example/tasks/resource/ResolvedTaskResourceQuery.java 2009-12-09 10:01:36 UTC (rev 11802)
@@ -35,7 +35,6 @@
import org.jboss.resteasy.plugins.providers.atom.Feed;
import org.jboss.resteasy.plugins.providers.atom.Person;
import org.jboss.seam.annotations.Create;
-import org.jboss.seam.annotations.Factory;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.example.tasks.ResourceNotFoundException;
import org.jboss.seam.example.tasks.entity.Task;
@@ -69,7 +68,7 @@
{
super.create();
List<String> restrictions = new ArrayList<String>();
- restrictions.add("category.owner.username = #{username} AND resolved = true");
+ restrictions.add("category.owner.username = #{resolvedTaskResourceQuery.username} AND resolved = true");
getEntityQuery().setRestrictionExpressionStrings(restrictions);
getEntityQuery().setOrderColumn("updated");
getEntityQuery().setOrderDirection("desc");
@@ -103,7 +102,6 @@
return feed;
}
- @Factory("username")
public String getUsername()
{
return username;
Modified: branches/community/Seam_2_2/examples/tasks/src/main/org/jboss/seam/example/tasks/resource/UserResourceHome.java
===================================================================
--- branches/community/Seam_2_2/examples/tasks/src/main/org/jboss/seam/example/tasks/resource/UserResourceHome.java 2009-12-09 09:40:45 UTC (rev 11801)
+++ branches/community/Seam_2_2/examples/tasks/src/main/org/jboss/seam/example/tasks/resource/UserResourceHome.java 2009-12-09 10:01:36 UTC (rev 11802)
@@ -49,7 +49,7 @@
setMediaTypes(new String[] { "application/xml", "application/json", "application/fastinfoset" });
}
- @In()
+ @In
private EntityHome<User> userHome;
@Override
Modified: branches/community/Seam_2_2/examples/tasks/view/template.xhtml
===================================================================
--- branches/community/Seam_2_2/examples/tasks/view/template.xhtml 2009-12-09 09:40:45 UTC (rev 11801)
+++ branches/community/Seam_2_2/examples/tasks/view/template.xhtml 2009-12-09 10:01:36 UTC (rev 11802)
@@ -35,7 +35,7 @@
</div>
<div id="footer">
<hr/>
- <div>Powered by Seam 2.1, RESTEasy, Hibernate, Facelets and jQuery. Find more at <span><a href="http://seamframework.org">seamframework.org</a></span></div>
+ <div>Powered by Seam 2.2, RESTEasy, Hibernate, Facelets and jQuery. Find more at <span><a href="http://seamframework.org">seamframework.org</a></span></div>
</div>
</div>
</body>
15 years
Seam SVN: r11801 - in branches/community/Seam_2_2/examples/wiki: src/main/org/jboss/seam/wiki/core/dao and 1 other directories.
by seam-commits@lists.jboss.org
Author: christian.bauer(a)jboss.com
Date: 2009-12-09 04:40:45 -0500 (Wed, 09 Dec 2009)
New Revision: 11801
Modified:
branches/community/Seam_2_2/examples/wiki/src/main/org/jboss/seam/wiki/core/action/UserHome.java
branches/community/Seam_2_2/examples/wiki/src/main/org/jboss/seam/wiki/core/dao/UserDAO.java
branches/community/Seam_2_2/examples/wiki/view/userHome_d.xhtml
Log:
JBSEAM-4501, wiki registration protection
Modified: branches/community/Seam_2_2/examples/wiki/src/main/org/jboss/seam/wiki/core/action/UserHome.java
===================================================================
--- branches/community/Seam_2_2/examples/wiki/src/main/org/jboss/seam/wiki/core/action/UserHome.java 2009-12-09 08:55:44 UTC (rev 11800)
+++ branches/community/Seam_2_2/examples/wiki/src/main/org/jboss/seam/wiki/core/action/UserHome.java 2009-12-09 09:40:45 UTC (rev 11801)
@@ -72,6 +72,7 @@
private List<Role> roles;
private org.jboss.seam.wiki.core.model.Role defaultRole;
private Uploader uploader;
+ private Long createdWikiNodeCount;
private String requestedUsername;
private WikiTextEditor bioTextEditor;
private WikiTextEditor signatureTextEditor;
@@ -109,6 +110,8 @@
if (roles == null) roles = getInstance().getRoles();
if (oldUsername == null) oldUsername = getInstance().getUsername();
+ createdWikiNodeCount = userDAO.countNodesCreatedBy(getInstance().getId());
+
uploader = (Uploader)Component.getInstance(Uploader.class);
} else {
@@ -216,6 +219,7 @@
"Activiate account: /confirmRegistration.seam?activationCode=" + getInstance().getActivationCode());
*/
+ org.jboss.seam.core.Events.instance().raiseEvent("User.registered", getInstance());
org.jboss.seam.core.Events.instance().raiseEvent("User.persisted", getInstance());
}
return outcome;
@@ -226,12 +230,13 @@
@Restrict("#{s:hasPermission('User', 'edit', userHome.instance)}")
public String update() {
- if (!validateWikiTextEditors()) {
- return null;
+ if (isManaged() && getCreatedWikiNodeCount() != null && getCreatedWikiNodeCount() > 0) {
+ if (!validateWikiTextEditors()) {
+ return null;
+ }
+ syncWikiTextEditorsToInstance();
}
- syncWikiTextEditorsToInstance();
-
if (uploader.hasData()) {
uploader.uploadNewInstance();
if (WikiUploadImage.class.isAssignableFrom(uploader.getUpload().getClass())) {
@@ -508,6 +513,10 @@
return userDAO.findRatingPoints(getInstance().getId());
}
+ public Long getCreatedWikiNodeCount() {
+ return createdWikiNodeCount;
+ }
+
public WikiTextEditor getBioTextEditor() {
return bioTextEditor;
}
Modified: branches/community/Seam_2_2/examples/wiki/src/main/org/jboss/seam/wiki/core/dao/UserDAO.java
===================================================================
--- branches/community/Seam_2_2/examples/wiki/src/main/org/jboss/seam/wiki/core/dao/UserDAO.java 2009-12-09 08:55:44 UTC (rev 11800)
+++ branches/community/Seam_2_2/examples/wiki/src/main/org/jboss/seam/wiki/core/dao/UserDAO.java 2009-12-09 09:40:45 UTC (rev 11801)
@@ -100,6 +100,12 @@
return ratingPoints != null ? (Long)ratingPoints : 0;
}
+ public Long countNodesCreatedBy(Long userId) {
+ return (Long)entityManager.createQuery("select count(n) from WikiNode n where n.createdBy.id = :userId")
+ .setParameter("userId", userId)
+ .getSingleResult();
+ }
+
public void resetNodeCreatorToAdmin(User user) {
User adminUser = (User) Component.getInstance("adminUser");
@@ -149,7 +155,7 @@
if (orderByProperty != null)
crit.addOrder( orderDescending ? Order.desc(orderByProperty) : Order.asc(orderByProperty) );
- return crit.setResultTransformer(new DistinctRootEntityResultTransformer());
+ return crit.setResultTransformer(DistinctRootEntityResultTransformer.INSTANCE);
}
}
Modified: branches/community/Seam_2_2/examples/wiki/view/userHome_d.xhtml
===================================================================
--- branches/community/Seam_2_2/examples/wiki/view/userHome_d.xhtml 2009-12-09 08:55:44 UTC (rev 11800)
+++ branches/community/Seam_2_2/examples/wiki/view/userHome_d.xhtml 2009-12-09 09:40:45 UTC (rev 11801)
@@ -215,29 +215,31 @@
</s:span>
</s:div>
- <s:div styleClass="entry">
- <div class="label"><h:outputText value="#{messages['lacewiki.label.userHome.Bio']}:"/></div>
- <div class="output"> </div>
- </s:div>
- <ui:include src="includes/wikitext/editor/editor.xhtml">
- <ui:param name="textEditor" value="#{userHome.bioTextEditor}"/>
- <ui:param name="namingContainer" value="userHomeForm"/>
- <ui:param name="tabId" value="userProfileTab"/>
- </ui:include>
- <ui:include src="includes/wikitext/editor/preview.xhtml">
- <ui:param name="textEditor" value="#{userHome.bioTextEditor}"/>
- <ui:param name="baseDocument" value="#{wikiStart}"/>
- <ui:param name="baseDirectory" value="#{wikiStart.parent}"/>
- </ui:include>
+ <s:fragment rendered="#{userHome.createdWikiNodeCount > 0}">
+ <s:div styleClass="entry">
+ <div class="label"><h:outputText value="#{messages['lacewiki.label.userHome.Bio']}:"/></div>
+ <div class="output"> </div>
+ </s:div>
+ <ui:include src="includes/wikitext/editor/editor.xhtml">
+ <ui:param name="textEditor" value="#{userHome.bioTextEditor}"/>
+ <ui:param name="namingContainer" value="userHomeForm"/>
+ <ui:param name="tabId" value="userProfileTab"/>
+ </ui:include>
+ <ui:include src="includes/wikitext/editor/preview.xhtml">
+ <ui:param name="textEditor" value="#{userHome.bioTextEditor}"/>
+ <ui:param name="baseDocument" value="#{wikiStart}"/>
+ <ui:param name="baseDirectory" value="#{wikiStart.parent}"/>
+ </ui:include>
- <s:decorate id="websiteDecorate" template="includes/formFieldDecorate.xhtml">
- <ui:param name="tabId" value="userProfileTab"/>
- <ui:param name="fieldId" value="website"/>
- <ui:define name="label">#{messages['lacewiki.label.userHome.Website']}</ui:define>
- <h:inputText styleClass="ajaxSupport" tabindex="1" size="55" maxlength="1000" value="#{userHome.instance.profile.website}">
- <a:support status="globalStatus" event="onchange" reRender="websiteDecorate" oncomplete="onAjaxRequestComplete()"/>
- </h:inputText>
- </s:decorate>
+ <s:decorate id="websiteDecorate" template="includes/formFieldDecorate.xhtml">
+ <ui:param name="tabId" value="userProfileTab"/>
+ <ui:param name="fieldId" value="website"/>
+ <ui:define name="label">#{messages['lacewiki.label.userHome.Website']}</ui:define>
+ <h:inputText styleClass="ajaxSupport" tabindex="1" size="55" maxlength="1000" value="#{userHome.instance.profile.website}">
+ <a:support status="globalStatus" event="onchange" reRender="websiteDecorate" oncomplete="onAjaxRequestComplete()"/>
+ </h:inputText>
+ </s:decorate>
+ </s:fragment>
<s:decorate id="locationDecorate" template="includes/formFieldDecorate.xhtml">
<ui:param name="tabId" value="userProfileTab"/>
@@ -257,20 +259,22 @@
</h:inputText>
</s:decorate>
- <s:div styleClass="entry">
- <div class="label"><h:outputText value="#{messages['lacewiki.label.userHome.Signature']}:"/></div>
- <div class="output"> </div>
- </s:div>
- <ui:include src="includes/wikitext/editor/editor.xhtml">
- <ui:param name="textEditor" value="#{userHome.signatureTextEditor}"/>
- <ui:param name="namingContainer" value="userHomeForm"/>
- <ui:param name="tabId" value="userProfileTab"/>
- </ui:include>
- <ui:include src="includes/wikitext/editor/preview.xhtml">
- <ui:param name="textEditor" value="#{userHome.signatureTextEditor}"/>
- <ui:param name="baseDocument" value="#{wikiStart}"/>
- <ui:param name="baseDirectory" value="#{wikiStart.parent}"/>
- </ui:include>
+ <s:fragment rendered="#{userHome.createdWikiNodeCount > 0}">
+ <s:div styleClass="entry">
+ <div class="label"><h:outputText value="#{messages['lacewiki.label.userHome.Signature']}:"/></div>
+ <div class="output"> </div>
+ </s:div>
+ <ui:include src="includes/wikitext/editor/editor.xhtml">
+ <ui:param name="textEditor" value="#{userHome.signatureTextEditor}"/>
+ <ui:param name="namingContainer" value="userHomeForm"/>
+ <ui:param name="tabId" value="userProfileTab"/>
+ </ui:include>
+ <ui:include src="includes/wikitext/editor/preview.xhtml">
+ <ui:param name="textEditor" value="#{userHome.signatureTextEditor}"/>
+ <ui:param name="baseDocument" value="#{wikiStart}"/>
+ <ui:param name="baseDirectory" value="#{wikiStart.parent}"/>
+ </ui:include>
+ </s:fragment>
</s:validateAll>
</div>
15 years