ruanwenjun commented on a change in pull request #1592:
URL: 
https://github.com/apache/incubator-seatunnel/pull/1592#discussion_r836555803



##########
File path: 
seatunnel-core/seatunnel-core-base/src/main/java/org/apache/seatunnel/config/ConfigBuilder.java
##########
@@ -130,49 +129,37 @@ private boolean checkIsContainHive() {
     /**
      * create plugin class instance, ignore case.
      **/
-    private <T extends Plugin<ENVIRONMENT>> T 
createPluginInstanceIgnoreCase(String name, PluginType pluginType) throws 
Exception {
-        if (name.split("\\.").length != 1) {
-            // canonical class name
-            return (T) Class.forName(name).newInstance();
+    @SuppressWarnings("unchecked")
+    private <T extends Plugin<ENVIRONMENT>> T 
createPluginInstanceIgnoreCase(String pluginName, PluginType pluginType) throws 
Exception {
+        Map<PluginType, Class<?>> pluginBaseClassMap = engine.getPluginTypes();
+        if (!pluginBaseClassMap.containsKey(pluginType)) {
+            throw new IllegalArgumentException("PluginType not support : [" + 
pluginType + "]");
         }
-        String packageName;
-        ServiceLoader<T> plugins;
-        switch (pluginType) {
-            case SOURCE:
-                packageName = configPackage.getSourcePackage();
-                Class<T> baseSource = (Class<T>) 
Class.forName(configPackage.getBaseSourceClass());
-                plugins = ServiceLoader.load(baseSource);
-                break;
-            case TRANSFORM:
-                packageName = configPackage.getTransformPackage();
-                Class<T> baseTransform = (Class<T>) 
Class.forName(configPackage.getBaseTransformClass());
-                plugins = ServiceLoader.load(baseTransform);
-                break;
-            case SINK:
-                packageName = configPackage.getSinkPackage();
-                Class<T> baseSink = (Class<T>) 
Class.forName(configPackage.getBaseSinkClass());
-                plugins = ServiceLoader.load(baseSink);
-                break;
-            default:
-                throw new IllegalArgumentException("PluginType not support : 
[" + pluginType + "]");
+        Class<T> pluginBaseClass = (Class<T>) 
pluginBaseClassMap.get(pluginType);
+        if (pluginName.split("\\.").length != 1) {
+            // canonical class name
+            Class<T> pluginClass = (Class<T>) Class.forName(pluginName);
+            if (pluginClass.isAssignableFrom(pluginBaseClass)) {
+                throw new IllegalArgumentException("plugin: " + pluginName + " 
is not extends from " + pluginBaseClass);
+            }
+            return pluginClass.newInstance();

Review comment:
       Done, use constructor to create instance.




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