mbeckerle commented on a change in pull request #431:
URL: https://github.com/apache/incubator-daffodil/pull/431#discussion_r504258248



##########
File path: daffodil-lib/src/main/scala/org/apache/daffodil/api/Validator.scala
##########
@@ -0,0 +1,40 @@
+/*
+ * 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.api
+
+import org.xml.sax.ErrorHandler
+
+trait Validator {
+  def name(): String = getClass.getTypeName.toLowerCase
+
+  def checkArgs(args: Validator.Arguments): Either[String, Unit] = Right(())
+
+  def validateXML(document: java.io.InputStream, errHandler: ErrorHandler, 
args: Validator.Arguments): Unit

Review comment:
       I think rather than requiring validators to cache and hide the fact that 
validation has a compilation step in it, we should make the API allow for this 
compilation step explicitly. 
   
   I think the validator you find via SPI should have an explicit 
compile(params) step that returns a CompiledValidator, and a CompiledValidator 
should have a validate(xmlInput, errorHandler) call on it. as well as be 
Serializable so it can be saved/restored as part of the runtime objects of a 
compiled DFDL schema binary. 
   
   The validate(xmlInput, errorHandler) should be thread safe, and if it 
depends on underlying non-threadsafe libraries it should deal with using 
ThreadLocals so that the caller need not be aware of this. 
   
   
   

##########
File path: daffodil-lib/src/main/scala/org/apache/daffodil/api/Validator.scala
##########
@@ -0,0 +1,40 @@
+/*
+ * 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.api
+
+import org.xml.sax.ErrorHandler
+
+trait Validator {
+  def name(): String = getClass.getTypeName.toLowerCase
+
+  def checkArgs(args: Validator.Arguments): Either[String, Unit] = Right(())

Review comment:
       This is a CLI-specific thing? Belongs in the CLI, not in a validator 
class. That is to say, people defining validators should not be thinking in 
terms of CLI interfaces, but an API. 




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

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to