tuxji commented on a change in pull request #651:
URL: https://github.com/apache/daffodil/pull/651#discussion_r726510973



##########
File path: 
daffodil-runtime1-layers/src/main/resources/META-INF/services/org.apache.daffodil.layers.LayerCompiler
##########
@@ -0,0 +1,23 @@
+#  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.
+#
+# These are the layers that are built-in to Daffodil's runtime1.
+#
+org.apache.daffodil.layers.Base64MIMELayerCompiler
+org.apache.daffodil.layers.FourByteSwapLayerCompiler
+org.apache.daffodil.layers.GZIPLayerCompiler
+org.apache.daffodil.layers.LineFoldedIMFLayerCompiler
+org.apache.daffodil.layers.LineFoldedICalendarLayerCompiler

Review comment:
       I use a Maven plugin (serviceloader-maven-plugin) to generate SPI files 
automatically, so I checked and found sbt has a corresponding plugin too (see 
<https://index.scala-lang.org/nyavro/spi-plugin/sbt-spi-plugin/1.0.4>).  If we 
use that plugin, we won't need to add a new class or remove a deleted class 
from this SPI file whenever someone adds or removes a layer compiler class from 
the package.

##########
File path: 
daffodil-lib/src/main/scala/org/apache/daffodil/util/DynamicLoader.scala
##########
@@ -0,0 +1,71 @@
+/*
+ * 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.util
+
+import java.util.ServiceConfigurationError
+import java.util.ServiceLoader
+import scala.collection.mutable.ArrayBuffer
+import scala.language.reflectiveCalls
+
+/**
+ * Contains methods for dynamic loading of classes from the class path.
+ */
+object DynamicLoader {
+
+  /**
+   * Load all instances of a particular class from the class path that are
+   * declared service providers
+   * @param clazz The class to be loaded. E.g., classOf[LayerCompiler]
+   * @tparam T The type to be loaded. Usually this is inferred and isn't 
explicitly supplied.
+   *           It must have a name member returning a string. It must have a 
default (no-arg) constructor.
+   * @return A map from the name (string) to the corresponding instance of the 
class.
+   */
+  def loadClass[T <: { def name(): String }](clazz : Class[T]): Map[String, T] 
=  {
+    val thingName = {
+      val classNameWithPackage = clazz.getName
+      val packageName = clazz.getPackageName

Review comment:
       Class.getPackageName was introduced in Java 9, so that's why the CI Java 
8 jobs are getting compilation errors.  You can use 
class.getPackage().getName() instead as shown in 
<https://kodejava.org/how-do-i-get-package-name-of-a-class/>.  I wonder how 
long we need to keep supporting Java 8 LTS now that it's been superseded by two 
long-term-service releases (Java 11 LTS and Java 17 LTS)?  

##########
File path: 
daffodil-test/src/test/resources/META-INF/services/org.apache.daffodil.layers.LayerCompiler
##########
@@ -0,0 +1,20 @@
+#  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.
+#
+org.apache.daffodil.layers.AISPayloadArmoringLayerCompiler
+org.apache.daffodil.layers.CheckDigitLayerCompiler
+org.apache.daffodil.layers.IPv4ChecksumLayerCompiler
+

Review comment:
       Be nice to generate this SPI file automatically, too.

##########
File path: 
daffodil-runtime1/src/main/scala/org/apache/daffodil/layers/LayerCompiler.scala
##########
@@ -0,0 +1,130 @@
+/*
+ * 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.layers
+
+import org.apache.daffodil.api.WarnID
+import org.apache.daffodil.dpath.NodeInfo.PrimType
+import org.apache.daffodil.dsom.ImplementsThrowsOrSavesSDE
+import org.apache.daffodil.processors.SequenceRuntimeData
+import org.apache.daffodil.processors.VariableRuntimeData
+import org.apache.daffodil.processors.charset.BitsCharsetJava
+import org.apache.daffodil.processors.charset.BitsCharsetNonByteSize
+import org.apache.daffodil.schema.annotation.props.gen.LayerLengthKind
+import org.apache.daffodil.schema.annotation.props.gen.LayerLengthUnits
+import org.apache.daffodil.xml.NS
+import org.apache.daffodil.xml.RefQName
+
+/**
+ * Must be implemented by all layers.
+ *
+ * These are the classes which must be dynamically loaded in order to add a 
layer implementation
+ * to Daffodil.
+ *
+ * These instances are NOT serialized as part of a saved processor. The 
compileLayer method
+ * is called and the resulting LayerTransformerFactory is the serialized 
object.
+ */
+abstract class LayerCompiler(nom: String) {
+
+  def name() = nom

Review comment:
       What's the motivation for splitting up `name` and `nom` when adding a 
`val` prefix to `nom` would make it both a parameter and a field that can be 
read by other objects?  And that explanation should be a scaladoc here.




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