KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > sapia > util > text > CompositeElement


1 package org.sapia.util.text;
2
3
4 // Import of Sun's JDK classes
5
// ---------------------------
6
import java.util.Iterator JavaDoc;
7 import java.util.List JavaDoc;
8
9
10 /**
11  * This class implements a composite <code>TemplateElementIF</code>, which holds
12  * <code>VariableElement</code> and <code>ConstantElment</code> instances.
13  *
14  * @author JC Desrochers
15  *
16  * <dl>
17  * <dt><b>Copyright:</b><dd>Copyright &#169; 2002-2003 <a HREF="http://www.sapia-oss.org">Sapia Open Source Software</a>. All Rights Reserved.</dd></dt>
18  * <dt><b>License:</b><dd>Read the license.txt file of the jar or visit the
19  * <a HREF="http://www.sapia-oss.org/license.html">license page</a> at the Sapia OSS web site</dd></dt>
20  * </dl>
21  */

22 public class CompositeElement implements TemplateElementIF {
23   /////////////////////////////////////////////////////////////////////////////////////////
24
////////////////////////////////// CLASS ATTRIBUTES ///////////////////////////////////
25
/////////////////////////////////////////////////////////////////////////////////////////
26

27   /** Defines the logger instance for this class. */
28
29   //private static final Logger _theLogger = Logger.getLogger(CompositeElement.class);
30
/////////////////////////////////////////////////////////////////////////////////////////
31
///////////////////////////////// INSTANCE ATTRIBUTES /////////////////////////////////
32
/////////////////////////////////////////////////////////////////////////////////////////
33

34   /** The list of template elements. */
35   private List JavaDoc _theElements;
36
37   /////////////////////////////////////////////////////////////////////////////////////////
38
//////////////////////////////////// CONSTRUCTORS /////////////////////////////////////
39
/////////////////////////////////////////////////////////////////////////////////////////
40

41   /**
42    * Creates a new CompositeElement instance with the argument passed in.
43    *
44    * @param someElements The template elements of this composite element.
45    */

46   public CompositeElement(List JavaDoc someElements) {
47     _theElements = someElements;
48   }
49
50   /////////////////////////////////////////////////////////////////////////////////////////
51
////////////////////////////////// ACCESSOR METHODS ///////////////////////////////////
52
/////////////////////////////////////////////////////////////////////////////////////////
53

54   /**
55    * Returns the template elements of this composite element.
56    *
57    * @return The template elements of this composite element.
58    */

59   public List JavaDoc getElements() {
60     return _theElements;
61   }
62
63   /////////////////////////////////////////////////////////////////////////////////////////
64
/////////////////////////////// INTERACE IMPLEMENTATION ///////////////////////////////
65
/////////////////////////////////////////////////////////////////////////////////////////
66

67   /**
68    * Renders this template element using the template context passed in and
69    * returns the result in a new string.
70    *
71    * @param aContext The template context to use in the rendering process.
72    * @return The result of the rendering operation as a new string.
73    * @exception TemplateException If an error occurs rendering this template element.
74    */

75   public String JavaDoc render(TemplateContextIF aContext) throws TemplateException {
76     StringBuffer JavaDoc aBuffer = new StringBuffer JavaDoc();
77     render(aContext, aBuffer);
78
79     return aBuffer.toString();
80   }
81
82   /**
83    * Renders this template element using the template context passed in and
84    * appending the result in the string buffer passed in.
85    *
86    * @param aContext The template context to use in the rendering process.
87    * @exception TemplateException If an error occurs rendering this template element.
88    */

89   public void render(TemplateContextIF aContext, StringBuffer JavaDoc aBuffer)
90     throws TemplateException {
91     try {
92       for (Iterator JavaDoc it = _theElements.iterator(); it.hasNext();) {
93         TemplateElementIF anElement = (TemplateElementIF) it.next();
94         anElement.render(aContext, aBuffer);
95       }
96     } catch (TemplateException re) {
97       String JavaDoc aMessage = "Unable to render the elements of this composite element";
98       throw new TemplateException(aMessage, re);
99     }
100   }
101 }
102
Popular Tags