package org.simantics.interop.xmlio; import java.util.List; import org.simantics.db.ReadGraph; import org.simantics.db.Resource; import org.simantics.db.exception.DatabaseException; import org.simantics.interop.xmlio.LoadXML.Bundle; import org.simantics.layer0.Layer0; public class DefaultLoadRule implements LoadRule{ private Layer0 l0; @Override public Resource getResource(ReadGraph graph, String uri) throws DatabaseException { return graph.getResource(uri); } @Override public Object createValue(ReadGraph graph, List value, List types) throws DatabaseException { if (types.contains(Layer0.URIs.String)) return value.get(0); if (types.contains(Layer0.URIs.Boolean)) return Boolean.parseBoolean(value.get(0)); if (types.contains(Layer0.URIs.Byte)) return Byte.parseByte(value.get(0)); if (types.contains(Layer0.URIs.Double)) return Double.parseDouble(value.get(0)); if (types.contains(Layer0.URIs.Integer)) return Integer.parseInt(value.get(0)); if (types.contains(Layer0.URIs.Long)) return Long.parseLong(value.get(0)); if (types.contains(Layer0.URIs.Float)) return Float.parseFloat(value.get(0)); if (types.contains(Layer0.URIs.StringArray)) { String[] result = new String[value.size()]; for (int i = 0; i < result.length; i++) result[i] = value.get(i); return result; } if (types.contains(Layer0.URIs.BooleanArray)) { boolean[] result = new boolean[value.size()]; for (int i = 0; i < result.length; i++) result[i] = Boolean.parseBoolean(value.get(i)); return result; } if (types.contains(Layer0.URIs.BooleanArray)) { boolean[] result = new boolean[value.size()]; for (int i = 0; i < result.length; i++) result[i] = Boolean.parseBoolean(value.get(i)); return result; } if (types.contains(Layer0.URIs.ByteArray)) { byte[] result = new byte[value.size()]; for (int i = 0; i < result.length; i++) result[i] = Byte.parseByte(value.get(i)); return result; } if (types.contains(Layer0.URIs.DoubleArray)) { double[] result = new double[value.size()]; for (int i = 0; i < result.length; i++) result[i] = Double.parseDouble(value.get(i)); return result; } if (types.contains(Layer0.URIs.IntegerArray)) { int[] result = new int[value.size()]; for (int i = 0; i < result.length; i++) result[i] = Integer.parseInt(value.get(i)); return result; } if (types.contains(Layer0.URIs.LongArray)) { long[] result = new long[value.size()]; for (int i = 0; i < result.length; i++) result[i] = Long.parseLong(value.get(i)); return result; } if (types.contains(Layer0.URIs.FloatArray)) { float[] result = new float[value.size()]; for (int i = 0; i < result.length; i++) result[i] = Float.parseFloat(value.get(i)); return result; } throw new DatabaseException("Unknow value"); } @Override public void initializeWithBundles(ReadGraph graph, List bundles) throws DatabaseException { l0 = Layer0.getInstance(graph); } }