KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ofbiz > minilang > method > envops > OrderMapList


1 /*
2  * $Id: OrderMapList.java 5462 2005-08-05 18:35:48Z jonesde $
3  *
4  * Copyright (c) 2001, 2002 The Open For Business Project - www.ofbiz.org
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the "Software"),
8  * to deal in the Software without restriction, including without limitation
9  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  * and/or sell copies of the Software, and to permit persons to whom the
11  * Software is furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included
14  * in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
21  * OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
22  * THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23  */

24 package org.ofbiz.minilang.method.envops;
25
26 import java.util.*;
27
28 import javolution.util.FastList;
29
30 import org.w3c.dom.*;
31 import org.ofbiz.base.util.*;
32 import org.ofbiz.base.util.collections.FlexibleMapAccessor;
33 import org.ofbiz.base.util.collections.MapComparator;
34 import org.ofbiz.minilang.*;
35 import org.ofbiz.minilang.method.*;
36
37 /**
38  * Copies an environment field to a list
39  *
40  * @author <a HREF="mailto:jonesde@ofbiz.org">David E. Jones</a>
41  * @version $Rev: 5462 $
42  * @since 2.0
43  */

44 public class OrderMapList extends MethodOperation {
45     
46     public static final String JavaDoc module = FieldToList.class.getName();
47     
48     protected ContextAccessor listAcsr;
49     protected List orderByAcsrList = FastList.newInstance();
50     protected MapComparator mc;
51
52     public OrderMapList(Element element, SimpleMethod simpleMethod) {
53         super(element, simpleMethod);
54         listAcsr = new ContextAccessor(element.getAttribute("list-name"));
55         
56         List orderByElementList = UtilXml.childElementList(element, "order-by");
57         Iterator orderByElementIter = orderByElementList.iterator();
58         while (orderByElementIter.hasNext()) {
59             Element orderByElement = (Element) orderByElementIter.next();
60             this.orderByAcsrList.add(new FlexibleMapAccessor(orderByElement.getAttribute("field-name")));
61         }
62
63         this.mc = new MapComparator(this.orderByAcsrList);
64     }
65
66     public boolean exec(MethodContext methodContext) {
67         Object JavaDoc fieldVal = null;
68
69         List orderList = (List) listAcsr.get(methodContext);
70
71         if (orderList == null) {
72             if (Debug.infoOn()) Debug.logInfo("List not found with name " + listAcsr + ", not ordering/sorting list.", module);
73             return true;
74         }
75         
76         Collections.sort(orderList, mc);
77
78         return true;
79     }
80
81     public String JavaDoc rawString() {
82         return "<order-map-list list-name=\"" + this.listAcsr + "\"/>";
83     }
84     public String JavaDoc expandedString(MethodContext methodContext) {
85         // TODO: something more than a stub/dummy
86
return this.rawString();
87     }
88 }
89
Popular Tags