diff --git a/gxdynamiccall/src/main/java/com/genexus/gxdynamiccall/GXDynCallProperties.java b/gxdynamiccall/src/main/java/com/genexus/gxdynamiccall/GXDynCallProperties.java new file mode 100644 index 000000000..3e168defa --- /dev/null +++ b/gxdynamiccall/src/main/java/com/genexus/gxdynamiccall/GXDynCallProperties.java @@ -0,0 +1,23 @@ +package com.genexus.gxdynamiccall; + +public class GXDynCallProperties { + private String externalName; + private String packageName; + + public String getExternalName() { + return externalName; + } + public void setExternalName(String name) { + externalName = name; + } + public String getPackageName() { + return packageName; + } + public void setPackageName(String packageN) { + packageName = packageN; + } + + + + +} diff --git a/gxdynamiccall/src/main/java/com/genexus/gxdynamiccall/GXDynamicCall.java b/gxdynamiccall/src/main/java/com/genexus/gxdynamiccall/GXDynamicCall.java index 05dfc94fd..d514b8daa 100644 --- a/gxdynamiccall/src/main/java/com/genexus/gxdynamiccall/GXDynamicCall.java +++ b/gxdynamiccall/src/main/java/com/genexus/gxdynamiccall/GXDynamicCall.java @@ -7,38 +7,36 @@ import com.genexus.CommonUtil; import com.genexus.GXBaseCollection; -import com.genexus.ModelContext; import com.genexus.SdtMessages_Message; -import com.genexus.util.GXProperties; +import com.genexus.common.interfaces.SpecificImplementation; public class GXDynamicCall { - private GXProperties properties; + private GXDynCallProperties properties; private Object instanceObject; - private String externalName; - private int remoteHandle; - private ModelContext context; + private String objectName; - public GXDynamicCall(int remoteHandle, ModelContext context){ - this.remoteHandle = remoteHandle; - this.context = context; - this.properties = new GXProperties(); + public GXDynamicCall(){ + properties = new GXDynCallProperties(); + properties.setPackageName(SpecificImplementation.Application.getPACKAGE()); } - public GXProperties getProperties() { + public GXDynCallProperties getProperties() { return properties; } - public void setProperties(GXProperties properties) { + public void setProperties(GXDynCallProperties properties) { this.properties = properties; } - public String getExternalName(){ - return externalName; + public String getObjectName(){ + return objectName; + } - public void setExternalName(String name){ - externalName=name; + public void setObjectName(String name){ + objectName=name; + properties.setExternalName(name); } public void execute(Vector parameters, Vector errorsArray) { @@ -75,7 +73,7 @@ public Object execute(Vector parameters, GXDynCallMethodConf methodConfi { Class auxClass=null; try { - auxClass = loadClass(this.externalName, properties.get("PackageName")); + auxClass = loadClass(properties.getExternalName(),properties.getPackageName()); } catch (ClassNotFoundException e) { CommonUtil.ErrorToMessages("Load class Error", e.getMessage(), errors); errorsArray.addAll(errors.getStruct()); @@ -90,10 +88,12 @@ public Object execute(Vector parameters, GXDynCallMethodConf methodConfi public void create(Vector constructParameters, Vector errors) { GXBaseCollection error =new GXBaseCollection(); + String objectNameToInvoke; Constructor constructor=null; - if (!this.externalName.isEmpty()) { + objectNameToInvoke = constructParameters==null?objectName:properties.getExternalName(); + if (!objectNameToInvoke.isEmpty()) { try { - Class objClass = loadClass(this.externalName, properties.get("PackageName")); + Class objClass = loadClass(objectNameToInvoke, properties.getPackageName()); Object[] auxConstParameters; Class[] auxConstructorTypes; if (constructParameters != null && constructParameters.size() > 0) { @@ -104,9 +104,9 @@ public void create(Vector constructParameters, Vector originalParameter, Object[] call private Class loadClass(String className, String sPackage) throws ClassNotFoundException { String classPackage=""; - if(sPackage != null && !sPackage.isEmpty()) + if(sPackage != null) classPackage+= sPackage + "."; classPackage+= className; Class c = Class.forName(classPackage);; diff --git a/gxdynamiccall/src/test/java/com/genexus/gxdynamiccall/test/GxDynamicCallTest.java b/gxdynamiccall/src/test/java/com/genexus/gxdynamiccall/test/GxDynamicCallTest.java index 6120d3706..d36e15677 100644 --- a/gxdynamiccall/src/test/java/com/genexus/gxdynamiccall/test/GxDynamicCallTest.java +++ b/gxdynamiccall/src/test/java/com/genexus/gxdynamiccall/test/GxDynamicCallTest.java @@ -1,10 +1,12 @@ package com.genexus.gxdynamiccall.test; import com.genexus.Application; -import com.genexus.ModelContext; +import com.genexus.GXBaseCollection; +import com.genexus.GXSimpleCollection; import com.genexus.SdtMessages_Message; import com.genexus.gxdynamiccall.GXDynCallMethodConf; - +import com.genexus.gxdynamiccall.GXDynCallProperties; import com.genexus.gxdynamiccall.GXDynamicCall; +import com.genexus.specific.java.Connect; import org.junit.Assert; import org.junit.Test; @@ -16,8 +18,8 @@ public class GxDynamicCallTest { @Test public void callGxNativeObject(){ Application.init(com.genexus.gxdynamiccall.test.GXcfg.class); - GXDynamicCall call = new GXDynamicCall(-1, new ModelContext(GxDynamicCallTest.class)); - call.setExternalName("com.genexus.gxdynamiccall.test.DynamicCallTestProcedure"); + GXDynamicCall call = new GXDynamicCall(); + call.setObjectName("DynamicCallTestProcedure"); Vector paramArray = new Vector<>(); paramArray.add(Double.parseDouble("3")); paramArray.add((short)4); @@ -32,9 +34,10 @@ public void callGxNativeObject(){ @Test public void callExternalClass(){ Application.init(com.genexus.gxdynamiccall.test.GXcfg.class); - GXDynamicCall call = new GXDynamicCall(-1, new ModelContext(GxDynamicCallTest.class)); + GXDynamicCall call = new GXDynamicCall(); Vector errorsArray= new Vector<>(); - call.setExternalName("com.genexus.gxdynamiccall.test.DynamicCallExternalTestProcedure"); + call.getProperties().setExternalName("DynamicCallExternalTestProcedure"); + call.getProperties().setPackageName("com.genexus.gxdynamiccall.test"); //Constructor Vector constructParamArray = new Vector<>(); constructParamArray.add((int)3); @@ -61,8 +64,9 @@ public void callExternalClass(){ @Test public void callExternalClassWithStaticMethod(){ Application.init(com.genexus.gxdynamiccall.test.GXcfg.class); - GXDynamicCall call = new GXDynamicCall(-1, new ModelContext(GxDynamicCallTest.class)); - call.setExternalName("com.genexus.gxdynamiccall.test.DynamicCallExternalTestProcedure"); + GXDynamicCall call = new GXDynamicCall(); + call.getProperties().setExternalName("DynamicCallExternalTestProcedure"); + call.getProperties().setPackageName("com.genexus.gxdynamiccall.test"); Vector errorsArray= new Vector<>(); //Parameters Vector paramArray = new Vector<>();