import java.util.*; import javax.naming.*; import com.linar.jintegra.Jvm; import com.linar.jintegra.AutomationException; import com.linar.jintegra.Instanciator; import oracle.aurora.jndi.sess_iiop.ServiceCtx; import oracle.jdbc.driver.*; import oracle.aurora.jndi.jdbc_access.jdbc_accessURLContextFactory; import java.sql.*; public class COMtoOracle { public static void main(String[] args) throws Exception { Jvm.register("oraclejvm", new OracleInstanciator(args[0], args[1])); while (true) { // endless loop to keep the bridge alive Thread.sleep(10000000); } } } class OracleInstanciator implements Instanciator { Context ctx; static String JDBC_SERVICE="jdbc:oracle:thin:@jintegra-test4:1521:ICS"; OracleInstanciator(String user, String password) throws NamingException { Hashtable env = new Hashtable(); env.put(Context.URL_PKG_PREFIXES, "oracle.aurora.jndi"); env.put (jdbc_accessURLContextFactory.CONNECTION_URL_PROP, JDBC_SERVICE); env.put(Context.SECURITY_PRINCIPAL, user); env.put(Context.SECURITY_CREDENTIALS, password); env.put(Context.SECURITY_AUTHENTICATION, ServiceCtx.NON_SSL_LOGIN); ctx = new InitialContext (env); try { DriverManager.registerDriver (new oracle.jdbc.driver.OracleDriver()); } catch(Exception ex) { ex.printStackTrace(); } } // This method is called by the J-Integra® runtime when a COM client tries // to instantiate an object. First we try to instantiate it as a Java class // and if that fails, we do a JNDI lookup public Object instanciate(String javaClass) throws AutomationException { try { try { return Class.forName(javaClass).newInstance(); } catch(Exception e) {} return ctx.lookup(javaClass); } catch (Throwable t) { t.printStackTrace(); throw new AutomationException(new Exception("Unexpected: " + t)); } } } |