[sword-svn] r2504 - in trunk: bindings/corba bindings/corba/java/src/org/crosswire/sword/orb bindings/corba/java/src/org/crosswire/util bindings/corba/omniorbcpp bindings/corba/orbitcpp examples/classes

scribe at crosswire.org scribe at crosswire.org
Tue Jan 26 09:46:19 MST 2010


Author: scribe
Date: 2010-01-26 09:46:19 -0700 (Tue, 26 Jan 2010)
New Revision: 2504

Modified:
   trunk/bindings/corba/java/src/org/crosswire/sword/orb/SwordOrb.java
   trunk/bindings/corba/java/src/org/crosswire/util/Base64.java
   trunk/bindings/corba/omniorbcpp/swordorb-impl.cpp
   trunk/bindings/corba/orbitcpp/swordorb-impl.cpp
   trunk/bindings/corba/swordorb.idl
   trunk/examples/classes/ciphercng.cpp
Log:
Cleaned up compile and runtime warnings
Added a debug level mechanism
Added support for intros via CORBA interface



Modified: trunk/bindings/corba/java/src/org/crosswire/sword/orb/SwordOrb.java
===================================================================
--- trunk/bindings/corba/java/src/org/crosswire/sword/orb/SwordOrb.java	2010-01-21 01:13:18 UTC (rev 2503)
+++ trunk/bindings/corba/java/src/org/crosswire/sword/orb/SwordOrb.java	2010-01-26 16:46:19 UTC (rev 2504)
@@ -45,6 +45,31 @@
 	public static final String GENBOOKS = "Generic Books";
 	public static final String DAILYDEVOS = "Daily Devotional";
 
+
+	public static final int DEBUG   = 9;
+	public static final int INFO    = 7;
+	public static final int WARN    = 5;
+	public static final int ERROR   = 2;
+	public static final int NONE    = 0;
+
+	// set this to your desired debug output level
+	public static int debugLevel = INFO;
+
+
+	static void log(int level, String message, Throwable e) {
+		if (debugLevel >= level) {
+			System.err.println(new Date() + " | " + message);
+			// some warnings give a stackstrace, but we don't want to
+			// see the stacktrace part unless our current run level is set to DEBUG
+			if (debugLevel >= DEBUG && e != null) {
+				System.err.println(e);
+				e.printStackTrace(System.err);
+			}
+		}
+	}
+
+
+
 	static java.util.Properties p = new java.util.Properties();
 	static {
 		p.setProperty("com.sun.CORBA.codeset.charsets", "0x05010001, 0x00010109");    // UTF-8, UTF-16
@@ -52,7 +77,7 @@
 	}
 
 	static org.omg.CORBA.ORB orb = org.omg.CORBA_2_3.ORB.init(new String[]{}, p);
-	static Hashtable clients = new Hashtable();
+	static Hashtable<String, Vector<SwordOrb>> clients = new Hashtable<String, Vector<SwordOrb>>();
 	String ior = null;
 	String remoteAddr = null;
 	String localeName = null;
@@ -69,17 +94,22 @@
 
 		SWMgr retVal = null;
 		try {
-System.out.println("attaching...");
+log(INFO, "attaching...", null);
 			org.omg.CORBA.Object obj = orb.string_to_object(ior);
 			retVal = SWMgrHelper.narrow(obj);
-System.out.println("calling testConnection");
-			retVal.testConnection();
-System.out.println("testConnection successful");
+log(INFO, "calling testConnection", null);
+			try {
+				retVal.testConnection();
+log(INFO, "testConnection successful", null);
+			}
+			catch (Throwable e) {
+log(WARN, "We lost our ORB service.  No worries, it was likely just reaped by a cron to killall ORB services. We'll respawn another...", e);
+				retVal = null;
+			}
 		}
 		catch(Throwable e) {
-//			e.printStackTrace();
 			retVal = null;
-System.out.println("failed in attach");
+log(ERROR, "failed in attach", e);
 		}
 		return retVal;
 	}
