/* * Copyright (c) 2006 Manuel Traut and Volker Dahnke * All rights reserved. This program and the accompanying materials * are made available under the terms of the Common Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/cpl-v10.html * * Contributors: Manuel Traut and Volker Dahnke */ package YalpInputs.YalpPGSqlInput; import YalpInterfaces.*; import org.omg.CosNaming.*; import org.omg.CosNaming.NamingContextPackage.*; import org.omg.CORBA.*; import org.omg.PortableServer.*; import org.omg.PortableServer.POA; /* * Class PGSqlInput * * Postgre SQL database connection * * @author Volker Dahnke / Manuel Traut * * @version 2.0 2008-09-23
*/ public class PGSqlInput { private static ORB orb; private static POA poa; private static YalpInputPluginImpl psql; private static InputPluginInterface inputPlugin; private static ServerControlInterface srvCon; private static PluginInfo pluginInfo; public PGSqlInput(String[] argv) { pluginInfo = new PluginInfo(); pluginInfo.name = "Postgre SQL Input Plugin"; pluginInfo.description = "provides information about files, which are stored on a harddisk and have been indicated to the YALP Postgre SQL database"; pluginInfo.type = PluginType.INPUT_PLUGIN; pluginInfo.supportedTypes = new MediaType[3]; pluginInfo.supportedTypes[0] = MediaType.IMAGE; pluginInfo.supportedTypes[1] = MediaType.VIDEO; pluginInfo.supportedTypes[2] = MediaType.SOUND; pluginInfo.access = new AccessInfo(); pluginInfo.access.name = "local files"; pluginInfo.access.description = ""; pluginInfo.access.executable = ""; pluginInfo.access.params = ""; pluginInfo.access.type = AccessType.FILES; try { this.orb = ORB.init(argv, null); org.omg.CORBA.Object objRef = orb.resolve_initial_references("NameService"); NamingContextExt ncRef = NamingContextExtHelper.narrow(objRef); poa = POAHelper.narrow(orb.resolve_initial_references("RootPOA")); } catch(Exception e) { /* t.b.d. error handling */ System.out.println("couldn't host plugin implementation"); } try { poa.the_POAManager().activate(); } catch(org.omg.PortableServer.POAManagerPackage.AdapterInactive e) { /* t.b.d. error handling */ System.out.println("poa inactive"); } YalpErrorHolder err = new YalpErrorHolder(); try { org.omg.CORBA.Object objRef = orb.resolve_initial_references("NameService"); NamingContextExt ncRef = NamingContextExtHelper.narrow(objRef); String name = "YALP_Server"; srvCon = ServerControlInterfaceHelper.narrow(ncRef.resolve_str(name)); } catch (Exception e) { System.out.println("Couldn't connect to YALP Server"); System.exit(0); } psql = new YalpInputPluginImpl(); psql.setORB(orb); try { poa.activate_object(psql); org.omg.CORBA.Object ref = poa.servant_to_reference(psql); inputPlugin = InputPluginInterfaceHelper.narrow(ref); org.omg.CORBA.Object objRef = orb.resolve_initial_references("NameService"); NamingContextExt ncRef = NamingContextExtHelper.narrow(objRef); String name = "YALP_Postgre_SQL_Input"; NameComponent path[] = ncRef.to_name(name); ncRef.rebind(path, inputPlugin); PluginInfoHolder tmp = new PluginInfoHolder(pluginInfo); srvCon.ping(err); System.out.println(err.value.descr); srvCon.registerInputPlugin(inputPlugin, tmp, err ); pluginInfo = tmp.value; if(err.value.code != YalpErrorCode.OK) { System.out.println("registring inputplugin failed"); return; } psql.setInfo(pluginInfo); System.out.println("input plugin registered"); orb.run(); } catch (Exception e) { System.out.println("binding plugin failed 1"); e.printStackTrace(); System.exit(0); } } }