use of com.cosylab.CDB.WDAL 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 com.cosylab.CDB.WDAL in project ACS by ACS-Community.
the class DAOManager method backupCDB.
public void backupCDB() {
DAL dal = null;
WDAL wdal = null;
try {
dal = _contServ.getCDB();
} catch (AcsJContainerServicesEx e) {
return;
}
wdal = WDALHelper.narrow(dal);
if (wdal == null)
return;
String src = "Alarms";
String dst;
int i = 1;
do {
dst = src + ".bkp." + i;
i++;
} while (nodeExists(wdal, "", dst));
copyNode(wdal, src, dst);
}
use of com.cosylab.CDB.WDAL in project ACS by ACS-Community.
the class CDBDefault method setDefault.
/**
* Recursively go throw the xml finding nodes with the same Type. If the type match,
* compares the Name. If is the same name, sets the Default=true, in the other case
* sets the Default attribute to false.
* @param node_root the root of all components xml .
* @param in_type the type of the component.
* @param in_name the name of the component to set up default.
*
*/
public static void setDefault(XMLTreeNode node_root, String in_type, String in_name) {
try {
Iterator<String> nodesIter = node_root.getNodesMap().keySet().iterator();
WDAL wdal = WDALHelper.narrow(orb.string_to_object(strIOR));
while (nodesIter.hasNext()) {
String key = nodesIter.next();
XMLTreeNode node = node_root.getNodesMap().get(key);
String name = node.getFieldMap().get("Name");
String type = node.getFieldMap().get("Type");
String isDefault = node.getFieldMap().get("Default");
String strTrue = "true";
if (in_type.equals(type)) {
if (strTrue.equals(isDefault)) {
if (in_name.equals(name))
return;
else {
//write Default = false
try {
//System.out.println("1-"+curl_allComponents+"\t"+name);
WDAO wdao = wdal.get_WDAO_Servant(curl_allComponents);
wdao.set_string(name + "/Default", "false");
} catch (Exception e) {
//System.out.println("2-"+curl_allComponents+ "/" + name);
WDAO wdao = wdal.get_WDAO_Servant(curl_allComponents + "/" + name);
wdao.set_string("Default", "false");
}
}
} else if (in_name.equals(name)) {
// write Default = true
try {
//System.out.println("3-"+curl_allComponents+ "\t" + name);
WDAO wdao = wdal.get_WDAO_Servant(curl_allComponents);
wdao.set_string(name + "/Default", "true");
} catch (Exception e) {
//System.out.println("4-"+curl);
WDAO wdao = wdal.get_WDAO_Servant(curl);
wdao.set_string("Default", "true");
}
}
}
XMLTreeNode value = node_root.getNodesMap().get(key);
setDefault(value, in_type, in_name);
}
} catch (CDBXMLErrorEx e) {
m_logger.log(AcsLogLevel.NOTICE, "Xml Error", e);
e.printStackTrace();
} catch (Exception e) {
m_logger.log(AcsLogLevel.NOTICE, "Error", e);
e.printStackTrace();
}
}
Aggregations