001: /**
002: * Copyright (C) 2001-2004 France Telecom R&D
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 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: */package org.objectweb.speedo.generation.mivisitor;
018:
019: import java.util.Iterator;
020:
021: import org.objectweb.speedo.api.SpeedoException;
022: import org.objectweb.speedo.generation.api.SpeedoCompilerParameter;
023: import org.objectweb.speedo.lib.Personality;
024: import org.objectweb.speedo.metadata.SpeedoClass;
025: import org.objectweb.speedo.metadata.SpeedoElement;
026: import org.objectweb.speedo.metadata.SpeedoExtension;
027: import org.objectweb.speedo.metadata.SpeedoField;
028: import org.objectweb.speedo.metadata.SpeedoIndex;
029: import org.objectweb.speedo.metadata.SpeedoPackage;
030: import org.objectweb.speedo.metadata.SpeedoXMLDescriptor;
031: import org.objectweb.speedo.sequence.lib.SpeedoSequence;
032: import org.objectweb.util.monolog.api.BasicLevel;
033:
034: /**
035: * This class is the default implementation of the Speedo Meta information
036: * visitor. By default it does nothing and follow the Meta information visit on
037: * the next visitor.
038: *
039: * @author S.Chassande-Barrioz
040: */
041: public class MetaInfoVisitorImpl extends AbstractMetaInfoVisitor {
042:
043: /**
044: * builds a MetaInfoVisitor which is the last of the chain
045: */
046: public MetaInfoVisitorImpl(Personality p) {
047: super (p);
048: }
049:
050: /**
051: * builds a MetaInfoVisitor which is the last of the chain
052: */
053: public MetaInfoVisitorImpl(MetaInfoVisitor mim, Personality p) {
054: super (mim, p);
055: }
056:
057: public void visitCompilerParameter(SpeedoCompilerParameter cp)
058: throws SpeedoException {
059: super .visitCompilerParameter(cp);
060: Iterator xmlIt = cp.getXmldescriptor().values().iterator();
061: while (xmlIt.hasNext()) {
062: SpeedoXMLDescriptor xml = (SpeedoXMLDescriptor) xmlIt
063: .next();
064: visitXml(xml);
065: }
066: visitEnd();
067: }
068:
069: public void visitXml(SpeedoXMLDescriptor xml)
070: throws SpeedoException {
071: super .visitXml(xml);
072: Iterator packIt = xml.packages.values().iterator();
073: while (packIt.hasNext()) {
074: SpeedoPackage pack = (SpeedoPackage) packIt.next();
075: visitPackage(pack);
076: }
077: }
078:
079: public void visitPackage(SpeedoPackage sp) throws SpeedoException {
080: logger.log(BasicLevel.DEBUG, "Visit package " + sp.name);
081: super .visitPackage(sp);
082: visitExtension(sp);
083: for (Iterator classIt = sp.classes.values().iterator(); classIt
084: .hasNext();) {
085: SpeedoClass clazz = (SpeedoClass) classIt.next();
086: visitClass(clazz);
087: }
088: for (Iterator it = sp.sequences.values().iterator(); it
089: .hasNext();) {
090: SpeedoSequence sequence = (SpeedoSequence) it.next();
091: visitSequence(sequence, sp);
092: }
093: }
094:
095: public void visitClass(SpeedoClass sc) throws SpeedoException {
096: logger.log(BasicLevel.DEBUG, "Visit Class " + sc.name);
097: super .visitClass(sc);
098: visitExtension(sc);
099: for (Iterator fieldIt = sc.fields.values().iterator(); fieldIt
100: .hasNext();) {
101: SpeedoField sf = (SpeedoField) fieldIt.next();
102: visitField(sf);
103: }
104: for (Iterator it = sc.getTableIndexes().iterator(); it
105: .hasNext();) {
106: SpeedoIndex si = (SpeedoIndex) it.next();
107: visitIndex(si, sc.moPackage);
108: }
109: visitEndClass(sc);
110: }
111:
112: public void visitField(SpeedoField sf) throws SpeedoException {
113: logger.log(BasicLevel.DEBUG, "Visit field " + sf.name);
114: super .visitField(sf);
115: visitExtension(sf);
116: }
117:
118: private void visitExtension(SpeedoElement se)
119: throws SpeedoException {
120: if (se.jdoExtension.size() == 0) {
121: logger.log(BasicLevel.DEBUG, "no extensionto visit");
122: } else {
123: for (int i = 0; i < se.jdoExtension.size(); i++) {
124: SpeedoExtension ext = (SpeedoExtension) se.jdoExtension
125: .get(i);
126: logger.log(BasicLevel.DEBUG, "Visit extension "
127: + ext.key + "=" + ext.value);
128: visitExtension(ext);
129: }
130: }
131: }
132:
133: }
|