stevedlawrence commented on code in PR #1170:
URL: https://github.com/apache/daffodil/pull/1170#discussion_r1508353897


##########
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:
   I like it! I like how everything is inferred--no need to define variables or 
say which are input vs output.
   
   A bunch of random thoughts that popped into my head thinking about the 
implications:
   
   1. It maybe makes Scala layer implementations a little weird since Scala 
only allows one primary constructor? I think it would have to look something 
like this:
      
      ```scala
      class MyLayer(val input1: String, val input2: Int) extends 
Layer("mylayer") {
           
        def this() = this(null, null)
        ...
      }
      ```
      
      The Java no-arg constructor can just leave the input variables unset, no 
big deal. I'm not sure of a way around the scala weirdness, but it's also maybe 
not the worst thing in the world?
   
   2. I wonder if it would be possible to support optional variables by giving 
a constructor arg of type `Optional<T>`? I'm not sure if type erasure would 
mean reflection couldn't figure out the type of the optional, which wouldn't 
work as that's needed to check variable type. Probably not worth complicating 
and I don't think any layers need optional variables. And I'm not even sure 
optional variables is a good idea, probably best to require all input variables 
be defined and set.
   
   3. This means Layer's can't be treated like a factory like I mentioned in 
another comment, but not a big deal. It's probably for the best, since that 
required that they be thread safe--from an implementation perspective it's nice 
to not have to require thread safety.  
   
   4. Another minor thought, does it make sense to pass in the LayerRuntime as 
a parameter to this variable input constructor? So there's always two 
constructors: the empty-arg constructor that's really just used for inferring 
types during compilation and the one with a LayerRuntime + input variables 
created at runtime? Then most wrap implementations will look virtually the 
same, e.g.
      
      ```scala
      override def wrap(is: InputStream): InputStream = new 
MyLayerInputStream(is, this)
      ```
      
      Passing LayerRuntime in to the constructor also means Layers could 
inspect the variables and create PE's or SDE's during construction instead of 
waiting until wrap is called.
   
   5. Regarding name of he output variable getter, we maybe do want some kind 
of prefix? If the getter was just the variable name then the Layer can't have 
other public functions without us confusing them as variables. Maybe something 
clearly for DFDL variables like `getDFDLVariable_<variableName>`?
   
   6. Related to the above, maybe we also use `setDFDLVariable_<variableName>` 
to define input variables instead of the constructor? This avoids the weird 
scala constructor stuff mentioned in 1? And it means setting and getting 
variables is exactly the same. Though I kindof like the constructor way better. 
It feels simpler and implementations can check all input variables at once in 
the constructor instead of a bunch of individual setters. Especially useful if 
any inputs have co-constraints since the setters could be called in unknown 
orders. Though maybe a single `setDFDLVariables(...)` function to se all input 
variables, so same as the constructor idea, but a setter function instead?



-- 
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]

Reply via email to