[libimdb-commit] CVS: libimdb/java/org/libimdb/swig JLog.java,NONE,1.1 Parser.java,NONE,1.1 Progress
Status: Pre-Alpha
Brought to you by:
jveldhuis
|
From: Jerry V. <jve...@us...> - 2003-06-16 04:18:48
|
Update of /cvsroot/libimdb/libimdb/java/org/libimdb/swig
In directory sc8-pr-cvs1:/tmp/cvs-serv11812/java/org/libimdb/swig
Added Files:
JLog.java Parser.java ProgressListener.java
Log Message:
initial checkin
--- NEW FILE: JLog.java ---
package org.libimdb.swig;
public class JLog
{
private long m_swigCPtr;
static {
try {
System.loadLibrary("imdbParser_java");
} catch (UnsatisfiedLinkError e) {
System.err.println("Native code library failed to load.\n" + e);
System.exit(1);
}
}
public JLog(long swigCPtr) throws IllegalArgumentException
{
if ( swigCPtr == 0 ) {
throw new IllegalArgumentException("create failed");
}
m_swigCPtr=swigCPtr;
}
public static long getCPtr(JLog obj)
{
return (obj == null) ? 0 : obj.m_swigCPtr;
}
public static JLog create()
{
return(org.libimdb.swig.gen.JLog.JLog_create());
}
public int destroy()
{
int ret=org.libimdb.swig.gen.JLog.JLog_destroy(this);
m_swigCPtr=-1;
return(ret);
}
public int JLogMessage_cb(String srcFile,
String srcFunc,
int srcLine,
int module,
int reportLevel,
int messageNumber,
String messageText)
{
String errstr;
if ( reportLevel == org.libimdb.swig.gen.JLog.JLOG_DEBUG ) {
errstr="DEBUG-"+messageNumber;
}
else if ( reportLevel == org.libimdb.swig.gen.JLog.JLOG_ERROR ) {
errstr="ERROR-"+messageNumber;
}
else if ( reportLevel == org.libimdb.swig.gen.JLog.JLOG_CRITICAL ) {
errstr="CRITICAL-"+messageNumber;
}
else {
errstr="UNDEFINED-"+messageNumber;
}
System.err.println(srcFile+" "+srcFunc+":"+srcLine+":"+module+": "+errstr+": "+messageText);
return(0);
}
/*
public int fmtfile(int logReportLevel,
int module,
int errorNumber,
String srcfile,
String srcfunc,
int srcline,
String file)
{
if ( m_swigCPtr == -1 ) {
System.err.println("attempt to use a closed JLog connection");
System.exit(1);
}
return(org.libimdb.swig.gen.JLog.jlog_fmtfile(this,
logReportLevel,
module,
errorNumber,
srcfile,
srcfunc,
srcline,
file));
}
*/
public int setMessageLevel()
{
if ( m_swigCPtr == -1 ) {
System.err.println("attempt to use a closed JLog connection");
System.exit(1);
}
/*
return(org.libimdb.swig.gen.JLog.jlog_setAppendLevel(this,
org.libimdb.swig.gen.JLog.JLOGT_DEBUG));
*/
return(-1);
}
public static void main(String args[])
{
JLog log;
log=create();
/*
System.out.println("messlevel:"+log.setMessageLevel());
System.out.println("fmtfile:"+log.fmtfile(org.libimdb.swig.gen.JLog.JLOGT_ERROR,
org.libimdb.swig.gen.JLog.MOD_JLG,
98,
"main", "Log.java", 31,
"/tmp/Makefile"));
System.out.println("dumped:"+log.dumpMessages());
*/
//System.out.println("Messages:"+l.messages());
//System.out.println("error number:"+l.errorNumber());
log.destroy();
log=null;
}
}
--- NEW FILE: Parser.java ---
package org.libimdb.swig;
public class Parser
{
private long m_swigCPtr;
private class MyProgress implements ProgressListener
{
private int m_itemEstimate=0;
MyProgress()
{
}
public void progressStarting_cb(String shortDescription, int itemEstimate)
{
m_itemEstimate=itemEstimate;
System.out.println("starting: "+shortDescription+" expect "+itemEstimate+" entries");
}
public int progressUpdate_cb(int itemCount, int itemEstimate)
{
if ( m_itemEstimate != itemEstimate ) {
/* new estimate */
m_itemEstimate=itemEstimate;
}
int perc=m_itemEstimate==0?0:(itemCount*100)/itemEstimate;
System.out.println("finished "+perc+"% done ("+itemCount+" of "+m_itemEstimate+")");
int next=((perc+5)*m_itemEstimate)/100;
if (next > itemEstimate ) {
return(itemEstimate);
}
else {
return(next);
}
}
public void progressFinished_cb(int itemCount, int abortCode)
{
if ( abortCode != 0 ) {
System.out.println("progress aborted after "+itemCount+" items with code="+abortCode);
}
else {
progressUpdate_cb(itemCount, itemCount);
System.out.println("progress done after "+itemCount+" items");
}
}
}
public Parser(long swigCPtr) throws IllegalArgumentException
{
if ( swigCPtr == 0 ) {
throw new IllegalArgumentException("create failed");
}
m_swigCPtr=swigCPtr;
}
public static long getCPtr(Parser obj)
{
return (obj == null) ? 0 : obj.m_swigCPtr;
}
public static Parser create(JLog logh, String dbsDir) throws IllegalArgumentException
{
Parser parser=org.libimdb.swig.gen.Parser.imdbParser_create(logh, dbsDir);
if ( parser == null ) {
throw new IllegalArgumentException("create failed");
}
return(parser);
}
public int destroy(JLog logh)
{
int ret=org.libimdb.swig.gen.Parser.imdbParser_destroy(logh, this);
m_swigCPtr=-1;
return(ret);
}
public int movieListEntry_cb(int lineNumber, int entryNumber,
int movieType, String movieTitle, int movieYear)
{
//System.out.println("ya: "+number+":"+movieTitle);
return(0);
}
public int directorListEntry_cb(int lineNumber, int entryNumber,
String directorName, String movieLabel)
{
System.out.println("ya: "+entryNumber+":"+directorName);
if ( entryNumber == 10 ) {
/* stop ! */
return(-1);
}
return(0);
}
public int actorListEntry_cb(int lineNumber, int entryNumber,
String actorName, int billing, int isNarrator,
String characterName,
String characterNameAka,
String movieLabel)
{
System.out.println("ya: "+entryNumber+":"+actorName);
if ( entryNumber == 10 ) {
/* stop ! */
return(-1);
}
return(0);
}
public int actressListEntry_cb(int lineNumber, int entryNumber,
String actressName, int billing, int isNarrator,
String characterName,
String characterNameAka,
String movieLabel)
{
System.out.println("ya: "+entryNumber+":"+actressName);
if ( entryNumber == 10 ) {
/* stop ! */
return(-1);
}
return(0);
}
void dumpThem(JLog logh)
{
/*org.libimdb.swig.gen.Parser.imdbParser_dumpMovies(logh, this, new MyProgress());*/
org.libimdb.swig.gen.Parser.imdbParser_dumpDirectors(logh, this, new MyProgress());
org.libimdb.swig.gen.Parser.imdbParser_dumpActors(logh, this, new MyProgress());
org.libimdb.swig.gen.Parser.imdbParser_dumpActresses(logh, this, new MyProgress());
}
public static void main(String args[])
{
JLog logh;
logh=JLog.create();
Parser parser=create(logh, "/home/jerry/imdb/moviedb-3.21/lists");
if ( parser != null ) {
parser.dumpThem(logh);
/*org.libimdb.swig.gen.Parser.imdbParser_dumpMovies(logh, new MyProgress(),
parser);*/
parser.destroy(logh);
parser=null;
}
logh.destroy();
logh=null;
}
}
--- NEW FILE: ProgressListener.java ---
package org.libimdb.swig;
public interface ProgressListener
{
/**
* progress starting callback.
* Includes short string describing operation about
* to start with an estimate of the number of items
* we expect to process
*/
void progressStarting_cb(String shortDescription, int itemEstimate);
/**
* progress update callback.
* Includes the current item being processed and a
* possibly updated number of items we estimate we will
* process.
* @returns item number you'd like to get another progressUpdate_cb
* callback for.
*/
int progressUpdate_cb(int itemCount, int itemEstimate);
/**
* progress finished callback.
* includes the total number of items processed and
* an abortCode which it non-zero if we stopped progress
* prematurly.
*/
void progressFinished_cb(int itemCount, int abortCode);
}
|