Author: mbooth Date: 2004-12-21 20:37:41 +0100 (Tue, 21 Dec 2004) New Revision: 160 Removed: ccm-core/trunk/src/com/arsdigita/formbuilder/AttributeMetaDataProvider.java ccm-core/trunk/src/com/arsdigita/formbuilder/FormBuilderDispatcher.java ccm-core/trunk/src/com/arsdigita/formbuilder/PersistentComponentFactory.java ccm-core/trunk/src/com/arsdigita/formbuilder/PersistentFormGenerator.java ccm-core/trunk/src/com/arsdigita/formbuilder/SimpleQuestionnaire.java ccm-core/trunk/src/com/arsdigita/formbuilder/ui/FormBuildingPage.java ccm-core/trunk/src/com/arsdigita/formbuilder/ui/FormPropertiesForm.java ccm-core/trunk/src/com/arsdigita/formbuilder/ui/FormPropertiesFormPageConnector.java ccm-core/trunk/src/com/arsdigita/formbuilder/ui/FormPropertiesPage.java ccm-core/trunk/src/com/arsdigita/formbuilder/ui/FormViewPage.java ccm-core/trunk/src/com/arsdigita/formbuilder/ui/IndexPage.java ccm-core/trunk/src/com/arsdigita/formbuilder/ui/OptionGroupPage.java ccm-core/trunk/src/com/arsdigita/formbuilder/ui/PreviewForm.java ccm-core/trunk/src/com/arsdigita/formbuilder/ui/PreviewFormPageConnector.java ccm-core/trunk/src/com/arsdigita/formbuilder/ui/PropertiesMetaForm.java ccm-core/trunk/src/com/arsdigita/formbuilder/ui/PropertiesMetaFormConnector.java ccm-core/trunk/src/com/arsdigita/formbuilder/ui/QuestionPropertiesForm.java ccm-core/trunk/src/com/arsdigita/formbuilder/ui/SimpleQuestionnaireList.java ccm-core/trunk/src/com/arsdigita/formbuilder/ui/SimpleQuestionnaireListModel.java ccm-core/trunk/src/com/arsdigita/formbuilder/ui/TemplatePage.java Modified: ccm-cms-types-formitem/trunk/src/com/arsdigita/cms/formbuilder/FormItem.java ccm-cms-types-formitem/trunk/src/com/arsdigita/cms/ui/formbuilder/FormControls.java ccm-cms-types-formsectionitem/trunk/src/com/arsdigita/cms/formbuilder/FormCopier.java ccm-cms-types-formsectionitem/trunk/src/com/arsdigita/cms/formbuilder/FormSectionItem.java ccm-cms-types-formsectionitem/trunk/src/com/arsdigita/cms/formbuilder/FormSectionWrapper.java ccm-cms/trunk/src/com/arsdigita/cms/ui/authoring/PageCreateDynamic.java ccm-cms/trunk/src/com/arsdigita/cms/ui/authoring/PageEditDynamic.java ccm-core/trunk/pdl/com/arsdigita/formbuilder/Component.pdl ccm-core/trunk/pdl/com/arsdigita/formbuilder/ProcessListener.pdl ccm-core/trunk/pdl/com/arsdigita/formbuilder/WidgetLabel.pdl ccm-core/trunk/src/com/arsdigita/formbuilder/ComponentAddObserver.java ccm-core/trunk/src/com/arsdigita/formbuilder/FormSectionGenerator.java ccm-core/trunk/src/com/arsdigita/formbuilder/PersistentComponent.java ccm-core/trunk/src/com/arsdigita/formbuilder/PersistentContainer.java ccm-core/trunk/src/com/arsdigita/formbuilder/PersistentDeditor.java ccm-core/trunk/src/com/arsdigita/formbuilder/PersistentFormSection.java ccm-core/trunk/src/com/arsdigita/formbuilder/PersistentOptionGroup.java ccm-core/trunk/src/com/arsdigita/formbuilder/PersistentTextArea.java ccm-core/trunk/src/com/arsdigita/formbuilder/PersistentWidget.java ccm-core/trunk/src/com/arsdigita/formbuilder/TestAttributeListener.java ccm-core/trunk/src/com/arsdigita/formbuilder/WidgetLabel.java ccm-core/trunk/src/com/arsdigita/formbuilder/actions/SimpleEmailListener.java ccm-core/trunk/src/com/arsdigita/formbuilder/ui/BaseAddObserver.java ccm-core/trunk/src/com/arsdigita/formbuilder/ui/BaseEditAddObserver.java ccm-core/trunk/src/com/arsdigita/formbuilder/ui/ControlEditor.java ccm-core/trunk/src/com/arsdigita/formbuilder/ui/ControlProperties.java ccm-core/trunk/src/com/arsdigita/formbuilder/ui/MoveControl.java ccm-core/trunk/src/com/arsdigita/formbuilder/ui/NewSection.java ccm-core/trunk/src/com/arsdigita/formbuilder/ui/editors/OptionEditor.java ccm-core/trunk/src/com/arsdigita/formbuilder/ui/editors/OptionGroupForm.java ccm-core/trunk/src/com/arsdigita/formbuilder/ui/editors/TemplateEmailForm.java ccm-core/trunk/src/com/arsdigita/formbuilder/ui/editors/WidgetLabelForm.java ccm-core/trunk/src/com/arsdigita/formbuilder/util/FormBuilderUtil.java ccm-core/trunk/src/com/arsdigita/formbuilder/util/PersistentContainerHelper.java Log: Significant refactoring of formbuilder. Fixes copying of forms, and hence publishing of forms, and also deleting of forms. Involves deletion of unused SimpleQuestionnaire, and all related UI. Also deletion of two idiotic abstractions. Datamodel upgrade scripts not required, but might be advisable. Previous code left lots of cruft in DB, so cruft cleanup script definitely required. Will follow. Modified: ccm-cms/trunk/src/com/arsdigita/cms/ui/authoring/PageCreateDynamic.java =================================================================== --- ccm-cms/trunk/src/com/arsdigita/cms/ui/authoring/PageCreateDynamic.java 2004-12-21 19:20:24 UTC (rev 159) +++ ccm-cms/trunk/src/com/arsdigita/cms/ui/authoring/PageCreateDynamic.java 2004-12-21 19:37:41 UTC (rev 160) @@ -57,13 +57,14 @@ import com.arsdigita.dispatcher.MultipartHttpServletRequest; import com.arsdigita.domain.DataObjectNotFoundException; import com.arsdigita.domain.DomainObjectFactory; -import com.arsdigita.formbuilder.PersistentComponentFactory; +import com.arsdigita.formbuilder.PersistentComponent; import com.arsdigita.formbuilder.PersistentForm; import com.arsdigita.kernel.Kernel; import com.arsdigita.kernel.Party; import com.arsdigita.kernel.User; import com.arsdigita.metadata.DynamicObjectType; import com.arsdigita.mimetypes.ImageMimeType; +import com.arsdigita.persistence.DataAssociationCursor; import com.arsdigita.persistence.DataCollection; import com.arsdigita.persistence.DataObject; import com.arsdigita.persistence.OID; @@ -254,15 +255,15 @@ } FormSection thisSection = new FormSection(new ColumnPanel(3)); - Iterator componentIter = pForm.getComponents().iterator(); + DataAssociationCursor components = pForm.getComponents(); String associationTypeParameter = null; String associationContentType = null; //add all persistent components to this form - while (componentIter.hasNext()) { + while (components.next()) { + PersistentComponent component = (PersistentComponent) + DomainObjectFactory.newInstance( components.getDataObject() ); - PersistentComponentFactory componentFactory = - (PersistentComponentFactory)componentIter.next(); - Component thisComponent = componentFactory.createComponent(); + Component thisComponent = component.createComponent(); if (thisComponent instanceof Hidden) { String thisParameterName = ((Hidden) thisComponent).getParameterModel().getName(); String thisValue = ((Hidden) thisComponent).getDefaultValue(); Modified: ccm-cms/trunk/src/com/arsdigita/cms/ui/authoring/PageEditDynamic.java =================================================================== --- ccm-cms/trunk/src/com/arsdigita/cms/ui/authoring/PageEditDynamic.java 2004-12-21 19:20:24 UTC (rev 159) +++ ccm-cms/trunk/src/com/arsdigita/cms/ui/authoring/PageEditDynamic.java 2004-12-21 19:37:41 UTC (rev 160) @@ -55,10 +55,12 @@ import com.arsdigita.dispatcher.MultipartHttpServletRequest; import com.arsdigita.domain.DataObjectNotFoundException; import com.arsdigita.domain.DomainObject; -import com.arsdigita.formbuilder.PersistentComponentFactory; +import com.arsdigita.domain.DomainObjectFactory; +import com.arsdigita.formbuilder.PersistentComponent; import com.arsdigita.formbuilder.PersistentForm; import com.arsdigita.metadata.DynamicObjectType; import com.arsdigita.mimetypes.ImageMimeType; +import com.arsdigita.persistence.DataAssociationCursor; import com.arsdigita.persistence.DataObject; import com.arsdigita.persistence.OID; import com.arsdigita.persistence.SessionManager; @@ -315,15 +317,15 @@ ContentType type = itemSel.getContentType(); PersistentForm pForm = m_originatingType.getItemForm(); - Iterator componentIter = pForm.getComponents().iterator(); + DataAssociationCursor components = pForm.getComponents(); String associationTypeParameter = null; String associationContentType = null; //add all persistent components to this form - while (componentIter.hasNext()) { + while (components.next()) { + PersistentComponent component = (PersistentComponent) + DomainObjectFactory.newInstance( components.getDataObject() ); - PersistentComponentFactory componentFactory = - (PersistentComponentFactory)componentIter.next(); - Component thisComponent = componentFactory.createComponent(); + Component thisComponent = component.createComponent(); if (thisComponent instanceof Hidden) { String thisParameterName = ((Hidden) thisComponent).getParameterModel().getName(); String thisValue = ((Hidden) thisComponent).getDefaultValue(); Modified: ccm-cms-types-formitem/trunk/src/com/arsdigita/cms/formbuilder/FormItem.java =================================================================== --- ccm-cms-types-formitem/trunk/src/com/arsdigita/cms/formbuilder/FormItem.java 2004-12-21 19:20:24 UTC (rev 159) +++ ccm-cms-types-formitem/trunk/src/com/arsdigita/cms/formbuilder/FormItem.java 2004-12-21 19:37:41 UTC (rev 160) @@ -37,7 +37,8 @@ import com.arsdigita.cms.dispatcher.XMLGenerator; import com.arsdigita.cms.util.GlobalizationUtil; import com.arsdigita.domain.DataObjectNotFoundException; -import com.arsdigita.formbuilder.PersistentComponentFactory; +import com.arsdigita.domain.DomainObjectFactory; +import com.arsdigita.formbuilder.PersistentComponent; import com.arsdigita.formbuilder.PersistentForm; import com.arsdigita.formbuilder.PersistentFormSection; import com.arsdigita.formbuilder.ui.BaseAddObserver; @@ -45,6 +46,7 @@ import com.arsdigita.formbuilder.ui.FormBuilderXMLRenderer; import com.arsdigita.formbuilder.ui.ComponentTraverse; import com.arsdigita.formbuilder.util.FormBuilderUtil; +import com.arsdigita.persistence.DataAssociationCursor; import com.arsdigita.persistence.DataCollection; import com.arsdigita.persistence.DataObject; import com.arsdigita.persistence.OID; @@ -62,8 +64,6 @@ import java.util.Collection; import java.util.Iterator; - - public class FormItem extends ContentPage implements XMLGenerator { public static final String BASE_DATA_OBJECT_TYPE = "com.arsdigita.cms.formbuilder.FormItem"; @@ -108,44 +108,24 @@ super.beforeSave(); } - public void delete() { + protected void beforeDelete() { PersistentForm form = getForm(); - - Collection children = form.getComponents(); - form.clearComponents(); - - Iterator i = children.iterator(); - while (i.hasNext()) { - PersistentComponentFactory c = (PersistentComponentFactory)i.next(); - - if (c instanceof PersistentFormSection) { - // In draft version, Form Sections are shared - if (DRAFT.equals(getVersion())) { - continue; - } else { - deleteSection((PersistentFormSection)c); - } - } else { - c.delete(); - } - } - - super.delete(); - form.delete(); + + super.beforeDelete(); } private void deleteSection(PersistentFormSection form) { - Collection children = form.getComponents(); - form.clearComponents(); + DataAssociationCursor children = form.getComponents(); - Iterator i = children.iterator(); - while (i.hasNext()) { - PersistentComponentFactory c = (PersistentComponentFactory)i.next(); + while (children.next()) { + PersistentComponent c = (PersistentComponent) + DomainObjectFactory.newInstance( children.getDataObject() ); c.delete(); } + form.clearComponents(); form.delete(); } Modified: ccm-cms-types-formitem/trunk/src/com/arsdigita/cms/ui/formbuilder/FormControls.java =================================================================== --- ccm-cms-types-formitem/trunk/src/com/arsdigita/cms/ui/formbuilder/FormControls.java 2004-12-21 19:20:24 UTC (rev 159) +++ ccm-cms-types-formitem/trunk/src/com/arsdigita/cms/ui/formbuilder/FormControls.java 2004-12-21 19:37:41 UTC (rev 160) @@ -32,7 +32,7 @@ import com.arsdigita.cms.ui.workflow.WorkflowLockedContainer; import com.arsdigita.domain.DataObjectNotFoundException; import com.arsdigita.domain.DomainObjectFactory; -import com.arsdigita.formbuilder.PersistentComponentFactory; +import com.arsdigita.formbuilder.PersistentComponent; import com.arsdigita.formbuilder.ui.ControlEditor; import com.arsdigita.persistence.OID; import com.arsdigita.util.UncheckedWrapperException; @@ -59,8 +59,8 @@ super.addEditableComponent(container, lock); } - protected PersistentComponentFactory getFormSection(PageState state, - BigDecimal sectionID) { + protected PersistentComponent getFormSection(PageState state, + BigDecimal sectionID) { FormSectionItem section = null; try { section = (FormSectionItem)DomainObjectFactory.newInstance( Modified: ccm-cms-types-formsectionitem/trunk/src/com/arsdigita/cms/formbuilder/FormCopier.java =================================================================== --- ccm-cms-types-formsectionitem/trunk/src/com/arsdigita/cms/formbuilder/FormCopier.java 2004-12-21 19:20:24 UTC (rev 159) +++ ccm-cms-types-formsectionitem/trunk/src/com/arsdigita/cms/formbuilder/FormCopier.java 2004-12-21 19:37:41 UTC (rev 160) @@ -18,6 +18,11 @@ */ package com.arsdigita.cms.formbuilder; +import com.arsdigita.formbuilder.PersistentForm; +import com.arsdigita.formbuilder.PersistentFormSection; +import com.arsdigita.formbuilder.PersistentOptionGroup; +import com.arsdigita.formbuilder.PersistentWidget; +import com.arsdigita.formbuilder.WidgetLabel; import com.arsdigita.cms.ACSObjectFactory; import com.arsdigita.cms.ContentItem; @@ -26,11 +31,6 @@ import com.arsdigita.domain.DomainObjectFactory; import com.arsdigita.domain.DomainService; import com.arsdigita.domain.InstantiatorNotFoundException; -import com.arsdigita.formbuilder.PersistentForm; -import com.arsdigita.formbuilder.PersistentFormSection; -import com.arsdigita.formbuilder.PersistentOptionGroup; -import com.arsdigita.formbuilder.PersistentWidget; -import com.arsdigita.formbuilder.WidgetLabel; import com.arsdigita.kernel.ACSObject; import com.arsdigita.persistence.DataAssociation; import com.arsdigita.persistence.DataAssociationCursor; @@ -41,6 +41,7 @@ import com.arsdigita.util.UncheckedWrapperException; import java.util.Collection; +import java.util.HashMap; import java.util.Iterator; /** @@ -54,6 +55,8 @@ private static org.apache.log4j.Logger s_log = org.apache.log4j.Logger.getLogger(FormCopier.class); + private HashMap m_copied = new HashMap(); + public PersistentForm copyForm(PersistentForm form) { PersistentForm tgt = (PersistentForm)copyFormSection(form); @@ -63,7 +66,9 @@ public PersistentFormSection copyFormSection(PersistentFormSection src) { PersistentFormSection tgt = (PersistentFormSection)copyObject(src); - s_log.debug("Copying form section " + src.getClass().getName()); + if( s_log.isDebugEnabled() ) { + s_log.debug("Copying form section " + src.getClass().getName()); + } copyDataObjectAssociation(getDataObject(src), getDataObject(tgt), @@ -81,7 +86,9 @@ protected FormSectionWrapper copyFormSectionWrapper(FormSectionWrapper src) { FormSectionWrapper tgt = (FormSectionWrapper)copyObject(src); - s_log.debug("Copying form section wrapper " + src.getOID()); + if( s_log.isDebugEnabled() ) { + s_log.debug("Copying form section wrapper " + src.getOID()); + } tgt.setFormSectionItem(src.getFormSectionItem()); tgt.setVersion(ContentItem.LIVE); @@ -94,7 +101,9 @@ protected WidgetLabel copyWidgetLabel(WidgetLabel src) { WidgetLabel tgt = (WidgetLabel)copyObject(src); - s_log.debug("Copying widget label " + src.getOID()); + if( s_log.isDebugEnabled() ) { + s_log.debug("Copying widget label " + src.getOID()); + } PersistentWidget srcWgt = null; try { @@ -103,7 +112,11 @@ throw new UncheckedWrapperException( "cannot find widget for label " + src.getOID(), ex); } - PersistentWidget dstWgt = (PersistentWidget)copyObject(srcWgt); + + DataObject dstObj = copySingleObject( getDataObject( srcWgt ) ); + + PersistentWidget dstWgt = (PersistentWidget) + DomainObjectFactory.newInstance( dstObj ); tgt.setWidget(dstWgt); @@ -116,7 +129,9 @@ public PersistentOptionGroup copyOptionGroup(PersistentOptionGroup src) { PersistentOptionGroup tgt = (PersistentOptionGroup)copyWidget(src); - s_log.debug("Copying option group " + src.getClass().getName()); + if( s_log.isDebugEnabled() ) { + s_log.debug("Copying option group " + src.getClass().getName()); + } copyDataObjectAssociation(getDataObject(src), getDataObject(tgt), @@ -131,7 +146,9 @@ private PersistentWidget copyWidget(PersistentWidget src) { PersistentWidget tgt = (PersistentWidget)copyObject(src); - s_log.debug("Copying form widget " + src.getClass().getName()); + if( s_log.isDebugEnabled() ) { + s_log.debug("Copying form widget " + src.getClass().getName(), new Exception() ); + } copyDataObjectAssociation(getDataObject(src), getDataObject(tgt), @@ -147,13 +164,15 @@ String objectType = src.getSpecificObjectType(); String javaClass = (String)get(src, ACSObject.DEFAULT_DOMAIN_CLASS); - s_log.debug("Copying object " + src.getClass().getName()); + if( s_log.isDebugEnabled() ) { + s_log.debug("Copying object " + src.getClass().getName() + " " + src.getOID(), new Exception()); + } Assert.exists(objectType, String.class); Assert.exists(javaClass, String.class); + // Attempt to instantiate the copy ACSObject tgt; - // Attempt to instantiate the copy try { tgt = (ACSObject)ACSObjectFactory.createACSObject(javaClass, objectType); @@ -174,21 +193,26 @@ private void copyDataObjectAssociation(DataObject src, DataObject tgt, String name) { - s_log.debug("Copy association " + src.get("objectType") + " " + name); + if( s_log.isDebugEnabled() ) { + s_log.debug("Copy association " + src.get("objectType") + " " + name); + } DataAssociation tgtAssoc = (DataAssociation)tgt.get(name); DataAssociation srcAssoc = (DataAssociation)src.get(name); - DataAssociationCursor daCursor = - ((DataAssociation)srcAssoc).getDataAssociationCursor(); + DataAssociationCursor daCursor = ((DataAssociation)srcAssoc).cursor(); while (daCursor.next()) { - s_log.debug("Copy association object " + name + - " " + daCursor.getDataObject()); + if( s_log.isDebugEnabled() ) { + s_log.debug("Copy association object " + name + + " " + daCursor.getDataObject()); + } DataObject copy = copySingleObject(daCursor.getDataObject()); DataObject tgtLink = tgtAssoc.add(copy); if (tgtLink != null) { - s_log.debug("Copy link " + daCursor.getLink()); + if( s_log.isDebugEnabled() ) { + s_log.debug("Copy link " + daCursor.getLink()); + } copyDataObjectAttributes(daCursor.getLink(), tgtLink); } @@ -198,29 +222,34 @@ } private DataObject copySingleObject(DataObject src) { - // Specialize the object to ensure we have the right OID - ACSObject srcObj = null; - try { - srcObj = (ACSObject)DomainObjectFactory.newInstance(src); - } catch (InstantiatorNotFoundException ex) { - throw new UncheckedWrapperException( - (String) GlobalizationUtil.globalize( - "cms.formbuilder.cannot_instantiate_object").localize(), ex); - } + ACSObject srcObj = (ACSObject) DomainObjectFactory.newInstance(src); - ACSObject tgtObj; - if (srcObj instanceof PersistentFormSection) { - tgtObj = copyFormSection((PersistentFormSection)srcObj); - } else if (srcObj instanceof PersistentOptionGroup) { - tgtObj = copyOptionGroup((PersistentOptionGroup)srcObj); - } else if (srcObj instanceof FormSectionWrapper) { - tgtObj = copyFormSectionWrapper((FormSectionWrapper)srcObj); - } else if (srcObj instanceof PersistentWidget) { - tgtObj = copyWidget((PersistentWidget)srcObj); - } else if (srcObj instanceof WidgetLabel) { - tgtObj = copyWidgetLabel((WidgetLabel)srcObj); + ACSObject tgtObj = (ACSObject) m_copied.get( srcObj.getOID().toString() ); + if( null != tgtObj ) { + if( s_log.isDebugEnabled() ) { + s_log.debug( "Using cached copy of " + srcObj.getOID() ); + } } else { - tgtObj = copyObject(srcObj); + if( s_log.isDebugEnabled() ) { + s_log.debug( "Copying " + srcObj.getClass().getName() + " " + + srcObj.getOID() ); + } + + if (srcObj instanceof PersistentFormSection) { + tgtObj = copyFormSection((PersistentFormSection)srcObj); + } else if (srcObj instanceof PersistentOptionGroup) { + tgtObj = copyOptionGroup((PersistentOptionGroup)srcObj); + } else if (srcObj instanceof FormSectionWrapper) { + tgtObj = copyFormSectionWrapper((FormSectionWrapper)srcObj); + } else if (srcObj instanceof PersistentWidget) { + tgtObj = copyWidget((PersistentWidget)srcObj); + } else if (srcObj instanceof WidgetLabel) { + tgtObj = copyWidgetLabel((WidgetLabel)srcObj); + } else { + tgtObj = copyObject(srcObj); + } + + m_copied.put( srcObj.getOID().toString(), tgtObj ); } return getDataObject(tgtObj); Modified: ccm-cms-types-formsectionitem/trunk/src/com/arsdigita/cms/formbuilder/FormSectionItem.java =================================================================== --- ccm-cms-types-formsectionitem/trunk/src/com/arsdigita/cms/formbuilder/FormSectionItem.java 2004-12-21 19:20:24 UTC (rev 159) +++ ccm-cms-types-formsectionitem/trunk/src/com/arsdigita/cms/formbuilder/FormSectionItem.java 2004-12-21 19:37:41 UTC (rev 160) @@ -33,7 +33,7 @@ import com.arsdigita.cms.ItemCopier; import com.arsdigita.cms.dispatcher.XMLGenerator; import com.arsdigita.domain.DataObjectNotFoundException; -import com.arsdigita.formbuilder.PersistentComponentFactory; +import com.arsdigita.formbuilder.PersistentComponent; import com.arsdigita.formbuilder.PersistentFormSection; import com.arsdigita.formbuilder.ui.BaseAddObserver; import com.arsdigita.formbuilder.ui.PlaceholdersInitListener; @@ -107,21 +107,26 @@ } - public void delete() { + protected void beforeDelete() { PersistentFormSection form = getFormSection(); + form.delete(); + super.beforeDelete(); + + /* Collection children = form.getComponents(); form.clearComponents(); Iterator i = children.iterator(); while (i.hasNext()) { - PersistentComponentFactory c = (PersistentComponentFactory)i.next(); + PersistentComponent c = (PersistentComponent) i.next(); c.delete(); } super.delete(); form.delete(); + */ } public boolean copyProperty(CustomCopy src, Modified: ccm-cms-types-formsectionitem/trunk/src/com/arsdigita/cms/formbuilder/FormSectionWrapper.java =================================================================== --- ccm-cms-types-formsectionitem/trunk/src/com/arsdigita/cms/formbuilder/FormSectionWrapper.java 2004-12-21 19:20:24 UTC (rev 159) +++ ccm-cms-types-formsectionitem/trunk/src/com/arsdigita/cms/formbuilder/FormSectionWrapper.java 2004-12-21 19:37:41 UTC (rev 160) @@ -25,7 +25,6 @@ import com.arsdigita.formbuilder.ComponentAddObserver; import com.arsdigita.formbuilder.CompoundComponent; import com.arsdigita.formbuilder.PersistentComponent; -import com.arsdigita.formbuilder.PersistentComponentFactory; import com.arsdigita.formbuilder.PersistentFormSection; import com.arsdigita.persistence.DataObject; import com.arsdigita.persistence.OID; @@ -166,30 +165,30 @@ } */ - public void addComponent(PersistentComponentFactory componentFactory) { + public void addComponent(PersistentComponent component) { FormSectionItem item = getFormSectionItem(); Assert.exists(item, FormSectionItem.class); - item.getFormSection().addComponent(componentFactory); + item.getFormSection().addComponent(component); } - public void addComponent(PersistentComponentFactory componentFactory, + public void addComponent(PersistentComponent component, int position) { FormSectionItem item = getFormSectionItem(); Assert.exists(item, FormSectionItem.class); - item.getFormSection().addComponent(componentFactory, position); + item.getFormSection().addComponent(component, position); } - public void removeComponent(PersistentComponentFactory componentFactory) { + public void removeComponent(PersistentComponent component) { FormSectionItem item = getFormSectionItem(); Assert.exists(item, FormSectionItem.class); - item.getFormSection().removeComponent(componentFactory); + item.getFormSection().removeComponent(component); } - public void moveComponent(PersistentComponentFactory componentFactory, + public void moveComponent(PersistentComponent component, int toPosition) { FormSectionItem item = getFormSectionItem(); Assert.exists(item, FormSectionItem.class); - item.getFormSection().moveComponent(componentFactory, toPosition); + item.getFormSection().moveComponent(component, toPosition); } public void clearComponents() { Modified: ccm-core/trunk/pdl/com/arsdigita/formbuilder/Component.pdl =================================================================== --- ccm-core/trunk/pdl/com/arsdigita/formbuilder/Component.pdl 2004-12-21 19:20:24 UTC (rev 159) +++ ccm-core/trunk/pdl/com/arsdigita/formbuilder/Component.pdl 2004-12-21 19:37:41 UTC (rev 160) @@ -36,11 +36,11 @@ // Disabled pending reworking of the whole PersistentContainerHelper // class and removal of the old UI. association { - Component[0..n] componentContainer = join bebop_components.component_id + composite Component[0..1] componentContainer = join bebop_components.component_id to bebop_component_hierarchy.component_id, join bebop_component_hierarchy.container_id to bebop_components.component_id; - Component[0..n] \component = join bebop_components.component_id + component Component[0..n] \component = join bebop_components.component_id to bebop_component_hierarchy.container_id, join bebop_component_hierarchy.component_id to bebop_components.component_id; Modified: ccm-core/trunk/pdl/com/arsdigita/formbuilder/ProcessListener.pdl =================================================================== --- ccm-core/trunk/pdl/com/arsdigita/formbuilder/ProcessListener.pdl 2004-12-21 19:20:24 UTC (rev 159) +++ ccm-core/trunk/pdl/com/arsdigita/formbuilder/ProcessListener.pdl 2004-12-21 19:37:41 UTC (rev 160) @@ -29,9 +29,8 @@ reference key (bebop_process_listeners.listener_id); } - association { - FormSection[0..1] form = join bebop_process_listeners.listener_id + composite FormSection[0..1] form = join bebop_process_listeners.listener_id to bebop_form_process_listeners.listener_id, join bebop_form_process_listeners.form_section_id to bebop_form_sections.form_section_id; Modified: ccm-core/trunk/pdl/com/arsdigita/formbuilder/WidgetLabel.pdl =================================================================== --- ccm-core/trunk/pdl/com/arsdigita/formbuilder/WidgetLabel.pdl 2004-12-21 19:20:24 UTC (rev 159) +++ ccm-core/trunk/pdl/com/arsdigita/formbuilder/WidgetLabel.pdl 2004-12-21 19:37:41 UTC (rev 160) @@ -20,7 +20,12 @@ model com.arsdigita.formbuilder; object type WidgetLabel extends Component { - BigDecimal[1..1] widgetId = forms_widget_label.widget_id INTEGER; - reference key (forms_widget_label.label_id); } + +association { + component WidgetLabel[0..1] widgetLabel = join bebop_widgets.widget_id to + forms_widget_label.widget_id; + composite Widget[1..1] widget = join forms_widget_label.widget_id to + bebop_widgets.widget_id; +} Deleted: ccm-core/trunk/src/com/arsdigita/formbuilder/AttributeMetaDataProvider.java =================================================================== --- ccm-core/trunk/src/com/arsdigita/formbuilder/AttributeMetaDataProvider.java 2004-12-21 19:20:24 UTC (rev 159) +++ ccm-core/trunk/src/com/arsdigita/formbuilder/AttributeMetaDataProvider.java 2004-12-21 19:37:41 UTC (rev 160) @@ -1,46 +0,0 @@ -/* - * Copyright (C) 2001-2004 Red Hat Inc. All Rights Reserved. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ -package com.arsdigita.formbuilder; - - -/** - * This interface should be implemented by classes implementing the - * <code>FormProcessListener</code> that are used by persistent forms. The attribute - * metadata provided serves a number of purposes when building a PersistentForm: - * - * <ul> - * - * <li>We can ensure that the PersistentForm submits the parameters that the process listener - expects</li> - * - * <li> We can generate a default form that can be customized and persisted with the Form Builder admin UI. - * We thus avoid that the administrator having to build the persistent form scratch.</li> - * - * </ul> - * - * @author Peter Marklund - * @version $Id: //core-platform/dev/src/com/arsdigita/formbuilder/AttributeMetaDataProvider.java#8 $ - * - */ -public interface AttributeMetaDataProvider { - - public static final String versionId = "$Id: //core-platform/dev/src/com/arsdigita/formbuilder/AttributeMetaDataProvider.java#8 $ by $Author: dennis $, $DateTime: 2004/08/16 18:10:38 $"; - - public AttributeMetaDataList getAttributeMetaData(); -} Modified: ccm-core/trunk/src/com/arsdigita/formbuilder/ComponentAddObserver.java =================================================================== --- ccm-core/trunk/src/com/arsdigita/formbuilder/ComponentAddObserver.java 2004-12-21 19:20:24 UTC (rev 159) +++ ccm-core/trunk/src/com/arsdigita/formbuilder/ComponentAddObserver.java 2004-12-21 19:37:41 UTC (rev 160) @@ -21,7 +21,7 @@ import com.arsdigita.bebop.Component; import com.arsdigita.bebop.FormSection; -import com.arsdigita.formbuilder.PersistentComponentFactory; +import com.arsdigita.formbuilder.PersistentComponent; /** @@ -32,14 +32,14 @@ public interface ComponentAddObserver { public void beforeAddingComponent(FormSection formSection, - PersistentComponentFactory componentFactory, + PersistentComponent component, int componentPosition); - public void addingComponent(PersistentComponentFactory componentFactory, + public void addingComponent(PersistentComponent persistentComponent, int componentPosition, Component component); public void afterAddingComponent(FormSection formSection, - PersistentComponentFactory componentFactory, + PersistentComponent component, int componentPosition); } Deleted: ccm-core/trunk/src/com/arsdigita/formbuilder/FormBuilderDispatcher.java =================================================================== --- ccm-core/trunk/src/com/arsdigita/formbuilder/FormBuilderDispatcher.java 2004-12-21 19:20:24 UTC (rev 159) +++ ccm-core/trunk/src/com/arsdigita/formbuilder/FormBuilderDispatcher.java 2004-12-21 19:37:41 UTC (rev 160) @@ -1,87 +0,0 @@ -/* - * Copyright (C) 2001-2004 Red Hat Inc. All Rights Reserved. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ -package com.arsdigita.formbuilder; - - -// This BebopMapDispatcher lets us map Bebop pages to URLs -// in a convenient way -import com.arsdigita.bebop.BebopMapDispatcher; - - -// All admin UI pages extend this class - -// The Pages of the admin UI -import com.arsdigita.formbuilder.ui.IndexPage; -import com.arsdigita.formbuilder.ui.FormPropertiesPage; -import com.arsdigita.formbuilder.ui.FormBuildingPage; -import com.arsdigita.formbuilder.ui.FormViewPage; -import com.arsdigita.formbuilder.ui.OptionGroupPage; - -// We shouldn't need those here, but BebopMapDispatcher has -// no addPage method - -import org.apache.log4j.Logger; - - - -/** - * The dispatcher of the Form Builder admin UI. All admin UI classes - * are in the <code>com.arsdigita.formbuilder.ui</code> package. There are - * a handful of pages that are each mapped to one relative URL and each - * page is implemented by its own class (a subclass of Bebop Page). - * - * @author Peter Marklund - * @version $Id: //core-platform/dev/src/com/arsdigita/formbuilder/FormBuilderDispatcher.java#10 $ - */ -public class FormBuilderDispatcher extends BebopMapDispatcher { - - public static final String versionId = "$Id: //core-platform/dev/src/com/arsdigita/formbuilder/FormBuilderDispatcher.java#10 $ by $Author: dennis $, $DateTime: 2004/08/16 18:10:38 $"; - - private static final Logger s_log = - Logger.getLogger(FormBuilderDispatcher.class); - - private static final String URL_ENDING = ".acs"; - - /** - * Constructor. Builds all pages and maps them to urls. - */ - public FormBuilderDispatcher() { - super(); - - buildAndMapPages(); - } - - /** - * Will populate the url-page map. - */ - private void buildAndMapPages() { - - // Setup up the map between Pages and relative URLs - addPage(IndexPage.instance().getRelativeURL(), IndexPage.instance()); - addPage("", IndexPage.instance()); - addPage(FormPropertiesPage.instance().getRelativeURL(), FormPropertiesPage.instance()); - addPage(FormBuildingPage.instance().getRelativeURL(), FormBuildingPage.instance()); - addPage(FormViewPage.instance().getRelativeURL(), FormViewPage.instance()); - addPage(OptionGroupPage.instance().getRelativeURL(), OptionGroupPage.instance()); - } - - public static String getURLEnding() { - return URL_ENDING; - } -} Modified: ccm-core/trunk/src/com/arsdigita/formbuilder/FormSectionGenerator.java =================================================================== --- ccm-core/trunk/src/com/arsdigita/formbuilder/FormSectionGenerator.java 2004-12-21 19:20:24 UTC (rev 159) +++ ccm-core/trunk/src/com/arsdigita/formbuilder/FormSectionGenerator.java 2004-12-21 19:37:41 UTC (rev 160) @@ -56,8 +56,8 @@ /** - * This class can generate a Bebop Form given an object implementing the - * <code>AttributeMetaDataProvider</code> interface. The Form Builder uses + * This class can generate a Bebop Form given a PersistentComponent. + * The Form Builder uses * this class for its own admin UI to generate forms for the various persistent * components. It is unclear how useful this class will be applicable outside * the Form Builder since its functionality is still restricted. @@ -73,13 +73,13 @@ private static final Logger s_log = Logger.getLogger(FormSectionGenerator.class.getName()); - private AttributeMetaDataProvider m_metaDataProvider; + private PersistentComponent m_component; private boolean m_isAdd = true; - public FormSectionGenerator(AttributeMetaDataProvider metaDataProvider) { + public FormSectionGenerator(PersistentComponent component) { - m_metaDataProvider = metaDataProvider; + m_component = component; } public FormSection generateFormSection() { @@ -105,7 +105,7 @@ m_isAdd = isAdd; // Loop over the attributes and add appropriate widgets to the Form - AttributeMetaDataList attributeList = m_metaDataProvider.getAttributeMetaData(); + AttributeMetaDataList attributeList = m_component.getAttributeMetaData(); attributeList.setIteratorAtStart(); while(attributeList.hasNext()) { @@ -155,16 +155,7 @@ // Add a process listener that sets the attributes formSection.addProcessListener(getSetProcessListener()); - - // Save if this is a domain object - // This is a hack - I should check for a save method instead - Class domainObjectClass = - FormBuilderUtil.loadClass("com.arsdigita.domain.DomainObject"); - if (domainObjectClass.isAssignableFrom(m_metaDataProvider.getClass()) - || m_metaDataProvider instanceof com.arsdigita.formbuilder.PersistentComponentFactory) { - - formSection.addProcessListener(getDomainObjectSaveListener()); - } + formSection.addProcessListener(getDomainObjectSaveListener()); } return formSection; @@ -184,7 +175,7 @@ FormData formData = event.getFormData(); // Iterate over the attributes and set them - AttributeMetaDataList attributeList = m_metaDataProvider.getAttributeMetaData(); + AttributeMetaDataList attributeList = m_component.getAttributeMetaData(); attributeList.setIteratorAtStart(); while(attributeList.hasNext()) { @@ -203,7 +194,7 @@ try { FormBuilderUtil.invokeMethod(setMethod, - m_metaDataProvider, + m_component, new Object[] {parameterValue}); } catch (IllegalArgumentException e) { @@ -225,7 +216,7 @@ Method getMethod = getParameterMethod(parameterName, false); Object defaultValue = FormBuilderUtil.invokeMethod(getMethod, - m_metaDataProvider, + m_component, new Object[] {}); if (defaultValue != null) { @@ -263,7 +254,7 @@ Method returnMethod = null; // Simply loop over the methods and look for a matching set method name - Method[] methods = m_metaDataProvider.getClass().getMethods(); + Method[] methods = m_component.getClass().getMethods(); for (int i = 0; i < methods.length; ++i) { Method method = methods[i]; @@ -287,17 +278,10 @@ private FormProcessListener getDomainObjectSaveListener() { return new FormProcessListener() { - - public void process(FormSectionEvent event) { - - if (m_metaDataProvider instanceof com.arsdigita.domain.DomainObject) { - ((DomainObject)m_metaDataProvider).save(); - } else { - - ((PersistentComponentFactory)m_metaDataProvider).save(); - } - } - }; + public void process(FormSectionEvent event) { + m_component.save(); + } + }; } private void addValidationListeners(Widget widget, List validationListeners) { Modified: ccm-core/trunk/src/com/arsdigita/formbuilder/PersistentComponent.java =================================================================== --- ccm-core/trunk/src/com/arsdigita/formbuilder/PersistentComponent.java 2004-12-21 19:20:24 UTC (rev 159) +++ ccm-core/trunk/src/com/arsdigita/formbuilder/PersistentComponent.java 2004-12-21 19:37:41 UTC (rev 160) @@ -59,8 +59,7 @@ * @version $Id: //core-platform/dev/src/com/arsdigita/formbuilder/PersistentComponent.java#15 $ * */ -public abstract class PersistentComponent extends AuditedACSObject - implements PersistentComponentFactory, AttributeMetaDataProvider { +public abstract class PersistentComponent extends AuditedACSObject { public static final String versionId = "$Id: //core-platform/dev/src/com/arsdigita/formbuilder/PersistentComponent.java#15 $ by $Author: dennis $, $DateTime: 2004/08/16 18:10:38 $"; @@ -82,6 +81,8 @@ // *** Constructors ------------- + private RuntimeException m_creation; + /** * Sub classes can create a new component domain object with * this constructor. @@ -92,10 +93,14 @@ // We need to save the class name of this factory object be able // to resurrect it set("defaultDomainClass", this.getClass().getName()); + + m_creation = new RuntimeException( getClass().getName() ); } public PersistentComponent(ObjectType type) { super(type); + + m_creation = new RuntimeException( getClass().getName() ); } /** @@ -106,12 +111,16 @@ throws DataObjectNotFoundException { super(oID); + + m_creation = new RuntimeException( getClass().getName() ); } public PersistentComponent(DataObject obj) { super(obj); + + m_creation = new RuntimeException( getClass().getName() ); } /** @@ -127,7 +136,15 @@ m_attributeChanged = false; } + if( s_log.isDebugEnabled() ) { + s_log.debug( "Saving a " + getClass().getName() ); + } + + try { super.beforeSave(); + } catch( Exception ex ) { + throw m_creation; + } } /** Deleted: ccm-core/trunk/src/com/arsdigita/formbuilder/PersistentComponentFactory.java =================================================================== --- ccm-core/trunk/src/com/arsdigita/formbuilder/PersistentComponentFactory.java 2004-12-21 19:20:24 UTC (rev 159) +++ ccm-core/trunk/src/com/arsdigita/formbuilder/PersistentComponentFactory.java 2004-12-21 19:37:41 UTC (rev 160) @@ -1,59 +0,0 @@ -/* - * Copyright (C) 2001-2004 Red Hat Inc. All Rights Reserved. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ -package com.arsdigita.formbuilder; - - -// Each factory has a unique id by which it can be retrievd -import java.math.BigDecimal; - -// The factory creates Bebop Components -import com.arsdigita.bebop.Component; - - -/** - * Implemented by classes that can persist and create a Bebop - * Component. - * - * @author Peter Marklund - * @version $Id: //core-platform/dev/src/com/arsdigita/formbuilder/PersistentComponentFactory.java#9 $ - * - */ -public interface PersistentComponentFactory { - - public static final String versionId = "$Id: //core-platform/dev/src/com/arsdigita/formbuilder/PersistentComponentFactory.java#9 $ by $Author: dennis $, $DateTime: 2004/08/16 18:10:38 $"; - - /** - * Using the metadata in this persistent component - * create a Bebop component that is a snapshot of - * this data. - */ - public Component createComponent(); - - public void save(); - - public void delete(); - - public BigDecimal getID(); - - /** - * Indicates if the factory has been saved or not. See - * {@link com.arsdigita.domain.DomainObject#isNew()} - */ - public boolean isNew(); -} Modified: ccm-core/trunk/src/com/arsdigita/formbuilder/PersistentContainer.java =================================================================== --- ccm-core/trunk/src/com/arsdigita/formbuilder/PersistentContainer.java 2004-12-21 19:20:24 UTC (rev 159) +++ ccm-core/trunk/src/com/arsdigita/formbuilder/PersistentContainer.java 2004-12-21 19:37:41 UTC (rev 160) @@ -23,7 +23,7 @@ /** * Implemented by classes that contain persistent Bebop components. The - * components are added via their corresponding PersistentComponentFactory that + * components are added via their corresponding PersistentComponent that * knows how to create the component. The relationship between the container * and the components is an aggregate association (in UML terminology) with * multiplicity 0..N on both ends of the association. @@ -40,7 +40,7 @@ * Add a component last in the list of components in * this container. */ - public void addComponent(PersistentComponentFactory componentFactory); + public void addComponent(PersistentComponent component); /** @@ -49,20 +49,20 @@ * @param position The position to add the component at. Positions start * with 1 */ - public void addComponent(PersistentComponentFactory componentFactory, + public void addComponent(PersistentComponent component, int position); /** * Remove a component from the Container */ - public void removeComponent(PersistentComponentFactory componentFactory); + public void removeComponent(PersistentComponent component); /** * Move component to new position. * * @param toPosition The position to move the component to. Positions start with 1. */ - public void moveComponent(PersistentComponentFactory componentFactory, + public void moveComponent(PersistentComponent component, int toPosition); /** Modified: ccm-core/trunk/src/com/arsdigita/formbuilder/PersistentDeditor.java =================================================================== --- ccm-core/trunk/src/com/arsdigita/formbuilder/PersistentDeditor.java 2004-12-21 19:20:24 UTC (rev 159) +++ ccm-core/trunk/src/com/arsdigita/formbuilder/PersistentDeditor.java 2004-12-21 19:37:41 UTC (rev 160) @@ -25,7 +25,7 @@ // This factory creates a Deditor import com.arsdigita.bebop.form.Deditor; -// Every PersistentComponentFactory can create a Bebop Component +// Every PersistentComponent can create a Bebop Component import com.arsdigita.bebop.Component; // Id class used by internal constructor @@ -52,8 +52,7 @@ * @version $Id: //core-platform/dev/src/com/arsdigita/formbuilder/PersistentDeditor.java#9 $ * */ -public class PersistentDeditor extends PersistentWidget - implements AttributeMetaDataProvider { +public class PersistentDeditor extends PersistentWidget { public static final String versionId = "$Id: //core-platform/dev/src/com/arsdigita/formbuilder/PersistentDeditor.java#9 $ by $Author: dennis $, $DateTime: 2004/08/16 18:10:38 $"; Deleted: ccm-core/trunk/src/com/arsdigita/formbuilder/PersistentFormGenerator.java =================================================================== --- ccm-core/trunk/src/com/arsdigita/formbuilder/PersistentFormGenerator.java 2004-12-21 19:20:24 UTC (rev 159) +++ ccm-core/trunk/src/com/arsdigita/formbuilder/PersistentFormGenerator.java 2004-12-21 19:37:41 UTC (rev 160) @@ -1,48 +0,0 @@ -/* - * Copyright (C) 2001-2004 Red Hat Inc. All Rights Reserved. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ -package com.arsdigita.formbuilder; - - -/** - * This class can generate a PersistentForm given an object implementing the - * <code>AttributeMetaDataProvider</code> interface. Such a persistent form - * can be used as a starting point for an administrator building a persistent form - * for a certain process listener. - * - * @author Peter Marklund - * @version $Id: //core-platform/dev/src/com/arsdigita/formbuilder/PersistentFormGenerator.java#8 $ - * - */ -public class PersistentFormGenerator { - - public static final String versionId = "$Id: //core-platform/dev/src/com/arsdigita/formbuilder/PersistentFormGenerator.java#8 $ by $Author: dennis $, $DateTime: 2004/08/16 18:10:38 $"; - - private AttributeMetaDataProvider m_metaDataProvider; - - public PersistentFormGenerator(AttributeMetaDataProvider metaDataProvider) { - - m_metaDataProvider = metaDataProvider; - } - - public PersistentForm generatePersistentForm() { - - // TODO - return PersistentForm.create("dummy form"); - } -} Modified: ccm-core/trunk/src/com/arsdigita/formbuilder/PersistentFormSection.java =================================================================== --- ccm-core/trunk/src/com/arsdigita/formbuilder/PersistentFormSection.java 2004-12-21 19:20:24 UTC (rev 159) +++ ccm-core/trunk/src/com/arsdigita/formbuilder/PersistentFormSection.java 2004-12-21 19:37:41 UTC (rev 160) @@ -18,46 +18,27 @@ */ package com.arsdigita.formbuilder; - -// This domain object can create a Bebop FormSection -import com.arsdigita.bebop.FormSection; - -// Manages associations with child components import com.arsdigita.formbuilder.util.PersistentContainerHelper; -// For the FormSection constructor - -// What we add to the form section import com.arsdigita.bebop.Component; import com.arsdigita.bebop.Container; +import com.arsdigita.bebop.FormSection; +import com.arsdigita.domain.DataObjectNotFoundException; +import com.arsdigita.domain.DomainObject; +import com.arsdigita.domain.DomainObjectFactory; +import com.arsdigita.persistence.DataAssociation; +import com.arsdigita.persistence.DataAssociationCursor; +import com.arsdigita.persistence.DataObject; +import com.arsdigita.persistence.OID; +import com.arsdigita.persistence.metadata.ObjectType; -// For attributes of the form - -// Child components are returned in a collection +import java.math.BigDecimal; import java.util.Collection; import java.util.Iterator; import java.util.ArrayList; -// Thrown if the underlying DataObject with given id cannot be found -import com.arsdigita.domain.DataObjectNotFoundException; - -// We are persisting these via their class name - -// For instantiating objects - -// All ACSObjects have a unique id -import java.math.BigDecimal; -import com.arsdigita.persistence.OID; -import com.arsdigita.persistence.DataObject; -import com.arsdigita.persistence.metadata.ObjectType; - -// ACS 5 uses Log4J for logging import org.apache.log4j.Logger; -import com.arsdigita.domain.DomainObjectFactory; -import com.arsdigita.persistence.DataAssociationCursor; -import com.arsdigita.persistence.DataAssociation; - /** * This domain object manages persistence of a Bebop FormSection. * @@ -147,19 +128,36 @@ * I am overriding this method to delete all associations with * components before the form is deleted. The components themselves are not deleted. */ - public void delete() { + /* + protected void beforeDelete() { + if( s_log.isDebugEnabled() ) { + s_log.debug( "Deleting children of " + getOID() ); + } - m_container.clearComponents(); + DataAssociationCursor components = m_container.getComponents(); + while( components.next() ) { + DomainObject obj = + DomainObjectFactory.newInstance( components.getDataObject() ); - super.delete(); + if( s_log.isDebugEnabled() ) { + s_log.debug( "Deleting child of " + getOID() + ": " + + obj.getOID() + "(" + obj.getClass().getName() + + ")" ); + } + obj.delete(); + } + + //m_container.clearComponents(); + super.beforeDelete(); } + */ /** * Add a component after the already added components (in the last position). * If this domain object has not been saved (with save()) before you invoke this method * it will be saved by this method. */ - public void addComponent(PersistentComponentFactory componentFactory) { + public void addComponent(PersistentComponent componentFactory) { // Delegate to the Container helper m_container.addComponent(componentFactory); @@ -174,7 +172,7 @@ * the third component to be added to the form this * value would be 3) */ - public void addComponent(PersistentComponentFactory componentFactory, + public void addComponent(PersistentComponent componentFactory, int position) { // Delegate to the Container helper @@ -186,7 +184,7 @@ * If this domain object has not been saved (with save()) before you invoke this method * it will be saved by this method. */ - public void removeComponent(PersistentComponentFactory componentFactory) { + public void removeComponent(PersistentComponent componentFactory) { // Delegate to the Container helper m_container.removeComponent(componentFactory); @@ -197,7 +195,7 @@ * * @param toPosition The position to move the component to. Positions start with 1. */ - public void moveComponent(PersistentComponentFactory componentFactory, + public void moveComponent(PersistentComponent componentFactory, int toPosition) { // Delegate to the Container helper @@ -234,10 +232,9 @@ } /** - * Return all children components represented by their PersistentComponentFactory - * objects. + * Return all child components */ - public Collection getComponents() { + public DataAssociationCursor getComponents() { // Delegate to the Container helper return m_container.getComponents(); @@ -260,40 +257,38 @@ } /** - * Add all child components to the FormSection. Each persisted component has an associated - * PersistentComponentFactory that can be resurrected with the id of the component. - * The Bebop components are created with the createComponent() method of their factory. + * Add all child components to the FormSection. */ protected void addComponents(FormSection formSection) { - Iterator componentIter = m_container.getComponents().iterator(); + DataAssociationCursor components = m_container.getComponents(); // Loop over the child components int componentCounter = 1; - while (componentIter.hasNext()) { - // Fetch the next component factory from the list - PersistentComponentFactory factory = - (PersistentComponentFactory)componentIter.next(); + while (components.next()) { + // Fetch the next component from the list + PersistentComponent persistentComponent = (PersistentComponent) + DomainObjectFactory.newInstance( components.getDataObject() ); - // Add the component to the form with the factory + // Add the component to the form // Fire the component add observer if (m_componentAddObserver != null) { - m_componentAddObserver.beforeAddingComponent(formSection, factory, componentCounter); + m_componentAddObserver.beforeAddingComponent(formSection, persistentComponent, componentCounter); } - Component component = factory.createComponent(); + Component component = persistentComponent.createComponent(); // Give the observer an opportunity to modify the component that we add to the form if (m_componentAddObserver != null) { - m_componentAddObserver.addingComponent(factory, componentCounter, component); + m_componentAddObserver.addingComponent(persistentComponent, componentCounter, component); } formSection.add(component); // Fire the component add observer if (m_componentAddObserver != null) { - m_componentAddObserver.afterAddingComponent(formSection, factory, componentCounter); + m_componentAddObserver.afterAddingComponent(formSection, persistentComponent, componentCounter); } ++componentCounter; Modified: ccm-core/trunk/src/com/arsdigita/formbuilder/PersistentOptionGroup.java =================================================================== --- ccm-core/trunk/src/com/arsdigita/formbuilder/PersistentOptionGroup.java 2004-12-21 19:20:24 UTC (rev 159) +++ ccm-core/trunk/src/com/arsdigita/fo... [truncated message content] |