use of alma.cdbErrType.wrappers.AcsJCDBXMLErrorEx in project ACS by ACS-Community.
the class HibernateWDALImpl method parseXML.
private void parseXML(String xml, XMLHandler xmlSolver) throws CDBXMLErrorEx {
try {
SAXParserFactory factory = SAXParserFactory.newInstance();
SAXParser saxParser = factory.newSAXParser();
synchronized (xmlNodeMonitor) {
saxParser.parse(new InputSource(new StringReader(xml)), xmlSolver);
}
if (xmlSolver.m_errorString != null) {
String info = "XML parser error: " + xmlSolver.m_errorString;
CDBXMLErrorEx xmlErr = new CDBXMLErrorEx();
m_logger.log(AcsLogLevel.NOTICE, info);
throw xmlErr;
}
} catch (Throwable t) {
String info = "SAXException: " + t.getMessage();
m_logger.log(AcsLogLevel.NOTICE, info);
AcsJCDBXMLErrorEx xmlErr = new AcsJCDBXMLErrorEx(t);
xmlErr.setErrorString(info);
throw xmlErr.toCDBXMLErrorEx();
}
}
use of alma.cdbErrType.wrappers.AcsJCDBXMLErrorEx in project ACS by ACS-Community.
the class HibernateWDALImpl method get_WDAO_Servant.
/* (non-Javadoc)
* @see com.cosylab.CDB.WDALOperations#get_WDAO_Servant(java.lang.String)
*/
public WDAO get_WDAO_Servant(String curl) throws CDBRecordIsReadOnlyEx, 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 (wdaoMap) {
// get cached
if (wdaoMap.containsKey(curl))
return (WDAO) wdaoMap.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, "WDAL::get_WDAO_Servant " + ex.getShortDescription());
throw ex.toCDBRecordDoesNotExistEx();
}
try {
Object objImpl = null;
WDAOPOA wdaoImpl = null;
if (node instanceof WDAOPOA)
objImpl = wdaoImpl = (WDAOPOA) node;
else //else if (node instanceof XMLTreeNode)
//{
// DAOImpl daoImpl = new DAOImpl(curl, (XMLTreeNode)node, poa, m_logger);
// objImpl = wdaoImpl = new WDAOImpl(this, curl, daoImpl, poa, m_logger);
//}
{
HibernateWDAOImpl impl = new HibernateWDAOImpl(mainSession, curl, node, poa, m_logger);
objImpl = impl;
wdaoImpl = new WDAOPOATie(impl);
impl.setSetvant(wdaoImpl);
}
// create object id
byte[] id = ("WDAO" + curl).getBytes();
// activate object
poa.activate_object_with_id(id, wdaoImpl);
WDAO href = WDAOHelper.narrow(poa.servant_to_reference(wdaoImpl));
// map DAO reference
wdaoMap.put(curl, href);
wdaoObjMap.put(curl, objImpl);
m_logger.log(AcsLogLevel.INFO, "Returning WDAO servant for: " + curl);
return href;
} catch (Throwable t) {
// @todo not clean, just to be consistent v DAL impl
String info = "WDAL::get_WDAO_Servant " + t;
AcsJCDBXMLErrorEx xmlErr = new AcsJCDBXMLErrorEx(t);
xmlErr.setErrorString(info);
m_logger.log(AcsLogLevel.NOTICE, info);
throw xmlErr.toCDBXMLErrorEx();
}
}
}
use of alma.cdbErrType.wrappers.AcsJCDBXMLErrorEx in project ACS by ACS-Community.
the class HibernateWDALImpl method get_DAO.
/* (non-Javadoc)
* @see com.cosylab.CDB.DALOperations#get_DAO(java.lang.String)
*/
public String get_DAO(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);
m_logger.log(AcsLogLevel.INFO, "Returning XML record for: " + 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);
String detailMsg = (node == null ? "node is null." : "node is primitive (" + node.getClass().getName() + ").");
m_logger.log(AcsLogLevel.NOTICE, detailMsg, ex);
throw ex.toCDBRecordDoesNotExistEx();
} else if (node instanceof DAOImpl) {
String ret = ((DAOImpl) node).getRootNode().toString(false);
m_logger.finest("get_DAO(" + curl + ") returning " + ret);
return ret;
}
// remove last slash
if (curl.length() > 0 && curl.charAt(curl.length() - 1) == '/')
curl = curl.substring(0, curl.length() - 1);
// get node name only
String name;
int pos = curl.lastIndexOf('/');
if (pos == -1)
name = curl;
else
name = curl.substring(pos + 1, curl.length());
// root
if (name.length() == 0)
name = "root";
try {
String ret = "<?xml version='1.0' encoding='ISO-8859-1'?>" + DOMJavaClassIntrospector.toXML(DOMJavaClassIntrospector.getRootNodeXMLName(name, node), node, curl, m_logger);
m_logger.finest("get_DAO(" + curl + ") returning " + ret);
return ret;
} catch (Throwable t) {
t.printStackTrace();
String info = "DAL::get_DAO " + t;
AcsJCDBXMLErrorEx xmlErr = new AcsJCDBXMLErrorEx(t);
xmlErr.setErrorString(info);
m_logger.log(AcsLogLevel.NOTICE, info);
throw xmlErr.toCDBXMLErrorEx();
}
}
use of alma.cdbErrType.wrappers.AcsJCDBXMLErrorEx in project ACS by ACS-Community.
the class WDALImpl method saveChanges.
/**
* Save changes given by map to the node identified by curl
*
* @param curl
* @param propertyMap
*
* @throws CDBXMLErrorEx
* @throws CDBExceptionEx
* @throws CDBFieldDoesNotExistEx
*/
public void saveChanges(String curl, Map propertyMap) throws AcsJCDBXMLErrorEx, AcsJCDBExceptionEx, AcsJCDBFieldDoesNotExistEx {
if (!nodeExists(curl)) {
// we can't save merged curl
return;
}
WriteXMLHandler xmlHandler = null;
try {
// create plain parser
SAXParserFactory factory = SAXParserFactory.newInstance();
SAXParser saxParser = factory.newSAXParser();
xmlHandler = new WriteXMLHandler(propertyMap);
Object lexicalParser = saxParser.getProperty("http://xml.org/sax/properties/lexical-handler");
saxParser.setProperty("http://xml.org/sax/properties/lexical-handler", xmlHandler);
logger.log(AcsLogLevel.DEBUG, "saveChanges('" + curl + "'): - Parsing");
saxParser.parse(getNodeFile(curl), xmlHandler);
} catch (Exception e) {
e.printStackTrace();
AcsJCDBXMLErrorEx e2 = new AcsJCDBXMLErrorEx(e);
e2.setCurl(curl);
//throw new CDBXMLErrorEx(e.toString());
throw e2;
}
StringWriter sw = new StringWriter();
xmlHandler.writeXML(sw);
// try{
// now check that everything conforms to the schema
validateXML(sw.toString());
// ok it is safe now to write it to disk
writeXmlData(curl, sw.toString());
// }catch(AcsJCDBXMLErrorEx e){
// throw e;
//}catch(AcsJCDBException e){
// thro
//}
}
use of alma.cdbErrType.wrappers.AcsJCDBXMLErrorEx in project ACS by ACS-Community.
the class WDALImpl method add_node.
/**
* Adds a new node specified by curl to the CDB initially filed with
*
* @param curl uri for the CDB node
* @param xml
*
* @throws CDBRecordAlreadyExistsEx
* @throws CDBXMLErrorEx
* @throws CDBExceptionEx
*/
public void add_node(String curl, String xml) throws CDBRecordAlreadyExistsEx, CDBXMLErrorEx, CDBExceptionEx {
dalImpl.totalDALInvocationCounter.incrementAndGet();
logger.log(AcsLogLevel.INFO, "add_node " + curl);
// check if node is already there
if (nodeExists(curl)) {
logger.log(AcsLogLevel.NOTICE, "Record already exists: " + curl);
AcsJCDBRecordAlreadyExistsEx e2 = new AcsJCDBRecordAlreadyExistsEx();
e2.setCurl(curl);
e2.log(logger);
throw e2.toCDBRecordAlreadyExistsEx();
}
// check that suplied xml is valid
try {
validateXML(xml);
} catch (AcsJCDBXMLErrorEx e) {
e.log(logger);
throw e.toCDBXMLErrorEx();
}
// recreate dir structure and put data content
getNodeFile(curl).getParentFile().mkdirs();
try {
// write content
writeXmlData(curl, xml);
} catch (AcsJCDBExceptionEx e) {
throw e.toCDBExceptionEx();
}
}
Aggregations