Search in sources :

Example 11 with AcsJCDBXMLErrorEx

use of alma.cdbErrType.wrappers.AcsJCDBXMLErrorEx in project ACS by ACS-Community.

the class BrowserJNDIContext method lookup.

/**
     * This methos returns either a new JNDI_Context or a new JNDI_XMLContxt obj.
     */
public Object lookup(Name name) throws NamingException {
    final String lookupName = name.toString();
    final String fullLookupName = this.name + "/" + lookupName;
    String daoElements = dal.list_daos(fullLookupName);
    if (daoElements.length() == 0)
        daoElements = null;
    // @todo TODO this creates DAO and wastes some of resources... DAL method to get resources would be nice
    boolean hasAttributes = false;
    try {
        // NOTE check only if needed
        if (daoElements == null)
            hasAttributes = dal.get_DAO_Servant(fullLookupName).get_string("_attributes").trim().length() > 0;
    } catch (Throwable th) {
    // noop
    }
    CDBLogic.setKey(fullLookupName);
    // is subnode
    StringTokenizer token = new StringTokenizer(elements);
    while (token.hasMoreTokens()) if (token.nextElement().equals(lookupName)) {
        // is DAO?
        if (daoElements != null || hasAttributes) {
            try {
                return new BrowserJNDIXMLContext(fullLookupName, dal.list_nodes(fullLookupName), dal.get_DAO(fullLookupName), logger);
            } catch (CDBXMLErrorEx th) {
                AcsJCDBXMLErrorEx jex = AcsJCDBXMLErrorEx.fromCDBXMLErrorEx(th);
                NamingException ex2 = new NamingException(jex.getFilename() + ": " + jex.getErrorString());
                ex2.setRootCause(jex);
                throw ex2;
            } catch (Throwable th) {
                throw new NamingException("Failed to retrieve DAO: " + fullLookupName);
            }
        } else
            return new BrowserJNDIContext(fullLookupName, dal.list_nodes(fullLookupName), logger);
    }
    if (daoElements != null) {
        // lookup in DAO
        token = new StringTokenizer(daoElements);
        while (token.hasMoreTokens()) if (token.nextElement().equals(lookupName)) {
            try {
                return new BrowserJNDIXMLContext(fullLookupName, dal.list_nodes(fullLookupName), dal.get_DAO(fullLookupName), logger);
            } catch (CDBXMLErrorEx th) {
                AcsJCDBXMLErrorEx jex = AcsJCDBXMLErrorEx.fromCDBXMLErrorEx(th);
                NamingException ex2 = new NamingException(jex.getFilename() + ": " + jex.getErrorString());
                ex2.setRootCause(jex);
                throw ex2;
            } catch (Throwable th) {
                throw new NamingException("Failed to retrieve DAO: " + fullLookupName);
            }
        }
    }
    // not found
    throw new NamingException("No name " + fullLookupName);
}
Also used : StringTokenizer(java.util.StringTokenizer) CDBXMLErrorEx(alma.cdbErrType.CDBXMLErrorEx) AcsJCDBXMLErrorEx(alma.cdbErrType.wrappers.AcsJCDBXMLErrorEx) AcsJCDBXMLErrorEx(alma.cdbErrType.wrappers.AcsJCDBXMLErrorEx) NamingException(javax.naming.NamingException)

Example 12 with AcsJCDBXMLErrorEx

use of alma.cdbErrType.wrappers.AcsJCDBXMLErrorEx 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)

Example 13 with AcsJCDBXMLErrorEx

use of alma.cdbErrType.wrappers.AcsJCDBXMLErrorEx in project ACS by ACS-Community.

the class DALWrite method main.

