mbeckerle commented on code in PR #1170:
URL: https://github.com/apache/daffodil/pull/1170#discussion_r1505161717
##########
daffodil-propgen/src/main/resources/org/apache/daffodil/xsd/dfdlx.xsd:
##########
@@ -123,106 +123,10 @@
<xs:attributeGroup name="ExtLayeringAGQualified">
<xs:attribute form="qualified" name="layerTransform"
type="dfdlx:LayerTransformType" />
Review Comment:
Should we rename layerTransform to just layer now, since it is the only
property left in the layer system?
##########
daffodil-io/src/main/scala/org/apache/daffodil/io/processors/charset/AISPayloadArmoring.scala:
##########
Review Comment:
Moved into daffodil-test. Really should come out of daffodil and become a
schema project.
##########
daffodil-runtime1/src/main/scala/org/apache/daffodil/runtime1/layers/api/LayerCompileInfo.java:
##########
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.daffodil.runtime1.layers.api;
+
+import org.apache.daffodil.lib.exceptions.SchemaFileLocation;
+
+/**
+ * Provides contextual information for the layer's own static checking.
+ *
+ * This mostly is about getting access to DFDL variables. I
+ * It also allows reporting schema definition errors for any
+ * reason.
+ */
+public interface LayerCompileInfo {
+
+ String layerName();
+
+ SchemaFileLocation schemaFileLocation();
+
+ /**
+ * Obtains the LayerVariable object that can be used to access the variable
at runtime.
+ *
Review Comment:
LayerVariable objects are serializable (they are a view trait on
VariableRuntimeData objects) - these could be computed and saved as part of the
LayerTransformer object.
Right now there's a lot of check(...) code dealing with variables. It would
be good to eliminate that complexity.
##########
daffodil-lib/src/main/scala/org/apache/daffodil/lib/exceptions/ThrowsSDE.scala:
##########
@@ -55,7 +55,7 @@ trait ThrowsSDE {
throw th // good place for a breakpoint
}
- final def schemaDefinitionError(str: String, args: Any*): Nothing =
+ final def schemaDefinitionError(str: String, args: AnyRef*): Nothing =
Review Comment:
Needed so that java classes can implement it.
##########
daffodil-runtime1/src/main/scala/org/apache/daffodil/runtime1/layers/api/Layer.java:
##########
@@ -0,0 +1,91 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.daffodil.runtime1.layers.api;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+/**
+ * This is the primary API class for writing layers.
+ * <p/>
+ * All layers are derived from this class, and must have no-args default
constructors.
+ * <p/>
+ * Derived classes will be dynamically loaded by Java's SPI system.
+ * The names of concrete classes derived from Layer are listed in a
resources/M.services file
+ * so that they can be found and dynamically loaded.
+ * <p/>
+ * The SPI creates an instance the class of which is used as a factory to
create the
+ * instances actually used by the Daffodil runtime. Compilation of the static
information about
+ * the layer occurs only once and is then shared by all runtime instances.
+ * <p/>
+ * Instances of derived layer classes can be stateful. They are private to
threads, and each time a layer
+ * is encountered during parse/unparse, an instance is created for that
situation.
+ * <p/>
+ * Layer instances should not share mutable state (such as via singleton
objects)
+ * <p/>
+ * All the static information about the layer is provided in the arguments.
+ * <p/>
+ * The rest of the Layer class implements the
+ * layer decode/encode logic, which is done as part of deriving one's Layer
class from the
+ * Layer base class.
+ * <p/>
+ * About variables: Layer logic may read and write variables. Variables being
read are parameters to
+ * the layer algorithm. Variables being written are outputs (such as
checksums) from the layer algorithm.
+ * Variables being written must be undefined, since variables in DFDL are
single-assignment.
+ * Variables being read must be defined before being read by the layer, and
this is true for both
+ * parsing and unparsing. When unparsing, variables being read cannot be
forward-referencing to parts
+ * of the DFDL infoset that have not yet been unparsed.
+ * <p/>
+ */
+public abstract class Layer {
+
+ protected final String layerName;
+
+ public Layer(String layerName) {
+ this.layerName = layerName;
+ }
+
+ public final String name() {
+ return this.layerName; // name() method with empty args is required by SPI
loader
+ }
+
+ /**
+ * Called exactly once when the schema is compiled to do extra checking that
the layer is being used properly.
+ * The thrown exception becomes a SchemaDefinitionError at schema compile
time.
+ *
+ * Example checks are:
+ * - layerEncoding is constant and is a single-byte charset
+ * - layerLength, if constant, is within a maximum value range
+ * - layerBoundaryMark string, if constant, is not too long and contains
only allowed characters.
+ * These things can be required to be constant by this check, or it can
check their values for legality
+ * if they happen to be constant. Since these are runtime-valued properties
(can be expressions), then if the
+ * layer allowed that, they must also be checked at runtime.
+ *
+ * You don't have to check that the variables are defined and declared in
matching manner, that happens automatically.
+ *
+ * @throws LayerException on any error.
+ *
+ */
+ public void check(LayerCompileInfo layerPropertyInfo) throws LayerException
{ /* nothing */ }
+
+
+ public InputStream wrapLayerDecoder(InputStream jis, LayerRuntime lr) throws
IOException { return null; }
Review Comment:
These wrap methods should not have default implementations.
##########
daffodil-runtime1/src/main/scala/org/apache/daffodil/runtime1/layers/api/LayerRuntime.java:
##########
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.daffodil.runtime1.layers.api;
+
+import java.nio.charset.Charset;
+
+/**
+ * Runtime information and stateful services available to the layer when
+ * encoding/decoding the layer data to/from the input/output stream.
+ *
+ * Provides the ability to cause runtime processing errors, which can cause
backtracking
+ * when parsing, but are fatal when unparsing.
+ *
+ * Also provides the ability to cause runtime schema definition errors, which
are always
+ * fatal.
+ *
+ * This object contains the processor state, but hidden behind an API so that
only relevant
+ * aspects of the processor state are visible.
+ */
+public interface LayerRuntime extends LayerCompileInfo {
+
Review Comment:
Java doc needed for all methods. Should inherit them from LayerCompileInfo
for most of the methods.
##########
daffodil-runtime1-unparser/src/main/scala/org/apache/daffodil/unparsers/runtime1/PackedBinaryUnparserTraits.scala:
##########
@@ -94,9 +94,9 @@ abstract class PackedBinaryDecimalBaseUnparser(
val bigDec = number.asInstanceOf[JBigDecimal]
if (bigDec.movePointRight(binaryDecimalVirtualPoint).scale != 0) {
e.schemaDefinitionError(
- "Decimal point of number '%s' does not match the
binaryVirtualDecmialPoint: %d",
+ "Decimal point of number '%s' does not match the
binaryVirtualDecmialPoint: %s",
bigDec,
- binaryDecimalVirtualPoint,
+ binaryDecimalVirtualPoint.toString,
Review Comment:
This is a java-ism about varargs. Can't pass primitive types from scala code
to java varargs code.
##########
daffodil-runtime1-layers/src/main/scala/org/apache/daffodil/layers/runtime1/ByteSwapTransformer.scala:
##########
Review Comment:
Should rename from "Transformer" to "Layer"
##########
daffodil-runtime1-layers/src/main/scala/org/apache/daffodil/layers/runtime1/Base64Transformer.scala:
##########
Review Comment:
Renamed to Base64MimeLayer.scala
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]