01: /*
02: * Copyright 2005 Joe Walker
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16: package org.directwebremoting.dwrp;
17:
18: import org.directwebremoting.extend.OutboundContext;
19: import org.directwebremoting.extend.OutboundVariable;
20:
21: /**
22: * An OutboundVariable that creates data from Collections.
23: * @author Joe Walker [joe at getahead dot ltd dot uk]
24: */
25: public class ArrayNonJsonOutboundVariable extends
26: NonJsonNestedOutboundVariable implements
27: CollectionOutboundVariable {
28: /**
29: * Setup
30: * @param outboundContext A collection of objects already converted and the results
31: */
32: public ArrayNonJsonOutboundVariable(OutboundContext outboundContext) {
33: super (outboundContext);
34: }
35:
36: /* (non-Javadoc)
37: * @see org.directwebremoting.extend.OutboundVariable#prepareAssignCode()
38: */
39: public void prepareAssignCode() {
40: if (isOutline()) {
41: setAssignCode(getVariableName());
42: } else {
43: prepareChildAssignCodes();
44: setAssignCode(ArrayJsonOutboundVariable
45: .createJsonString(children));
46: }
47: }
48:
49: /* (non-Javadoc)
50: * @see org.directwebremoting.extend.OutboundVariable#prepareBuildDeclareCodes()
51: */
52: public void prepareBuildDeclareCodes() {
53: if (isOutline()) {
54: StringBuffer buffer = new StringBuffer();
55:
56: int i = 0;
57: String variableName = getVariableName();
58: for (OutboundVariable child : children) {
59: if (child != null) {
60: buffer.append(variableName);
61: buffer.append('[');
62: buffer.append(i);
63: buffer.append("]=");
64: buffer.append(child.getAssignCode());
65: buffer.append(';');
66: }
67:
68: i++;
69: }
70: buffer.append("\r\n");
71:
72: setBaseDeclareCode("var " + variableName + "=[];");
73: setBaseBuildCode(buffer.toString());
74: } else {
75: setBaseDeclareCode("");
76: setBaseBuildCode("");
77: }
78: }
79:
80: /* (non-Javadoc)
81: * @see java.lang.Object#toString()
82: */
83: @Override
84: public String toString() {
85: return "ArrayNonJsonOutboundVariable:" + children;
86: }
87: }
|