You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lenya.apache.org by an...@apache.org on 2005/01/27 16:02:13 UTC
svn commit: r126613 - in lenya/trunk/src/java/org/apache/lenya: . cms/ac/workflow cms/ant cms/cocoon/acting cms/cocoon/components/modules/input cms/cocoon/flow cms/cocoon/transformation cms/cocoon/workflow cms/publication/task cms/site/usecases cms/task cms/usecase cms/workflow cms/workflow/usecases workflow workflow/impl
Author: andreas
Date: Thu Jan 27 07:02:08 2005
New Revision: 126613
URL: http://svn.apache.org/viewcvs?view=rev&rev=126613
Log:
introduced workflow resolver
Added:
lenya/trunk/src/java/org/apache/lenya/cms/workflow/WorkflowResolver.java
lenya/trunk/src/java/org/apache/lenya/cms/workflow/WorkflowResolverImpl.java
lenya/trunk/src/java/org/apache/lenya/workflow/History.java
lenya/trunk/src/java/org/apache/lenya/workflow/impl/HistoryImpl.java
Removed:
lenya/trunk/src/java/org/apache/lenya/workflow/impl/History.java
Modified:
lenya/trunk/src/java/org/apache/lenya/cms/ac/workflow/WorkflowAuthorizer.java
lenya/trunk/src/java/org/apache/lenya/cms/ant/InitCopyWorkflowTask.java
lenya/trunk/src/java/org/apache/lenya/cms/ant/InitWorkflowHistoryTask.java
lenya/trunk/src/java/org/apache/lenya/cms/ant/MoveDocumentTask.java
lenya/trunk/src/java/org/apache/lenya/cms/ant/MoveWorkflowTask.java
lenya/trunk/src/java/org/apache/lenya/cms/cocoon/acting/WorkflowInvokerAction.java
lenya/trunk/src/java/org/apache/lenya/cms/cocoon/components/modules/input/WorkflowModule.java
lenya/trunk/src/java/org/apache/lenya/cms/cocoon/flow/FlowHelperImpl.java
lenya/trunk/src/java/org/apache/lenya/cms/cocoon/transformation/WorkflowMenuTransformer.java
lenya/trunk/src/java/org/apache/lenya/cms/cocoon/workflow/WorkflowHelper.java
lenya/trunk/src/java/org/apache/lenya/cms/publication/task/PublicationTask.java
lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/Create.java
lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/DeleteLanguage.java
lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/SiteUsecase.java
lenya/trunk/src/java/org/apache/lenya/cms/task/WorkflowInvoker.java
lenya/trunk/src/java/org/apache/lenya/cms/usecase/DocumentUsecase.java
lenya/trunk/src/java/org/apache/lenya/cms/usecase/WorkflowUsecase.java
lenya/trunk/src/java/org/apache/lenya/cms/workflow/CMSHistory.java
lenya/trunk/src/java/org/apache/lenya/cms/workflow/WorkflowDocument.java
lenya/trunk/src/java/org/apache/lenya/cms/workflow/WorkflowFactory.java
lenya/trunk/src/java/org/apache/lenya/cms/workflow/usecases/InvokeWorkflow.java
lenya/trunk/src/java/org/apache/lenya/lenya.roles
lenya/trunk/src/java/org/apache/lenya/workflow/SynchronizedWorkflowInstances.java
lenya/trunk/src/java/org/apache/lenya/workflow/Workflow.java
lenya/trunk/src/java/org/apache/lenya/workflow/WorkflowInstance.java
lenya/trunk/src/java/org/apache/lenya/workflow/WorkflowListener.java
lenya/trunk/src/java/org/apache/lenya/workflow/impl/AbstractCondition.java
lenya/trunk/src/java/org/apache/lenya/workflow/impl/BooleanVariableCondition.java
lenya/trunk/src/java/org/apache/lenya/workflow/impl/ConditionFactory.java
lenya/trunk/src/java/org/apache/lenya/workflow/impl/SynchronizedWorkflowInstancesImpl.java
lenya/trunk/src/java/org/apache/lenya/workflow/impl/TransitionImpl.java
lenya/trunk/src/java/org/apache/lenya/workflow/impl/WorkflowBuilder.java
lenya/trunk/src/java/org/apache/lenya/workflow/impl/WorkflowImpl.java
lenya/trunk/src/java/org/apache/lenya/workflow/impl/WorkflowInstanceImpl.java
Modified: lenya/trunk/src/java/org/apache/lenya/cms/ac/workflow/WorkflowAuthorizer.java
Url: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/ac/workflow/WorkflowAuthorizer.java?view=diff&rev=126613&p1=lenya/trunk/src/java/org/apache/lenya/cms/ac/workflow/WorkflowAuthorizer.java&r1=126612&p2=lenya/trunk/src/java/org/apache/lenya/cms/ac/workflow/WorkflowAuthorizer.java&r2=126613
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/ac/workflow/WorkflowAuthorizer.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/ac/workflow/WorkflowAuthorizer.java Thu Jan 27 07:02:08 2005
@@ -32,8 +32,7 @@
import org.apache.lenya.cms.publication.DocumentIdentityMap;
import org.apache.lenya.cms.publication.Publication;
import org.apache.lenya.cms.publication.PublicationFactory;
-import org.apache.lenya.cms.workflow.WorkflowFactory;
-import org.apache.lenya.workflow.Event;
+import org.apache.lenya.cms.workflow.WorkflowResolver;
import org.apache.lenya.workflow.Situation;
import org.apache.lenya.workflow.SynchronizedWorkflowInstances;
@@ -63,6 +62,7 @@
String event = request.getParameter(EVENT_PARAMETER);
SourceResolver resolver = null;
+ WorkflowResolver workflowResolver = null;
if (getLogger().isDebugEnabled()) {
getLogger().debug("Authorizing workflow for event [" + event + "]");
@@ -78,20 +78,19 @@
if (map.getFactory().isDocument(url)) {
Document document = map.getFactory().getFromURL(url);
- WorkflowFactory factory = WorkflowFactory.newInstance();
+ workflowResolver = (WorkflowResolver) this.manager.lookup(WorkflowResolver.ROLE);
- if (factory.hasWorkflow(document)) {
- SynchronizedWorkflowInstances instance = factory
- .buildSynchronizedInstance(document);
+ if (workflowResolver.hasWorkflow(document)) {
+ SynchronizedWorkflowInstances instance = workflowResolver.getSynchronizedInstance(document);
authorized = false;
- Situation situation = WorkflowHelper.buildSituation(request);
- Event[] events = instance.getExecutableEvents(situation);
+ Situation situation = workflowResolver.getSituation();
+ String[] events = instance.getExecutableEvents(situation);
int i = 0;
while (!authorized && (i < events.length)) {
- if (events[i].getName().equals(event)) {
+ if (events[i].equals(event)) {
authorized = true;
}
if (getLogger().isDebugEnabled()) {
@@ -108,6 +107,9 @@
} finally {
if (resolver != null) {
manager.release(resolver);
+ }
+ if (workflowResolver != null) {
+ this.manager.release(workflowResolver);
}
}
}
Modified: lenya/trunk/src/java/org/apache/lenya/cms/ant/InitCopyWorkflowTask.java
Url: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/ant/InitCopyWorkflowTask.java?view=diff&rev=126613&p1=lenya/trunk/src/java/org/apache/lenya/cms/ant/InitCopyWorkflowTask.java&r1=126612&p2=lenya/trunk/src/java/org/apache/lenya/cms/ant/InitCopyWorkflowTask.java&r2=126613
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/ant/InitCopyWorkflowTask.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/ant/InitCopyWorkflowTask.java Thu Jan 27 07:02:08 2005
@@ -21,13 +21,12 @@
import org.apache.lenya.cms.publication.Document;
import org.apache.lenya.cms.publication.DocumentBuildException;
-import org.apache.lenya.cms.publication.DocumentBuilder;
-import org.apache.lenya.cms.publication.Publication;
import org.apache.lenya.cms.site.Label;
import org.apache.lenya.cms.site.tree.SiteTreeNode;
import org.apache.lenya.cms.workflow.WorkflowFactory;
import org.apache.lenya.workflow.Situation;
import org.apache.lenya.workflow.WorkflowException;
+import org.apache.lenya.workflow.WorkflowInstance;
import org.apache.tools.ant.BuildException;
@@ -106,8 +105,12 @@
if (factory.hasWorkflow(document)) {
String[] roles = new String[0];
Situation situation =
- WorkflowFactory.newInstance().buildSituation(roles, getUserId(), getMachineIp());
- WorkflowFactory.initHistory(document, newdocument, situation);
+ factory.buildSituation(roles, getUserId(), getMachineIp());
+
+ WorkflowInstance sourceInstance = factory.buildExistingInstance(document);
+ String workflowName = sourceInstance.getWorkflow().getName();
+ WorkflowInstance destInstance = factory.buildNewInstance(newdocument, workflowName);
+ destInstance.getHistory().initialize(situation);
}
} catch (WorkflowException e) {
throw new BuildException(e);
Modified: lenya/trunk/src/java/org/apache/lenya/cms/ant/InitWorkflowHistoryTask.java
Url: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/ant/InitWorkflowHistoryTask.java?view=diff&rev=126613&p1=lenya/trunk/src/java/org/apache/lenya/cms/ant/InitWorkflowHistoryTask.java&r1=126612&p2=lenya/trunk/src/java/org/apache/lenya/cms/ant/InitWorkflowHistoryTask.java&r2=126613
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/ant/InitWorkflowHistoryTask.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/ant/InitWorkflowHistoryTask.java Thu Jan 27 07:02:08 2005
@@ -24,6 +24,7 @@
import org.apache.lenya.cms.publication.Publication;
import org.apache.lenya.cms.workflow.WorkflowFactory;
import org.apache.lenya.workflow.Situation;
+import org.apache.lenya.workflow.WorkflowInstance;
import org.apache.tools.ant.BuildException;
public class InitWorkflowHistoryTask extends PublicationTask {
@@ -86,7 +87,9 @@
getMachineIp());
DocumentType type = DocumentTypeBuilder.buildDocumentType(getDocumentType(),
getPublication());
- WorkflowFactory.initHistory(document, type.getWorkflowFileName(), situation);
+ WorkflowFactory factory = WorkflowFactory.newInstance();
+ WorkflowInstance instance = factory.buildNewInstance(document, type.getWorkflowFileName());
+ instance.getHistory().initialize(situation);
} catch (Exception e) {
throw new BuildException(e);
}
Modified: lenya/trunk/src/java/org/apache/lenya/cms/ant/MoveDocumentTask.java
Url: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/ant/MoveDocumentTask.java?view=diff&rev=126613&p1=lenya/trunk/src/java/org/apache/lenya/cms/ant/MoveDocumentTask.java&r1=126612&p2=lenya/trunk/src/java/org/apache/lenya/cms/ant/MoveDocumentTask.java&r2=126613
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/ant/MoveDocumentTask.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/ant/MoveDocumentTask.java Thu Jan 27 07:02:08 2005
@@ -27,6 +27,7 @@
import org.apache.lenya.cms.site.tree.SiteTreeNodeVisitor;
import org.apache.lenya.cms.workflow.WorkflowFactory;
import org.apache.lenya.workflow.WorkflowException;
+import org.apache.lenya.workflow.WorkflowInstance;
import org.apache.tools.ant.BuildException;
/**
@@ -35,137 +36,144 @@
*/
public class MoveDocumentTask extends PublicationTask implements SiteTreeNodeVisitor {
- private String firstarea;
- private String firstdocumentid;
- private String secarea;
- private String secdocumentid;
-
- /**
- *
- */
- public MoveDocumentTask() {
- super();
- }
-
- /**
- * @return String The area of the source.
- */
- public String getFirstarea() {
- return firstarea;
- }
-
- /**
- * @return String The document-id corresponding to the source.
- */
- public String getFirstdocumentid() {
- return firstdocumentid;
- }
-
- /**
- * @return String The area of the destination.
- */
- public String getSecarea() {
- return secarea;
- }
-
- /**
- * @return String The document-id corresponding to the destination.
- */
- public String getSecdocumentid() {
- return secdocumentid;
- }
-
- /**
- * @param string
- * The area of the source.
- */
- public void setFirstarea(String string) {
- firstarea = string;
- }
-
- /**
- * @param string
- * The document-id corresponding to the source.
- */
- public void setFirstdocumentid(String string) {
- firstdocumentid = string;
- }
-
- /**
- * @param string
- * The area of the destination.
- */
- public void setSecarea(String string) {
- secarea = string;
- }
-
- /**
- * @param string
- * The document-id corresponding to the destination.
- */
- public void setSecdocumentid(String string) {
- secdocumentid = string;
- }
-
- /**
- * move the workflow files
- *
- * @see org.apache.lenya.cms.site.tree.SiteTreeNodeVisitor#visitSiteTreeNode(org.apache.lenya.cms.site.tree.SiteTreeNode)
- */
- public void visitSiteTreeNode(SiteTreeNode node) {
- Label[] labels = node.getLabels();
- for (int i = 0; i < labels.length; i++) {
- String language = labels[i].getLanguage();
-
- String srcDocumentid = node.getAbsoluteId();
- String destDocumentid = srcDocumentid.replaceFirst(firstdocumentid, secdocumentid);
-
- // TODO: content(fix the build file)
- // TODO: resources (fix the build file)
- // TODO: rcml (fix the build file)
- // TODO: rcbak (fix the build file)
-
- //move workflow
-
- Document document;
- Document newDocument;
- WorkflowFactory factory = WorkflowFactory.newInstance();
-
- log("move workflow history");
- try {
- document = getIdentityMap().getFactory().get(firstarea, srcDocumentid, language);
- newDocument = getIdentityMap().getFactory().get(secarea, destDocumentid, language);
- } catch (DocumentBuildException e) {
- throw new BuildException(e);
- }
- try {
- if (factory.hasWorkflow(document)) {
- WorkflowFactory.moveHistory(document, newDocument);
- }
- } catch (WorkflowException e) {
- throw new BuildException(e);
- }
-
- }
- }
-
- /**
- * @see org.apache.tools.ant.Task#execute()
- */
- public void execute() throws BuildException {
- try {
- log("document id for the source" + this.getFirstdocumentid());
- log("area for the source" + this.getFirstarea());
- log("document id for the destination" + this.getSecdocumentid());
- log("area for the destination" + this.getSecarea());
-
- SiteTree tree = getSiteTree(getFirstarea());
- SiteTreeNode node = tree.getNode(getFirstdocumentid());
-
- node.acceptSubtree(this);
- } catch (Exception e) {
- throw new BuildException(e);
- }
- }
+ private String firstarea;
+ private String firstdocumentid;
+ private String secarea;
+ private String secdocumentid;
+
+ /**
+ *
+ */
+ public MoveDocumentTask() {
+ super();
+ }
+
+ /**
+ * @return String The area of the source.
+ */
+ public String getFirstarea() {
+ return firstarea;
+ }
+
+ /**
+ * @return String The document-id corresponding to the source.
+ */
+ public String getFirstdocumentid() {
+ return firstdocumentid;
+ }
+
+ /**
+ * @return String The area of the destination.
+ */
+ public String getSecarea() {
+ return secarea;
+ }
+
+ /**
+ * @return String The document-id corresponding to the destination.
+ */
+ public String getSecdocumentid() {
+ return secdocumentid;
+ }
+
+ /**
+ * @param string
+ * The area of the source.
+ */
+ public void setFirstarea(String string) {
+ firstarea = string;
+ }
+
+ /**
+ * @param string
+ * The document-id corresponding to the source.
+ */
+ public void setFirstdocumentid(String string) {
+ firstdocumentid = string;
+ }
+
+ /**
+ * @param string
+ * The area of the destination.
+ */
+ public void setSecarea(String string) {
+ secarea = string;
+ }
+
+ /**
+ * @param string
+ * The document-id corresponding to the destination.
+ */
+ public void setSecdocumentid(String string) {
+ secdocumentid = string;
+ }
+
+ /**
+ * move the workflow files
+ *
+ * @see org.apache.lenya.cms.site.tree.SiteTreeNodeVisitor#visitSiteTreeNode(org.apache.lenya.cms.site.tree.SiteTreeNode)
+ */
+ public void visitSiteTreeNode(SiteTreeNode node) {
+ Label[] labels = node.getLabels();
+ for (int i = 0; i < labels.length; i++) {
+ String language = labels[i].getLanguage();
+
+ String srcDocumentid = node.getAbsoluteId();
+ String destDocumentid = srcDocumentid.replaceFirst(firstdocumentid, secdocumentid);
+
+ // TODO: content(fix the build file)
+ // TODO: resources (fix the build file)
+ // TODO: rcml (fix the build file)
+ // TODO: rcbak (fix the build file)
+
+ //move workflow
+
+ Document document;
+ Document newDocument;
+ WorkflowFactory factory = WorkflowFactory.newInstance();
+
+ log("move workflow history");
+ try {
+ document = getIdentityMap().getFactory().get(firstarea, srcDocumentid, language);
+ newDocument = getIdentityMap().getFactory().get(secarea, destDocumentid, language);
+ } catch (DocumentBuildException e) {
+ throw new BuildException(e);
+ }
+ try {
+ if (factory.hasWorkflow(document)) {
+
+ WorkflowInstance sourceInstance = factory.buildExistingInstance(document);
+ String workflowName = sourceInstance.getWorkflow().getName();
+
+ WorkflowInstance destInstance = factory.buildNewInstance(newDocument, workflowName);
+ destInstance.getHistory().replaceWith(sourceInstance.getHistory());
+
+ sourceInstance.getHistory().delete();
+ }
+ } catch (WorkflowException e) {
+ throw new BuildException(e);
+ }
+
+ }
+ }
+
+ /**
+ * @see org.apache.tools.ant.Task#execute()
+ */
+ public void execute() throws BuildException {
+ try {
+ log("document id for the source" + this.getFirstdocumentid());
+ log("area for the source" + this.getFirstarea());
+ log("document id for the destination" + this.getSecdocumentid());
+ log("area for the destination" + this.getSecarea());
+
+ SiteTree tree = getSiteTree(getFirstarea());
+ SiteTreeNode node = tree.getNode(getFirstdocumentid());
+
+ node.acceptSubtree(this);
+ } catch (Exception e) {
+ throw new BuildException(e);
+ }
+ }
}
Modified: lenya/trunk/src/java/org/apache/lenya/cms/ant/MoveWorkflowTask.java
Url: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/ant/MoveWorkflowTask.java?view=diff&rev=126613&p1=lenya/trunk/src/java/org/apache/lenya/cms/ant/MoveWorkflowTask.java&r1=126612&p2=lenya/trunk/src/java/org/apache/lenya/cms/ant/MoveWorkflowTask.java&r2=126613
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/ant/MoveWorkflowTask.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/ant/MoveWorkflowTask.java Thu Jan 27 07:02:08 2005
@@ -25,6 +25,7 @@
import org.apache.lenya.cms.site.tree.SiteTreeNode;
import org.apache.lenya.cms.workflow.WorkflowFactory;
import org.apache.lenya.workflow.WorkflowException;
+import org.apache.lenya.workflow.WorkflowInstance;
import org.apache.tools.ant.BuildException;
/**
@@ -70,7 +71,13 @@
try {
if (factory.hasWorkflow(srcDoc)) {
log("has workflow");
- WorkflowFactory.moveHistory(srcDoc, destDoc);
+ WorkflowInstance sourceInstance = factory.buildExistingInstance(srcDoc);
+ String workflowName = sourceInstance.getWorkflow().getName();
+
+ WorkflowInstance destInstance = factory.buildNewInstance(destDoc, workflowName);
+ destInstance.getHistory().replaceWith(sourceInstance.getHistory());
+
+ sourceInstance.getHistory().delete();
log("workflow moved");
}
} catch (WorkflowException e) {
Modified: lenya/trunk/src/java/org/apache/lenya/cms/cocoon/acting/WorkflowInvokerAction.java
Url: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/cocoon/acting/WorkflowInvokerAction.java?view=diff&rev=126613&p1=lenya/trunk/src/java/org/apache/lenya/cms/cocoon/acting/WorkflowInvokerAction.java&r1=126612&p2=lenya/trunk/src/java/org/apache/lenya/cms/cocoon/acting/WorkflowInvokerAction.java&r2=126613
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/cocoon/acting/WorkflowInvokerAction.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/cocoon/acting/WorkflowInvokerAction.java Thu Jan 27 07:02:08 2005
@@ -23,16 +23,14 @@
import java.util.Map;
import org.apache.avalon.framework.parameters.Parameters;
-import org.apache.cocoon.acting.AbstractAction;
+import org.apache.cocoon.acting.ServiceableAction;
import org.apache.cocoon.environment.Redirector;
import org.apache.cocoon.environment.SourceResolver;
-import org.apache.lenya.cms.cocoon.workflow.WorkflowHelper;
import org.apache.lenya.cms.publication.Document;
import org.apache.lenya.cms.publication.DocumentIdentityMap;
import org.apache.lenya.cms.publication.Publication;
import org.apache.lenya.cms.publication.PublicationFactory;
-import org.apache.lenya.cms.workflow.WorkflowFactory;
-import org.apache.lenya.workflow.Event;
+import org.apache.lenya.cms.workflow.WorkflowResolver;
import org.apache.lenya.workflow.Situation;
import org.apache.lenya.workflow.SynchronizedWorkflowInstances;
@@ -45,7 +43,7 @@
* <li><strong>event: </strong> The event to invoke.</li>
* </ul>
*/
-public class WorkflowInvokerAction extends AbstractAction {
+public class WorkflowInvokerAction extends ServiceableAction {
public static final String AREA = "area";
public static final String DOCUMENT_ID = "document-id";
@@ -77,31 +75,29 @@
Publication pub = pubFactory.getPublication(objectModel);
DocumentIdentityMap map = new DocumentIdentityMap(pub);
Document document = map.getFactory().get(area, documentId, language);
+
+ WorkflowResolver workflowResolver = null;
+
+ try {
+ workflowResolver = (WorkflowResolver) this.manager.lookup(WorkflowResolver.ROLE);
+ if (workflowResolver.hasWorkflow(document)) {
- WorkflowFactory factory = WorkflowFactory.newInstance();
-
- if (factory.hasWorkflow(document)) {
-
- if (getLogger().isDebugEnabled()) {
- getLogger().debug(" Invoking workflow event");
- }
+ if (getLogger().isDebugEnabled()) {
+ getLogger().debug(" Invoking workflow event");
+ }
- SynchronizedWorkflowInstances instance = factory.buildSynchronizedInstance(document);
- Situation situation = WorkflowHelper.buildSituation(objectModel);
- Event[] events = instance.getExecutableEvents(situation);
- Event event = null;
-
- for (int i = 0; i < events.length; i++) {
- if (events[i].getName().equals(eventName)) {
- event = events[i];
+ SynchronizedWorkflowInstances instance = workflowResolver.getSynchronizedInstance(document);
+ Situation situation = workflowResolver.getSituation();
+ instance.invoke(situation, eventName);
+ } else {
+ if (getLogger().isDebugEnabled()) {
+ getLogger().debug(" Document has no workflow.");
}
}
-
- assert event != null;
- instance.invoke(situation, event);
- } else {
- if (getLogger().isDebugEnabled()) {
- getLogger().debug(" Document has no workflow.");
+ }
+ finally {
+ if (resolver != null) {
+ this.manager.release(resolver);
}
}
Modified: lenya/trunk/src/java/org/apache/lenya/cms/cocoon/components/modules/input/WorkflowModule.java
Url: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/cocoon/components/modules/input/WorkflowModule.java?view=diff&rev=126613&p1=lenya/trunk/src/java/org/apache/lenya/cms/cocoon/components/modules/input/WorkflowModule.java&r1=126612&p2=lenya/trunk/src/java/org/apache/lenya/cms/cocoon/components/modules/input/WorkflowModule.java&r2=126613
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/cocoon/components/modules/input/WorkflowModule.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/cocoon/components/modules/input/WorkflowModule.java Thu Jan 27 07:02:08 2005
@@ -23,12 +23,10 @@
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
-import org.apache.cocoon.components.modules.input.AbstractInputModule;
import org.apache.lenya.cms.publication.Document;
import org.apache.lenya.cms.publication.PageEnvelope;
-import org.apache.lenya.cms.publication.PageEnvelopeFactory;
import org.apache.lenya.cms.workflow.CMSHistory;
-import org.apache.lenya.cms.workflow.WorkflowFactory;
+import org.apache.lenya.cms.workflow.WorkflowResolver;
import org.apache.lenya.workflow.WorkflowInstance;
/**
@@ -52,14 +50,15 @@
throws ConfigurationException {
Object value = null;
+ WorkflowResolver resolver = null;
try {
PageEnvelope envelope = getEnvelope(objectModel);
Document document = envelope.getDocument();
- WorkflowFactory factory = WorkflowFactory.newInstance();
- if (factory.hasWorkflow(document)) {
- WorkflowInstance instance = factory.buildInstance(document);
+ resolver = (WorkflowResolver) this.manager.lookup(WorkflowResolver.ROLE);
+ if (resolver.hasWorkflow(document)) {
+ WorkflowInstance instance = resolver.getWorkflowInstance(document);
if (name.equals(STATE)) {
value = instance.getCurrentState().toString();
} else if (name.startsWith(VARIABLE_PREFIX)) {
@@ -69,7 +68,7 @@
value = Boolean.valueOf(instance.getValue(variableName));
}
} else if (name.equals(HISTORY_PATH)) {
- value = ((CMSHistory) WorkflowFactory.getHistory(document)).getHistoryPath();
+ value = ((CMSHistory) instance.getHistory()).getHistoryPath();
} else {
throw new ConfigurationException("The attribute [" + name
+ "] is not supported!");
@@ -79,6 +78,11 @@
throw e;
} catch (Exception e) {
throw new ConfigurationException("Resolving attribute failed: ", e);
+ }
+ finally {
+ if (resolver != null) {
+ this.manager.release(resolver);
+ }
}
return value;
}
Modified: lenya/trunk/src/java/org/apache/lenya/cms/cocoon/flow/FlowHelperImpl.java
Url: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/cocoon/flow/FlowHelperImpl.java?view=diff&rev=126613&p1=lenya/trunk/src/java/org/apache/lenya/cms/cocoon/flow/FlowHelperImpl.java&r1=126612&p2=lenya/trunk/src/java/org/apache/lenya/cms/cocoon/flow/FlowHelperImpl.java&r2=126613
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/cocoon/flow/FlowHelperImpl.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/cocoon/flow/FlowHelperImpl.java Thu Jan 27 07:02:08 2005
@@ -177,7 +177,7 @@
public void triggerWorkflow(FOM_Cocoon cocoon, String event) throws WorkflowException,
PageEnvelopeException, AccessControlException {
final WorkflowDocument wf = (WorkflowDocument) WorkflowFactory.newInstance()
- .buildInstance(getPageEnvelope(cocoon).getDocument());
+ .buildExistingInstance(getPageEnvelope(cocoon).getDocument());
wf.invoke(getSituation(cocoon), event);
}
Modified: lenya/trunk/src/java/org/apache/lenya/cms/cocoon/transformation/WorkflowMenuTransformer.java
Url: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/cocoon/transformation/WorkflowMenuTransformer.java?view=diff&rev=126613&p1=lenya/trunk/src/java/org/apache/lenya/cms/cocoon/transformation/WorkflowMenuTransformer.java&r1=126612&p2=lenya/trunk/src/java/org/apache/lenya/cms/cocoon/transformation/WorkflowMenuTransformer.java&r2=126613
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/cocoon/transformation/WorkflowMenuTransformer.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/cocoon/transformation/WorkflowMenuTransformer.java Thu Jan 27 07:02:08 2005
@@ -26,15 +26,13 @@
import org.apache.cocoon.ProcessingException;
import org.apache.cocoon.environment.SourceResolver;
import org.apache.cocoon.transformation.AbstractSAXTransformer;
-import org.apache.lenya.cms.cocoon.workflow.WorkflowHelper;
import org.apache.lenya.cms.publication.Document;
import org.apache.lenya.cms.publication.DocumentIdentityMap;
import org.apache.lenya.cms.publication.PageEnvelope;
import org.apache.lenya.cms.publication.PageEnvelopeFactory;
import org.apache.lenya.cms.publication.Publication;
import org.apache.lenya.cms.publication.PublicationFactory;
-import org.apache.lenya.cms.workflow.WorkflowFactory;
-import org.apache.lenya.workflow.Event;
+import org.apache.lenya.cms.workflow.WorkflowResolver;
import org.apache.lenya.workflow.Situation;
import org.apache.lenya.workflow.SynchronizedWorkflowInstances;
import org.apache.lenya.workflow.Workflow;
@@ -111,45 +109,53 @@
super.setup(resolver, objectModel, src, parameters);
PageEnvelope envelope = null;
+ WorkflowResolver workflowResolver = null;
try {
PublicationFactory factory = PublicationFactory.getInstance(getLogger());
Publication pub = factory.getPublication(objectModel);
DocumentIdentityMap map = new DocumentIdentityMap(pub);
envelope = PageEnvelopeFactory.getInstance().getPageEnvelope(map, objectModel);
- } catch (Exception e) {
- throw new ProcessingException(e);
- }
- Document document = envelope.getDocument();
- WorkflowFactory factory = WorkflowFactory.newInstance();
+ Document document = envelope.getDocument();
+ workflowResolver = (WorkflowResolver) this.manager.lookup(WorkflowResolver.ROLE);
- setHasWorkflow(factory.hasWorkflow(document));
+ setHasWorkflow(workflowResolver.hasWorkflow(document));
- if (hasWorkflow()) {
- Situation situation = null;
+ if (hasWorkflow()) {
+ Situation situation = null;
- try {
- setInstance(factory.buildSynchronizedInstance(document));
- situation = WorkflowHelper.buildSituation(objectModel);
- } catch (Exception e) {
- throw new ProcessingException(e);
- }
+ try {
+ setInstance(workflowResolver.getSynchronizedInstance(document));
+ situation = workflowResolver.getSituation();
+ } catch (Exception e) {
+ throw new ProcessingException(e);
+ }
- try {
- this.events = getInstance().getExecutableEvents(situation);
+ try {
+ this.events = getInstance().getExecutableEvents(situation);
- if (getLogger().isDebugEnabled()) {
- getLogger().debug("Executable events: ");
- for (int i = 0; i < events.length; i++) {
- getLogger().debug(" [" + events[i] + "]");
+ if (getLogger().isDebugEnabled()) {
+ getLogger().debug("Executable events: ");
+ for (int i = 0; i < events.length; i++) {
+ getLogger().debug(" [" + events[i] + "]");
+ }
}
- }
- } catch (WorkflowException e) {
- throw new ProcessingException(e);
+ } catch (WorkflowException e) {
+ throw new ProcessingException(e);
+ }
}
+
+ } catch (Exception e) {
+ throw new ProcessingException(e);
}
+ finally {
+ if (workflowResolver != null) {
+ this.manager.release(workflowResolver);
+ }
+ }
+
}
private boolean hasWorkflow;
@@ -164,7 +170,7 @@
return instance;
}
- private Event[] events;
+ private String[] events;
/**
* Returns if the events contain a specific event.
@@ -175,7 +181,7 @@
boolean result = false;
for (int i = 0; i < events.length; i++) {
- if (events[i].getName().equals(eventName)) {
+ if (events[i].equals(eventName)) {
result = true;
}
}
Modified: lenya/trunk/src/java/org/apache/lenya/cms/cocoon/workflow/WorkflowHelper.java
Url: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/cocoon/workflow/WorkflowHelper.java?view=diff&rev=126613&p1=lenya/trunk/src/java/org/apache/lenya/cms/cocoon/workflow/WorkflowHelper.java&r1=126612&p2=lenya/trunk/src/java/org/apache/lenya/cms/cocoon/workflow/WorkflowHelper.java&r2=126613
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/cocoon/workflow/WorkflowHelper.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/cocoon/workflow/WorkflowHelper.java Thu Jan 27 07:02:08 2005
@@ -35,6 +35,7 @@
/**
* Workflow helper.
+ * @deprecated Use WorkflowResolver instead.
*/
public class WorkflowHelper {
Modified: lenya/trunk/src/java/org/apache/lenya/cms/publication/task/PublicationTask.java
Url: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/publication/task/PublicationTask.java?view=diff&rev=126613&p1=lenya/trunk/src/java/org/apache/lenya/cms/publication/task/PublicationTask.java&r1=126612&p2=lenya/trunk/src/java/org/apache/lenya/cms/publication/task/PublicationTask.java&r2=126613
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/publication/task/PublicationTask.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/publication/task/PublicationTask.java Thu Jan 27 07:02:08 2005
@@ -40,7 +40,6 @@
import org.apache.lenya.cms.task.ExecutionException;
import org.apache.lenya.cms.task.Task;
import org.apache.lenya.cms.workflow.WorkflowFactory;
-import org.apache.lenya.workflow.Event;
import org.apache.lenya.workflow.Situation;
import org.apache.lenya.workflow.SynchronizedWorkflowInstances;
import org.apache.lenya.workflow.WorkflowException;
@@ -152,7 +151,7 @@
} catch (WorkflowException e) {
throw new ExecutionException(e);
}
- Event event = getExecutableEvent(instance, situation);
+ String event = getExecutableEvent(instance, situation);
if (event == null) {
canFire = false;
@@ -203,12 +202,12 @@
}
Situation situation = factory.buildSituation(getRoleIDs(), userId, machineIp);
- Event event = getExecutableEvent(instance, situation);
+ String event = getExecutableEvent(instance, situation);
assert event != null;
if (log.isDebugEnabled()) {
- log.debug("Invoking event [" + event.getName() + "]");
+ log.debug("Invoking event [" + event + "]");
}
instance.invoke(situation, event);
if (log.isDebugEnabled()) {
@@ -235,13 +234,13 @@
* @throws ParameterException when the {@link #PARAMETER_WORKFLOW_EVENT}
* parameter could not be resolved.
*/
- protected Event getExecutableEvent(SynchronizedWorkflowInstances instance, Situation situation)
+ protected String getExecutableEvent(SynchronizedWorkflowInstances instance, Situation situation)
throws WorkflowException, ParameterException {
String workflowEvent = getEventName();
- Event event = null;
- Event[] events = instance.getExecutableEvents(situation);
+ String event = null;
+ String[] events = instance.getExecutableEvents(situation);
if (log.isDebugEnabled()) {
log.debug("Workflow event name: [" + workflowEvent + "]");
@@ -249,7 +248,7 @@
}
for (int i = 0; i < events.length; i++) {
- if (events[i].getName().equals(workflowEvent)) {
+ if (events[i].equals(workflowEvent)) {
event = events[i];
}
}
Modified: lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/Create.java
Url: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/Create.java?view=diff&rev=126613&p1=lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/Create.java&r1=126612&p2=lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/Create.java&r2=126613
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/Create.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/Create.java Thu Jan 27 07:02:08 2005
@@ -29,12 +29,10 @@
import org.apache.lenya.cms.metadata.dublincore.DublinCore;
import org.apache.lenya.cms.publication.Document;
import org.apache.lenya.cms.publication.DocumentException;
-import org.apache.lenya.cms.publication.DocumentType;
-import org.apache.lenya.cms.publication.DocumentTypeBuilder;
import org.apache.lenya.cms.publication.Publication;
import org.apache.lenya.cms.site.SiteManager;
import org.apache.lenya.cms.usecase.DocumentUsecase;
-import org.apache.lenya.cms.workflow.WorkflowFactory;
+import org.apache.lenya.workflow.WorkflowInstance;
/**
* Abstract superclass for usecases to create a resource.
@@ -80,16 +78,13 @@
Document document = createDocument();
Publication publication = document.getPublication();
- String documentTypeName = getDocumentTypeName();
-
- DocumentType documentType = DocumentTypeBuilder.buildDocumentType(documentTypeName,
- publication);
SiteManager manager = publication.getSiteManager(document.getIdentityMap());
manager.add(document);
manager.setLabel(document, getParameterAsString(DublinCore.ELEMENT_TITLE));
- WorkflowFactory.initHistory(document, documentType.getWorkflowFileName(), getSituation());
+ WorkflowInstance instance = getWorkflowInstance(document);
+ instance.getHistory().initialize(getSituation());
setMetaData(document);
setTargetDocument(document);
Modified: lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/DeleteLanguage.java
Url: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/DeleteLanguage.java?view=diff&rev=126613&p1=lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/DeleteLanguage.java&r1=126612&p2=lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/DeleteLanguage.java&r2=126613
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/DeleteLanguage.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/DeleteLanguage.java Thu Jan 27 07:02:08 2005
@@ -20,7 +20,6 @@
import org.apache.lenya.cms.publication.util.DocumentHelper;
import org.apache.lenya.cms.site.SiteManager;
import org.apache.lenya.cms.usecase.DocumentUsecase;
-import org.apache.lenya.cms.workflow.WorkflowFactory;
/**
* Delete a language version.
@@ -52,9 +51,8 @@
document.getFile().delete();
- WorkflowFactory workflowFactory = WorkflowFactory.newInstance();
- if (workflowFactory.hasWorkflow(document)) {
- WorkflowFactory.getHistory(document).delete();
+ if (hasWorkflow(document)) {
+ getWorkflowInstance(document).getHistory().delete();
}
setTargetDocument(DocumentHelper.getExistingLanguageVersion(document));
Modified: lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/SiteUsecase.java
Url: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/SiteUsecase.java?view=diff&rev=126613&p1=lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/SiteUsecase.java&r1=126612&p2=lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/SiteUsecase.java&r2=126613
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/SiteUsecase.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/SiteUsecase.java Thu Jan 27 07:02:08 2005
@@ -20,7 +20,6 @@
import org.apache.lenya.cms.publication.Document;
import org.apache.lenya.cms.usecase.DocumentUsecase;
-import org.apache.lenya.cms.workflow.WorkflowFactory;
import org.apache.lenya.workflow.WorkflowInstance;
/**
@@ -53,9 +52,8 @@
super.doInitialize();
doc = getSourceDocument();
try {
- WorkflowFactory factory = WorkflowFactory.newInstance();
- if (factory.hasWorkflow(getSourceDocument())) {
- instance = factory.buildInstance(getSourceDocument());
+ if (hasWorkflow(getSourceDocument())) {
+ instance = getWorkflowInstance(getSourceDocument());
setParameter(STATE, instance.getCurrentState().toString());
String[] variableNames = instance.getWorkflow().getVariableNames();
if (Arrays.asList(variableNames).contains(ISLIVE)) {
Modified: lenya/trunk/src/java/org/apache/lenya/cms/task/WorkflowInvoker.java
Url: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/task/WorkflowInvoker.java?view=diff&rev=126613&p1=lenya/trunk/src/java/org/apache/lenya/cms/task/WorkflowInvoker.java&r1=126612&p2=lenya/trunk/src/java/org/apache/lenya/cms/task/WorkflowInvoker.java&r2=126613
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/task/WorkflowInvoker.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/task/WorkflowInvoker.java Thu Jan 27 07:02:08 2005
@@ -29,7 +29,6 @@
import org.apache.lenya.cms.publication.Publication;
import org.apache.lenya.cms.workflow.WorkflowFactory;
import org.apache.lenya.util.NamespaceMap;
-import org.apache.lenya.workflow.Event;
import org.apache.lenya.workflow.Situation;
import org.apache.lenya.workflow.SynchronizedWorkflowInstances;
import org.apache.log4j.Category;
@@ -197,21 +196,8 @@
Situation situation = factory.buildSituation(getRoleIDs(), getUserId(),
getMachineIp());
- Event event = null;
- Event[] events = instance.getExecutableEvents(situation);
-
- log.debug("Resolved executable events.");
-
- for (int i = 0; i < events.length; i++) {
- if (events[i].getName().equals(getEventName())) {
- event = events[i];
- }
- }
-
- assert event != null;
-
log.debug("Invoking transition.");
- instance.invoke(situation, event);
+ instance.invoke(situation, getEventName());
log.debug("Invoking transition completed.");
} catch (Exception e) {
Modified: lenya/trunk/src/java/org/apache/lenya/cms/usecase/DocumentUsecase.java
Url: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/usecase/DocumentUsecase.java?view=diff&rev=126613&p1=lenya/trunk/src/java/org/apache/lenya/cms/usecase/DocumentUsecase.java&r1=126612&p2=lenya/trunk/src/java/org/apache/lenya/cms/usecase/DocumentUsecase.java&r2=126613
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/usecase/DocumentUsecase.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/usecase/DocumentUsecase.java Thu Jan 27 07:02:08 2005
@@ -134,15 +134,6 @@
}
/**
- * Checks if an event can be executed on the source document.
- * @param event The event.
- * @return A boolean value.
- */
- protected boolean canExecuteWorkflow(String event) {
- return canExecuteWorkflow(event, getSourceDocument());
- }
-
- /**
* @see org.apache.lenya.cms.usecase.AbstractUsecase#initParameters()
*/
protected void initParameters() {
Modified: lenya/trunk/src/java/org/apache/lenya/cms/usecase/WorkflowUsecase.java
Url: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/usecase/WorkflowUsecase.java?view=diff&rev=126613&p1=lenya/trunk/src/java/org/apache/lenya/cms/usecase/WorkflowUsecase.java&r1=126612&p2=lenya/trunk/src/java/org/apache/lenya/cms/usecase/WorkflowUsecase.java&r2=126613
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/usecase/WorkflowUsecase.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/usecase/WorkflowUsecase.java Thu Jan 27 07:02:08 2005
@@ -21,11 +21,11 @@
import java.util.Map;
+import org.apache.avalon.framework.service.ServiceException;
import org.apache.cocoon.components.ContextHelper;
import org.apache.lenya.cms.cocoon.workflow.WorkflowHelper;
import org.apache.lenya.cms.publication.Document;
-import org.apache.lenya.cms.workflow.WorkflowFactory;
-import org.apache.lenya.workflow.Event;
+import org.apache.lenya.cms.workflow.WorkflowResolver;
import org.apache.lenya.workflow.Situation;
import org.apache.lenya.workflow.WorkflowException;
import org.apache.lenya.workflow.WorkflowInstance;
@@ -65,13 +65,7 @@
protected void triggerWorkflow(String event, Document document) {
try {
WorkflowInstance instance = getWorkflowInstance(document);
- Event executableEvent = getExecutableEvent(event, document);
-
- if (executableEvent == null) {
- throw new RuntimeException("The event [" + event
- + "] is not executable on document [" + document + "]");
- }
- instance.invoke(getSituation(), executableEvent);
+ instance.invoke(getSituation(), event);
} catch (WorkflowException e) {
throw new RuntimeException(e);
}
@@ -84,41 +78,45 @@
* @throws WorkflowException if an error occurs.
*/
protected WorkflowInstance getWorkflowInstance(Document document) throws WorkflowException {
- WorkflowFactory factory = WorkflowFactory.newInstance();
- WorkflowInstance instance = factory.buildInstance(document);
- return instance;
- }
-
- /**
- * Returns the event object if an event is exectuable.
- * @param document The document.
- * @param event The name of the event.
- * @return An event or <code>null</code> if the event is not executable.
- */
- protected Event getExecutableEvent(String event, Document document) {
- Event[] events;
+
+ WorkflowInstance instance = null;
+ WorkflowResolver resolver = null;
try {
- events = getWorkflowInstance(document).getExecutableEvents(getSituation());
- } catch (WorkflowException e) {
- throw new RuntimeException(e);
+ resolver = (WorkflowResolver) manager.lookup(WorkflowResolver.ROLE);
+ instance = resolver.getWorkflowInstance(document);
+ } catch (ServiceException e) {
+ throw new WorkflowException(e);
}
- Event executableEvent = null;
- for (int i = 0; i < events.length; i++) {
- if (events[i].getName().equals(event)) {
- executableEvent = events[i];
+ finally {
+ if (resolver != null) {
+ this.manager.release(resolver);
}
}
- return executableEvent;
+ return instance;
}
/**
- * Checks if a certain event can be executed on a workflow instance.
+ * Returns if a document has a workflow.
* @param document The document.
- * @param event The event.
* @return A boolean value.
+ * @throws WorkflowException if an error occurs.
*/
- protected boolean canExecuteWorkflow(String event, Document document) {
- return getExecutableEvent(event, document) != null;
+ protected boolean hasWorkflow(Document document) throws WorkflowException {
+
+ boolean hasWorkflow = false;
+ WorkflowResolver resolver = null;
+ try {
+ resolver = (WorkflowResolver) manager.lookup(WorkflowResolver.ROLE);
+ hasWorkflow = resolver.hasWorkflow(document);
+ } catch (ServiceException e) {
+ throw new WorkflowException(e);
+ }
+ finally {
+ if (resolver != null) {
+ this.manager.release(resolver);
+ }
+ }
+ return hasWorkflow;
}
}
Modified: lenya/trunk/src/java/org/apache/lenya/cms/workflow/CMSHistory.java
Url: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/workflow/CMSHistory.java?view=diff&rev=126613&p1=lenya/trunk/src/java/org/apache/lenya/cms/workflow/CMSHistory.java&r1=126612&p2=lenya/trunk/src/java/org/apache/lenya/cms/workflow/CMSHistory.java&r2=126613
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/workflow/CMSHistory.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/workflow/CMSHistory.java Thu Jan 27 07:02:08 2005
@@ -1,52 +1,50 @@
/*
- * Copyright 1999-2004 The Apache Software Foundation
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
+ * Copyright 1999-2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ *
*/
-/* $Id$ */
+/* $Id$ */
package org.apache.lenya.cms.workflow;
import java.io.File;
-import org.apache.avalon.excalibur.io.FileUtil;
import org.apache.lenya.cms.publication.Document;
import org.apache.lenya.cms.publication.DocumentIdToPathMapper;
import org.apache.lenya.cms.publication.Publication;
+import org.apache.lenya.workflow.History;
import org.apache.lenya.workflow.Situation;
import org.apache.lenya.workflow.WorkflowException;
-import org.apache.lenya.workflow.impl.History;
+import org.apache.lenya.workflow.impl.HistoryImpl;
import org.apache.lenya.workflow.impl.Version;
-import org.apache.lenya.workflow.impl.WorkflowInstanceImpl;
import org.apache.lenya.xml.NamespaceHelper;
import org.w3c.dom.Element;
-public class CMSHistory extends History {
+public class CMSHistory extends HistoryImpl {
public static final String HISTORY_PATH = "content/workflow/history";
/**
* Creates a new CMSHistory object.
*
- * @param document the document to which the CMSHistory is attached
+ * @param workflowDocument the document to which the CMSHistory is attached
+ * @throws WorkflowException if an error occurs.
*/
- protected CMSHistory(Document document) {
- setDocument(document);
+ protected CMSHistory(WorkflowDocument workflowDocument) throws WorkflowException {
+ super(workflowDocument);
}
- private Document document;
-
public static final String IDENTITY_ELEMENT = "identity";
public static final String USER_ELEMENT = "user";
public static final String MACHINE_ELEMENT = "machine";
@@ -55,7 +53,8 @@
public static final String IP_ATTRIBUTE = "ip-address";
/**
- * @see org.apache.lenya.workflow.impl.History#createVersionElement(org.apache.lenya.xml.NamespaceHelper, org.apache.lenya.workflow.Situation)
+ * @see org.apache.lenya.workflow.impl.HistoryImpl#createVersionElement(org.apache.lenya.xml.NamespaceHelper,
+ * org.apache.lenya.workflow.Situation)
*/
protected Element createVersionElement(NamespaceHelper helper, Situation situation) {
Element element = super.createVersionElement(helper, situation);
@@ -106,10 +105,12 @@
/**
* Returns the path of the history file inside the publication directory.
- * @param document A CMS document.
* @return A string.
*/
- public String getHistoryPath(Document document) {
+ public String getHistoryPath() {
+
+ Document document = ((WorkflowDocument) getInstance()).getDocument();
+
DocumentIdToPathMapper pathMapper = document.getPublication().getPathMapper();
String documentPath = pathMapper.getPath(document.getId(), document.getLanguage());
@@ -124,77 +125,42 @@
}
/**
- * @see org.apache.lenya.workflow.impl.History#getHistoryFile()
+ * @see org.apache.lenya.workflow.impl.HistoryImpl#getHistoryFile()
*/
protected File getHistoryFile() {
- return getHistoryFile(getDocument());
- }
-
- /**
- * Returns the history file for a certain document.
- * @param document The document.
- * @return A file.
- */
- protected File getHistoryFile(Document document) {
- File historyFile =
- new File(document.getPublication().getDirectory(), getHistoryPath(document));
+ WorkflowDocument document = (WorkflowDocument) getInstance();
+ File historyFile = new File(document.getDocument().getPublication().getDirectory(),
+ getHistoryPath());
return historyFile;
}
/**
- * @see org.apache.lenya.workflow.impl.History#createInstance()
- */
- protected WorkflowInstanceImpl createInstance() throws WorkflowException {
- return new WorkflowDocument(getDocument());
- }
-
- /**
- * Get the document
- *
- * @return the Document
- */
- public Document getDocument() {
- return document;
- }
-
- /**
- * Set the document
- *
- * @param document the document
- */
- public void setDocument(Document document) {
- this.document = document;
- }
-
- /**
* Initializes the workflow history of another document using the same
* workflow schema like this history.
* @param newDocument The document to initialize the history for.
* @param situation The current situation.
* @throws WorkflowException when something went wrong.
*/
- protected void initialize(Document newDocument, Situation situation) throws WorkflowException {
- String workflowId = getWorkflowId();
+ protected void initialize(WorkflowDocument newDocument, Situation situation)
+ throws WorkflowException {
CMSHistory newHistory = new CMSHistory(newDocument);
- newHistory.initialize(workflowId, situation);
+ newHistory.initialize(situation);
}
/**
- * Moves this history to a new document.
- * @param newDocument The new document.
- * @throws WorkflowException when something went wrong.
+ * @see org.apache.lenya.workflow.History#replaceWith(org.apache.lenya.workflow.History)
*/
- protected void move(Document newDocument) throws WorkflowException {
- assert newDocument != null;
- move(getHistoryFile(newDocument));
- setDocument(newDocument);
+ public void replaceWith(History otherHistory) throws WorkflowException {
+ CMSHistory history = (CMSHistory) otherHistory;
+ history.copy(getHistoryFile());
}
/**
- * @see org.apache.lenya.workflow.impl.History#restoreVersion(NamespaceHelper, org.w3c.dom.Element)
+ * @see org.apache.lenya.workflow.impl.HistoryImpl#restoreVersion(NamespaceHelper,
+ * org.w3c.dom.Element)
*/
protected Version restoreVersion(NamespaceHelper helper, Element element)
- throws WorkflowException {
+ throws WorkflowException {
Version version = super.restoreVersion(helper, element);
CMSVersion cmsVersion = new CMSVersion(version.getEvent(), version.getState());
@@ -209,33 +175,26 @@
}
/**
- * Returns the history path of this history.
- * @return A string.
- */
- public String getHistoryPath() {
- return getHistoryPath(getDocument());
- }
-
- /**
- * Additionally to deleting the workflow history, the parent directories
- * are deleted up to the workflow history directory.
- * @see org.apache.lenya.workflow.impl.History#delete()
+ * Additionally to deleting the workflow history, the parent directories are
+ * deleted up to the workflow history directory.
+ * @see org.apache.lenya.workflow.impl.HistoryImpl#delete()
*/
public void delete() throws WorkflowException {
super.delete();
-
- File stopDirectory = new File(getDocument().getPublication().getDirectory(), HISTORY_PATH);
+
+ Document document = ((WorkflowDocument) getInstance()).getDocument();
+ File stopDirectory = new File(document.getPublication().getDirectory(), HISTORY_PATH);
if (!stopDirectory.isDirectory())
throw new WorkflowException("Stop dir '" + stopDirectory.getAbsolutePath()
+ "' is not a directory");
if (!getHistoryFile().getAbsolutePath().startsWith(stopDirectory.getAbsolutePath()))
throw new WorkflowException("Start dir '" + getHistoryFile().getAbsolutePath()
- + "' is not a descending sibling of stop directory '" + stopDirectory.getAbsolutePath()
- + "'.");
+ + "' is not a descending sibling of stop directory '"
+ + stopDirectory.getAbsolutePath() + "'.");
File parent = getHistoryFile().getParentFile();
while (!parent.equals(stopDirectory) && parent.delete())
parent = parent.getParentFile();
}
-}
+}
\ No newline at end of file
Modified: lenya/trunk/src/java/org/apache/lenya/cms/workflow/WorkflowDocument.java
Url: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/workflow/WorkflowDocument.java?view=diff&rev=126613&p1=lenya/trunk/src/java/org/apache/lenya/cms/workflow/WorkflowDocument.java&r1=126612&p2=lenya/trunk/src/java/org/apache/lenya/cms/workflow/WorkflowDocument.java&r2=126613
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/workflow/WorkflowDocument.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/workflow/WorkflowDocument.java Thu Jan 27 07:02:08 2005
@@ -20,22 +20,26 @@
package org.apache.lenya.cms.workflow;
import org.apache.lenya.cms.publication.Document;
-import org.apache.lenya.workflow.Event;
-import org.apache.lenya.workflow.Situation;
+import org.apache.lenya.workflow.History;
import org.apache.lenya.workflow.WorkflowException;
import org.apache.lenya.workflow.impl.WorkflowImpl;
import org.apache.lenya.workflow.impl.WorkflowInstanceImpl;
+/**
+ * Workflow instance for CMS documents.
+ *
+ * @version $Id:$
+ */
public class WorkflowDocument extends WorkflowInstanceImpl {
/**
- * Create a new <code>WorkflowDocument</code>
- *
+ * Ctor.
+ * @param workflow The workflow.
* @param document the document
- *
- * @throws WorkflowException if an error occurs
+ * @throws WorkflowException if an error occurs.
*/
- protected WorkflowDocument(Document document) throws WorkflowException {
+ protected WorkflowDocument(WorkflowImpl workflow, Document document) throws WorkflowException {
+ super(workflow);
assert document != null;
this.document = document;
}
@@ -49,32 +53,20 @@
public Document getDocument() {
return document;
}
+
+ private History history;
/**
- * DOCUMENT ME!
- *
- * @param situation DOCUMENT ME!
- * @param eventName DOCUMENT ME!
- *
- * @throws WorkflowException DOCUMENT ME!
+ * @see org.apache.lenya.workflow.WorkflowInstance#getHistory()
*/
- public void invoke(Situation situation, String eventName)
- throws WorkflowException {
- assert eventName != null;
-
- Event event = ((WorkflowImpl) getWorkflow()).getEvent(eventName);
- invoke(situation, event);
- }
-
- /** (non-Javadoc)
- * @see org.apache.lenya.workflow.impl.WorkflowInstanceImpl#getWorkflow(java.lang.String)
- */
- protected WorkflowImpl getWorkflow(String workflowName)
- throws WorkflowException {
- assert workflowName != null && !"".equals(workflowName);
- WorkflowImpl workflow = (WorkflowImpl) WorkflowFactory.buildWorkflow(document.getPublication(),
- workflowName);
-
- return workflow;
+ public History getHistory() {
+ try {
+ if (this.history == null) {
+ this.history = new CMSHistory(this);
+ }
+ } catch (WorkflowException e) {
+ throw new RuntimeException(e);
+ }
+ return this.history;
}
}
Modified: lenya/trunk/src/java/org/apache/lenya/cms/workflow/WorkflowFactory.java
Url: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/workflow/WorkflowFactory.java?view=diff&rev=126613&p1=lenya/trunk/src/java/org/apache/lenya/cms/workflow/WorkflowFactory.java&r1=126612&p2=lenya/trunk/src/java/org/apache/lenya/cms/workflow/WorkflowFactory.java&r2=126613
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/workflow/WorkflowFactory.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/workflow/WorkflowFactory.java Thu Jan 27 07:02:08 2005
@@ -21,28 +21,33 @@
import java.io.File;
+import org.apache.avalon.framework.container.ContainerUtil;
+import org.apache.avalon.framework.logger.ConsoleLogger;
import org.apache.lenya.ac.Identity;
import org.apache.lenya.ac.Machine;
import org.apache.lenya.ac.Role;
import org.apache.lenya.ac.User;
import org.apache.lenya.cms.publication.Document;
import org.apache.lenya.cms.publication.DocumentException;
+import org.apache.lenya.cms.publication.DocumentIdToPathMapper;
import org.apache.lenya.cms.publication.Publication;
import org.apache.lenya.cms.publication.util.LanguageVersions;
import org.apache.lenya.workflow.Situation;
import org.apache.lenya.workflow.SynchronizedWorkflowInstances;
-import org.apache.lenya.workflow.Workflow;
import org.apache.lenya.workflow.WorkflowException;
import org.apache.lenya.workflow.WorkflowInstance;
-import org.apache.lenya.workflow.impl.History;
+import org.apache.lenya.workflow.impl.HistoryImpl;
+import org.apache.lenya.workflow.impl.SynchronizedWorkflowInstancesImpl;
import org.apache.lenya.workflow.impl.WorkflowBuilder;
+import org.apache.lenya.workflow.impl.WorkflowImpl;
+import org.apache.lenya.xml.DocumentHelper;
+import org.w3c.dom.Element;
/**
* Workflow factory.
+ * @deprecated Use WorkflowResolver instead.
*/
public class WorkflowFactory {
- public static final String WORKFLOW_DIRECTORY =
- "config/workflow".replace('/', File.separatorChar);
/** Creates a new instance of WorkflowFactory */
protected WorkflowFactory() {
@@ -62,9 +67,48 @@
* @return A workflow instance.
* @throws WorkflowException when something went wrong.
*/
- public WorkflowInstance buildInstance(Document document) throws WorkflowException {
- assert document != null;
- return getHistory(document).getInstance();
+ public WorkflowInstance buildExistingInstance(Document document) throws WorkflowException {
+
+ File file = getHistoryFile(document);
+ WorkflowDocument workflowDocument = null;
+
+ if (file.exists()) {
+ org.w3c.dom.Document xml;
+ try {
+ xml = DocumentHelper.readDocument(file);
+ } catch (Exception e) {
+ throw new WorkflowException(e);
+ }
+
+ Element documentElement = xml.getDocumentElement();
+ String workflowName = documentElement.getAttribute(HistoryImpl.WORKFLOW_ATTRIBUTE);
+
+ workflowDocument = (WorkflowDocument) buildNewInstance(document, workflowName);
+ }
+
+ return workflowDocument;
+ }
+
+ /**
+ * Creates a new workflow instance.
+ * @param document The document to create the instance for.
+ * @param workflowName The name of the workflow.
+ * @return A workflow instance.
+ * @throws WorkflowException when something went wrong.
+ */
+ public WorkflowInstance buildNewInstance(Document document, String workflowName)
+ throws WorkflowException {
+
+ File workflowDirectory = new File(document.getPublication().getDirectory(),
+ WorkflowResolverImpl.WORKFLOW_DIRECTORY);
+ File workflowFile = new File(workflowDirectory, workflowName);
+
+ WorkflowBuilder builder = new WorkflowBuilder(new ConsoleLogger());
+ WorkflowImpl workflow = builder.buildWorkflow(workflowName, workflowFile);
+
+ WorkflowDocument workflowDocument = new WorkflowDocument(workflow, document);
+ ContainerUtil.enableLogging(workflowDocument, new ConsoleLogger());
+ return workflowDocument;
}
/**
@@ -73,7 +117,8 @@
* @return A synchronized workflow instances object.
* @throws WorkflowException when something went wrong.
*/
- public SynchronizedWorkflowInstances buildSynchronizedInstance(Document document) throws WorkflowException {
+ public SynchronizedWorkflowInstances buildSynchronizedInstance(Document document)
+ throws WorkflowException {
assert document != null;
LanguageVersions versions;
try {
@@ -81,18 +126,17 @@
} catch (DocumentException e) {
throw new WorkflowException(e);
}
- return new WorkflowDocumentSet(versions, document);
- }
- /**
- * Moves the history of a document.
- * @param oldDocument The document to move the instance for.
- * @param newDocument The new document.
- * @throws WorkflowException when something went wrong.
- */
- public static void moveHistory(Document oldDocument, Document newDocument) throws WorkflowException {
- assert oldDocument != null;
- new CMSHistory(oldDocument).move(newDocument);
+ Document[] documents = versions.getDocuments();
+ WorkflowInstance[] instances = new WorkflowInstance[documents.length];
+ for (int i = 0; i < documents.length; i++) {
+ instances[i] = buildExistingInstance(documents[i]);
+ }
+
+ SynchronizedWorkflowInstances set = new SynchronizedWorkflowInstancesImpl(instances,
+ buildExistingInstance(document));
+ ContainerUtil.enableLogging(set, new ConsoleLogger());
+ return set;
}
/**
@@ -102,36 +146,19 @@
*/
public static void deleteHistory(Document document) throws WorkflowException {
assert document != null;
- getHistory(document).delete();
+ WorkflowInstance instance = WorkflowFactory.newInstance().buildExistingInstance(document);
+ instance.getHistory().delete();
}
/**
- * Checks if a workflow is assigned to the document.
- * This is done by looking for the workflow history file.
+ * Checks if a workflow is assigned to the document. This is done by looking
+ * for the workflow history file.
* @param document The document to check.
- * @return <code>true</code> if the document has a workflow, <code>false</code> otherwise.
+ * @return <code>true</code> if the document has a workflow,
+ * <code>false</code> otherwise.
*/
public boolean hasWorkflow(Document document) {
- return getHistory(document).isInitialized();
- }
-
- /**
- * Builds a workflow for a given publication.
- * @param publication The publication.
- * @param workflowFileName The workflow definition filename.
- * @return A workflow object.
- * @throws WorkflowException when something went wrong.
- */
- protected static Workflow buildWorkflow(Publication publication, String workflowFileName)
- throws WorkflowException {
- assert publication != null;
- assert(workflowFileName != null) && !"".equals(workflowFileName);
-
- File workflowDirectory = new File(publication.getDirectory(), WORKFLOW_DIRECTORY);
- File workflowFile = new File(workflowDirectory, workflowFileName);
- Workflow workflow = WorkflowBuilder.buildWorkflow(workflowFile);
-
- return workflow;
+ return getHistoryFile(document).exists();
}
/**
@@ -150,23 +177,24 @@
if (user != null) {
userId = user.getId();
}
-
+
String machineIp = null;
Machine machine = identity.getMachine();
if (machine != null) {
machineIp = machine.getIp();
}
-
+
String[] roleIds = new String[roles.length];
for (int i = 0; i < roles.length; i++) {
roleIds[i] = roles[i].getId();
}
-
+
return buildSituation(roleIds, userId, machineIp);
}
/**
- * Builds a situation from a role name set, a user ID and a machine IP address.
+ * Builds a situation from a role name set, a user ID and a machine IP
+ * address.
* @param roleIds The role IDs.
* @param userId The user ID.
* @param machineIp The machine IP address.
@@ -177,36 +205,34 @@
}
/**
- * Initializes the history of a document.
- * @param document The document object.
- * @param workflowId The ID of the workflow.
- * @param situation The current situation.
- * @throws WorkflowException When something goes wrong.
- */
- public static void initHistory(Document document, String workflowId, Situation situation) throws WorkflowException {
- new CMSHistory(document).initialize(workflowId, situation);
- }
-
- /**
- * Returns the workflow history of a document.
- * @param document A document.
- * @return A workflow history.
- */
- public static History getHistory(Document document) {
- return new CMSHistory(document);
+ * Returns the path of the history file inside the publication directory.
+ * @param document The document.
+ * @return A string.
+ */
+ public String getHistoryPath(Document document) {
+
+ DocumentIdToPathMapper pathMapper = document.getPublication().getPathMapper();
+ String documentPath = pathMapper.getPath(document.getId(), document.getLanguage());
+
+ String area = document.getArea();
+ if (!area.equals(Publication.ARCHIVE_AREA) && !area.equals(Publication.TRASH_AREA)) {
+ area = Publication.AUTHORING_AREA;
+ }
+
+ String path = CMSHistory.HISTORY_PATH + "/" + area + "/" + documentPath;
+ path = path.replace('/', File.separatorChar);
+ return path;
}
/**
- * Initializes the workflow history of a document that is a copy of
- * another document.
- * @param sourceDocument The original document.
- * @param destinationDocument The document to initialize the history for.
- * @throws WorkflowException When something goes wrong.
+ * Returns the CMS history file of a document.
+ * @param document The document.
+ * @return A file.
+ * @deprecated Use WorkflowResolver instead.
*/
- public static void initHistory(Document sourceDocument, Document destinationDocument, Situation situation)
- throws WorkflowException {
- CMSHistory history = new CMSHistory(sourceDocument);
- history.initialize(destinationDocument, situation);
+ protected File getHistoryFile(Document document) {
+ File historyFile = new File(document.getPublication().getDirectory(),
+ getHistoryPath(document));
+ return historyFile;
}
-
-}
+}
\ No newline at end of file
Added: lenya/trunk/src/java/org/apache/lenya/cms/workflow/WorkflowResolver.java
Url: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/workflow/WorkflowResolver.java?view=auto&rev=126613
==============================================================================
--- (empty file)
+++ lenya/trunk/src/java/org/apache/lenya/cms/workflow/WorkflowResolver.java Thu Jan 27 07:02:08 2005
@@ -0,0 +1,66 @@
+/*
+ * Copyright 1999-2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.lenya.cms.workflow;
+
+import org.apache.lenya.cms.publication.Document;
+import org.apache.lenya.workflow.Situation;
+import org.apache.lenya.workflow.SynchronizedWorkflowInstances;
+import org.apache.lenya.workflow.WorkflowException;
+import org.apache.lenya.workflow.WorkflowInstance;
+
+/**
+ * Class to resolve workflow-related objects.
+ *
+ * @version $Id:$
+ */
+public interface WorkflowResolver {
+
+ /**
+ * The Avalon component role.
+ */
+ String ROLE = WorkflowResolver.class.getName();
+
+ /**
+ * Checks if a document has a workflow.
+ * @param document The document.
+ * @return A boolean value.
+ */
+ boolean hasWorkflow(Document document);
+
+ /**
+ * Resolves the workflow instance of a document.
+ * @param document The document.
+ * @return A workflow instance.
+ * @throws WorkflowException if the document has no workflow.
+ */
+ WorkflowInstance getWorkflowInstance(Document document) throws WorkflowException;
+
+ /**
+ * Resolves the current workflow situation.
+ * @return A situation object.
+ */
+ Situation getSituation();
+
+ /**
+ * Creates a new synchronized workflow instances object..
+ * @param document The document to create the instances for.
+ * @return A synchronized workflow instances object.
+ * @throws WorkflowException when something went wrong.
+ */
+ SynchronizedWorkflowInstances getSynchronizedInstance(Document document)
+ throws WorkflowException;
+}
\ No newline at end of file
Added: lenya/trunk/src/java/org/apache/lenya/cms/workflow/WorkflowResolverImpl.java
Url: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/workflow/WorkflowResolverImpl.java?view=auto&rev=126613
==============================================================================
--- (empty file)
+++ lenya/trunk/src/java/org/apache/lenya/cms/workflow/WorkflowResolverImpl.java Thu Jan 27 07:02:08 2005
@@ -0,0 +1,205 @@
+/*
+ * Copyright 1999-2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.lenya.cms.workflow;
+
+import java.io.File;
+import java.util.Map;
+
+import org.apache.avalon.framework.container.ContainerUtil;
+import org.apache.avalon.framework.context.Context;
+import org.apache.avalon.framework.context.ContextException;
+import org.apache.avalon.framework.context.Contextualizable;
+import org.apache.avalon.framework.logger.AbstractLogEnabled;
+import org.apache.avalon.framework.logger.ConsoleLogger;
+import org.apache.avalon.framework.service.ServiceException;
+import org.apache.avalon.framework.service.ServiceManager;
+import org.apache.avalon.framework.service.Serviceable;
+import org.apache.cocoon.components.ContextHelper;
+import org.apache.cocoon.environment.ObjectModelHelper;
+import org.apache.cocoon.environment.Request;
+import org.apache.cocoon.environment.Session;
+import org.apache.lenya.ac.AccessControlException;
+import org.apache.lenya.ac.Identity;
+import org.apache.lenya.ac.Machine;
+import org.apache.lenya.ac.Role;
+import org.apache.lenya.ac.User;
+import org.apache.lenya.ac.impl.PolicyAuthorizer;
+import org.apache.lenya.cms.publication.Document;
+import org.apache.lenya.cms.publication.DocumentException;
+import org.apache.lenya.cms.publication.DocumentType;
+import org.apache.lenya.cms.publication.DocumentTypeResolver;
+import org.apache.lenya.cms.publication.Publication;
+import org.apache.lenya.cms.publication.PublicationFactory;
+import org.apache.lenya.cms.publication.util.LanguageVersions;
+import org.apache.lenya.workflow.Situation;
+import org.apache.lenya.workflow.SynchronizedWorkflowInstances;
+import org.apache.lenya.workflow.WorkflowException;
+import org.apache.lenya.workflow.WorkflowInstance;
+import org.apache.lenya.workflow.impl.SynchronizedWorkflowInstancesImpl;
+import org.apache.lenya.workflow.impl.WorkflowBuilder;
+import org.apache.lenya.workflow.impl.WorkflowImpl;
+
+/**
+ * Default implementation of the workflow resolver component.
+ *
+ * @version $Id:$
+ */
+public class WorkflowResolverImpl extends AbstractLogEnabled implements WorkflowResolver,
+ Contextualizable, Serviceable {
+
+ /**
+ * @see org.apache.lenya.cms.workflow.WorkflowResolver#getWorkflowInstance(org.apache.lenya.cms.publication.Document)
+ */
+ public WorkflowInstance getWorkflowInstance(Document document) throws WorkflowException {
+ WorkflowInstance instance = new WorkflowDocument(buildWorkflow(document), document);
+ ContainerUtil.enableLogging(instance, getLogger());
+ return instance;
+ }
+
+ /**
+ * @see org.apache.lenya.cms.workflow.WorkflowResolver#getSituation()
+ */
+ public Situation getSituation() {
+ Request request = ObjectModelHelper.getRequest(objectModel);
+ Session session = request.getSession(false);
+
+ Situation situation = null;
+ if (session != null) {
+ Identity identity = (Identity) session.getAttribute(Identity.class.getName());
+
+ User user = identity.getUser();
+ String userId = null;
+ if (user != null) {
+ userId = user.getId();
+ }
+
+ Machine machine = identity.getMachine();
+ String machineIp = null;
+ if (machine != null) {
+ machineIp = machine.getIp();
+ }
+
+ Role[] roles;
+ try {
+ roles = PolicyAuthorizer.getRoles(request);
+ } catch (AccessControlException e) {
+ throw new RuntimeException(e);
+ }
+ String[] roleIds = new String[roles.length];
+ for (int i = 0; i < roles.length; i++) {
+ roleIds[i] = roles[i].getId();
+ }
+
+ situation = new CMSSituation(roleIds, userId, machineIp);
+ }
+ return situation;
+ }
+
+ private Map objectModel;
+
+ /**
+ * @see org.apache.avalon.framework.context.Contextualizable#contextualize(org.apache.avalon.framework.context.Context)
+ */
+ public void contextualize(Context context) throws ContextException {
+ this.objectModel = ContextHelper.getObjectModel(context);
+ }
+
+ /**
+ * @see org.apache.lenya.cms.workflow.WorkflowResolver#hasWorkflow(org.apache.lenya.cms.publication.Document)
+ */
+ public boolean hasWorkflow(Document document) {
+ try {
+ return getWorkflowInstance(document).getHistory().isInitialized();
+ } catch (WorkflowException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ protected static final String WORKFLOW_DIRECTORY = "config/workflow".replace('/',
+ File.separatorChar);
+
+ /**
+ * Builds a workflow for a given document.
+ * @param document The document.
+ * @return A workflow object or <code>null</code> if there is no workflow
+ * assigned to the document's document type.
+ */
+ protected WorkflowImpl buildWorkflow(Document document) {
+
+ DocumentTypeResolver doctypeResolver = null;
+ WorkflowImpl workflow = null;
+ try {
+
+ doctypeResolver = (DocumentTypeResolver) this.manager.lookup(DocumentTypeResolver.ROLE);
+ DocumentType doctype = doctypeResolver.resolve(document);
+
+ if (doctype.hasWorkflow()) {
+ String workflowFileName = doctype.getWorkflowFileName();
+
+ PublicationFactory factory = PublicationFactory.getInstance(getLogger());
+ Publication publication = factory.getPublication(this.objectModel);
+
+ File workflowDirectory = new File(publication.getDirectory(), WORKFLOW_DIRECTORY);
+ File workflowFile = new File(workflowDirectory, workflowFileName);
+ WorkflowBuilder builder = new WorkflowBuilder(getLogger());
+ workflow = builder.buildWorkflow(workflowFileName, workflowFile);
+ }
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ } finally {
+ if (doctypeResolver != null) {
+ this.manager.release(doctypeResolver);
+ }
+ }
+
+ return workflow;
+ }
+
+ private ServiceManager manager;
+
+ /**
+ * @see org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager)
+ */
+ public void service(ServiceManager manager) throws ServiceException {
+ this.manager = manager;
+ }
+
+ /**
+ * @see org.apache.lenya.cms.workflow.WorkflowResolver#getSynchronizedInstance(org.apache.lenya.cms.publication.Document)
+ */
+ public SynchronizedWorkflowInstances getSynchronizedInstance(Document document)
+ throws WorkflowException {
+ assert document != null;
+ LanguageVersions versions;
+ try {
+ versions = new LanguageVersions(document);
+ } catch (DocumentException e) {
+ throw new WorkflowException(e);
+ }
+
+ Document[] documents = versions.getDocuments();
+ WorkflowInstance[] instances = new WorkflowInstance[documents.length];
+ for (int i = 0; i < documents.length; i++) {
+ instances[i] = getWorkflowInstance(documents[i]);
+ }
+
+ SynchronizedWorkflowInstances set = new SynchronizedWorkflowInstancesImpl(instances,
+ getWorkflowInstance(document));
+ ContainerUtil.enableLogging(set, getLogger());
+ return set;
+ }
+}
\ No newline at end of file
Modified: lenya/trunk/src/java/org/apache/lenya/cms/workflow/usecases/InvokeWorkflow.java
Url: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/workflow/usecases/InvokeWorkflow.java?view=diff&rev=126613&p1=lenya/trunk/src/java/org/apache/lenya/cms/workflow/usecases/InvokeWorkflow.java&r1=126612&p2=lenya/trunk/src/java/org/apache/lenya/cms/workflow/usecases/InvokeWorkflow.java&r2=126613
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/workflow/usecases/InvokeWorkflow.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/workflow/usecases/InvokeWorkflow.java Thu Jan 27 07:02:08 2005
@@ -17,8 +17,6 @@
package org.apache.lenya.cms.workflow.usecases;
import org.apache.lenya.cms.usecase.DocumentUsecase;
-import org.apache.lenya.cms.workflow.WorkflowFactory;
-import org.apache.lenya.workflow.Event;
import org.apache.lenya.workflow.WorkflowInstance;
/**
@@ -29,6 +27,9 @@
*/
public class InvokeWorkflow extends DocumentUsecase {
+ /**
+ * The name of the event request parameter.
+ */
public static final String EVENT = "lenya.event";
/**
@@ -44,8 +45,9 @@
protected void doCheckPreconditions() throws Exception {
super.doCheckPreconditions();
String eventName = getParameterAsString(EVENT);
-
- if (canExecuteWorkflow(eventName, getSourceDocument())) {
+
+ WorkflowInstance instance = getWorkflowInstance(getSourceDocument());
+ if (!instance.canInvoke(getSituation(), eventName)) {
addErrorMessage("The event [" + eventName + "] is not executable on document ["
+ getSourceDocument() + "].");
}
Modified: lenya/trunk/src/java/org/apache/lenya/lenya.roles
Url: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/lenya.roles?view=diff&rev=126613&p1=lenya/trunk/src/java/org/apache/lenya/lenya.roles&r1=126612&p2=lenya/trunk/src/java/org/apache/lenya/lenya.roles&r2=126613
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/lenya.roles (original)
+++ lenya/trunk/src/java/org/apache/lenya/lenya.roles Thu Jan 27 07:02:08 2005
@@ -102,4 +102,8 @@
shorthand="flowhelper"
default-class="org.apache.lenya.cms.cocoon.flow.FlowHelperImpl"/>
+ <role name="org.apache.lenya.cms.workflow.WorkflowResolver"
+ shorthand="workflow-resolver"
+ default-class="org.apache.lenya.cms.workflow.WorkflowResolverImpl"/>
+
</role-list>
Added: lenya/trunk/src/java/org/apache/lenya/workflow/History.java
Url: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/workflow/History.java?view=auto&rev=126613
==============================================================================
--- (empty file)
+++ lenya/trunk/src/java/org/apache/lenya/workflow/History.java Thu Jan 27 07:02:08 2005
@@ -0,0 +1,63 @@
+/*
+ * Copyright 1999-2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.lenya.workflow;
+
+/**
+ * Workflow history.
+ *
+ * @version $Id:$
+ */
+public interface History {
+
+ /**
+ * @return The workflow instance this history belongs to.
+ */
+ WorkflowInstance getInstance();
+
+ /**
+ * Initializes the workflow history.
+ * @param situation The situation.
+ * @throws WorkflowException if an error occurs.
+ */
+ void initialize(Situation situation) throws WorkflowException;
+
+ /**
+ * Replace this workflow history with another history.
+ * @param sourceHistory The source history.
+ * @throws WorkflowException if an error occurs.
+ */
+ void replaceWith(History sourceHistory) throws WorkflowException;
+
+ /**
+ * @return If the workflow history is initialized.
+ * @throws WorkflowException if an error occurs.
+ */
+ boolean isInitialized() throws WorkflowException;
+
+ /**
+ * Deletes the workflow history.
+ * @throws WorkflowException if an error occurs.
+ */
+ void delete() throws WorkflowException;
+
+ /**
+ * @return The last state of the history.
+ * @throws WorkflowException if the history is not yet initialized.
+ */
+ State getLastState() throws WorkflowException;
+
+}
Modified: lenya/trunk/src/java/org/apache/lenya/workflow/SynchronizedWorkflowInstances.java
Url: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/workflow/SynchronizedWorkflowInstances.java?view=diff&rev=126613&p1=lenya/trunk/src/java/org/apache/lenya/workflow/SynchronizedWorkflowInstances.java&r1=126612&p2=lenya/trunk/src/java/org/apache/lenya/workflow/SynchronizedWorkflowInstances.java&r2=126613
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/workflow/SynchronizedWorkflowInstances.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/workflow/SynchronizedWorkflowInstances.java Thu Jan 27 07:02:08 2005
@@ -54,11 +54,11 @@
* Returns all executable events.
* @see org.apache.lenya.workflow.WorkflowInstance#getExecutableEvents(org.apache.lenya.workflow.Situation)
*/
- Event[] getExecutableEvents(Situation situation) throws WorkflowException;
+ String[] getExecutableEvents(Situation situation) throws WorkflowException;
/**
* Invokes an event on all documents.
- * @see org.apache.lenya.workflow.WorkflowInstance#invoke(org.apache.lenya.workflow.Situation, org.apache.lenya.workflow.Event)
+ * @see org.apache.lenya.workflow.WorkflowInstance#invoke(org.apache.lenya.workflow.Situation, String)
*/
- void invoke(Situation situation, Event event) throws WorkflowException;
+ void invoke(Situation situation, String event) throws WorkflowException;
}
Modified: lenya/trunk/src/java/org/apache/lenya/workflow/Workflow.java
Url: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/workflow/Workflow.java?view=diff&rev=126613&p1=lenya/trunk/src/java/org/apache/lenya/workflow/Workflow.java&r1=126612&p2=lenya/trunk/src/java/org/apache/lenya/workflow/Workflow.java&r2=126613
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/workflow/Workflow.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/workflow/Workflow.java Thu Jan 27 07:02:08 2005
@@ -33,7 +33,7 @@
public interface Workflow {
String NAMESPACE = "http://apache.org/cocoon/lenya/workflow/1.0";
String DEFAULT_PREFIX = "wf";
-
+
/**
* Returns the initial state of this workflow.
* @return The initial state
@@ -53,4 +53,9 @@
* @return A string array.
*/
String[] getVariableNames();
+
+ /**
+ * @return The name of this workflow.
+ */
+ String getName();
}
Modified: lenya/trunk/src/java/org/apache/lenya/workflow/WorkflowInstance.java
Url: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/workflow/WorkflowInstance.java?view=diff&rev=126613&p1=lenya/trunk/src/java/org/apache/lenya/workflow/WorkflowInstance.java&r1=126612&p2=lenya/trunk/src/java/org/apache/lenya/workflow/WorkflowInstance.java&r2=126613
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/workflow/WorkflowInstance.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/workflow/WorkflowInstance.java Thu Jan 27 07:02:08 2005
@@ -44,26 +44,32 @@
* Returns the executable events in a certain situation.
* @param situation The situation.
* @return An array of events.
- * @throws WorkflowException when something went wrong.
*/
- Event[] getExecutableEvents(Situation situation) throws WorkflowException;
+ String[] getExecutableEvents(Situation situation);
+
+ /**
+ * Checks if an event can be executed in a certain situation.
+ * @param situation The situation.
+ * @param event The event.
+ * @return A boolean value.
+ */
+ boolean canInvoke(Situation situation, String event);
/**
* Indicates that the user invoked an event.
*
* @param situation The situation in which the event was invoked.
* @param event The event that was invoked.
- * @throws WorkflowException when something went wrong.
+ * @throws WorkflowException if the event cannot be invoked in this situation.
*/
- void invoke(Situation situation, Event event) throws WorkflowException;
+ void invoke(Situation situation, String event) throws WorkflowException;
/**
* Returns the current value of a variable.
* @param variableName A variable name.
* @return A boolean value.
- * @throws WorkflowException when the variable does not exist.
*/
- boolean getValue(String variableName) throws WorkflowException;
+ boolean getValue(String variableName);
/**
* Adds a workflow listener.
@@ -81,6 +87,13 @@
* Returns if the transition for a certain event is synchronized.
* @param event An event.
* @return A boolean value.
+ * @throws WorkflowException if the event is not supported.
+ */
+ boolean isSynchronized(String event) throws WorkflowException;
+
+ /**
+ * @return The history of this workflow instance.
*/
- boolean isSynchronized(Event event) throws WorkflowException;
+ History getHistory();
+
}
Modified: lenya/trunk/src/java/org/apache/lenya/workflow/WorkflowListener.java
Url: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/workflow/WorkflowListener.java?view=diff&rev=126613&p1=lenya/trunk/src/java/org/apache/lenya/workflow/WorkflowListener.java&r1=126612&p2=lenya/trunk/src/java/org/apache/lenya/workflow/WorkflowListener.java&r2=126613
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/workflow/WorkflowListener.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/workflow/WorkflowListener.java Thu Jan 27 07:02:08 2005
@@ -31,9 +31,10 @@
* @param instance The workflow instance.
* @param situation The situation before the transition has fired.
* @param event The event that was invoked.
+ * @param resultingState The resulting state.
*
* @throws WorkflowException if an error occured
*/
- void transitionFired(WorkflowInstance instance, Situation situation, Event event)
+ void transitionFired(WorkflowInstance instance, Situation situation, String event, State resultingState)
throws WorkflowException;
}
Modified: lenya/trunk/src/java/org/apache/lenya/workflow/impl/AbstractCondition.java
Url: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/workflow/impl/AbstractCondition.java?view=diff&rev=126613&p1=lenya/trunk/src/java/org/apache/lenya/workflow/impl/AbstractCondition.java&r1=126612&p2=lenya/trunk/src/java/org/apache/lenya/workflow/impl/AbstractCondition.java&r2=126613
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/workflow/impl/AbstractCondition.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/workflow/impl/AbstractCondition.java Thu Jan 27 07:02:08 2005
@@ -19,13 +19,14 @@
package org.apache.lenya.workflow.impl;
+import org.apache.avalon.framework.logger.AbstractLogEnabled;
import org.apache.lenya.workflow.Condition;
import org.apache.lenya.workflow.WorkflowException;
/**
* Abstract base class for workflow conditions.
*/
-public abstract class AbstractCondition implements Condition {
+public abstract class AbstractCondition extends AbstractLogEnabled implements Condition {
private String expression;
Modified: lenya/trunk/src/java/org/apache/lenya/workflow/impl/BooleanVariableCondition.java
Url: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/workflow/impl/BooleanVariableCondition.java?view=diff&rev=126613&p1=lenya/trunk/src/java/org/apache/lenya/workflow/impl/BooleanVariableCondition.java&r1=126612&p2=lenya/trunk/src/java/org/apache/lenya/workflow/impl/BooleanVariableCondition.java&r2=126613
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/workflow/impl/BooleanVariableCondition.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/workflow/impl/BooleanVariableCondition.java Thu Jan 27 07:02:08 2005
@@ -22,15 +22,12 @@
import org.apache.lenya.workflow.Situation;
import org.apache.lenya.workflow.WorkflowException;
import org.apache.lenya.workflow.WorkflowInstance;
-import org.apache.log4j.Category;
/**
* Implementation of a boolean variable condition.
*/
public class BooleanVariableCondition extends AbstractCondition {
- private static final Category log = Category.getInstance(BooleanVariableCondition.class);
-
private String variableName;
private boolean value;
@@ -64,9 +61,9 @@
variableName = sides[0].trim();
value = Boolean.valueOf(sides[1].trim()).booleanValue();
- if (log.isDebugEnabled()) {
- log.debug("Expression: [" + sides[1].trim() + "]");
- log.debug("Setting value: [" + value + "]");
+ if (getLogger().isDebugEnabled()) {
+ getLogger().debug("Expression: [" + sides[1].trim() + "]");
+ getLogger().debug("Setting value: [" + value + "]");
}
}
@@ -74,10 +71,10 @@
* @see org.apache.lenya.workflow.Condition#isComplied(org.apache.lenya.workflow.Situation, org.apache.lenya.workflow.WorkflowInstance)
*/
public boolean isComplied(Situation situation, WorkflowInstance instance) throws WorkflowException {
- if (log.isDebugEnabled()) {
- log.debug("Checking boolean variable condition");
- log.debug(" Condition value: [" + getValue() + "]");
- log.debug(" Variable value: [" + instance.getValue(getVariableName()) + "]");
+ if (getLogger().isDebugEnabled()) {
+ getLogger().debug("Checking boolean variable condition");
+ getLogger().debug(" Condition value: [" + getValue() + "]");
+ getLogger().debug(" Variable value: [" + instance.getValue(getVariableName()) + "]");
}
return instance.getValue(getVariableName()) == getValue();
}
Modified: lenya/trunk/src/java/org/apache/lenya/workflow/impl/ConditionFactory.java
Url: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/workflow/impl/ConditionFactory.java?view=diff&rev=126613&p1=lenya/trunk/src/java/org/apache/lenya/workflow/impl/ConditionFactory.java&r1=126612&p2=lenya/trunk/src/java/org/apache/lenya/workflow/impl/ConditionFactory.java&r2=126613
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/workflow/impl/ConditionFactory.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/workflow/impl/ConditionFactory.java Thu Jan 27 07:02:08 2005
@@ -19,6 +19,9 @@
package org.apache.lenya.workflow.impl;
+import org.apache.avalon.framework.container.ContainerUtil;
+import org.apache.avalon.framework.logger.AbstractLogEnabled;
+import org.apache.avalon.framework.logger.Logger;
import org.apache.lenya.workflow.Condition;
import org.apache.lenya.workflow.WorkflowException;
@@ -26,12 +29,14 @@
/**
* Factory to build conditions.
*/
-public final class ConditionFactory {
+public final class ConditionFactory extends AbstractLogEnabled {
/**
* Ctor.
+ * @param logger The logger to use.
*/
- private ConditionFactory() {
+ public ConditionFactory(Logger logger) {
+ ContainerUtil.enableLogging(this, logger);
}
/**
@@ -41,7 +46,7 @@
* @return A condition.
* @throws WorkflowException when creating the condition failed.
*/
- protected static Condition createCondition(String className, String expression)
+ protected Condition createCondition(String className, String expression)
throws WorkflowException {
Condition condition;
@@ -49,6 +54,7 @@
try {
Class clazz = Class.forName(className);
condition = (Condition) clazz.newInstance();
+ ContainerUtil.enableLogging(condition, getLogger());
condition.setExpression(expression);
} catch (ClassNotFoundException e) {
throw new WorkflowException(e);
Deleted: /lenya/trunk/src/java/org/apache/lenya/workflow/impl/History.java
Url: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/workflow/impl/History.java?view=auto&rev=126612
==============================================================================
Added: lenya/trunk/src/java/org/apache/lenya/workflow/impl/HistoryImpl.java
Url: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/workflow/impl/HistoryImpl.java?view=auto&rev=126613
==============================================================================
--- (empty file)
+++ lenya/trunk/src/java/org/apache/lenya/workflow/impl/HistoryImpl.java Thu Jan 27 07:02:08 2005
@@ -0,0 +1,481 @@
+/*
+ * Copyright 1999-2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+/* $Id: History.java 126320 2005-01-24 22:16:21Z gregor $ */
+
+package org.apache.lenya.workflow.impl;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.nio.channels.FileChannel;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+import javax.xml.transform.TransformerException;
+
+import org.apache.lenya.workflow.BooleanVariable;
+import org.apache.lenya.workflow.Event;
+import org.apache.lenya.workflow.History;
+import org.apache.lenya.workflow.Situation;
+import org.apache.lenya.workflow.State;
+import org.apache.lenya.workflow.Workflow;
+import org.apache.lenya.workflow.WorkflowException;
+import org.apache.lenya.workflow.WorkflowInstance;
+import org.apache.lenya.workflow.WorkflowListener;
+import org.apache.lenya.xml.DocumentHelper;
+import org.apache.lenya.xml.NamespaceHelper;
+import org.apache.xpath.XPathAPI;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+/**
+ * <p>
+ * The history of a workflow instance contains a list of all versions of the
+ * instance. A version contains
+ * </p>
+ * <ul>
+ * <li>the state,</li>
+ * <li>the event that caused the transition (omitted in the first version).
+ * </li>
+ * </ul>
+ */
+public abstract class HistoryImpl implements History, WorkflowListener {
+
+ public static final String WORKFLOW_ATTRIBUTE = "workflow";
+ public static final String HISTORY_ELEMENT = "history";
+ public static final String VERSION_ELEMENT = "version";
+ public static final String STATE_ATTRIBUTE = "state";
+ public static final String EVENT_ATTRIBUTE = "event";
+ public static final String VARIABLE_ELEMENT = "variable";
+ public static final String NAME_ATTRIBUTE = "name";
+ public static final String VALUE_ATTRIBUTE = "value";
+ public static final String DATE_ATTRIBUTE = "date";
+
+ /**
+ * Creates a new history object. A new history file is created and
+ * initialized.
+ * @param workflowId The workflow ID.
+ * @param situation The current situation.
+ * @throws WorkflowException when something went wrong.
+ */
+ public void initialize(Situation situation) throws WorkflowException {
+ try {
+ File file = getHistoryFile();
+ file.getParentFile().mkdirs();
+ file.createNewFile();
+
+ NamespaceHelper helper = new NamespaceHelper(Workflow.NAMESPACE,
+ Workflow.DEFAULT_PREFIX, HISTORY_ELEMENT);
+
+ Element historyElement = helper.getDocument().getDocumentElement();
+ String workflowName = getInstance().getWorkflow().getName();
+ historyElement.setAttribute(WORKFLOW_ATTRIBUTE, workflowName);
+
+ Element initialVersionElement = createInitialVersionElement(helper, situation);
+ historyElement.appendChild(initialVersionElement);
+
+ DocumentHelper.writeDocument(helper.getDocument(), file);
+ } catch (Exception e) {
+ throw new WorkflowException(e);
+ }
+ }
+
+ /**
+ * Creates a new history object for a workflow instance.
+ * @param instance The workflow instance.
+ * @throws WorkflowException if an error occurs.
+ */
+ protected HistoryImpl(WorkflowInstanceImpl instance) throws WorkflowException {
+ this.instance = instance;
+ if (isInitialized()) {
+ NamespaceHelper helper = getNamespaceHelper();
+ restoreState(instance, helper);
+ restoreVariables(instance, helper);
+ instance.addWorkflowListener(this);
+ }
+ }
+
+ private WorkflowInstanceImpl instance = null;
+
+ /**
+ * Returns the namespace helper for the history file.
+ * @return A namespace helper.
+ * @throws WorkflowException It the helper could not be obtained.
+ */
+ protected NamespaceHelper getNamespaceHelper() throws WorkflowException {
+ NamespaceHelper helper;
+ try {
+ Document document = DocumentHelper.readDocument(getHistoryFile());
+ helper = new NamespaceHelper(Workflow.NAMESPACE, Workflow.DEFAULT_PREFIX, document);
+ } catch (Exception e) {
+ throw new WorkflowException(e);
+ }
+ return helper;
+ }
+
+ /**
+ * Returns the workflow ID for this history.
+ * @return A string.
+ * @throws WorkflowException when something went wrong.
+ */
+ protected String getWorkflowId() throws WorkflowException {
+ return getWorkflowId(getNamespaceHelper());
+ }
+
+ /**
+ * Returns the workflow ID for this history.
+ * @param helper The namespace helper for the history document.
+ * @return A string.
+ * @throws WorkflowException when something went wrong.
+ */
+ protected String getWorkflowId(NamespaceHelper helper) throws WorkflowException {
+ String workflowId = helper.getDocument().getDocumentElement()
+ .getAttribute(WORKFLOW_ATTRIBUTE);
+ if (workflowId == null) {
+ throw new WorkflowException("The attribute '" + WORKFLOW_ATTRIBUTE + "' is missing!");
+ }
+ if ("".equals(workflowId)) {
+ throw new WorkflowException("The workflow ID must not be empty!");
+ }
+ return workflowId;
+ }
+
+ /**
+ * Returns if the history has been initialized.
+ * @return A boolean value.
+ */
+ public boolean isInitialized() {
+ return getHistoryFile().exists();
+ }
+
+ /**
+ * Factory method to obtain the history file.
+ * @return A file.
+ */
+ protected abstract File getHistoryFile();
+
+ /**
+ * Creates a new version element. This method is called after a tansition
+ * invocation.
+ * @param helper The namespace helper of the history document.
+ * @param situation The current situation.
+ * @param workflowId The workflow ID.
+ * @return An XML element.
+ * @throws WorkflowException when something went wrong.
+ */
+ protected Element createInitialVersionElement(NamespaceHelper helper, Situation situation)
+ throws WorkflowException {
+ Element versionElement = createVersionElement(helper, situation);
+
+ StateImpl initialState = (StateImpl) instance.getWorkflow().getInitialState();
+ versionElement.setAttribute(STATE_ATTRIBUTE, initialState.getId());
+
+ return versionElement;
+ }
+
+ /**
+ * Creates a new version element. This method is called after a tansition
+ * invocation.
+ * @param helper The namespace helper of the history document.
+ * @param state The state of the new version.
+ * @param situation The current situation.
+ * @param event The event that was invoked.
+ * @return An XML element.
+ */
+ protected Element createVersionElement(NamespaceHelper helper, StateImpl state,
+ Situation situation, String event) {
+ Element versionElement = createVersionElement(helper, situation);
+ versionElement.setAttribute(STATE_ATTRIBUTE, state.getId());
+ versionElement.setAttribute(EVENT_ATTRIBUTE, event);
+ return versionElement;
+ }
+
+ /**
+ * Creates a version element based on a situation.
+ * @param helper The namespace helper of the history document.
+ * @param situation The current situation.
+ * @return An XML element.
+ */
+ protected Element createVersionElement(NamespaceHelper helper, Situation situation) {
+ Element versionElement = helper.createElement(VERSION_ELEMENT);
+ Date now = new Date();
+ SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+ String dateString = format.format(now);
+ versionElement.setAttribute(DATE_ATTRIBUTE, dateString);
+ return versionElement;
+ }
+
+ /**
+ * Advances the workflow history when a tranistion was invoked.
+ *
+ * @param instance The workflow instance.
+ * @param situation The situation before the transition.
+ * @param event The invoked event.
+ * @param resultingState The resulting state.
+ *
+ * @throws WorkflowException when something went wrong.
+ */
+ public void transitionFired(WorkflowInstance instance, Situation situation, String event,
+ State resultingState) throws WorkflowException {
+ try {
+ this.lastState = resultingState;
+ org.w3c.dom.Document xmlDocument = DocumentHelper.readDocument(getHistoryFile());
+ Element root = xmlDocument.getDocumentElement();
+
+ NamespaceHelper helper = new NamespaceHelper(Workflow.NAMESPACE,
+ Workflow.DEFAULT_PREFIX, xmlDocument);
+
+ Element versionElement = createVersionElement(helper, (StateImpl) instance
+ .getCurrentState(), situation, event);
+
+ root.appendChild(versionElement);
+
+ saveVariables(helper);
+
+ DocumentHelper.writeDocument(xmlDocument, getHistoryFile());
+ } catch (Exception e) {
+ throw new WorkflowException(e);
+ }
+ }
+
+ /**
+ * Sets the workflow instance.
+ * @param impl A workflow instance implementation.
+ */
+ public void setInstance(WorkflowInstanceImpl impl) {
+ instance = impl;
+ }
+
+ /**
+ * Saves the state variables as children of the document element.
+ * @param helper The helper that holds the document.
+ * @throws WorkflowException when something went wrong.
+ */
+ protected void saveVariables(NamespaceHelper helper) throws WorkflowException {
+ Element parent = helper.getDocument().getDocumentElement();
+ WorkflowImpl workflow = (WorkflowImpl) getInstance().getWorkflow();
+ BooleanVariable[] variables = workflow.getVariables();
+
+ for (int i = 0; i < variables.length; i++) {
+ String name = variables[i].getName();
+ boolean value = getInstance().getValue(name);
+
+ try {
+ Element element = (Element) XPathAPI.selectSingleNode(parent, "*[local-name() = '"
+ + VARIABLE_ELEMENT + "']" + "[@" + NAME_ATTRIBUTE + " = '" + name + "']");
+
+ if (element == null) {
+ element = helper.createElement(VARIABLE_ELEMENT);
+ element.setAttribute(NAME_ATTRIBUTE, name);
+ parent.appendChild(element);
+ }
+
+ element.setAttribute(VALUE_ATTRIBUTE, Boolean.toString(value));
+ } catch (TransformerException e) {
+ throw new WorkflowException(e);
+ }
+ }
+ }
+
+ /**
+ * Restores the state variables of a workflow instance.
+ * @param instance The instance to restore.
+ * @param helper The helper that wraps the history document.
+ * @throws WorkflowException when something went wrong.
+ */
+ protected void restoreVariables(WorkflowInstanceImpl instance, NamespaceHelper helper)
+ throws WorkflowException {
+ Element parent = helper.getDocument().getDocumentElement();
+
+ Element[] variableElements = helper.getChildren(parent, VARIABLE_ELEMENT);
+
+ for (int i = 0; i < variableElements.length; i++) {
+ String name = variableElements[i].getAttribute(NAME_ATTRIBUTE);
+ String value = variableElements[i].getAttribute(VALUE_ATTRIBUTE);
+ instance.setValue(name, Boolean.valueOf(value).booleanValue());
+ }
+ }
+
+ /**
+ * Restores the state of a workflow instance.
+ * @param instance The instance to restore.
+ * @param helper The helper that wraps the history document.
+ * @throws WorkflowException when something went wrong.
+ */
+ protected void restoreState(WorkflowInstanceImpl instance, NamespaceHelper helper)
+ throws WorkflowException {
+ State state;
+ Element[] versionElements = helper.getChildren(helper.getDocument().getDocumentElement(),
+ VERSION_ELEMENT);
+
+ if (versionElements.length > 0) {
+ Element lastElement = versionElements[versionElements.length - 1];
+ String stateId = lastElement.getAttribute(STATE_ATTRIBUTE);
+ state = instance.getWorkflowImpl().getState(stateId);
+ } else {
+ state = instance.getWorkflow().getInitialState();
+ }
+
+ this.lastState = state;
+ }
+
+ private State lastState = null;
+
+ /**
+ * @see org.apache.lenya.workflow.History#getLastState()
+ */
+ public State getLastState() throws WorkflowException {
+ return this.lastState;
+ }
+
+ /**
+ * Moves this history to a new file.
+ * @param newFile The new file.
+ * @throws WorkflowException when something went wrong.
+ */
+ protected void move(File newFile) throws WorkflowException {
+
+ copy(newFile);
+
+ File historyFile = getHistoryFile();
+ File directory = historyFile.getParentFile();
+ boolean deleted = historyFile.delete();
+ if (!deleted) {
+ throw new WorkflowException("The old history file could not be deleted!");
+ }
+ if (directory.exists() && directory.isDirectory() && directory.listFiles().length == 0) {
+ directory.delete();
+ }
+ }
+
+ /**
+ * Copies this history to a new file.
+ * @param newFile The new file.
+ * @throws WorkflowException when something went wrong.
+ */
+ protected void copy(File newFile) throws WorkflowException {
+
+ FileInputStream sourceStream = null;
+ FileOutputStream destinationStream = null;
+ FileChannel sourceChannel = null;
+ FileChannel destinationChannel = null;
+ try {
+ newFile.getParentFile().mkdirs();
+ newFile.createNewFile();
+ File historyFile = getHistoryFile();
+
+ sourceStream = new FileInputStream(historyFile);
+ sourceChannel = sourceStream.getChannel();
+
+ destinationStream = new FileOutputStream(newFile);
+ destinationChannel = destinationStream.getChannel();
+
+ destinationChannel.transferFrom(sourceChannel, 0, sourceChannel.size());
+ sourceStream.close();
+ destinationStream.close();
+ } catch (IOException e) {
+ throw new WorkflowException(e);
+ } finally {
+ try {
+ if (sourceStream != null)
+ sourceStream.close();
+ if (destinationStream != null)
+ destinationStream.close();
+ } catch (IOException e) {
+ throw new WorkflowException(e);
+ }
+ }
+ }
+
+ /**
+ * Restores a version from an XML element.
+ * @param helper The namespace helper.
+ * @param element An XML element.
+ * @return A version.
+ * @throws WorkflowException when something went wrong.
+ */
+ protected Version restoreVersion(NamespaceHelper helper, Element element)
+ throws WorkflowException {
+ if (!element.getLocalName().equals(VERSION_ELEMENT)) {
+ throw new WorkflowException("Invalid history XML!");
+ }
+
+ WorkflowImpl workflow = (WorkflowImpl) getInstance().getWorkflow();
+
+ Event event = null;
+ String eventId = element.getAttribute(EVENT_ATTRIBUTE);
+ if (eventId != null && !"".equals(eventId)) {
+ event = workflow.getEvent(eventId);
+ }
+
+ String stateId = element.getAttribute(STATE_ATTRIBUTE);
+ State state = workflow.getState(stateId);
+
+ Version version = new Version(event, state);
+ return version;
+ }
+
+ /**
+ * Returns the versions of this history.
+ * @return An array of versions.
+ * @throws WorkflowException when something went wrong.
+ */
+ public Version[] getVersions() throws WorkflowException {
+ List versions = new ArrayList();
+
+ NamespaceHelper helper = getNamespaceHelper();
+ Element documentElement = helper.getDocument().getDocumentElement();
+ Element[] versionElements = getNamespaceHelper().getChildren(documentElement,
+ VERSION_ELEMENT);
+
+ for (int i = 0; i < versionElements.length; i++) {
+ Version version = restoreVersion(helper, versionElements[i]);
+ versions.add(version);
+ }
+ return (Version[]) versions.toArray(new Version[versions.size()]);
+ }
+
+ /**
+ * Deletes the history.
+ * @throws WorkflowException when something went wrong.
+ */
+ public void delete() throws WorkflowException {
+ System.out.println("Deleting file [" + getHistoryFile() + "]");
+ if (!isInitialized()) {
+ throw new WorkflowException("The workflow history is not initialized!");
+ }
+
+ boolean deleted = getHistoryFile().delete();
+
+ if (!deleted) {
+ throw new WorkflowException("The workflow history could not be deleted!");
+ }
+
+ }
+
+ /**
+ * @see org.apache.lenya.workflow.History#getInstance()
+ */
+ public WorkflowInstance getInstance() {
+ return this.instance;
+ }
+
+}
\ No newline at end of file
Modified: lenya/trunk/src/java/org/apache/lenya/workflow/impl/SynchronizedWorkflowInstancesImpl.java
Url: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/workflow/impl/SynchronizedWorkflowInstancesImpl.java?view=diff&rev=126613&p1=lenya/trunk/src/java/org/apache/lenya/workflow/impl/SynchronizedWorkflowInstancesImpl.java&r1=126612&p2=lenya/trunk/src/java/org/apache/lenya/workflow/impl/SynchronizedWorkflowInstancesImpl.java&r2=126613
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/workflow/impl/SynchronizedWorkflowInstancesImpl.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/workflow/impl/SynchronizedWorkflowInstancesImpl.java Thu Jan 27 07:02:08 2005
@@ -23,21 +23,19 @@
import java.util.HashSet;
import java.util.Set;
-import org.apache.lenya.workflow.Event;
+import org.apache.avalon.framework.logger.AbstractLogEnabled;
import org.apache.lenya.workflow.Situation;
import org.apache.lenya.workflow.State;
import org.apache.lenya.workflow.SynchronizedWorkflowInstances;
import org.apache.lenya.workflow.WorkflowException;
import org.apache.lenya.workflow.WorkflowInstance;
-import org.apache.log4j.Category;
/**
- * An object of this class encapsulates a set of synchronized
- * workflow instances.
+ * An object of this class encapsulates a set of synchronized workflow
+ * instances.
*/
-public class SynchronizedWorkflowInstancesImpl implements SynchronizedWorkflowInstances {
-
- private static final Category log = Category.getInstance(SynchronizedWorkflowInstancesImpl.class);
+public class SynchronizedWorkflowInstancesImpl extends AbstractLogEnabled implements
+ SynchronizedWorkflowInstances {
/**
* Ctor.
@@ -48,18 +46,19 @@
/**
* Ctor.
* @param instances The set of workflow instances to synchronize.
- * @param mainInstance The main workflow instance to invoke for non-synchronized transitions.
+ * @param mainInstance The main workflow instance to invoke for
+ * non-synchronized transitions.
*/
- public SynchronizedWorkflowInstancesImpl(
- WorkflowInstance[] instances,
- WorkflowInstance mainInstance) {
+ public SynchronizedWorkflowInstancesImpl(WorkflowInstance[] instances,
+ WorkflowInstance mainInstance) {
setInstances(instances);
setMainInstance(mainInstance);
}
/**
* Sets the main workflow instance.
- * @param mainInstance The main workflow instance to invoke for non-synchronized transitions.
+ * @param mainInstance The main workflow instance to invoke for
+ * non-synchronized transitions.
*/
public void setMainInstance(WorkflowInstance mainInstance) {
this.mainInstance = mainInstance;
@@ -80,9 +79,9 @@
* Returns all executable events.
* @see org.apache.lenya.workflow.WorkflowInstance#getExecutableEvents(org.apache.lenya.workflow.Situation)
*/
- public Event[] getExecutableEvents(Situation situation) throws WorkflowException {
- if (log.isDebugEnabled()) {
- log.debug("Resolving executable events");
+ public String[] getExecutableEvents(Situation situation) throws WorkflowException {
+ if (getLogger().isDebugEnabled()) {
+ getLogger().debug("Resolving executable events");
}
WorkflowInstance[] instances = getInstances();
@@ -90,16 +89,16 @@
throw new WorkflowException("The set must contain at least one workflow instance!");
}
- Event[] events = mainInstance.getExecutableEvents(situation);
+ String[] events = mainInstance.getExecutableEvents(situation);
Set executableEvents = new HashSet(Arrays.asList(events));
for (int i = 0; i < events.length; i++) {
- Event event = events[i];
+ String event = events[i];
if (mainInstance.isSynchronized(event)) {
boolean canFire = true;
- if (log.isDebugEnabled()) {
- log.debug(" Transition for event [" + event + "] is synchronized.");
+ if (getLogger().isDebugEnabled()) {
+ getLogger().debug(" Transition for event [" + event + "] is synchronized.");
}
boolean sameState = true;
@@ -109,17 +108,18 @@
sameState = instances[j].getCurrentState().equals(currentState);
j++;
}
- if (log.isDebugEnabled()) {
- log.debug(" All instances are in the same state: [" + sameState + "]");
+ if (getLogger().isDebugEnabled()) {
+ getLogger().debug(" All instances are in the same state: [" + sameState + "]");
}
if (sameState) {
for (int k = 0; k < instances.length; k++) {
WorkflowInstanceImpl instance = (WorkflowInstanceImpl) instances[k];
- if (instance != mainInstance && !instance.getNextTransition(event).canFire(situation, instance)) {
+ if (instance != mainInstance
+ && !instance.getNextTransition(event).canFire(situation, instance)) {
canFire = false;
- if (log.isDebugEnabled()) {
- log.debug(" Workflow instance [" + instance + "] can not fire.");
+ if (getLogger().isDebugEnabled()) {
+ getLogger().debug(" Workflow instance [" + instance + "] can not fire.");
}
}
}
@@ -129,34 +129,35 @@
if (!canFire) {
executableEvents.remove(event);
- if (log.isDebugEnabled()) {
- log.debug(" Event [" + event + "] can not fire - removing from executable events.");
+ if (getLogger().isDebugEnabled()) {
+ getLogger().debug(" Event [" + event
+ + "] can not fire - removing from executable events.");
}
}
}
}
- if (log.isDebugEnabled()) {
- log.debug(" Resolving executable events completed.");
+ if (getLogger().isDebugEnabled()) {
+ getLogger().debug(" Resolving executable events completed.");
}
- return (Event[]) executableEvents.toArray(new Event[executableEvents.size()]);
+ return (String[]) executableEvents.toArray(new String[executableEvents.size()]);
}
/**
* Invokes an event on all documents.
- * @see org.apache.lenya.workflow.WorkflowInstance#invoke(org.apache.lenya.workflow.Situation, org.apache.lenya.workflow.Event)
+ * @see org.apache.lenya.workflow.WorkflowInstance#invoke(org.apache.lenya.workflow.Situation,
+ * java.lang.String)
*/
- public void invoke(Situation situation, Event event) throws WorkflowException {
-
- if (mainInstance.isSynchronized(event)) {
- for (int i = 0; i < instances.length; i++) {
- instances[i].invoke(situation, event);
+ public void invoke(Situation situation, String event) throws WorkflowException {
+
+ if (this.mainInstance.isSynchronized(event)) {
+ for (int i = 0; i < this.instances.length; i++) {
+ this.instances[i].invoke(situation, event);
}
- }
- else {
- mainInstance.invoke(situation, event);
+ } else {
+ this.mainInstance.invoke(situation, event);
}
}
-}
+}
\ No newline at end of file
Modified: lenya/trunk/src/java/org/apache/lenya/workflow/impl/TransitionImpl.java
Url: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/workflow/impl/TransitionImpl.java?view=diff&rev=126613&p1=lenya/trunk/src/java/org/apache/lenya/workflow/impl/TransitionImpl.java&r1=126612&p2=lenya/trunk/src/java/org/apache/lenya/workflow/impl/TransitionImpl.java&r2=126613
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/workflow/impl/TransitionImpl.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/workflow/impl/TransitionImpl.java Thu Jan 27 07:02:08 2005
@@ -19,6 +19,7 @@
package org.apache.lenya.workflow.impl;
+import org.apache.avalon.framework.logger.AbstractLogEnabled;
import org.apache.lenya.workflow.Action;
import org.apache.lenya.workflow.Condition;
import org.apache.lenya.workflow.Event;
@@ -26,7 +27,6 @@
import org.apache.lenya.workflow.Transition;
import org.apache.lenya.workflow.WorkflowException;
import org.apache.lenya.workflow.WorkflowInstance;
-import org.apache.log4j.Category;
import java.util.ArrayList;
import java.util.List;
@@ -35,9 +35,8 @@
/**
* Implementation of a transition.
*/
-public class TransitionImpl implements Transition {
+public class TransitionImpl extends AbstractLogEnabled implements Transition {
- private static final Category log = Category.getInstance(TransitionImpl.class);
/**
* Ctor.
@@ -138,8 +137,8 @@
int i = 0;
while (canFire && i < conditions.length) {
canFire = canFire && conditions[i].isComplied(situation, instance);
- if (log.isDebugEnabled()) {
- log.debug("Condition [" + conditions[i] + "] returns [" + canFire + "]");
+ if (getLogger().isDebugEnabled()) {
+ getLogger().debug("Condition [" + conditions[i] + "] returns [" + canFire + "]");
}
i++;
}
Modified: lenya/trunk/src/java/org/apache/lenya/workflow/impl/WorkflowBuilder.java
Url: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/workflow/impl/WorkflowBuilder.java?view=diff&rev=126613&p1=lenya/trunk/src/java/org/apache/lenya/workflow/impl/WorkflowBuilder.java&r1=126612&p2=lenya/trunk/src/java/org/apache/lenya/workflow/impl/WorkflowBuilder.java&r2=126613
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/workflow/impl/WorkflowBuilder.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/workflow/impl/WorkflowBuilder.java Thu Jan 27 07:02:08 2005
@@ -26,13 +26,15 @@
import javax.xml.parsers.ParserConfigurationException;
+import org.apache.avalon.framework.container.ContainerUtil;
+import org.apache.avalon.framework.logger.AbstractLogEnabled;
+import org.apache.avalon.framework.logger.Logger;
import org.apache.lenya.workflow.Action;
import org.apache.lenya.workflow.Condition;
import org.apache.lenya.workflow.Event;
import org.apache.lenya.workflow.Workflow;
import org.apache.lenya.workflow.WorkflowException;
import org.apache.lenya.xml.DocumentHelper;
-import org.apache.log4j.Category;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
@@ -41,28 +43,30 @@
/**
* Utility class to build a workflow schema from a file.
*/
-public class WorkflowBuilder {
-
- private static final Category log = Category.getInstance(WorkflowBuilder.class);
+public class WorkflowBuilder extends AbstractLogEnabled {
/**
* Ctor.
+ * @param logger The logger to use.
*/
- protected WorkflowBuilder() {
+ public WorkflowBuilder(Logger logger) {
+ ContainerUtil.enableLogging(this, logger);
}
/**
* Builds a workflow schema from a file.
+ * @param name The workflow name.
* @param file The file.
* @return A workflow schema implementation.
- * @throws WorkflowException if the file does not represent a valid workflow schema.
+ * @throws WorkflowException if the file does not represent a valid workflow
+ * schema.
*/
- public static WorkflowImpl buildWorkflow(File file) throws WorkflowException {
+ public WorkflowImpl buildWorkflow(String name, File file) throws WorkflowException {
WorkflowImpl workflow;
try {
Document document = DocumentHelper.readDocument(file);
- workflow = buildWorkflow(document);
+ workflow = buildWorkflow(name, document);
} catch (Exception e) {
throw new WorkflowException(e);
}
@@ -72,6 +76,7 @@
/**
* Builds a workflow object from an XML document.
+ * @param name The workflow name.
* @param document The XML document.
* @return A workflow implementation.
* @throws ParserConfigurationException when something went wrong.
@@ -79,8 +84,8 @@
* @throws IOException when something went wrong.
* @throws WorkflowException when something went wrong.
*/
- protected static WorkflowImpl buildWorkflow(Document document)
- throws ParserConfigurationException, SAXException, IOException, WorkflowException {
+ protected WorkflowImpl buildWorkflow(String name, Document document) throws ParserConfigurationException,
+ SAXException, IOException, WorkflowException {
Element root = document.getDocumentElement();
StateImpl initialState = null;
@@ -103,11 +108,11 @@
}
}
- WorkflowImpl workflow = new WorkflowImpl(initialState);
+ WorkflowImpl workflow = new WorkflowImpl(name, initialState);
// load variables
- NodeList variableElements =
- root.getElementsByTagNameNS(Workflow.NAMESPACE, VARIABLE_ELEMENT);
+ NodeList variableElements = root.getElementsByTagNameNS(Workflow.NAMESPACE,
+ VARIABLE_ELEMENT);
for (int i = 0; i < variableElements.getLength(); i++) {
Element element = (Element) variableElements.item(i);
@@ -127,12 +132,14 @@
}
// load transitions
- NodeList transitionElements =
- root.getElementsByTagNameNS(Workflow.NAMESPACE, TRANSITION_ELEMENT);
+ NodeList transitionElements = root.getElementsByTagNameNS(Workflow.NAMESPACE,
+ TRANSITION_ELEMENT);
for (int i = 0; i < transitionElements.getLength(); i++) {
- TransitionImpl transition =
- buildTransition((Element) transitionElements.item(i), states, events, variables);
+ TransitionImpl transition = buildTransition((Element) transitionElements.item(i),
+ states,
+ events,
+ variables);
workflow.addTransition(transition);
}
@@ -140,15 +147,15 @@
}
/**
- * Checks if a state element contains the initial state.
+ * Checks if a state element contains the initial state.
* @param element An XML element.
* @return A boolean value.
*/
- protected static boolean isInitialStateElement(Element element) {
+ protected boolean isInitialStateElement(Element element) {
String initialAttribute = element.getAttribute(INITIAL_ATTRIBUTE);
return (initialAttribute != null)
- && (initialAttribute.equals("yes") || initialAttribute.equals("true"));
+ && (initialAttribute.equals("yes") || initialAttribute.equals("true"));
}
protected static final String STATE_ELEMENT = "state";
@@ -173,7 +180,7 @@
* @param element An XML element.
* @return A state.
*/
- protected static StateImpl buildState(Element element) {
+ protected StateImpl buildState(Element element) {
String id = element.getAttribute(ID_ATTRIBUTE);
StateImpl state = new StateImpl(id);
@@ -189,15 +196,11 @@
* @return A transition.
* @throws WorkflowException when something went wrong.
*/
- protected static TransitionImpl buildTransition(
- Element element,
- Map states,
- Map events,
- Map variables)
- throws WorkflowException {
+ protected TransitionImpl buildTransition(Element element, Map states, Map events, Map variables)
+ throws WorkflowException {
- if (log.isDebugEnabled()) {
- log.debug("Building transition");
+ if (getLogger().isDebugEnabled()) {
+ getLogger().debug("Building transition");
}
String sourceId = element.getAttribute(SOURCE_ATTRIBUTE);
@@ -207,21 +210,22 @@
StateImpl destination = (StateImpl) states.get(destinationId);
TransitionImpl transition = new TransitionImpl(source, destination);
+ ContainerUtil.enableLogging(transition, getLogger());
// set event
- Element eventElement =
- (Element) element.getElementsByTagNameNS(Workflow.NAMESPACE, EVENT_ELEMENT).item(0);
+ Element eventElement = (Element) element.getElementsByTagNameNS(Workflow.NAMESPACE,
+ EVENT_ELEMENT).item(0);
String id = eventElement.getAttribute(ID_ATTRIBUTE);
Event event = (Event) events.get(id);
transition.setEvent(event);
- if (log.isDebugEnabled()) {
- log.debug(" Event: [" + event + "]");
+ if (getLogger().isDebugEnabled()) {
+ getLogger().debug(" Event: [" + event + "]");
}
// load conditions
- NodeList conditionElements =
- element.getElementsByTagNameNS(Workflow.NAMESPACE, CONDITION_ELEMENT);
+ NodeList conditionElements = element.getElementsByTagNameNS(Workflow.NAMESPACE,
+ CONDITION_ELEMENT);
for (int i = 0; i < conditionElements.getLength(); i++) {
Condition condition = buildCondition((Element) conditionElements.item(i));
@@ -229,18 +233,18 @@
}
// load assignments
- NodeList assignmentElements =
- element.getElementsByTagNameNS(Workflow.NAMESPACE, ASSIGNMENT_ELEMENT);
+ NodeList assignmentElements = element.getElementsByTagNameNS(Workflow.NAMESPACE,
+ ASSIGNMENT_ELEMENT);
for (int i = 0; i < assignmentElements.getLength(); i++) {
- BooleanVariableAssignmentImpl action =
- buildAssignment(variables, (Element) assignmentElements.item(i));
+ BooleanVariableAssignmentImpl action = buildAssignment(variables,
+ (Element) assignmentElements.item(i));
transition.addAction(action);
}
// load actions
- NodeList actionElements =
- element.getElementsByTagNameNS(Workflow.NAMESPACE, ACTION_ELEMENT);
+ NodeList actionElements = element
+ .getElementsByTagNameNS(Workflow.NAMESPACE, ACTION_ELEMENT);
for (int i = 0; i < actionElements.getLength(); i++) {
Action action = buildAction((Element) actionElements.item(i));
@@ -261,23 +265,28 @@
* @param element An XML element.
* @return An event.
*/
- protected static EventImpl buildEvent(Element element) {
+ protected EventImpl buildEvent(Element element) {
String id = element.getAttribute(ID_ATTRIBUTE);
EventImpl event = new EventImpl(id);
return event;
}
+ private ConditionFactory conditionFactory = null;
+
/**
* Builds a condition from an XML element.
* @param element An XML element.
* @return A condition.
* @throws WorkflowException when something went wrong.
*/
- protected static Condition buildCondition(Element element) throws WorkflowException {
+ protected Condition buildCondition(Element element) throws WorkflowException {
String className = element.getAttribute(CLASS_ATTRIBUTE);
String expression = DocumentHelper.getSimpleElementText(element);
- Condition condition = ConditionFactory.createCondition(className, expression);
+ if (this.conditionFactory == null) {
+ this.conditionFactory = new ConditionFactory(getLogger());
+ }
+ Condition condition = this.conditionFactory.createCondition(className, expression);
return condition;
}
@@ -287,7 +296,7 @@
* @param element An XML element.
* @return An action.
*/
- protected static Action buildAction(Element element) {
+ protected Action buildAction(Element element) {
String id = element.getAttribute(ID_ATTRIBUTE);
Action action = new ActionImpl(id);
@@ -299,7 +308,7 @@
* @param element An XML element.
* @return A boolean variable.
*/
- protected static BooleanVariableImpl buildVariable(Element element) {
+ protected BooleanVariableImpl buildVariable(Element element) {
String name = element.getAttribute(NAME_ATTRIBUTE);
String value = element.getAttribute(VALUE_ATTRIBUTE);
@@ -313,8 +322,8 @@
* @return An assignment object.
* @throws WorkflowException when something went wrong.
*/
- protected static BooleanVariableAssignmentImpl buildAssignment(Map variables, Element element)
- throws WorkflowException {
+ protected BooleanVariableAssignmentImpl buildAssignment(Map variables, Element element)
+ throws WorkflowException {
String variableName = element.getAttribute(VARIABLE_ATTRIBUTE);
String valueString = element.getAttribute(VALUE_ATTRIBUTE);
@@ -324,4 +333,4 @@
return new BooleanVariableAssignmentImpl(variable, value);
}
-}
+}
\ No newline at end of file
Modified: lenya/trunk/src/java/org/apache/lenya/workflow/impl/WorkflowImpl.java
Url: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/workflow/impl/WorkflowImpl.java?view=diff&rev=126613&p1=lenya/trunk/src/java/org/apache/lenya/workflow/impl/WorkflowImpl.java&r1=126612&p2=lenya/trunk/src/java/org/apache/lenya/workflow/impl/WorkflowImpl.java&r2=126613
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/workflow/impl/WorkflowImpl.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/workflow/impl/WorkflowImpl.java Thu Jan 27 07:02:08 2005
@@ -29,26 +29,29 @@
import org.apache.lenya.workflow.Workflow;
import org.apache.lenya.workflow.WorkflowException;
-
/**
* Implementation of a workflow schema.
*/
public class WorkflowImpl implements Workflow {
-
+
/**
* Creates a new instance of WorkflowImpl.
+ * @param name The name.
* @param initialState the initial state of the workflow.
*/
- protected WorkflowImpl(StateImpl initialState) {
+ protected WorkflowImpl(String name, StateImpl initialState) {
this.initialState = initialState;
+ this.name = name;
addState(initialState);
}
private State initialState;
+ private String name;
- /** Returns the initial state of this workflow.
+ /**
+ * Returns the initial state of this workflow.
* @return The initial state.
- *
+ *
*/
public State getInitialState() {
return initialState;
@@ -83,19 +86,21 @@
return (TransitionImpl[]) transitions.toArray(new TransitionImpl[transitions.size()]);
}
- /** Returns the destination state of a transition.
+ /**
+ * Returns the destination state of a transition.
* @param transition A transition.
* @return The destination state.
- *
+ *
*/
protected State getDestination(Transition transition) {
return ((TransitionImpl) transition).getDestination();
}
- /** Returns the transitions that leave a state.
+ /**
+ * Returns the transitions that leave a state.
* @param state A state.
* @return The transitions that leave the state.
- *
+ *
*/
public Transition[] getLeavingTransitions(State state) {
Set leavingTransitions = new HashSet();
@@ -113,7 +118,8 @@
/**
* Checks if this workflow contains a state.
* @param state The state to check.
- * @return <code>true</code> if the state is contained, <code>false</code> otherwise.
+ * @return <code>true</code> if the state is contained, <code>false</code>
+ * otherwise.
*/
protected boolean containsState(State state) {
return states.containsValue(state);
@@ -181,8 +187,7 @@
* @return A variable.
* @throws WorkflowException if no variable with the given name exists.
*/
- public BooleanVariableImpl getVariable(String name)
- throws WorkflowException {
+ public BooleanVariableImpl getVariable(String name) throws WorkflowException {
if (!variables.containsKey(name)) {
throw new WorkflowException("Workflow does not contain the variable '" + name + "'!");
}
@@ -195,7 +200,8 @@
* @return An array of variables.
*/
protected BooleanVariableImpl[] getVariables() {
- return (BooleanVariableImpl[]) variables.values().toArray(new BooleanVariableImpl[variables.size()]);
+ return (BooleanVariableImpl[]) variables.values().toArray(new BooleanVariableImpl[variables
+ .size()]);
}
/**
@@ -204,9 +210,16 @@
public String[] getVariableNames() {
BooleanVariableImpl[] variables = getVariables();
String[] names = new String[variables.length];
- for (int i = 0; i <names.length; i++) {
+ for (int i = 0; i < names.length; i++) {
names[i] = variables[i].getName();
}
return names;
}
-}
+
+ /**
+ * @see org.apache.lenya.workflow.Workflow#getName()
+ */
+ public String getName() {
+ return this.name;
+ }
+}
\ No newline at end of file
Modified: lenya/trunk/src/java/org/apache/lenya/workflow/impl/WorkflowInstanceImpl.java
Url: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/workflow/impl/WorkflowInstanceImpl.java?view=diff&rev=126613&p1=lenya/trunk/src/java/org/apache/lenya/workflow/impl/WorkflowInstanceImpl.java&r1=126612&p2=lenya/trunk/src/java/org/apache/lenya/workflow/impl/WorkflowInstanceImpl.java&r2=126613
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/workflow/impl/WorkflowInstanceImpl.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/workflow/impl/WorkflowInstanceImpl.java Thu Jan 27 07:02:08 2005
@@ -28,10 +28,10 @@
import java.util.Map;
import java.util.Set;
+import org.apache.avalon.framework.logger.AbstractLogEnabled;
import org.apache.lenya.workflow.Action;
import org.apache.lenya.workflow.BooleanVariable;
import org.apache.lenya.workflow.BooleanVariableInstance;
-import org.apache.lenya.workflow.Event;
import org.apache.lenya.workflow.Situation;
import org.apache.lenya.workflow.State;
import org.apache.lenya.workflow.Transition;
@@ -39,20 +39,19 @@
import org.apache.lenya.workflow.WorkflowException;
import org.apache.lenya.workflow.WorkflowInstance;
import org.apache.lenya.workflow.WorkflowListener;
-import org.apache.log4j.Category;
-
/**
* Implementation of a workflow instance.
*/
-public abstract class WorkflowInstanceImpl implements WorkflowInstance {
-
- private static final Category log = Category.getInstance(WorkflowInstanceImpl.class);
-
+public abstract class WorkflowInstanceImpl extends AbstractLogEnabled implements WorkflowInstance {
+
/**
* Creates a new instance of WorkflowInstanceImpl.
+ * @param workflow The workflow implementation to use.
*/
- protected WorkflowInstanceImpl() {
+ protected WorkflowInstanceImpl(WorkflowImpl workflow) {
+ this.workflow = workflow;
+ initVariableInstances();
}
private WorkflowImpl workflow;
@@ -73,58 +72,59 @@
return workflow;
}
- /** Returns the events that can be invoked in a certain situation.
- * @param situation The situation to check.
- * @return The events that can be invoked.
- * @throws WorkflowException when something went wrong.
- */
- public Event[] getExecutableEvents(Situation situation) throws WorkflowException {
-
- if (log.isDebugEnabled()) {
- log.debug("Resolving executable events");
+ /**
+ * @see org.apache.lenya.workflow.WorkflowInstance#getExecutableEvents(org.apache.lenya.workflow.Situation)
+ */
+ public String[] getExecutableEvents(Situation situation) {
+
+ if (getLogger().isDebugEnabled()) {
+ getLogger().debug("Resolving executable events");
}
-
+
Transition[] transitions = getWorkflow().getLeavingTransitions(getCurrentState());
Set executableEvents = new HashSet();
- for (int i = 0; i < transitions.length; i++) {
- if (transitions[i].canFire(situation, this)) {
- executableEvents.add(transitions[i].getEvent());
- if (log.isDebugEnabled()) {
- log.debug(" [" + transitions[i].getEvent() + "] can fire.");
+ try {
+ for (int i = 0; i < transitions.length; i++) {
+ if (transitions[i].canFire(situation, this)) {
+ executableEvents.add(transitions[i].getEvent().getName());
+ if (getLogger().isDebugEnabled()) {
+ getLogger().debug(" [" + transitions[i].getEvent() + "] can fire.");
+ }
+ } else {
+ if (getLogger().isDebugEnabled()) {
+ getLogger().debug(" [" + transitions[i].getEvent() + "] can not fire.");
+ }
}
}
- else {
- if (log.isDebugEnabled()) {
- log.debug(" [" + transitions[i].getEvent() + "] can not fire.");
- }
+
+ if (getLogger().isDebugEnabled()) {
+ getLogger().debug(" Resolving executable events completed.");
}
+ } catch (WorkflowException e) {
+ throw new RuntimeException(e);
}
- if (log.isDebugEnabled()) {
- log.debug(" Resolving executable events completed.");
- }
-
- return (Event[]) executableEvents.toArray(new Event[executableEvents.size()]);
+ return (String[]) executableEvents.toArray(new String[executableEvents.size()]);
}
- /** Invoke an event on this workflow instance.
- * @param situation The situation when the event was invoked.
- * @param event The event that was invoked.
- * @throws WorkflowException when the event may not be invoked.
+ /**
+ * @see org.apache.lenya.workflow.WorkflowInstance#invoke(org.apache.lenya.workflow.Situation,
+ * java.lang.String)
*/
- public void invoke(Situation situation, Event event)
- throws WorkflowException {
+ public void invoke(Situation situation, String event) throws WorkflowException {
+
if (!Arrays.asList(getExecutableEvents(situation)).contains(event)) {
- throw new WorkflowException("The event '" + event +
- "' cannot be invoked in the situation '" + situation + "'.");
+ throw new WorkflowException("The event '" + event
+ + "' cannot be invoked in the situation '" + situation + "'.");
}
- fire(getNextTransition(event));
+ TransitionImpl transition = getNextTransition(event);
+ fire(transition);
- for (Iterator iter = listeners.iterator(); iter.hasNext();) {
+ for (Iterator iter = this.listeners.iterator(); iter.hasNext();) {
WorkflowListener listener = (WorkflowListener) iter.next();
- listener.transitionFired(this, situation, event);
+ listener.transitionFired(this, situation, event, transition.getDestination());
}
}
@@ -134,25 +134,26 @@
* @return A transition.
* @throws WorkflowException if no single transition would fire.
*/
- protected TransitionImpl getNextTransition(Event event) throws WorkflowException {
+ protected TransitionImpl getNextTransition(String event) throws WorkflowException {
TransitionImpl nextTransition = null;
Transition[] transitions = getWorkflow().getLeavingTransitions(getCurrentState());
for (int i = 0; i < transitions.length; i++) {
- if (transitions[i].getEvent().equals(event)) {
-
+ if (transitions[i].getEvent().getName().equals(event)) {
+
if (nextTransition != null) {
- throw new WorkflowException("More than one transition found for event [" + event + "]!");
+ throw new WorkflowException("More than one transition found for event ["
+ + event + "]!");
}
-
+
nextTransition = (TransitionImpl) transitions[i];
}
}
-
+
if (nextTransition == null) {
throw new WorkflowException("No transition found for event [" + event + "]!");
}
-
+
return nextTransition;
}
@@ -167,56 +168,28 @@
for (int i = 0; i < actions.length; i++) {
actions[i].execute(this);
}
-
- setCurrentState(transition.getDestination());
}
- private State currentState;
-
/**
- * Sets the current state of this instance.
- * @param state The state to set.
- */
- protected void setCurrentState(State state) {
- this.currentState = state;
- }
-
- /** Returns the current state of this WorkflowInstance.
+ * Returns the current state of this WorkflowInstance.
* @return A state object.
*/
public State getCurrentState() {
- return currentState;
- }
- /**
- * Sets the workflow of this instance.
- * @param workflow A workflow object.
- */
- protected void setWorkflow(WorkflowImpl workflow) {
- this.workflow = workflow;
- setCurrentState(getWorkflow().getInitialState());
- initVariableInstances();
- }
-
- /**
- * Sets the workflow of this instance.
- * @param workflowName The identifier of the workflow.
- * @throws WorkflowException if something goes wrong.
- */
- protected void setWorkflow(String workflowName) throws WorkflowException {
- setWorkflow(getWorkflow(workflowName));
+ State state = null;
+ try {
+ if (getHistory().isInitialized()) {
+ state = getHistory().getLastState();
+ } else {
+ state = getWorkflow().getInitialState();
+ }
+ } catch (WorkflowException e) {
+ throw new RuntimeException(e);
+ }
+ return state;
}
/**
- * Factory method to create a workflow object for a given identifier.
- * @param workflowName The workflow identifier.
- * @return A workflow object.
- * @throws WorkflowException when the workflow could not be created.
- */
- protected abstract WorkflowImpl getWorkflow(String workflowName)
- throws WorkflowException;
-
- /**
* Returns a workflow state for a given name.
* @param id The state id.
* @return A workflow object.
@@ -250,22 +223,28 @@
* @throws WorkflowException when the variable instance was not found.
*/
protected BooleanVariableInstance getVariableInstance(BooleanVariable variable)
- throws WorkflowException {
- if (!variableInstances.containsKey(variable)) {
+ throws WorkflowException {
+ if (!this.variableInstances.containsKey(variable)) {
throw new WorkflowException("No instance for variable '" + variable.getName() + "'!");
}
- return (BooleanVariableInstance) variableInstances.get(variable);
+ return (BooleanVariableInstance) this.variableInstances.get(variable);
}
/**
* @see org.apache.lenya.workflow.WorkflowInstance#getValue(java.lang.String)
*/
- public boolean getValue(String variableName) throws WorkflowException {
- BooleanVariable variable = getWorkflowImpl().getVariable(variableName);
- BooleanVariableInstance instance = getVariableInstance(variable);
+ public boolean getValue(String variableName) {
+ boolean value = false;
+ try {
+ BooleanVariable variable = getWorkflowImpl().getVariable(variableName);
+ BooleanVariableInstance instance = getVariableInstance(variable);
+ value = instance.getValue();
+ } catch (WorkflowException e) {
+ throw new RuntimeException(e);
+ }
- return instance.getValue();
+ return value;
}
/**
@@ -274,8 +253,7 @@
* @param value The value to set.
* @throws WorkflowException when the variable was not found.
*/
- protected void setValue(String variableName, boolean value)
- throws WorkflowException {
+ protected void setValue(String variableName, boolean value) throws WorkflowException {
BooleanVariable variable = getWorkflowImpl().getVariable(variableName);
BooleanVariableInstance instance = getVariableInstance(variable);
instance.setValue(value);
@@ -300,11 +278,18 @@
}
/**
- * @see org.apache.lenya.workflow.WorkflowInstance#isSynchronized(org.apache.lenya.workflow.Event)
+ * @see org.apache.lenya.workflow.WorkflowInstance#isSynchronized(String)
*/
- public boolean isSynchronized(Event event) throws WorkflowException {
+ public boolean isSynchronized(String event) throws WorkflowException {
Transition nextTransition = getNextTransition(event);
return nextTransition.isSynchronized();
}
-}
+ /**
+ * @see org.apache.lenya.workflow.WorkflowInstance#canInvoke(org.apache.lenya.workflow.Situation,
+ * java.lang.String)
+ */
+ public boolean canInvoke(Situation situation, String event) {
+ return Arrays.asList(getExecutableEvents(situation)).contains(event);
+ }
+}
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@lenya.apache.org
For additional commands, e-mail: commits-help@lenya.apache.org