|
From: Gerd M. <li...@us...> - 2001-06-01 16:55:40
|
Update of /cvsroot/tm4j/tm4j/src/com/techquila/topicmap/ozone
In directory usw-pr-cvs1:/tmp/cvs-serv15598
Added Files:
OzoneXTMBuilder.java OzoneXTMBuilderHelper.java
OzoneXTMBuilderHelperImpl.java
Log Message:
- initial check in
--- NEW FILE: OzoneXTMBuilder.java ---
/*
* You can redistribute this software and/or modify it under the terms of
* the TM4J Software License published with this distribution.
*
* Copyright (C) 2001 Khalil Ahmed, Gerd Mueller. All rights reserved.
*
* $Id: OzoneXTMBuilder.java,v 1.1 2001/06/01 16:55:37 lilli Exp $
*/
package com.techquila.topicmap.ozone;
import org.ozoneDB.OzoneInterface;
import org.ozoneDB.ExternalDatabase;
import org.ozoneDB.xml.util.SAXChunkConsumer;
import org.ozoneDB.xml.util.SAXChunkProducer;
import org.ozoneDB.xml.util.SAXChunkProducerDelegate;
import com.techquila.topicmap.TopicMap;
import org.xml.sax.InputSource;
import org.xml.sax.helpers.ParserAdapter;
import org.apache.xerces.parsers.SAXParser;
//import javax.xml.parsers.SAXParser;
//import javax.xml.parsers.SAXParserFactory;
import java.io.File;
/**
*
* @author <a href="mailto:ka...@te...">Kal Ahmed</a>
* @author <a href="mailto:ge...@sm...">Gerd Mueller</a>
*/
public class OzoneXTMBuilder implements SAXChunkProducerDelegate {
private OzoneInterface m_database = null;
private OzoneXTMBuilderHelper m_helper = null;
/** */
public OzoneXTMBuilder( OzoneInterface database ) {
m_database = database;
}
/** */
public TopicMap buildTopicMap( InputSource input ) throws Exception {
return buildTopicMap( input, null );
}
/** */
public TopicMap buildTopicMap( InputSource input, TopicMap existingTopicMap ) throws Exception {
m_helper = (OzoneXTMBuilderHelper)m_database
.createObject( OzoneXTMBuilderHelperImpl.class.getName() );
if (existingTopicMap != null) {
m_helper.setTopicMap( existingTopicMap );
}
SAXChunkProducer producer = new SAXChunkProducer( this );
SAXParser parser = new SAXParser(); //SAXParserFactory.newInstance().newSAXParser();
//ParserAdapter adapter = new ParserAdapter( parser.getParser() );
parser.setContentHandler( producer );
parser.parse( input );
TopicMap result = m_helper.getTopicMap();
m_database.deleteObject( m_helper );
return result;
}
/** */
public void processChunk( SAXChunkProducer producer ) throws Exception {
m_helper.putChunk( producer.chunkStream().toByteArray() );
}
/** */
public static void main( String[] args ) throws Exception {
if (args.length < 2) {
System.out.println( "usage: java OzoneXTMBuilder <database URL> <XTM file>" );
System.exit( 0 );
}
if (!new File( args[1] ).exists()) {
System.out.println( "File '" + args[1] + "' doesn't exist !" );
System.exit( 0 );
}
ExternalDatabase database = ExternalDatabase.openDatabase( args[0] );
OzoneXTMBuilder builder = new OzoneXTMBuilder( database );
TopicMap tm = (TopicMap)database.objectForName( "topicmap" );
boolean newTMap = (tm == null);
tm = builder.buildTopicMap( new InputSource( args[1] ), tm );
if (newTMap) {
database.nameObject( (OzoneTopicMap)tm, "topicmap" );
}
System.out.println( " --> found " + tm.getTopicCount() + " topics" );
database.close();
}
}
--- NEW FILE: OzoneXTMBuilderHelper.java ---
/*
* You can redistribute this software and/or modify it under the terms of
* the TM4J Software License published with this distribution.
*
* Copyright (C) 2001 Khalil Ahmed, Gerd Mueller. All rights reserved.
*
* $Id: OzoneXTMBuilderHelper.java,v 1.1 2001/06/01 16:55:37 lilli Exp $
*/
package com.techquila.topicmap.ozone;
import org.ozoneDB.OzoneRemote;
import com.techquila.topicmap.TopicMap;
import org.xml.sax.SAXException;
import java.io.IOException;
/**
*
* @author <a href="mailto:ka...@te...">Kal Ahmed</a>
* @author <a href="mailto:ge...@sm...">Gerd Mueller</a>
*/
public interface OzoneXTMBuilderHelper extends OzoneRemote {
/** */
public void putChunk( byte[] chunkData ) throws SAXException, IOException; // update
/** */
public void setTopicMap( TopicMap topicMap ); // update
/** */
public TopicMap getTopicMap();
}
--- NEW FILE: OzoneXTMBuilderHelperImpl.java ---
/*
* You can redistribute this software and/or modify it under the terms of
* the TM4J Software License published with this distribution.
*
* Copyright (C) 2001 Khalil Ahmed, Gerd Mueller. All rights reserved.
*
* $Id: OzoneXTMBuilderHelperImpl.java,v 1.1 2001/06/01 16:55:37 lilli Exp $
*/
package com.techquila.topicmap.ozone;
import org.ozoneDB.OzoneObject;
import org.ozoneDB.xml.util.SAXChunkConsumer;
import com.techquila.topicmap.TopicMap;
import com.techquila.topicmap.utils.XTMParser;
import com.techquila.topicmap.utils.XTMBuilder;
import org.xml.sax.SAXException;
import java.io.IOException;
/**
*
* @author <a href="mailto:ka...@te...">Kal Ahmed</a>
* @author <a href="mailto:ge...@sm...">Gerd Mueller</a>
*/
public class OzoneXTMBuilderHelperImpl extends OzoneObject
implements OzoneXTMBuilderHelper {
private TopicMap m_topicMap = null;
transient private SAXChunkConsumer m_consumer = null;
transient private XTMBuilder m_builder = null;
/** */
public OzoneXTMBuilderHelperImpl() {
}
/** */
public void putChunk( byte[] chunkData )
throws SAXException, IOException {
if (m_consumer == null) {
m_builder = (m_topicMap == null) ?
new XTMBuilder( new OzoneTopicMapFactoryImpl( database() ) ) :
new XTMBuilder( m_topicMap );
m_consumer = new SAXChunkConsumer( new XTMParser( m_builder ) );
}
m_consumer.processChunk( chunkData );
}
/** */
public void setTopicMap( TopicMap topicMap ) {
if (!(topicMap instanceof OzoneTopicMap)) {
throw new IllegalArgumentException( "setTopicMap(): Can't mix non ozone topicmap with ozone topicmap !" );
}
m_topicMap = topicMap;
}
/** */
public TopicMap getTopicMap() {
return m_builder.getTopicMap();
}
}
|