Search in sources :

Example 1 with XMLHandler

use of com.cosylab.cdb.jdal.XMLHandler in project ACS by ACS-Community.

the class CDBAccess method internalConnect.

/**
	 * Performs the connect of the specified DAO.
	 * 
	 * @param	proxy	the proxy to connect, non-<code>null</code>
	 */
private void internalConnect(DAOProxy proxy) {
    String curl = null;
    try {
        checkDALConnection();
    } catch (Throwable th) {
        // TODO @todo replace
        RuntimeException re = new RuntimeException("Failed to obtain DAO for proxy '" + proxy + "'.", th);
        throw re;
    }
    DAOOperations dao = null;
    try {
        curl = proxy.getCURL();
        if (remoteDAO) {
            dao = dalReference.get_DAO_Servant(curl);
        } else {
            String xml = dalReference.get_DAO(curl);
            SAXParserFactory factory = SAXParserFactory.newInstance();
            SAXParser saxParser = factory.newSAXParser();
            // use CDB XML handler which does not creates strings...
            XMLHandler xmlSolver = new XMLHandler(false, logger);
            saxParser.parse(new InputSource(new StringReader(xml)), xmlSolver);
            if (xmlSolver.m_errorString != null) {
                AcsJCDBXMLErrorEx e = new AcsJCDBXMLErrorEx();
                e.setErrorString("XML parser error: " + xmlSolver.m_errorString);
                throw e;
            //throw new XMLerror("XML parser error: " + xmlSolver.m_errorString);
            }
            // create non-CORBA related, silent DAO
            dao = new DAOImpl(curl, xmlSolver.m_rootNode, null, logger, true);
            proxy.setElementName(xmlSolver.m_rootNode.getName());
        }
        // register listener, if not already registered
        if (changeListener != null) {
            if (!changeListener.isRegistered(curl))
                changeListener.handle(dalReference, curl, proxy);
        }
    } catch (Throwable th) {
        // TODO @todo replace
        RuntimeException re = new RuntimeException("Failed to obtain DAO object for proxy '" + proxy + "'.", th);
        throw re;
    }
    try {
        proxy.initialize(dao);
    } catch (Throwable th) {
        // TODO @todo replace
        RuntimeException re = new RuntimeException("The proxy '" + proxy + "' rejects the DAO.", th);
        throw re;
    }
    logger.config("Connected to DAO '" + proxy.getCURL() + "'.");
}
Also used : XMLHandler(com.cosylab.cdb.jdal.XMLHandler) InputSource(org.xml.sax.InputSource) DAOOperations(com.cosylab.CDB.DAOOperations) StringReader(java.io.StringReader) SAXParser(javax.xml.parsers.SAXParser) AcsJCDBXMLErrorEx(alma.cdbErrType.wrappers.AcsJCDBXMLErrorEx) DAOImpl(com.cosylab.cdb.jdal.DAOImpl) SAXParserFactory(javax.xml.parsers.SAXParserFactory)

Example 2 with XMLHandler

use of com.cosylab.cdb.jdal.XMLHandler in project ACS by ACS-Community.

the class CDBDefault method main.

public static void main(String[] args) {
    try {
        strIOR = null;
        if (args.length < 2) {
            System.out.println("Usage: cmd <idl_type> <instance_name> [-d ior -h]");
            return;
        }
        m_logger = ClientLogManager.getAcsLogManager().getLoggerForApplication("CDBDefault", true);
        String in_type = args[0];
        String in_name = args[1];
        curl_allComponents = "MACI/Components";
        curl = curl_allComponents + "/" + in_name;
        for (int i = 0; i < args.length; i++) {
            if (args[i].equals("-d")) {
                if (i < args.length - 1) {
                    strIOR = args[++i];
                }
            }
            if (args[i].equals("-h")) {
                System.out.println("Usage: cmd idl_type instance_name [-d ior -h]");
                return;
            }
        }
        if (strIOR == null) {
            strIOR = "corbaloc::" + InetAddress.getLocalHost().getHostName() + ":" + ACSPorts.getCDBPort() + "/CDB";
        }
        // create and initialize the ORB
        orb = ORB.init(new String[0], null);
        WDAL wdal = WDALHelper.narrow(orb.string_to_object(strIOR));
        String xml = wdal.get_DAO(curl_allComponents);
        SAXParserFactory factory = SAXParserFactory.newInstance();
        SAXParser saxParser = factory.newSAXParser();
        XMLHandler xmlSolver = new XMLHandler(false, m_logger);
        saxParser.parse(new InputSource(new StringReader(xml)), xmlSolver);
        if (xmlSolver.m_errorString != null) {
            String info = "XML parser error: " + xmlSolver.m_errorString;
            AcsJCDBXMLErrorEx cdbxmlErr = new AcsJCDBXMLErrorEx();
            //XMLerror xmlErr = new XMLerror(info);
            throw cdbxmlErr;
        }
        setDefault(xmlSolver.m_rootNode, in_type, in_name);
    } catch (AcsJCDBXMLErrorEx e) {
        m_logger.log(AcsLogLevel.NOTICE, "Xml Error", e);
        e.printStackTrace();
    } catch (Exception e) {
        m_logger.log(AcsLogLevel.NOTICE, "Error", e);
        e.printStackTrace();
    }
}
Also used : WDAL(com.cosylab.CDB.WDAL) XMLHandler(com.cosylab.cdb.jdal.XMLHandler) InputSource(org.xml.sax.InputSource) StringReader(java.io.StringReader) SAXParser(javax.xml.parsers.SAXParser) AcsJCDBXMLErrorEx(alma.cdbErrType.wrappers.AcsJCDBXMLErrorEx) SAXParserFactory(javax.xml.parsers.SAXParserFactory)

