From fd50e1630a38dd904a9a4ae89abd885c276a210f Mon Sep 17 00:00:00 2001 From: quasi Date: Wed, 24 Mar 2010 18:10:37 +0000 Subject: [PATCH] FormBuilder MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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-94f89814c4df --- .../formbuilder/installer/Initializer.java | 204 ++++++++++-------- .../arsdigita/formbuilder/ui/NewAction.java | 4 + 2 files changed, 114 insertions(+), 94 deletions(-) diff --git a/ccm-core/src/com/arsdigita/formbuilder/installer/Initializer.java b/ccm-core/src/com/arsdigita/formbuilder/installer/Initializer.java index e7503b985..6fc69b9f2 100755 --- a/ccm-core/src/com/arsdigita/formbuilder/installer/Initializer.java +++ b/ccm-core/src/com/arsdigita/formbuilder/installer/Initializer.java @@ -40,38 +40,55 @@ import com.arsdigita.formbuilder.PersistentComponent; * @author Daniel Berrange * @version $Revision: #10 $ $Date: 2004/08/16 $ */ - public class Initializer extends BaseInitializer { + public static String WIDGET_TYPES = "widgetTypes"; public static String PROCESS_LISTENER_TYPES = "processListenerTypes"; public static String DATA_QUERIES = "dataQueries"; - private Configuration m_conf = new Configuration(); public Initializer() throws InitializationException { - m_conf.initParameter - (WIDGET_TYPES, - "The persistent widget types", - List.class); - m_conf.initParameter - (PROCESS_LISTENER_TYPES, - "The persistent process listener types", - List.class); - m_conf.initParameter - (DATA_QUERIES, - "The queries for the data driven select box", - List.class); + m_conf.initParameter(WIDGET_TYPES, + "The persistent widget types", + List.class); + m_conf.initParameter(PROCESS_LISTENER_TYPES, + "The persistent process listener types", + List.class); + m_conf.initParameter(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. **/ - public Configuration getConfiguration() { return m_conf; } - /** * Called on startup. Note. As you can not find a call * to this method in enterprise.ini, this method @@ -82,128 +99,127 @@ public class Initializer extends BaseInitializer { * present in enterprise.ini * **/ - - protected void doStartup() { - TransactionContext txn = SessionManager.getSession() - .getTransactionContext(); + TransactionContext txn = SessionManager.getSession().getTransactionContext(); txn.beginTxn(); - List widgets = (List)m_conf.getParameter(WIDGET_TYPES); - if (widgets != null) - loadMetaObjects(widgets, PersistentComponent.class); + List widgets = (List) m_conf.getParameter(WIDGET_TYPES); + loadMetaObjects(widgets, PersistentComponent.class); - List listeners = (List)m_conf.getParameter(PROCESS_LISTENER_TYPES); - if (listeners != null) - loadMetaObjects(listeners, PersistentProcessListener.class); + List listeners = (List) m_conf.getParameter(PROCESS_LISTENER_TYPES); + loadMetaObjects(listeners, PersistentProcessListener.class); - List queries = (List)m_conf.getParameter(DATA_QUERIES); - if (queries != null) - loadDataQueries(queries); + List queries = (List) m_conf.getParameter(DATA_QUERIES); + loadDataQueries(queries); txn.commitTxn(); } - /** * Called on shutdown. It's probably not a good idea to depend on this * being called. **/ - protected void doShutdown() { } public BebopObjectType getObjectType(String name, - Class type) { + Class type) { BebopObjectType objectType = null; try { objectType = BebopObjectType.findByClass(name, - type); + type); } catch (DataObjectNotFoundException ex) { objectType = BebopObjectType.create(name, - type); + type); objectType.save(); } return objectType; } - protected void loadMetaObjects(List objects, - Class type) - throws InitializationException { + protected void loadMetaObjects(List objects, Class type) + throws InitializationException { - // XXX we don't yet delete types which are no longer in the list - Iterator objects_i = objects.iterator(); - while (objects_i.hasNext()) { - List object = (List)objects_i.next(); + // If the objects list is not null, load the object list into the database + if (objects != null) { - String appName = (String)object.get(0); - String prettyName = (String)object.get(1); - String prettyPlural = (String)object.get(2); - String className = (String)object.get(3); - String propertiesForm = (String)object.get(4); + // XXX we don't yet delete types which are no longer in the list + Iterator objects_i = objects.iterator(); + while (objects_i.hasNext()) { + List object = (List) objects_i.next(); - try { - Class.forName(className); - } catch (ClassNotFoundException ex) { - throw new InitializationException("cannot find class " + className); - } - try { - Class.forName(propertiesForm); - } catch (ClassNotFoundException ex) { - throw new InitializationException("cannot find class " + propertiesForm); - } + String appName = (String) object.get(0); + String prettyName = (String) object.get(1); + String prettyPlural = (String) object.get(2); + String className = (String) object.get(3); + String propertiesForm = (String) object.get(4); - try { - MetaObject mo = MetaObject.findByClassName(getObjectType(appName, - type), - className); + try { + Class.forName(className); + } catch (ClassNotFoundException ex) { + throw new InitializationException("cannot find class " + className); + } + try { + Class.forName(propertiesForm); + } catch (ClassNotFoundException ex) { + throw new InitializationException("cannot find class " + propertiesForm); + } - mo.setPrettyName(prettyName); - mo.setPrettyPlural(prettyPlural); - mo.setWidgetClassName(className); - mo.setPropertiesFormName(propertiesForm); + try { + MetaObject mo = MetaObject.findByClassName(getObjectType(appName, + type), + className); - mo.save(); - } catch (DataObjectNotFoundException ex) { - MetaObject mo = MetaObject.create(getObjectType(appName, - type), - prettyName, - prettyPlural, - className, - propertiesForm); - mo.save(); + mo.setPrettyName(prettyName); + mo.setPrettyPlural(prettyPlural); + mo.setWidgetClassName(className); + mo.setPropertiesFormName(propertiesForm); + + mo.save(); + } catch (DataObjectNotFoundException ex) { + MetaObject mo = MetaObject.create(getObjectType(appName, + type), + prettyName, + prettyPlural, + className, + propertiesForm); + mo.save(); + } } } } + protected void loadDataQueries(List objects) - throws InitializationException { + throws InitializationException { - // XXX we don't yet delete types which are no longer in the list - Iterator objects_i = objects.iterator(); - while (objects_i.hasNext()) { - List object = (List)objects_i.next(); + // If the objects list is not null, load the object list into the database + if (objects != null) { - String appName = (String)object.get(0); - String name = (String)object.get(1); - String description = (String)object.get(2); + // XXX we don't yet delete types which are no longer in the list + Iterator objects_i = objects.iterator(); + while (objects_i.hasNext()) { + List object = (List) objects_i.next(); - try { - PersistentDataQuery q = PersistentDataQuery.findByName(getObjectType(appName, - PersistentDataQuery.class), - name); + String appName = (String) object.get(0); + String name = (String) object.get(1); + String description = (String) object.get(2); - q.setName(name); - q.setDescription(description); + try { + PersistentDataQuery q = PersistentDataQuery.findByName(getObjectType(appName, + PersistentDataQuery.class), + name); - q.save(); - } catch (DataObjectNotFoundException ex) { - PersistentDataQuery q = PersistentDataQuery.create(getObjectType(appName, - PersistentDataQuery.class), - description, name); - q.save(); + q.setName(name); + q.setDescription(description); + + q.save(); + } catch (DataObjectNotFoundException ex) { + PersistentDataQuery q = PersistentDataQuery.create(getObjectType(appName, + PersistentDataQuery.class), + description, name); + q.save(); + } } } } - } diff --git a/ccm-core/src/com/arsdigita/formbuilder/ui/NewAction.java b/ccm-core/src/com/arsdigita/formbuilder/ui/NewAction.java index 46fa86665..f3667f536 100755 --- a/ccm-core/src/com/arsdigita/formbuilder/ui/NewAction.java +++ b/ccm-core/src/com/arsdigita/formbuilder/ui/NewAction.java @@ -68,6 +68,10 @@ public class NewAction extends Form { 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) { try { MetaObjectCollection objects = MetaObject.getWidgets(app,