FormBuilder
Initializer um Konstruktor erweitert, der es ermöglicht, die Konfiguration als Parameter zu übergeben, anstatt sie mittels enterprise.init und LegacyInitializer einzulesen. Kommentar in NewAction hinzugefügt git-svn-id: https://svn.libreccm.org/ccm/trunk@364 8810af33-2d31-482b-a856-94f89814c4dfmaster
parent
93d082caa6
commit
fd50e1630a
|
|
@ -40,38 +40,55 @@ import com.arsdigita.formbuilder.PersistentComponent;
|
||||||
* @author <a href="mailto:berrange@redhat.com">Daniel Berrange</a>
|
* @author <a href="mailto:berrange@redhat.com">Daniel Berrange</a>
|
||||||
* @version $Revision: #10 $ $Date: 2004/08/16 $
|
* @version $Revision: #10 $ $Date: 2004/08/16 $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class Initializer extends BaseInitializer {
|
public class Initializer extends BaseInitializer {
|
||||||
|
|
||||||
public static String WIDGET_TYPES = "widgetTypes";
|
public static String WIDGET_TYPES = "widgetTypes";
|
||||||
public static String PROCESS_LISTENER_TYPES = "processListenerTypes";
|
public static String PROCESS_LISTENER_TYPES = "processListenerTypes";
|
||||||
public static String DATA_QUERIES = "dataQueries";
|
public static String DATA_QUERIES = "dataQueries";
|
||||||
|
|
||||||
private Configuration m_conf = new Configuration();
|
private Configuration m_conf = new Configuration();
|
||||||
|
|
||||||
public Initializer() throws InitializationException {
|
public Initializer() throws InitializationException {
|
||||||
m_conf.initParameter
|
m_conf.initParameter(WIDGET_TYPES,
|
||||||
(WIDGET_TYPES,
|
"The persistent widget types",
|
||||||
"The persistent widget types",
|
List.class);
|
||||||
List.class);
|
m_conf.initParameter(PROCESS_LISTENER_TYPES,
|
||||||
m_conf.initParameter
|
"The persistent process listener types",
|
||||||
(PROCESS_LISTENER_TYPES,
|
List.class);
|
||||||
"The persistent process listener types",
|
m_conf.initParameter(DATA_QUERIES,
|
||||||
List.class);
|
"The queries for the data driven select box",
|
||||||
m_conf.initParameter
|
List.class);
|
||||||
(DATA_QUERIES,
|
}
|
||||||
"The queries for the data driven select box",
|
|
||||||
List.class);
|
/* Quasimodo: BEGIN */
|
||||||
|
/**
|
||||||
|
* Initializer
|
||||||
|
*
|
||||||
|
* A new Initializer, which doesn't use the Configuration and the enterprise
|
||||||
|
* init. This initializer can be called during DomainInitEvents, so it is
|
||||||
|
* ready for the new Initializer framework. Configuration will be read from
|
||||||
|
* parameters (for now - maybe there's wil be a better way in the future).
|
||||||
|
*
|
||||||
|
* @throws InitializationException
|
||||||
|
*/
|
||||||
|
public Initializer(List widgets, List processListeners, List dataQueries) throws InitializationException {
|
||||||
|
TransactionContext txn = SessionManager.getSession().getTransactionContext();
|
||||||
|
txn.beginTxn();
|
||||||
|
|
||||||
|
// Load widgets, processListeners and dataQueries from parameters
|
||||||
|
loadMetaObjects(widgets, PersistentComponent.class);
|
||||||
|
loadMetaObjects(processListeners, PersistentProcessListener.class);
|
||||||
|
loadDataQueries(dataQueries);
|
||||||
|
|
||||||
|
txn.commitTxn();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the configuration object used by this initializer.
|
* Returns the configuration object used by this initializer.
|
||||||
**/
|
**/
|
||||||
|
|
||||||
public Configuration getConfiguration() {
|
public Configuration getConfiguration() {
|
||||||
return m_conf;
|
return m_conf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called on startup. Note. As you can not find a call
|
* Called on startup. Note. As you can not find a call
|
||||||
* to this method in enterprise.ini, this method
|
* to this method in enterprise.ini, this method
|
||||||
|
|
@ -82,128 +99,127 @@ public class Initializer extends BaseInitializer {
|
||||||
* present in enterprise.ini
|
* present in enterprise.ini
|
||||||
*
|
*
|
||||||
**/
|
**/
|
||||||
|
|
||||||
|
|
||||||
protected void doStartup() {
|
protected void doStartup() {
|
||||||
|
|
||||||
TransactionContext txn = SessionManager.getSession()
|
TransactionContext txn = SessionManager.getSession().getTransactionContext();
|
||||||
.getTransactionContext();
|
|
||||||
txn.beginTxn();
|
txn.beginTxn();
|
||||||
|
|
||||||
List widgets = (List)m_conf.getParameter(WIDGET_TYPES);
|
List widgets = (List) m_conf.getParameter(WIDGET_TYPES);
|
||||||
if (widgets != null)
|
loadMetaObjects(widgets, PersistentComponent.class);
|
||||||
loadMetaObjects(widgets, PersistentComponent.class);
|
|
||||||
|
|
||||||
List listeners = (List)m_conf.getParameter(PROCESS_LISTENER_TYPES);
|
List listeners = (List) m_conf.getParameter(PROCESS_LISTENER_TYPES);
|
||||||
if (listeners != null)
|
loadMetaObjects(listeners, PersistentProcessListener.class);
|
||||||
loadMetaObjects(listeners, PersistentProcessListener.class);
|
|
||||||
|
|
||||||
List queries = (List)m_conf.getParameter(DATA_QUERIES);
|
List queries = (List) m_conf.getParameter(DATA_QUERIES);
|
||||||
if (queries != null)
|
loadDataQueries(queries);
|
||||||
loadDataQueries(queries);
|
|
||||||
|
|
||||||
txn.commitTxn();
|
txn.commitTxn();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called on shutdown. It's probably not a good idea to depend on this
|
* Called on shutdown. It's probably not a good idea to depend on this
|
||||||
* being called.
|
* being called.
|
||||||
**/
|
**/
|
||||||
|
|
||||||
protected void doShutdown() {
|
protected void doShutdown() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public BebopObjectType getObjectType(String name,
|
public BebopObjectType getObjectType(String name,
|
||||||
Class type) {
|
Class type) {
|
||||||
BebopObjectType objectType = null;
|
BebopObjectType objectType = null;
|
||||||
try {
|
try {
|
||||||
objectType = BebopObjectType.findByClass(name,
|
objectType = BebopObjectType.findByClass(name,
|
||||||
type);
|
type);
|
||||||
} catch (DataObjectNotFoundException ex) {
|
} catch (DataObjectNotFoundException ex) {
|
||||||
objectType = BebopObjectType.create(name,
|
objectType = BebopObjectType.create(name,
|
||||||
type);
|
type);
|
||||||
objectType.save();
|
objectType.save();
|
||||||
}
|
}
|
||||||
return objectType;
|
return objectType;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void loadMetaObjects(List objects,
|
protected void loadMetaObjects(List objects, Class type)
|
||||||
Class type)
|
throws InitializationException {
|
||||||
throws InitializationException {
|
|
||||||
|
|
||||||
// XXX we don't yet delete types which are no longer in the list
|
// If the objects list is not null, load the object list into the database
|
||||||
Iterator objects_i = objects.iterator();
|
if (objects != null) {
|
||||||
while (objects_i.hasNext()) {
|
|
||||||
List object = (List)objects_i.next();
|
|
||||||
|
|
||||||
String appName = (String)object.get(0);
|
// XXX we don't yet delete types which are no longer in the list
|
||||||
String prettyName = (String)object.get(1);
|
Iterator objects_i = objects.iterator();
|
||||||
String prettyPlural = (String)object.get(2);
|
while (objects_i.hasNext()) {
|
||||||
String className = (String)object.get(3);
|
List object = (List) objects_i.next();
|
||||||
String propertiesForm = (String)object.get(4);
|
|
||||||
|
|
||||||
try {
|
String appName = (String) object.get(0);
|
||||||
Class.forName(className);
|
String prettyName = (String) object.get(1);
|
||||||
} catch (ClassNotFoundException ex) {
|
String prettyPlural = (String) object.get(2);
|
||||||
throw new InitializationException("cannot find class " + className);
|
String className = (String) object.get(3);
|
||||||
}
|
String propertiesForm = (String) object.get(4);
|
||||||
try {
|
|
||||||
Class.forName(propertiesForm);
|
|
||||||
} catch (ClassNotFoundException ex) {
|
|
||||||
throw new InitializationException("cannot find class " + propertiesForm);
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
MetaObject mo = MetaObject.findByClassName(getObjectType(appName,
|
Class.forName(className);
|
||||||
type),
|
} catch (ClassNotFoundException ex) {
|
||||||
className);
|
throw new InitializationException("cannot find class " + className);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
Class.forName(propertiesForm);
|
||||||
|
} catch (ClassNotFoundException ex) {
|
||||||
|
throw new InitializationException("cannot find class " + propertiesForm);
|
||||||
|
}
|
||||||
|
|
||||||
mo.setPrettyName(prettyName);
|
try {
|
||||||
mo.setPrettyPlural(prettyPlural);
|
MetaObject mo = MetaObject.findByClassName(getObjectType(appName,
|
||||||
mo.setWidgetClassName(className);
|
type),
|
||||||
mo.setPropertiesFormName(propertiesForm);
|
className);
|
||||||
|
|
||||||
mo.save();
|
mo.setPrettyName(prettyName);
|
||||||
} catch (DataObjectNotFoundException ex) {
|
mo.setPrettyPlural(prettyPlural);
|
||||||
MetaObject mo = MetaObject.create(getObjectType(appName,
|
mo.setWidgetClassName(className);
|
||||||
type),
|
mo.setPropertiesFormName(propertiesForm);
|
||||||
prettyName,
|
|
||||||
prettyPlural,
|
mo.save();
|
||||||
className,
|
} catch (DataObjectNotFoundException ex) {
|
||||||
propertiesForm);
|
MetaObject mo = MetaObject.create(getObjectType(appName,
|
||||||
mo.save();
|
type),
|
||||||
|
prettyName,
|
||||||
|
prettyPlural,
|
||||||
|
className,
|
||||||
|
propertiesForm);
|
||||||
|
mo.save();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void loadDataQueries(List objects)
|
protected void loadDataQueries(List objects)
|
||||||
throws InitializationException {
|
throws InitializationException {
|
||||||
|
|
||||||
// XXX we don't yet delete types which are no longer in the list
|
// If the objects list is not null, load the object list into the database
|
||||||
Iterator objects_i = objects.iterator();
|
if (objects != null) {
|
||||||
while (objects_i.hasNext()) {
|
|
||||||
List object = (List)objects_i.next();
|
|
||||||
|
|
||||||
String appName = (String)object.get(0);
|
// XXX we don't yet delete types which are no longer in the list
|
||||||
String name = (String)object.get(1);
|
Iterator objects_i = objects.iterator();
|
||||||
String description = (String)object.get(2);
|
while (objects_i.hasNext()) {
|
||||||
|
List object = (List) objects_i.next();
|
||||||
|
|
||||||
try {
|
String appName = (String) object.get(0);
|
||||||
PersistentDataQuery q = PersistentDataQuery.findByName(getObjectType(appName,
|
String name = (String) object.get(1);
|
||||||
PersistentDataQuery.class),
|
String description = (String) object.get(2);
|
||||||
name);
|
|
||||||
|
|
||||||
q.setName(name);
|
try {
|
||||||
q.setDescription(description);
|
PersistentDataQuery q = PersistentDataQuery.findByName(getObjectType(appName,
|
||||||
|
PersistentDataQuery.class),
|
||||||
|
name);
|
||||||
|
|
||||||
q.save();
|
q.setName(name);
|
||||||
} catch (DataObjectNotFoundException ex) {
|
q.setDescription(description);
|
||||||
PersistentDataQuery q = PersistentDataQuery.create(getObjectType(appName,
|
|
||||||
PersistentDataQuery.class),
|
q.save();
|
||||||
description, name);
|
} catch (DataObjectNotFoundException ex) {
|
||||||
q.save();
|
PersistentDataQuery q = PersistentDataQuery.create(getObjectType(appName,
|
||||||
|
PersistentDataQuery.class),
|
||||||
|
description, name);
|
||||||
|
q.save();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -68,6 +68,10 @@ public class NewAction extends Form {
|
||||||
m_selection.getStateParameter());
|
m_selection.getStateParameter());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Loads the PersistenProcessListener from database using the preselected
|
||||||
|
* object by application. The preselection is made in enterprise.init
|
||||||
|
*/
|
||||||
protected void loadComponents(String app) {
|
protected void loadComponents(String app) {
|
||||||
try {
|
try {
|
||||||
MetaObjectCollection objects = MetaObject.getWidgets(app,
|
MetaObjectCollection objects = MetaObject.getWidgets(app,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue