001: /*
002: The contents of this file are subject to the Common Public Attribution License
003: Version 1.0 (the "License"); you may not use this file except in compliance with
004: the License. You may obtain a copy of the License at
005: http://www.projity.com/license . The License is based on the Mozilla Public
006: License Version 1.1 but Sections 14 and 15 have been added to cover use of
007: software over a computer network and provide for limited attribution for the
008: Original Developer. In addition, Exhibit A has been modified to be consistent
009: with Exhibit B.
010:
011: Software distributed under the License is distributed on an "AS IS" basis,
012: WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the
013: specific language governing rights and limitations under the License. The
014: Original Code is OpenProj. The Original Developer is the Initial Developer and
015: is Projity, Inc. All portions of the code written by Projity are Copyright (c)
016: 2006, 2007. All Rights Reserved. Contributors Projity, Inc.
017:
018: Alternatively, the contents of this file may be used under the terms of the
019: Projity End-User License Agreeement (the Projity License), in which case the
020: provisions of the Projity License are applicable instead of those above. If you
021: wish to allow use of your version of this file only under the terms of the
022: Projity License and not to allow others to use your version of this file under
023: the CPAL, indicate your decision by deleting the provisions above and replace
024: them with the notice and other provisions required by the Projity License. If
025: you do not delete the provisions above, a recipient may use your version of this
026: file under either the CPAL or the Projity License.
027:
028: [NOTE: The text of this license may differ slightly from the text of the notices
029: in Exhibits A and B of the license at http://www.projity.com/license. You should
030: use the latest text at http://www.projity.com/license for your modifications.
031: You may not remove this license text from the source files.]
032:
033: Attribution Information: Attribution Copyright Notice: Copyright © 2006, 2007
034: Projity, Inc. Attribution Phrase (not exceeding 10 words): Powered by OpenProj,
035: an open source solution from Projity. Attribution URL: http://www.projity.com
036: Graphic Image as provided in the Covered Code as file: openproj_logo.png with
037: alternatives listed on http://www.projity.com/logo
038:
039: Display of Attribution Information is required in Larger Works which are defined
040: in the CPAL as a work which combines Covered Code or portions thereof with code
041: not governed by the terms of the CPAL. However, in addition to the other notice
042: obligations, all copies of the Covered Code in Executable and Source Code form
043: distributed must, as a form of attribution of the original author, include on
044: each user interface screen the "OpenProj" logo visible to all users. The
045: OpenProj logo should be located horizontally aligned with the menu bar and left
046: justified on the top left of the screen adjacent to the File menu. The logo
047: must be at least 100 x 25 pixels. When users click on the "OpenProj" logo it
048: must direct them back to http://www.projity.com.
049: */
050: package com.projity.grouping.core.transform;
051:
052: import java.util.ArrayList;
053: import java.util.HashMap;
054: import java.util.Iterator;
055: import java.util.List;
056: import java.util.Map;
057:
058: import org.apache.commons.digester.Digester;
059:
060: import com.projity.configuration.Dictionary;
061: import com.projity.configuration.NamedItem;
062: import com.projity.contrib.util.Log;
063: import com.projity.contrib.util.LogFactory;
064: import com.projity.field.InvalidFormulaException;
065: import com.projity.grouping.core.transform.filtering.NodeFilter;
066: import com.projity.grouping.core.transform.filtering.NotVoidFilter;
067: import com.projity.strings.Messages;
068: import com.projity.util.Environment;
069:
070: /**
071: *
072: */
073: public class TransformList implements NamedItem {
074: static Log log = LogFactory.getLog(TransformList.class);
075: public static final String category = "TransformCategory";
076:
077: public String getCategory() {
078: return category;
079: }
080:
081: String name = null;
082: String id = null;
083: Map elementMap = new HashMap();
084: Map factoryMap = new HashMap();
085: List factories = new ArrayList();
086:
087: public TransformList() {
088: }
089:
090: public void addFactory(CommonTransformFactory factory) {
091: if (factory.isServer() && Environment.getStandAlone())
092: return;
093: factories.add(factory);
094: factoryMap.put(factory.getId(), factory);
095: }
096:
097: /**
098: * @return Returns the name.
099: */
100: public String getName() {
101: return name;
102: }
103:
104: /**
105: * @param name The name to set.
106: */
107: public void setName(String name) {
108: this .name = name;
109: }
110:
111: public void setId(String id) {
112: this .id = id;
113: setName(Messages.getString(id));
114: }
115:
116: /**
117: * @return Returns the id.
118: */
119: public String getId() {
120: return id;
121: }
122:
123: public Object getTransform(String id) {
124: Object transform = null;
125: if (elementMap.containsKey(id))
126: transform = elementMap.get(id);
127: else {
128: CommonTransformFactory factory = getFactory(id);
129: if (factory == null)
130: return null;
131: try {
132: transform = factory.getTransform();
133: elementMap.put(id, transform);
134: } catch (InvalidFormulaException e) {
135: log.error("Formula not set: invalid formula text: "
136: + factory.getFormulaText());
137: }
138: }
139: return transform;
140: }
141:
142: public CommonTransformFactory getFactory(String id) {
143: return (CommonTransformFactory) factoryMap.get(id);
144: }
145:
146: public List getFactories() {
147: return factories;
148: }
149:
150: public List getFactories(ViewConfiguration view, String type) {
151: List authorizedList;
152: if (view == null) {
153: authorizedList = new ArrayList();
154: if ("user_filters".equals(type))
155: authorizedList.add(ViewTransformer.FILTER_NONE_ID);
156: else if ("user_sorters".equals(type))
157: authorizedList.add(ViewTransformer.SORTER_NONE_ID);
158: else if ("user_groupers".equals(type))
159: authorizedList.add(ViewTransformer.GROUPER_NONE_ID);
160: } else {
161: if ("user_filters".equals(type))
162: authorizedList = view.getTransform().getFilterList();
163: else if ("user_sorters".equals(type))
164: authorizedList = view.getTransform().getSorterList();
165: else
166: authorizedList = view.getTransform().getGrouperList();
167: if (authorizedList == null)
168: return factories;
169: }
170: List filtered = new ArrayList();
171: CommonTransformFactory f;
172: for (Iterator i = factories.iterator(); i.hasNext();) {
173: f = (CommonTransformFactory) i.next();
174: if (authorizedList.contains(f.getId()))
175: filtered.add(f);
176: }
177: return filtered;
178: }
179:
180: public static void addDigesterEvents(Digester digester) {
181: //filters
182: digester.addObjectCreate("*/transform/filters",
183: "com.projity.grouping.core.transform.TransformList");
184: digester.addSetProperties("*/transform/filters");
185: digester.addSetNext("*/transform/filters", "add",
186: "com.projity.configuration.NamedItem");
187:
188: digester
189: .addObjectCreate("*/filter",
190: "com.projity.grouping.core.transform.filtering.NodeFilterFactory");
191: digester.addSetProperties("*/filter");
192: digester.addCallMethod("*/filter/formulaText",
193: "setFormulaText", 0);
194: digester
195: .addSetNext("*/filter", "addFactory",
196: "com.projity.grouping.core.transform.filtering.NodeFilterFactory");
197:
198: //sorters
199: digester.addObjectCreate("*/transform/sorters",
200: "com.projity.grouping.core.transform.TransformList");
201: digester.addSetProperties("*/transform/sorters");
202: digester.addSetNext("*/transform/sorters", "add",
203: "com.projity.configuration.NamedItem");
204:
205: digester
206: .addObjectCreate("*/sorter",
207: "com.projity.grouping.core.transform.sorting.NodeSorterFactory");
208: digester.addSetProperties("*/sorter");
209: digester.addCallMethod("*/sorter/formulaText",
210: "setFormulaText", 0);
211: digester.addCallMethod("*/sorter/groupNameFormula",
212: "setGroupNameFormula", 0);
213: digester
214: .addSetNext("*/sorter", "addFactory",
215: "com.projity.grouping.core.transform.sorting.NodeSorterFactory");
216:
217: //groupers
218: digester.addObjectCreate("*/transform/groupers",
219: "com.projity.grouping.core.transform.TransformList");
220: digester.addSetProperties("*/transform/groupers");
221: digester.addSetNext("*/transform/groupers", "add",
222: "com.projity.configuration.NamedItem");
223:
224: digester
225: .addObjectCreate("*/grouper",
226: "com.projity.grouping.core.transform.grouping.NodeGrouper");
227: digester.addSetProperties("*/grouper");
228: digester
229: .addSetNext("*/grouper", "addFactory",
230: "com.projity.grouping.core.transform.grouping.NodeGrouper");
231:
232: digester
233: .addObjectCreate("*/grouper/group",
234: "com.projity.grouping.core.transform.grouping.NodeGroup");
235: digester.addSetProperties("*/grouper/group");
236: digester
237: .addSetNext("*/grouper/group", "addGroup",
238: "com.projity.grouping.core.transform.grouping.NodeGroup");
239:
240: digester
241: .addObjectCreate("*/param",
242: "com.projity.grouping.core.transform.TransformParameter");
243: digester.addSetProperties("*/param");
244: digester
245: .addSetNext("*/param", "addParameter",
246: "com.projity.grouping.core.transform.TransformParameter");
247:
248: //transformers
249: digester.addObjectCreate("*/transform/transformers",
250: "com.projity.grouping.core.transform.TransformList");
251: digester.addSetProperties("*/transform/transformers");
252: digester.addSetNext("*/transform/transformers", "add",
253: "com.projity.configuration.NamedItem");
254:
255: digester
256: .addObjectCreate("*/transformer",
257: "com.projity.grouping.core.transform.transformer.NodeTransformerFactory");
258: digester.addSetProperties("*/transformer");
259: digester.addCallMethod("*/transformer/formulaText",
260: "setFormulaText", 0);
261: digester
262: .addSetNext("*/transformer", "addFactory",
263: "com.projity.grouping.core.transform.transformer.NodeTransformerFactory");
264:
265: }
266:
267: public static TransformList getInstance(String name) {
268: return (TransformList) Dictionary.get(category, name);
269: }
270:
271: /*public static NodeFilter getNotAssignmentFilter(){
272: return (NodeFilter)getInstance("hidden_filters").getTransform("Filter.NotAssignment");
273: }*/
274:
275: public static NodeFilter getNotVoidFilter() {
276: return NotVoidFilter.getInstance();
277: }
278:
279: public static NodeFilter getTrueFilter() {
280: return (NodeFilter) getInstance("user_filters").getTransform(
281: "Filter.True");
282: }
283:
284: }
|