Search in sources :

Example 1 with AcsJCDBXMLErrorEx

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

the class JNDIContext method lookup.

/**
	 * @see Context#lookup(Name)
	 * THIS IS OLD CDB implementation
	public Object lookup(Name name) throws NamingException {
		//System.out.println("CDBContext lookup on " + this.name + " for " + name.toString());
		String nameToLookup = this.name + "/" + name;
		String recordName = nameToLookup.substring(nameToLookup.lastIndexOf('/')+1);
		// get list from the server 
		String elements = dal.list_nodes(nameToLookup);
		try {
			if (elements.indexOf(recordName + ".xml") != -1) {
				String xml = dal.get_DAO(nameToLookup);
				return new JNDIXMLContext(nameToLookup, elements, xml);
			} else {
				if (elements.length() == 0 ) { // inside a XML?
					int slashIndex = nameToLookup.lastIndexOf('/');
					String newName;
					while( slashIndex != -1 ) {
						newName = nameToLookup.substring(0,slashIndex);
						recordName = newName.substring(newName.lastIndexOf('/')+1);
						elements = dal.list_nodes(newName);
						if (elements.indexOf(recordName + ".xml") != -1) {
							String xml = dal.get_DAO(newName);
							recordName = nameToLookup.substring(slashIndex+1);
							return new JNDIXMLContext(newName, elements, xml).lookup(recordName);
						}
						slashIndex = newName.lastIndexOf('/');
					}
					throw new NamingException("No name " + nameToLookup );
				}
				return new JNDIContext(nameToLookup, elements);
			}
		} catch (CDBRecordDoesNotExistEx e) {
			// if it does not exists then it is just a context
			return new JNDIContext(nameToLookup, elements);
		} catch (CDBXMLErrorEx e) {
			AcsJCDBXMLErrorEx acse = new AcsJCDBXMLErrorEx(e);
			throw new NamingException(acse.getFilename());
		}
	}*/
/**
     * 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;
    // is subnode
    StringTokenizer token = new StringTokenizer(elements);
    while (token.hasMoreTokens()) if (token.nextElement().equals(lookupName)) {
        // is DAO?
        if (daoElements != null) {
            try {
                return new JNDIXMLContext(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 JNDIContext(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 JNDIXMLContext(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 2 with AcsJCDBXMLErrorEx

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

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

the class DALImpl method loadRecords.

/**
	 * Returns a xml constructed of all records below given curl
	 * 
	 * @param curl
	 * @param toString
	 * @return
	 * @throws AcsJCDBRecordDoesNotExistEx
	 * @throws AcsJCDBXMLErrorEx
	 */
public XMLHandler loadRecords(String curl, boolean toString) throws AcsJCDBRecordDoesNotExistEx, AcsJCDBXMLErrorEx {
    StopWatch sw = new StopWatch(m_logger);
    try {
        // create hierarchy of all nodes if it is not created yet 
        synchronized (this) {
            if (rootNode == null) {
                //no Error thrown
                rootNode = DALNode.getRoot(m_root);
            }
        }
        //no Error thrown
        String strFileCurl = curl;
        String strNodeCurl = "";
        DALNode curlNode = null;
        boolean isEmbeddedNode = false;
        while (strFileCurl != null) {
            curlNode = rootNode.findNode(strFileCurl);
            if (curlNode == null) {
                // Therefore we must move up toward the root node to find a valid parent xml node.
                if (strFileCurl.lastIndexOf('/') > 0) {
                    strNodeCurl = strFileCurl.substring(strFileCurl.lastIndexOf('/') + 1) + "/" + strNodeCurl;
                    strFileCurl = strFileCurl.substring(0, strFileCurl.lastIndexOf('/'));
                    isEmbeddedNode = true;
                } else {
                    strFileCurl = null;
                }
            } else {
                // curlNode and strFileCurl point to the node that has the relevant XML file 
                break;
            }
        }
        m_logger.log(AcsLogLevel.DEBUG, "loadRecords(curl=" + curl + "), strFileCurl=" + strFileCurl + ", strNodeCurl=" + strNodeCurl);
        // because the "embedded" node data will not be found in other XML files.
        if (strFileCurl == null || (isEmbeddedNode && !curlNode.hasXmlChild())) {
            AcsJCDBRecordDoesNotExistEx recordDoesNotExist = new AcsJCDBRecordDoesNotExistEx();
            recordDoesNotExist.setCurl(curl);
            throw recordDoesNotExist;
        }
        if (curlNode.isSimple()) {
            m_logger.log(AcsLogLevel.DEBUG, "loadRecords(curl=" + curl + "); curlNode '" + curlNode.name + "' is simple.");
            if (curl.equals(strFileCurl)) {
                return loadRecord(strFileCurl, toString);
            } else {
                XMLHandler xmlSolver = loadRecord(strFileCurl, false);
                try {
                    return xmlSolver.getChild(strNodeCurl);
                } catch (AcsJCDBRecordDoesNotExistEx e) {
                    e.setCurl(strFileCurl + e.getCurl());
                    throw e;
                }
            }
        }
        m_logger.log(AcsLogLevel.DEBUG, "loadRecords(curl=" + curl + "), curlNode is Complex");
        XMLHandler xmlSolver;
        try {
            //xmlSolver.startElement(null,null,"curl",new org.xml.sax.helpers.AttributesImpl);
            if (curl.equals(strFileCurl)) {
                xmlSolver = new XMLHandler(toString, m_logger);
                xmlSolver.setAutoCloseStartingElement(false);
                parseNode(curlNode, xmlSolver, "");
                //xmlSolver.closeElement();
                return xmlSolver;
            } else {
                //here we must return the node inside the xmlSolver with curl= strNodeCurl		
                xmlSolver = new XMLHandler(false, m_logger);
                xmlSolver.setMarkArrays(1);
                xmlSolver.setAutoCloseStartingElement(false);
                parseNode(curlNode, xmlSolver, "");
                return xmlSolver.getChild(strNodeCurl);
            }
        } catch (AcsJCDBRecordDoesNotExistEx e) {
            e.setCurl(strFileCurl + e.getCurl());
            throw e;
        } catch (SAXParseException e) {
            AcsJCDBXMLErrorEx cdbxmlErr = new AcsJCDBXMLErrorEx();
            cdbxmlErr.setErrorString("SAXParseException: " + e.getMessage());
            cdbxmlErr.setCurl(curl);
            cdbxmlErr.setFilename(e.getSystemId() + ", line=" + e.getLineNumber());
            throw cdbxmlErr;
        } catch (Throwable thr) {
            AcsJCDBXMLErrorEx cdbxmlErr = new AcsJCDBXMLErrorEx(thr);
            cdbxmlErr.setCurl(curl);
            throw cdbxmlErr;
        }
    } finally {
        long lt = sw.getLapTimeMillis();
        m_logger.finest("Time spent in loadRecords(" + curl + "): " + lt);
    }
}
Also used : SAXParseException(org.xml.sax.SAXParseException) AcsJCDBRecordDoesNotExistEx(alma.cdbErrType.wrappers.AcsJCDBRecordDoesNotExistEx) AcsJCDBXMLErrorEx(alma.cdbErrType.wrappers.AcsJCDBXMLErrorEx) StopWatch(alma.acs.util.StopWatch)

