KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openharmonise > rm > resources > publishing > Template


1 /*
2  * The contents of this file are subject to the
3  * Mozilla Public License Version 1.1 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at http://www.mozilla.org/MPL/
6  *
7  * Software distributed under the License is distributed on an "AS IS"
8  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
9  * See the License for the specific language governing rights and
10  * limitations under the License.
11  *
12  * The Initial Developer of the Original Code is Simulacra Media Ltd.
13  * Portions created by Simulacra Media Ltd are Copyright (C) Simulacra Media Ltd, 2004.
14  *
15  * All Rights Reserved.
16  *
17  * Contributor(s):
18  */

19 package org.openharmonise.rm.resources.publishing;
20
21 import org.openharmonise.commons.dsi.AbstractDataStoreInterface;
22 import org.openharmonise.commons.xml.XMLDocument;
23 import org.openharmonise.rm.*;
24 import org.openharmonise.rm.publishing.*;
25 import org.openharmonise.rm.resources.lifecycle.Editable;
26 import org.openharmonise.rm.resources.xml.XMLResource;
27 import org.w3c.dom.Element JavaDoc;
28
29
30 /**
31  * Extension of <code>XMLResource</code> which adds functionality for handling the
32  * XML content as a template with which a <code>Publishable</code> object may
33  * be published.
34  *
35  * @author Michael Bell
36  * @version $Revision: 1.3 $
37  *
38  */

39 public class Template extends XMLResource implements Editable {
40     
41     //XML constants
42
public static final String JavaDoc ATTRIB_TEMPLATEID = "templateId";
43     public static final String JavaDoc TAG_TEMPLATE = "Template" ;
44     
45     //DB constants
46
private static final String JavaDoc TBL_TEMPLATEGROUP = "template";
47     
48
49     /**
50      * Basic constructor.
51      */

52     public Template() {
53         super();
54     }
55
56     /**
57      * Constructor for a template with an interface to the DB.
58      *
59      * @param con
60      */

61     public Template(AbstractDataStoreInterface con) {
62         super(con);
63     }
64
65     /**
66      * Standard constructor for a known template.
67      *
68      * @param con
69      * @param nId
70      */

71     public Template(AbstractDataStoreInterface con, int nId) {
72         super(con,nId);
73     }
74
75     /**
76      * Standard constructor for a known template that may be historical.
77      *
78      * @param con
79      * @param nId
80      * @param bIsHistorical
81      */

82     public Template(AbstractDataStoreInterface con, int nId, int nKey, boolean bIsHistorical)
83               {
84         super(con,nId, nKey, bIsHistorical);
85     }
86
87     /**
88      * Publishes the <code>Publishable</code> object using this template and the
89      * <code>State</code>.
90      *
91      * @exception Exception General exception
92      * @param pubObj XML to publish object with
93      * @param output XML Document to publish to
94      * @param state
95      * @return XML output
96      */

97     public Element JavaDoc publishObjectToElement(Publishable pubObj,
98                                           HarmoniseOutput output, State state)
99                                    throws PublishException {
100         Element JavaDoc rootEl;
101         try {
102             rootEl = getTemplateRootElement();
103         } catch (DataAccessException e) {
104             throw new PublishException("Error occurred getting template element",e);
105         }
106         
107         Element JavaDoc el = pubObj.publish(rootEl,(HarmoniseOutput) output,(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 JavaDoc getTemplateRootElement() throws DataAccessException {
119         if (isPopulated() == false) {
120             try {
121                 populateFromDatabase();
122             } catch (PopulateException e) {
123                 throw new DataAccessException("Error occured populating object",e);
124             }
125         }
126
127         XMLDocument xml = getXIncludeResolvedDocument();
128            
129
130         Element JavaDoc root = xml.getDocumentElement();
131         root.setAttribute(ATTRIB_TEMPLATEID, "" + m_nId);
132         
133         return (xml.getDocumentElement());
134     }
135
136     /* (non-Javadoc)
137      * @see org.openharmonise.rm.dsi.DataStoreObject#getDBTableName()
138      */

139     public String JavaDoc getDBTableName() {
140         return TBL_TEMPLATEGROUP;
141     }
142
143     /* (non-Javadoc)
144      * @see org.openharmonise.rm.resources.AbstractChildObject#getParentObjectClassName()
145      */

146     public String JavaDoc getParentObjectClassName() {
147         
148         return TemplateGroup.class.getName();
149     }
150
151 }
Popular Tags