01: /*******************************************************************************
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing,
13: * software distributed under the License is distributed on an
14: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15: * KIND, either express or implied. See the License for the
16: * specific language governing permissions and limitations
17: * under the License.
18: *******************************************************************************/package org.ofbiz.minilang.method.envops;
19:
20: import java.util.*;
21:
22: import org.w3c.dom.*;
23: import org.ofbiz.base.util.*;
24: import org.ofbiz.minilang.*;
25: import org.ofbiz.minilang.method.*;
26:
27: /**
28: * Copies an environment field to a list
29: */
30: public class ListToList extends MethodOperation {
31:
32: public static final String module = ListToList.class.getName();
33:
34: ContextAccessor listAcsr;
35: ContextAccessor toListAcsr;
36:
37: public ListToList(Element element, SimpleMethod simpleMethod) {
38: super (element, simpleMethod);
39: listAcsr = new ContextAccessor(element
40: .getAttribute("list-name"));
41: toListAcsr = new ContextAccessor(element
42: .getAttribute("to-list-name"));
43: }
44:
45: public boolean exec(MethodContext methodContext) {
46:
47: List fromList = (List) listAcsr.get(methodContext);
48: List toList = (List) toListAcsr.get(methodContext);
49:
50: if (fromList == null) {
51: if (Debug.infoOn())
52: Debug.logInfo("List not found with name " + listAcsr
53: + ", not copying list", module);
54: return true;
55: }
56:
57: if (toList == null) {
58: if (Debug.verboseOn())
59: Debug.logVerbose("List not found with name "
60: + toListAcsr + ", creating new list", module);
61: toList = new LinkedList();
62: toListAcsr.put(methodContext, toList);
63: }
64:
65: toList.addAll(fromList);
66: return true;
67: }
68:
69: public String rawString() {
70: // TODO: something more than the empty tag
71: return "<list-to-list/>";
72: }
73:
74: public String expandedString(MethodContext methodContext) {
75: // TODO: something more than a stub/dummy
76: return this.rawString();
77: }
78: }
|