public void setHistoryType(final Class< ? extends Archiver> historyType, String... historyArgs) { checkExtendingQuerier(historyType); this.historyXml = "<history name='" + HISTORY_DEFAULT_KEY + "' class='" + historyType.getName() + "'>" + Misc.LINE_SEPARATOR; for (String arg : historyArgs) { this.historyXml += defaultIndent + arg + Misc.LINE_SEPARATOR; } this.historyXml += "</history>"; }
/** * Add or replace an entry in the environment to generate. * * @param name * name of the entry * @param classToUse * implementation * @return previous declaration for this name */ public String setApplicationEntry(final String name, final Class< ? > classToUse) { String xml = getObjectDecl(name, classToUse); return setApplicationEntry(name, xml); }
/** * Add or replace an entry in the environment to generate. * * @param name * name of the entry * @param classToUse * implementation * @param fieldKeys * list of fields to set * @param refKeys * value to set to the fields * @return previous declaration for this name */ public String setApplicationEntry(final String name, final Class< ? > classToUse, String[] fieldKeys, String[] refKeys) { String xml = getObjectDeclWithFields(name, classToUse, fieldKeys, refKeys); return setApplicationEntry(name, xml); }
/** * Add or replace an entry in the environment to generate. * * @param name * name of the entry * @param classToUse * implementation * @return previous declaration for this name */ public String setBlockEntry(final String name, final Class< ? > classToUse) { String xml = getObjectDecl(name, classToUse); return setBlockEntry(name, xml); }
private void setRuntimeHibernateConf() { String hibernateConfigXml = ""; hibernateConfigXml += "<hibernate-configuration name='" + EnvConstants.CORE_HB_CONF_NAME + "' >\n"; hibernateConfigXml += defaultIndent + "<properties resource='hibernate-core.properties' />\n"; hibernateConfigXml += defaultIndent + "<mappings resource='bonita.mappings.hbm.xml' />\n"; hibernateConfigXml += defaultIndent + "<cache-configuration resource='bonita.cache.xml' usage='read-write' />\n"; hibernateConfigXml += "</hibernate-configuration>"; this.setApplicationEntry(EnvConstants.CORE_HB_CONF_NAME, hibernateConfigXml); this.setApplicationEntry(EnvConstants.CORE_HB_SESSION_FACTORY_NAME, "<hibernate-session-factory name='" + EnvConstants.CORE_HB_SESSION_FACTORY_NAME + "' configuration='" + EnvConstants.CORE_HB_CONF_NAME + "' />"); this.setBlockEntry(EnvConstants.CORE_HB_SESSION_NAME, "<hibernate-session name='" + EnvConstants.CORE_HB_SESSION_NAME + "' factory='" + EnvConstants.CORE_HB_SESSION_FACTORY_NAME + "' />"); this.setBlockEntry(EnvConstants.CORE_PERSISTENCESERVICE_NAME, "<" + EnvConstants.XPDL_PERSISTENCE_SERVICE + " name='" + EnvConstants.CORE_PERSISTENCESERVICE_NAME + "' session='" + EnvConstants.CORE_HB_SESSION_NAME + "'/>"); }
@SuppressWarnings("unchecked") public EnvGenerator() { applicationVariables = new HashMap<String, String>(); blockVariables = new HashMap<String, String>(); this.setAPIType(Context.AutoDetect); // Hibernate configuration for bonita core engine. setRuntimeHibernateConf(); // Command execution configuration String commandServiceConfigXml = "<command-service>\n"; commandServiceConfigXml += defaultIndent + "<retry-interceptor />\n"; commandServiceConfigXml += defaultIndent + "<environment-interceptor />\n"; commandServiceConfigXml += defaultIndent + "<standard-transaction-interceptor />\n"; commandServiceConfigXml += "</command-service>\n"; this.setApplicationEntry("command-service", commandServiceConfigXml); this.setApplicationEntry("job-executor", "<job-executor threads='1' auto-start='true' />"); this.setApplicationEntry("type-resolver", "<variable-types resource='bonita.type.resolver.xml' />"); this.setRepositoryType(DbRepository.class, "<arg><string value='" + EnvConstants.CORE_PERSISTENCESERVICE_NAME + "' /></arg>"); this.setBlockEntry("transaction", "<transaction />"); this.setJournalType(DbJournal.class, "<arg><string value='" + EnvConstants.CORE_PERSISTENCESERVICE_NAME + "' /></arg>"); this.setFinishedInstanceHandlerType(DeleteFinishedInstanceHandler.class, ArchiveFinishedInstanceHandler.class); this.setUndeployedPackageHandlerType(ArchiveUndeployedPackageHandler.class); this.setRecorderType(LoggerRecorder.class); this.setArchiverType(LoggerArchiver.class); this.setHistoryType(XMLHistory.class); this.setBlockEntry("timer_session", "<timer-session />"); this.setBlockEntry("job-session", "<job-db-session session='" + EnvConstants.CORE_HB_SESSION_NAME + "' />"); }
/** * Add or replace an entry in the environment to generate. * * @param name * name of the entry * @param classToUse * implementation * @param fieldKeys * list of fields to set * @param refKeys * value to set to the fields * @return previous declaration for this name */ public String setBlockEntry(final String name, final Class< ? > classToUse, final String[] fieldKeys, final String[] refKeys) { String xml = getObjectDeclWithFields(name, classToUse, fieldKeys, refKeys); return setBlockEntry(name, xml); }
result.append(getIndent(indentDepth) + "<environment-factory>" + Misc.LINE_SEPARATOR); result.append(reIndent(indentDepth, entry)).append(Misc.LINE_SEPARATOR); .append(reIndent(indentDepth, apiTypeXml)).append(Misc.LINE_SEPARATOR) .append(reIndent(indentDepth, finishedInstanceHandlerXml)).append(Misc.LINE_SEPARATOR) .append(reIndent(indentDepth, undeployedPackageHandlerXml)).append(Misc.LINE_SEPARATOR); .append(getIndent(indentDepth)).append("</environment-factory>" + Misc.LINE_SEPARATOR + Misc.LINE_SEPARATOR); .append(getIndent(indentDepth)).append("<environment>" + Misc.LINE_SEPARATOR); indentDepth++; .append(reIndent(indentDepth, journalXml)).append(Misc.LINE_SEPARATOR); .append(reIndent(indentDepth, historyXml)).append(Misc.LINE_SEPARATOR); .append(getIndent(indentDepth)).append("<!-- DbJournal cannot be shared by several environments." + Misc.LINE_SEPARATOR) .append(getIndent(indentDepth)).append("It contains a session cache that needs to be recreated for each environment -->") .append(Misc.LINE_SEPARATOR) .append(getIndent(indentDepth)).append("<chainer name='").append(Recorder.DEFAULT_KEY + "'>" + Misc.LINE_SEPARATOR) .append(reIndent(indentDepth + 1, recorderXml)).append(Misc.LINE_SEPARATOR) .append(getIndent(indentDepth + 1)).append("<ref object='" + JOURNAL_DEFAULT_KEY + "' />").append(Misc.LINE_SEPARATOR) .append(getIndent(indentDepth)).append("</chainer>" + Misc.LINE_SEPARATOR); .append(getIndent(indentDepth)).append("<chainer name='").append(Archiver.DEFAULT_KEY + "'>" + Misc.LINE_SEPARATOR) .append(reIndent(indentDepth + 1 , archiverXml)).append(Misc.LINE_SEPARATOR) .append(getIndent(indentDepth + 1)).append("<ref object='" + HISTORY_DEFAULT_KEY + "' />").append(Misc.LINE_SEPARATOR) .append(getIndent(indentDepth)).append("</chainer>" + Misc.LINE_SEPARATOR);
public void setFinishedInstanceHandlerType(final Class< ? extends FinishedInstanceHandler>... finishedInstanceHandlerTypes) { this.finishedInstanceHandlerXml = "<chainer name='" + FinishedInstanceHandler.DEFAULT_KEY + "'>" + Misc.LINE_SEPARATOR; for (Class< ? extends FinishedInstanceHandler> finishedInstanceHandlerType : finishedInstanceHandlerTypes) { this.finishedInstanceHandlerXml += defaultIndent + getObjectDecl(finishedInstanceHandlerType) + Misc.LINE_SEPARATOR; } this.finishedInstanceHandlerXml += "</chainer>" + Misc.LINE_SEPARATOR; }
/** * Creates a new EnvironmentFactory from the list of entries. */ public EnvironmentFactory createEnvironmentFactory() { final String envConfig = createEnvironmentXml(); if (LOG.isLoggable(Level.CONFIG)) { LOG.config("The following environment has been generated by: " + this.getClass().getName() + Misc.LINE_SEPARATOR + envConfig); } EnvironmentFactory environmentFactory = XpdlEnvironmentParser .parseEnvironmentFactoryFromXmlString(envConfig); return environmentFactory; }
private String reIndent(int depth, String initialString) { StringReader stringReader = new StringReader(initialString); BufferedReader reader = new BufferedReader(stringReader); StringBuilder builder = new StringBuilder(); String line; try { while ((line = reader.readLine()) != null) { if (builder.length() != 0) { builder.append(Misc.LINE_SEPARATOR); } builder.append(getIndent(depth)).append(line); } } catch (IOException e) { Misc.unreachableStatement(); } finally { Misc.close(reader); Misc.close(stringReader); } return builder.toString(); } /**
public void setUndeployedPackageHandlerType(final Class< ? extends UndeployedPackageHandler>... undeployedPackageHandlerTypes) { this.undeployedPackageHandlerXml = "<chainer name='" + UndeployedPackageHandler.DEFAULT_KEY + "'>" + Misc.LINE_SEPARATOR; for (Class< ? extends UndeployedPackageHandler> undeployedPackageHandlerType : undeployedPackageHandlerTypes) { this.undeployedPackageHandlerXml += defaultIndent + getObjectDecl(undeployedPackageHandlerType) + Misc.LINE_SEPARATOR; } this.undeployedPackageHandlerXml += "</chainer>" + Misc.LINE_SEPARATOR; }
/** * Prints the default environment on standard output. * * @param args * @throws IOException */ @SuppressWarnings("unchecked") public static void main(String[] args) throws IOException { if (args.length != 1 && args.length != 2) { System.exit(1); } EnvGenerator envGenerator = null; try { Class <EnvGenerator> envGeneratorClass = (Class<EnvGenerator>) EnvGenerator.class.getClassLoader().loadClass(args[0]); envGenerator = envGeneratorClass.newInstance(); } catch (Exception e) { throw new RuntimeException(e); } if (args.length == 1) { if (LOG.isLoggable(Level.INFO)) { LOG.config(envGenerator.createEnvironmentXml()); } } else { Misc.write(envGenerator.createEnvironmentXml(), new File(args[1])); } }
public void setJournalType(final Class< ? extends Recorder> journalType, String... args) { checkExtendingQuerier(journalType); this.journalXml = "<journal name='" + JOURNAL_DEFAULT_KEY + "' class='" + journalType.getName() + "'> " + Misc.LINE_SEPARATOR; for (String arg : args) { this.journalXml += defaultIndent + arg + Misc.LINE_SEPARATOR; } this.journalXml += "</journal>"; }