use of com.cosylab.cdb.jdal.hibernate.DOMJavaClassIntrospector.XMLSaver 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();
}
}
Aggregations