Author: adrianc
Date: Sat Nov 1 23:47:47 2014
New Revision: 1636071
URL: http://svn.apache.org/r1636071
Log:
Move form widget artifact info code to a separate class. This eliminates a lot
of duplicate code and it should speed up artifact info gathering. Also
converted form widget to reuse screen widget action models.
Modified:
ofbiz/trunk/framework/webtools/src/org/ofbiz/webtools/artifactinfo/FormWidgetArtifactInfo.java
ofbiz/trunk/framework/widget/src/org/ofbiz/widget/ModelActionVisitor.java
ofbiz/trunk/framework/widget/src/org/ofbiz/widget/ModelWidgetAction.java
ofbiz/trunk/framework/widget/src/org/ofbiz/widget/artifact/ArtifactInfoContext.java
ofbiz/trunk/framework/widget/src/org/ofbiz/widget/artifact/ArtifactInfoGatherer.java
ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelForm.java
ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelFormAction.java
Modified:
ofbiz/trunk/framework/webtools/src/org/ofbiz/webtools/artifactinfo/FormWidgetArtifactInfo.java
URL:
http://svn.apache.org/viewvc/ofbiz/trunk/framework/webtools/src/org/ofbiz/webtools/artifactinfo/FormWidgetArtifactInfo.java?rev=1636071&r1=1636070&r2=1636071&view=diff
==============================================================================
---
ofbiz/trunk/framework/webtools/src/org/ofbiz/webtools/artifactinfo/FormWidgetArtifactInfo.java
(original)
+++
ofbiz/trunk/framework/webtools/src/org/ofbiz/webtools/artifactinfo/FormWidgetArtifactInfo.java
Sat Nov 1 23:47:47 2014
@@ -31,6 +31,8 @@ import org.ofbiz.base.util.Debug;
import org.ofbiz.base.util.GeneralException;
import org.ofbiz.base.util.UtilMisc;
import org.ofbiz.base.util.UtilURL;
+import org.ofbiz.widget.artifact.ArtifactInfoContext;
+import org.ofbiz.widget.artifact.ArtifactInfoGatherer;
import org.ofbiz.widget.form.ModelForm;
import org.xml.sax.SAXException;
@@ -68,12 +70,14 @@ public class FormWidgetArtifactInfo exte
/** note this is mean to be called after the object is created and added
to the ArtifactInfoFactory.allFormInfos in
ArtifactInfoFactory.getFormWidgetArtifactInfo */
public void populateAll() throws GeneralException {
- // populate entitiesUsedInThisForm, servicesUsedInThisForm,
formThisFormExtends (and reverse in aif.allFormInfosExtendingForm)
- this.populateUsedEntities();
- this.populateUsedServices();
+ ArtifactInfoContext infoContext = new ArtifactInfoContext();
+ ArtifactInfoGatherer infoGatherer = new
ArtifactInfoGatherer(infoContext);
+ infoGatherer.visit(this.modelForm);
+ populateEntitiesFromNameSet(infoContext.getEntityNames());
+ populateServicesFromNameSet(infoContext.getServiceNames());
this.populateFormExtended();
- this.populateLinkedRequests();
- this.populateTargetedRequests();
+ this.populateLinkedRequests(infoContext.getRequestLocations());
+ this.populateTargetedRequests(infoContext.getTargetLocations());
}
protected void populateFormExtended() throws GeneralException {
@@ -97,11 +101,7 @@ public class FormWidgetArtifactInfo exte
UtilMisc.addToSortedSetInMap(this, aif.allFormInfosExtendingForm,
formName);
}
}
- protected void populateUsedEntities() throws GeneralException {
- // populate entitiesUsedInThisForm and for each the reverse-associate
cache in the aif
- Set<String> allEntityNameSet = this.modelForm.getAllEntityNamesUsed();
- populateEntitiesFromNameSet(allEntityNameSet);
- }
+
protected void populateEntitiesFromNameSet(Set<String> allEntityNameSet)
throws GeneralException {
for (String entityName: allEntityNameSet) {
if (entityName.contains("${")) {
@@ -118,11 +118,6 @@ public class FormWidgetArtifactInfo exte
UtilMisc.addToSortedSetInMap(this,
aif.allFormInfosReferringToEntityName, entityName);
}
}
- protected void populateUsedServices() throws GeneralException {
- // populate servicesUsedInThisForm and for each the reverse-associate
cache in the aif
- Set<String> allServiceNameSet =
this.modelForm.getAllServiceNamesUsed();
- populateServicesFromNameSet(allServiceNameSet);
- }
protected void populateServicesFromNameSet(Set<String> allServiceNameSet)
throws GeneralException {
for (String serviceName: allServiceNameSet) {
if (serviceName.contains("${")) {
@@ -142,8 +137,7 @@ public class FormWidgetArtifactInfo exte
}
}
- protected void populateLinkedRequests() throws GeneralException{
- Set<String> allRequestUniqueId =
this.modelForm.getLinkedRequestsLocationAndUri();
+ protected void populateLinkedRequests(Set<String> allRequestUniqueId)
throws GeneralException{
for (String requestUniqueId: allRequestUniqueId) {
if (requestUniqueId.contains("${")) {
@@ -160,8 +154,7 @@ public class FormWidgetArtifactInfo exte
}
}
}
- protected void populateTargetedRequests() throws GeneralException{
- Set<String> allRequestUniqueId =
this.modelForm.getTargetedRequestsLocationAndUri();
+ protected void populateTargetedRequests(Set<String> allRequestUniqueId)
throws GeneralException{
for (String requestUniqueId: allRequestUniqueId) {
if (requestUniqueId.contains("${")) {
Modified:
ofbiz/trunk/framework/widget/src/org/ofbiz/widget/ModelActionVisitor.java
URL:
http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/ModelActionVisitor.java?rev=1636071&r1=1636070&r2=1636071&view=diff
==============================================================================
--- ofbiz/trunk/framework/widget/src/org/ofbiz/widget/ModelActionVisitor.java
(original)
+++ ofbiz/trunk/framework/widget/src/org/ofbiz/widget/ModelActionVisitor.java
Sat Nov 1 23:47:47 2014
@@ -18,12 +18,15 @@
*******************************************************************************/
package org.ofbiz.widget;
+import org.ofbiz.widget.form.ModelFormAction;
/**
* A <code>ModelWidgetAction</code> visitor.
*/
public interface ModelActionVisitor {
+ void visit(ModelFormAction.CallParentActions callParentActions);
+
void visit(ModelWidgetAction.EntityAnd entityAnd);
void visit(ModelWidgetAction.EntityCondition entityCondition);
Modified:
ofbiz/trunk/framework/widget/src/org/ofbiz/widget/ModelWidgetAction.java
URL:
http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/ModelWidgetAction.java?rev=1636071&r1=1636070&r2=1636071&view=diff
==============================================================================
--- ofbiz/trunk/framework/widget/src/org/ofbiz/widget/ModelWidgetAction.java
(original)
+++ ofbiz/trunk/framework/widget/src/org/ofbiz/widget/ModelWidgetAction.java
Sat Nov 1 23:47:47 2014
@@ -76,33 +76,37 @@ public abstract class ModelWidgetAction
public abstract void accept(ModelActionVisitor visitor);
+ public static ModelWidgetAction toModelWidgetAction(ModelWidget
modelWidget, Element actionElement) {
+ if ("set".equals(actionElement.getNodeName())) {
+ return new SetField(modelWidget, actionElement);
+ } else if ("property-map".equals(actionElement.getNodeName())) {
+ return new PropertyMap(modelWidget, actionElement);
+ } else if ("property-to-field".equals(actionElement.getNodeName())) {
+ return new PropertyToField(modelWidget, actionElement);
+ } else if ("script".equals(actionElement.getNodeName())) {
+ return new Script(modelWidget, actionElement);
+ } else if ("service".equals(actionElement.getNodeName())) {
+ return new Service(modelWidget, actionElement);
+ } else if ("entity-one".equals(actionElement.getNodeName())) {
+ return new EntityOne(modelWidget, actionElement);
+ } else if ("entity-and".equals(actionElement.getNodeName())) {
+ return new EntityAnd(modelWidget, actionElement);
+ } else if ("entity-condition".equals(actionElement.getNodeName())) {
+ return new EntityCondition(modelWidget, actionElement);
+ } else if ("get-related-one".equals(actionElement.getNodeName())) {
+ return new GetRelatedOne(modelWidget, actionElement);
+ } else if ("get-related".equals(actionElement.getNodeName())) {
+ return new GetRelated(modelWidget, actionElement);
+ } else {
+ throw new IllegalArgumentException("Action element not supported
with name: " + actionElement.getNodeName());
+ }
+ }
+
public static List<ModelWidgetAction> readSubActions(ModelWidget
modelWidget, Element parentElement) {
List<? extends Element> actionElementList =
UtilXml.childElementList(parentElement);
List<ModelWidgetAction> actions = new
ArrayList<ModelWidgetAction>(actionElementList.size());
for (Element actionElement: actionElementList) {
- if ("set".equals(actionElement.getNodeName())) {
- actions.add(new SetField(modelWidget, actionElement));
- } else if ("property-map".equals(actionElement.getNodeName())) {
- actions.add(new PropertyMap(modelWidget, actionElement));
- } else if
("property-to-field".equals(actionElement.getNodeName())) {
- actions.add(new PropertyToField(modelWidget, actionElement));
- } else if ("script".equals(actionElement.getNodeName())) {
- actions.add(new Script(modelWidget, actionElement));
- } else if ("service".equals(actionElement.getNodeName())) {
- actions.add(new Service(modelWidget, actionElement));
- } else if ("entity-one".equals(actionElement.getNodeName())) {
- actions.add(new EntityOne(modelWidget, actionElement));
- } else if ("entity-and".equals(actionElement.getNodeName())) {
- actions.add(new EntityAnd(modelWidget, actionElement));
- } else if ("entity-condition".equals(actionElement.getNodeName()))
{
- actions.add(new EntityCondition(modelWidget, actionElement));
- } else if ("get-related-one".equals(actionElement.getNodeName())) {
- actions.add(new GetRelatedOne(modelWidget, actionElement));
- } else if ("get-related".equals(actionElement.getNodeName())) {
- actions.add(new GetRelated(modelWidget, actionElement));
- } else {
- throw new IllegalArgumentException("Action element not
supported with name: " + actionElement.getNodeName());
- }
+ actions.add(toModelWidgetAction(modelWidget, actionElement));
}
return actions;
}
Modified:
ofbiz/trunk/framework/widget/src/org/ofbiz/widget/artifact/ArtifactInfoContext.java
URL:
http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/artifact/ArtifactInfoContext.java?rev=1636071&r1=1636070&r2=1636071&view=diff
==============================================================================
---
ofbiz/trunk/framework/widget/src/org/ofbiz/widget/artifact/ArtifactInfoContext.java
(original)
+++
ofbiz/trunk/framework/widget/src/org/ofbiz/widget/artifact/ArtifactInfoContext.java
Sat Nov 1 23:47:47 2014
@@ -31,6 +31,7 @@ public final class ArtifactInfoContext {
private final Set<String> screenLocationSet = new HashSet<String>();
private final Set<String> formLocationSet = new HashSet<String>();
private final Set<String> requestLocationSet = new HashSet<String>();
+ private final Set<String> targetLocationSet = new HashSet<String>();
/**
* Adds an entity name to this context.
@@ -83,6 +84,16 @@ public final class ArtifactInfoContext {
}
/**
+ * Adds a target location to this context.
+ * @param name The target location to add to this context
+ */
+ public void addTargetLocation(String name) {
+ if (name != null) {
+ this.targetLocationSet.add(name);
+ }
+ }
+
+ /**
* Returns the entity names in this context.
* @return The entity names in this context
*/
@@ -121,4 +132,12 @@ public final class ArtifactInfoContext {
public Set<String> getServiceNames() {
return this.serviceNameSet;
}
+
+ /**
+ * Returns the target locations in this context.
+ * @return The target locations in this context
+ */
+ public Set<String> getTargetLocations() {
+ return this.targetLocationSet;
+ }
}
Modified:
ofbiz/trunk/framework/widget/src/org/ofbiz/widget/artifact/ArtifactInfoGatherer.java
URL:
http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/artifact/ArtifactInfoGatherer.java?rev=1636071&r1=1636070&r2=1636071&view=diff
==============================================================================
---
ofbiz/trunk/framework/widget/src/org/ofbiz/widget/artifact/ArtifactInfoGatherer.java
(original)
+++
ofbiz/trunk/framework/widget/src/org/ofbiz/widget/artifact/ArtifactInfoGatherer.java
Sat Nov 1 23:47:47 2014
@@ -21,8 +21,10 @@ package org.ofbiz.widget.artifact;
import java.util.Set;
import org.ofbiz.base.util.GeneralException;
+import org.ofbiz.base.util.UtilValidate;
import org.ofbiz.webapp.control.ConfigXMLReader;
import org.ofbiz.widget.ModelActionVisitor;
+import org.ofbiz.widget.ModelFieldVisitor;
import org.ofbiz.widget.ModelWidgetAction;
import org.ofbiz.widget.ModelWidgetAction.EntityAnd;
import org.ofbiz.widget.ModelWidgetAction.EntityCondition;
@@ -36,6 +38,33 @@ import org.ofbiz.widget.ModelWidgetActio
import org.ofbiz.widget.ModelWidgetAction.SetField;
import org.ofbiz.widget.ModelWidgetVisitor;
import org.ofbiz.widget.form.ModelForm;
+import org.ofbiz.widget.form.ModelForm.AltTarget;
+import org.ofbiz.widget.form.ModelForm.AutoFieldsEntity;
+import org.ofbiz.widget.form.ModelForm.AutoFieldsService;
+import org.ofbiz.widget.form.ModelFormAction.CallParentActions;
+import org.ofbiz.widget.form.ModelFormField;
+import org.ofbiz.widget.form.ModelFormField.CheckField;
+import org.ofbiz.widget.form.ModelFormField.ContainerField;
+import org.ofbiz.widget.form.ModelFormField.DateFindField;
+import org.ofbiz.widget.form.ModelFormField.DateTimeField;
+import org.ofbiz.widget.form.ModelFormField.DisplayEntityField;
+import org.ofbiz.widget.form.ModelFormField.DisplayField;
+import org.ofbiz.widget.form.ModelFormField.DropDownField;
+import org.ofbiz.widget.form.ModelFormField.FieldInfo;
+import org.ofbiz.widget.form.ModelFormField.FileField;
+import org.ofbiz.widget.form.ModelFormField.HiddenField;
+import org.ofbiz.widget.form.ModelFormField.HyperlinkField;
+import org.ofbiz.widget.form.ModelFormField.IgnoredField;
+import org.ofbiz.widget.form.ModelFormField.ImageField;
+import org.ofbiz.widget.form.ModelFormField.LookupField;
+import org.ofbiz.widget.form.ModelFormField.PasswordField;
+import org.ofbiz.widget.form.ModelFormField.RadioField;
+import org.ofbiz.widget.form.ModelFormField.RangeFindField;
+import org.ofbiz.widget.form.ModelFormField.ResetField;
+import org.ofbiz.widget.form.ModelFormField.SubmitField;
+import org.ofbiz.widget.form.ModelFormField.TextField;
+import org.ofbiz.widget.form.ModelFormField.TextFindField;
+import org.ofbiz.widget.form.ModelFormField.TextareaField;
import org.ofbiz.widget.menu.ModelMenu;
import org.ofbiz.widget.screen.HtmlWidget;
import org.ofbiz.widget.screen.HtmlWidget.HtmlTemplate;
@@ -77,6 +106,10 @@ public final class ArtifactInfoGatherer
}
@Override
+ public void visit(CallParentActions callParentActions) {
+ }
+
+ @Override
public void visit(EntityAnd entityAnd) {
infoContext.addEntityName(entityAnd.getFinder().getEntityName());
}
@@ -147,6 +180,80 @@ public final class ArtifactInfoGatherer
@Override
public void visit(ModelForm modelForm) {
+ if (modelForm.getActions() != null) {
+ for (ModelWidgetAction action : modelForm.getActions()) {
+ action.accept(this);
+ }
+ }
+ if (modelForm.getRowActions() != null) {
+ for (ModelWidgetAction action : modelForm.getRowActions()) {
+ action.accept(this);
+ }
+ }
+ for (AutoFieldsEntity autoFieldsEntity :
modelForm.getAutoFieldsEntities()) {
+ infoContext.addEntityName(autoFieldsEntity.entityName);
+ }
+ for (AutoFieldsService autoFieldsService :
modelForm.getAutoFieldsServices()) {
+ infoContext.addServiceName(autoFieldsService.serviceName);
+ }
+ if (modelForm.getAltTargets() != null) {
+ for (AltTarget altTarget : modelForm.getAltTargets()) {
+ String target = altTarget.targetExdr.getOriginal();
+ String urlMode = "intra-app";
+ try {
+ Set<String> controllerLocAndRequestSet =
ConfigXMLReader.findControllerRequestUniqueForTargetType(target,
+ urlMode);
+ if (controllerLocAndRequestSet != null) {
+ for (String requestLocation :
controllerLocAndRequestSet) {
+ infoContext.addTargetLocation(requestLocation);
+ }
+ }
+ } catch (GeneralException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ }
+ if (!modelForm.getTarget().isEmpty()) {
+ String target = modelForm.getTarget();
+ String urlMode =
UtilValidate.isNotEmpty(modelForm.getTargetType()) ? modelForm.getTargetType()
: "intra-app";
+ if (target.indexOf("${") < 0) {
+ try {
+ Set<String> controllerLocAndRequestSet =
ConfigXMLReader.findControllerRequestUniqueForTargetType(target,
+ urlMode);
+ if (controllerLocAndRequestSet != null) {
+ for (String requestLocation :
controllerLocAndRequestSet) {
+ infoContext.addTargetLocation(requestLocation);
+ }
+ }
+ } catch (GeneralException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ }
+ FieldInfoGatherer fieldInfoGatherer = new FieldInfoGatherer();
+ for (ModelFormField modelFormField : modelForm.getFieldList()) {
+ if (UtilValidate.isNotEmpty(modelFormField.getEntityName())) {
+ infoContext.addEntityName(modelFormField.getEntityName());
+ }
+ if (modelFormField.getFieldInfo() instanceof
ModelFormField.DisplayEntityField) {
+ infoContext.addEntityName(((ModelFormField.DisplayEntityField)
modelFormField.getFieldInfo()).getEntityName());
+ }
+ if (modelFormField.getFieldInfo() instanceof
ModelFormField.FieldInfoWithOptions) {
+ for (ModelFormField.OptionSource optionSource :
((ModelFormField.FieldInfoWithOptions) modelFormField
+ .getFieldInfo()).getOptionSources()) {
+ if (optionSource instanceof ModelFormField.EntityOptions) {
+
infoContext.addEntityName(((ModelFormField.EntityOptions)
optionSource).getEntityName());
+ }
+ }
+ }
+ if (UtilValidate.isNotEmpty(modelFormField.getServiceName())) {
+ infoContext.addServiceName(modelFormField.getServiceName());
+ }
+ FieldInfo fieldInfo = modelFormField.getFieldInfo();
+ if (fieldInfo != null) {
+ fieldInfo.accept(fieldInfoGatherer);
+ }
+ }
}
@Override
@@ -157,7 +264,8 @@ public final class ArtifactInfoGatherer
public void visit(ModelScreen modelScreen) {
String screenLocation =
modelScreen.getSourceLocation().concat("#").concat(modelScreen.getName());
infoContext.addScreenLocation(screenLocation);
- modelScreen.getSection().accept(this);;
+ modelScreen.getSection().accept(this);
+ ;
}
@Override
@@ -279,4 +387,128 @@ public final class ArtifactInfoGatherer
@Override
public void visit(ModelTree modelTree) {
}
+
+ private class FieldInfoGatherer implements ModelFieldVisitor {
+
+ private void addRequestLocations(String target, String urlMode) {
+ try {
+ Set<String> controllerLocAndRequestSet = ConfigXMLReader
+ .findControllerRequestUniqueForTargetType(target,
urlMode);
+ if (controllerLocAndRequestSet != null) {
+ for (String requestLocation : controllerLocAndRequestSet) {
+ infoContext.addRequestLocation(requestLocation);
+ }
+ }
+ } catch (GeneralException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ @Override
+ public void visit(CheckField checkField) {
+ }
+
+ @Override
+ public void visit(ContainerField containerField) {
+ }
+
+ @Override
+ public void visit(DateFindField dateTimeField) {
+ }
+
+ @Override
+ public void visit(DateTimeField dateTimeField) {
+ }
+
+ @Override
+ public void visit(DisplayEntityField displayField) {
+ if (displayField.getSubHyperlink() != null) {
+ String target = displayField.getSubHyperlink().getTarget(null);
+ String urlMode =
displayField.getSubHyperlink().getTargetType();
+ addRequestLocations(target, urlMode);
+ }
+ }
+
+ @Override
+ public void visit(DisplayField displayField) {
+ }
+
+ @Override
+ public void visit(DropDownField dropDownField) {
+ if (dropDownField.getSubHyperlink() != null) {
+ String target =
dropDownField.getSubHyperlink().getTarget(null);
+ String urlMode =
dropDownField.getSubHyperlink().getTargetType();
+ addRequestLocations(target, urlMode);
+ }
+ }
+
+ @Override
+ public void visit(FileField textField) {
+ if (textField.getSubHyperlink() != null) {
+ String target = textField.getSubHyperlink().getTarget(null);
+ String urlMode = textField.getSubHyperlink().getTargetType();
+ addRequestLocations(target, urlMode);
+ }
+ }
+
+ @Override
+ public void visit(HiddenField hiddenField) {
+ }
+
+ @Override
+ public void visit(HyperlinkField hyperlinkField) {
+ String target = hyperlinkField.getTarget(null);
+ String urlMode = hyperlinkField.getTargetType();
+ addRequestLocations(target, urlMode);
+ }
+
+ @Override
+ public void visit(IgnoredField ignoredField) {
+ }
+
+ @Override
+ public void visit(ImageField imageField) {
+ if (imageField.getSubHyperlink() != null) {
+ String target = imageField.getSubHyperlink().getTarget(null);
+ String urlMode = imageField.getSubHyperlink().getTargetType();
+ addRequestLocations(target, urlMode);
+ }
+ }
+
+ @Override
+ public void visit(LookupField textField) {
+ }
+
+ @Override
+ public void visit(PasswordField textField) {
+ }
+
+ @Override
+ public void visit(RadioField radioField) {
+ }
+
+ @Override
+ public void visit(RangeFindField textField) {
+ }
+
+ @Override
+ public void visit(ResetField resetField) {
+ }
+
+ @Override
+ public void visit(SubmitField submitField) {
+ }
+
+ @Override
+ public void visit(TextareaField textareaField) {
+ }
+
+ @Override
+ public void visit(TextField textField) {
+ }
+
+ @Override
+ public void visit(TextFindField textField) {
+ }
+ }
}
Modified: ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelForm.java
URL:
http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelForm.java?rev=1636071&r1=1636070&r2=1636071&view=diff
==============================================================================
--- ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelForm.java
(original)
+++ ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelForm.java Sat
Nov 1 23:47:47 2014
@@ -35,7 +35,6 @@ import java.util.TreeSet;
import org.ofbiz.base.util.BshUtil;
import org.ofbiz.base.util.Debug;
-import org.ofbiz.base.util.GeneralException;
import org.ofbiz.base.util.StringUtil;
import org.ofbiz.base.util.UtilGenerics;
import org.ofbiz.base.util.UtilMisc;
@@ -55,8 +54,8 @@ import org.ofbiz.service.DispatchContext
import org.ofbiz.service.GenericServiceException;
import org.ofbiz.service.ModelParam;
import org.ofbiz.service.ModelService;
-import org.ofbiz.webapp.control.ConfigXMLReader;
import org.ofbiz.widget.ModelWidget;
+import org.ofbiz.widget.ModelWidgetAction;
import org.ofbiz.widget.ModelWidgetVisitor;
import org.ofbiz.widget.WidgetWorker;
import org.w3c.dom.Element;
@@ -189,8 +188,8 @@ public class ModelForm extends ModelWidg
public static String DEFAULT_SORT_FIELD_ASC_STYLE = "sort-order-asc";
public static String DEFAULT_SORT_FIELD_DESC_STYLE = "sort-order-desc";
- protected List<ModelFormAction> actions;
- protected List<ModelFormAction> rowActions;
+ protected List<ModelWidgetAction> actions;
+ protected List<ModelWidgetAction> rowActions;
protected FlexibleStringExpander rowCountExdr;
protected List<ModelFormField> multiSubmitFields = new
ArrayList<ModelFormField>();
protected int rowCount = 0;
@@ -223,6 +222,30 @@ public class ModelForm extends ModelWidg
initForm(formElement);
}
+ public String getTarget() {
+ return target.getOriginal();
+ }
+
+ public List<AltTarget> getAltTargets() {
+ return altTargets;
+ }
+
+ public List<ModelWidgetAction> getActions() {
+ return actions;
+ }
+
+ public List<ModelWidgetAction> getRowActions() {
+ return rowActions;
+ }
+
+ public List<AutoFieldsEntity> getAutoFieldsEntities() {
+ return autoFieldsEntities;
+ }
+
+ public List<AutoFieldsService> getAutoFieldsServices() {
+ return autoFieldsServices;
+ }
+
public void initForm(Element formElement) {
setDefaultViewSize(UtilProperties.getPropertyValue("widget.properties",
"widget.form.defaultViewSize"));
@@ -3160,166 +3183,6 @@ public class ModelForm extends ModelWidg
}
}
- public Set<String> getAllEntityNamesUsed() {
- Set<String> allEntityNamesUsed = new HashSet<String>();
- for (AutoFieldsEntity autoFieldsEntity: this.autoFieldsEntities) {
- allEntityNamesUsed.add(autoFieldsEntity.entityName);
- }
- if (this.actions != null) {
- for (ModelFormAction modelFormAction: this.actions) {
- if (modelFormAction instanceof ModelFormAction.EntityOne) {
-
allEntityNamesUsed.add(((ModelFormAction.EntityOne)modelFormAction).finder.getEntityName());
- } else if (modelFormAction instanceof
ModelFormAction.EntityAnd) {
-
allEntityNamesUsed.add(((ModelFormAction.EntityAnd)modelFormAction).finder.getEntityName());
- } else if (modelFormAction instanceof
ModelFormAction.EntityCondition) {
-
allEntityNamesUsed.add(((ModelFormAction.EntityCondition)modelFormAction).finder.getEntityName());
- }
-
- }
- }
- if (this.rowActions != null) {
- for (ModelFormAction modelFormAction: this.rowActions) {
- if (modelFormAction instanceof ModelFormAction.EntityOne) {
-
allEntityNamesUsed.add(((ModelFormAction.EntityOne)modelFormAction).finder.getEntityName());
- } else if (modelFormAction instanceof
ModelFormAction.EntityAnd) {
-
allEntityNamesUsed.add(((ModelFormAction.EntityAnd)modelFormAction).finder.getEntityName());
- } else if (modelFormAction instanceof
ModelFormAction.EntityCondition) {
-
allEntityNamesUsed.add(((ModelFormAction.EntityCondition)modelFormAction).finder.getEntityName());
- }
- }
- }
- for (ModelFormField modelFormField: this.fieldList) {
- if (UtilValidate.isNotEmpty(modelFormField.getEntityName())) {
- allEntityNamesUsed.add(modelFormField.getEntityName());
- }
- if (modelFormField.getFieldInfo() instanceof
ModelFormField.DisplayEntityField) {
-
allEntityNamesUsed.add(((ModelFormField.DisplayEntityField)modelFormField.getFieldInfo()).entityName);
- }
- if (modelFormField.getFieldInfo() instanceof
ModelFormField.FieldInfoWithOptions) {
- for (ModelFormField.OptionSource optionSource:
((ModelFormField.FieldInfoWithOptions)modelFormField.getFieldInfo()).optionSources)
{
- if (optionSource instanceof ModelFormField.EntityOptions) {
-
allEntityNamesUsed.add(((ModelFormField.EntityOptions)optionSource).entityName);
- }
- }
- }
- }
- return allEntityNamesUsed;
- }
-
- public Set<String> getAllServiceNamesUsed() {
- Set<String> allServiceNamesUsed = new HashSet<String>();
- for (AutoFieldsService autoFieldsService: this.autoFieldsServices) {
- allServiceNamesUsed.add(autoFieldsService.serviceName);
- }
- if (this.actions != null) {
- for (ModelFormAction modelFormAction: this.actions) {
- try {
- ModelFormAction.Service service =
(ModelFormAction.Service) modelFormAction;
- if (!service.serviceNameExdr.isEmpty()) {
-
allServiceNamesUsed.add(service.serviceNameExdr.toString());
- }
- } catch (ClassCastException e) {}
- }
- }
- if (this.rowActions != null) {
- for (ModelFormAction modelFormAction: this.rowActions) {
- try {
- ModelFormAction.Service service =
(ModelFormAction.Service) modelFormAction;
- if (!service.serviceNameExdr.isEmpty()) {
-
allServiceNamesUsed.add(service.serviceNameExdr.toString());
- }
- } catch (ClassCastException e) {}
- }
- }
- for (ModelFormField modelFormField: this.fieldList) {
- if (UtilValidate.isNotEmpty(modelFormField.getServiceName())) {
- allServiceNamesUsed.add(modelFormField.getServiceName());
- }
- }
- return allServiceNamesUsed;
- }
-
- public Set<String> getLinkedRequestsLocationAndUri() throws
GeneralException {
- Set<String> allRequestsUsed = new HashSet<String>();
-
- if (this.fieldList != null) {
- for (ModelFormField modelFormField: this.fieldList) {
- if (modelFormField.getFieldInfo() instanceof
ModelFormField.HyperlinkField) {
- ModelFormField.HyperlinkField link =
(ModelFormField.HyperlinkField) modelFormField.getFieldInfo();
- String target = link.getTarget(null);
- String urlMode = link.getTargetType();
-
- Set<String> controllerLocAndRequestSet =
ConfigXMLReader.findControllerRequestUniqueForTargetType(target, urlMode);
- if (controllerLocAndRequestSet != null) {
- allRequestsUsed.addAll(controllerLocAndRequestSet);
- }
- } else if (modelFormField.getFieldInfo() instanceof
ModelFormField.DisplayEntityField) {
- ModelFormField.DisplayEntityField parentField =
(ModelFormField.DisplayEntityField) modelFormField.getFieldInfo();
- if (parentField.subHyperlink != null) {
- Set<String> controllerLocAndRequestSet =
ConfigXMLReader.findControllerRequestUniqueForTargetType(parentField.subHyperlink.getTarget(null),
parentField.subHyperlink.getTargetType());
- if (controllerLocAndRequestSet != null) {
- allRequestsUsed.addAll(controllerLocAndRequestSet);
- }
- }
- } else if (modelFormField.getFieldInfo() instanceof
ModelFormField.TextField) {
- ModelFormField.TextField parentField =
(ModelFormField.TextField) modelFormField.getFieldInfo();
- if (parentField.subHyperlink != null) {
- Set<String> controllerLocAndRequestSet =
ConfigXMLReader.findControllerRequestUniqueForTargetType(parentField.subHyperlink.getTarget(null),
parentField.subHyperlink.getTargetType());
- if (controllerLocAndRequestSet != null) {
- allRequestsUsed.addAll(controllerLocAndRequestSet);
- }
- }
- } else if (modelFormField.getFieldInfo() instanceof
ModelFormField.DropDownField) {
- ModelFormField.DropDownField parentField =
(ModelFormField.DropDownField) modelFormField.getFieldInfo();
- if (parentField.subHyperlink != null) {
- Set<String> controllerLocAndRequestSet =
ConfigXMLReader.findControllerRequestUniqueForTargetType(parentField.subHyperlink.getTarget(null),
parentField.subHyperlink.getTargetType());
- if (controllerLocAndRequestSet != null) {
- allRequestsUsed.addAll(controllerLocAndRequestSet);
- }
- }
- } else if (modelFormField.getFieldInfo() instanceof
ModelFormField.ImageField) {
- ModelFormField.ImageField parentField =
(ModelFormField.ImageField) modelFormField.getFieldInfo();
- if (parentField.subHyperlink != null) {
- Set<String> controllerLocAndRequestSet =
ConfigXMLReader.findControllerRequestUniqueForTargetType(parentField.subHyperlink.getTarget(null),
parentField.subHyperlink.getTargetType());
- if (controllerLocAndRequestSet != null) {
- allRequestsUsed.addAll(controllerLocAndRequestSet);
- }
- }
- }
- }
- }
- return allRequestsUsed;
- }
-
- public Set<String> getTargetedRequestsLocationAndUri() throws
GeneralException {
- Set<String> allRequestsUsed = new HashSet<String>();
-
- if (this.altTargets != null) {
- for (AltTarget altTarget: this.altTargets) {
- String target = altTarget.targetExdr.getOriginal();
- String urlMode = "intra-app";
-
- Set<String> controllerLocAndRequestSet =
ConfigXMLReader.findControllerRequestUniqueForTargetType(target, urlMode);
- if (controllerLocAndRequestSet != null) {
- allRequestsUsed.addAll(controllerLocAndRequestSet);
- }
- }
- }
-
- if (!this.target.isEmpty()) {
- String target = this.target.getOriginal();
- String urlMode = UtilValidate.isNotEmpty(this.targetType) ?
this.targetType : "intra-app";
- if (target.indexOf("${") < 0) {
- Set<String> controllerLocAndRequestSet =
ConfigXMLReader.findControllerRequestUniqueForTargetType(target, urlMode);
- if (controllerLocAndRequestSet != null) {
- allRequestsUsed.addAll(controllerLocAndRequestSet);
- }
- }
- }
-
- return allRequestsUsed;
- }
-
@Override
public void accept(ModelWidgetVisitor visitor) {
visitor.visit(this);
Modified:
ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelFormAction.java
URL:
http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelFormAction.java?rev=1636071&r1=1636070&r2=1636071&view=diff
==============================================================================
--- ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelFormAction.java
(original)
+++ ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelFormAction.java
Sat Nov 1 23:47:47 2014
@@ -18,518 +18,62 @@
*******************************************************************************/
package org.ofbiz.widget.form;
-import java.text.MessageFormat;
-import java.util.HashMap;
-import java.util.LinkedList;
+import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
-import java.util.ListIterator;
-import java.util.Locale;
import java.util.Map;
-import java.util.TimeZone;
-import java.util.regex.PatternSyntaxException;
import org.ofbiz.base.util.Debug;
import org.ofbiz.base.util.GeneralException;
-import org.ofbiz.base.util.ObjectType;
-import org.ofbiz.base.util.ScriptUtil;
-import org.ofbiz.base.util.UtilGenerics;
-import org.ofbiz.base.util.UtilProperties;
-import org.ofbiz.base.util.UtilValidate;
import org.ofbiz.base.util.UtilXml;
-import org.ofbiz.base.util.collections.FlexibleMapAccessor;
-import org.ofbiz.base.util.string.FlexibleStringExpander;
-import org.ofbiz.entity.finder.ByAndFinder;
-import org.ofbiz.entity.finder.ByConditionFinder;
-import org.ofbiz.entity.finder.EntityFinderUtil;
-import org.ofbiz.entity.finder.PrimaryKeyFinder;
-import org.ofbiz.entity.util.EntityUtilProperties;
-import org.ofbiz.minilang.MiniLangException;
-import org.ofbiz.minilang.SimpleMethod;
-import org.ofbiz.minilang.method.MethodContext;
-import org.ofbiz.service.DispatchContext;
-import org.ofbiz.service.GenericServiceException;
-import org.ofbiz.service.ModelService;
-import org.ofbiz.widget.WidgetWorker;
+import org.ofbiz.widget.ModelActionVisitor;
+import org.ofbiz.widget.ModelWidgetAction;
import org.w3c.dom.Element;
-
/**
* Widget Library - Screen model class
*/
-public abstract class ModelFormAction {
- public static final String module = ModelFormAction.class.getName();
+public class ModelFormAction {
- protected ModelForm modelForm;
-
- public ModelFormAction(ModelForm modelForm, Element actionElement) {
- this.modelForm = modelForm;
- if (Debug.verboseOn()) Debug.logVerbose("Reading Screen action with
name: " + actionElement.getNodeName(), module);
- }
-
- public abstract void runAction(Map<String, Object> context);
-
- public static List<ModelFormAction> readSubActions(ModelForm modelForm,
Element parentElement) {
- List<ModelFormAction> actions = new LinkedList<ModelFormAction>();
+ public static final String module = ModelFormAction.class.getName();
+ public static List<ModelWidgetAction> readSubActions(ModelForm modelForm,
Element parentElement) {
+ List<? extends Element> elementList =
UtilXml.childElementList(parentElement);
+ if (elementList.isEmpty()) {
+ return Collections.emptyList();
+ }
+ List<ModelWidgetAction> actions = new
ArrayList<ModelWidgetAction>(elementList.size());
for (Element actionElement: UtilXml.childElementList(parentElement)) {
- if ("set".equals(actionElement.getNodeName())) {
- actions.add(new SetField(modelForm, actionElement));
- } else if ("property-map".equals(actionElement.getNodeName())) {
- actions.add(new PropertyMap(modelForm, actionElement));
- } else if
("property-to-field".equals(actionElement.getNodeName())) {
- actions.add(new PropertyToField(modelForm, actionElement));
- } else if ("script".equals(actionElement.getNodeName())) {
- actions.add(new Script(modelForm, actionElement));
- } else if ("service".equals(actionElement.getNodeName())) {
- actions.add(new Service(modelForm, actionElement));
- } else if ("entity-one".equals(actionElement.getNodeName())) {
- actions.add(new EntityOne(modelForm, actionElement));
- } else if ("entity-and".equals(actionElement.getNodeName())) {
- actions.add(new EntityAnd(modelForm, actionElement));
- } else if ("entity-condition".equals(actionElement.getNodeName()))
{
- actions.add(new EntityCondition(modelForm, actionElement));
- } else if
("call-parent-actions".equals(actionElement.getNodeName())) {
+ if ("call-parent-actions".equals(actionElement.getNodeName())) {
actions.add(new CallParentActions(modelForm, actionElement));
} else {
- throw new IllegalArgumentException("Action element not
supported with name: " + actionElement.getNodeName());
+ actions.add(ModelWidgetAction.toModelWidgetAction(modelForm,
actionElement));
}
}
-
- return actions;
+ return Collections.unmodifiableList(actions);
}
- public static void runSubActions(List<ModelFormAction> actions,
Map<String, Object> context) {
+ public static void runSubActions(List<ModelWidgetAction> actions,
Map<String, Object> context) {
if (actions == null) return;
-
- for (ModelFormAction action: actions) {
- if (Debug.verboseOn()) Debug.logVerbose("Running screen action " +
action.getClass().getName(), module);
- action.runAction(context);
- }
- }
-
- public static class SetField extends ModelFormAction {
- protected FlexibleMapAccessor<Object> field;
- protected FlexibleMapAccessor<String> fromField;
- protected FlexibleStringExpander valueExdr;
- protected FlexibleStringExpander defaultExdr;
- protected FlexibleStringExpander globalExdr;
- protected String type;
-
- public SetField(ModelForm modelForm, Element setElement) {
- super (modelForm, setElement);
- this.field =
FlexibleMapAccessor.getInstance(setElement.getAttribute("field"));
- this.fromField =
FlexibleMapAccessor.getInstance(setElement.getAttribute("from-field"));
- this.valueExdr =
FlexibleStringExpander.getInstance(setElement.getAttribute("value"));
- this.defaultExdr =
FlexibleStringExpander.getInstance(setElement.getAttribute("default-value"));
- this.globalExdr =
FlexibleStringExpander.getInstance(setElement.getAttribute("global"));
- this.type = setElement.getAttribute("type");
- if (!this.fromField.isEmpty() && !this.valueExdr.isEmpty()) {
- throw new IllegalArgumentException("Cannot specify a
from-field [" + setElement.getAttribute("from-field") + "] and a value [" +
setElement.getAttribute("value") + "] on the set action in a screen widget");
- }
- }
-
- @SuppressWarnings("rawtypes")
- @Override
- public void runAction(Map<String, Object> context) {
- String globalStr = this.globalExdr.expandString(context);
- // default to false
- boolean global = "true".equals(globalStr);
-
- Object newValue = null;
- if (!this.fromField.isEmpty()) {
- newValue = this.fromField.get(context);
- if (Debug.verboseOn()) Debug.logVerbose("In screen getting
value for field from [" + this.fromField.getOriginalName() + "]: " + newValue,
module);
- } else if (!this.valueExdr.isEmpty()) {
- newValue = this.valueExdr.expand(context);
- }
-
- // If newValue is still empty, use the default value
- if (ObjectType.isEmpty(newValue) && !this.defaultExdr.isEmpty()) {
- newValue = this.defaultExdr.expand(context);
- }
-
- if (UtilValidate.isNotEmpty(this.type)) {
- if ("NewMap".equals(this.type)) {
- newValue = new HashMap();
- } else if ("NewList".equals(this.type)) {
- newValue = new LinkedList();
- } else {
- try {
- newValue = ObjectType.simpleTypeConvert(newValue,
this.type, null, (TimeZone) context.get("timeZone"), (Locale)
context.get("locale"), true);
- } catch (GeneralException e) {
- String errMsg = "Could not convert field value for the
field: [" + this.field.getOriginalName() + "] to the [" + this.type + "] type
for the value [" + newValue + "]: " + e.toString();
- Debug.logError(e, errMsg, module);
- throw new IllegalArgumentException(errMsg);
- }
- }
- }
- if (Debug.verboseOn()) Debug.logVerbose("In screen setting field
[" + this.field.getOriginalName() + "] to value: " + newValue, module);
- this.field.put(context, newValue);
-
- if (global) {
- Map<String, Object> globalCtx =
UtilGenerics.checkMap(context.get("globalContext"));
- if (globalCtx != null) {
- this.field.put(globalCtx, newValue);
- }
- }
-
- // this is a hack for backward compatibility with the JPublish
page object
- Map<String, Object> page =
UtilGenerics.checkMap(context.get("page"));
- if (page != null) {
- this.field.put(page, newValue);
- }
- }
- }
-
- public static class PropertyMap extends ModelFormAction {
- protected FlexibleStringExpander resourceExdr;
- protected FlexibleMapAccessor<Map<String, Object>> mapNameAcsr;
- protected FlexibleStringExpander globalExdr;
-
- public PropertyMap(ModelForm modelForm, Element setElement) {
- super (modelForm, setElement);
- this.resourceExdr =
FlexibleStringExpander.getInstance(setElement.getAttribute("resource"));
- this.mapNameAcsr =
FlexibleMapAccessor.getInstance(setElement.getAttribute("map-name"));
- this.globalExdr =
FlexibleStringExpander.getInstance(setElement.getAttribute("global"));
- }
-
- @Override
- public void runAction(Map<String, Object> context) {
- String globalStr = this.globalExdr.expandString(context);
- // default to false
- boolean global = "true".equals(globalStr);
-
- Locale locale = (Locale) context.get("locale");
- String resource = this.resourceExdr.expandString(context, locale);
- Map<String, Object> propertyMap =
UtilProperties.getResourceBundleMap(resource, locale);
- this.mapNameAcsr.put(context, propertyMap);
-
- if (global) {
- Map<String, Object> globalCtx =
UtilGenerics.checkMap(context.get("globalContext"));
- if (globalCtx != null) {
- this.mapNameAcsr.put(globalCtx, propertyMap);
- }
- }
- }
- }
-
- public static class PropertyToField extends ModelFormAction {
-
- protected FlexibleStringExpander resourceExdr;
- protected FlexibleStringExpander propertyExdr;
- protected FlexibleMapAccessor<String> fieldAcsr;
- protected FlexibleStringExpander defaultExdr;
- protected boolean noLocale;
- protected FlexibleMapAccessor<List<Object>> argListAcsr;
- protected FlexibleStringExpander globalExdr;
-
- public PropertyToField(ModelForm modelForm, Element setElement) {
- super (modelForm, setElement);
- this.resourceExdr =
FlexibleStringExpander.getInstance(setElement.getAttribute("resource"));
- this.propertyExdr =
FlexibleStringExpander.getInstance(setElement.getAttribute("property"));
- this.fieldAcsr =
FlexibleMapAccessor.getInstance(setElement.getAttribute("field"));
- this.defaultExdr =
FlexibleStringExpander.getInstance(setElement.getAttribute("default"));
- noLocale = "true".equals(setElement.getAttribute("no-locale"));
- this.argListAcsr =
FlexibleMapAccessor.getInstance(setElement.getAttribute("arg-list-name"));
- this.globalExdr =
FlexibleStringExpander.getInstance(setElement.getAttribute("global"));
- }
-
- @Override
- public void runAction(Map<String, Object> context) {
- //String globalStr = this.globalExdr.expandString(context);
- // default to false
- //boolean global = "true".equals(globalStr);
-
- Locale locale = (Locale) context.get("locale");
- String resource = this.resourceExdr.expandString(context, locale);
- String property = this.propertyExdr.expandString(context, locale);
-
- String value = null;
- if (noLocale) {
- value = EntityUtilProperties.getPropertyValue(resource,
property, WidgetWorker.getDelegator(context));
- } else {
- value = EntityUtilProperties.getMessage(resource, property,
locale, WidgetWorker.getDelegator(context));
- }
- if (UtilValidate.isEmpty(value)) {
- value = this.defaultExdr.expandString(context);
- }
-
- // note that expanding the value string here will handle
defaultValue and the string from
- // the properties file; if we decide later that we don't want the
string from the properties
- // file to be expanded we should just expand the defaultValue at
the beginning of this method.
- value = FlexibleStringExpander.expandString(value, context);
-
- if (!argListAcsr.isEmpty()) {
- List<Object> argList = argListAcsr.get(context);
- if (UtilValidate.isNotEmpty(argList)) {
- value = MessageFormat.format(value, argList.toArray());
- }
- }
-
- fieldAcsr.put(context, value);
- }
- }
-
- public static class Script extends ModelFormAction {
- protected String location;
- protected String method;
-
- public Script(ModelForm modelForm, Element scriptElement) {
- super (modelForm, scriptElement);
- String scriptLocation = scriptElement.getAttribute("location");
- this.location = WidgetWorker.getScriptLocation(scriptLocation);
- this.method = WidgetWorker.getScriptMethodName(scriptLocation);
- }
-
- @Override
- public void runAction(Map<String, Object> context) {
- if (location.endsWith(".xml")) {
- Map<String, Object> localContext = new HashMap<String,
Object>();
- localContext.putAll(context);
- DispatchContext ctx = this.modelForm.dispatchContext;
- MethodContext methodContext = new MethodContext(ctx,
localContext, null);
- try {
- SimpleMethod.runSimpleMethod(location, method,
methodContext);
- context.putAll(methodContext.getResults());
- } catch (MiniLangException e) {
- throw new IllegalArgumentException("Error running simple
method at location [" + location + "]", e);
- }
- } else {
- ScriptUtil.executeScript(this.location, this.method, context);
- }
- }
- }
-
- public static class Service extends ModelFormAction {
- protected FlexibleStringExpander serviceNameExdr;
- protected FlexibleMapAccessor<Map<String, Object>> resultMapNameAcsr;
- protected FlexibleStringExpander autoFieldMapExdr;
- protected FlexibleStringExpander resultMapListNameExdr;
- protected Map<FlexibleMapAccessor<Object>, Object> fieldMap;
- protected boolean ignoreError = false;
-
- public Service(ModelForm modelForm, Element serviceElement) {
- super (modelForm, serviceElement);
- this.serviceNameExdr =
FlexibleStringExpander.getInstance(serviceElement.getAttribute("service-name"));
- this.resultMapNameAcsr =
FlexibleMapAccessor.getInstance(serviceElement.getAttribute("result-map"));
- if (this.resultMapNameAcsr.isEmpty()) this.resultMapNameAcsr =
FlexibleMapAccessor.getInstance(serviceElement.getAttribute("result-map-name"));
- this.autoFieldMapExdr =
FlexibleStringExpander.getInstance(serviceElement.getAttribute("auto-field-map"));
- if
(UtilValidate.isEmpty(serviceElement.getAttribute("result-map-list")) &&
UtilValidate.isEmpty(serviceElement.getAttribute("result-map-list-name"))) {
- if
(UtilValidate.isEmpty(serviceElement.getAttribute("result-map-list-iterator"))
&&
UtilValidate.isEmpty(serviceElement.getAttribute("result-map-list-iterator-name")))
{
- String lstNm = modelForm.getListName();
- if (UtilValidate.isEmpty(lstNm)) {
- lstNm = ModelForm.DEFAULT_FORM_RESULT_LIST_NAME;
- }
- this.resultMapListNameExdr =
FlexibleStringExpander.getInstance(lstNm);
- } else {
- // this is deprecated, but support it for now anyway
- this.resultMapListNameExdr =
FlexibleStringExpander.getInstance(serviceElement.getAttribute("result-map-list-iterator"));
- if (this.resultMapListNameExdr.isEmpty())
this.resultMapListNameExdr =
FlexibleStringExpander.getInstance(serviceElement.getAttribute("result-map-list-iterator-name"));
- }
- } else {
- this.resultMapListNameExdr =
FlexibleStringExpander.getInstance(serviceElement.getAttribute("result-map-list"));
- if (this.resultMapListNameExdr.isEmpty())
this.resultMapListNameExdr =
FlexibleStringExpander.getInstance(serviceElement.getAttribute("result-map-list-name"));
- }
-
- this.fieldMap = EntityFinderUtil.makeFieldMap(serviceElement);
- this.ignoreError =
"true".equals(serviceElement.getAttribute("ignore-error"));
- }
-
- @Override
- public void runAction(Map<String, Object> context) {
- String serviceNameExpanded =
this.serviceNameExdr.expandString(context);
- if (UtilValidate.isEmpty(serviceNameExpanded)) {
- throw new IllegalArgumentException("Service name was empty,
expanded from: " + this.serviceNameExdr.getOriginal());
- }
-
- String autoFieldMapString =
this.autoFieldMapExdr.expandString(context);
- boolean autoFieldMapBool = !"false".equals(autoFieldMapString);
-
- try {
- Map<String, Object> serviceContext = null;
- if (autoFieldMapBool) {
- if (! "true".equals(autoFieldMapString)) {
- Map<String, Object> autoFieldMap =
UtilGenerics.checkMap(context.get(autoFieldMapString));
- serviceContext =
WidgetWorker.getDispatcher(context).getDispatchContext().makeValidContext(serviceNameExpanded,
ModelService.IN_PARAM, autoFieldMap);
- } else {
- serviceContext =
WidgetWorker.getDispatcher(context).getDispatchContext().makeValidContext(serviceNameExpanded,
ModelService.IN_PARAM, context);
- }
- } else {
- serviceContext = new HashMap<String, Object>();
- }
-
- if (this.fieldMap != null) {
- EntityFinderUtil.expandFieldMapToContext(this.fieldMap,
context, serviceContext);
- }
-
- Map<String, Object> result = null;
- if (this.ignoreError) {
- result =
WidgetWorker.getDispatcher(context).runSync(serviceNameExpanded,
serviceContext, -1, true);
- } else {
- result =
WidgetWorker.getDispatcher(context).runSync(serviceNameExpanded,
serviceContext);
- }
-
- if (!this.resultMapNameAcsr.isEmpty()) {
- this.resultMapNameAcsr.put(context, result);
- String queryString = (String)result.get("queryString");
- context.put("queryString", queryString);
- context.put("queryStringMap",
result.get("queryStringMap"));
- if (UtilValidate.isNotEmpty(queryString)) {
- try {
- String queryStringEncoded =
queryString.replaceAll("&", "%26");
- context.put("queryStringEncoded",
queryStringEncoded);
- } catch (PatternSyntaxException e) {
-
- }
- }
- } else {
- context.putAll(result);
- }
- String listName = resultMapListNameExdr.expandString(context);
- Object listObj = result.get(listName);
- if (listObj != null) {
- if (!(listObj instanceof List<?>) && !(listObj instanceof
ListIterator<?>)) {
- throw new IllegalArgumentException("Error in form [" +
this.modelForm.getName() + "] calling service with name [" +
serviceNameExpanded + "]: the result that is supposed to be a List or
ListIterator and is not.");
- }
- context.put("listName", listName);
- context.put(listName, listObj);
- }
- } catch (GenericServiceException e) {
- String errMsg = "Error in form [" + this.modelForm.getName() +
"] calling service with name [" + serviceNameExpanded + "]: " + e.toString();
- Debug.logError(e, errMsg, module);
- if (!this.ignoreError) {
- throw new IllegalArgumentException(errMsg);
- }
- }
- }
- }
-
- public static class EntityOne extends ModelFormAction {
- protected PrimaryKeyFinder finder;
-
- public EntityOne(ModelForm modelForm, Element entityOneElement) {
- super (modelForm, entityOneElement);
- finder = new PrimaryKeyFinder(entityOneElement);
- }
-
- @Override
- public void runAction(Map<String, Object> context) {
+ for (ModelWidgetAction action: actions) {
+ if (Debug.verboseOn()) Debug.logVerbose("Running form action " +
action.getClass().getName(), module);
try {
- finder.runFind(context, WidgetWorker.getDelegator(context));
+ action.runAction(context);
} catch (GeneralException e) {
- String errMsg = "Error doing entity query by condition: " +
e.toString();
- Debug.logError(e, errMsg, module);
- throw new IllegalArgumentException(errMsg);
+ throw new RuntimeException(e);
}
}
}
- public static class EntityAnd extends ModelFormAction {
- protected ByAndFinder finder;
- String actualListName;
-
- public EntityAnd(ModelForm modelForm, Element entityAndElement) {
- super (modelForm, entityAndElement);
-
- //don't want to default to the iterator, should be specified
explicitly, not the default
- // Document ownerDoc = entityAndElement.getOwnerDocument();
- // boolean useCache =
"true".equalsIgnoreCase(entityAndElement.getAttribute("use-cache"));
- // if (!useCache) UtilXml.addChildElement(entityAndElement,
"use-iterator", ownerDoc);
-
- // make list-name optional
- if (UtilValidate.isEmpty(entityAndElement.getAttribute("list")) &&
UtilValidate.isEmpty(entityAndElement.getAttribute("list-name"))) {
- String lstNm = modelForm.getListName();
- if (UtilValidate.isEmpty(lstNm)) {
- lstNm = ModelForm.DEFAULT_FORM_RESULT_LIST_NAME;
- }
- entityAndElement.setAttribute("list", lstNm);
- }
- this.actualListName = entityAndElement.getAttribute("list");
- if (UtilValidate.isEmpty(this.actualListName)) this.actualListName
= entityAndElement.getAttribute("list-name");
- finder = new ByAndFinder(entityAndElement);
- }
-
- @Override
- public void runAction(Map<String, Object> context) {
- try {
- // don't want to do this: context.put("defaultFormResultList",
null);
- finder.runFind(context, WidgetWorker.getDelegator(context));
-
- /* NOTE DEJ20100925: this should not be running any more as it
causes actions in a list or multi
- * form definition to overwrite the desired list elsewhere,
this was the really old way of doing
- * it that was removed a long time ago and needs to stay gone
to avoid issues; the form's list
- * should be found by explicitly matching the name:
- Object obj = context.get(this.actualListName);
- if (obj != null && ((obj instanceof List) || (obj instanceof
EntityListIterator))) {
- String modelFormListName = modelForm.getListName();
- context.put(modelFormListName, obj);
- }
- */
- } catch (GeneralException e) {
- String errMsg = "Error doing entity query by condition: " +
e.toString();
- Debug.logError(e, errMsg, module);
- throw new IllegalArgumentException(errMsg);
- }
- }
-
- }
-
- public static class EntityCondition extends ModelFormAction {
- ByConditionFinder finder;
- String actualListName;
-
- public EntityCondition(ModelForm modelForm, Element
entityConditionElement) {
- super (modelForm, entityConditionElement);
-
- //don't want to default to the iterator, should be specified
explicitly, not the default
- // Document ownerDoc = entityConditionElement.getOwnerDocument();
- // boolean useCache =
"true".equalsIgnoreCase(entityConditionElement.getAttribute("use-cache"));
- // if (!useCache) UtilXml.addChildElement(entityConditionElement,
"use-iterator", ownerDoc);
-
- // make list-name optional
- if
(UtilValidate.isEmpty(entityConditionElement.getAttribute("list")) &&
UtilValidate.isEmpty(entityConditionElement.getAttribute("list-name"))) {
- String lstNm = modelForm.getListName();
- if (UtilValidate.isEmpty(lstNm)) {
- lstNm = ModelForm.DEFAULT_FORM_RESULT_LIST_NAME;
- }
- entityConditionElement.setAttribute("list", lstNm);
- }
- this.actualListName = entityConditionElement.getAttribute("list");
- if (UtilValidate.isEmpty(this.actualListName)) this.actualListName
= entityConditionElement.getAttribute("list-name");
- finder = new ByConditionFinder(entityConditionElement);
- }
-
- @Override
- public void runAction(Map<String, Object> context) {
- try {
- // don't want to do this: context.put("defaultFormResultList",
null);
- finder.runFind(context, WidgetWorker.getDelegator(context));
-
- /* NOTE DEJ20100925: this should not be running any more as it
causes actions in a list or multi
- * form definition to overwrite the desired list elsewhere,
this was the really old way of doing
- * it that was removed a long time ago and needs to stay gone
to avoid issues; the form's list
- * should be found by explicitly matching the name:
- Object obj = context.get(this.actualListName);
- if (obj != null && ((obj instanceof List) || (obj instanceof
EntityListIterator))) {
- String modelFormListName = modelForm.getListName();
- context.put(modelFormListName, obj);
- }
- */
- } catch (GeneralException e) {
- String errMsg = "Error doing entity query by condition: " +
e.toString();
- Debug.logError(e, errMsg, module);
- throw new IllegalArgumentException(errMsg);
- }
- }
- }
-
- public static class CallParentActions extends ModelFormAction {
+ @SuppressWarnings("serial")
+ public static class CallParentActions extends ModelWidgetAction {
protected static enum ActionsKind {
ACTIONS,
ROW_ACTIONS
};
protected ActionsKind kind;
+ private final ModelForm modelForm;
public CallParentActions(ModelForm modelForm, Element
callParentActionsElement) {
super(modelForm, callParentActionsElement);
@@ -541,11 +85,11 @@ public abstract class ModelFormAction {
} else {
throw new IllegalArgumentException("Action element not
supported for call-parent-actions : " + parentName);
}
-
ModelForm parentModel = modelForm.getParentModelForm();
if (parentModel == null) {
throw new IllegalArgumentException("call-parent-actions can
only be used with form extending another form");
}
+ this.modelForm = modelForm;
}
@Override
@@ -560,5 +104,10 @@ public abstract class ModelFormAction {
break;
}
}
+
+ @Override
+ public void accept(ModelActionVisitor visitor) {
+ visitor.visit(this);
+ }
}
}