All Downloads are FREE. Search and download functionalities are using the official Maven repository.

jaxx.compiler.tools.jaxxcapture.CapturedObject Maven / Gradle / Ivy

There is a newer version: 3.0-alpha-6
Show newest version
/*
 * #%L
 * JAXX :: Compiler
 * 
 * $Id: CapturedObject.java 2228 2011-02-19 21:56:44Z tchemit $
 * $HeadURL: http://svn.nuiton.org/svn/jaxx/tags/jaxx-2.5.19/jaxx-compiler/src/main/java/jaxx/compiler/tools/jaxxcapture/CapturedObject.java $
 * %%
 * Copyright (C) 2008 - 2010 CodeLutin
 * %%
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as 
 * published by the Free Software Foundation, either version 3 of the 
 * License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Lesser Public License for more details.
 * 
 * You should have received a copy of the GNU General Lesser Public 
 * License along with this program.  If not, see
 * .
 * #L%
 */

package jaxx.compiler.tools.jaxxcapture;

import jaxx.compiler.JAXXCompiler;
import jaxx.compiler.tools.jaxxcapture.handlers.ObjectHandler;

import java.awt.Component;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;

public class CapturedObject extends AbstractContextNode {
    private String className;
    private ObjectHandler handler;
    /** Maps children to their constraints. */
    private Map children = new LinkedHashMap();
    private CapturedObject parent;
    private Map properties = new LinkedHashMap();
    private Map additionalData = new HashMap();
    private StringBuilder innerXML = new StringBuilder();
    private StringBuilder script = new StringBuilder();
    private boolean inlineable = true;
    private JAXXCapture capture;

    public CapturedObject(ObjectHandler handler, String className, JAXXCapture capture) {
        this.handler = handler;
        this.className = className;
        this.capture = capture;
    }


    public ObjectHandler getObjectHandler() {
        return handler;
    }


    public void addChild(CapturedObject child, ContextNode constraints) {
        children.put(child, constraints);
        child.setParent(this);
    }


    public CapturedObject[] getChildren() {
        return children.keySet().toArray(new CapturedObject[children.size()]);
    }


    public CapturedObject getParent() {
        return parent;
    }


    public void setParent(CapturedObject parent) {
        this.parent = parent;
    }


    public ContextNode getConstraints(CapturedObject child) {
        return children.get(child);
    }


    public String getClassName() {
        return className;
    }


    public String getProperty(String key) {
        return properties.get(key);
    }


    public void setProperty(String key, String value) {
        properties.put(key, value);
    }


    public Map getProperties() {
        return properties;
    }


    public Object getAdditionalData(String key) {
        return additionalData.get(key);
    }


    public void setAdditionalData(String key, Object value) {
        additionalData.put(key, value);
    }


    public Map getAdditionalData() {
        return additionalData;
    }


    public void setInlineable(boolean inlineable) {
        this.inlineable = inlineable;
    }


    public boolean isInlineable() {
        try {
            return script.length() == 0 && !Component.class.isAssignableFrom(Class.forName(className, true, capture.getClassLoader())) && inlineable;
        }
        catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        }
    }


    public void appendInnerXML(String xml) {
        if (this.innerXML.length() > 0) {
            this.innerXML.append(JAXXCompiler.getLineSeparator());
        }
        this.innerXML.append(xml);
    }


    public String getInnerXML() {
        return innerXML.toString();
    }


    public void appendScriptCode(String script) {
        if (this.script.length() > 0) {
            this.script.append(JAXXCompiler.getLineSeparator());
        }
        this.script.append(script);
    }


    public String getScriptCode() {
        return script.toString();
    }


    public String getXML(JAXXCapture capture) {
        return getObjectHandler().getXML(this, capture);
    }

    @Override
    public String toString() {
        return "CapturedObject[" + getProperty("id") + ", " + className + "]";
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy