001: //WebOnSwing - Web Application Framework
002: //Copyright (C) 2003 Fernando Damian Petrola
003: //
004: //This library is free software; you can redistribute it and/or
005: //modify it under the terms of the GNU Lesser General Public
006: //License as published by the Free Software Foundation; either
007: //version 2.1 of the License, or (at your option) any later version.
008: //
009: //This library is distributed in the hope that it will be useful,
010: //but WITHOUT ANY WARRANTY; without even the implied warranty of
011: //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012: //Lesser General Public License for more details.
013: //
014: //You should have received a copy of the GNU Lesser General Public
015: //License along with this library; if not, write to the Free Software
016: //Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017:
018: package net.ar.webonswing.render.templates;
019:
020: import java.util.*;
021:
022: import net.ar.webonswing.render.*;
023: import net.ar.webonswing.visitor.*;
024:
025: public class DefaultTemplate implements Template, PublicCloneable {
026: protected Vector theElements;
027: protected TemplateBody theBody;
028:
029: public DefaultTemplate(TemplateBody aBody) {
030: theBody = aBody;
031: theElements = new Vector();
032: }
033:
034: public void setBody(TemplateBody aBody) {
035: theBody = aBody;
036: }
037:
038: public void addElement(TemplateElement anElement) {
039: if (theElements.contains(anElement))
040: theElements.remove(anElement);
041:
042: theElements.add(anElement);
043: }
044:
045: public void removeElement(TemplateElement anElement) {
046: theElements.remove(anElement);
047: }
048:
049: public TemplateBody getBody() {
050: return theBody;
051: }
052:
053: public List getElements() {
054: return theElements;
055: }
056:
057: public void accept(Visitor aTemplateVisitor) {
058: ((TemplateVisitor) aTemplateVisitor).visitTemplate(this );
059: }
060:
061: public String toString() {
062: return new ContentRenderer(this ).getResult();
063: }
064:
065: public TemplateElement getElementForId(Object anId) {
066: List theStoredElements = getElements();
067: for (Iterator i = theStoredElements.iterator(); i.hasNext();) {
068: TemplateElement theElement = (TemplateElement) i.next();
069: if (theElement.getId().equals(anId))
070: return theElement;
071: }
072:
073: return null;
074: }
075:
076: public Object clone() throws CloneNotSupportedException {
077: DefaultTemplate theNewTemplate = (DefaultTemplate) super
078: .clone();
079:
080: theNewTemplate.theElements = new Vector();
081: for (Iterator i = theElements.iterator(); i.hasNext();)
082: theNewTemplate.theElements.add(((PublicCloneable) i.next())
083: .clone());
084:
085: theNewTemplate.theBody = (TemplateBody) theBody.clone();
086:
087: return theNewTemplate;
088: }
089:
090: public void setElements(Vector vector) {
091: theElements = vector;
092: }
093:
094: public TemplateElement getElementAt(int i) {
095: return (TemplateElement) getElements().get(i);
096: }
097:
098: public int getElementCount() {
099: return getElements().size();
100: }
101: }
|