KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > speedo > generation > mivisitor > AbstractMetaInfoVisitor


1 /**
2  * Copyright (C) 2001-2004 France Telecom R&D
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 package org.objectweb.speedo.generation.mivisitor;
19
20 import org.objectweb.speedo.api.SpeedoException;
21 import org.objectweb.speedo.api.SpeedoProperties;
22 import org.objectweb.speedo.generation.api.SpeedoCompilerParameter;
23 import org.objectweb.speedo.generation.lib.AbstractGeneratorComponent;
24 import org.objectweb.speedo.metadata.SpeedoClass;
25 import org.objectweb.speedo.metadata.SpeedoExtension;
26 import org.objectweb.speedo.metadata.SpeedoField;
27 import org.objectweb.speedo.metadata.SpeedoPackage;
28 import org.objectweb.speedo.metadata.SpeedoTuple;
29 import org.objectweb.speedo.metadata.SpeedoXMLDescriptor;
30 import org.objectweb.util.monolog.api.BasicLevel;
31
32 /**
33  *
34  * @author S.Chassande-Barrioz
35  */

36 public class AbstractMetaInfoVisitor
37         extends AbstractGeneratorComponent
38         implements MetaInfoVisitor{
39
40     public final static String JavaDoc LOGGER_NAME =
41             SpeedoProperties.LOGGER_NAME + ".generation.mivisitor";
42
43     /**
44      * The next MetaInfoVisitor instance. If the field is null that means there
45      * is no next. Then the current MetaInfoVisitor is the last.
46      */

47     MetaInfoVisitor mim;
48
49     /**
50      * builds a MetaInfoVisitor which is the last of the chain
51      */

52     public AbstractMetaInfoVisitor() {
53         mim = null;
54     }
55
56     /**
57      * builds a MetaInfoVisitor which is the last of the chain
58      */

59     public AbstractMetaInfoVisitor(MetaInfoVisitor mim) {
60         this.mim = mim;
61     }
62
63     protected String JavaDoc getLoggerName() {
64         return LOGGER_NAME;
65     }
66
67     public boolean init() throws SpeedoException {
68         logger = scp.loggerFactory.getLogger(getLoggerName());
69         debug = logger != null && logger.isLoggable(BasicLevel.DEBUG);
70         return !scp.getXmldescriptor().isEmpty();
71     }
72
73     public void process() throws SpeedoException {
74         visitCompilerParameter(scp);
75     }
76     
77     // IMPLEMENTATION OF THE METHODS FROM THE MetaInfoVisitor INTERFACE //
78
//------------------------------------------------------------------//
79

80     public MetaInfoVisitor getNext() {
81         return mim;
82     }
83
84     public void setNext(MetaInfoVisitor next) {
85         mim = next;
86     }
87
88     public void visitCompilerParameter(SpeedoCompilerParameter scp) throws SpeedoException {
89         if (logger == null) {
90             setLogger(scp.loggerFactory.getLogger(getLoggerName()));
91         }
92         if (mim != null) {
93             mim.visitCompilerParameter(scp);
94         }
95     }
96
97     public void visitXml(SpeedoXMLDescriptor xml) throws SpeedoException {
98         if (mim != null) {
99             mim.visitXml(xml);
100         }
101     }
102
103     public void visitPackage(SpeedoPackage sp) throws SpeedoException {
104         if (mim != null) {
105             mim.visitPackage(sp);
106         }
107     }
108
109     public void visitClass(SpeedoClass sc) throws SpeedoException {
110         if (mim != null) {
111             mim.visitClass(sc);
112         }
113     }
114
115     public void visitField(SpeedoField sf) throws SpeedoException {
116         if (mim != null) {
117             mim.visitField(sf);
118         }
119     }
120
121     public void visitExtension(SpeedoExtension se) throws SpeedoException {
122         if (mim != null) {
123             mim.visitExtension(se);
124         }
125     }
126
127     /**
128      * Helper method able to find the SpeedoClass hosting a Speedo meta object.
129      * if the specified object is not a child (directly or not) of a SpeedoClass
130      * then a null value is returned.
131      * @param o is a child (directly or not) of SpeedoClass
132      * (supported types: SpeedoClass, SpeedoField, SpeedoTuple, SpeedoExtension)
133      */

134     protected static SpeedoClass getSpeedoClass(Object JavaDoc o) {
135         if (o instanceof SpeedoClass) {
136             return (SpeedoClass) o;
137         } else if (o instanceof SpeedoField) {
138             return ((SpeedoField) o).jdoClass;
139         } else if (o instanceof SpeedoTuple) {
140             return ((SpeedoTuple) o).jdoField.jdoClass;
141         } else if (o instanceof SpeedoExtension) {
142             return getSpeedoClass(((SpeedoExtension) o).jdoElement);
143         } else {//SpeedoPackage, SpeedoXMLDescriptor, ...
144
return null;
145         }
146     }
147 }
148
Popular Tags