Commit 07149dec authored by Fabien Triolet's avatar Fabien Triolet
Browse files

Removed reference to TProcessFactory inside the java code generated by the compilation.

Introduced the use of XSLTC in TTransformation (not enabled yet : problems with Loop and
with regular expression)
parent 7dd3f94c
/**
* $Id: TTransformation.java,v 1.2 2002-11-13 15:43:41 triolet Exp $
* $Id: TTransformation.java,v 1.3 2002-11-22 16:07:33 triolet Exp $
*
* Transmorpher
*
......@@ -60,7 +60,7 @@ import javax.xml.transform.sax.TransformerHandler;
import javax.xml.transform.stream.StreamSource;
// Imported SAX classes
import java.util.Properties;
import org.xml.sax.SAXException;
/**
......@@ -96,6 +96,8 @@ public abstract class TTransformation extends TProcessBasic {
*/
private static Map cache = new HashMap();
protected SAXTransformerFactory tfactory = null;
/**
* The file in which the transformation is stored
*/
......@@ -214,7 +216,19 @@ public abstract class TTransformation extends TProcessBasic {
} catch (Exception e) {
}
}
protected SAXTransformerFactory getTransformerFactory() {
if (tfactory == null) {
String key = "javax.xml.transform.TransformerFactory";
String value = "org.apache.xalan.xsltc.trax.TransformerFactoryImpl";
Properties props = System.getProperties();
props.put(key, value);
System.setProperties(props);
tfactory = (SAXTransformerFactory)TransformerFactory.newInstance();
}
return tfactory;
}
/**
* generates ports for a TTranformer
*/
......
/**
* $Id: ApplyExternal.java,v 1.1 2002-11-06 14:08:21 serge Exp $
* $Id: ApplyExternal.java,v 1.2 2002-11-22 16:07:33 triolet Exp $
*
* Transmorpher
*
......@@ -164,7 +164,9 @@ public class ApplyExternal extends ApplyImpl {
file.writeln(4, "//------------------ Generation of ApplyExternal " + getId() + " -------------------");
generatePorts(file);
generateParameters(file);
file.writeln(4, "tmCurrentProcess = tmProcessFactory.newExternal(portIn,portOut,\"" + getType() + "\",tmParameters,tmAttributes);");
String className = this.getProcess().getTransmorpher().getClassForType(getType());
file.writeln(4, "tmCurrentProcess = new "+className+"(portIn,portOut,tmParameters,tmAttributes);");
//+",tmAttributes);");
file.writeln(4, "tmCurrentProcess.setName(\"" + getId() + "\");");
file.writeln();
......
/**
* $Id: ApplyProcess.java,v 1.1 2002-11-06 14:08:21 serge Exp $
* $Id: ApplyProcess.java,v 1.2 2002-11-22 16:07:33 triolet Exp $
*
* Transmorpher
*
......@@ -133,7 +133,7 @@ public class ApplyProcess extends ApplyImpl {
file.writeln(4,"//------------------ Generation of ApplyProcess "+getId()+" -------------------");
generatePorts(file);
generateParameters(file);
file.writeln(4,"tmCurrentProcess = tmProcessFactory.newApplyProcess(portIn,portOut,\""+getType()+"\",tmParameters,tmAttributes);");
file.writeln(4,"tmCurrentProcess = new TApplyProcess(portIn,portOut,tmParameters,tmAttributes);");
file.writeln(4,"tmCurrentProcess.setName(\""+getId()+"\");");
file.writeln();
file.writeln(4,"tmCurrentCompositeProcess.addProcess(tmCurrentProcess);");
......
/**
* $Id: ApplyQuery.java,v 1.1 2002-11-06 14:08:21 serge Exp $
* $Id: ApplyQuery.java,v 1.2 2002-11-22 16:07:33 triolet Exp $
*
* Transmorpher
*
......@@ -124,7 +124,8 @@ public class ApplyQuery extends ApplyImpl {
// Added just for being generated afterwards
getParameters().setParameter("file",f);
generateParameters(file);
file.writeln(4,"tmCurrentProcess = tmProcessFactory.newApplyQuery(portIn,portOut,\""+getType()+"\",tmParameters,tmAttributes);");
String className = this.getProcess().getTransmorpher().getClassForType(getType());
file.writeln(4,"tmCurrentProcess = new "+className+"(portIn,portOut,tmParameters,tmAttributes);");
file.writeln(4,"tmCurrentProcess.setName(\""+getId()+"\");");
file.writeln("");
file.writeln(4,"tmCurrentCompositeProcess.addProcess(tmCurrentProcess);");
......
/**
* $Id: ApplyRuleset.java,v 1.1 2002-11-06 14:08:21 serge Exp $
* $Id: ApplyRuleset.java,v 1.2 2002-11-22 16:07:33 triolet Exp $
*
* Transmorpher
*
......@@ -141,7 +141,7 @@ public class ApplyRuleset extends ApplyImpl {
// Added just for being generated afterwards
getParameters().setParameter("file",f);
generateParameters(file);
file.writeln(4,"tmCurrentProcess = tmProcessFactory.newApplyRuleset(portIn,portOut,\""+getType()+"\",tmParameters,tmAttributes);");
file.writeln(4,"tmCurrentProcess = new fr.fluxmedia.transmorpher.engine.TApplyRuleset(portIn,portOut,tmParameters,tmAttributes);");
file.writeln(4,"tmCurrentProcess.setName(\""+getId()+"\");");
file.writeln("");
file.writeln(4,"tmCurrentCompositeProcess.addProcess(tmCurrentProcess);");
......
/**
* $Id: Dispatch.java,v 1.1 2002-11-06 14:08:21 serge Exp $
* $Id: Dispatch.java,v 1.2 2002-11-22 16:07:33 triolet Exp $
*
* Transmorpher
*
......@@ -102,7 +102,9 @@ public class Dispatch extends CallImpl {
file.writeln(4,"//------------------ Generation of Dispatcher "+getId()+" -------------------");
generatePorts(file);
generateParameters(file);
file.writeln(4,"tmCurrentProcess = tmProcessFactory.newDispatcher(portIn,portOut,\""+getType()+"\",tmParameters);");
String className = this.getProcess().getTransmorpher().getClassForType(getType());
file.writeln(4,"tmCurrentProcess = new "+className+"(portIn,portOut,tmParameters);");
file.writeln(4,"tmCurrentProcess.setName(\""+getId()+"\");");
file.writeln();
file.writeln(4,"tmCurrentCompositeProcess.addProcess(tmCurrentProcess);");
......
/**
* $Id: Generate.java,v 1.1 2002-11-06 14:08:21 serge Exp $
* $Id: Generate.java,v 1.2 2002-11-22 16:07:33 triolet Exp $
*
* Transmorpher
*
......@@ -119,7 +119,8 @@ public class Generate extends CallImpl {
file.writeln(4,"//------------------ Generation of Generator "+getId()+" -------------------");
generatePorts(file);
generateParameters(file);
file.writeln(4,"tmCurrentProcess = tmProcessFactory.newGenerator(portOut,\""+getType()+"\",tmParameters,tmAttributes);");
String className = this.getProcess().getTransmorpher().getClassForType(getType());
file.writeln(4,"tmCurrentProcess = new "+className+"(portOut,tmParameters,tmAttributes);");
file.writeln(4,"tmCurrentProcess.setName(\""+getId()+"\");");
file.writeln("");
file.writeln(4,"tmCurrentCompositeProcess.addProcess(tmCurrentProcess);");
......
/**
* $Id: Iterator.java,v 1.1 2002-11-06 14:08:21 serge Exp $
* $Id: Iterator.java,v 1.2 2002-11-22 16:07:33 triolet Exp $
*
* Transmorpher
*
......@@ -173,8 +173,9 @@ public class Iterator {
file.writeln(4, "name=\"" + name + "\";");
file.writeln(4, "type=\"" + type + "\";");
generateParameters(file);
file.writeln(4, "iterator = tmProcessFactory.newIterator(name,type,tmParameters);");
String className = this.getRepeat().getProcess().getTransmorpher().getClassForType(getType());
file.writeln(4, "iterator = new "+className+"(name,tmParameters);");
file.writeln(4, "if (tmCurrentCompositeProcess instanceof TLoop) {");
file.writeln(8, "((TLoop) tmCurrentCompositeProcess).addIterator(iterator);");
file.writeln(4, "}");
......
/**
* $Id: Main.java,v 1.1 2002-11-06 14:08:21 serge Exp $
* $Id: Main.java,v 1.2 2002-11-22 16:07:33 triolet Exp $
*
* Transmorpher
*
......@@ -81,7 +81,7 @@ public class Main extends MainProcess {
public void generateMainHeader(Writer iFile) throws IOException {
iFile.writeln(2,"public static void main(String[] argc) throws Exception {");
iFile.writeln(4,"tmProcessFactory = new TProcessFactory(newDefexterns(),debug_mode);");
//iFile.writeln(4,"tmProcessFactory = new TProcessFactory(newDefexterns(),debug_mode);");
iFile.writeln(4,"tmProcessStack = new Stack();");
iFile.writeln(4,"vSR = new SystemResources();");
}
......@@ -101,7 +101,7 @@ public class Main extends MainProcess {
String key = (String)e.nextElement();
iFile.writeln(4,"p.setParameter(\""+key+"\", \""+(String)param.getParameter(key)+"\");");
}
iFile.writeln(4,"tmCurrentCompositeProcess = (TMain)tmProcessFactory.newMain(new String[0], new String[0], p);");
iFile.writeln(4,"tmCurrentCompositeProcess = (TMain)new TMain(p);");
for( ListIterator l = getCalls().listIterator(); l.hasNext() ; ){
((Call)l.next()).generateJavaCode(iFile);
}
......
/**
* $Id: MainProcess.java,v 1.1 2002-11-06 14:08:21 serge Exp $
* $Id: MainProcess.java,v 1.2 2002-11-22 16:07:33 triolet Exp $
*
* Transmorpher
*
......@@ -81,7 +81,7 @@ public abstract class MainProcess extends fr.fluxmedia.transmorpher.graph.Proces
iFile.writeln();
iFile.writeln(4," // global variable for the processFactory");
// BUG: This is not really compiling since stuff are created at runtime!
iFile.writeln(4,"static TProcessFactory tmProcessFactory = null;");
//iFile.writeln(4,"static TProcessFactory tmProcessFactory = null;");
iFile.writeln();
iFile.writeln(4,"private static LinearIndexedStruct newDefexterns(){");
iFile.writeln(6,"LinearIndexedStruct defs = new LinearIndexedStruct();");
......
/**
* $Id: Merge.java,v 1.1 2002-11-06 14:08:21 serge Exp $
* $Id: Merge.java,v 1.2 2002-11-22 16:07:33 triolet Exp $
*
* Transmorpher
*
......@@ -100,7 +100,8 @@ public class Merge extends CallImpl {
file.writeln(4,"//------------------ Generation of Merge "+getId()+" -------------------");
generatePorts(file);
generateParameters(file);
file.writeln(4,"tmCurrentProcess = tmProcessFactory.newConnector(portIn,portOut,\""+getType()+"\",tmParameters);");
String className = this.getProcess().getTransmorpher().getClassForType(getType());
file.writeln(4,"tmCurrentProcess = new "+className+"(portIn,portOut,tmParameters);");
file.writeln(4,"tmCurrentProcess.setName(\""+getId()+"\");");
file.writeln();
file.writeln(4,"tmCurrentCompositeProcess.addProcess(tmCurrentProcess);");
......
/**
* $Id: Repeat.java,v 1.1 2002-11-06 14:08:21 serge Exp $
* $Id: Repeat.java,v 1.2 2002-11-22 16:07:33 triolet Exp $
*
* Transmorpher
*
......@@ -177,7 +177,7 @@ public class Repeat extends CallImpl {
file.writeln(4,"//------------------ Generation of Repeat "+getId()+" -------------------");
generatePorts(file);
generateParameters(file);
file.writeln(4,"tmCurrentProcess = tmProcessFactory.newLoop(portIn,portOut,portBuf,tmParameters,tmAttributes);");
file.writeln(4,"tmCurrentProcess = new TLoop(portIn,portOut,portBuf,tmParameters,tmAttributes);");
file.writeln(4,"tmCurrentProcess.setName(\""+getId()+"\");");
file.writeln();
......
/**
* $Id: Serialize.java,v 1.2 2002-11-13 15:43:41 triolet Exp $
* $Id: Serialize.java,v 1.3 2002-11-22 16:07:33 triolet Exp $
*
* Transmorpher
*
......@@ -121,7 +121,9 @@ public class Serialize extends CallImpl {
file.writeln(4,"//------------------ Generation of Serializer "+getId()+" -------------------");
generatePorts(file);
generateParameters(file);
file.writeln(4,"tmCurrentProcess = tmProcessFactory.newSerializer(portIn,\""+getType()+"\",tmParameters,tmAttributes);");
String className = this.getProcess().getTransmorpher().getClassForType(getType());
file.writeln(4,"tmCurrentProcess = new "+className+"(portIn,tmParameters,tmAttributes);");
file.writeln(4,"tmCurrentProcess.setName(\""+getId()+"\");");
file.writeln();
file.writeln(4,"tmCurrentCompositeProcess.addProcess(tmCurrentProcess);");
......
/**
* $Id: Servlet.java,v 1.4 2002-11-21 08:04:36 triolet Exp $
* $Id: Servlet.java,v 1.5 2002-11-22 16:07:33 triolet Exp $
*
* Transmorpher
*
......@@ -96,7 +96,7 @@ public class Servlet extends MainProcess {
iFile.writeln(6,"root = context.getRealPath(\"/\");");
iFile.writeln(6,"vSR= new SystemResources();");
iFile.writeln(6,"tmProcessStack = new Stack();");
iFile.writeln(6,"tmProcessFactory = new TProcessFactory(newDefexterns(),debug_mode);");
//iFile.writeln(6,"tmProcessFactory = new TProcessFactory(newDefexterns(),debug_mode);");
iFile.writeln(4,"} catch (Exception TransformException) {");
iFile.writeln(4,"}");
iFile.writeln(2,"}");
......@@ -109,7 +109,7 @@ public class Servlet extends MainProcess {
iFile.writeln(2,"protected void doPost(HttpServletRequest req, HttpServletResponse res)");
iFile.writeln(4," throws ServletException, IOException {");
iFile.writeln();
iFile.writeln(4,"tmProcessFactory.initFactory(newDefexterns());");
//iFile.writeln(4,"tmProcessFactory.initFactory(newDefexterns());");
}
public void generateReadParameters(Writer iFile) throws IOException {
......@@ -137,12 +137,12 @@ public class Servlet extends MainProcess {
iFile.writeln(8,"servletParameters.setParameter(\""+key+"\",req.getParameter(\""+key+"\"));");
iFile.writeln(6,"};");
} //end for
iFile.writeln(8,"tmCurrentCompositeProcess = (TServlet)tmProcessFactory.newServlet(new String[0], new String[0], servletParameters);");
iFile.writeln(8,"tmCurrentCompositeProcess = (TServlet)new TServlet(servletParameters);");
for( ListIterator l = getCalls().listIterator(); l.hasNext() ; ){
((Call)l.next()).generateJavaCode(iFile);
}
// JE: warning, reuse of parameters
iFile.writeln(8,"setoutput(tmCurrentCompositeProcess,res);");
iFile.writeln(8,"setOutput(tmCurrentCompositeProcess,res);");
iFile.writeln(8,"tmCurrentCompositeProcess.bindParameters(servletParameters);");
iFile.writeln(8,"tmCurrentCompositeProcess.execProcess(false);");
......@@ -174,7 +174,7 @@ public class Servlet extends MainProcess {
}
public void generateSetOutput(Writer iFile)throws IOException{
iFile.writeln(2,"protected void setoutput(TProcessComposite tmCurrentCompositeProcess,HttpServletResponse res){");
iFile.writeln(2,"protected void setOutput(TProcessComposite tmCurrentCompositeProcess,HttpServletResponse res){");
iFile.writeln(4,"for (Enumeration e = tmCurrentCompositeProcess.getProcessBasic().elements() ; e.hasMoreElements() ;) {");
iFile.writeln(6,"boolean test=true;");
iFile.writeln(6,"TProcess_Impl process=(TProcess_Impl)e.nextElement();");
......
/*
* $Id: Transformer.java,v 1.1 2002-11-06 14:08:21 serge Exp $
* $Id: Transformer.java,v 1.2 2002-11-22 16:07:33 triolet Exp $
*
* Transmorpher
*
......@@ -80,7 +80,7 @@ public class Transformer extends MainProcess {
// JE: Here, this should not be main but:
iFile.writeln(2,"public void transform(Source in, Result out){");
//iFile.writeln(2,"public static void main(String[] args){");
iFile.writeln(4,"tmProcessFactory = new TProcessFactory(newDefexterns(),debug_mode);");
//iFile.writeln(4,"tmProcessFactory = new TProcessFactory(newDefexterns(),debug_mode);");
iFile.writeln(4,"tmProcessStack = new Stack();");
iFile.writeln(4,"vSR = new SystemResources();");
iFile.writeln();
......@@ -108,7 +108,7 @@ public class Transformer extends MainProcess {
String key = (String)e.nextElement();
iFile.writeln(4,"p.setParameter(\""+key+"\", \""+(String)param.getParameter(key)+"\");");
}
iFile.writeln(4,"tmCurrentCompositeProcess = (TMain)tmProcessFactory.newMain(new String[0], new String[0], p);");
iFile.writeln(4,"tmCurrentCompositeProcess = (TMain)new TMain(p);");
for( ListIterator l = getCalls().listIterator(); l.hasNext() ; ){
((Call)l.next()).generateJavaCode(iFile);
}
......
/**
* $Id: Transmorpher.java,v 1.3 2002-11-18 16:08:40 triolet Exp $
* $Id: Transmorpher.java,v 1.4 2002-11-22 16:07:33 triolet Exp $
*
* Transmorpher
*
......@@ -91,7 +91,7 @@ public class Transmorpher extends Observable {
/** the list of declared names of components */
protected LinearIndexedStruct defexterns = null ;
protected LinearIndexedStruct listOfType = null ;
protected int debug = 0;
protected String reloc = "";
......@@ -107,6 +107,8 @@ public class Transmorpher extends Observable {
defexterns = new LinearIndexedStruct();
imports = new LinkedList();
includes = new LinkedList();
if (listOfType==null)
initListOfType();
}
public Transmorpher(String n, String v, int d, boolean o){
......@@ -131,9 +133,27 @@ public class Transmorpher extends Observable {
defexterns = t.getDefexterns();
}
public final String getName(){
return name;
}
public void initListOfType(){
listOfType = new LinearIndexedStruct();
// Default merger/dispatchers
listOfType.add("broadcast", (Object)"fr.fluxmedia.transmorpher.stdlib.Broadcast");
listOfType.add("concat", (Object)"fr.fluxmedia.transmorpher.stdlib.Concat");
listOfType.add("wrap", (Object)"fr.fluxmedia.transmorpher.stdlib.Wrap");
// Default reader/writers
listOfType.add("readfile", (Object)"fr.fluxmedia.transmorpher.stdlib.ReadFile");
listOfType.add("writefile", (Object)"fr.fluxmedia.transmorpher.stdlib.WriteFile");
// These two should be replaced by two different classes...
listOfType.add("standardInput", (Object)"fr.fluxmedia.transmorpher.engine.TReader");
listOfType.add("standardOutput", (Object)"fr.fluxmedia.transmorpher.stdlib.StdOut");
// Default transformations
listOfType.add("xslt", (Object)"fr.fluxmedia.transmorpher.stdlib.XSLT");
listOfType.add("tmq", (Object)"fr.fluxmedia.transmorpher.stdlib.TMQuery");
listOfType.add("if", (Object)"fr.fluxmedia.transmorpher.stdlib.TestingDispatcher");
}
public final String getName(){
return name;
}
public final void setName(String n){
name = n;
......@@ -240,7 +260,15 @@ public class Transmorpher extends Observable {
notifyObservers(new TmActionImpl(TmActionImpl.REMOVE,this,trans,null,null));
}
public final String getClassForType(String name){
String className=null;
className=(String)listOfType.get(name);
if (className==null)
className=(String)defexterns.get(name);
return className;
}
public final String getExtern(String name){
return (String)defexterns.get(name);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment