001: /*
002: * The contents of this file are subject to the
003: * Mozilla Public License Version 1.1 (the "License");
004: * you may not use this file except in compliance with the License.
005: * You may obtain a copy of the License at http://www.mozilla.org/MPL/
006: *
007: * Software distributed under the License is distributed on an "AS IS"
008: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
009: * See the License for the specific language governing rights and
010: * limitations under the License.
011: *
012: * The Initial Developer of the Original Code is Simulacra Media Ltd.
013: * Portions created by Simulacra Media Ltd are Copyright (C) Simulacra Media Ltd, 2004.
014: *
015: * All Rights Reserved.
016: *
017: * Contributor(s):
018: */
019: package org.openharmonise.rm.resources.publishing;
020:
021: import org.openharmonise.commons.dsi.AbstractDataStoreInterface;
022: import org.openharmonise.commons.xml.XMLDocument;
023: import org.openharmonise.rm.*;
024: import org.openharmonise.rm.publishing.*;
025: import org.openharmonise.rm.resources.lifecycle.Editable;
026: import org.openharmonise.rm.resources.xml.XMLResource;
027: import org.w3c.dom.Element;
028:
029: /**
030: * Extension of <code>XMLResource</code> which adds functionality for handling the
031: * XML content as a template with which a <code>Publishable</code> object may
032: * be published.
033: *
034: * @author Michael Bell
035: * @version $Revision: 1.3.2.1 $
036: *
037: */
038: public class Template extends XMLResource implements Editable {
039:
040: //XML constants
041: public static final String ATTRIB_TEMPLATEID = "templateId";
042: public static final String TAG_TEMPLATE = "Template";
043:
044: //DB constants
045: private static final String TBL_TEMPLATEGROUP = "template";
046:
047: /**
048: * Basic constructor.
049: */
050: public Template() {
051: super ();
052: }
053:
054: /**
055: * Constructor for a template with an interface to the DB.
056: *
057: * @param con
058: */
059: public Template(AbstractDataStoreInterface con) {
060: super (con);
061: }
062:
063: /**
064: * Standard constructor for a known template.
065: *
066: * @param con
067: * @param nId
068: */
069: public Template(AbstractDataStoreInterface con, int nId) {
070: super (con, nId);
071: }
072:
073: /**
074: * Standard constructor for a known template that may be historical.
075: *
076: * @param con
077: * @param nId
078: * @param bIsHistorical
079: */
080: public Template(AbstractDataStoreInterface con, int nId, int nKey,
081: boolean bIsHistorical) {
082: super (con, nId, nKey, bIsHistorical);
083: }
084:
085: /**
086: * Publishes the <code>Publishable</code> object using this template and the
087: * <code>State</code>.
088: *
089: * @exception Exception General exception
090: * @param pubObj XML to publish object with
091: * @param output XML Document to publish to
092: * @param state
093: * @return XML output
094: */
095: public Element publishObjectToElement(Publishable pubObj,
096: HarmoniseOutput output, State state)
097: throws PublishException {
098: Element rootEl;
099: try {
100: rootEl = getTemplateRootElement();
101: } catch (DataAccessException e) {
102: throw new PublishException(
103: "Error occurred getting template element", e);
104: }
105:
106: Element el = pubObj.publish(rootEl, (HarmoniseOutput) output,
107: (State) state);
108:
109: return el;
110: }
111:
112: /**
113: * Returns the root element of this template.
114: *
115: * @return
116: * @throws DataAccessException
117: */
118: public Element getTemplateRootElement() throws DataAccessException {
119: if (isPopulated() == false) {
120: try {
121: populateFromDatabase();
122: } catch (PopulateException e) {
123: throw new DataAccessException(
124: "Error occured populating object", e);
125: }
126: }
127:
128: XMLDocument xml = getXIncludeResolvedDocument();
129:
130: Element root = xml.getDocumentElement();
131:
132: if (root == null) {
133: throw new DataAccessException(
134: "No Document Element present in template "
135: + this .m_nId);
136: }
137: return (root);
138: }
139:
140: /* (non-Javadoc)
141: * @see org.openharmonise.rm.dsi.DataStoreObject#getDBTableName()
142: */
143: public String getDBTableName() {
144: return TBL_TEMPLATEGROUP;
145: }
146:
147: /* (non-Javadoc)
148: * @see org.openharmonise.rm.resources.AbstractChildObject#getParentObjectClassName()
149: */
150: public String getParentObjectClassName() {
151:
152: return TemplateGroup.class.getName();
153: }
154:
155: }
|