X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.db.layer0%2Fsrc%2Forg%2Fsimantics%2Fdb%2Flayer0%2Fadapter%2Fimpl%2FDefaultValuations.java;fp=bundles%2Forg.simantics.db.layer0%2Fsrc%2Forg%2Fsimantics%2Fdb%2Flayer0%2Fadapter%2Fimpl%2FDefaultValuations.java;h=3c1da867a13a5fbe7b9d7fb4e793b9cf88fa7b17;hp=8cb7bcf80934803c23e881b6a8efa87e6fba3375;hb=0ae2b770234dfc3cbb18bd38f324125cf0faca07;hpb=24e2b34260f219f0d1644ca7a138894980e25b14 diff --git a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/adapter/impl/DefaultValuations.java b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/adapter/impl/DefaultValuations.java index 8cb7bcf80..3c1da867a 100644 --- a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/adapter/impl/DefaultValuations.java +++ b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/adapter/impl/DefaultValuations.java @@ -1,84 +1,84 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Association for Decentralized Information Management - * in Industry THTH ry. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * VTT Technical Research Centre of Finland - initial API and implementation - *******************************************************************************/ -package org.simantics.db.layer0.adapter.impl; - -import org.simantics.db.ReadGraph; -import org.simantics.db.Resource; -import org.simantics.db.common.uri.ResourceToURI; -import org.simantics.db.exception.DatabaseException; -import org.simantics.db.layer0.adapter.Valuations; -import org.simantics.simulation.ontology.SimulationResource; -import org.simantics.utils.datastructures.Pair; - -public class DefaultValuations implements Valuations { - - final private Resource resource; - - public DefaultValuations(Resource module) { - this.resource = module; - } - - public static Pair splitModelAndStructure(ReadGraph graph, String path, int startPosition) throws DatabaseException { - int position = path.indexOf("/", startPosition); - String prefix = path.substring(0, position); -// System.out.println("prefix=" + prefix); - Resource r = graph.getResource(prefix); - if(graph.isInstanceOf(r, SimulationResource.getInstance(graph).Model)) { - return new Pair(path.substring(0, position), path.substring(position+1, path.length())); - } else { - return splitModelAndStructure(graph, path, position + 1); - } - } - - public static Pair splitModelAndStructure(ReadGraph graph, String path) throws DatabaseException { - Resource r = graph.getResource(path); - if(graph.isInstanceOf(r, SimulationResource.getInstance(graph).Model)) { - return new Pair(path, ""); - } else { - return splitModelAndStructure(graph, path, 8); - } - } - - @Override - public Resource getValue(ReadGraph graph, String variableIdentityPrefix, String experiment) throws DatabaseException { -// System.out.println("getValue " + module); - String path = graph.syncRequest(new ResourceToURI(resource)); -// System.out.println("path=" + path); - Pair modelAndStructure = splitModelAndStructure(graph, path); -// System.out.println("mas=" + modelAndStructure); - // TODO: fixme please - try { - return graph.getResource(modelAndStructure.first + "/" + experiment + "/" + modelAndStructure.second); - } catch (DatabaseException e) { - try { - return graph.getResource(modelAndStructure.first + "/BaseRealization/" + modelAndStructure.second); - } catch (DatabaseException e2) { - return null; - } - } - } - - @Override - public Resource getValue(ReadGraph graph, String variableIdentityPrefix, String experiment, String suffix) throws DatabaseException { -// System.out.println("getValue " + resource); - String path = graph.syncRequest(new ResourceToURI(resource)); -// System.out.println("path=" + path); - Pair modelAndStructure = splitModelAndStructure(graph, path); -// System.out.println("mas=" + modelAndStructure); - String prefix = modelAndStructure.second.isEmpty() ? "" : "/" + modelAndStructure.second; - String uri = modelAndStructure.first + "/" + experiment + prefix + (suffix.isEmpty() ? "" : "/" + suffix); -// System.out.println("defaultValuations uri=" + uri); - return graph.getResource(uri); - } - - -} +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.layer0.adapter.impl; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.uri.ResourceToURI; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.adapter.Valuations; +import org.simantics.simulation.ontology.SimulationResource; +import org.simantics.utils.datastructures.Pair; + +public class DefaultValuations implements Valuations { + + final private Resource resource; + + public DefaultValuations(Resource module) { + this.resource = module; + } + + public static Pair splitModelAndStructure(ReadGraph graph, String path, int startPosition) throws DatabaseException { + int position = path.indexOf("/", startPosition); + String prefix = path.substring(0, position); +// System.out.println("prefix=" + prefix); + Resource r = graph.getResource(prefix); + if(graph.isInstanceOf(r, SimulationResource.getInstance(graph).Model)) { + return new Pair(path.substring(0, position), path.substring(position+1, path.length())); + } else { + return splitModelAndStructure(graph, path, position + 1); + } + } + + public static Pair splitModelAndStructure(ReadGraph graph, String path) throws DatabaseException { + Resource r = graph.getResource(path); + if(graph.isInstanceOf(r, SimulationResource.getInstance(graph).Model)) { + return new Pair(path, ""); + } else { + return splitModelAndStructure(graph, path, 8); + } + } + + @Override + public Resource getValue(ReadGraph graph, String variableIdentityPrefix, String experiment) throws DatabaseException { +// System.out.println("getValue " + module); + String path = graph.syncRequest(new ResourceToURI(resource)); +// System.out.println("path=" + path); + Pair modelAndStructure = splitModelAndStructure(graph, path); +// System.out.println("mas=" + modelAndStructure); + // TODO: fixme please + try { + return graph.getResource(modelAndStructure.first + "/" + experiment + "/" + modelAndStructure.second); + } catch (DatabaseException e) { + try { + return graph.getResource(modelAndStructure.first + "/BaseRealization/" + modelAndStructure.second); + } catch (DatabaseException e2) { + return null; + } + } + } + + @Override + public Resource getValue(ReadGraph graph, String variableIdentityPrefix, String experiment, String suffix) throws DatabaseException { +// System.out.println("getValue " + resource); + String path = graph.syncRequest(new ResourceToURI(resource)); +// System.out.println("path=" + path); + Pair modelAndStructure = splitModelAndStructure(graph, path); +// System.out.println("mas=" + modelAndStructure); + String prefix = modelAndStructure.second.isEmpty() ? "" : "/" + modelAndStructure.second; + String uri = modelAndStructure.first + "/" + experiment + prefix + (suffix.isEmpty() ? "" : "/" + suffix); +// System.out.println("defaultValuations uri=" + uri); + return graph.getResource(uri); + } + + +}