[jbpm-commits] JBoss JBPM SVN: r4577 - in jbpm4/trunk/modules: api/src/main/java/org/jbpm/api/model and 6 other directories.
do-not-reply at jboss.org
do-not-reply at jboss.org
Fri Apr 17 16:12:41 EDT 2009
Author: tom.baeyens at jboss.com
Date: 2009-04-17 16:12:41 -0400 (Fri, 17 Apr 2009)
New Revision: 4577
Added:
jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/model/ActivityCoordinates.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/GetActivityCoordinates.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/ActivityCoordinatesImpl.java
jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/process/ActivityCoordinatesTest.java
Removed:
jbpm4/trunk/modules/examples/src/test/resources/org/jbpm/examples/states/
Modified:
jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/RepositoryService.java
jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/xml/JpdlParser.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/ActivityImpl.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/CompositeElementImpl.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/repository/RepositoryServiceImpl.java
Log:
JBPM-2177 added activity coordinates retrieval through api
Modified: jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/RepositoryService.java
===================================================================
--- jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/RepositoryService.java 2009-04-17 15:36:53 UTC (rev 4576)
+++ jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/RepositoryService.java 2009-04-17 20:12:41 UTC (rev 4577)
@@ -23,7 +23,9 @@
import java.io.InputStream;
+import org.jbpm.api.model.ActivityCoordinates;
+
/**
* @author Tom Baeyens
*/
@@ -37,5 +39,7 @@
InputStream getResourceAsStream(long deploymentDbid, String resourceName);
ProcessDefinitionQuery createProcessDefinitionQuery();
+
+ ActivityCoordinates getActivityCoordinates(String processDefinitionId, String activityName);
}
Added: jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/model/ActivityCoordinates.java
===================================================================
--- jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/model/ActivityCoordinates.java (rev 0)
+++ jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/model/ActivityCoordinates.java 2009-04-17 20:12:41 UTC (rev 4577)
@@ -0,0 +1,38 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jbpm.api.model;
+
+/** activity coordinates indicating the graphical position in the diagram.
+ *
+ * @author Tom Baeyens
+ */
+public interface ActivityCoordinates {
+
+ int getX();
+
+ int getY();
+
+ int getWidth();
+
+ int getHeight();
+
+}
\ No newline at end of file
Property changes on: jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/model/ActivityCoordinates.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/xml/JpdlParser.java
===================================================================
--- jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/xml/JpdlParser.java 2009-04-17 15:36:53 UTC (rev 4576)
+++ jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/xml/JpdlParser.java 2009-04-17 20:12:41 UTC (rev 4577)
@@ -29,6 +29,7 @@
import java.util.Enumeration;
import java.util.List;
import java.util.Set;
+import java.util.StringTokenizer;
import org.jbpm.api.activity.ActivityBehaviour;
import org.jbpm.api.env.Environment;
@@ -36,6 +37,7 @@
import org.jbpm.internal.log.Log;
import org.jbpm.jpdl.internal.activity.JpdlBinding;
import org.jbpm.jpdl.internal.model.JpdlProcessDefinition;
+import org.jbpm.pvm.internal.model.ActivityCoordinatesImpl;
import org.jbpm.pvm.internal.model.ActivityImpl;
import org.jbpm.pvm.internal.model.EventImpl;
import org.jbpm.pvm.internal.model.ObservableElementImpl;
@@ -234,16 +236,37 @@
parseOnEvents(element, parse, activity);
+ String g = XmlUtil.attribute(element, "g");
+ if (g!=null) {
+ StringTokenizer stringTokenizer = new StringTokenizer(g, ",");
+ ActivityCoordinatesImpl coordinates = null;
+ if (stringTokenizer.countTokens()==4) {
+ try {
+ int x = Integer.parseInt(stringTokenizer.nextToken());
+ int y = Integer.parseInt(stringTokenizer.nextToken());
+ int width = Integer.parseInt(stringTokenizer.nextToken());
+ int height = Integer.parseInt(stringTokenizer.nextToken());
+ coordinates = new ActivityCoordinatesImpl(x, y, width, height);
+ } catch (NumberFormatException e) {
+ coordinates = null;
+ }
+ }
+ if (coordinates!=null) {
+ activity.setCoordinates(coordinates);
+ } else {
+ parse.addProblem("invalid coordinates g=\""+g+"\" in "+activity);
+ }
+ }
} finally {
parse.popObject();
}
} else {
log.debug("unrecognized activity: "+XmlUtil.getTagLocalName(element));
}
+ }
}
- }
}
-
+
public TimerDefinitionImpl parseTimerDefinition(Element timerElement, Parse parse, ScopeElementImpl scopeElement) {
TimerDefinitionImpl timerDefinition = scopeElement.createTimerDefinition();
Added: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/GetActivityCoordinates.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/GetActivityCoordinates.java (rev 0)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/GetActivityCoordinates.java 2009-04-17 20:12:41 UTC (rev 4577)
@@ -0,0 +1,60 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jbpm.pvm.internal.cmd;
+
+import org.jbpm.api.JbpmException;
+import org.jbpm.api.cmd.Command;
+import org.jbpm.api.env.Environment;
+import org.jbpm.api.model.ActivityCoordinates;
+import org.jbpm.api.session.RepositorySession;
+import org.jbpm.pvm.internal.model.ActivityImpl;
+import org.jbpm.pvm.internal.model.ProcessDefinitionImpl;
+
+
+/**
+ * @author Tom Baeyens
+ */
+public class GetActivityCoordinates implements Command<ActivityCoordinates> {
+
+ private static final long serialVersionUID = 1L;
+
+ String processDefinitionId;
+ String activityName;
+
+ public GetActivityCoordinates(String processDefinitionId, String activityName) {
+ this.processDefinitionId = processDefinitionId;
+ this.activityName = activityName;
+ }
+
+ public ActivityCoordinates execute(Environment environment) throws Exception {
+ RepositorySession repositorySession = environment.get(RepositorySession.class);
+ ProcessDefinitionImpl processDefinition = (ProcessDefinitionImpl) repositorySession.loadProcessDefinitionById(processDefinitionId);
+ if (processDefinition==null) {
+ throw new JbpmException("process definition "+processDefinitionId+" doesn't exist");
+ }
+ ActivityImpl activity = processDefinition.findActivity(activityName);
+ if (activity==null) {
+ throw new JbpmException("activity '"+activityName+"' doesn't exist in process definition "+processDefinitionId);
+ }
+ return activity.getCoordinates();
+ }
+}
Property changes on: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/GetActivityCoordinates.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/ActivityCoordinatesImpl.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/ActivityCoordinatesImpl.java (rev 0)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/ActivityCoordinatesImpl.java 2009-04-17 20:12:41 UTC (rev 4577)
@@ -0,0 +1,63 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jbpm.pvm.internal.model;
+
+import java.io.Serializable;
+
+import org.jbpm.api.model.ActivityCoordinates;
+
+
+/**
+ * @author Tom Baeyens
+ */
+public class ActivityCoordinatesImpl implements Serializable, ActivityCoordinates {
+
+ private static final long serialVersionUID = 1L;
+
+ int x;
+ int y;
+ int width;
+ int height;
+
+ public ActivityCoordinatesImpl(int x, int y, int width, int height) {
+ this.x = x;
+ this.y = y;
+ this.width = width;
+ this.height = height;
+ }
+
+ public int getX() {
+ return x;
+ }
+
+ public int getY() {
+ return y;
+ }
+
+ public int getWidth() {
+ return width;
+ }
+
+ public int getHeight() {
+ return height;
+ }
+}
Property changes on: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/ActivityCoordinatesImpl.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/ActivityImpl.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/ActivityImpl.java 2009-04-17 15:36:53 UTC (rev 4576)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/ActivityImpl.java 2009-04-17 20:12:41 UTC (rev 4577)
@@ -50,6 +50,8 @@
protected boolean isSignalAsync;
protected boolean isLeaveAsync;
protected boolean isPreviousNeeded;
+
+ protected ActivityCoordinatesImpl coordinates;
transient protected Map<String, TransitionImpl> outgoingTransitionsMap;
@@ -483,4 +485,10 @@
public void setType(String type) {
this.type = type;
}
+ public ActivityCoordinatesImpl getCoordinates() {
+ return coordinates;
+ }
+ public void setCoordinates(ActivityCoordinatesImpl coordinates) {
+ this.coordinates = coordinates;
+ }
}
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/CompositeElementImpl.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/CompositeElementImpl.java 2009-04-17 15:36:53 UTC (rev 4576)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/CompositeElementImpl.java 2009-04-17 20:12:41 UTC (rev 4577)
@@ -139,7 +139,7 @@
* Beware: the actual member is returned. No copy is made.
*/
public Map<String, Activity> getActivitiesMap() {
- if(activitiesMap == null){
+ if (activitiesMap == null) {
this.activitiesMap = ActivityImpl.getActivitiesMap(activities);
}
return (Map) activitiesMap;
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/repository/RepositoryServiceImpl.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/repository/RepositoryServiceImpl.java 2009-04-17 15:36:53 UTC (rev 4576)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/repository/RepositoryServiceImpl.java 2009-04-17 20:12:41 UTC (rev 4577)
@@ -27,7 +27,9 @@
import org.jbpm.api.ProcessDefinitionQuery;
import org.jbpm.api.RepositoryService;
import org.jbpm.api.cmd.CommandService;
+import org.jbpm.api.model.ActivityCoordinates;
import org.jbpm.pvm.internal.cmd.DeleteDeploymentCmd;
+import org.jbpm.pvm.internal.cmd.GetActivityCoordinates;
import org.jbpm.pvm.internal.cmd.GetResourceAsStreamCmd;
import org.jbpm.pvm.internal.query.ProcessDefinitionQueryImpl;
@@ -58,4 +60,7 @@
return new ProcessDefinitionQueryImpl(commandService);
}
+ public ActivityCoordinates getActivityCoordinates(String processDefinitionId, String activityName) {
+ return commandService.execute(new GetActivityCoordinates(processDefinitionId, activityName));
+ }
}
Added: jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/process/ActivityCoordinatesTest.java
===================================================================
--- jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/process/ActivityCoordinatesTest.java (rev 0)
+++ jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/process/ActivityCoordinatesTest.java 2009-04-17 20:12:41 UTC (rev 4577)
@@ -0,0 +1,73 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jbpm.test.process;
+
+import org.jbpm.api.model.ActivityCoordinates;
+import org.jbpm.test.JbpmTestCase;
+
+
+/**
+ * @author Tom Baeyens
+ */
+public class ActivityCoordinatesTest extends JbpmTestCase {
+
+ public void testActivityCoordinates() {
+ deployJpdlXmlString(
+ "<process name='ActivityCoordinatesProcess'>" +
+ " <start>" +
+ " <transition to='a' />" +
+ " </start>" +
+ " <state name='a' g='96,16,75,52' />" +
+ "</process>"
+ );
+
+ String processDefinitionId = repositoryService.createProcessDefinitionQuery()
+ .key("ActivityCoordinatesProcess")
+ .uniqueResult()
+ .getId();
+
+ ActivityCoordinates activityCoordinates = repositoryService.getActivityCoordinates(processDefinitionId, "a");
+ assertEquals(96, activityCoordinates.getX());
+ assertEquals(16, activityCoordinates.getY());
+ assertEquals(75, activityCoordinates.getWidth());
+ assertEquals(52, activityCoordinates.getHeight());
+ }
+
+ public void testUnexistingCoordinates() {
+ deployJpdlXmlString(
+ "<process name='ActivityCoordinatesProcess'>" +
+ " <start>" +
+ " <transition to='a' />" +
+ " </start>" +
+ " <state name='a' />" +
+ "</process>"
+ );
+
+ String processDefinitionId = repositoryService.createProcessDefinitionQuery()
+ .key("ActivityCoordinatesProcess")
+ .uniqueResult()
+ .getId();
+
+ ActivityCoordinates activityCoordinates = repositoryService.getActivityCoordinates(processDefinitionId, "a");
+ assertNull(activityCoordinates);
+ }
+}
Property changes on: jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/process/ActivityCoordinatesTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
More information about the jbpm-commits
mailing list