001: package jaxx.tools.jaxxcapture;
002:
003: import java.awt.Component;
004: import java.util.*;
005:
006: import jaxx.compiler.*;
007: import jaxx.tools.jaxxcapture.handlers.*;
008:
009: public class CapturedObject extends AbstractContextNode {
010: private String className;
011: private ObjectHandler handler;
012: /** Maps children to their constraints. */
013: private Map/*<CapturedObject, ContextNode>*/children = new LinkedHashMap/*<CapturedObject, ContextNode>*/();
014: private CapturedObject parent;
015: private Map/*<String, String>*/properties = new LinkedHashMap/*<String, String>*/();
016: private Map/*<String, Object>*/additionalData = new HashMap/*<String, Object>*/();
017: private StringBuffer innerXML = new StringBuffer();
018: private StringBuffer script = new StringBuffer();
019: private boolean inlineable = true;
020: private JAXXCapture capture;
021:
022: public CapturedObject(ObjectHandler handler, String className,
023: JAXXCapture capture) {
024: this .handler = handler;
025: this .className = className;
026: this .capture = capture;
027: }
028:
029: public ObjectHandler getObjectHandler() {
030: return handler;
031: }
032:
033: public void addChild(CapturedObject child, ContextNode constraints) {
034: children.put(child, constraints);
035: child.setParent(this );
036: }
037:
038: public CapturedObject[] getChildren() {
039: return (CapturedObject[]) children.keySet().toArray(
040: new CapturedObject[children.size()]);
041: }
042:
043: public CapturedObject getParent() {
044: return parent;
045: }
046:
047: public void setParent(CapturedObject parent) {
048: this .parent = parent;
049: }
050:
051: public ContextNode getConstraints(CapturedObject child) {
052: return (ContextNode) children.get(child);
053: }
054:
055: public String getClassName() {
056: return className;
057: }
058:
059: public String getProperty(String key) {
060: return (String) properties.get(key);
061: }
062:
063: public void setProperty(String key, String value) {
064: properties.put(key, value);
065: }
066:
067: public Map/*<String, String>*/getProperties() {
068: return properties;
069: }
070:
071: public Object getAdditionalData(String key) {
072: return (String) additionalData.get(key);
073: }
074:
075: public void setAdditionalData(String key, Object value) {
076: additionalData.put(key, value);
077: }
078:
079: public Map/*<String, Object>*/getAdditionalData() {
080: return additionalData;
081: }
082:
083: public void setInlineable(boolean inlineable) {
084: this .inlineable = inlineable;
085: }
086:
087: public boolean isInlineable() {
088: try {
089: return script.length() == 0
090: && !Component.class.isAssignableFrom(Class.forName(
091: className, true, capture.getClassLoader()))
092: && inlineable;
093: } catch (ClassNotFoundException e) {
094: throw new RuntimeException(e);
095: }
096: }
097:
098: public void appendInnerXML(String xml) {
099: if (this .innerXML.length() > 0)
100: this .innerXML.append(JAXXCompiler.getLineSeparator());
101: this .innerXML.append(xml);
102: }
103:
104: public String getInnerXML() {
105: return innerXML.toString();
106: }
107:
108: public void appendScriptCode(String script) {
109: if (this .script.length() > 0)
110: this .script.append(JAXXCompiler.getLineSeparator());
111: this .script.append(script);
112: }
113:
114: public String getScriptCode() {
115: return script.toString();
116: }
117:
118: public String getXML(JAXXCapture capture) {
119: return getObjectHandler().getXML(this , capture);
120: }
121:
122: public String toString() {
123: return "CapturedObject[" + getProperty("id") + ", " + className
124: + "]";
125: }
126: }
|