001: /*
002: * Copyright 2007 Frank W. Zammetti
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016:
017: package com.omnytex;
018:
019: import java.util.ArrayList;
020: import java.util.HashMap;
021: import java.util.List;
022: import java.util.Map;
023:
024: /**
025: * This class is a data structure used to pass data from the client to the
026: * Freemarker class.
027: */
028: public class FreemarkerData {
029:
030: /**
031: * The name of the template, fully-qualified, to use to generate output.
032: */
033: private String template;
034:
035: /**
036: * Data that will sit directly in the root of the Map passed to Freemarker.
037: */
038: private Map rootData = new HashMap();
039:
040: /**
041: * Data that consists of Maps passed to Freemarker.
042: */
043: private Map mapData = new HashMap();
044:
045: /**
046: * Mutator for template.
047: *
048: * @param inTemplate New value for template.
049: */
050: public void setTemplate(final String inTemplate) {
051:
052: template = inTemplate;
053:
054: } // End setTemplate().
055:
056: /**
057: * Accessor for template.
058: *
059: * @return Value of template.
060: */
061: public String getTemplate() {
062:
063: return template;
064:
065: } // End getTemplate().
066:
067: /**
068: * Mutator for rootData.
069: *
070: * @param inRootData New value for rootData.
071: */
072: public void setRootData(final Map inRootData) {
073:
074: rootData = inRootData;
075:
076: } // End setRootData().
077:
078: /**
079: * Accessor for rootData.
080: *
081: * @return Value of rootData.
082: */
083: public Map getRootData() {
084:
085: return rootData;
086:
087: } // End getRootData().
088:
089: /**
090: * Mutator for mapData.
091: *
092: * @param inMapData New value for mapData.
093: */
094: public void setMapData(final Map inMapData) {
095:
096: mapData = inMapData;
097:
098: } // End setMapData().
099:
100: /**
101: * Accessor for mapData.
102: *
103: * @return Value of mapData.
104: */
105: public Map getMapData() {
106:
107: return mapData;
108:
109: } // End getMapData().
110:
111: /**
112: * Overriden toString method.
113: *
114: * @return A reflexively-built string representation of this bean.
115: */
116: public String toString() {
117:
118: String str = null;
119: StringBuffer sb = new StringBuffer(1000);
120: sb.append("[").append(super .toString()).append("]={");
121: boolean firstPropertyDisplayed = false;
122: try {
123: java.lang.reflect.Field[] fields = this .getClass()
124: .getDeclaredFields();
125: for (int i = 0; i < fields.length; i++) {
126: if (firstPropertyDisplayed) {
127: sb.append(", ");
128: } else {
129: firstPropertyDisplayed = true;
130: }
131: sb.append(fields[i].getName()).append("=").append(
132: fields[i].get(this ));
133: }
134: sb.append("}");
135: str = sb.toString().trim();
136: } catch (IllegalAccessException iae) {
137: iae.printStackTrace();
138: }
139: return str;
140:
141: } // End toString().
142:
143: } // End class.
|