01: /*
02: * This file is part of PFIXCORE.
03: *
04: * PFIXCORE is free software; you can redistribute it and/or modify
05: * it under the terms of the GNU Lesser General Public License as published by
06: * the Free Software Foundation; either version 2 of the License, or
07: * (at your option) any later version.
08: *
09: * PFIXCORE is distributed in the hope that it will be useful,
10: * but WITHOUT ANY WARRANTY; without even the implied warranty of
11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12: * GNU Lesser General Public License for more details.
13: *
14: * You should have received a copy of the GNU Lesser General Public License
15: * along with PFIXCORE; if not, write to the Free Software
16: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17: *
18: */
19:
20: package de.schlund.pfixcore.example;
21:
22: import java.util.HashMap;
23:
24: import org.apache.log4j.Logger;
25: import org.w3c.dom.Element;
26:
27: import de.schlund.pfixcore.util.PropertiesUtils;
28: import de.schlund.pfixxml.ResultDocument;
29:
30: /**
31: * ContextTrouser.java
32: *
33: *
34: * Created: Thu Oct 18 19:24:37 2001
35: *
36: * @author <a href="mailto:jtl@schlund.de">Jens Lautenbacher</a>
37: *
38: *
39: */
40:
41: // Uuugh, you wouldn't want to do this in a normal C-Res.
42: // Inheritance from one C-Res to another is asking for trouble.
43: // But for this example it helps keeping the code small.
44: public class ContextTrouserImpl extends ContextTShirtImpl implements
45: ContextTrouser {
46: private final static Logger LOG = Logger
47: .getLogger(ContextTrouserImpl.class);
48:
49: public String toString() {
50: LOG.debug("Doing ContextTrouser...");
51: return "[Size: " + getSize() + "][Color: " + getColor() + "]";
52: }
53:
54: public void insertStatus(ResultDocument resdoc, Element elem) {
55: if (getSize() != null && getColor() != null) {
56: elem.setAttribute("size", getSize());
57: elem.setAttribute("color", "" + getColor());
58:
59: Integer[] trouserfeatures = getFeature();
60: HashMap<String, String> featmap = PropertiesUtils
61: .selectProperties(context.getProperties(),
62: "contexttrouser.feature");
63: if (trouserfeatures != null) {
64: for (int i = 0; i < trouserfeatures.length; i++) {
65: Integer feat = trouserfeatures[i];
66: ResultDocument.addTextChild(elem, "feature",
67: (String) featmap.get(feat.toString()));
68: }
69: }
70: }
71: }
72:
73: }// ContextTrouser
|