This repository has been archived by the owner on Jan 10, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* git ist völlig beknackt - Amokgit!
- Loading branch information
jan.rehwaldt
committed
May 25, 2011
1 parent
9d357d7
commit 8e0a2e4
Showing
7 changed files
with
442 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
test-output | ||
target | ||
bin | ||
reports | ||
logs | ||
/engine-demo/.project | ||
test-output | ||
target | ||
bin | ||
reports | ||
logs |
109 changes: 109 additions & 0 deletions
109
engine-core-impl/src/main/java/org/jodaengine/util/juel/ProcessELContext.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
package org.jodaengine.util.juel; | ||
|
||
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import javax.annotation.Nonnull; | ||
import javax.el.ExpressionFactory; | ||
import javax.el.ValueExpression; | ||
import javax.el.VariableMapper; | ||
|
||
import org.jodaengine.process.instance.ProcessInstanceContext; | ||
|
||
import de.odysseus.el.ExpressionFactoryImpl; | ||
import de.odysseus.el.util.SimpleContext; | ||
|
||
/** | ||
* This is a Juel {@link javax.el.ELContext} implementation, which is able to work | ||
* with our {@link ProcessInstanceContext}. | ||
* | ||
* @author Jan Rehwaldt | ||
* @since 20111-05-20 | ||
*/ | ||
public class ProcessELContext extends SimpleContext { | ||
|
||
private ProcessInstanceContext instanceContext; | ||
private ExpressionFactory expressionFactory; | ||
|
||
private Variables variables; | ||
|
||
/** | ||
* Constructs a {@link ProcessELContext} using an {@link ProcessInstanceContext} | ||
* for variable resolution. | ||
* | ||
* @param instanceContext the instance's context | ||
*/ | ||
public ProcessELContext(@Nonnull ProcessInstanceContext instanceContext) { | ||
super(); | ||
this.instanceContext = instanceContext; | ||
this.expressionFactory = new ExpressionFactoryImpl(); | ||
|
||
} | ||
|
||
@Override | ||
public VariableMapper getVariableMapper() { | ||
if (this.variables == null) { | ||
this.variables = new Variables(); | ||
} | ||
return this.variables; | ||
} | ||
|
||
@Override | ||
public ValueExpression setVariable(String variable, ValueExpression expression) { | ||
return getVariableMapper().setVariable(variable, expression); | ||
} | ||
|
||
/** | ||
* Our {@link ProcessInstanceContext}-aware {@link VariableMapper}. | ||
*/ | ||
class Variables extends VariableMapper { | ||
|
||
/** | ||
* We need this map so we can | ||
* <ul> | ||
* <li> | ||
* a) always return the same ValueExpression instance for the same variable | ||
* </li> | ||
* <li> | ||
* and | ||
* b) allow overriding variables by setting them explicitly. | ||
* </li> | ||
* </ul> | ||
*/ | ||
private Map<String, ValueExpression> map = Collections.emptyMap(); | ||
|
||
@Override | ||
public ValueExpression resolveVariable(String variable) { | ||
|
||
// | ||
// check the map if we already have a mapping resolved | ||
// | ||
if (this.map.containsKey(variable)) { | ||
return this.map.get(variable); | ||
} | ||
|
||
// | ||
// check the context and bind the resolved value into our map | ||
// | ||
Object contextValue = instanceContext.getVariable(variable); | ||
|
||
ValueExpression valueExpression = null; | ||
if (contextValue != null) { | ||
valueExpression = expressionFactory.createValueExpression(contextValue, contextValue.getClass()); | ||
} | ||
setVariable(variable, valueExpression); | ||
|
||
return valueExpression; | ||
} | ||
|
||
@Override | ||
public ValueExpression setVariable(String variable, ValueExpression expression) { | ||
if (this.map.isEmpty()) { | ||
this.map = new HashMap<String, ValueExpression>(); | ||
} | ||
|
||
return this.map.put(variable, expression); | ||
} | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
engine-ext-debugger/src/main/java/org/jodaengine/ext/debugging/api/Breakpoint.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package org.jodaengine.ext.debugging.api; | ||
|
||
import javax.annotation.Nonnull; | ||
|
||
import org.jodaengine.process.structure.Node; | ||
import org.jodaengine.process.token.Token; | ||
|
||
/** | ||
* This represents a container class for a breakpoint, which will be available in the | ||
* {@link Node} attribute set. Static getter methods are provided within this class. | ||
* | ||
* @author Jan Rehwaldt | ||
* @since 2011-05-24 | ||
*/ | ||
public interface Breakpoint { | ||
|
||
/** | ||
* Returns the {@link Node} this breakpoint is bound to. | ||
* | ||
* @return a node | ||
*/ | ||
@Nonnull Node getNode(); | ||
|
||
/** | ||
* Sets a {@link BreakpointCondition}, which is considered when evaluating whether | ||
* this breakpoint matches to a {@link Token} state. | ||
* | ||
* @param condition a condition | ||
*/ | ||
void setCondition(@Nonnull BreakpointCondition condition); | ||
|
||
/** | ||
* Checks whether the breakpoint will match the current token state. | ||
* | ||
* Properly considers any eventually defined condition. | ||
* | ||
* @param token the token | ||
* @return a boolean, whether this token is matched by this breakpoint | ||
*/ | ||
boolean matches(@Nonnull Token token); | ||
} |
25 changes: 25 additions & 0 deletions
25
engine-ext-debugger/src/main/java/org/jodaengine/ext/debugging/api/BreakpointCondition.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package org.jodaengine.ext.debugging.api; | ||
|
||
import javax.annotation.Nonnull; | ||
|
||
import org.jodaengine.process.token.Token; | ||
|
||
/** | ||
* This interface represents a condition, which may be attached to a {@link Breakpoint}. | ||
* | ||
* @author Jan Rehwaldt | ||
* @since 2011-05-24 | ||
*/ | ||
public interface BreakpointCondition { | ||
|
||
/** | ||
* When this method is called the condition needs to be evaluated. | ||
* If it evaluates to true this is returned, false respectively. | ||
* | ||
* True is furthermore returned if the condition fails to be evaluated. | ||
* | ||
* @param token the token | ||
* @return whether the condition is true | ||
*/ | ||
boolean evaluate(@Nonnull Token token); | ||
} |
116 changes: 116 additions & 0 deletions
116
engine-ext-debugger/src/main/java/org/jodaengine/ext/debugging/shared/BreakpointImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
package org.jodaengine.ext.debugging.shared; | ||
|
||
import javax.annotation.Nonnull; | ||
import javax.annotation.Nullable; | ||
|
||
import org.jodaengine.ext.debugging.api.Breakpoint; | ||
import org.jodaengine.ext.debugging.api.BreakpointCondition; | ||
import org.jodaengine.process.structure.Node; | ||
import org.jodaengine.process.token.Token; | ||
|
||
/** | ||
* This represents a container class for a {@link Breakpoint}, which will be available in the | ||
* {@link Node} attribute set. Static getter methods are provided within this class. | ||
* | ||
* @author Jan Rehwaldt | ||
* @since 2011-05-24 | ||
*/ | ||
public class BreakpointImpl extends DebuggerAttribute implements Breakpoint { | ||
|
||
private final Node node; | ||
private BreakpointCondition condition; | ||
|
||
/** | ||
* Default constructor. Creates a new {@link Breakpoint}, which will be enabled by default | ||
* and bound to a specified {@link Node}. | ||
* | ||
* @param node the node, this breakpoint is bound to | ||
*/ | ||
protected BreakpointImpl(@Nonnull Node node) { | ||
super(); | ||
this.node = node; | ||
this.condition = null; | ||
enable(); | ||
} | ||
|
||
@Override | ||
public Node getNode() { | ||
return node; | ||
} | ||
|
||
@Override | ||
public void setCondition(BreakpointCondition condition) { | ||
this.condition = condition; | ||
} | ||
|
||
@Override | ||
public boolean matches(Token token) { | ||
|
||
// | ||
// is this breakpoint enabled? | ||
// | ||
if (!this.isEnabled()) { | ||
return false; | ||
} | ||
|
||
// | ||
// does the token's position match (which node?) | ||
// | ||
if (token.getCurrentNode().equals(this.node)) { | ||
|
||
// | ||
// no condition attached? | ||
// | ||
if (this.condition == null) { | ||
return true; | ||
} | ||
|
||
// | ||
// condition attached: does it match? | ||
// | ||
if (this.condition.evaluate(token)) { | ||
return true; | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
|
||
|
||
/** | ||
* Returns a {@link BreakpointImpl} instance related to the provided | ||
* {@link Node}. If none exists, a new one is created and associated | ||
* with the definition. | ||
* | ||
* Default breakpoints will be enabled. | ||
* | ||
* @param node the {@link Node}, the attribute is related to | ||
* @return an attribute instance, null if none provided | ||
*/ | ||
public static @Nonnull BreakpointImpl getAttribute(@Nonnull Node node) { | ||
|
||
BreakpointImpl breakpoint = getAttributeIfExists(node); | ||
|
||
// | ||
// register a new instance | ||
// | ||
if (breakpoint == null) { | ||
breakpoint = new BreakpointImpl(node); | ||
node.setAttribute(ATTRIBUTE_KEY, breakpoint); | ||
} | ||
|
||
return breakpoint; | ||
} | ||
|
||
/** | ||
* Returns a {@link BreakpointImpl} instance related to the provided | ||
* {@link Node}. If none exists, null is returned. | ||
* | ||
* @param node the {@link Node}, the attribute is related to | ||
* @return an attribute instance, null if none provided | ||
*/ | ||
public static @Nullable BreakpointImpl getAttributeIfExists(@Nonnull Node node) { | ||
|
||
return (BreakpointImpl) node.getAttribute(ATTRIBUTE_KEY); | ||
} | ||
} |
86 changes: 86 additions & 0 deletions
86
engine-ext-debugger/src/main/java/org/jodaengine/ext/debugging/shared/DebuggerAttribute.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package org.jodaengine.ext.debugging.shared; | ||
|
||
import java.util.UUID; | ||
|
||
import javax.annotation.Nonnull; | ||
|
||
import org.jodaengine.process.definition.ProcessDefinition; | ||
import org.jodaengine.util.Identifiable; | ||
|
||
/** | ||
* This represents a container class, which will be available in the {@link ProcessDefinition} | ||
* attribute set. A static getter method is provided within this class. | ||
* | ||
* @author Jan Rehwaldt | ||
* @since 2011-05-24 | ||
*/ | ||
public class DebuggerAttribute implements Identifiable<UUID> { | ||
|
||
protected static final String ATTRIBUTE_KEY = "extension-debugger-attribute"; | ||
|
||
private boolean enabled; | ||
private final UUID id; | ||
|
||
/** | ||
* Creates a new instance. Debugging is disabled by default. | ||
*/ | ||
public DebuggerAttribute() { | ||
this.id = UUID.randomUUID(); | ||
disable(); | ||
} | ||
|
||
@Override | ||
public UUID getID() { | ||
return this.id; | ||
} | ||
|
||
/** | ||
* Disable debugging for this debugging element. | ||
*/ | ||
public void disable() { | ||
this.enabled = false; | ||
} | ||
|
||
/** | ||
* Enable debugging for this debugging element. | ||
*/ | ||
public void enable() { | ||
this.enabled = true; | ||
} | ||
|
||
/** | ||
* Returns true if this debugging element is enabled. | ||
* | ||
* @return true, if debugging is enabled | ||
*/ | ||
public boolean isEnabled() { | ||
return enabled; | ||
} | ||
|
||
|
||
|
||
/** | ||
* Returns a {@link DebuggerAttribute} instance related to the provided | ||
* {@link ProcessDefinition}. If none exists, a new one is created and associated | ||
* with the definition. | ||
* | ||
* Default instances will have debugging disabled. | ||
* | ||
* @param definition the {@link ProcessDefinition}, the attribute is related to | ||
* @return an attribute instance, creates a new one if none exists | ||
*/ | ||
public static @Nonnull DebuggerAttribute getAttribute(@Nonnull ProcessDefinition definition) { | ||
|
||
DebuggerAttribute attribute = (DebuggerAttribute) definition.getAttribute(ATTRIBUTE_KEY); | ||
|
||
// | ||
// register a new instance | ||
// | ||
if (attribute == null) { | ||
attribute = new DebuggerAttribute(); | ||
definition.setAttribute(ATTRIBUTE_KEY, attribute); | ||
} | ||
|
||
return attribute; | ||
} | ||
} |
Oops, something went wrong.