Example 3 with XMLHandler

use of com.cosylab.cdb.jdal.XMLHandler in project ACS by ACS-Community.

the class DALRead method main.

public static void main(String[] args) {
    Logger m_logger = ClientLogManager.getAcsLogManager().getLoggerForApplication("DALRead", false);
    try {
        String curl;
        String strIOR = null;
        boolean rawOutput = false;
        if (args.length < 1) {
            System.out.println("Usage: cmd curl [-d ior -raw -h]");
            return;
        }
        curl = args[0];
        // test for IOR in cmd line
        for (int i = 0; i < args.length; i++) {
            if (args[i].equals("-d")) {
                if (i < args.length - 1) {
                    strIOR = args[++i];
                }
            }
            if (args[i].equals("-raw")) {
                rawOutput = true;
            }
            if (args[i].equals("-h")) {
                System.out.println("Usage: cmd curl [-d ior -raw -h]");
                return;
            }
        }
        if (strIOR == null) {
            // use default
            strIOR = "corbaloc::" + InetAddress.getLocalHost().getHostName() + ":" + ACSPorts.getCDBPort() + "/CDB";
        }
        // create and initialize the ORB
        ORB orb = ORB.init(args, null);
        DAL dal = DALHelper.narrow(orb.string_to_object(strIOR));
        String xml = dal.get_DAO(curl);
        if (rawOutput) {
            m_logger.log(AcsLogLevel.INFO, "Curl data:\n" + xml);
            return;
        }
        SAXParserFactory factory = SAXParserFactory.newInstance();
        SAXParser saxParser = factory.newSAXParser();
        XMLHandler xmlSolver = new XMLHandler(false, m_logger);
        saxParser.parse(new InputSource(new StringReader(xml)), xmlSolver);
        if (xmlSolver.m_errorString != null) {
            String info = "XML parser error: " + xmlSolver.m_errorString;
            AcsJCDBXMLErrorEx xmlErr = new AcsJCDBXMLErrorEx();
            System.err.println(info);
            throw xmlErr;
        }
        System.out.println("Env " + System.getProperty("HOMEPATH"));
        // dump contents
        System.out.println("________________________________________________________");
        walk(xmlSolver.m_rootNode);
        System.out.println("________________________________________________________");
    } catch (AcsJCDBXMLErrorEx e) {
        e.printStackTrace();
        e.log(m_logger);
    } catch (CDBXMLErrorEx e) {
        AcsJCDBXMLErrorEx je = AcsJCDBXMLErrorEx.fromCDBXMLErrorEx(e);
        String smsg = "XML Error \tCURL='" + je.getCurl() + "'\n\t\tFilename='" + je.getFilename() + "'\n\t\tNodename='" + je.getNodename() + "'\n\t\tMSG='" + je.getErrorString() + "'";
        je.log(m_logger);
        m_logger.log(AcsLogLevel.NOTICE, smsg, je);
    } catch (CDBRecordDoesNotExistEx e) {
        AcsJCDBRecordDoesNotExistEx je = AcsJCDBRecordDoesNotExistEx.fromCDBRecordDoesNotExistEx(e);
        String smsg = "Record does not exist \tCURL='" + je.getCurl() + "'";
        je.log(m_logger);
        m_logger.log(AcsLogLevel.NOTICE, smsg, je);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : XMLHandler(com.cosylab.cdb.jdal.XMLHandler) AcsJCDBXMLErrorEx(alma.cdbErrType.wrappers.AcsJCDBXMLErrorEx) CDBXMLErrorEx(alma.cdbErrType.CDBXMLErrorEx) AcsJCDBXMLErrorEx(alma.cdbErrType.wrappers.AcsJCDBXMLErrorEx) Logger(java.util.logging.Logger) CDBRecordDoesNotExistEx(alma.cdbErrType.CDBRecordDoesNotExistEx) AcsJCDBRecordDoesNotExistEx(alma.cdbErrType.wrappers.AcsJCDBRecordDoesNotExistEx) AcsJCDBRecordDoesNotExistEx(alma.cdbErrType.wrappers.AcsJCDBRecordDoesNotExistEx)

Aggregations

AcsJCDBXMLErrorEx (alma.cdbErrType.wrappers.AcsJCDBXMLErrorEx)3 XMLHandler (com.cosylab.cdb.jdal.XMLHandler)3 StringReader (java.io.StringReader)2 SAXParser (javax.xml.parsers.SAXParser)2 SAXParserFactory (javax.xml.parsers.SAXParserFactory)2 InputSource (org.xml.sax.InputSource)2 CDBRecordDoesNotExistEx (alma.cdbErrType.CDBRecordDoesNotExistEx)1 CDBXMLErrorEx (alma.cdbErrType.CDBXMLErrorEx)1 AcsJCDBRecordDoesNotExistEx (alma.cdbErrType.wrappers.AcsJCDBRecordDoesNotExistEx)1 DAOOperations (com.cosylab.CDB.DAOOperations)1 WDAL (com.cosylab.CDB.WDAL)1 DAOImpl (com.cosylab.cdb.jdal.DAOImpl)1 Logger (java.util.logging.Logger)1