1 package org.jbpm.bpel.service.def; 2 3 import java.io.Serializable ; 4 5 import org.jbpm.context.exe.ContextInstance; 6 import org.jbpm.graph.exe.Token; 7 8 import org.jbpm.bpel.service.exe.PartnerLinkInstance; 9 import org.jbpm.bpel.wsdl.def.PartnerLinkType; 10 import org.jbpm.bpel.wsdl.def.PartnerLinkType.Role; 11 12 16 public class PartnerLinkDefinition implements Serializable { 17 18 private long id; 19 private String name; 20 private PartnerLinkType partnerLinkType; 21 private boolean partnerRoleIsFirst; 22 23 private static final String PLINK_PREFIX = "p_"; 24 private static final long serialVersionUID = 1L; 25 26 public PartnerLinkDefinition() { 27 } 28 29 public String getName() { 30 return name; 31 } 32 33 public void setName(String name) { 34 this.name = name; 35 } 36 37 public PartnerLinkType getPartnerLinkType() { 38 return partnerLinkType; 39 } 40 41 public void setPartnerLinkType(PartnerLinkType partnerLinkType) { 42 this.partnerLinkType = partnerLinkType; 43 } 44 45 public Role getPartnerRole() { 46 return partnerLinkType != null ? 47 partnerRoleIsFirst ? 48 partnerLinkType.getFirstRole() 49 : partnerLinkType.getSecondRole() 50 : null; 51 } 52 53 public void setPartnerRole(Role partnerRole) { 54 if (partnerLinkType == null) 55 throw new IllegalStateException ("set the partner link type before the roles"); 56 57 partnerRoleIsFirst = partnerRole == partnerLinkType.getFirstRole(); 58 } 59 60 public Role getMyRole() { 61 return partnerLinkType != null ? 62 partnerRoleIsFirst ? 63 partnerLinkType.getSecondRole() 64 : partnerLinkType.getFirstRole() 65 : null; 66 } 67 68 public void setMyRole(Role myRole) { 69 if (partnerLinkType == null) 70 throw new IllegalStateException ("set the partner link type before the roles"); 71 72 partnerRoleIsFirst = myRole != partnerLinkType.getFirstRole(); 73 } 74 75 public long getId() { 76 return id; 77 } 78 79 public void setId(long id) { 80 this.id = id; 81 } 82 83 public PartnerLinkInstance createInstance(Token token) { 84 PartnerLinkInstance instance = new PartnerLinkInstance(); 85 instance.setDefinition(this); 86 ContextInstance context = token.getProcessInstance().getContextInstance(); 87 context.createVariable(PLINK_PREFIX + name, instance, token); 88 return instance; 89 } 90 91 public PartnerLinkInstance getInstance(Token token) { 92 ContextInstance context = token.getProcessInstance().getContextInstance(); 93 return (PartnerLinkInstance) context.getVariable(PLINK_PREFIX + name, token); 94 } 95 } 96 | Popular Tags |