Example 4 with AcsJCDBXMLErrorEx

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

the class WDALImpl method validateXML.

/**
	 * Check that everything conforms to the schema in given xml. This check
	 * will be done by parser used in DAL.
	 *
	 * @param xml
	 *
	 * @throws AcsJCDBXMLErrorEx
	 */
public void validateXML(String xml) throws AcsJCDBXMLErrorEx {
    try {
        XMLHandler dalSolver = new XMLHandler(true, logger);
        SAXParser saxParser = dalImpl.getSaxParser();
        saxParser.parse(new InputSource(new StringReader(xml)), dalSolver);
        if (dalSolver.m_errorString != null) {
            logger.log(AcsLogLevel.NOTICE, dalSolver.m_errorString);
            AcsJCDBXMLErrorEx e2 = new AcsJCDBXMLErrorEx();
            e2.setErrorString(dalSolver.m_errorString);
            throw e2;
        }
    } catch (AcsJCDBXMLErrorEx e) {
        throw e;
    } catch (Throwable t) {
        t.printStackTrace();
        AcsJCDBXMLErrorEx e2 = new AcsJCDBXMLErrorEx(t);
        throw e2;
    //CDBXMLErrorEx xmlErr = new CDBXMLErrorEx(t.toString());
    //throw xmlErr;
    }
}
Also used : InputSource(org.xml.sax.InputSource) StringReader(java.io.StringReader) SAXParser(javax.xml.parsers.SAXParser) AcsJCDBXMLErrorEx(alma.cdbErrType.wrappers.AcsJCDBXMLErrorEx)

Example 5 with AcsJCDBXMLErrorEx

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

the class WDALImpl method checkforChanges.

/**
	 * Recursively scans nodes and check every property with current xml 
	 *
	 * @param name
	 * @param node
	 * @param map
	 * @param dao
	 *
	 * @throws AcsJCDBFieldDoesNotExistEx
	 * @throws AcsJCDBXMLErrorEx
	 */
private void checkforChanges(String name, XMLTreeNode node, Map map, DAOImpl dao) throws AcsJCDBFieldDoesNotExistEx, AcsJCDBXMLErrorEx {
    String propertyName;
    String currentValue;
    String value;
    for (Iterator iter = node.m_subNodesMap.keySet().iterator(); iter.hasNext(); ) {
        String key = (String) iter.next();
        XMLTreeNode childNode = (XMLTreeNode) node.m_subNodesMap.get(key);
        if (childNode.isMapNode()) {
            for (Iterator iterator = childNode.m_fieldMap.keySet().iterator(); iterator.hasNext(); ) {
                String childKey = (String) iterator.next();
                map.put(XMLTreeNode.MAP_TYPE + "/" + key + "/" + childKey, childNode.m_fieldMap.get(childKey));
            }
            node.m_subNodesMap.clear();
        }
    }
    // node attributes i.e 'CommandLine' in node 'Manager'
    for (Iterator iter = node.m_fieldMap.keySet().iterator(); iter.hasNext(); ) {
        String key = (String) iter.next();
        propertyName = name + "/" + key;
        try {
            currentValue = dao.get_field_data(propertyName);
        } catch (Exception e) {
            // TODO additional elements in maps will cause an exception... they are not supported
            // TODO also if an element is removed, this will not be detected
            e.printStackTrace();
            AcsJCDBXMLErrorEx xmlErr = new AcsJCDBXMLErrorEx(e);
            throw xmlErr;
        }
        value = (String) node.m_fieldMap.get(key);
        if (!value.equals(currentValue)) {
            map.put(propertyName, value);
        }
    }
    // subnodes for this node i.e. 'current' for 'TEST_PS_1'
    for (Iterator iter = node.m_subNodesMap.keySet().iterator(); iter.hasNext(); ) {
        String key = (String) iter.next();
        checkforChanges(name + "/" + key, (XMLTreeNode) node.m_subNodesMap.get(key), map, dao);
    }
}
Also used : Iterator(java.util.Iterator) AcsJCDBXMLErrorEx(alma.cdbErrType.wrappers.AcsJCDBXMLErrorEx) IOException(java.io.IOException) SAXException(org.xml.sax.SAXException)

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