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.entityops;
19:
20: import java.util.List;
21:
22: import org.ofbiz.entity.util.EntityUtil;
23: import org.ofbiz.minilang.SimpleMethod;
24: import org.ofbiz.minilang.method.ContextAccessor;
25: import org.ofbiz.minilang.method.MethodContext;
26: import org.ofbiz.minilang.method.MethodOperation;
27: import org.w3c.dom.Element;
28:
29: /**
30: * Order the given list of GenericValue objects
31: */
32: public class OrderValueList extends MethodOperation {
33:
34: ContextAccessor listAcsr;
35: ContextAccessor toListAcsr;
36: ContextAccessor orderByListAcsr;
37:
38: public OrderValueList(Element element, SimpleMethod simpleMethod) {
39: super (element, simpleMethod);
40: listAcsr = new ContextAccessor(element
41: .getAttribute("list-name"));
42: toListAcsr = new ContextAccessor(element
43: .getAttribute("to-list-name"), element
44: .getAttribute("list-name"));
45: orderByListAcsr = new ContextAccessor(element
46: .getAttribute("order-by-list-name"));
47: }
48:
49: public boolean exec(MethodContext methodContext) {
50: List orderByList = null;
51:
52: if (!orderByListAcsr.isEmpty()) {
53: orderByList = (List) orderByListAcsr.get(methodContext);
54: }
55: toListAcsr.put(methodContext, EntityUtil.orderBy(
56: (List) listAcsr.get(methodContext), orderByList));
57: return true;
58: }
59:
60: public String rawString() {
61: // TODO: something more than the empty tag
62: return "<order-value-list/>";
63: }
64:
65: public String expandedString(MethodContext methodContext) {
66: // TODO: something more than a stub/dummy
67: return this.rawString();
68: }
69: }
|