📄 simpleexpressionpool.java
字号:
{ return (System.getProperty("java.security.manager") != null); } catch (final java.security.AccessControlException ace) { // obviously, it's present... } return true; } private void securityCheck (final String actionName) { if (isSecurityManagerPresent()) { java.security.AccessController.checkPermission (ControlPermission.newControlPermission(getName(), actionName)); } } public java.util.List listExpressions () { securityCheck("read"); final java.util.List result = new java.util.ArrayList(2048); final java.util.Iterator it = contentIterator(null); while (it.hasNext()) result.add(it.next()); log.debug ("listExpressions() returning "+result.size()+ " expressions"); return result; } public void unfreezeExpression (final FlowExpressionId fei) throws PoolException { securityCheck("freeze"); final FlowExpression fe = fetch(fei); try { getState(fe).exitState(); } catch (final ApplyException ae) { throw new PoolException("Unfreeze failure", ae); } log.debug("unfreezeExpression() unfroze "+fei); getHistory().log(fe.getId(), null, FrozenState.EVT_UNFREEZE, null, ""); } /** * Freezes an entire flow. */ public void freezeFlow (final String workflowInstanceId) throws PoolException { securityCheck("freeze"); log.warn("freezeFlow() not yet implemented."); throw new PoolException("freezeFlow() not yet implemented."); } /** * Attaches a frozen state to the given expression. */ public void freezeExpression (final FlowExpressionId fei) throws PoolException { securityCheck("freeze"); final FlowExpression fe = fetch(fei); if (fe.getState() != null) { throw new PoolException ("Expression already in state '"+fe.getState().getName()+"'"); } fe.setState(new FrozenState()); fe.storeItself(); log.debug("freezeExpression() froze "+fei); getHistory().log(fe.getId(), null, FrozenState.EVT_FREEZE, null, ""); } // // METHODS about variables /** * Lookup for the value of a variable in the scope of this expression. * If no value is found, then return the result of the lookup for the * parent expression.<br> * If there is no parent, return null.<br> * This may turn quite expensive, especially if all the parent expressions * have been serialized... */ public Object lookupVariable (final FlowExpression requester, final String variableName) { if (variableName.startsWith("///")) return lookupEngineVariable(variableName.substring(3)); if (variableName.startsWith("//")) return lookupRootVariable(requester, variableName.substring(2)); if (variableName.startsWith("/")) return lookupProcessVariable(requester, variableName.substring(1)); return lookupRegularVariable(requester, variableName); } /** * Regular lookup : lookups locally and if not found, will lookup * in parent ; if there is no parent, will lookup at engine level. */ protected Object lookupRegularVariable (final FlowExpression requester, final String variableName) { if (requester == null) { throw new IllegalArgumentException ("[parent] expression not found when looking for var '"+ variableName+"'"); } log.debug("lookupRegularVariable() requester is "+requester.getId()); final Object value = requester.lookupLocalVariable(variableName); if (value != null) return value; if (requester.getParent() == null) return lookupEngineVariable(variableName); final FlowExpression parent = this.fetch(requester.getParent()); return lookupRegularVariable(parent, variableName); } /** * Looks up for a variable at the engine-level (thus in the ur-expression) * (${///x}) */ protected Object lookupEngineVariable (final String variableName) { return this.fetchUrExpression().getVariables().get(variableName); } /** * Looks up for a variable at the root of a process (${//x}). */ protected Object lookupRootVariable (final FlowExpression requester, final String variableName) { if (requester.getParent() == null) return lookupRegularVariable(requester, variableName); final FlowExpression parent = this.fetch(requester.getParent()); return lookupRootVariable(parent, variableName); } /** * Looks up for a variable at the top of the current [sub-]process (${/x}). */ protected Object lookupProcessVariable (final FlowExpression requester, final String variableName) { if (requester.getParent() == null) return requester.lookupLocalVariable(variableName); if (areNotInSameFlowInstance(requester.getId(), requester.getParent())) return lookupRegularVariable(requester, variableName); final FlowExpression parent = this.fetch(requester.getParent()); return lookupProcessVariable(parent, variableName); } private boolean areNotInSameFlowInstance (final FlowExpressionId id1, final FlowExpressionId id2) { if ( ! id1.getWorkflowInstanceId().equals(id2.getWorkflowInstanceId())) return true; return ( ! id1.getInitialEngineId().equals(id2.getInitialEngineId())); } /** * Sets a variable. * If the variableName is prefixed, this method will take care of * storing the variable in the appropriate [upper] expression. */ public void setVariable (final FlowExpression requester, final String variableName, final Object value) { log.debug("setVariable() '"+variableName+"' for "+requester.getId()); if (variableName.startsWith("///")) { setEngineVariable(variableName.substring(3), value); return; } if (variableName.startsWith("//")) { setRootVariable(requester, variableName.substring(2), value); return; } if (variableName.startsWith("/")) { setProcessVariable(requester, variableName.substring(1), value); return; } requester.setLocalVariable(variableName, value); } /** * Sets a variable in the parent of the requester expression (${x}). */ public void setVariableInParent (final FlowExpression requester, final String variableName, final Object value) { final FlowExpression parent = fetch(requester.getParent()); if (parent == null) { log.warn ("setVariableInParent() parent not found : "+ requester.getParent()); return; } parent.setLocalVariable(variableName, value); } /** * Sets a variable in the process definition holding the requester * expression (${/x}). */ protected void setProcessVariable (final FlowExpression requester, final String variableName, final Object value) { if (requester.getParent() == null) { requester.setLocalVariable(variableName, value); return; } if ( ! requester.getParent().getWorkflowInstanceId() .equals(requester.getId().getWorkflowInstanceId())) { requester.setLocalVariable(variableName, value); return; } final FlowExpression parent = this.fetch(requester.getParent()); if (parent == null) { log.warn ("setProcessVariable() failed : "+ "couldn't find parent "+requester.getParent()); return; } setProcessVariable(parent, variableName, value); } /** * Sets a variable in the root process definition holding the requester * expression (${//x}). */ protected void setRootVariable (final FlowExpression requester, final String variableName, final Object value) { if (requester.getParent() == null) { requester.setLocalVariable(variableName, value); return; } final FlowExpression parent = this.fetch(requester.getParent()); if (parent == null) { log.warn ("setRootVariable() failed : "+ "couldn't find parent "+requester.getParent()); return; } setRootVariable(parent, variableName, value); } /** * Sets a variable at the engine level (${///x}) (thus in the ur-expression * of the expression pool). */ protected void setEngineVariable (final String variableName, final Object value) { fetchUrExpression().setLocalVariable(variableName, value); } /** * Returns the state of the flow expression, if it's not state, the * NormalState singleton will be returned. */ protected ExpressionState getState (final FlowExpression fe) { ExpressionState state = fe.getState(); if (state == null) state = new NormalState(); state.setExpression(fe); return state; } /** * A shortcut to get the history service. */ protected History getHistory () { return Definitions.getHistory(getContext()); } // // STATUS public org.jdom.Element getStatus () { org.jdom.Element result = new org.jdom.Element(getName()); result.addContent(XmlUtils.getClassElt(this)); result.addContent(XmlUtils.getRevisionElt("$Id: SimpleExpressionPool.java,v 1.44 2005/07/17 16:31:49 jmettraux Exp $")); // // pooled expression count org.jdom.Element pecElt = new org.jdom.Element("pooledExpressionCount"); pecElt.addContent(""+getStore().size()); result.addContent(pecElt); return result; } /** * A convenience method for looking up the expression store in the * application context */ protected ExpressionStore getStore () { if (this.store != null) return this.store; this.store = Definitions.getExpressionStore(getContext()); //log.debug("getStore() first call, pointing to '"+this.store+"'"); return this.store; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -