use of alma.cdbErrType.wrappers.AcsJCDBXMLErrorEx in project ACS by ACS-Community.
the class WDALImpl method set_DAO.
/**
* Change content of a node identified by curl so given xml is scanned for
* differences which are applied. This function can be invoked with full
* expanded version of the existing xml with some changes or it can be
* invoked by small xml with only changes to be applied. For example to
* change parameter 'Timeot' in Manager we can pass as xml
* <pre>
* <code>
* <?xml version="1.0" encoding="ISO-8859-1"?>
* <Manager Timeout="50.0"/>
* </code>
* </pre>
* and new value will be saved in the xml file.
*
* @param curl uri for the CDB node
* @param xml
*
* @throws CDBRecordDoesNotExistEx
* @throws CDBFieldDoesNotExistEx
* @throws CDBRecordIsReadOnlyEx
* @throws CDBXMLErrorEx
* @throws CDBExceptionEx
*/
public void set_DAO(String curl, String xml) throws CDBRecordDoesNotExistEx, CDBFieldDoesNotExistEx, CDBRecordIsReadOnlyEx, CDBXMLErrorEx, CDBExceptionEx {
dalImpl.totalDALInvocationCounter.incrementAndGet();
logger.log(AcsLogLevel.INFO, "set_DAO " + curl);
// check if node exists
if (!nodeExists(curl)) {
logger.log(AcsLogLevel.NOTICE, "Record does not exist: " + curl);
throw new CDBRecordDoesNotExistEx();
}
File xmlFile = getNodeFile(curl);
if (!xmlFile.canWrite()) {
throw new CDBRecordIsReadOnlyEx();
}
// 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 smal composed xml of few properties
XMLHandler xmlSolver = new XMLHandler(false, logger);
// TODO markArrays == 2 impl. is a mess... I think lot of code could be removed!
//xmlSolver.setMarkArrays(2);
parseXML(xml, xmlSolver);
// get original xml that we will use to compare
xml = dalImpl.get_DAO(curl);
daoXMLSolver = new XMLHandler(false, logger);
parseXML(xml, daoXMLSolver);
daoImp = new DAOImpl(curl, daoXMLSolver.m_rootNode, poa, 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();
} catch (AcsJCDBExceptionEx e) {
throw e.toCDBExceptionEx();
}
}
use of alma.cdbErrType.wrappers.AcsJCDBXMLErrorEx in project ACS by ACS-Community.
the class DALImpl method parseNode.
public void parseNode(DALNode node, XMLHandler xmlSolver, String path) throws SAXException, IOException, AcsJCDBXMLErrorEx {
m_logger.finest("parseNode called for " + path + "/" + node.name);
DALNode[] childs = node.getChilds();
DALNode curlNode = node.getCurlNode();
if (curlNode != null) {
String xmlPath = getRecordPath(node.getCurl());
// NOTE: we cannot cache due to setFirstElement.... sadly :(
//getFromCache(node.getCurl());
String xml = null;
File xmlFile = null;
if (xml != null) {
saxParser.parse(new InputSource(new StringReader(xml)), xmlSolver);
} else {
xmlFile = new File(xmlPath);
xmlSolver.setFirstElement(node.name);
saxParser.parse(xmlFile, xmlSolver);
}
if (xmlSolver.m_errorString != null) {
String info = "XML parser error: ";
if (xmlFile != null) {
info += "file=" + xmlFile.getAbsolutePath() + " ";
}
info += xmlSolver.m_errorString;
AcsJCDBXMLErrorEx cdbxmlErr = new AcsJCDBXMLErrorEx();
cdbxmlErr.setFilename(xmlPath);
cdbxmlErr.setNodename(node.name);
cdbxmlErr.setCurl(node.getCurl());
cdbxmlErr.setErrorString(info);
m_logger.log(AcsLogLevel.NOTICE, info);
throw cdbxmlErr;
}
} else {
xmlSolver.startDocument();
xmlSolver.startElement(null, null, node.name, new org.xml.sax.helpers.AttributesImpl());
}
// make m_elementsMap containing only elements from the XML
if (xmlSolver.m_rootNode != null)
xmlSolver.m_rootNode.markNodesAsElements();
// and childs if exist
for (int i = 0; i < childs.length; i++) {
parseNode(childs[i], xmlSolver, path + "/" + node.name);
}
xmlSolver.closeElement();
}
use of alma.cdbErrType.wrappers.AcsJCDBXMLErrorEx in project ACS by ACS-Community.
the class DALImpl method loadRecord.
private XMLHandler loadRecord(String curl, boolean toString) throws AcsJCDBRecordDoesNotExistEx, AcsJCDBXMLErrorEx {
String xmlPath = getRecordPath(curl);
File xmlFile = new File(xmlPath);
if (!xmlFile.exists()) {
AcsJCDBRecordDoesNotExistEx recordDoesNotExist = new AcsJCDBRecordDoesNotExistEx();
recordDoesNotExist.setCurl(curl);
throw recordDoesNotExist;
}
XMLHandler xmlSolver = new XMLHandler(toString, m_logger);
xmlSolver.setMarkArrays(1);
try {
m_logger.log(AcsLogLevel.DEBUG, "Parsing xmlFile=" + xmlFile);
saxParser.parse(xmlFile, xmlSolver);
if (xmlSolver.m_errorString != null) {
String info = "XML parser error: " + xmlSolver.m_errorString;
//CDBXMLError xmlErr = new CDBXMLError(info);
AcsJCDBXMLErrorEx cdbxmlErr = new AcsJCDBXMLErrorEx();
cdbxmlErr.setFilename(xmlPath);
cdbxmlErr.setCurl(curl);
cdbxmlErr.setErrorString(info);
throw cdbxmlErr;
}
return xmlSolver;
} catch (AcsJCDBXMLErrorEx cdbxmlErr) {
throw cdbxmlErr;
} catch (Throwable t) {
String info = "SAXException " + t;
//CDBXMLError xmlErr = new CDBXMLError(info);
AcsJCDBXMLErrorEx cdbxmlErr = new AcsJCDBXMLErrorEx(t);
cdbxmlErr.setCurl(curl);
cdbxmlErr.setErrorString(info);
throw cdbxmlErr;
}
}
use of alma.cdbErrType.wrappers.AcsJCDBXMLErrorEx 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();
}
}
use of alma.cdbErrType.wrappers.AcsJCDBXMLErrorEx in project ACS by ACS-Community.
the class HibernateWDALImpl method checkforChanges.
// ------------------------------------------------------------------------------
// code below copied from DALImpl
// ------------------------------------------------------------------------------
/**
* 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);
}
}
Aggregations