Author: shane.bryzak(a)jboss.com
Date: 2009-12-30 05:42:54 -0500 (Wed, 30 Dec 2009)
New Revision: 11892
Modified:
modules/remoting/trunk/examples/model/src/main/webapp/model.html
modules/remoting/trunk/src/main/java/org/jboss/seam/remoting/Call.java
modules/remoting/trunk/src/main/java/org/jboss/seam/remoting/ExecutionHandler.java
modules/remoting/trunk/src/main/java/org/jboss/seam/remoting/MarshalUtils.java
modules/remoting/trunk/src/main/java/org/jboss/seam/remoting/RequestContext.java
modules/remoting/trunk/src/main/java/org/jboss/seam/remoting/RequestHandler.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:
rewrite call handling, removed support for batch requests
Modified: modules/remoting/trunk/examples/model/src/main/webapp/model.html
===================================================================
--- modules/remoting/trunk/examples/model/src/main/webapp/model.html 2009-12-29 09:13:05
UTC (rev 11891)
+++ modules/remoting/trunk/examples/model/src/main/webapp/model.html 2009-12-30 10:42:54
UTC (rev 11892)
@@ -11,7 +11,6 @@
<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[
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-29
09:13:05 UTC (rev 11891)
+++ modules/remoting/trunk/src/main/java/org/jboss/seam/remoting/Call.java 2009-12-30
10:42:54 UTC (rev 11892)
@@ -31,8 +31,6 @@
private BeanManager beanManager;
- private String id;
-
private String methodName;
private Throwable exception;
@@ -46,11 +44,9 @@
private Bean<?> targetBean = null;
- public Call(BeanManager beanManager, String id, String beanName,
- String qualifiers, String methodName)
+ public Call(BeanManager beanManager, String beanName, String qualifiers, String
methodName)
{
this.beanManager = beanManager;
- this.id = id;
this.methodName = methodName;
this.context = new CallContext(beanManager);
@@ -134,16 +130,6 @@
}
/**
- * Returns the id of this call.
- *
- * @return String
- */
- public String getId()
- {
- return id;
- }
-
- /**
* Returns the object graph constraints annotated on the method that is
* called.
*
Modified:
modules/remoting/trunk/src/main/java/org/jboss/seam/remoting/ExecutionHandler.java
===================================================================
---
modules/remoting/trunk/src/main/java/org/jboss/seam/remoting/ExecutionHandler.java 2009-12-29
09:13:05 UTC (rev 11891)
+++
modules/remoting/trunk/src/main/java/org/jboss/seam/remoting/ExecutionHandler.java 2009-12-30
10:42:54 UTC (rev 11892)
@@ -4,9 +4,7 @@
import java.io.IOException;
import java.io.OutputStream;
import java.io.StringReader;
-import java.util.ArrayList;
import java.util.Iterator;
-import java.util.List;
import javax.enterprise.context.Conversation;
import javax.enterprise.inject.spi.BeanManager;
@@ -76,19 +74,14 @@
}
// Extract the calls from the request
- List<Call> calls = unmarshalCalls(env);
+ Call call = unmarshalCall(env);
+ call.execute();
- // Execute each of the calls
- for (Call call : calls)
- {
- call.execute();
- }
-
// Store the conversation ID in the outgoing context
ctx.setConversationId(conversation.getId());
// Package up the response
- marshalResponse(calls, ctx, response.getOutputStream());
+ marshalResponse(call, ctx, response.getOutputStream());
}
/**
@@ -99,57 +92,49 @@
* @throws Exception
*/
@SuppressWarnings("unchecked")
- private List<Call> unmarshalCalls(Element env) throws Exception
+ private Call unmarshalCall(Element env) throws Exception
{
try
{
- List<Call> calls = new ArrayList<Call>();
+ Element callElement = env.element("body").element("call");
+
+ Element targetNode = callElement.element("target");
+ Element qualifiersNode = callElement.element("qualifiers");
+ Element methodNode = callElement.element("method");
+
+ Call call = new Call(beanManager, targetNode.getText(),
+ qualifiersNode != null ? qualifiersNode.getText() : null,
+ methodNode.getText());
- List<Element> callElements =
env.element("body").elements("call");
+ // First reconstruct all the references
+ Element refsNode = callElement.element("refs");
+
+ Iterator iter = refsNode.elementIterator("ref");
+ while (iter.hasNext())
+ {
+ call.getContext()
+ .createWrapperFromElement((Element) iter.next());
+ }
- for (Element e : callElements)
- {
- Element targetNode = e.element("target");
- Element qualifiersNode = e.element("qualifiers");
- Element methodNode = e.element("method");
-
- Call call = new Call(beanManager, e.attributeValue("id"),
- targetNode.getText(),
- qualifiersNode != null ? qualifiersNode.getText() : null,
- methodNode.getText());
+ // Now unmarshal the ref values
+ for (Wrapper w : call.getContext().getInRefs().values())
+ {
+ w.unmarshal();
+ }
- // First reconstruct all the references
- Element refsNode = e.element("refs");
-
- Iterator iter = refsNode.elementIterator("ref");
- while (iter.hasNext())
- {
- call.getContext()
- .createWrapperFromElement((Element) iter.next());
- }
+ Element paramsNode = callElement.element("params");
- // Now unmarshal the ref values
- for (Wrapper w : call.getContext().getInRefs().values())
- {
- w.unmarshal();
- }
+ // Then process the param values
+ iter = paramsNode.elementIterator("param");
+ while (iter.hasNext())
+ {
+ Element param = (Element) iter.next();
- Element paramsNode = e.element("params");
-
- // Then process the param values
- iter = paramsNode.elementIterator("param");
- while (iter.hasNext())
- {
- Element param = (Element) iter.next();
-
- call.addParameter(call.getContext().createWrapperFromElement(
- (Element) param.elementIterator().next()));
- }
-
- calls.add(call);
+ call.addParameter(call.getContext().createWrapperFromElement(
+ (Element) param.elementIterator().next()));
}
- return calls;
+ return call;
}
catch (Exception ex)
{
@@ -167,29 +152,27 @@
* OutputStream The stream to write to
* @throws IOException
*/
- private void marshalResponse(List<Call> calls, RequestContext ctx,
- OutputStream out) throws IOException
+ private void marshalResponse(Call call, RequestContext ctx, OutputStream out)
+ throws IOException
{
out.write(ENVELOPE_TAG_OPEN);
-
+ out.write(HEADER_OPEN);
+ out.write(CONTEXT_TAG_OPEN);
if (ctx.getConversationId() != null)
{
- out.write(HEADER_OPEN);
- out.write(CONTEXT_TAG_OPEN);
out.write(CONVERSATION_ID_TAG_OPEN);
out.write(ctx.getConversationId().getBytes());
out.write(CONVERSATION_ID_TAG_CLOSE);
- out.write(CONTEXT_TAG_CLOSE);
- out.write(HEADER_CLOSE);
}
+ out.write(CALL_ID_TAG_OPEN);
+ out.write(ctx.getCallId().toString().getBytes());
+ out.write(CALL_ID_TAG_CLOSE);
+ out.write(CONTEXT_TAG_CLOSE);
+ out.write(HEADER_CLOSE);
out.write(BODY_TAG_OPEN);
+ MarshalUtils.marshalCallResult(call, out);
- for (Call call : calls)
- {
- MarshalUtils.marshalCallResult(call, out);
- }
-
out.write(BODY_TAG_CLOSE);
out.write(ENVELOPE_TAG_CLOSE);
out.flush();
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-29
09:13:05 UTC (rev 11891)
+++
modules/remoting/trunk/src/main/java/org/jboss/seam/remoting/MarshalUtils.java 2009-12-30
10:42:54 UTC (rev 11892)
@@ -15,8 +15,6 @@
*/
public class MarshalUtils
{
- private static final byte[] RESULT_TAG_OPEN_START = "<result
id=\"".getBytes();
- private static final byte[] RESULT_TAG_OPEN_END = "\">".getBytes();
private static final byte[] RESULT_TAG_OPEN = "<result>".getBytes();
private static final byte[] RESULT_TAG_CLOSE =
"</result>".getBytes();
@@ -40,16 +38,7 @@
public static void marshalCallResult(Call call, OutputStream out)
throws IOException
{
- if (call.getId() != null)
- {
- out.write(RESULT_TAG_OPEN_START);
- out.write(call.getId().getBytes());
- out.write(RESULT_TAG_OPEN_END);
- }
- else
- {
- out.write(RESULT_TAG_OPEN);
- }
+ out.write(RESULT_TAG_OPEN);
if (call.getException() != null)
{
@@ -84,14 +73,7 @@
throws IOException
{
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.getId().getBytes());
out.write(MODEL_TAG_OPEN_END);
for (String alias : model.getBeanProperties().keySet())
Modified:
modules/remoting/trunk/src/main/java/org/jboss/seam/remoting/RequestContext.java
===================================================================
---
modules/remoting/trunk/src/main/java/org/jboss/seam/remoting/RequestContext.java 2009-12-29
09:13:05 UTC (rev 11891)
+++
modules/remoting/trunk/src/main/java/org/jboss/seam/remoting/RequestContext.java 2009-12-30
10:42:54 UTC (rev 11892)
@@ -20,11 +20,17 @@
{
setConversationId(convId.getText());
}
+ Element callId = context.element("callId");
+ if (callId != null)
+ {
+ setCallId(Long.valueOf(callId.getText()));
+ }
}
}
}
private String conversationId;
+ private Long callId;
public String getConversationId()
{
@@ -35,4 +41,14 @@
{
this.conversationId = conversationId;
}
+
+ public Long getCallId()
+ {
+ return callId;
+ }
+
+ public void setCallId(Long callId)
+ {
+ this.callId = callId;
+ }
}
Modified:
modules/remoting/trunk/src/main/java/org/jboss/seam/remoting/RequestHandler.java
===================================================================
---
modules/remoting/trunk/src/main/java/org/jboss/seam/remoting/RequestHandler.java 2009-12-29
09:13:05 UTC (rev 11891)
+++
modules/remoting/trunk/src/main/java/org/jboss/seam/remoting/RequestHandler.java 2009-12-30
10:42:54 UTC (rev 11892)
@@ -18,15 +18,12 @@
static final byte[] REF_TAG_OPEN_START = "<ref id=\"".getBytes();
static final byte[] REF_TAG_OPEN_END = "\">".getBytes();
static final byte[] REF_TAG_CLOSE = "</ref>".getBytes();
-
-
static final byte[] HEADER_OPEN = "<header>".getBytes();
static final byte[] HEADER_CLOSE = "</header>".getBytes();
- static final byte[] CONVERSATION_ID_TAG_OPEN = "<conversationId>"
- .getBytes();
- static final byte[] CONVERSATION_ID_TAG_CLOSE = "</conversationId>"
- .getBytes();
-
+ static final byte[] CONVERSATION_ID_TAG_OPEN =
"<conversationId>".getBytes();
+ static final byte[] CONVERSATION_ID_TAG_CLOSE =
"</conversationId>".getBytes();
+ static final byte[] CALL_ID_TAG_OPEN = "<callId>".getBytes();
+ static final byte[] CALL_ID_TAG_CLOSE = "</callId>".getBytes();
static final byte[] CONTEXT_TAG_OPEN = "<context>".getBytes();
static final byte[] CONTEXT_TAG_CLOSE = "</context>".getBytes();
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-29
09:13:05 UTC (rev 11891)
+++
modules/remoting/trunk/src/main/java/org/jboss/seam/remoting/model/Model.java 2009-12-30
10:42:54 UTC (rev 11892)
@@ -31,7 +31,6 @@
private BeanManager beanManager;
private String id;
- private String callId;
private CallContext callContext;
private Call action;
@@ -121,17 +120,7 @@
callContext = new CallContext(beanManager);
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-29
09:13:05 UTC (rev 11891)
+++
modules/remoting/trunk/src/main/java/org/jboss/seam/remoting/model/ModelHandler.java 2009-12-30
10:42:54 UTC (rev 11892)
@@ -93,15 +93,14 @@
for (Element modelElement : (List<Element>)
env.element("body").elements("model"))
{
String operation = modelElement.attributeValue("operation");
- String callId = modelElement.attributeValue("callId");
if ("fetch".equals(operation))
{
- processFetchRequest(modelElement, models, callId);
+ processFetchRequest(modelElement, models);
}
else if ("apply".equals(operation))
{
- processApplyRequest(modelElement, models, callId);
+ processApplyRequest(modelElement, models);
}
}
@@ -140,16 +139,15 @@
}
@SuppressWarnings({ "unchecked" })
- private void processFetchRequest(Element modelElement, Set<Model> models, String
callId)
+ private void processFetchRequest(Element modelElement, Set<Model> models)
throws Exception
{
Model model = registry.createModel();
- models.add(model);
- model.setCallId(callId);
+ models.add(model);
if (modelElement.elements("action").size() > 0)
{
- unmarshalAction(modelElement.element("action"), model, callId);
+ unmarshalAction(modelElement.element("action"), model);
}
for (Element beanElement : (List<Element>)
modelElement.elements("bean"))
@@ -177,7 +175,7 @@
}
@SuppressWarnings("unchecked")
- private void unmarshalAction(Element actionElement, Model model, String callId)
+ private void unmarshalAction(Element actionElement, Model model)
{
Element targetElement = actionElement.element("target");
Element qualifiersElement = actionElement.element("qualifiers");
@@ -185,7 +183,7 @@
Element paramsElement = actionElement.element("params");
Element refsElement = actionElement.element("refs");
- model.setAction(new Call(beanManager, callId, targetElement.getTextTrim(),
+ model.setAction(new Call(beanManager, targetElement.getTextTrim(),
qualifiersElement != null ? qualifiersElement.getTextTrim() : null,
methodElement != null ? methodElement.getTextTrim() : null));
@@ -213,12 +211,11 @@
}
@SuppressWarnings("unchecked")
- private void processApplyRequest(Element modelElement, Set<Model> models, String
callId)
+ private void processApplyRequest(Element modelElement, Set<Model> models)
throws Exception
{
Model model = registry.getModel(modelElement.attributeValue("uid"));
models.add(model);
- model.setCallId(callId);
model.setAction(null);
CallContext ctx = new CallContext(beanManager);
@@ -253,7 +250,7 @@
if (modelElement.elements("action").size() > 0)
{
- unmarshalAction(modelElement.element("action"), model, callId);
+ unmarshalAction(modelElement.element("action"), model);
}
if (model.getAction() != null)
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-29
09:13:05 UTC (rev 11891)
+++ modules/remoting/trunk/src/main/resources/org/jboss/seam/remoting/remote.js 2009-12-30
10:42:54 UTC (rev 11892)
@@ -70,14 +70,40 @@
var names = [];
var cb = null;
for (var i=0; i<arguments.length; i++) {
- if (typeof arguments[i] != "function")
- names.push(arguments[i]);
- else
- cb = arguments[i];
+ if (typeof arguments[i] != "function") {
+ if (arguments[i] instanceof Array) {
+ for (var j=0; j<arguments[i].length; j++) {
+ names.push(arguments[i][j]);
+ }
+ } else {
+ names.push(arguments[i]);
+ }
+ } else {
+ cb = arguments[i];
+ }
}
var n = "org.jboss.seam.remoting.BeanMetadata";
if (!Seam.isBeanRegistered(n)) Seam.registerBean(n, {name: "str", methods:
"Seam.Map", properties: "Seam.Map"});
- Seam.execute("org.jboss.seam.remoting.MetadataCache", "loadBeans",
[names], cb);
+ var callback = function(beans) {
+ for (var i=0; i<beans.length; i++) {
+ var meta = beans[i];
+ if (meta.beanType == "state") {
+ var props = {};
+ for (var j=0;j<meta.properties.elements.length; j++) {
+ props[meta.properties.elements[j].key] = meta.properties.elements[j].value;
+ }
+ Seam.registerBean(meta.name, props);
+ } else if (meta.beanType == "action") {
+ var methods = {};
+ for (var j=0; j<meta.methods.elements.length; j++) {
+ methods[meta.methods.elements[j].key] = meta.methods.elements[j].value;
+ }
+ Seam.registerBean(meta.name, null, methods);
+ }
+ }
+ if (cb) cb();
+ }
+ Seam.execute("org.jboss.seam.remoting.MetadataCache", "loadBeans",
[names], callback);
}
Seam.getBeanMetadata = function(obj) {
@@ -129,13 +155,11 @@
Seam.Context = function() {
this.conversationId = null;
- Seam.Context.prototype.setConversationId = function(conversationId) {
- this.conversationId = conversationId;
- }
-
- Seam.Context.prototype.getConversationId = function() {
- return this.conversationId;
- }
+ this.callId = null;
+ Seam.Context.prototype.setConversationId = function(conversationId) {
this.conversationId = conversationId; }
+ Seam.Context.prototype.getConversationId = function() { return this.conversationId; }
+ Seam.Context.prototype.setCallId = function(callId) { this.callId = callId; }
+ Seam.Context.prototype.getCallId = function() { return this.callId; }
}
Seam.context = new Seam.Context();
@@ -301,8 +325,7 @@
Seam.createCall = function(component, methodName, params, callback, exceptionHandler) {
var callId = "" + Seam.__callId++;
if (!callback) callback = component.__callback[methodName];
- var d = "<call id=\"" + callId + "\">\n" +
- "<target>" + Seam.getBeanType(component).__name +
"</target>";
+ var d = "<call><target>" + Seam.getBeanType(component).__name +
"</target>";
if (component.__qualifiers != null) {
d += "<qualifiers>";
for (var i=0; i<component.__qualifiers.length; i++) {
@@ -311,7 +334,7 @@
}
d += "</qualifiers>";
}
- d += "<method>" + methodName + "</method>" +
"<params>";
+ d += "<method>" + methodName +
"</method><params>";
var refs = [];
for (var i=0; i<params.length; i++) {
d += "<param>" + Seam.serializeValue(params[i], null, refs) +
"</param>";
@@ -321,11 +344,11 @@
d += "<ref id=\"" + i + "\">" +
Seam.serializeType(refs[i], refs) + "</ref>";
}
d += "</refs></call>";
- return {data: d, id: callId, callback: callback, exceptionHandler: exceptionHandler};
+ return {data: d, id: callId, callback: callback, exceptionHandler: exceptionHandler,
handler: Seam.preProcessCallResponse};
}
-Seam.createHeader = function() {
- var h = "<context>";
+Seam.createHeader = function(callId) {
+ var h = "<context><callId>" + callId +
"</callId>";
if (Seam.context.getConversationId()) {
h += "<conversationId>" + Seam.context.getConversationId() +
"</conversationId>";
}
@@ -343,34 +366,7 @@
Seam.__callId = 0;
Seam.pendingCalls = new Seam.Map();
-Seam.inBatch = false;
-Seam.batchedCalls = [];
-Seam.startBatch = function() {
- Seam.inBatch = true;
- Seam.batchedCalls.length = 0;
-}
-
-Seam.executeBatch = function() {
- if (!Seam.inBatch) return;
- var d = "";
- 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.createEnvelope(Seam.createHeader(), d);
- Seam.batchAsyncReq = Seam.sendAjaxRequest(envelope, Seam.PATH_EXECUTE,
- Seam.processResponse, false);
- Seam.inBatch = false;
-}
-
-Seam.cancelBatch = function() {
- Seam.inBatch = false;
- for (var i=0; i<Seam.batchedCalls.length; i++) {
- Seam.pendingCalls.remove(Seam.batchedCalls[i].id);
- }
-}
-
Seam.cancelCall = function(callId) {
var c = Seam.pendingCalls.get(callId);
Seam.pendingCalls.remove(callId);
@@ -386,9 +382,9 @@
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;
+ Seam.batchedCalls.push(c);
} else {
- var envelope = Seam.createEnvelope(Seam.createHeader(), c.data);
+ var envelope = Seam.createEnvelope(Seam.createHeader(c.id), c.data);
Seam.pendingCalls.put(c.id, c);
Seam.sendAjaxRequest(envelope, Seam.PATH_EXECUTE, Seam.processResponse, false);
}
@@ -405,7 +401,6 @@
} else {
r = new ActiveXObject("Microsoft.XMLHTTP");
}
-
r.onreadystatechange = function() {
if (r.readyState == 4) {
var inScope = typeof(Seam) == "undefined" ? false : true;
@@ -452,6 +447,54 @@
r.send(env);
}
+Seam.preProcessCallResponse = function(call) {
+ var cn = Seam.Xml.childNode;
+ var bodyNode = cn(call.response.documentElement, "body");
+ if (bodyNode) {
+ var n = cn(bodyNode, "result");
+ if (n) {
+ var refsNode = cn(n, "refs");
+ var u = Seam.validateRefs(refsNode, call);
+ if (u.length > 0) {
+ // todo load the unknown types
+ } else {
+ Seam.processCallResponse(call);
+ }
+ }
+ }
+}
+
+Seam.processCallResponse = function(call) {
+ var cn = Seam.Xml.childNode;
+ Seam.pendingCalls.remove(call.callId);
+ var n = cn(cn(call.response.documentElement, "body"), "result");
+ var valueNode = cn(n, "value");
+ var exceptionNode = cn(n, "exception");
+ if (exceptionNode != null && call.exceptionHandler != null) {
+ var msgNode = cn(exceptionNode, "message");
+ var msg = Seam.unmarshalValue(msgNode.firstChild);
+ call.exceptionHandler(new Seam.Exception(msg));
+ } else if (call.callback != null) {
+ var refsNode = cn(n, "refs");
+ var refs = Seam.unmarshalRefs(refsNode);
+ var v = Seam.unmarshalValue(valueNode.firstChild, refs);
+ call.callback(v, call.context);
+ }
+}
+
+Seam.preProcessModelResponse = function(call) {
+ var bodyNode = cn(doc.documentElement, "body");
+ if (bodyNode) {
+ var n = Seam.Xml.childNodes(bodyNode, "model");
+ for (var i=0; i<n.length; i++) {
+ var callId = n[i].getAttribute("callId");
+ var call = Seam.pendingCalls.get(callId);
+ Seam.pendingCalls.remove(callId);
+ if (call.model) call.model.processResponse(n[i]);
+ }
+ }
+}
+
Seam.displayError = function(code) {
alert("There was an error processing your request. Error code: " + code);
}
@@ -466,50 +509,49 @@
if (!doc.documentElement) return;
var ctx = new Seam.Context;
var headerNode = cn(doc.documentElement, "header");
- var bodyNode = cn(doc.documentElement, "body");
if (headerNode) {
var contextNode = cn(headerNode, "context");
if (contextNode) {
Seam.unmarshalContext(contextNode, ctx);
- }
- }
- Seam.context.setConversationId(ctx.getConversationId() ? ctx.getConversationId() :
null);
- if (bodyNode) {
- var n = cn(bodyNode, "result");
- if (n) {
- var callId = n.getAttribute("id");
- var call = Seam.pendingCalls.get(callId);
- Seam.pendingCalls.remove(callId);
- if (call && (call.callback || call.exceptionHandler)) {
- var valueNode = cn(n, "value");
- var refsNode = cn(n, "refs");
- var exceptionNode = cn(n, "exception");
- if (exceptionNode != null) {
- var msgNode = cn(exceptionNode, "message");
- var msg = Seam.unmarshalValue(msgNode.firstChild);
- call.exceptionHandler(new Seam.Exception(msg));
- } else {
- var refs = Seam.unmarshalRefs(refsNode);
- var v = Seam.unmarshalValue(valueNode.firstChild, refs);
- call.callback(v, ctx, callId);
- }
+ var call = Seam.pendingCalls.get(ctx.getCallId());
+ Seam.context.setConversationId(ctx.getConversationId() ? ctx.getConversationId() :
null);
+ if (call) {
+ call.context = ctx;
+ call.response = doc;
+ if (call.handler) call.handler(call);
}
}
- var n = Seam.Xml.childNodes(bodyNode, "model");
- for (var i=0; i<n.length; i++) {
- var callId = n[i].getAttribute("callId");
- var call = Seam.pendingCalls.get(callId);
- Seam.pendingCalls.remove(callId);
- if (call.model) call.model.processResponse(n[i]);
- }
}
}
+Seam.processLoadTypes = function(callId) {
+ var call = Seam.pendingCalls.get(callId);
+ if (call) {
+ Seam.pendingCalls.remove(callId);
+ if (call.model) call.model.processResponse(call.model.modelNode, true);
+ }
+}
+
Seam.unmarshalContext = function(ctxNode, context) {
var c = Seam.Xml.childNode(ctxNode, "conversationId");
if (c) context.setConversationId(c.firstChild.nodeValue);
+ c = Seam.Xml.childNode(ctxNode, "callId");
+ if (c) context.setCallId(c.firstChild.nodeValue);
}
+Seam.validateRefs = function(refsNode) {
+ var unknowns = [];
+ var cn = Seam.Xml.childNodes(refsNode, "ref");
+ for (var i=0; i<cn.length; i++) {
+ var n = cn[i].firstChild;
+ if (n.tagName == "bean") {
+ var name = n.getAttribute("type");
+ if (!Seam.isBeanRegistered(name)) unknowns.push(name);
+ }
+ }
+ return unknowns;
+}
+
Seam.unmarshalRefs = function(refsNode) {
if (!refsNode) return;
var refs = [];
@@ -826,7 +868,7 @@
Seam.Model.prototype.fetch = function(action, callback) {
this.callback = callback;
var r = this.createFetchRequest(action);
- var env = Seam.createEnvelope(Seam.createHeader(), r.data);
+ var env = Seam.createEnvelope(Seam.createHeader(r.id), r.data);
Seam.pendingCalls.put(r.id, r);
Seam.sendAjaxRequest(env, Seam.PATH_MODEL, Seam.processResponse, false);
}
@@ -882,19 +924,18 @@
}
}
d += "</model>";
- return {data:d, id:callId, model:this};
+ return {data:d, id:callId, model:this, handler: null};
}
Seam.Model.prototype.processResponse = function(modelNode) {
+ var refsNode = Seam.Xml.childNode(modelNode, "refs");
this.id = modelNode.getAttribute("uid");
- var valueNodes = Seam.Xml.childNodes(modelNode, "value");
- var refsNode = Seam.Xml.childNode(modelNode, "refs");
+ var valueNodes = Seam.Xml.childNodes(modelNode, "value");
this.sourceRefs = Seam.unmarshalRefs(refsNode);
this.workingRefs = Seam.cloneObject(this.sourceRefs);
for (var i=0; i<valueNodes.length; i++) {
var value = Seam.unmarshalValue(valueNodes[i].firstChild,this.workingRefs);
this.values.push({alias:valueNodes[i].getAttribute("alias"),value:value,
refIndex:i});
-
}
if (this.callback) this.callback(this);
}
@@ -905,7 +946,7 @@
d.scanForChanges(this.values[i].value);
}
var r = this.createApplyRequest(a, d);
- var env = Seam.createEnvelope(Seam.createHeader(), r.data);
+ var env = Seam.createEnvelope(Seam.createHeader(r.id), r.data);
Seam.pendingCalls.put(r.id, r);
Seam.sendAjaxRequest(env, Seam.PATH_MODEL, Seam.processResponse, false);
}
@@ -963,7 +1004,7 @@
d += "</refs>";
}
d += "</model>";
- return {data:d, id:callId, model:this};
+ return {data:d, id:callId, model:this, handler: null};
}
Seam.Model.prototype.getRefId = function(v) {