use of alma.cdbErrType.CDBXMLErrorEx in project ACS by ACS-Community.
the class ACSCategoryDAOImpl method flushCategories.
public void flushCategories(Categories cats) {
if (conf == null || !conf.isWriteable())
throw new IllegalStateException("no writable configuration accessor");
if (cats == null)
throw new IllegalArgumentException("Null Categories argument");
StringWriter FFWriter = new StringWriter();
Marshaller FF_marshaller;
try {
FF_marshaller = new Marshaller(FFWriter);
} catch (IOException e) {
e.printStackTrace();
return;
}
FF_marshaller.setValidation(false);
try {
FF_marshaller.marshal(cats);
} catch (MarshalException e) {
e.printStackTrace();
return;
} catch (ValidationException e) {
e.printStackTrace();
return;
}
try {
conf.deleteConfiguration(CATEGORY_DEFINITION_PATH);
conf.addConfiguration(CATEGORY_DEFINITION_PATH, FFWriter.toString().replaceFirst("xsi:type=\".*\"", ""));
} catch (org.omg.CORBA.UNKNOWN e) {
try {
conf.addConfiguration(CATEGORY_DEFINITION_PATH, FFWriter.toString().replaceFirst("xsi:type=\".*\"", ""));
} catch (Exception e1) {
e1.printStackTrace();
}
} catch (CDBXMLErrorEx e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
throw new IllegalStateException("Category already exists");
}
}
use of alma.cdbErrType.CDBXMLErrorEx 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);
}
use of alma.cdbErrType.CDBXMLErrorEx in project ACS by ACS-Community.
the class WDALImpl method parseXML.
private void parseXML(String xml, XMLHandler xmlSolver) throws CDBXMLErrorEx {
try {
SAXParserFactory factory = SAXParserFactory.newInstance();
SAXParser saxParser = factory.newSAXParser();
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();
logger.log(AcsLogLevel.NOTICE, info);
throw xmlErr;
}
} catch (Throwable t) {
String info = "SAXException " + t;
CDBXMLErrorEx xmlErr = new CDBXMLErrorEx();
logger.log(AcsLogLevel.NOTICE, info);
throw xmlErr;
}
}
use of alma.cdbErrType.CDBXMLErrorEx in project ACS by ACS-Community.
the class BrowserJNDIContext method lookup.
/**
* 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;
// @todo TODO this creates DAO and wastes some of resources... DAL method to get resources would be nice
boolean hasAttributes = false;
try {
// NOTE check only if needed
if (daoElements == null)
hasAttributes = dal.get_DAO_Servant(fullLookupName).get_string("_attributes").trim().length() > 0;
} catch (Throwable th) {
// noop
}
CDBLogic.setKey(fullLookupName);
// is subnode
StringTokenizer token = new StringTokenizer(elements);
while (token.hasMoreTokens()) if (token.nextElement().equals(lookupName)) {
// is DAO?
if (daoElements != null || hasAttributes) {
try {
return new BrowserJNDIXMLContext(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 BrowserJNDIContext(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 BrowserJNDIXMLContext(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);
}
use of alma.cdbErrType.CDBXMLErrorEx 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