Commit b2c90a3c authored by Fabien Triolet's avatar Fabien Triolet
Browse files

Added javadoc comments, copyright metion for 2003, changed names of some fields for more

comprehensive names ( type instead of t)
parent cb743950
/**
* $Id: ApplyExternal.java,v 1.3 2002-11-25 16:09:11 triolet Exp $
*
/*
* $Id: ApplyExternal.java,v 1.4 2003-01-28 15:40:53 triolet Exp $
*
* Transmorpher
*
* Copyright (C) 2001-2002 Fluxmedia and INRIA Rhône-Alpes.
* Copyright (C) INRIA Rhône-Alpes, 2003.
*
* http://www.fluxmedia.fr - http://transmorpher.inrialpes.fr
*
......@@ -21,87 +22,90 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
package fr.fluxmedia.transmorpher.graph;
import java.io.IOException;
import fr.fluxmedia.transmorpher.utils.Writer;
import fr.fluxmedia.transmorpher.engine.TProcess;
import fr.fluxmedia.transmorpher.engine.TProcessComposite;
import fr.fluxmedia.transmorpher.utils.Writer;
import java.io.IOException;
/**
* Transmorpher graph call node interface
* This class allows to instanciate a call for an object able to apply a transformation on the SAX events flow.
*
*@author Jerome.Euzenat@inrialpes.fr
*@since jdk 1.3 / SAX 2.0
* <br/><code><i><br/>
* &lt;apply-external id="FormatHTML" type="xslt" in="X2" out="Z34"&gt;<br/>
* &lt;with-param name="file"&gt;../samples/biblio/xslt/form-hauth.xsl&lt;/with-param&gt;<br/>
* &lt;/apply-external&gt;<br/>
* </i></code></br>
*@author Jerome.Euzenat@inrialpes.fr
*@since jdk 1.3 / SAX 2.0
*/
public class ApplyExternal extends ApplyImpl {
/**
* Constructor for the ApplyExternal object
* Creates a simple instance of ApplyExternal
*/
public ApplyExternal() {
this((String) null, (String) null);
this((String)null, (String)null);
}
/**
* Constructor for the ApplyExternal object
* Creates an instance of ApplyExternal with an id and a type
*
*@param n ApplyExternal name
*@param t ApplyExternal type
*@param id The id of this instance
*@param type The type of this instance
*/
public ApplyExternal(String n, String t) {
this(n, t, (String) null);
public ApplyExternal(String id, String type) {
this( id, type, (String)null);
}
/**
* Constructor for the ApplyExternal object
* Creates an instance of ApplyExternal with an id,a type and a file name
*
*@param n ApplyExternal name
*@param t ApplyExternal type
*@param f Description of the Parameter
*@param id The id of this instance
*@param type The type of this instance
*@param file The file name
*/
public ApplyExternal(String n, String t, String f) {
this(n, t, f, null);
public ApplyExternal(String id, String type, String file) {
this( id, type, file, null);
}
/**
* Constructor for the ApplyExternal object
* Creates an instance of ApplyExternal with an id,a type and a process
*
*@param n ApplyExternal name
*@param t ApplyExternal type
*@param p
*@param id The id of this instance
*@param type The type of this instance
*@param process The process that owns this instance
*/
public ApplyExternal(String n, String t, Process p) {
this(n, t, null, p);
public ApplyExternal(String id, String type, Process process) {
this(id, type, null, process);
}
/**
* Constructor for the ApplyExternal object
* Creates an instance of ApplyExternal with an id,a type, a file name and a process
*
*@param n ApplyExternal name
*@param t ApplyExternal type
*@param p
*@param f Description of the Parameter
*@param id The id of this instance
*@param type The type of this instance
*@param file The file name
*@param process The process that owns this instance
*/
public ApplyExternal(String n, String t, String f, Process p) {
this(n, t, f, p, 0, 0);
public ApplyExternal(String id, String type, String file, Process process) {
this(id, type, file, process, 0, 0);
}
/**
* Constructor for the ApplyExternal object
* Creates an instance of ApplyExternal with an id,a type, a file name, a process, a number of in and a number of out
*
*@param n ApplyExternal name
*@param t ApplyExternal type
*@param file
*@param p Description of the Parameter
*@param in Number of ins
*@param out Nomber of outs
*@param id The id of this instance
*@param type The type of this instance
*@param file The file name
*@param process The process that owns this instance
*@param in The umber of in ports
*@param out The number of out ports
*/
public ApplyExternal(String n, String t, String file, Process p, int in, int out) {
super(n, t, p, null, in, out);
public ApplyExternal(String id, String type, String file, Process process, int in, int out) {
super(id, type, process, null, in, out);
if (file != null) {
parameters.setParameter("file", file);
}
......@@ -119,7 +123,7 @@ public class ApplyExternal extends ApplyImpl {
}
/**
* Generates XML for this component
* Prints an XML description of this instance
*/
public void generateXML() {
System.out.print(" <apply-external id=\"" + id + "\" type=\"" + getType() + "\" ");
......@@ -137,38 +141,38 @@ public class ApplyExternal extends ApplyImpl {
}//end generate XML
/**
* Creates a new TApplyProcess corresponding to this ApplyProcess.
* Creates a new TApplyProcess corresponding to this ApplyProcess instance
*
*@param currentProcess The container of this component.
*@param iProcessFactory Used to create the TApplyProcess.
*/
public final void createProcess(TProcessComposite currentProcess) {
String[] vPortIn = inPorts().toStringList();
String[] vPortOut = outPorts().toStringList();
String className = this.getProcess().getTransmorpher().getClassForType(getType());
Object [] params = {(Object)vPortIn,(Object)vPortOut, (Object)getParameters(), (Object)getAttributes()};
TProcess vCurrent = this.newProcess(className,params);
Object[] params = {(Object)vPortIn, (Object)vPortOut, (Object)getParameters(), (Object)getAttributes()};
TProcess vCurrent = this.newProcess(className, params);
currentProcess.addProcess(vCurrent);
update(vCurrent);
}//end proc
/**
* Generates java code of this component
* Generates a java code description of this instance
*
*@param file the file to write in.
*@param file a writer used for printing the code in a file
*@exception IOException when IO errors occur
*/
public void generateJavaCode(Writer file) throws IOException {
file.writeln();
file.writeln(4, "//------------------ Generation of ApplyExternal " + getId() + " -------------------");
generatePorts(file);
generateParameters(file);
String className = this.getProcess().getTransmorpher().getClassForType(getType());
file.writeln();
file.writeln(4, "//------------------ Generation of ApplyExternal " + getId() + " -------------------");
generatePorts(file);
generateParameters(file);
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();
file.writeln(4, "tmCurrentCompositeProcess.addProcess(tmCurrentProcess);");
file.writeln(4, "tmCurrentProcess = new " + className + "(portIn,portOut,tmParameters,tmAttributes);");
//+",tmAttributes);");
file.writeln(4, "tmCurrentProcess.setName(\"" + getId() + "\");");
file.writeln();
file.writeln(4, "tmCurrentCompositeProcess.addProcess(tmCurrentProcess);");
}//end proc
}
/**
* $Id: ApplyImpl.java,v 1.1 2002-11-06 14:08:21 serge Exp $
/*
* $Id: ApplyImpl.java,v 1.2 2003-01-28 15:40:53 triolet Exp $
*
* Transmorpher
*
* Copyright (C) 2001 Fluxmedia and INRIA Rhône-Alpes.
* Copyright (C) INRIA Rhône-Alpes, 2003
*
* http://www.fluxmedia.fr - http://transmorpher.inrialpes.fr
*
......@@ -21,53 +22,84 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
package fr.fluxmedia.transmorpher.graph;
/**
* Transmorpher graph call node interface
*
* @author Jerome.Euzenat@inrialpes.fr
* @since jdk 1.3 / SAX 2.0
*/
* This class is an helper class for the Apply Call .
* Methods to manage the reference (name of the transformation to call) are provided
*
*
*@author Jerome.Euzenat@inrialpes.fr
*@since jdk 1.3 / SAX 2.0
*/
public abstract class ApplyImpl extends CallImpl {
package fr.fluxmedia.transmorpher.graph ;
// JE: LT has discarded the ref as class attribute, but I would prefer it...
// String ref = null;
public abstract class ApplyImpl extends CallImpl {
/**
* Creates an instance of ApplyImpl with an id, a type, a process, a reference ,a nuber of in and a number of out
*
*@param id The id of this instance
*@param type The type of this instance
*@param process The process that owns this instance
*@param reference The name of the transformation called by this instance
*@param in The number of in ports
*@param out The number of out ports
*/
public ApplyImpl(String id, String type, Process process, String reference, int in, int out) {
super(id, type, process, in, out);
// ref = r;
if (reference != null) {
attributes.setParameter("ref", reference);
}
}
// JE: LT has discarded the ref as class attribute, but I would prefer it...
// String ref = null;
public ApplyImpl (String n, String t, Process p, String r, int in, int out){
super(n, t, p, in, out);
// ref = r;
if(r!=null)
iAttributes.setParameter("ref",r);
}
/**
* Propagates the nullity of all its output to all its input.
* This is a basic implementation that does not take into account
* the structure of the applied stuff and can be overloaded
*
*@param out Description of the Parameter
*@param in Description of the Parameter
*/
public void retroNull(PortList out, PortList in) {
nullified = true;
for (int i = 1; nullified && i != out.length(); i++) {
if (!(out.getPort(i).getChannel().nullifiedP())) {
nullified = false;
}
}// end for
for (int i = 1; i != in.length(); i++) {
in.getPort(i).getChannel().setVisited();
if (nullified) {
in.getPort(i).getChannel().nullify();
}
}//end for
visited = true;
}
/** Propagates the nullity of all its output to all its input.
* This is a basic implementation that does not take into account
* the structure of the applied stuff and can be overloaded */
public void retroNull( PortList out, PortList in) {
nullified = true;
for ( int i=1; nullified && i != out.length() ; i++){
if ( !(out.getPort(i).getChannel().nullifiedP()) )
nullified = false;
} // end for
for ( int i=1; i != in.length() ; i++) {
in.getPort(i).getChannel().setVisited();
if ( nullified ) in.getPort(i).getChannel().nullify();
} //end for
visited = true;
}
public String getRef(){
// return ref;
return iAttributes.getStringParameter("ref");
}
/**
* Gets the name of the transformation called by this ApplyImpl object
*
*@return The reference value
*/
public String getRef() {
// return ref;
return attributes.getStringParameter("ref");
}
public void setRef(String r){
// ref = r;
if(r!=null)
iAttributes.setParameter("ref",r);
}
/**
* Sets the name of the transformation this ApplyImpl object has to call
*
*@param reference The new reference value
*/
public void setRef(String reference) {
// ref = r;
if (reference != null) {
attributes.setParameter("ref", reference);
}
}
}
/**
* $Id: ApplyProcess.java,v 1.3 2002-11-25 16:09:11 triolet Exp $
/*
* $Id: ApplyProcess.java,v 1.4 2003-01-28 15:40:53 triolet Exp $
*
* Transmorpher
*
* Copyright (C) 2001-2002 Fluxmedia and INRIA Rhne-Alpes.
* Copyright (C) INRIA Rhne-Alpes, 2003.
*
* http://www.fluxmedia.fr - http://transmorpher.inrialpes.fr
*
......@@ -22,150 +23,214 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/**
* Transmorpher graph call node interface
*
* @author Jerome.Euzenat@inrialpes.fr
* @since jdk 1.3 / SAX 2.0
*/
package fr.fluxmedia.transmorpher.graph;
package fr.fluxmedia.transmorpher.graph ;
import fr.fluxmedia.transmorpher.engine.TApplyProcess;
import fr.fluxmedia.transmorpher.engine.TProcess;
import fr.fluxmedia.transmorpher.engine.TProcessComposite;
import fr.fluxmedia.transmorpher.utils.LinearIndexedStruct;
import fr.fluxmedia.transmorpher.utils.Writer;
import java.util.ListIterator;
import java.io.IOException;
import fr.fluxmedia.transmorpher.utils.Writer;
import fr.fluxmedia.transmorpher.utils.LinearIndexedStruct ;
import fr.fluxmedia.transmorpher.engine.TProcessComposite;
import fr.fluxmedia.transmorpher.engine.TApplyProcess;
import fr.fluxmedia.transmorpher.engine.TProcess;
import java.util.ListIterator;
/**
*@author Jerome.Euzenat@inrialpes.fr
*@since jdk 1.3 / SAX 2.0
*/
public class ApplyProcess extends ApplyImpl {
public ApplyProcess(String n, String t){
this(n,t,null,null);
}
public ApplyProcess(String n, String t, String pr){
this(n,t,null,pr);
}
public ApplyProcess(String n, String t, Process p){
this(n,t,p,null,0,0);
}
public ApplyProcess(String n, String t, Process p, String pr){
this(n,t,p,pr,0,0);
}
public ApplyProcess (String n, String t, Process p, String pr, int in, int out){
super(n, t, p, pr, in, out);
}
/** ask a nullify call to the called process */
public void retroNull( PortList out, PortList in) {
// JE: check is it is a Process
Process called = (Process)(getProcess().getTransmorpher().findTransformation(getRef()));
nullified = called.retroNull(out, in, true);
visited = true;
update(null);
}
public void generateXML (){
System.out.print(" <apply-process id=\""+id+"\" ref=\""+getRef()+"\" ");
System.out.print("in=\"");
inPorts.generateXML();
System.out.print("\" out=\"");
outPorts.generateXML();
if ( parameters.isEmpty() ){
System.out.println("\"/>");
} else {
System.out.println("\">");
parameters.generateXMLCalls();
System.out.println(" </apply-process>");
}
} //end generate XML
public final void createProcess(TProcessComposite currentProcess){
try{
String[] vPortIn = inPorts().toStringList();
String[] vPortOut = outPorts().toStringList();
// get the name corresponding to the generated stylesheet and pass it in parameter
String ref = getAttributes().getStringParameter("ref");
Transmorpher t = getProcess().getTransmorpher() ;
Process p = (Process)(t.findTransformation(ref));
LinearIndexedStruct vCalls = p.getCalls();
//System.out.println("[ExecutionStructure]ApplyProcess : findTransformation"
// +((fr.fluxmedia.transmorpher.graph.Process)iTransmorpher.getTransformation(ref)));
TProcessComposite vCurrent =
(TProcessComposite)new TApplyProcess(vPortIn,vPortOut,
getParameters(),
getAttributes());
PortList LocIn = p.inPorts();
PortList LocOut= p.outPorts();
((TApplyProcess)vCurrent).setLocalName(LocIn.getNames(),LocOut.getNames());
for( ListIterator l = vCalls.listIterator(); l.hasNext() ; ){
((Call)l.next()).createProcess(vCurrent);
}
currentProcess.addProcess(vCurrent);
update(vCurrent);
/**
*Constructor for the ApplyProcess object
*
*@param n Description of the Parameter
*@param t Description of the Parameter
*/
public ApplyProcess(String n, String t) {
this(n, t, null, null);
}
catch(Exception e){
System.out.println("[ApplyProcess] Error : cannot create Process");
System.out.println("[ApplyProcess] "+e);
/**
*Constructor for the ApplyProcess object
*
*@param n Description of the Parameter
*@param t Description of the Parameter
*@param pr Description of the Parameter
*/
public ApplyProcess(String n, String t, String pr) {
this(n, t, null, pr);
}
} //end proc
public void setUp() {
if( getProcess().getTransmorpher().findTransformation(getRef()) == null ){
System.err.println("warning : unknown process : "+getRef());
/**
*Constructor for the ApplyProcess object
*
*@param n Description of the Parameter
*@param t Description of the Parameter
*@param p Description of the Parameter
*/
public ApplyProcess(String n, String t, Process p) {
this(n, t, p, null, 0, 0);
}
update(null);
} //end setUp
/** This is the main problematic aspect:
There is a possible recursion in Process calls: they should thus be stacked for working correctly
**/
public void generateJavaCode(Writer file) throws IOException {
String r = getAttributes().getStringParameter("ref");
Transmorpher tr = getProcess().getTransmorpher() ;
fr.fluxmedia.transmorpher.graph.Process processDef = ((fr.fluxmedia.transmorpher.graph.Process)tr.findTransformation(r));
file.writeln();
file.writeln(4,"//------------------ Generation of ApplyProcess "+getId()+" -------------------");
generatePorts(file);
generateParameters(file);
file.writeln(4,"tmCurrentProcess = new TApplyProcess(portIn,portOut,tmParameters,tmAttributes);");
file.writeln(4,"tmCurrentProcess.setName(\""+getId()+"\");");
file.writeln();
file.writeln(4,"tmCurrentCompositeProcess.addProcess(tmCurrentProcess);");
file.writeln();
// JE: Here we stack the tmCurrentCompositeProcess
file.writeln(4,"tmProcessStack.push((Object)tmCurrentCompositeProcess);");
file.writeln(4,"tmCurrentCompositeProcess = (TProcessComposite)tmCurrentProcess;");
file.writeln();
// JE: Change of port names ?
file.writeln(4,"LocIn = new String["+ processDef.inPorts().getNames().length+"];");
for(int i=0;i<processDef.inPorts().length();i++){
file.writeln(4,"LocIn["+i+"]=\""+processDef.inPorts().getNames()[i]+"\";");
/**
*Constructor for the ApplyProcess object
*
*@param n Description of the Parameter
*@param t Description of the Parameter
*@param p Description of the Parameter
*@param pr Description of the Parameter
*/
public ApplyProcess(String n, String t, Process p, String pr) {
this(n, t, p, pr, 0, 0);
}
file.writeln(4,"LocOut = new String["+processDef.outPorts().getNames().length+"];");
for(int i=0;i<processDef.outPorts().length();i++){
file.writeln(4,"LocOut["+i+"]=\""+processDef.outPorts().getNames()[i]+"\";");
/**
*Constructor for the ApplyProcess object
*
*@param n Description of the Parameter
*@param t Description of the Parameter
*@param p Description of the Parameter
*@param pr Description of the Parameter
*@param in Description of the Parameter
*@param out Description of the Parameter
*/
public ApplyProcess(String n, String t, Process p, String pr, int in, int out) {
super(n, t, p, pr, in, out);
}
file.writeln(4,"((TApplyProcess)tmCurrentProcess).setLocalName(LocIn,LocOut);");
file.writeln(4,"//------------------ Generation of process body for "+getId()+" -------------------");
for( ListIterator l = processDef.getCalls().listIterator(); l.hasNext() ; ){
((Call)l.next()).generateJavaCode(file);
/**
* ask a nullify call to the called process
*
*@param out Description of the Parameter
*@param in Description of the Parameter
*/
public void retroNull(PortList out, PortList in) {
// JE: check is it is a Process
Process called = (Process)(getProcess().getTransmorpher().findTransformation(getRef()));
nullified = called.retroNull(out, in, true);
visited = true;
update(null);
}