@@ -93,7 +123,7 @@
 	public void finalize () throws Throwable {
 		// shut down external process
 		try {
-System.out.println("calling finalize.");
+log(INFO, "calling finalize.", null);
 			getSWMgrInstance().terminate();
 		}
 		catch (Exception e) {}	// we know this doesn't return property cuz we killed the orb! :)
@@ -112,7 +142,7 @@
 size = orbs.size();
 				orbs.remove(this);
 			}
-System.out.println("calling valueUnbound. size before: " + size + "; size after: "+orbs.size());
+log(INFO, "calling valueUnbound. size before: " + size + "; size after: "+orbs.size(), null);
 			getSWMgrInstance().terminate();
 		}
 		catch (Exception e) {}	// we know this doesn't return properly cuz we killed the orb! :)
@@ -145,7 +175,7 @@
 			line = input.readLine();
 //		retVal = p.waitFor();
 			ior = line;
-System.out.println("Launched ORB, IOR: " + ior);
+log(INFO, "Launched ORB, IOR: " + ior, null);
 		}
 		catch (Exception e) {e.printStackTrace();}
 	}
@@ -169,18 +199,18 @@
 		checkAccessAbuse();
 		SWMgr retVal = null;
 		try {
-System.out.println("trying to attach to running ORB");
+log(INFO, "trying to see if we have and attach to a running ORB", null);
 			retVal = attach();
 		}
 		catch(Exception e) {
-//			e.printStackTrace();
+log(ERROR, "exception attaching to running ORB", e);
 			retVal = null;
 		}
 		if (retVal == null) {
 			try {
-System.out.println("no ORB running; trying to launch");
+log(INFO, "no ORB running; trying to launch", null);
 				startOrb();
-System.out.println("trying to attach to newly launched ORB");
+log(INFO, "trying to attach to newly launched ORB", null);
 				retVal = attach();
 				if (retVal != null) {
 					if (localeName != null) {
@@ -209,11 +239,11 @@
 		SwordOrb orb = (SwordOrb)session.getAttribute("SwordOrb");
 		String remoteAddr = request.getRemoteAddr();
 		if (orb == null) {
-System.out.println("No ORB found in session; constructing a new instance");
+log(INFO, "No ORB found in session; constructing a new instance", null);
 
-			Vector orbs = (Vector)clients.get(remoteAddr);
+			Vector<SwordOrb> orbs = clients.get(remoteAddr);
 			if (orbs == null) {
-				orbs = new Vector();
+				orbs = new Vector<SwordOrb>();
 				clients.put(remoteAddr, orbs);
 			}
 			if (orbs.size() < MAX_REMOTE_ADDR_CONNECTIONS) {
@@ -229,7 +259,7 @@
 			else throw new Exception("Max Remote Addr Connections from: ["+remoteAddr+"]");
 		}
 		else {
-System.out.println("ORB found in session");
+log(INFO, "ORB found in session", null);
 		}
 		return orb;
 	}

Modified: trunk/bindings/corba/java/src/org/crosswire/util/Base64.java
===================================================================
--- trunk/bindings/corba/java/src/org/crosswire/util/Base64.java	2010-01-21 01:13:18 UTC (rev 2503)
+++ trunk/bindings/corba/java/src/org/crosswire/util/Base64.java	2010-01-26 16:46:19 UTC (rev 2504)
@@ -117,178 +117,6 @@
     
     
     
-    /**
-     * Testing. Feel free--in fact I encourage you--to throw out 
-     * this entire "main" method when you actually deploy this code.
-     */
-    public static void main( String[] args )
-    {
-        try
-        {
-            // Test encoding/decoding byte arrays
-            {
-                byte[] bytes1 = { (byte)2,(byte)2,(byte)3,(byte)0,(byte)9 }; // My zip code
-                byte[] bytes2 = { (byte)99,(byte)2,(byte)2,(byte)3,(byte)0,(byte)9 };
-                System.out.println( "Bytes 2,2,3,0,9 as Base64: " + encodeBytes( bytes1 ) );
-                System.out.println( "Bytes 2,2,3,0,9 w/ offset: " + encodeBytes( bytes2, 1, bytes2.length-1 ) );
-                byte[] dbytes = decode( encodeBytes( bytes1 ) );
-                System.out.print( encodeBytes( bytes1 ) + " decoded: " );
-                for( int i = 0; i < dbytes.length; i++ )
-                    System.out.print( dbytes[i] + (i<dbytes.length-1?",":"\n") );
-            }   // end testing byte arrays
-            
-            
-            
-            
-            // Test Input Stream
-            {
-                // Read GIF stored in base64 form.
-                java.io.FileInputStream fis = new java.io.FileInputStream( "test.gif.b64" );
-                Base64.InputStream b64is = new Base64.InputStream( fis, DECODE );
-
-                byte[] bytes = new byte[0];
-                int b = -1;
-                while( (b = b64is.read()) >= 0 ){
-                    byte[] temp = new byte[ bytes.length + 1 ];
-                    System.arraycopy( bytes,0, temp,0,bytes.length );
-                    temp[bytes.length] = (byte)b;
-                    bytes = temp;
-                }   // end while: terribly inefficient way to read data
-                b64is.close();
-                javax.swing.ImageIcon iicon = new javax.swing.ImageIcon( bytes );
-                javax.swing.JLabel jlabel = new javax.swing.JLabel( "Read from test.gif.b64", iicon,0 );
-                javax.swing.JFrame jframe = new javax.swing.JFrame();
-                jframe.getContentPane().add( jlabel );
-                jframe.pack();
-                jframe.show();
-
-                // Write raw bytes to file
-                java.io.FileOutputStream fos = new java.io.FileOutputStream( "test.gif_out" );
-                fos.write( bytes );
-                fos.close();
-
-                // Read raw bytes and encode
-                fis = new java.io.FileInputStream( "test.gif_out" );
-                b64is = new Base64.InputStream( fis, ENCODE );
-                byte[] ebytes = new byte[0];
-                b = -1;
-                while( (b = b64is.read()) >= 0 ){
-                    byte[] temp = new byte[ ebytes.length + 1 ];
-                    System.arraycopy( ebytes,0, temp,0,ebytes.length );
-                    temp[ebytes.length] = (byte)b;
-                    ebytes = temp;
-                }   // end while: terribly inefficient way to read data
-                b64is.close();
-                String s = new String( ebytes );
-                javax.swing.JTextArea jta = new javax.swing.JTextArea( s );
-                javax.swing.JScrollPane jsp = new javax.swing.JScrollPane( jta );
-                jframe = new javax.swing.JFrame();
-                jframe.setTitle( "Read from test.gif_out" );
-                jframe.getContentPane().add( jsp );
-                jframe.pack();
-                jframe.show();
-
-                // Write encoded bytes to file
-                fos = new java.io.FileOutputStream( "test.gif.b64_out" );
-                fos.write( ebytes );
-
-                // Read GIF stored in base64 form.
-                fis = new java.io.FileInputStream( "test.gif.b64_out" );
-                b64is = new Base64.InputStream( fis, DECODE );
-                byte[] edbytes = new byte[0]; 
-                b = -1;
-                while( (b = b64is.read()) >= 0 ){
-                    byte[] temp = new byte[ edbytes.length + 1 ];
-                    System.arraycopy( edbytes,0, temp,0,edbytes.length );
-                    temp[edbytes.length] = (byte)b;
-                    edbytes = temp;
-                }   // end while: terribly inefficient way to read data
-                b64is.close();
-                iicon = new javax.swing.ImageIcon( edbytes );
-                jlabel = new javax.swing.JLabel( "Read from test.gif.b64_out", iicon,0 );
-                jframe = new javax.swing.JFrame();
-                jframe.getContentPane().add( jlabel );
-                jframe.pack();
-                jframe.show();
-            }   // end: Test Input Stream
-            
-            
-            // Test Output Stream
-            {
-                // Read raw bytes
-                java.io.FileInputStream fis = new java.io.FileInputStream( "test.gif_out" );
-                byte[] rbytes = new byte[0];
-                int b = -1;
-                while( (b = fis.read()) >= 0 ){
-                    byte[] temp = new byte[ rbytes.length + 1 ];
-                    System.arraycopy( rbytes,0, temp,0,rbytes.length );
-                    temp[rbytes.length] = (byte)b;
-                    rbytes = temp;
-                }   // end while: terribly inefficient way to read data
-                fis.close();
-                
-                // Write raw bytes to encoded file
-                java.io.FileOutputStream fos = new java.io.FileOutputStream("test.gif.b64_out2");
-                Base64.OutputStream b64os = new Base64.OutputStream( fos, ENCODE );
-                b64os.write( rbytes );
-                b64os.close();
-                
-                
-                // Read raw bytes that are actually encoded (but we'll ignore that)
-                fis = new java.io.FileInputStream( "test.gif.b64_out2" );
-                byte[] rebytes = new byte[0];
-                b = -1;
-                while( (b = fis.read()) >= 0 ){
-                    byte[] temp = new byte[ rebytes.length + 1 ];
-                    System.arraycopy( rebytes,0, temp,0,rebytes.length );
-                    temp[rebytes.length] = (byte)b;
-                    rebytes = temp;
-                }   // end while: terribly inefficient way to read data
-                fis.close();
-                String s = new String( rebytes );
-                javax.swing.JTextArea jta = new javax.swing.JTextArea( s );
-                javax.swing.JScrollPane jsp = new javax.swing.JScrollPane( jta );
-                javax.swing.JFrame jframe = new javax.swing.JFrame();
-                jframe.setTitle( "Read from test.gif.b64_out2" );
-                jframe.getContentPane().add( jsp );
-                jframe.pack();
-                jframe.show();
-               
-                // Write encoded bytes to decoded raw file
-                fos = new java.io.FileOutputStream("test.gif_out2");
-                b64os = new Base64.OutputStream( fos, DECODE );
-                b64os.write( rebytes );
-                b64os.close();
-                javax.swing.ImageIcon iicon = new javax.swing.ImageIcon( "test.gif_out2" );
-                javax.swing.JLabel jlabel = new javax.swing.JLabel( "Read from test.gif_out2", iicon,0 );
-                jframe = new javax.swing.JFrame();
-                jframe.getContentPane().add( jlabel );
-                jframe.pack();
-                jframe.show();
-               
-            }   // end: Test Output Stream
-            
-            
-            // Test wagner's files
-            {
-                java.io.FileInputStream fis = new java.io.FileInputStream("D:\\temp\\testencoding.txt");
-                Base64.InputStream b64is = new Base64.InputStream( fis, DECODE );
-                java.io.FileOutputStream fos = new java.io.FileOutputStream("D:\\temp\\file.zip");
-                int b;
-                while( (b=b64is.read()) >= 0 )
-                    fos.write( b );
-                fos.close();
-                b64is.close();
-            
-            }   // end test wagner's file
-            
-        }   // end try
-        catch( Exception e)
-        {   e.printStackTrace();
-        }
-    }   // end main
-    
-    
 /* ********  E N C O D I N G   M E T H O D S  ******** */    
     
     

Modified: trunk/bindings/corba/omniorbcpp/swordorb-impl.cpp
===================================================================
--- trunk/bindings/corba/omniorbcpp/swordorb-impl.cpp	2010-01-21 01:13:18 UTC (rev 2503)
+++ trunk/bindings/corba/omniorbcpp/swordorb-impl.cpp	2010-01-26 16:46:19 UTC (rev 2504)
@@ -191,13 +191,21 @@
 void swordorb_SWModule_i::setKeyText(const char* keyText) {
 	sword::SWKey *key = delegate->getKey();
 	sword::VerseKey *vkey = SWDYNAMIC_CAST(VerseKey, key);
-	if (vkey && (*keyText=='+' ||*keyText=='-')) {
-		if (!stricmp(keyText+1, "book")) {
-			vkey->setBook(vkey->getBook() + ((*keyText=='+')?1:-1));
-			return;
+	if (vkey) {
+		if ((*keyText=='+' || *keyText=='-')) {
+			if (!stricmp(keyText+1, "book")) {
+				vkey->setBook(vkey->getBook() + ((*keyText=='+')?1:-1));
+				return;
+			}
+			else if (!stricmp(keyText+1, "chapter")) {
+				vkey->setChapter(vkey->getChapter() + ((*keyText=='+')?1:-1));
+				return;
+			}
 		}
-		else if (!stricmp(keyText+1, "chapter")) {
-			vkey->setChapter(vkey->getChapter() + ((*keyText=='+')?1:-1));
+		else if (*keyText=='=') {
+			vkey->Headings(true);
+			vkey->AutoNormalize(false);
+			vkey->setText(keyText+1);
 			return;
 		}
 	}

Modified: trunk/bindings/corba/orbitcpp/swordorb-impl.cpp
===================================================================
--- trunk/bindings/corba/orbitcpp/swordorb-impl.cpp	2010-01-21 01:13:18 UTC (rev 2503)
+++ trunk/bindings/corba/orbitcpp/swordorb-impl.cpp	2010-01-26 16:46:19 UTC (rev 2504)
@@ -290,18 +290,26 @@
 void SWModule_impl::setKeyText(const char *key) throw(CORBA::SystemException) {
 	sword::SWKey *key = delegate->getKey();
 	sword::VerseKey *vkey = SWDYNAMIC_CAST(VerseKey, key);
-	if (vkey && (*keyText=='+' ||*keyText=='-')) {
-		if (!stricmp(keyText+1, "book")) {
-			vkey->setBook(vkey->getBook() + ((*keyText=='+')?1:-1));
-			return;
+	if (vkey) {
+		if ((*keyText=='+' || *keyText=='-')) {
+			if (!stricmp(keyText+1, "book")) {
+				vkey->setBook(vkey->getBook() + ((*keyText=='+')?1:-1));
+				return;
+			}
+			else if (!stricmp(keyText+1, "chapter")) {
+				vkey->setChapter(vkey->getChapter() + ((*keyText=='+')?1:-1));
+				return;
+			}
 		}
-		else if (!stricmp(keyText+1, "chapter")) {
-			vkey->setChapter(vkey->getChapter() + ((*keyText=='+')?1:-1));
+		else if (*keyText=='=') {
+			vkey->Headings(true);
+			vkey->AutoNormalize(false);
+			vkey->setText(keyText+1);
 			return;
 		}
 	}
 
-	delegate->KeyText(key);
+	delegate->KeyText(keyText);
 }
 
 StringList *SWModule_impl::getKeyChildren() throw(CORBA::SystemException) {

Modified: trunk/bindings/corba/swordorb.idl
===================================================================
--- trunk/bindings/corba/swordorb.idl	2010-01-21 01:13:18 UTC (rev 2503)
+++ trunk/bindings/corba/swordorb.idl	2010-01-26 16:46:19 UTC (rev 2504)
@@ -63,8 +63,11 @@
 	StringList    getEntryAttribute(in string level1, in string level2, in string level3, in boolean filtered);
 	StringList    parseKeyList(in string keyText);
 
-	// Special values handled for VerseKey modules: [+-][book|chapter]
+	// Special values handled for VerseKey modules:
+	//	[+-][book|chapter]	- [de|in]crement by chapter or book
 	//	(e.g.	"+chapter" will increment the VerseKey 1 chapter)
+	//	[=][key]		- position absolutely and don't normalize
+	//	(e.g.	"jn.1.0" for John Chapter 1 intro; "jn.0.0" For Book of John Intro)
 	void          setKeyText(in string key);
 
 	string        getKeyText();

Modified: trunk/examples/classes/ciphercng.cpp
===================================================================
--- trunk/examples/classes/ciphercng.cpp	2010-01-21 01:13:18 UTC (rev 2503)
+++ trunk/examples/classes/ciphercng.cpp	2010-01-26 16:46:19 UTC (rev 2504)
@@ -23,6 +23,7 @@
  *
  */
 
+#include <stdio.h>
 #include <iostream>
 
 #include <swmgr.h>




More information about the sword-cvs mailing list