[seam-commits] Seam SVN: r11898 - in modules/remoting/trunk/src/main/java/org/jboss/seam/remoting: model and 1 other directories.
seam-commits at lists.jboss.org
seam-commits at lists.jboss.org
Sun Jan 3 02:58:56 EST 2010
Author: shane.bryzak at jboss.com
Date: 2010-01-03 02:58:56 -0500 (Sun, 03 Jan 2010)
New Revision: 11898
Modified:
modules/remoting/trunk/src/main/java/org/jboss/seam/remoting/MarshalUtils.java
modules/remoting/trunk/src/main/java/org/jboss/seam/remoting/model/ModelHandler.java
modules/remoting/trunk/src/main/java/org/jboss/seam/remoting/wrapper/BagWrapper.java
Log:
added handler for model expand requests
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 2010-01-02 11:04:40 UTC (rev 11897)
+++ modules/remoting/trunk/src/main/java/org/jboss/seam/remoting/MarshalUtils.java 2010-01-03 07:58:56 UTC (rev 11898)
@@ -95,6 +95,53 @@
out.write(MODEL_TAG_CLOSE);
}
+ public static void marshalModelExpand(Model model, Wrapper value,
+ OutputStream out, int newRefIdx)
+ throws IOException
+ {
+ out.write(MODEL_TAG_OPEN_START);
+ out.write(model.getId().getBytes());
+ out.write(MODEL_TAG_OPEN_END);
+
+ out.write(RESULT_TAG_OPEN);
+ value.marshal(out);
+ out.write(RESULT_TAG_CLOSE);
+
+ if (model.getCallContext().getOutRefs().size() > newRefIdx)
+ {
+ out.write(RequestHandler.REFS_TAG_OPEN);
+ marshalNewRefs(model.getCallContext().getOutRefs(), newRefIdx, null, out);
+ out.write(RequestHandler.REFS_TAG_CLOSE);
+ }
+
+ out.write(MODEL_TAG_CLOSE);
+ }
+
+ public static void marshalNewRefs(List<Wrapper> refs, int startIdx,
+ List<String> constraints, OutputStream out)
+ throws IOException
+ {
+ for (int i = startIdx; i < refs.size(); i++)
+ {
+ Wrapper wrapper = refs.get(i);
+
+ out.write(RequestHandler.REF_TAG_OPEN_START);
+ out.write(Integer.toString(i).getBytes());
+ out.write(RequestHandler.REF_TAG_OPEN_END);
+
+ if (wrapper instanceof BeanWrapper && constraints != null)
+ {
+ ((BeanWrapper) wrapper).serialize(out, constraints);
+ }
+ else
+ {
+ wrapper.serialize(out);
+ }
+
+ out.write(RequestHandler.REF_TAG_CLOSE);
+ }
+ }
+
public static void marshalRefs(List<Wrapper> refs, List<String> constraints,
OutputStream out)
throws IOException
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 2010-01-02 11:04:40 UTC (rev 11897)
+++ modules/remoting/trunk/src/main/java/org/jboss/seam/remoting/model/ModelHandler.java 2010-01-03 07:58:56 UTC (rev 11898)
@@ -6,7 +6,6 @@
import java.io.StringReader;
import java.lang.reflect.Array;
import java.lang.reflect.Type;
-import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -95,34 +94,40 @@
Element modelElement = env.element("body").element("model");
String operation = modelElement.attributeValue("operation");
-
- Model model = null;
- if ("fetch".equals(operation))
+ if ("expand".equals(operation))
{
- model = processFetchRequest(modelElement);
+ processExpandRequest(modelElement, ctx, response.getOutputStream());
}
- else if ("apply".equals(operation))
+ else
{
- model = processApplyRequest(modelElement);
+ Model model = null;
+ if ("fetch".equals(operation))
+ {
+ model = processFetchRequest(modelElement);
+ }
+ else if ("apply".equals(operation))
+ {
+ model = processApplyRequest(modelElement);
+ }
+
+ if (model.getAction() != null && model.getAction().getException() != null)
+ {
+ response.getOutputStream().write(ENVELOPE_TAG_OPEN);
+ response.getOutputStream().write(BODY_TAG_OPEN);
+ MarshalUtils.marshalException(model.getAction().getException(),
+ model.getAction().getContext(), response.getOutputStream());
+ response.getOutputStream().write(BODY_TAG_CLOSE);
+ response.getOutputStream().write(ENVELOPE_TAG_CLOSE);
+ response.getOutputStream().flush();
+ return;
+ }
+
+ model.evaluate();
+
+ ctx.setConversationId(conversation.isTransient() ? null : conversation.getId());
+ marshalResponse(model, ctx, response.getOutputStream());
}
-
- if (model.getAction() != null && model.getAction().getException() != null)
- {
- response.getOutputStream().write(ENVELOPE_TAG_OPEN);
- response.getOutputStream().write(BODY_TAG_OPEN);
- MarshalUtils.marshalException(model.getAction().getException(),
- model.getAction().getContext(), response.getOutputStream());
- response.getOutputStream().write(BODY_TAG_CLOSE);
- response.getOutputStream().write(ENVELOPE_TAG_CLOSE);
- response.getOutputStream().flush();
- return;
- }
-
- model.evaluate();
-
- ctx.setConversationId(conversation.isTransient() ? null : conversation.getId());
- marshalResponse(model, ctx, response.getOutputStream());
}
finally
{
@@ -322,6 +327,57 @@
return model;
}
+ private void processExpandRequest(Element modelElement, RequestContext ctx, OutputStream out)
+ throws Exception
+ {
+ Model model = registry.getModel(modelElement.attributeValue("id"));
+ model.setAction(null);
+
+ Element refElement = modelElement.element("ref");
+ if (refElement == null)
+ {
+ throw new IllegalStateException("Invalid request state - no object ref found");
+ }
+
+ int refId = Integer.parseInt(refElement.attributeValue("refid"));
+ Wrapper target = model.getCallContext().getOutRefs().get(refId);
+
+ int newRefIdx = model.getCallContext().getOutRefs().size();
+
+ Element memberElement = refElement.element("member");
+ String memberName = memberElement.attributeValue("name");
+
+ Wrapper value = ((BeanWrapper) target).getBeanProperty(memberName);
+ if (value instanceof BagWrapper)
+ {
+ ((BagWrapper) value).setLoadLazy(true);
+ }
+
+ out.write(ENVELOPE_TAG_OPEN);
+
+ out.write(HEADER_OPEN);
+ out.write(CONTEXT_TAG_OPEN);
+ if (ctx.getConversationId() != null)
+ {
+ out.write(CONVERSATION_ID_TAG_OPEN);
+ out.write(ctx.getConversationId().getBytes());
+ out.write(CONVERSATION_ID_TAG_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.marshalModelExpand(model, value, out, newRefIdx);
+
+ out.write(BODY_TAG_CLOSE);
+ out.write(ENVELOPE_TAG_CLOSE);
+ out.flush();
+ }
+
/**
* Clones the contents of the specified source bag into the specified target
* bag. If the contents can be cloned, this method returns true, otherwise it
Modified: modules/remoting/trunk/src/main/java/org/jboss/seam/remoting/wrapper/BagWrapper.java
===================================================================
--- modules/remoting/trunk/src/main/java/org/jboss/seam/remoting/wrapper/BagWrapper.java 2010-01-02 11:04:40 UTC (rev 11897)
+++ modules/remoting/trunk/src/main/java/org/jboss/seam/remoting/wrapper/BagWrapper.java 2010-01-03 07:58:56 UTC (rev 11898)
@@ -35,6 +35,13 @@
private static final byte[] ELEMENT_TAG_OPEN = "<element>".getBytes();
private static final byte[] ELEMENT_TAG_CLOSE = "</element>".getBytes();
+
+ private boolean loadLazy = false;
+
+ public void setLoadLazy(boolean loadLazy)
+ {
+ this.loadLazy = loadLazy;
+ }
@SuppressWarnings("unchecked")
public void marshal(OutputStream out) throws IOException
@@ -42,7 +49,7 @@
out.write(BAG_TAG_OPEN);
// Fix to prevent uninitialized lazy loading in Hibernate
- if (value instanceof PersistentCollection)
+ if (value instanceof PersistentCollection && !loadLazy)
{
if (!((PersistentCollection) value).wasInitialized())
{
More information about the seam-commits
mailing list