KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jbpm > bpel > xml > CompensateReader


1 package org.jbpm.bpel.xml;
2
3 import org.w3c.dom.Element JavaDoc;
4
5 import org.jbpm.bpel.def.Activity;
6 import org.jbpm.bpel.def.Compensate;
7 import org.jbpm.bpel.def.CompositeActivity;
8 import org.jbpm.bpel.def.Scope;
9 import org.jbpm.jpdl.xml.Problem;
10
11 import com.ibm.wsdl.util.xml.DOMUtils;
12
13 /**
14  * @author Juan Cantú
15  * @version $Revision: 1.4 $ $Date: 2005/06/23 20:45:04 $
16  */

17 public class CompensateReader extends ActivityReader {
18
19   public Activity createActivity() {
20     return new Compensate();
21   }
22   
23   public void readActivity(Activity activity, Element JavaDoc element) {
24     Compensate compensate = (Compensate) activity;
25     CompositeActivity parent = compensate.getCompositeActivity();
26     
27     String JavaDoc scopeName = DOMUtils.getAttribute(element, BpelConstants.ATTR_SCOPE);
28     
29     if(scopeName != null) {
30       Scope scope = (Scope) getScope(parent).findChild(scopeName);
31       if(scope == null) {
32         bpelReader.getProblemHandler().add(
33             new LocalizedProblem(Problem.LEVEL_ERROR, "scope not found", element) );
34         return;
35       }
36       compensate.setScope(scope);
37     }
38     else {
39       compensate.setScope(getScope(parent));
40     }
41   }
42   
43   private Scope getScope(CompositeActivity compositeActivity) {
44     while(true) {
45       if (compositeActivity instanceof Scope) return (Scope) compositeActivity;
46       compositeActivity = compositeActivity.getCompositeActivity();
47     }
48   }
49 }
50
Popular Tags