?? token.java
字號(hào):
li.addLog(processLog);
}
}
/**
* convenience method for starting a composite log. When you add composite logs,
* make sure you put the {@link #endCompositeLog()} in a finally block.
*/
public void startCompositeLog(CompositeLog compositeLog) {
LoggingInstance li = (LoggingInstance) processInstance.getInstance(LoggingInstance.class);
if (li != null) {
compositeLog.setToken(this);
li.startCompositeLog(compositeLog);
}
}
/**
* convenience method for ending a composite log. Make sure you put this in a finally block.
*/
public void endCompositeLog() {
LoggingInstance li = (LoggingInstance) processInstance.getInstance(LoggingInstance.class);
if (li != null) {
li.endCompositeLog();
}
}
// various information extraction methods ///////////////////////////////////
public String toString() {
return "Token("+getFullName()+")";
}
public boolean hasEnded() {
return (end != null);
}
public boolean isRoot() {
return (parent == null);
}
public boolean hasParent() {
return (parent != null);
}
public boolean hasChild(String name) {
return (children != null ? children.containsKey(name) : false);
}
public Token getChild(String name) {
Token child = null;
if (children != null) {
child = (Token) children.get(name);
}
return child;
}
public String getFullName() {
if (parent==null) return "/";
if (parent.getParent()==null) return "/"+name;
return parent.getFullName()+"/"+name;
}
public List getChildrenAtNode(Node aNode) {
List foundChildren = new ArrayList();
getChildrenAtNode(aNode, foundChildren);
return foundChildren;
}
void getChildrenAtNode(Node aNode, List foundTokens) {
if(aNode.equals(node)) {
foundTokens.add(this);
}
else if(children != null && !children.isEmpty()) {
for(Iterator it = children.values().iterator(); it.hasNext();) {
Token aChild = (Token)it.next();
aChild.getChildrenAtNode(aNode, foundTokens);
}
}
}
public void collectChildrenRecursively(List tokens) {
if (children!=null) {
Iterator iter = children.values().iterator();
while (iter.hasNext()) {
Token child = (Token) iter.next();
tokens.add(child);
child.collectChildrenRecursively(tokens);
}
}
}
public Token findToken(String relativeTokenPath) {
if (relativeTokenPath == null)
return null;
String path = relativeTokenPath.trim();
if (("".equals(path)) || (".".equals(path))) {
return this;
}
if ("..".equals(path)) {
return parent;
}
if (path.startsWith("/")) {
Token root = processInstance.getRootToken();
return root.findToken(path.substring(1));
}
if (path.startsWith("./")) {
return findToken(path.substring(2));
}
if (path.startsWith("../")) {
if (parent != null) {
return parent.findToken(path.substring(3));
}
return null;
}
int slashIndex = path.indexOf('/');
if (slashIndex == -1) {
return (Token) (children != null ? children.get(path) : null);
}
Token token = null;
String name = path.substring(0, slashIndex);
token = (Token) children.get(name);
if (token != null) {
return token.findToken(path.substring(slashIndex + 1));
}
return null;
}
public Map getActiveChildren() {
Map activeChildren = new HashMap();
if (children != null) {
Iterator iter = children.entrySet().iterator();
while (iter.hasNext()) {
Map.Entry entry = (Map.Entry) iter.next();
Token child = (Token) entry.getValue();
if (!child.hasEnded()) {
String childName = (String) entry.getKey();
activeChildren.put(childName, child);
}
}
}
return activeChildren;
}
public void checkImplicitTermination() {
if (isTerminationImplicit && node.hasNoLeavingTransitions()) {
end();
if (processInstance.isTerminatedImplicitly()) {
processInstance.end();
}
}
}
public boolean isTerminatedImplicitly() {
if (end != null) return true;
Map leavingTransitions = node.getLeavingTransitionsMap();
if ((leavingTransitions != null) && (leavingTransitions.size() > 0)) {
// ok: found a non-terminated token
return false;
}
// loop over all active child tokens
Iterator iter = getActiveChildren().values().iterator();
while (iter.hasNext()) {
Token child = (Token) iter.next();
if (!child.isTerminatedImplicitly()) {
return false;
}
}
// if none of the above, this token is terminated implicitly
return true;
}
public int nextLogIndex() {
return nextLogIndex++;
}
/**
* suspends a process execution.
*/
public void suspend() {
isSuspended = true;
suspendJobs();
suspendTaskInstances();
// propagate to child tokens
if (children!=null) {
Iterator iter = children.values().iterator();
while (iter.hasNext()) {
Token child = (Token) iter.next();
}
}
}
void suspendJobs() {
JbpmContext jbpmContext = JbpmContext.getCurrentJbpmContext();
JobSession jobSession = (jbpmContext!=null ? jbpmContext.getJobSession() : null);
if (jobSession!=null) {
jobSession.suspendJobs(this);
}
}
void suspendTaskInstances() {
TaskMgmtInstance taskMgmtInstance = (processInstance!=null ? processInstance.getTaskMgmtInstance() : null);
if (taskMgmtInstance!=null) {
taskMgmtInstance.suspend(this);
}
}
/**
* resumes a process execution.
*/
public void resume() {
isSuspended = false;
resumeJobs();
resumeTaskInstances();
// propagate to child tokens
if (children!=null) {
Iterator iter = children.values().iterator();
while (iter.hasNext()) {
Token child = (Token) iter.next();
child.resume();
}
}
}
void resumeJobs() {
JbpmContext jbpmContext = JbpmContext.getCurrentJbpmContext();
JobSession jobSession = (jbpmContext!=null ? jbpmContext.getJobSession() : null);
if (jobSession!=null) {
jobSession.resumeJobs(this);
}
}
void resumeTaskInstances() {
TaskMgmtInstance taskMgmtInstance = (processInstance!=null ? processInstance.getTaskMgmtInstance() : null);
if (taskMgmtInstance!=null) {
taskMgmtInstance.resume(this);
}
}
// equals ///////////////////////////////////////////////////////////////////
// hack to support comparing hibernate proxies against the real objects
// since this always falls back to ==, we don't need to overwrite the hashcode
public boolean equals(Object o) {
return EqualsUtil.equals(this, o);
}
public ProcessInstance createSubProcessInstance(ProcessDefinition subProcessDefinition) {
// create the new sub process instance
subProcessInstance = new ProcessInstance(subProcessDefinition);
// bind the subprocess to the super-process-token
setSubProcessInstance(subProcessInstance);
subProcessInstance.setSuperProcessToken(this);
// make sure the process gets saved during super process save
processInstance.addCascadeProcessInstance(subProcessInstance);
return subProcessInstance;
}
/**
* locks a process instance for further execution. A locked token
* cannot continue execution. This is a non-persistent
* operation. This is used to prevent tokens being propagated during
* the execution of actions.
* @see #unlock(String)
*/
public void lock(String lockOwnerId) {
if (lockOwnerId==null) {
throw new JbpmException("can't lock with null value for the lockOwnerId");
}
if ( (lock!=null)
&& (!lock.equals(lockOwnerId))
) {
throw new JbpmException("token '"+id+"' can't be locked by '"+lockOwnerId+"' cause it's already locked by '"+lock+"'");
}
log.debug("token["+id+"] is locked by "+lockOwnerId);
lock = lockOwnerId;
}
/**
* @see #lock(String)
*/
public void unlock(String lockOwnerId) {
if (lock==null) {
log.warn("lock owner '"+lockOwnerId+"' tries to unlock token '"+id+"' which is not locked");
} else if (!lock.equals(lockOwnerId)) {
throw new JbpmException("'"+lockOwnerId+"' can't unlock token '"+id+"' because it was already locked by '"+lock+"'");
}
log.debug("token["+id+"] is unlocked by "+lockOwnerId);
lock = null;
}
public boolean isLocked() {
return lock!=null;
}
// getters and setters //////////////////////////////////////////////////////
public long getId() {
return id;
}
public Date getStart() {
return start;
}
public Date getEnd() {
return end;
}
public String getName() {
return name;
}
public ProcessInstance getProcessInstance() {
return processInstance;
}
public Map getChildren() {
return children;
}
public Node getNode() {
return node;
}
public void setNode(Node node) {
this.node = node;
}
public Token getParent() {
return parent;
}
public void setParent(Token parent) {
this.parent = parent;
}
public void setProcessInstance(ProcessInstance processInstance) {
this.processInstance = processInstance;
}
public ProcessInstance getSubProcessInstance() {
return subProcessInstance;
}
public Date getNodeEnter() {
return nodeEnter;
}
public void setNodeEnter(Date nodeEnter) {
this.nodeEnter = nodeEnter;
}
public boolean isAbleToReactivateParent() {
return isAbleToReactivateParent;
}
public void setAbleToReactivateParent(boolean isAbleToReactivateParent) {
this.isAbleToReactivateParent = isAbleToReactivateParent;
}
public boolean isTerminationImplicit() {
return isTerminationImplicit;
}
public void setTerminationImplicit(boolean isTerminationImplicit) {
this.isTerminationImplicit = isTerminationImplicit;
}
public boolean isSuspended() {
return isSuspended;
}
public void setSubProcessInstance(ProcessInstance subProcessInstance) {
this.subProcessInstance = subProcessInstance;
}
private static final Log log = LogFactory.getLog(Token.class);
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -