mbeckerle commented on a change in pull request #273: WIP: Add User Defined 
Functions Capability
URL: https://github.com/apache/incubator-daffodil/pull/273#discussion_r336225854
 
 

 ##########
 File path: 
daffodil-udf/src/main/java/org/apache/daffodil/udf/UserDefinedFunctionProvider.java
 ##########
 @@ -0,0 +1,85 @@
+/*
+ * 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.udf;
+
+import java.lang.reflect.InvocationTargetException;
+
+/**
+ * Abstract class used by ServiceLoader to poll for UDF providers on classpath.
+ *
+ * Through this class, several User Defined Functions can be made available to
+ * Daffodil via a single entry in the META-INF/services file.
+ *
+ * UDF Providers must subclass this, and must initialize the
+ * userDefinedFunctionClasses array with all the UDF classes it is providing.
+ *
+ * If the UDFs being provided have constructors with arguments, the provider
+ * subclass must also implement the lookup function to return an initialized
+ * function class object based on the supplied namespace and name.
+ *
+ * Subclasses must also supply a
+ * src/META-INF/services/org.apache.daffodil.udf.UserDefinedFunctionProvider
+ * file in their JAVA project in order to be discoverable by Daffodil.
+ *
+ */
+
+public abstract class UserDefinedFunctionProvider {
+  /**
+   * Must be implemented to return the classes of the User Defined Function 
this
+   * provider is aware of/providing
+   *
+   * Should return array of UserDefinedFunction classes
+   */
+  abstract public Class<?>[] getUserDefinedFunctionClasses();
+
+  /**
+   * Finds and initializes User Defined Function class based on namespace and 
name
+   * provided. The UserDefinedFunctionInfo annotation applied to the function
+   * class must match name and namespaceURI field passed in from the schema.
+   *
+   * Must be overloaded if the function class's constructor takes arguments.
+   * Otherwise it will throw exceptions.
+   *
+   * @param namespaceURI XML namespace associated with schema function call
+   * @param fName function name called in schema
+   * @return initialized UserDefinedFunction object that must contain evaluate
+   *         function with functionality of UDF
+   *
+   * @throws SecurityException
+   * @throws NoSuchMethodException
+   * @throws InvocationTargetException
+   * @throws IllegalArgumentException
+   * @throws IllegalAccessException
+   * @throws InstantiationException
+   */
+  public UserDefinedFunction lookupInitializedUserDefinedFunction(String 
namespaceURI, String fName)
+      throws InstantiationException, IllegalAccessException, 
IllegalArgumentException, InvocationTargetException,
+      NoSuchMethodException, SecurityException {
 
 Review comment:
   There is a base which is ReflectiveOperationException that covers several of 
the individual ones. So you can certainly de-clutter by catching that instead 
of IllegalAccessException, InstantiationException, NoSuchMethodException, etc. 
In fact I'd suggest changing the throws clause here to 
ReflectiveOperationException. 

----------------------------------------------------------------
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:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to