Engine(DataModelDefinition<?> definition, URI id) { assert definition != null; this.definition = definition; this.id = id; this.builder = definition.newReflection(); }
/** * Converts JsonElement into a corresponded {@link DataModelReflection}. * @param definition structure of {@link DataModelReflection} * @param element conversion target * @return the converted object * @throws IOException if failed to convert * @throws IllegalArgumentException if some parameters were {@code null} */ public static DataModelReflection convert( DataModelDefinition<?> definition, JsonElement element) throws IOException { if ((element instanceof JsonObject) == false) { throw new IOException(MessageFormat.format( Messages.getString("JsonObjectDriver.errorInvalidJsonValue"), //$NON-NLS-1$ element)); } JsonObjectDriver driver = new JsonObjectDriver(definition.newReflection()); try { driver.scan(definition, (JsonObject) element); } catch (RuntimeException e) { throw new IOException(MessageFormat.format( Messages.getString("JsonObjectDriver.errorFailedToConvert"), //$NON-NLS-1$ element), e); } return driver.builder.build(); }
@Override public <V> DataModelSource createSource( DataModelDefinition<V> definition, DirectFileOutputDescription description, TestContext context) throws IOException { DirectIoTestHelper helper = new DirectIoTestHelper(context, description.getBasePath()); if (LOG.isDebugEnabled()) { LOG.debug(MessageFormat.format( "Retrieving Direct I/O output: {0}", //$NON-NLS-1$ description.getClass().getName())); } V object = definition.toObject(definition.newReflection().build()); ModelInput<? super V> input = helper.openInput(definition.getModelClass(), description); return new DataModelSource() { @Override public DataModelReflection next() throws IOException { if (input.readTo(object)) { return definition.toReflection(object); } return null; } @Override public void close() throws IOException { input.close(); } }; } }