public static void main(String[] args) {
    try {
        String strIOR = null;
        if (args.length < 3) {
            System.out.println("Usage: cmd curl field value [-d ior -h]");
            return;
        }
        String curl = args[0];
        String field = args[1];
        String value = args[2];
        // test for IOR in cmd line
        for (int i = 3; i < args.length; i++) {
            if (args[i].equals("-d")) {
                if (i < args.length - 1) {
                    strIOR = args[++i];
                }
            }
            if (args[i].equals("-h") || args[i].equals("-help")) {
                System.out.println("Usage: cmd curl field value [-d ior -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);
        WDAL wdal = WDALHelper.narrow(orb.string_to_object(strIOR));
        WDAO wdao = wdal.get_WDAO_Servant(curl);
        System.out.println("Reading '" + curl + "/" + field + "'='" + wdao.get_string(field) + "'");
        wdao.set_string(field, value);
        System.out.println("Setting '" + curl + "/" + field + "'='" + value + "'");
    } catch (CDBXMLErrorEx e) {
        AcsJCDBXMLErrorEx e2 = new AcsJCDBXMLErrorEx(e);
        System.out.println("XMLerror : " + e2.getCurl());
        e.printStackTrace(System.out);
    } catch (Exception e) {
        System.out.println("ERROR : " + e);
        e.printStackTrace(System.out);
    }
}
Also used : CDBXMLErrorEx(alma.cdbErrType.CDBXMLErrorEx) AcsJCDBXMLErrorEx(alma.cdbErrType.wrappers.AcsJCDBXMLErrorEx) AcsJCDBXMLErrorEx(alma.cdbErrType.wrappers.AcsJCDBXMLErrorEx)

Example 14 with AcsJCDBXMLErrorEx

use of alma.cdbErrType.wrappers.AcsJCDBXMLErrorEx in project ACS by ACS-Community.

the class HibernateWDALImpl method set_DAO.

/* (non-Javadoc)
	 * @see com.cosylab.CDB.WDALOperations#set_DAO(java.lang.String, java.lang.String)
	 */
public void set_DAO(String curl, String xml) throws CDBFieldDoesNotExistEx, CDBRecordIsReadOnlyEx, CDBExceptionEx, CDBXMLErrorEx, CDBRecordDoesNotExistEx {
    checkAccess();
    m_logger.log(AcsLogLevel.INFO, "set_DAO: " + curl);
    // read given xml and iterate through its content and check if something was changed
    DAOImpl daoImp = null;
    XMLHandler daoXMLSolver = null;
    // get content of the given xml string using parser without any shemas and validation
    // since given xml string come from a client that have no shemas and it is full expanded version
    // of existing xml or it is small composed xml of few properties
    XMLHandler xmlSolver = new XMLHandler(false, m_logger);
    // TODO markArrays == 2 impl. is a mess... I think lot of code could be removed!
    //xmlSolver.setMarkArrays(2);
    parseXML(xml, xmlSolver);
    Object node = DOMJavaClassIntrospector.getNode(curl, rootNode);
    if (node == null) {
        AcsJCDBRecordDoesNotExistEx ex = new AcsJCDBRecordDoesNotExistEx();
        ex.setCurl(curl);
        throw ex.toCDBRecordDoesNotExistEx();
    }
    // node is saved as XML
    if (node instanceof XMLSaver) {
        XMLSaver saver = (XMLSaver) node;
        Transaction tr = null;
        try {
            tr = mainSession.beginTransaction();
            saver.save(xml);
            tr.commit();
        } catch (Throwable th) {
            if (tr != null)
                tr.rollback();
            m_logger.log(AcsLogLevel.NOTICE, "Failed to set DAO: " + curl, th);
            AcsJCDBExceptionEx cdbex = new AcsJCDBExceptionEx(th);
            throw cdbex.toCDBExceptionEx();
        }
        return;
    }
    // get original xml that we will use to compare
    xml = get_DAO(curl);
    daoXMLSolver = new XMLHandler(false, m_logger);
    parseXML(xml, daoXMLSolver);
    daoImp = new DAOImpl(curl, daoXMLSolver.m_rootNode, poa, m_logger);
    // iterater throuth given xml and put changed attributes in map
    LinkedHashMap map = new LinkedHashMap();
    try {
        checkforChanges("", xmlSolver.m_rootNode, map, daoImp);
        saveChanges(curl, map);
    } catch (AcsJCDBFieldDoesNotExistEx e) {
        throw e.toCDBFieldDoesNotExistEx();
    } catch (AcsJCDBXMLErrorEx e) {
        throw e.toCDBXMLErrorEx();
    }
}
Also used : AcsJCDBExceptionEx(alma.cdbErrType.wrappers.AcsJCDBExceptionEx) AcsJCDBFieldDoesNotExistEx(alma.cdbErrType.wrappers.AcsJCDBFieldDoesNotExistEx) Transaction(org.hibernate.Transaction) XMLSaver(com.cosylab.cdb.jdal.hibernate.DOMJavaClassIntrospector.XMLSaver) AcsJCDBRecordDoesNotExistEx(alma.cdbErrType.wrappers.AcsJCDBRecordDoesNotExistEx) AcsJCDBXMLErrorEx(alma.cdbErrType.wrappers.AcsJCDBXMLErrorEx) LinkedHashMap(java.util.LinkedHashMap)

Example 15 with AcsJCDBXMLErrorEx

use of alma.cdbErrType.wrappers.AcsJCDBXMLErrorEx in project ACS by ACS-Community.

the class HibernateWDALImpl method get_DAO_Servant.

/* (non-Javadoc)
	 * @see com.cosylab.CDB.DALOperations#get_DAO_Servant(java.lang.String)
	 */
public DAO get_DAO_Servant(String curl) throws CDBXMLErrorEx, CDBRecordDoesNotExistEx {
    checkAccess();
    // remove trailing slashes, to have unique curl (used for key)
    if (curl.length() > 0 && curl.charAt(0) == '/')
        curl = curl.substring(1);
    // make sure there are no identical DAOs created
    synchronized (daoMap) {
        // get cached
        if (daoMap.containsKey(curl))
            return daoMap.get(curl);
        Object node = curl.length() == 0 ? rootNode : DOMJavaClassIntrospector.getNode(curl, rootNode);
        if (node == null || DOMJavaClassIntrospector.isPrimitive(node.getClass())) {
            AcsJCDBRecordDoesNotExistEx ex = new AcsJCDBRecordDoesNotExistEx();
            ex.setCurl(curl);
            m_logger.log(AcsLogLevel.NOTICE, "DAL::get_DAO_Servant " + ex.getShortDescription());
            throw ex.toCDBRecordDoesNotExistEx();
        }
        try {
            // create object id
            byte[] id = curl.getBytes();
            Object objImpl = null;
            DAOPOA daoImpl = null;
            if (node instanceof DAOPOA)
                objImpl = daoImpl = (DAOPOA) node;
            else if (node instanceof DAOImpl)
                objImpl = daoImpl = new DAOPOATie((DAOImpl) node);
            else if (node instanceof XMLTreeNode)
                //objImpl = daoImpl = new DAOImpl(curl, (XMLTreeNode)node, poa, m_logger);
                objImpl = daoImpl = new DAOPOATie(new NoDestroyDAOImpl(curl, (XMLTreeNode) node, poa, m_logger));
            else {
                //daoImpl = new HibernateDAOImpl(curl, node, poa, m_logger);
                HibernateWDAOImpl impl = new HibernateWDAOImpl(mainSession, curl, node, poa, m_logger);
                objImpl = impl;
                daoImpl = new DAOPOATie(impl);
                impl.setSetvant(daoImpl);
            }
            // activate object
            poa.activate_object_with_id(id, daoImpl);
            DAO href = DAOHelper.narrow(poa.servant_to_reference(daoImpl));
            // map DAO reference
            daoMap.put(curl, href);
            daoObjMap.put(curl, objImpl);
            m_logger.log(AcsLogLevel.INFO, "Returning DAO servant for: " + curl);
            return href;
        } catch (Throwable t) {
            // @todo not clean, just to be consistent v DAL impl
            t.printStackTrace();
            String info = "DAL::get_DAO_Servant " + t;
            AcsJCDBXMLErrorEx xmlErr = new AcsJCDBXMLErrorEx(t);
            xmlErr.setErrorString(info);
            m_logger.log(AcsLogLevel.NOTICE, info);
            throw xmlErr.toCDBXMLErrorEx();
        }
    }
}
Also used : WDAOPOATie(com.cosylab.CDB.WDAOPOATie) DAOPOATie(com.cosylab.CDB.DAOPOATie) AcsJCDBXMLErrorEx(alma.cdbErrType.wrappers.AcsJCDBXMLErrorEx) DAOPOA(com.cosylab.CDB.DAOPOA) WDAOPOA(com.cosylab.CDB.WDAOPOA) DAO(com.cosylab.CDB.DAO) WDAO(com.cosylab.CDB.WDAO) AcsJCDBRecordDoesNotExistEx(alma.cdbErrType.wrappers.AcsJCDBRecordDoesNotExistEx)

Aggregations

AcsJCDBXMLErrorEx (alma.cdbErrType.wrappers.AcsJCDBXMLErrorEx)21 AcsJCDBRecordDoesNotExistEx (alma.cdbErrType.wrappers.AcsJCDBRecordDoesNotExistEx)8 CDBXMLErrorEx (alma.cdbErrType.CDBXMLErrorEx)5 StringReader (java.io.StringReader)5 SAXParser (javax.xml.parsers.SAXParser)5 InputSource (org.xml.sax.InputSource)5 SAXParserFactory (javax.xml.parsers.SAXParserFactory)4 AcsJCDBExceptionEx (alma.cdbErrType.wrappers.AcsJCDBExceptionEx)3 XMLHandler (com.cosylab.cdb.jdal.XMLHandler)3 File (java.io.File)3 CDBRecordDoesNotExistEx (alma.cdbErrType.CDBRecordDoesNotExistEx)2 AcsJCDBFieldDoesNotExistEx (alma.cdbErrType.wrappers.AcsJCDBFieldDoesNotExistEx)2 DAO (com.cosylab.CDB.DAO)2 DAOOperations (com.cosylab.CDB.DAOOperations)2 DAOPOATie (com.cosylab.CDB.DAOPOATie)2 WDAO (com.cosylab.CDB.WDAO)2 WDAOPOA (com.cosylab.CDB.WDAOPOA)2 WDAOPOATie (com.cosylab.CDB.WDAOPOATie)2 IOException (java.io.IOException)2 Iterator (java.util.Iterator)2