Search in sources :

Example 6 with ProgrammingException

use of org.vcell.util.ProgrammingException in project vcell by virtualcell.

the class ClientTaskDispatcher method runTask.

/**
 * call currentTask.run(hash) with log4j logging; check for required keys
 * @param currentTask not null
 * @param hash not null
 * @param taskList current set of tasks being dispatched
 * @throws Exception
 */
private static void runTask(AsynchClientTask currentTask, Hashtable<String, Object> hash, Collection<AsynchClientTask> taskList) throws Exception {
    if (lg.isDebugEnabled()) {
        String msg = "Thread " + Thread.currentThread().getName() + " calling task " + currentTask.getTaskName();
        if (lg.isDebugEnabled()) {
            Object obj = hash.get(STACK_TRACE_ARRAY);
            StackTraceElement[] ste = BeanUtils.downcast(StackTraceElement[].class, obj);
            if (ste != null) {
                msg += '\n' + StringUtils.join(ste, '\n');
            }
            lg.debug(msg);
        } else {
            lg.debug(msg);
        }
    }
    // check required elements present
    StringBuilder sb = null;
    for (KeyInfo requiredKey : currentTask.requiredKeys()) {
        Object obj = hash.get(requiredKey.name);
        if (obj == null) {
            if (sb == null)
                sb = initStringBuilder(currentTask);
            sb.append("Missing required key  " + requiredKey.name + '\n');
            continue;
        }
        Class<?> foundClass = obj.getClass();
        if (!requiredKey.clzz.isAssignableFrom(foundClass)) {
            if (sb == null)
                sb = initStringBuilder(currentTask);
            sb.append("key " + requiredKey.name + " type " + foundClass.getName() + " not of required type " + requiredKey.clzz.getName());
            sb.append('\n');
        }
    }
    if (sb == null) {
        // no problems found
        currentTask.run(hash);
        return;
    }
    sb.append("Prior tasks\n");
    for (AsynchClientTask pt : taskList) {
        if (pt == currentTask) {
            break;
        }
        sb.append('\t' + pt.getTaskName() + '\n');
    }
    hash.put(HASH_DATA_ERROR, HASH_DATA_ERROR);
    throw new ProgrammingException(sb.toString());
}
Also used : KeyInfo(cbit.vcell.client.task.AsynchClientTask.KeyInfo) EventObject(java.util.EventObject) ProgrammingException(org.vcell.util.ProgrammingException)

Example 7 with ProgrammingException

use of org.vcell.util.ProgrammingException in project vcell by virtualcell.

the class ChildWindowManager method findChildWindowManager.

/**
 * @param component not null
 * @return ChildWindowManager
 * @throws ProgrammingException if unable to find ChildWindowManager
 */
public static ChildWindowManager findChildWindowManager(Component component) {
    ManagedChild mc = LWNamespace.findOwnerOfType(ManagedChild.class, component);
    if (mc != null) {
        return mc.getChildWindowManager();
    }
    if (LG.isDebugEnabled()) {
        LG.debug(ExecutionTrace.justClassName(component) + " does not have ManagedChild parent");
    }
    TopLevelWindow dw = LWNamespace.findOwnerOfType(TopLevelWindow.class, component);
    if (dw != null) {
        return dw.getChildWindowManager();
    }
    throw new ProgrammingException("ChildWindowManager.findChildWindowManager(Component) could not find a ChildWindowManager for component: " + component.getName() + " which is a " + component.getClass().getCanonicalName());
}
Also used : ProgrammingException(org.vcell.util.ProgrammingException) TopLevelWindow(cbit.vcell.client.desktop.TopLevelWindow)

Example 8 with ProgrammingException

use of org.vcell.util.ProgrammingException in project vcell by virtualcell.

the class LegacySimContextTransformer method transform.

