Commit 0f1b0626 authored by Jérôme Euzenat's avatar Jérôme Euzenat
Browse files

Completely re-implemented the merge

parent dc4813ab
/**
* $Id: concat.java,v 1.1 2002-06-25 10:01:01 jerome Exp $
* $Id: concat.java,v 1.2 2002-06-27 16:28:44 jerome Exp $
*
* Transmorpher
*
* Copyright (C) 2001-2002 Fluxmedia and INRIA Rhône-Alpes.
* Copyright (C) 2001 Fluxmedia and INRIA Rhône-Alpes.
*
* http://www.fluxmedia.fr - http://transmorpher.inrialpes.fr
*
......@@ -21,66 +21,172 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/**
* This class based on the TProcessBasic allow to define
* a Connector. A connector is a N -> 1 element.
* It 's allow to merge a set of ContentHandler flow
* @author Laurent Tardif (laurent.tardif@inrialpes.fr)
* @since jdk 1.2 / SAX 2.0
@see fr.fluxmedia.transmorpher.TProcessFactory.OneMixer
@see fr.fluxmedia.transmorpher.TProcessFactory.MultipleMixer
@see fr.fluxmedia.transmorpher.TProcessFactory.ProcessBasic
*/
* Concatenate homogeneous XML file
*
* @author laurent.tardif@inrialpes.fr
* @date 10 02 2001
* @see SAX 2.0 && JDK 1.3
*/
package fr.fluxmedia.transmorpher.stdlib ;
// Imported transmorpher classes
import fr.fluxmedia.transmorpher.TProcessFactory.*;
import fr.fluxmedia.transmorpher.Files.ReadWrite;
import fr.fluxmedia.transmorpher.Utils.Parameters;
// Imported SAX classes
import fr.fluxmedia.transmorpher.TProcessFactory.*;
// Imported SAX CLASSES
import org.xml.sax.SAXException;
import org.xml.sax.ContentHandler;
import org.xml.sax.Attributes;
import org.xml.sax.Locator ;
// java classes
import java.util.Hashtable;
public final class concat extends TConnector {
/** The multiple mixer which realize the concatenation */
MultipleMixer iMM = null;
public concat(String[] pIn, String[] pOut,Parameters pParam) {
super(pIn,pOut,pParam);
// The first current mixer is the first one
iMM = new MultipleMixer(iNbIn);
iMM.getMixer(0).setCurrent(true);
}
/** Allow to set the content handler on Mixer for out port */
public final void setContentHandler(ContentHandler pContentHandler ) {
iMM.setContentHandler(pContentHandler);
}
/** Allow to get the content handler for in port */
public final ContentHandler getContentHandler( ) {
return iMM.getContentHandler();
}
public void generatePort(){
if(nameFather==null) {
for (int i=0;i<iNbIn; i++) {
iListIn[i] = new XML_Port(nameIn[i],this,iMM.getMixer(i),i,XML_Port.IN);
}
iListOut[0]= new XML_Port(nameOut[0],this,this,0,XML_Port.OUT);
} else {
for (int i=0;i<iNbIn; i++) {
iListIn[i] = new XML_Port(nameFather+"-"+nameIn[i],this,iMM.getMixer(i),i,XML_Port.IN);
}
iListOut[0]= new XML_Port(nameFather+"-"+nameOut[0],this,this,0,XML_Port.OUT);
} //end if
} //end proc
public final class concat extends TMerger {
/** The constructor */
public concat(String[] pIn, String[] pOut,Parameters pParam) {
super(pIn,pOut,pParam,(TmHandler)new concatHandler());
((concatHandler)getManagingHandler()).setOwner(this);
}
/** Is this the last handler */
public final boolean isLastHandler() {
return ( iCurrentHandler == iNbIn-1 );
//return ( m == getHandler(iNbIn-1));
}
/** Is this the first Handler? */
public final boolean isFirstHandler() {
return ( iCurrentHandler == 0 );
//return ( m == getHandler(0));
}
} //end class
/** concatHandler does the real handling of SAX events.
*/
final class concatHandler implements TmHandler {
/** true if the content handler is the current one*/
boolean isCurrent = false ;
/** true if the mixer is finished */
boolean isDone = false ;
/** the manager */
concat iOwner = null;
/** parenthesis rank */
int rank = 0;
/** the constructor */
public concatHandler () {
rank = 0;
}
void setOwner ( concat pOwner ) {
iOwner = pOwner ;
}
/** The startElement command */
public final void startElement(String ns,String localName,String name, Attributes atts) throws SAXException {
rank++;
// Do not include the opening tag unless it is in the first input
if( rank != 1 || iOwner.isFirstHandler() ){
iOwner.getContentHandler().startElement(ns,localName,name,atts);
}
}
/** The endElement command */
public final void endElement(String ns,String localName,String name) throws SAXException {
// Do not include the closing tag unless it is in the last input
if( rank != 1 || iOwner.isLastHandler() ){
iOwner.getContentHandler().endElement(ns,localName,name);
}
rank--;
}
/** The startDocument command */
public final void startDocument() throws SAXException {
if( iOwner.isFirstHandler() ){
iOwner.getContentHandler().startDocument();
}
}
/** The setDocumentLocator command */
public final void setDocumentLocator(Locator locator) {
iOwner.getContentHandler().setDocumentLocator(locator);
}
/** The endDocument command */
public final void endDocument() throws SAXException {
if (iOwner.isLastHandler()) {
iOwner.getContentHandler().endDocument();
}
isDone = true;
}
/** The skippedEntity command */
public final void skippedEntity(java.lang.String name) throws SAXException{
iOwner.getContentHandler().skippedEntity(name);
}
/** The processingInstruction command */
public final void processingInstruction(java.lang.String target, java.lang.String data) throws SAXException{
if( iOwner.isFirstHandler() ){
iOwner.getContentHandler().processingInstruction(target,data);
}
}
/** The ignorableWhitespace command */
public final void ignorableWhitespace(char[] ch, int start, int length) throws SAXException{
iOwner.getContentHandler().ignorableWhitespace(ch,start,length);
}
/** The characters command */
public final void characters(char[] ch, int start, int length) throws SAXException{
iOwner.getContentHandler().characters(ch,start,length);
/*
String toto = "";
for (int i=start; i<length+start; i++) toto+=ch[i];
System.out.println("Handler . characters ; " + toto );
*/
}
/** The startPrefixMapping command */
public final void startPrefixMapping(java.lang.String prefix, java.lang.String uri) throws SAXException{
iOwner.getContentHandler().startPrefixMapping(prefix,uri);
}
/** The endPrefixMapping command */
public final void endPrefixMapping(java.lang.String prefix) throws SAXException{
iOwner.getContentHandler().endPrefixMapping(prefix);
}
/** set the curent attribut */
public final void setCurrent (boolean pCurrent) {
isCurrent = pCurrent ;
}
/** Set the done attribute */
public final void setDone (boolean pDone) {
isDone = pDone ;
}
/** Test if the mixer is done */
public final boolean isDone() {
return isDone ;
}
/** test if the mixer is the current mixer */
public final boolean isCurrent() {
return isCurrent ;
}
} //end class
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