From e4cd4830153c09efacdb32b628172d2ec1425b01 Mon Sep 17 00:00:00 2001 From: dalvarellos <98599414+dalvarellos@users.noreply.github.com> Date: Fri, 6 Dec 2024 08:55:43 -0300 Subject: [PATCH] Use GxProperties for properties and pass context to invoked objects (#916) Use GxProperties for properties and pass context to invoked objects Use package name from properties --------- Co-authored-by: dalvarellos --- .../gxdynamiccall/GXDynCallProperties.java | 23 ---------- .../genexus/gxdynamiccall/GXDynamicCall.java | 46 +++++++++---------- .../gxdynamiccall/test/GxDynamicCallTest.java | 20 ++++---- 3 files changed, 31 insertions(+), 58 deletions(-) delete mode 100644 gxdynamiccall/src/main/java/com/genexus/gxdynamiccall/GXDynCallProperties.java diff --git a/gxdynamiccall/src/main/java/com/genexus/gxdynamiccall/GXDynCallProperties.java b/gxdynamiccall/src/main/java/com/genexus/gxdynamiccall/GXDynCallProperties.java deleted file mode 100644 index 3e168defa..000000000 --- a/gxdynamiccall/src/main/java/com/genexus/gxdynamiccall/GXDynCallProperties.java +++ /dev/null @@ -1,23 +0,0 @@ -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 d514b8daa..05dfc94fd 100644 --- a/gxdynamiccall/src/main/java/com/genexus/gxdynamiccall/GXDynamicCall.java +++ b/gxdynamiccall/src/main/java/com/genexus/gxdynamiccall/GXDynamicCall.java @@ -7,36 +7,38 @@ import com.genexus.CommonUtil; import com.genexus.GXBaseCollection; +import com.genexus.ModelContext; import com.genexus.SdtMessages_Message; -import com.genexus.common.interfaces.SpecificImplementation; +import com.genexus.util.GXProperties; public class GXDynamicCall { - private GXDynCallProperties properties; + private GXProperties properties; private Object instanceObject; - private String objectName; + private String externalName; + private int remoteHandle; + private ModelContext context; - public GXDynamicCall(){ - properties = new GXDynCallProperties(); - properties.setPackageName(SpecificImplementation.Application.getPACKAGE()); + public GXDynamicCall(int remoteHandle, ModelContext context){ + this.remoteHandle = remoteHandle; + this.context = context; + this.properties = new GXProperties(); } - public GXDynCallProperties getProperties() { + public GXProperties getProperties() { return properties; } - public void setProperties(GXDynCallProperties properties) { + public void setProperties(GXProperties properties) { this.properties = properties; } - public String getObjectName(){ - return objectName; - + public String getExternalName(){ + return externalName; } - public void setObjectName(String name){ - objectName=name; - properties.setExternalName(name); + public void setExternalName(String name){ + externalName=name; } public void execute(Vector parameters, Vector errorsArray) { @@ -73,7 +75,7 @@ public Object execute(Vector parameters, GXDynCallMethodConf methodConfi { Class auxClass=null; try { - auxClass = loadClass(properties.getExternalName(),properties.getPackageName()); + auxClass = loadClass(this.externalName, properties.get("PackageName")); } catch (ClassNotFoundException e) { CommonUtil.ErrorToMessages("Load class Error", e.getMessage(), errors); errorsArray.addAll(errors.getStruct()); @@ -88,12 +90,10 @@ public Object execute(Vector parameters, GXDynCallMethodConf methodConfi public void create(Vector constructParameters, Vector errors) { GXBaseCollection error =new GXBaseCollection(); - String objectNameToInvoke; Constructor constructor=null; - objectNameToInvoke = constructParameters==null?objectName:properties.getExternalName(); - if (!objectNameToInvoke.isEmpty()) { + if (!this.externalName.isEmpty()) { try { - Class objClass = loadClass(objectNameToInvoke, properties.getPackageName()); + Class objClass = loadClass(this.externalName, properties.get("PackageName")); 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) + if(sPackage != null && !sPackage.isEmpty()) 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 d36e15677..6120d3706 100644 --- a/gxdynamiccall/src/test/java/com/genexus/gxdynamiccall/test/GxDynamicCallTest.java +++ b/gxdynamiccall/src/test/java/com/genexus/gxdynamiccall/test/GxDynamicCallTest.java @@ -1,12 +1,10 @@ package com.genexus.gxdynamiccall.test; import com.genexus.Application; -import com.genexus.GXBaseCollection; -import com.genexus.GXSimpleCollection; +import com.genexus.ModelContext; 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; @@ -18,8 +16,8 @@ public class GxDynamicCallTest { @Test public void callGxNativeObject(){ Application.init(com.genexus.gxdynamiccall.test.GXcfg.class); - GXDynamicCall call = new GXDynamicCall(); - call.setObjectName("DynamicCallTestProcedure"); + GXDynamicCall call = new GXDynamicCall(-1, new ModelContext(GxDynamicCallTest.class)); + call.setExternalName("com.genexus.gxdynamiccall.test.DynamicCallTestProcedure"); Vector paramArray = new Vector<>(); paramArray.add(Double.parseDouble("3")); paramArray.add((short)4); @@ -34,10 +32,9 @@ public void callGxNativeObject(){ @Test public void callExternalClass(){ Application.init(com.genexus.gxdynamiccall.test.GXcfg.class); - GXDynamicCall call = new GXDynamicCall(); + GXDynamicCall call = new GXDynamicCall(-1, new ModelContext(GxDynamicCallTest.class)); Vector errorsArray= new Vector<>(); - call.getProperties().setExternalName("DynamicCallExternalTestProcedure"); - call.getProperties().setPackageName("com.genexus.gxdynamiccall.test"); + call.setExternalName("com.genexus.gxdynamiccall.test.DynamicCallExternalTestProcedure"); //Constructor Vector constructParamArray = new Vector<>(); constructParamArray.add((int)3); @@ -64,9 +61,8 @@ public void callExternalClass(){ @Test public void callExternalClassWithStaticMethod(){ Application.init(com.genexus.gxdynamiccall.test.GXcfg.class); - GXDynamicCall call = new GXDynamicCall(); - call.getProperties().setExternalName("DynamicCallExternalTestProcedure"); - call.getProperties().setPackageName("com.genexus.gxdynamiccall.test"); + GXDynamicCall call = new GXDynamicCall(-1, new ModelContext(GxDynamicCallTest.class)); + call.setExternalName("com.genexus.gxdynamiccall.test.DynamicCallExternalTestProcedure"); Vector errorsArray= new Vector<>(); //Parameters Vector paramArray = new Vector<>();