Commit 16ccdd24 authored by Fabien Triolet's avatar Fabien Triolet
Browse files

Changed parameters passing in TLoop.

Added a new iterator
parent 6ed014c5
/*
* $Id: ParametersIterator.java,v 1.1 2002-11-13 15:43:41 triolet Exp $
*
* Transmorpher
*
* Copyright (C) 2002 Fluxmedia and INRIA Rhône-Alpes.
*
* http://www.fluxmedia.fr - http://transmorpher.inrialpes.fr
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* 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.tmcontrib.iterator;
// Imported Transmorpher classes
import fr.fluxmedia.transmorpher.engine.TIterator;
import fr.fluxmedia.transmorpher.utils.Parameters;
import fr.fluxmedia.transmorpher.utils.StringParameters;
import java.util.Enumeration;
// Imported Java classes
import java.util.NoSuchElementException;
/**
* An iterator which returns a new parameter value
*
*@author triolet
*/
public final class ParametersIterator implements TIterator {
private Parameters param;
private String name = null;
private String type = "string";
private Enumeration paramNames = null;
/**
*The constructor
*
*@param n Description of the Parameter
*@param p Description of the Parameter
*/
public ParametersIterator(String n, Parameters p) {
param = p;
name = n;
init(p);
}
/**
*Static initialization is currently not used
*
*@param p Description of the Parameter
*/
public void staticInit(Parameters p) {
}
/**
* The initializer
*
*@param p Description of the Parameter
*/
public void init(Parameters p) {
param = p.bindParameters(param);
paramNames = param.getNames();
}
/**
* Gets the name attribute of the ParametersIterator object
*
*@return The name value
*/
public String getName() {
return name;
}
/**
*Is this the last value
*
*@return Description of the Return Value
*/
public final boolean hasMoreElements() {
return (boolean)paramNames.hasMoreElements();
}
/**
* The next parameter value
*
*@return Description of the Return Value
*/
public final Object nextElement() {
return (Object)param.getParameter((String)paramNames.nextElement());
}
/**
* Gets the type attribute of the ParametersIterator object
*
*@return The type value
*/
public String getType() {
return type;
}
}//end class
/**
* $Id: TLoop.java,v 1.2 2002-11-07 14:31:11 triolet Exp $
* $Id: TLoop.java,v 1.3 2002-11-13 15:43:41 triolet Exp $
*
* Transmorpher
*
......@@ -28,12 +28,12 @@ package fr.fluxmedia.transmorpher.engine;
import fr.fluxmedia.transmorpher.engine.LoopHandler;
import fr.fluxmedia.transmorpher.engine.TIterator;
import fr.fluxmedia.transmorpher.utils.Parameters;
import fr.fluxmedia.transmorpher.utils.TMRuntimeException;
import fr.fluxmedia.transmorpher.utils.TMException;
import fr.fluxmedia.transmorpher.utils.StringParameters;
import fr.fluxmedia.transmorpher.stdlib.WriteFile;
import fr.fluxmedia.transmorpher.utils.Parameters;
import fr.fluxmedia.transmorpher.utils.StringParameters;
import fr.fluxmedia.transmorpher.utils.TMException;
import fr.fluxmedia.transmorpher.utils.TMRuntimeException;
// Imported java.io classes
import java.io.IOException;
......@@ -69,46 +69,74 @@ import org.xml.sax.helpers.XMLReaderFactory;
*/
public final class TLoop extends TProcessComposite {
/**Controller Handler */
/**
*Controller Handler
*/
LoopManagerHandler managers[];
/**In ports of this process */
/**
*In ports of this process
*/
String iListLocalIn[] = null;
/**Out ports of this process */
/**
*Out ports of this process
*/
String iListLocalOut[] = null;
/**Buf ports of this process */
/**
*Buf ports of this process
*/
String iListLocalBuf[] = null;
/**List of inner processes */
/**
*List of inner processes
*/
Vector listOfProcess = null;
/** Buf name */
/**
* Buf name
*/
String[] nameBuf = null;
/** Buf ports of this process */
/**
* Buf ports of this process
*/
XML_Port[] iListBuf = null;
/** true if it's first loop */
/**
* true if it's first loop
*/
boolean isFirstLoop = true;
/** flag for iterators, if one of them is finished then its value is true */
/**
* flag for iterators, if one of them is finished then its value is true
*/
boolean stop = false;
/** number of call to manage method */
/**
* number of call to manage method
*/
int numberOfManagers = 0;
/** counter of loop. */
/**
* counter of loop.
*/
int loopCounter = 0;
/** List of iterator */
/**
* List of iterator
*/
Vector iterators;
/** List of inner serializer */
/**
* List of inner serializer
*/
Vector listOfSerializer;
/** the list of PortProcess buf */
/**
* the list of PortProcess buf
*/
protected Hashtable listOfProcessBuf = null;
/**
......@@ -125,10 +153,10 @@ public final class TLoop extends TProcessComposite {
*@exception IOException Description of the Exception
*/
public TLoop(String[] pIn, String[] pOut, String[] pBuf, Parameters pParam, StringParameters staticAttributes)
throws TransformerException,
TransformerConfigurationException,
SAXException,
IOException {
throws TransformerException,
TransformerConfigurationException,
SAXException,
IOException {
super(pIn, pOut, pParam);
// managers creation.
managers = new LoopManagerHandler[nameIn.length];
......@@ -148,9 +176,12 @@ public final class TLoop extends TProcessComposite {
/**
* links ports and creates feedbacks.
*
*@param process The current process to link to the others
*@param process The current process to link to the others
*@exception TMRuntimeException Description of the Exception
*@exception TMException Description of the Exception
*@exception SAXException Description of the Exception
*/
public void bindPorts(TProcess process) throws TMRuntimeException, TMException, SAXException {
public void bindPorts(TProcess process) throws TMRuntimeException, TMException, SAXException {
//store process in order to reset them at the next loop.
if (isFirstLoop) {
listOfProcess.add(process);
......@@ -161,8 +192,8 @@ public final class TLoop extends TProcessComposite {
this.addChannel(new TChannel("_null_", process, null));
} else {
listOfProcessOut.put(process.getNameOut(i), process);
TProcess isSameIn = (TProcess) listOfProcessIn.get(process.getNameOut(i));
TProcess isBuf = (TProcess) listOfProcessBuf.get(process.getNameOut(i));
TProcess isSameIn = (TProcess)listOfProcessIn.get(process.getNameOut(i));
TProcess isBuf = (TProcess)listOfProcessBuf.get(process.getNameOut(i));
if ((isSameIn != null)) {
this.addChannel(new TChannel(process.getNameOut(i), process, isSameIn));
listOfProcessIn.remove(process.getNameOut(i));
......@@ -198,8 +229,8 @@ public final class TLoop extends TProcessComposite {
for (int i = 0; i < process.getNameIn().length; i++) {
listOfProcessIn.put(process.getNameIn(i), process);
TProcess isSameOut = (TProcess) listOfProcessOut.get(process.getNameIn(i));
TProcess isBuf = (TProcess) listOfProcessBuf.get(process.getNameIn(i));
TProcess isSameOut = (TProcess)listOfProcessOut.get(process.getNameIn(i));
TProcess isBuf = (TProcess)listOfProcessBuf.get(process.getNameIn(i));
if (isSameOut != null) {
if (isBuf == null) {
this.addChannel(new TChannel(process.getNameIn(i), isSameOut, process));
......@@ -230,7 +261,7 @@ public final class TLoop extends TProcessComposite {
} else {// may be a composite port
for (int i1 = 0; i1 < iListLocalIn.length; i1++) {
if (process.getNameIn(i).equals(iListLocalIn[i1])) {
managers[i1].loopHandler.setInnerHandler((ContentHandler) process.getIn(i).getContent());
managers[i1].loopHandler.setInnerHandler((ContentHandler)process.getIn(i).getContent());
XML_Port port = new XML_Port(process.getNameIn(i), this, managers[i1], i1, XML_Port.IN);
iListIn[i1] = port;
}//end if
......@@ -282,15 +313,19 @@ public final class TLoop extends TProcessComposite {
* Initializes all inner processes for a new loop. Due to a xalan bug,
* TransformerHandlerImpl can be use only once. So we have to create a new one
* at each loop.
*
*@exception TMRuntimeException Description of the Exception
*@exception TMException Description of the Exception
*@exception SAXException Description of the Exception
*/
public void reset() throws TMRuntimeException, TMException, SAXException {
listOfChannel = new Hashtable();
isFirstLoop = false;
for (int i = 0; i < listOfProcess.size(); i++) {
TProcess process = (TProcess) listOfProcess.elementAt(i);
process.reset();
bindPorts(process);
}//end for
public void reset() throws TMRuntimeException, TMException, SAXException {
listOfChannel = new Hashtable();
isFirstLoop = false;
for (int i = 0; i < listOfProcess.size(); i++) {
TProcess process = (TProcess)listOfProcess.elementAt(i);
process.reset();
bindPorts(process);
}//end for
}//end reset
/**
......@@ -301,11 +336,11 @@ public final class TLoop extends TProcessComposite {
*@param i manager position.
*/
public void setContentHandler(ContentHandler c, int i) {
managers[i].loopHandler.setOutputHandler((ContentHandler) c);
managers[i].loopHandler.setOutputHandler((ContentHandler)c);
}
/**
* Adds an Iterator to the Loop. If the iterator to add is an instance of fixpointIterator, TestHandler are used in each
* Adds an Iterator to the Loop. If the iterator to add is an instance of fixpointIterator, TestHandler are used in each
* managers of this loop instead of LoopHandler.
*
*@param iterator The iterator to be added to this Loop
......@@ -340,59 +375,63 @@ public final class TLoop extends TProcessComposite {
public void addSerializer(TProcess process) {
listOfSerializer.add(process);
}
private boolean isReady(){
boolean test = false;
numberOfManagers++;
if (numberOfManagers == managers.length)
test=true;
/**
* Gets the ready attribute of the TLoop object
*
*@return The ready value
*/
private boolean isReady() {
boolean test = false;
numberOfManagers++;
if (numberOfManagers == managers.length) {
test = true;
}
return test;
}
/**
* Manages the loop. When all the iterators have called this methods and if
* they all have a next element , a new loop is started . If one of them is
* finished, loop is ended .
*/
public void manage() {
String fileName="";
String number="";
String fileName = "";
Parameters iteratorParameters = new Parameters();
try {//maybe try should not be here.
/* numberOfManagers++;
//waiting for end of all loop.
if (numberOfManagers == managers.length) { */
if (isReady()){
//all loop have called this method and are ready to start a new loop. So now ,It's time to test iterators values
if (isReady()) {
//all loop have called this method and are ready to start a new loop. Now ,It's time to test iterators values
for (int i = 0; i < iterators.size(); i++) {
TIterator iterator = (TIterator) iterators.elementAt(i);
TIterator iterator = (TIterator)iterators.elementAt(i);
if (!(iterator.hasMoreElements())) {
stop = true;
} else {
if (!(iterator.getType().equals("fixpoint"))){
if (iterator.getType().equals("file")){
fileName=(String)iterator.nextElement();
}
else {
if (!(iterator.getType().equals("fixpoint"))) {
if (iterator.getType().equals("file")) {
fileName = (String)iterator.nextElement();
}
else {
iteratorParameters.setParameter(iterator.getName(), iterator.nextElement());
}
else
number=(String)iterator.nextElement();
}
/* if (iterator instanceof fileIterator){
fileName=(String)iterator.nextElement();
} */
else
}
else {
iterator.nextElement();
}
}
}
// testing difference between last input and output. If no difference, stop loop.
int counter = 0;
for (int i = 0; i < managers.length; i++) {
if (managers[i].loopHandler instanceof TestHandler) {
if (!(((TestHandler) managers[i].loopHandler).isDiff())) {
counter ++;
if (!(((TestHandler)managers[i].loopHandler).isDiff())) {
counter++;
}
if (counter == managers.length) {
stop = true;
}
if(counter==managers.length)
stop=true;
}
}
if (!stop) {// each managers starts a new loop
......@@ -401,27 +440,39 @@ public final class TLoop extends TProcessComposite {
if (loopCounter != 1) {
this.reset();
}
for (int j=0;j<listOfSerializer.size();j++){
for (int i = 0; i < iterators.size(); i++) {
TIterator iterator = (TIterator) iterators.elementAt(i);
String n = fileName;
// System.out.println("SERIALIZER :"+n);
if (iterator.getType().equals("file"))
((TSerializer)listOfSerializer.get(j)).setParameter(iterator.getName(),n.substring(fileName.lastIndexOf('/')+1));
else if (!(iterator.getType().equals("fixpoint"))){
((TSerializer)listOfSerializer.get(j)).setParameter(iterator.getName(),number);
for (int j = 0; j < listOfProcess.size(); j++) {
TProcess process = (TProcess)listOfProcess.get(j);
for (int i = 0; i < iterators.size(); i++) {
TIterator iterator = (TIterator)iterators.elementAt(i);
String n = fileName;
// System.out.println("SERIALIZER :"+n);
if (iterator.getType().equals("file")) {
if (!(process instanceof TReader))
process.setParameter(iterator.getName(), n.substring(fileName.lastIndexOf('/') + 1));
else
process.setParameter("file", fileName);
} else if (!(iterator.getType().equals("fixpoint"))) {
process.setParameters(iteratorParameters);
}
}
}
((TSerializer)listOfSerializer.get(j)).setOutputStream();
if (process instanceof TProcessBasic) {
((TProcessBasic)process).initParameters();
}
/* if (process instanceof TTransformation) {
((TTransformation)process).initParameters();
} */
//}
}
for (int i = 0; i < managers.length; i++) {
//System.out.println("NEW LOOP " + loopCounter);
managers[i].loopHandler.newLoop();
}
for (int i=0;i<listOfGenerator.size();i++){
}
for (int i = 0; i < listOfGenerator.size(); i++) {
//System.out.println("GENERATOR :"+fileName);
((TReader)listOfGenerator.get(i)).execProcess(fileName);
((TReader)listOfGenerator.get(i)).execProcess();
}
for (int i = 0; i < managers.length; i++) {
//System.out.println("FLUSH BUFFER ");
......@@ -435,7 +486,7 @@ public final class TLoop extends TProcessComposite {
}
}
} catch (Exception e) {
System.out.println("[TLoop manage()] "+e);
System.out.println("[TLoop manage()] " + e);
e.printStackTrace();
}
}
......@@ -449,17 +500,25 @@ public final class TLoop extends TProcessComposite {
*/
final class LoopManagerHandler implements ContentHandler {
/** the owner */
/**
* the owner
*/
TLoop iOwner = null;
/** the loop handler to manage */
/**
* the loop handler to manage
*/
LoopHandler loopHandler;
//TestHandler loopHandler;
/** a buffer for the output of inner process of the loop */
/**
* a buffer for the output of inner process of the loop
*/
BufferingHandler buffer;
/** number of loop */
/**
* number of loop
*/
int nbLoop;
/**
......@@ -474,9 +533,9 @@ final class LoopManagerHandler implements ContentHandler {
buffer = new BufferingHandler(this);
}
/**
* Changes loop handler to test handler.
*/
/**
* Changes loop handler to test handler.
*/
void setTestHandler() {
loopHandler = null;
loopHandler = new TestHandler();
......@@ -591,9 +650,9 @@ final class LoopManagerHandler implements ContentHandler {
*/
public final void characters(char[] ch, int start, int length) throws SAXException {
/* char[] tmp = new char[length + start];
for (int i = start; i < length + start; i++) {
tmp[i] = ch[i];
} */
*for (int i = start; i < length + start; i++) {
*tmp[i] = ch[i];
*} */
loopHandler.characters(ch, start, length);
}
......
/**
* $Id: TProcessBasic.java,v 1.1 2002-11-06 14:08:21 serge Exp $
* $Id: TProcessBasic.java,v 1.2 2002-11-13 15:43:41 triolet Exp $
*
* Transmorpher
*
......@@ -48,7 +48,12 @@ public abstract class TProcessBasic extends TProcess_Impl implements Runnable{
protected Thread procThread = null ;
protected boolean isThread = false ;
/**
* Description of the Field
*/
protected Parameters param = null;
/** the empty constructor*/
public TProcessBasic () {}
......@@ -61,6 +66,7 @@ public abstract class TProcessBasic extends TProcess_Impl implements Runnable{
/** The constructor */
protected TProcessBasic (String[] pIn, String[] pOut,Parameters pParam) {
this(pIn,pOut);
param=pParam;
type = (String)pParam.getParameter("type");
setParameters(pParam);
}
......@@ -97,4 +103,7 @@ public abstract class TProcessBasic extends TProcess_Impl implements Runnable{
procThread = new Thread(this);
}
}
public void initParameters(){
}
}
/*
* $Id: TReader.java,v 1.1 2002-11-06 14:08:21 serge Exp $
* $Id: TReader.java,v 1.2 2002-11-13 15:43:41 triolet Exp $
*
* Transmorpher
*
......@@ -22,198 +22,215 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
package fr.fluxmedia.transmorpher.engine;
import fr.fluxmedia.transmorpher.utils.Parameters;
import fr.fluxmedia.transmorpher.utils.StringParameters;
import fr.fluxmedia.transmorpher.utils.SystemResources;
// Imported Transmorpher classes
import fr.fluxmedia.transmorpher.utils.TMRuntimeException;
import fr.fluxmedia.transmorpher.utils.Parameters;
import fr.fluxmedia.transmorpher.utils.StringParameters;
import fr.fluxmedia.transmorpher.utils.SystemResources;