001: /*
002: * This file is part of PFIXCORE.
003: *
004: * PFIXCORE is free software; you can redistribute it and/or modify
005: * it under the terms of the GNU Lesser General Public License as published by
006: * the Free Software Foundation; either version 2 of the License, or
007: * (at your option) any later version.
008: *
009: * PFIXCORE is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
012: * GNU Lesser General Public License for more details.
013: *
014: * You should have received a copy of the GNU Lesser General Public License
015: * along with PFIXCORE; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017: *
018: */
019:
020: package de.schlund.pfixcore.example;
021:
022: import java.util.HashMap;
023:
024: import org.apache.log4j.Logger;
025: import org.w3c.dom.Element;
026:
027: import de.schlund.pfixcore.util.PropertiesUtils;
028: import de.schlund.pfixcore.workflow.Context;
029: import de.schlund.pfixxml.ResultDocument;
030:
031: /**
032: * ContextTShirt.java
033: *
034: *
035: * Created: Thu Oct 18 19:24:37 2001
036: *
037: * @author <a href="mailto:jtl@schlund.de">Jens Lautenbacher</a>
038: *
039: *
040: */
041:
042: public class ContextTShirtImpl implements ContextTShirt {
043: private String size = null;
044: private Integer color = null;
045: private Integer[] features = null;
046: protected Context context = null;
047: private final static Logger LOG = Logger
048: .getLogger(ContextTShirtImpl.class);
049:
050: public void init(Context context) {
051: this .context = context;
052: }
053:
054: public void reset() {
055: size = null;
056: color = null;
057: features = null;
058: }
059:
060: public Integer getColor() {
061: return color;
062: }
063:
064: public Integer[] getFeature() {
065: return features;
066: }
067:
068: public String getSize() {
069: return size;
070: }
071:
072: public void setColor(Integer color) {
073: this .color = color;
074: }
075:
076: public void setSize(String size) {
077: this .size = size;
078: }
079:
080: public void setFeature(Integer[] features) {
081: this .features = features;
082: }
083:
084: public boolean needsData() {
085: if (size == null || color == null) {
086: return true;
087: } else {
088: return false;
089: }
090: }
091:
092: public String toString() {
093: LOG.debug("Doing ContextTShirt...");
094: return "[Size: " + size + "][Color: " + color + "]";
095: }
096:
097: public void insertStatus(ResultDocument resdoc, Element tshirt) {
098: tshirt.setAttribute("size", getSize());
099: tshirt.setAttribute("color", "" + getColor());
100:
101: Integer[] tshirtfeatures = getFeature();
102: HashMap<String, String> featmap = PropertiesUtils
103: .selectProperties(context.getProperties(),
104: "contexttshirt.feature");
105: if (tshirtfeatures != null) {
106: for (int i = 0; i < tshirtfeatures.length; i++) {
107: Integer feat = tshirtfeatures[i];
108: ResultDocument.addTextChild(tshirt, "feature",
109: (String) featmap.get(feat.toString()));
110: }
111: }
112: }
113:
114: }// ContextTShirt
|