diff --git a/uk.co.strangeskies.modabi.core.api/src/uk/co/strangeskies/modabi/SchemaManager.java b/uk.co.strangeskies.modabi.core.api/src/uk/co/strangeskies/modabi/SchemaManager.java index 57d979f8..90723cdb 100644 --- a/uk.co.strangeskies.modabi.core.api/src/uk/co/strangeskies/modabi/SchemaManager.java +++ b/uk.co.strangeskies.modabi.core.api/src/uk/co/strangeskies/modabi/SchemaManager.java @@ -36,15 +36,21 @@ import java.util.function.Predicate; import java.util.function.Supplier; +import uk.co.strangeskies.modabi.io.DataTarget; import uk.co.strangeskies.modabi.io.structured.DataInterface; import uk.co.strangeskies.modabi.io.structured.StructuredDataSource; import uk.co.strangeskies.modabi.io.structured.StructuredDataTarget; +import uk.co.strangeskies.modabi.io.structured.StructuredDataTargetImpl; import uk.co.strangeskies.modabi.processing.BindingFuture; +import uk.co.strangeskies.modabi.processing.BindingState; +import uk.co.strangeskies.modabi.processing.UnbindingState; import uk.co.strangeskies.modabi.schema.ComplexNode; import uk.co.strangeskies.modabi.schema.DataNode; import uk.co.strangeskies.modabi.schema.Model; +import uk.co.strangeskies.modabi.schema.SchemaNode; import uk.co.strangeskies.reflection.Reified; import uk.co.strangeskies.reflection.TypeToken; +import uk.co.strangeskies.reflection.TypedObject; public interface SchemaManager { interface Binder { @@ -92,16 +98,22 @@ default BindingFuture from(URL input) { BindingFuture from(InputStream input); BindingFuture from(String extension, InputStream input); - } - interface Unbinder { + Binder supply(TypeToken type, + Supplier> action); + + Binder supply(TypeToken type, + Function> action); + /* - * TODO If errors are rethrown, deal with as normal. Otherwise. best effort - * at unbinding, outputting comments on errors instead of throwing - * exceptions. + * Errors which are rethrown will be passed to the next error handler if + * present, or dealt with as normal. Otherwise, a best effort is made at + * binding. */ - // Unbinder with(Consumer errorHandler); + Binder with(Consumer errorHandler); + } + interface Unbinder { U to(U output); default void to(File output) { @@ -136,23 +148,16 @@ default void to(URL output) { U to(String extension, U output); - Unbinder filter(ReturningSchemaProcessor filter); + Unbinder consume(Predicate filter); - Unbinder filter(TypeToken type, Predicate action); + Unbinder consume(BiPredicate> filter); - Unbinder filterComplex(TypeToken type, - BiPredicate, T> action); - - Unbinder filterData(TypeToken type, - BiPredicate, T> action); - - Unbinder consume(TypeToken type, Consumer action); - - Unbinder consumeComplex(TypeToken type, - BiConsumer, T> action); - - Unbinder consumeData(TypeToken type, - BiConsumer, T> action); + /* + * Errors which are rethrown will be passed to the next error handler if + * present, or dealt with as normal. Otherwise, a best effort is made at + * unbinding. + */ + Unbinder with(Consumer errorHandler); } void registerDataInterface(DataInterface handler); diff --git a/uk.co.strangeskies.modabi.core.api/src/uk/co/strangeskies/modabi/io/DiscardingDataTarget.java b/uk.co.strangeskies.modabi.core.api/src/uk/co/strangeskies/modabi/io/DiscardingDataTarget.java new file mode 100644 index 00000000..a926d225 --- /dev/null +++ b/uk.co.strangeskies.modabi.core.api/src/uk/co/strangeskies/modabi/io/DiscardingDataTarget.java @@ -0,0 +1,20 @@ +package uk.co.strangeskies.modabi.io; + +public class DiscardingDataTarget extends DataTargetDecorator { + public DiscardingDataTarget() { + super(new DataTarget() { + @Override + public void terminate() {} + + @Override + public DataTarget put(DataItem item) { + return this; + } + + @Override + public DataStreamState currentState() { + return null; + } + }); + } +} diff --git a/uk.co.strangeskies.modabi.core.api/src/uk/co/strangeskies/modabi/io/structured/DiscardingStructuredDataTarget.java b/uk.co.strangeskies.modabi.core.api/src/uk/co/strangeskies/modabi/io/structured/DiscardingStructuredDataTarget.java new file mode 100644 index 00000000..0ba3df5a --- /dev/null +++ b/uk.co.strangeskies.modabi.core.api/src/uk/co/strangeskies/modabi/io/structured/DiscardingStructuredDataTarget.java @@ -0,0 +1,34 @@ +package uk.co.strangeskies.modabi.io.structured; + +import uk.co.strangeskies.modabi.Namespace; +import uk.co.strangeskies.modabi.QualifiedName; +import uk.co.strangeskies.modabi.io.DataTarget; +import uk.co.strangeskies.modabi.io.DiscardingDataTarget; + +public class DiscardingStructuredDataTarget + extends StructuredDataTargetImpl { + @Override + protected void registerDefaultNamespaceHintImpl(Namespace namespace) {} + + @Override + protected void registerNamespaceHintImpl(Namespace namespace) {} + + @Override + protected void commentImpl(String comment) {} + + @Override + protected void nextChildImpl(QualifiedName name) {} + + @Override + protected DataTarget writePropertyImpl(QualifiedName name) { + return new DiscardingDataTarget(); + } + + @Override + protected DataTarget writeContentImpl() { + return new DiscardingDataTarget(); + } + + @Override + protected void endChildImpl() {} +} diff --git a/uk.co.strangeskies.modabi.core.provider/src/uk/co/strangeskies/modabi/impl/processing/ComplexNodeBinder.java b/uk.co.strangeskies.modabi.core.provider/src/uk/co/strangeskies/modabi/impl/processing/ComplexNodeBinder.java index 0168c428..9e7e9091 100644 --- a/uk.co.strangeskies.modabi.core.provider/src/uk/co/strangeskies/modabi/impl/processing/ComplexNodeBinder.java +++ b/uk.co.strangeskies.modabi.core.provider/src/uk/co/strangeskies/modabi/impl/processing/ComplexNodeBinder.java @@ -119,21 +119,25 @@ protected ComplexNode.Effective getExactNode( "Cannot find model '" + nextElement + "' to bind to", context); } - if (!node.getDataType().isAssignableFrom(extension.getDataType())) + if (!node.getDataType().isAssignableFrom(extension.getDataType())) { throw new BindingException( "Named input node '" + nextElement + "' of type '" + extension.getDataType() + "' does not match type '" + node.getDataType() + "' of extention point", context); + } exactNode = context.getComplexNodeOverrides(node) .putGet((Effective) extension); - } else if (node.isInline() || Objects.equals(nextElement, node.getName())) + } else if (node.isInline() + || Objects.equals(nextElement, node.getName())) { exactNode = node; - else + } else { exactNode = null; - } else + } + } else { exactNode = null; + } return exactNode; }