/**
* Copyright (C) 2001-2004 France Telecom R&D
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.objectweb.speedo.generation.mivisitor;
import java.util.Iterator;
import org.objectweb.speedo.api.SpeedoException;
import org.objectweb.speedo.generation.api.SpeedoCompilerParameter;
import org.objectweb.speedo.lib.Personality;
import org.objectweb.speedo.metadata.SpeedoClass;
import org.objectweb.speedo.metadata.SpeedoElement;
import org.objectweb.speedo.metadata.SpeedoExtension;
import org.objectweb.speedo.metadata.SpeedoField;
import org.objectweb.speedo.metadata.SpeedoIndex;
import org.objectweb.speedo.metadata.SpeedoPackage;
import org.objectweb.speedo.metadata.SpeedoXMLDescriptor;
import org.objectweb.speedo.sequence.lib.SpeedoSequence;
import org.objectweb.util.monolog.api.BasicLevel;
/**
* This class is the default implementation of the Speedo Meta information
* visitor. By default it does nothing and follow the Meta information visit on
* the next visitor.
*
* @author S.Chassande-Barrioz
*/
public class MetaInfoVisitorImpl extends AbstractMetaInfoVisitor {
/**
* builds a MetaInfoVisitor which is the last of the chain
*/
public MetaInfoVisitorImpl(Personality p) {
super(p);
}
/**
* builds a MetaInfoVisitor which is the last of the chain
*/
public MetaInfoVisitorImpl(MetaInfoVisitor mim, Personality p) {
super(mim, p);
}
public void visitCompilerParameter(SpeedoCompilerParameter cp) throws SpeedoException {
super.visitCompilerParameter(cp);
Iterator xmlIt = cp.getXmldescriptor().values().iterator();
while(xmlIt.hasNext()) {
SpeedoXMLDescriptor xml = (SpeedoXMLDescriptor) xmlIt.next();
visitXml(xml);
}
visitEnd();
}
public void visitXml(SpeedoXMLDescriptor xml) throws SpeedoException {
super.visitXml(xml);
Iterator packIt = xml.packages.values().iterator();
while(packIt.hasNext()) {
SpeedoPackage pack = (SpeedoPackage) packIt.next();
visitPackage(pack);
}
}
public void visitPackage(SpeedoPackage sp) throws SpeedoException {
logger.log(BasicLevel.DEBUG, "Visit package " + sp.name);
super.visitPackage(sp);
visitExtension(sp);
for(Iterator classIt = sp.classes.values().iterator();classIt.hasNext();) {
SpeedoClass clazz = (SpeedoClass) classIt.next();
visitClass(clazz);
}
for (Iterator it = sp.sequences.values().iterator(); it.hasNext();) {
SpeedoSequence sequence = (SpeedoSequence) it.next();
visitSequence(sequence, sp);
}
}
public void visitClass(SpeedoClass sc) throws SpeedoException {
logger.log(BasicLevel.DEBUG, "Visit Class " + sc.name);
super.visitClass(sc);
visitExtension(sc);
for(Iterator fieldIt = sc.fields.values().iterator(); fieldIt.hasNext();) {
SpeedoField sf = (SpeedoField) fieldIt.next();
visitField(sf);
}
for(Iterator it = sc.getTableIndexes().iterator(); it.hasNext(); ) {
SpeedoIndex si = (SpeedoIndex) it.next();
visitIndex(si, sc.moPackage);
}
visitEndClass(sc);
}
public void visitField(SpeedoField sf) throws SpeedoException {
logger.log(BasicLevel.DEBUG, "Visit field " + sf.name);
super.visitField(sf);
visitExtension(sf);
}
private void visitExtension(SpeedoElement se) throws SpeedoException {
if (se.jdoExtension.size() == 0) {
logger.log(BasicLevel.DEBUG, "no extensionto visit");
} else {
for(int i=0; i<se.jdoExtension.size(); i++) {
SpeedoExtension ext = (SpeedoExtension) se.jdoExtension.get(i);
logger.log(BasicLevel.DEBUG, "Visit extension "
+ ext.key + "=" + ext.value);
visitExtension(ext);
}
}
}
}