private static <T> T newDataObject(DataModelDefinition<T> definition) { try { return definition.getModelClass().newInstance(); } catch (ReflectiveOperationException e) { throw new IllegalStateException(e); } }
private T convert(DataModelReflection reflection) { if (reflection == null) { return null; } return definition.toObject(reflection); } }
@Override public DataModelReflection next() { E next = iterator.next(); return definition.toReflection(next); }
@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(); } }; } }
/** * Returns the sub rule builder for the specified property. * Note that this model will be only accepted if all properties are accepted. * @param name the property name * @return the rule builder for the property * @throws IllegalArgumentException if the property does not exist, * or if some parameters were {@code null} */ public Property property(String name) { if (name == null) { throw new IllegalArgumentException("name must not be null"); //$NON-NLS-1$ } String[] words = name.split("_|-|\\s+"); //$NON-NLS-1$ PropertyName propertyName = PropertyName.newInstance(words); PropertyType type = definition.getType(propertyName); if (type == null) { throw new IllegalArgumentException(MessageFormat.format( Messages.getString("VerifyRuleBuilder.errorUndefinedProperty"), //$NON-NLS-1$ definition.getModelClass().getName(), propertyName)); } Property subBuilder = propertyConditions.get(propertyName); if (subBuilder == null) { subBuilder = new Property(propertyName, type); propertyConditions.put(propertyName, subBuilder); } return subBuilder; }
if (definition.getProperties().size() > version.getMaxColumns()) { LOG.warn(MessageFormat.format( Messages.getString("ExcelSheetSinkFactory.warnExceedColumnCount"), //$NON-NLS-1$ definition.getModelClass().getName(), version.getMaxColumns(), output));
static void checkProperty(DataModelDefinition<?> definition, PropertyName name) { PropertyType type = definition.getType(name); if (type == null) { throw new IllegalArgumentException(MessageFormat.format( "property \"{1}\" is not defined in {0}", definition.getClass().getName(), name)); } }
return +1; for (PropertyName name : definition.getProperties()) { Class<?> type = definition.getType(name).getRepresentation(); if (Comparable.class.isAssignableFrom(type) == false) {
Engine(DataModelDefinition<?> definition, WorkbookInfo info, int maxColumns) { assert definition != null; assert info != null; this.definition = definition; this.info = info; List<PropertyName> props = new ArrayList<>(definition.getProperties()); if (props.size() > maxColumns) { props = props.subList(0, maxColumns); } this.properties = props; }
Engine(DataModelDefinition<?> definition, URI id) { assert definition != null; this.definition = definition; this.id = id; this.builder = definition.newReflection(); }
if (definition.getType(property) == null) { throw new IOException(MessageFormat.format( Messages.getString("ExcelSheetDataModelSource.errorMissingProperty"), //$NON-NLS-1$ definition.getModelClass().getName(), property, id,
private Object describeProperty(DataModelReflection object, PropertyName property) { assert property != null; if (object == null) { return null; } Object value = object.getValue(property); if (value == null) { return null; } PropertyType type = definition.getType(property); switch (type) { case DATE: return dateFormat.format(((Calendar) value).getTime()); case TIME: return timeFormat.format(((Calendar) value).getTime()); case DATETIME: return datetimeFormat.format(((Calendar) value).getTime()); case DECIMAL: return String.format( "%s(scale=%d)", //$NON-NLS-1$ ((BigDecimal) value).toPlainString(), ((BigDecimal) value).scale()); case STRING: return toStringLiteral((String) value); default: return value; } }
/** * Starts scan and visits each property method. * @param definition the model definition * @param context context objects (nullable) * @throws E if failed * @throws IllegalArgumentException if some parameters were {@code null} */ public void scan(DataModelDefinition<?> definition, C context) throws E { if (definition == null) { throw new IllegalArgumentException("definition must not be null"); //$NON-NLS-1$ } for (PropertyName name : definition.getProperties()) { scan(definition, name, context); } }
/** * 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 <S> DataModelSource createSource( DataModelDefinition<S> inner, TestContext context) throws IOException { if (inner.getModelClass() != definition.getModelClass()) { throw new IllegalStateException(); } return new IteratorDataModelSource(results.iterator()); } @Override
private T convert(DataModelReflection reflection) { if (reflection == null) { return null; } return definition.toObject(reflection); } }
@Override public DataModelReflection next() throws IOException { if (input.readTo(object)) { return definition.toReflection(object); } return null; } @Override
/** * Returns a {@link VerifyRule} from since added rules. * @return the created {@link VerifyRule} */ public VerifyRule toVerifyRule() { List<PropertyName> keys = new ArrayList<>(); List<PropertyCondition<?>> properties = new ArrayList<>(); for (Map.Entry<PropertyName, Property> entry : propertyConditions.entrySet()) { Property property = entry.getValue(); if (property.key) { keys.add(entry.getKey()); } if (property.predicates.isEmpty() == false) { @SuppressWarnings({ "unchecked", "rawtypes" }) PropertyCondition<?> cond = new PropertyCondition( entry.getKey(), definition.getType(entry.getKey()).getRepresentation(), property.predicates); properties.add(cond); } } return new VerifyRuleInterpretor(keys, dataModelConditions, properties); }
for (PropertyName property : definition.getProperties()) { writer.println("<tr>"); //$NON-NLS-1$
private static void checkDataType(DataModelDefinition<?> definition, DataFormat<?> format) { if (format.getSupportedType().isAssignableFrom(definition.getModelClass()) == false) { throw new IllegalArgumentException(MessageFormat.format( "inconsistent data format: data-type={0}, format-type={1}, supported-type={2}", definition.getModelClass().getName(), format.getClass().getName(), format.getSupportedType().getName())); } }