KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > barracuda > contrib > sam > models > TemplateModelDecorator


1 /*
2  * Copyright (C) 2003 Stefan Armbruster [stefan@armbruster-it.de]
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * $Id: TemplateModelDecorator.java,v 1.4 2004/02/01 05:16:27 christianc Exp $
19  */

20 package org.enhydra.barracuda.contrib.sam.models;
21
22 import java.util.*;
23 import org.enhydra.barracuda.core.comp.*;
24 import org.enhydra.barracuda.core.comp.model.*;
25
26 //import org.enhydra.barracuda.core.event.*;
27

28 /** Abstract Decorator class for using cascading models.
29  * It implements the well known decorator pattern.
30  * This class is subclassed by concrete Decorators, see {@link MapDecorator}.<br>
31  * TemplateModelDecorator is capable of handling {@link
32  * org.enhydra.barracuda.core.comp.TemplateModel } as well as {@link
33  * org.enhydra.barracuda.core.comp.IterativeModel }. <br>
34  * <B>Implementation detail:</B>
35  * Nearly all calls are passed directly to the decorated model. If the decorated
36  * model implements {@link org.enhydra.barracuda.core.comp.IterativeModel }, also
37  * all iterative methods are passed through.<br>
38  * Subclasses should override getItem, in order to modify the standard behavior.
39  * @author Stefan Armbruster
40  * @version $Id: TemplateModelDecorator.java,v 1.4 2004/02/01 05:16:27 christianc Exp $
41  */

42 public abstract class TemplateModelDecorator implements TemplateModel, IterativeModel {
43
44     /** reference to the decorated model */
45     protected TemplateModel _templateModel;
46
47     public TemplateModelDecorator(TemplateModel tm) {
48         _templateModel = tm;
49     }
50
51     public String JavaDoc getName() {
52         return _templateModel.getName();
53     }
54
55     public boolean processDirective(TemplateDirective td) {
56         return _templateModel.processDirective(td);
57     }
58
59     //csc_030703.1 - added
60
public Object JavaDoc getItem(TemplateDirective td) {
61         return _templateModel.getItem(td);
62     }
63
64 // abstract public Object getItem(String key);
65

66
67
68     // Implementation of Model interface
69
public void addModelListener(ModelListener ml) {
70         _templateModel.addModelListener(ml);
71     }
72
73     public void removeModelListener(ModelListener ml) {
74      _templateModel.removeModelListener(ml);
75     }
76
77     // implementation of Contextual interface
78
public ViewContext getViewContext() {
79         return _templateModel.getViewContext();
80     }
81
82     public void setViewContext(ViewContext vc) {
83         _templateModel.setViewContext(vc);
84     }
85
86     // implementation of IterativeModel
87

88     private boolean isIterativeModel() {
89         return _templateModel instanceof IterativeModel;
90     }
91
92     public boolean hasNext() {
93         if (isIterativeModel()) {
94             return ((IterativeModel)_templateModel).hasNext();
95         } else {
96             return false;
97         }
98     }
99
100     public void loadNext() {
101         if (isIterativeModel()) {
102             ((IterativeModel)_templateModel).loadNext();
103         }
104     }
105
106     public void postIterate() {
107         if (isIterativeModel()) {
108             ((IterativeModel)_templateModel).postIterate();
109         }
110     }
111
112     public void preIterate() {
113         if (isIterativeModel()) {
114             ((IterativeModel)_templateModel).preIterate();
115         }
116     }
117
118 }
119
Popular Tags