X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;f=runtime%2Forg.argeo.slc.core%2Fsrc%2Fmain%2Fjava%2Forg%2Fargeo%2Fslc%2Fcore%2Fexecution%2FInstantiationManager.java;h=478077a2d37469bcc11c0a955a33ddbd81f221ea;hb=a2ecbd2a3eae94576fe4db3d651bc0908245da90;hp=1f1ff73d21cae9642ab887cf9f044c4f599705c1;hpb=ef08ee82dcb187f6e96114fc9a9568c1da329eca;p=gpl%2Fargeo-slc.git diff --git a/runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/InstantiationManager.java b/runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/InstantiationManager.java index 1f1ff73d2..478077a2d 100644 --- a/runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/InstantiationManager.java +++ b/runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/InstantiationManager.java @@ -1,3 +1,19 @@ +/* + * Copyright (C) 2010 Mathieu Baudier + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package org.argeo.slc.core.execution; import java.util.Stack; @@ -8,6 +24,7 @@ import org.argeo.slc.SlcException; import org.argeo.slc.execution.ExecutionFlow; import org.argeo.slc.execution.ExecutionSpecAttribute; +/** Manage parameters that need to be set during the instantiation of a flow */ public class InstantiationManager { private final static Log log = LogFactory @@ -26,15 +43,15 @@ public class InstantiationManager { } public void flowInitializationStarted(ExecutionFlow flow, String flowName) { - if (log.isTraceEnabled()) - log.trace("Start initialization of " + flow.hashCode() + " (" - + flow + " - " + flow.getClass() + ")"); - // set the flow name if it is DefaultExecutionFlow if (flow instanceof DefaultExecutionFlow) { ((DefaultExecutionFlow) flow).setBeanName(flowName); } + if (log.isTraceEnabled()) + log.trace("Start initialization of " + flow.hashCode() + " (" + + flow + " - " + flow.getClass() + ")"); + // log.info("# flowInitializationStarted " + flowName); // create a stack for this thread if there is none if (flowStack.get() == null) { @@ -47,12 +64,18 @@ public class InstantiationManager { if (log.isTraceEnabled()) log.trace("Finish initialization of " + flow.hashCode() + " (" + flow + " - " + flow.getClass() + ")"); - ExecutionFlow registeredFlow = flowStack.get().pop(); - if (registeredFlow != null) { - if (!flow.getName().equals(registeredFlow.getName())) - throw new SlcException("Current flow is " + flow); - // log.info("# flowInitializationFinished " + flowName); - // initializingFlow.set(null); + + if (flowStack.get() != null) { + ExecutionFlow registeredFlow = flowStack.get().pop(); + if (registeredFlow != null) { + if (!flow.getName().equals(registeredFlow.getName())) + throw new SlcException("Current flow is " + flow); + // log.info("# flowInitializationFinished " + flowName); + // initializingFlow.set(null); + } + } else { + // happens for flows imported as services + log.warn("flowInitializationFinished - Flow Stack is null"); } } @@ -81,9 +104,14 @@ public class InstantiationManager { .getExecutionSpec().getAttributes().get(key); if (attr instanceof RefSpecAttribute) return ((RefSpecAttribute) attr).getTargetClass(); - else if (attr instanceof PrimitiveSpecAttribute) - return ((PrimitiveSpecAttribute) attr).getTypeAsClass(); - else + else if (attr instanceof PrimitiveSpecAttribute) { + String type = ((PrimitiveSpecAttribute) attr).getType(); + Class clss = PrimitiveUtils.typeAsClass(type); + if (clss == null) + throw new SlcException("Cannot convert type " + type + + " to class."); + return clss; + } else return null; }