@Override
public SimContextTransformation transform(SimulationContext originalSimContext, MathMappingCallback mathMappingCallback, NetworkGenerationRequirements networkGenerationRequirements) {
    SimulationContext transformedSimContext;
    try {
        transformedSimContext = (SimulationContext) BeanUtils.cloneSerializable(originalSimContext);
    } catch (ClassNotFoundException | IOException e) {
        e.printStackTrace();
        throw new RuntimeException("unexpected exception: " + e.getMessage());
    }
    try {
        StructureMapping structureMapping = transformedSimContext.getGeometryContext().getStructureMappings()[0];
        StructureSizeSolver.updateAbsoluteStructureSizes(transformedSimContext, structureMapping.getStructure(), 1.0, structureMapping.getSizeParameter().getUnitDefinition());
    } catch (Exception e) {
        throw new ProgrammingException("exception updating sizes", e);
    }
    transformedSimContext.getModel().refreshDependencies();
    transformedSimContext.refreshDependencies1(false);
    ArrayList<ModelEntityMapping> entityMappings = new ArrayList<ModelEntityMapping>();
    for (SpeciesContext sc : transformedSimContext.getModel().getSpeciesContexts()) {
        SpeciesContext origSpeciesContext = originalSimContext.getModel().getSpeciesContext(sc.getName());
        ModelEntityMapping em = new ModelEntityMapping(origSpeciesContext, sc);
        entityMappings.add(em);
    }
    ModelEntityMapping[] modelEntityMappings = entityMappings.toArray(new ModelEntityMapping[0]);
    return new SimContextTransformation(originalSimContext, transformedSimContext, modelEntityMappings);
}
Also used : ArrayList(java.util.ArrayList) IOException(java.io.IOException) SpeciesContext(cbit.vcell.model.SpeciesContext) ProgrammingException(org.vcell.util.ProgrammingException) IOException(java.io.IOException) ProgrammingException(org.vcell.util.ProgrammingException)

Example 9 with ProgrammingException

use of org.vcell.util.ProgrammingException in project vcell by virtualcell.

the class AsynchClientTask method setFinalWindow.

/**
 * set final window to be raised
 * @param hashTable non null
 * @param cntr non null
 * @throws ProgrammingException if more than one set in the same hash
 */
protected void setFinalWindow(Hashtable<String, Object> hashTable, Container cntr) {
    Objects.requireNonNull(cntr);
    Window w = GuiUtils.getWindowForComponent(cntr);
    if (w != null) {
        ClientTaskDispatcher.setFinalWindow(hashTable, () -> w.toFront());
        return;
    }
    throw new ProgrammingException("Container " + cntr.getName() + " has no window parent");
}
Also used : Window(java.awt.Window) ChildWindow(cbit.vcell.client.ChildWindowManager.ChildWindow) ProgrammingException(org.vcell.util.ProgrammingException)

Example 10 with ProgrammingException

use of org.vcell.util.ProgrammingException in project vcell by virtualcell.

the class VCReactionProxy method factory.

/**
 * get proxy for Reaction type
 * @param reaction not null
 * @return proxy
 * @throws ProgrammingException unknown type
 */
public static VCReactionProxy factory(ReactionStep reaction) {
    VCAssert.assertValid(reaction);
    SimpleReaction sr = BeanUtils.downcast(SimpleReaction.class, reaction);
    if (sr != null) {
        return new Simple(sr);
    }
    FluxReaction fr = BeanUtils.downcast(FluxReaction.class, reaction);
    if (fr != null) {
        return new Flux(fr);
    }
    throw new ProgrammingException("Unknown reaction type " + ExecutionTrace.justClassName(reaction));
}
Also used : SimpleReaction(cbit.vcell.model.SimpleReaction) FluxReaction(cbit.vcell.model.FluxReaction) ProgrammingException(org.vcell.util.ProgrammingException)

Aggregations

ProgrammingException (org.vcell.util.ProgrammingException)10 BioModel (cbit.vcell.biomodel.BioModel)2 Structure (cbit.vcell.model.Structure)2 File (java.io.File)2 IOException (java.io.IOException)2 EventObject (java.util.EventObject)2 UserCancelException (org.vcell.util.UserCancelException)2 ImageException (cbit.image.ImageException)1 VCMetaData (cbit.vcell.biomodel.meta.VCMetaData)1 ChildWindow (cbit.vcell.client.ChildWindowManager.ChildWindow)1 TopLevelWindow (cbit.vcell.client.desktop.TopLevelWindow)1 AsynchClientTask (cbit.vcell.client.task.AsynchClientTask)1 KeyInfo (cbit.vcell.client.task.AsynchClientTask.KeyInfo)1 AsynchClientTaskFunction (cbit.vcell.client.task.AsynchClientTaskFunction)1 ChooseFile (cbit.vcell.client.task.ChooseFile)1 CSGObject (cbit.vcell.geometry.CSGObject)1 GeometryException (cbit.vcell.geometry.GeometryException)1 GeometryInfo (cbit.vcell.geometry.GeometryInfo)1 PolygonImmutable (cbit.vcell.geometry.concept.PolygonImmutable)1 ThreeSpacePoint (cbit.vcell.geometry.concept.ThreeSpacePoint)1