}
- public static Variable possibleInvertibleExpressionReferencedProperty(ReadGraph graph, Variable base, String expression) throws DatabaseException {
+ @SuppressWarnings("unchecked")
+ private static Triple<Double, Double, String> possibleInvertibleExpression(ReadGraph graph, Variable base, String expression) throws DatabaseException {
if (base == null || expression == null || expression.isEmpty())
return null;
InvertBasicExpressionVisitor visitor = new InvertBasicExpressionVisitor();
//System.out.println("invert : " + expression + " -> " + replaced(expression) + " for " + base.getURI(graph));
Expressions.evaluate(replaced(expression), visitor);
- Object pair = visitor.getResult();
- if(pair == null)
- return null;
- if(pair instanceof Triple) {
- @SuppressWarnings("unchecked")
- Triple<Double, Double, String> data = (Triple<Double, Double, String>)pair;
- String key = data.third.replace(MAGIC,".");
- String path = getVariablePath(graph, base, key);
- if (path == null)
- return null;
- Variable targetVariable = base.browsePossible(graph, path);
- return targetVariable;
- }
+ Object result = visitor.getResult();
+ if (result instanceof Triple)
+ return (Triple<Double, Double, String>) result;
return null;
}
+ public static Variable possibleInvertibleExpressionReferencedProperty(ReadGraph graph, Variable base, String expression) throws DatabaseException {
+ Triple<Double, Double, String> data = possibleInvertibleExpression(graph, base, expression);
+ if (data == null)
+ return null;
+ String path = getVariablePath(graph, base, data.third.replace(MAGIC, "."));
+ return path != null ? base.browsePossible(graph, path) : null;
+ }
+
+ public static Triple<Double, Double, Variable> possibleInvertibleExpressionReferencedTransformedProperty(ReadGraph graph, Variable base, String expression) throws DatabaseException {
+ Triple<Double, Double, String> data = possibleInvertibleExpression(graph, base, expression);
+ if (data == null)
+ return null;
+ String path = getVariablePath(graph, base, data.third.replace(MAGIC, "."));
+ if (path == null)
+ return null;
+ Variable targetVariable = base.browsePossible(graph, path);
+ return targetVariable != null ? Triple.make(data.first, data.second, targetVariable) : null;
+ }
+
}
import java.util.concurrent.Executor;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
-import java.util.logging.Level;
-import java.util.logging.Logger;
import org.simantics.databoard.Bindings;
import org.simantics.databoard.accessor.error.AccessorException;
import org.simantics.history.util.subscription.SubscriptionItem;
import org.simantics.simulation.data.Datasource.DatasourceListener;
import org.simantics.utils.datastructures.Triple;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* This adapter reads data from Datasource and writes to an open Subscription.
*/
public class DatasourceAdapter implements DatasourceListener {
- protected Logger logger = Logger.getLogger( DatasourceAdapter.class.toString() );
+ protected Logger logger = LoggerFactory.getLogger( DatasourceAdapter.class );
protected Collector session;
protected boolean loaded = false;
protected List<VariableHandle> handles = new ArrayList<VariableHandle>();
result.add(Triple.make(key, binding, value));
} catch (AccessorException e) {
if (failedIds.add(key))
- logger.log(Level.SEVERE, e.toString(), e);
+ logger.error(e.toString(), e);
continue;
}
}
value = handle.getValue(source);
} catch (AccessorException e) {
if (failedIds.add(key))
- logger.log(Level.SEVERE, e.toString(), e);
+ logger.error(e.toString(), e);
continue;
}
Binding binding = handle.binding();
try {
session.setValue( key, binding, value );
} catch (HistoryException e) {
- logger.log(Level.SEVERE, e.toString(), e);
+ logger.error(e.toString(), e);
}
} else {
Binding binding = bindings.get(i);
if (binding != null) {
session.setValue( key, binding, value );
- }
+ }
}
}
try {
session.endStep();
} catch (HistoryException e) {
- logger.log(Level.SEVERE, e.toString(), e);
+ logger.error(e.toString(), e);
}
}
} catch (HistoryException e) {
- logger.log(Level.SEVERE, e.toString(), e);
+ logger.error(e.toString(), e);
} finally {
stepLock.unlock();
}
public Executor getExecutor() {
return null;
}
-
}