KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > kilim > model > mapping > TreeModelMapper


1 /**
2  * Copyright (C) 2002 Kelua SA
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 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
19 package org.objectweb.kilim.model.mapping;
20
21 import java.util.Stack JavaDoc;
22
23 import org.objectweb.kilim.KilimException;
24 import org.objectweb.kilim.tools.KilimTraceTreeModel;
25
26 /**
27  * @author horn
28  */

29 public class TreeModelMapper implements Mapper {
30     /** constants for a value source */
31     public static final int SOURCE = 0;
32     /** constants for an action trigger */
33     public static final int ACTION = 1;
34     
35     private Mapper wrappedMapper;
36     private KilimTraceTreeModel treeModel;
37     private int seqNumber = 0;
38    
39     /**
40      * Method JavaLogMapper.
41      * @param aMapper :
42      */

43     public TreeModelMapper(Mapper aMapper) {
44         wrappedMapper = aMapper;
45         treeModel = new KilimTraceTreeModel();
46     }
47     
48     /**
49      * Method JavaLogMapper.
50      */

51     public TreeModelMapper() {
52         this(null);
53     }
54     
55     /**
56      * Method getTreeModel.
57      * @return KilimTraceTreeModel
58      */

59     public KilimTraceTreeModel getTraceTree() {
60         return treeModel;
61     }
62     
63     /**
64      * @see org.objectweb.kilim.model.mapping.Mapper#enterContext(Object)
65      */

66     public void enterContext(MappingContext aContext) throws KilimException {
67         Stack JavaDoc stk = aContext.getCallStack();
68         int index = stk.size();
69         Object JavaDoc parent = (index >= 2) ? stk.get(index - 2) : null;
70         Object JavaDoc child = (index >= 1) ? stk.get(index - 1) : null;
71         treeModel.addChild(parent, child);
72     }
73     
74     /**
75      * @see org.objectweb.kilim.model.mapping.Mapper#leaveContext()
76      */

77     public void leaveContext(MappingContext aContext) throws KilimException { }
78
79     private void setSeqNumberAndMode(MappingContext aContext, int aMode) {
80         Stack JavaDoc stk = aContext.getCallStack();
81         int index = stk.size();
82         Object JavaDoc object = (index >= 1) ? stk.get(index - 1) : null;
83         treeModel.setSeqNumberAndMode(object, seqNumber, aMode);
84         seqNumber++;
85     }
86     /**
87      * @see org.objectweb.kilim.model.mapping.KilimMapper#getGetterValue(Object, boolean, String, MappingContext)
88      */

89     public Object JavaDoc getGetterValue (Object JavaDoc aSupport, boolean isStatic, String JavaDoc fieldName, MappingContext aContext) throws KilimException {
90         Object JavaDoc resultValue = null;
91         setSeqNumberAndMode(aContext, SOURCE);
92         if (wrappedMapper != null) {
93             resultValue = wrappedMapper.getGetterValue (aSupport, isStatic, fieldName, aContext);
94         }
95         return resultValue;
96     }
97     
98     /**
99      * @see org.objectweb.kilim.model.mapping.KilimMapper#executeSetter(Object, boolean, String, Object, MappingContext)
100      */

101     public void executeSetter(Object JavaDoc aSupport, boolean isStatic, String JavaDoc fieldName, Object JavaDoc toBeSet, MappingContext aContext) throws KilimException {
102         setSeqNumberAndMode(aContext, ACTION);
103         if (wrappedMapper != null) {
104             wrappedMapper.executeSetter(aSupport, isStatic, fieldName, toBeSet, aContext);
105         }
106     }
107
108     /**
109      * @see org.objectweb.kilim.model.mapping.KilimMapper#getMethodValue(Object, boolean, String, Object[], String[], MappingContext)
110      */

111     public Object JavaDoc getMethodValue(Object JavaDoc aSupport, boolean isStatic, String JavaDoc aMethodName, Object JavaDoc[] paramObjects, String JavaDoc[] typeNames, MappingContext aContext) throws KilimException {
112         Object JavaDoc resultValue = null;
113         setSeqNumberAndMode(aContext, SOURCE);
114         if (wrappedMapper != null) {
115             resultValue = wrappedMapper.getMethodValue (aSupport, isStatic, aMethodName, paramObjects, typeNames, aContext);
116         }
117         return resultValue;
118     }
119     
120     /**
121      * @see org.objectweb.kilim.model.mapping.KilimMapper#executeMethod(Object, boolean, String, Object[], String[], MappingContext)
122      */

123     public void executeMethod(Object JavaDoc aSupport, boolean isStatic, String JavaDoc aMethodName, Object JavaDoc[] paramObjects, String JavaDoc[] typeNames, MappingContext aContext) throws KilimException {
124         setSeqNumberAndMode(aContext, ACTION);
125         if (wrappedMapper != null) {
126             wrappedMapper.executeMethod (aSupport, isStatic, aMethodName, paramObjects, typeNames, aContext);
127         }
128
129     }
130             
131     /**
132      * @see org.objectweb.kilim.model.mapping.KilimMapper#getConstructorValue(Class, Object[], String[], MappingContext)
133      */

134     public Object JavaDoc getConstructorValue(Class JavaDoc aClass, Object JavaDoc[] paramObjects, String JavaDoc[] typeNames, MappingContext aContext) throws KilimException {
135         Object JavaDoc resultValue = null;
136         setSeqNumberAndMode(aContext, SOURCE);
137         if (wrappedMapper != null) {
138             resultValue = wrappedMapper.getConstructorValue(aClass, paramObjects, typeNames, aContext);
139         }
140         return resultValue;
141     }
142     
143     /**
144      * @see org.objectweb.kilim.model.mapping.KilimMapper#executeConstructor(Class, Object[], String[], MappingContext)
145      */

146     public void executeConstructor(Class JavaDoc aClass, Object JavaDoc[] paramObjects, String JavaDoc[] typeNames, MappingContext aContext) throws KilimException {
147         setSeqNumberAndMode(aContext, ACTION);
148         if (wrappedMapper != null) {
149             wrappedMapper.executeConstructor(aClass, paramObjects, typeNames, aContext);
150         }
151     }
152
153     /**
154      * @see org.objectweb.kilim.model.mapping.KilimMapper#getExternalValue(Object, MappingContext)
155      */

156     public Object JavaDoc getExternalValue(Object JavaDoc aValue, MappingContext aContext) throws KilimException {
157         Object JavaDoc resultValue = null;
158         setSeqNumberAndMode(aContext, SOURCE);
159         if (wrappedMapper != null) {
160             resultValue = wrappedMapper.getExternalValue(aValue, aContext);
161         }
162         return resultValue;
163     }
164     
165     /**
166      * @see org.objectweb.kilim.model.mapping.KilimMapper#getPropertyValue(Object, MappingContext)
167      */

168     public Object JavaDoc getPropertyValue(Object JavaDoc aValue, MappingContext aContext) throws KilimException {
169         Object JavaDoc resultValue = null;
170         setSeqNumberAndMode(aContext, SOURCE);
171         if (wrappedMapper != null) {
172             resultValue = wrappedMapper.getPropertyValue(aValue, aContext);
173         }
174         return resultValue;
175     }
176         
177     /**
178      * @see org.objectweb.kilim.model.mapping.KilimMapper#getClassValue(String, MappingContext)
179      */

180     public Object JavaDoc getClassValue(String JavaDoc aClassName, MappingContext aContext) throws KilimException {
181         Object JavaDoc resultValue = null;
182         setSeqNumberAndMode(aContext, SOURCE);
183         if (wrappedMapper != null) {
184             resultValue = wrappedMapper.getClassValue(aClassName, aContext);
185         }
186         return resultValue;
187     }
188     
189     /**
190      * @see org.objectweb.kilim.model.mapping.KilimMapper#getEventSourceValue(MappingContext)
191      */

192     public Object JavaDoc getEventSourceValue(MappingContext aContext) throws KilimException {
193         Object JavaDoc resultValue = null;
194         setSeqNumberAndMode(aContext, SOURCE);
195         if (wrappedMapper != null) {
196             resultValue = wrappedMapper.getEventSourceValue(aContext);
197         }
198         return resultValue;
199     }
200     
201     /**
202      * @see org.objectweb.kilim.model.mapping.KilimMapper#getNullElementValue(MappingContext)
203      */

204     public Object JavaDoc getNullElementValue(MappingContext aContext) throws KilimException {
205         Object JavaDoc resultValue = null;
206         setSeqNumberAndMode(aContext, SOURCE);
207         if (wrappedMapper != null) {
208             resultValue = wrappedMapper.getNullElementValue(aContext);
209         }
210         return resultValue;
211
212     }
213
214     /**
215      * @see org.objectweb.kilim.model.mapping.Mapper#executeNullElement(MappingContext)
216      */

217     public void executeNullElement(MappingContext aContext) throws KilimException {
218         setSeqNumberAndMode(aContext, ACTION);
219         if (wrappedMapper != null) {
220             wrappedMapper.executeNullElement(aContext);
221         }
222
223     }
224 }
Popular Tags