Warning: Can't use blame annotator:
svn blame failed on trunk/src/tmcsim/cadsimulator/paramicscontrol/ParamicsWriter.java: ("Can't find a temporary directory: Internal error", 20014)

source: tmcsimulator/trunk/src/tmcsim/cadsimulator/paramicscontrol/ParamicsWriter.java @ 2

Revision 2, 2.5 KB checked in by jdalbey, 10 years ago (diff)

Initial Import of project files

RevLine 
1package tmcsim.cadsimulator.paramicscontrol;
2
3import java.util.Observable;
4import java.util.logging.Level;
5import java.util.logging.Logger;
6
7import javax.xml.parsers.DocumentBuilderFactory;
8
9import org.w3c.dom.Document;
10import org.w3c.dom.Element;
11
12import tmcsim.common.CADProtocol.PARAMICS_ACTIONS;
13import tmcsim.common.CADProtocol.PARAMICS_COMM_TAGS;
14
15/**
16 * ParamicsWriter is an abstract class to define objects that may
17 * write data to the Paramics Communicator.  Each ParamicsWriter
18 * is identified by a unique id and has a target file that will be
19 * written to.  This file may be a file name or relative path, which
20 * will become relative to the target location of the remote Paramics
21 * Communicator.  All implementing Writers call the writeXML() method
22 * to transmit messages to the ParamicsCommunicator.
23 *
24 * @author Matthew Cechini
25 * @version
26 */
27public abstract class ParamicsWriter extends Observable {
28
29    /** Error Logger. */
30    private static Logger paramLogger = Logger.getLogger("tmcsim.cadsimulator.paramicscontrol");
31   
32    /** Unique identifier for writer. */
33    public String writerID   = null;
34   
35    /** Target file writer will write to. */
36    public String targetFile = null;
37       
38    /**
39     * This method adopts the parameter message data Document into
40     * a new document that has tags for the writer's id, the action
41     * (WRITE_FILE) being performed.  This new Document is then sent
42     * to the observing ParamicsCommunicator for transmission.
43     *
44     * @param xmlDoc Output Document containing message data.
45     */
46    public void writeXML(Document xmlDoc) {
47       
48        try {
49            Document writerDoc = DocumentBuilderFactory.newInstance()
50                .newDocumentBuilder().newDocument();
51           
52            Element writerElem = writerDoc.createElement(PARAMICS_COMM_TAGS.WRITER.tag);
53            writerElem.setAttribute(PARAMICS_COMM_TAGS.ID.tag, writerID.toString());
54            writerElem.setAttribute(PARAMICS_COMM_TAGS.ACTION.tag,
55                    PARAMICS_ACTIONS.WRITE_FILE.action);
56           
57            writerElem.appendChild(writerDoc.adoptNode(xmlDoc.getDocumentElement()));
58       
59            writerDoc.appendChild(writerElem);     
60                   
61            setChanged();
62            notifyObservers(writerDoc);
63        } catch(Exception e) {
64            paramLogger.logp(Level.SEVERE, "ParamicsWriter", "writeXML", 
65                    "Exception in writing XML for writer " + writerID, e);
66        }
67           
68    };
69}
Note: See TracBrowser for help on using the repository browser.