debug("newDocumentTemplateHandler", "start method");
// get the id of the object
String idStr = (String) request.getAttribute(ObjectsTreeConstants.OBJECT_ID);
Integer biObjectID = new Integer(idStr);
BIObject obj = DAOFactory.getBIObjectDAO().loadBIObjectById(biObjectID);
Engine engine = obj.getEngine();
// GET THE TYPE OF ENGINE (INTERNAL / EXTERNAL) AND THE SUITABLE BIOBJECT TYPES
Domain engineType = null;
Domain compatibleBiobjType = null;
engineType = DAOFactory.getDomainDAO().loadDomainById(engine.getEngineTypeId());
compatibleBiobjType = DAOFactory.getDomainDAO().loadDomainById(engine.getBiobjTypeId());
String compatibleBiobjTypeCd = compatibleBiobjType.getValueCd();
String biobjTypeCd = obj.getBiObjectTypeCode();
// CHECK IF THE BIOBJECT IS COMPATIBLE WITH THE TYPES SUITABLE FOR THE ENGINE
if (!compatibleBiobjTypeCd.equalsIgnoreCase(biobjTypeCd)) {
// the engine document type and the biobject type are not compatible
logger.fatal("Engine cannot execute input document type: " +
"the engine " + engine.getName() + " can execute '" + compatibleBiobjTypeCd + "' type documents " +
"while the input document is a '" + biobjTypeCd + "'.");
Vector params = new Vector();
params.add(engine.getName());
params.add(compatibleBiobjTypeCd);
params.add(biobjTypeCd);
errorHandler.addError(new EMFUserError(EMFErrorSeverity.ERROR, 2002, params));
return;
}
// IF THE ENGINE IS EXTERNAL
if ("EXT".equalsIgnoreCase(engineType.getValueCd())) {
try {
// instance the driver class
String driverClassName = obj.getEngine().getDriverName();
IEngineDriver aEngineDriver = (IEngineDriver)Class.forName(driverClassName).newInstance();
EngineURL templateBuildUrl = null;
try {
templateBuildUrl = aEngineDriver.getNewDocumentTemplateBuildUrl(obj, profile);
} catch (InvalidOperationRequest ior) {
logger.info("Engine " + engine.getName() + " cannot build document template");
Vector params = new Vector();
params.add(engine.getName());
errorHandler.addError(new EMFUserError(EMFErrorSeverity.INFORMATION, "1076", params));
response.setAttribute(ObjectsTreeConstants.OBJECT_ID, idStr);
response.setAttribute("biobject", obj);
return;
}
// set into the reponse the url to be invoked
response.setAttribute(ObjectsTreeConstants.CALL_URL, templateBuildUrl);
response.setAttribute(SpagoBIConstants.PUBLISHER_NAME, "TemplateBuildPublisher");
response.setAttribute("biobject", obj);
response.setAttribute("operation", "newDocumentTemplate");
} catch (Exception e) {
logger.fatal("Error retrieving template build url", e);
errorHandler.addError(new EMFUserError(EMFErrorSeverity.ERROR, 100));
}
// IF THE ENGINE IS INTERNAL
} else {
String className = engine.getClassName();
debug("execute", "Try instantiating class " + className + " for internal engine " + engine.getName() + "...");
InternalEngineIFace internalEngine = null;
// tries to instantiate the class for the internal engine
try {
if (className == null && className.trim().equals("")) throw new ClassNotFoundException();
internalEngine = (InternalEngineIFace) Class.forName(className).newInstance();
} catch (ClassNotFoundException cnfe) {
logger.fatal("The class ['" + className + "'] for internal engine " + engine.getName() + " was not found.", cnfe);
Vector params = new Vector();
params.add(className);
params.add(engine.getName());
errorHandler.addError(new EMFUserError(EMFErrorSeverity.ERROR, 2001, params));
return;
} catch (Exception e) {
logger.fatal("Error while instantiating class " + className, e);
errorHandler.addError(new EMFUserError(EMFErrorSeverity.ERROR, 100));
return;
}
debug("execute", "Class " + className + " instantiated successfully. Now engine's execution starts.");
// starts engine's execution
try {
internalEngine.handleNewDocumentTemplateCreation(requestContainer, obj, response);
} catch (InvalidOperationRequest ior) {
logger.info("Engine " + engine.getName() + " cannot build document template");
Vector params = new Vector();
params.add(engine.getName());
errorHandler.addError(new EMFUserError(EMFErrorSeverity.INFORMATION, "1076", params));
response.setAttribute(ObjectsTreeConstants.OBJECT_ID, idStr);
return;
} catch (Exception e) {
logger.fatal("Error while engine execution", e);