use of com.cosylab.CDB.DAOOperations in project ACS by ACS-Community.
the class CDBAccess method internalConnect.
/**
* Performs the connect of the specified DAO.
*
* @param proxy the proxy to connect, non-<code>null</code>
*/
private void internalConnect(DAOProxy proxy) {
String curl = null;
try {
checkDALConnection();
} catch (Throwable th) {
// TODO @todo replace
RuntimeException re = new RuntimeException("Failed to obtain DAO for proxy '" + proxy + "'.", th);
throw re;
}
DAOOperations dao = null;
try {
curl = proxy.getCURL();
if (remoteDAO) {
dao = dalReference.get_DAO_Servant(curl);
} else {
String xml = dalReference.get_DAO(curl);
SAXParserFactory factory = SAXParserFactory.newInstance();
SAXParser saxParser = factory.newSAXParser();
// use CDB XML handler which does not creates strings...
XMLHandler xmlSolver = new XMLHandler(false, logger);
saxParser.parse(new InputSource(new StringReader(xml)), xmlSolver);
if (xmlSolver.m_errorString != null) {
AcsJCDBXMLErrorEx e = new AcsJCDBXMLErrorEx();
e.setErrorString("XML parser error: " + xmlSolver.m_errorString);
throw e;
//throw new XMLerror("XML parser error: " + xmlSolver.m_errorString);
}
// create non-CORBA related, silent DAO
dao = new DAOImpl(curl, xmlSolver.m_rootNode, null, logger, true);
proxy.setElementName(xmlSolver.m_rootNode.getName());
}
// register listener, if not already registered
if (changeListener != null) {
if (!changeListener.isRegistered(curl))
changeListener.handle(dalReference, curl, proxy);
}
} catch (Throwable th) {
// TODO @todo replace
RuntimeException re = new RuntimeException("Failed to obtain DAO object for proxy '" + proxy + "'.", th);
throw re;
}
try {
proxy.initialize(dao);
} catch (Throwable th) {
// TODO @todo replace
RuntimeException re = new RuntimeException("The proxy '" + proxy + "' rejects the DAO.", th);
throw re;
}
logger.config("Connected to DAO '" + proxy.getCURL() + "'.");
}
use of com.cosylab.CDB.DAOOperations in project ACS by ACS-Community.
the class DALImpl method get_DAO_Servant.
/**
* create DAO servant with requested XML
*/
public synchronized DAO get_DAO_Servant(String curl) throws CDBRecordDoesNotExistEx, CDBXMLErrorEx {
totalDALInvocationCounter.incrementAndGet();
// make sure CURL->DAO mapping is surjective function, remove leading slash
if (curl.length() > 1 && curl.charAt(0) == '/')
curl = curl.substring(1);
// make sure there are no identical DAOs created
synchronized (daoMap) {
if (daoMap.containsKey(curl))
return daoMap.get(curl);
}
// do the hardwork here
XMLHandler xmlSolver;
try {
xmlSolver = loadRecords(curl, false);
} catch (AcsJCDBXMLErrorEx e) {
// @todo watch if this log also needs a repeat guard, similar to logRecordNotExistWithRepeatGuard
m_logger.log(AcsLogLevel.NOTICE, "Failed to read curl '" + curl + "'.", e);
throw e.toCDBXMLErrorEx();
} catch (AcsJCDBRecordDoesNotExistEx e) {
logRecordNotExistWithRepeatGuard(curl);
throw e.toCDBRecordDoesNotExistEx();
}
if (xmlSolver == null) {
// @TODO can this happen? Should we not throw an exception then?
return null;
}
try {
DAO href = null;
// bind to map
synchronized (daoMap) {
// execution when different DAO are created
if (daoMap.containsKey(curl))
return daoMap.get(curl);
final DAOImpl servantDelegate = new DAOImpl(curl, xmlSolver.m_rootNode, poa, m_logger);
DAOOperations topLevelServantDelegate = servantDelegate;
if (Boolean.getBoolean(Server.LOG_CDB_CALLS_PROPERTYNAME)) {
// Currently we only intercept the functional IDL-defined methods, by wrapping servantDelegate.
// If we want to also intercept the CORBA admin methods, then *servant* below should be wrapped with a dynamic proxy instead.
DAOOperations interceptingServantDelegate = SimpleCallInterceptor.createSimpleInterceptor(DAOOperations.class, servantDelegate, m_logger);
topLevelServantDelegate = interceptingServantDelegate;
}
final Servant servant = new DAOPOATie(topLevelServantDelegate);
// create object id.
// Note that the ID *must* be derived from the curl, because DAOImpl#destroy will do the same in POA#deactivate_object.
byte[] id = curl.getBytes();
// activate object
poa.activate_object_with_id(id, servant);
href = DAOHelper.narrow(poa.servant_to_reference(servant));
// map DAO reference
daoMap.put(curl, href);
}
m_logger.log(AcsLogLevel.DEBUG, "Returning DAO servant for: " + curl);
return href;
} catch (Throwable t) {
String info = "DAO::get_DAO_Servant " + t;
AcsJCDBXMLErrorEx xmlErr = new AcsJCDBXMLErrorEx(t);
xmlErr.setErrorString(info);
m_logger.log(AcsLogLevel.NOTICE, info);
throw xmlErr.toCDBXMLErrorEx();
}
}
Aggregations