Skip to content

Commit e4cd483

Browse files
dalvarellosdalvarellos
andauthored
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 <d.alvarellos@globant.com>
1 parent 9d8addf commit e4cd483

File tree

3 files changed

+31
-58
lines changed

3 files changed

+31
-58
lines changed

gxdynamiccall/src/main/java/com/genexus/gxdynamiccall/GXDynCallProperties.java

Lines changed: 0 additions & 23 deletions
This file was deleted.

gxdynamiccall/src/main/java/com/genexus/gxdynamiccall/GXDynamicCall.java

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,36 +7,38 @@
77

88
import com.genexus.CommonUtil;
99
import com.genexus.GXBaseCollection;
10+
import com.genexus.ModelContext;
1011
import com.genexus.SdtMessages_Message;
11-
import com.genexus.common.interfaces.SpecificImplementation;
12+
import com.genexus.util.GXProperties;
1213

1314
public class GXDynamicCall {
1415

15-
private GXDynCallProperties properties;
16+
private GXProperties properties;
1617
private Object instanceObject;
17-
private String objectName;
18+
private String externalName;
19+
private int remoteHandle;
20+
private ModelContext context;
1821

19-
public GXDynamicCall(){
20-
properties = new GXDynCallProperties();
21-
properties.setPackageName(SpecificImplementation.Application.getPACKAGE());
22+
public GXDynamicCall(int remoteHandle, ModelContext context){
23+
this.remoteHandle = remoteHandle;
24+
this.context = context;
25+
this.properties = new GXProperties();
2226
}
2327

24-
public GXDynCallProperties getProperties() {
28+
public GXProperties getProperties() {
2529
return properties;
2630
}
2731

28-
public void setProperties(GXDynCallProperties properties) {
32+
public void setProperties(GXProperties properties) {
2933
this.properties = properties;
3034
}
3135

32-
public String getObjectName(){
33-
return objectName;
34-
36+
public String getExternalName(){
37+
return externalName;
3538
}
3639

37-
public void setObjectName(String name){
38-
objectName=name;
39-
properties.setExternalName(name);
40+
public void setExternalName(String name){
41+
externalName=name;
4042
}
4143

4244
public void execute(Vector<Object> parameters, Vector<SdtMessages_Message> errorsArray) {
@@ -73,7 +75,7 @@ public Object execute(Vector<Object> parameters, GXDynCallMethodConf methodConfi
7375
{
7476
Class<?> auxClass=null;
7577
try {
76-
auxClass = loadClass(properties.getExternalName(),properties.getPackageName());
78+
auxClass = loadClass(this.externalName, properties.get("PackageName"));
7779
} catch (ClassNotFoundException e) {
7880
CommonUtil.ErrorToMessages("Load class Error", e.getMessage(), errors);
7981
errorsArray.addAll(errors.getStruct());
@@ -88,12 +90,10 @@ public Object execute(Vector<Object> parameters, GXDynCallMethodConf methodConfi
8890

8991
public void create(Vector<Object> constructParameters, Vector<SdtMessages_Message> errors) {
9092
GXBaseCollection<SdtMessages_Message> error =new GXBaseCollection<SdtMessages_Message>();
91-
String objectNameToInvoke;
9293
Constructor<?> constructor=null;
93-
objectNameToInvoke = constructParameters==null?objectName:properties.getExternalName();
94-
if (!objectNameToInvoke.isEmpty()) {
94+
if (!this.externalName.isEmpty()) {
9595
try {
96-
Class<?> objClass = loadClass(objectNameToInvoke, properties.getPackageName());
96+
Class<?> objClass = loadClass(this.externalName, properties.get("PackageName"));
9797
Object[] auxConstParameters;
9898
Class<?>[] auxConstructorTypes;
9999
if (constructParameters != null && constructParameters.size() > 0) {
@@ -104,9 +104,9 @@ public void create(Vector<Object> constructParameters, Vector<SdtMessages_Messag
104104
auxConstructorTypes[i] = obj.getClass();
105105
i++;
106106
}
107-
} else {
108-
auxConstParameters = new Object[] {Integer.valueOf(-1)};
109-
auxConstructorTypes = new Class[] {int.class};
107+
} else {
108+
auxConstParameters = new Object[] {this.remoteHandle, this.context};
109+
auxConstructorTypes = new Class[] {int.class, ModelContext.class};
110110
}
111111
try{
112112
constructor = objClass.getConstructor(auxConstructorTypes);
@@ -258,7 +258,7 @@ private static void updateParams(Vector<Object> originalParameter, Object[] call
258258

259259
private Class<?> loadClass(String className, String sPackage) throws ClassNotFoundException {
260260
String classPackage="";
261-
if(sPackage != null)
261+
if(sPackage != null && !sPackage.isEmpty())
262262
classPackage+= sPackage + ".";
263263
classPackage+= className;
264264
Class<?> c = Class.forName(classPackage);;

gxdynamiccall/src/test/java/com/genexus/gxdynamiccall/test/GxDynamicCallTest.java

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
package com.genexus.gxdynamiccall.test;
22
import com.genexus.Application;
3-
import com.genexus.GXBaseCollection;
4-
import com.genexus.GXSimpleCollection;
3+
import com.genexus.ModelContext;
54
import com.genexus.SdtMessages_Message;
65
import com.genexus.gxdynamiccall.GXDynCallMethodConf;
7-
import com.genexus.gxdynamiccall.GXDynCallProperties;
6+
87
import com.genexus.gxdynamiccall.GXDynamicCall;
9-
import com.genexus.specific.java.Connect;
108

119
import org.junit.Assert;
1210
import org.junit.Test;
@@ -18,8 +16,8 @@ public class GxDynamicCallTest {
1816
@Test
1917
public void callGxNativeObject(){
2018
Application.init(com.genexus.gxdynamiccall.test.GXcfg.class);
21-
GXDynamicCall call = new GXDynamicCall();
22-
call.setObjectName("DynamicCallTestProcedure");
19+
GXDynamicCall call = new GXDynamicCall(-1, new ModelContext(GxDynamicCallTest.class));
20+
call.setExternalName("com.genexus.gxdynamiccall.test.DynamicCallTestProcedure");
2321
Vector<Object> paramArray = new Vector<>();
2422
paramArray.add(Double.parseDouble("3"));
2523
paramArray.add((short)4);
@@ -34,10 +32,9 @@ public void callGxNativeObject(){
3432
@Test
3533
public void callExternalClass(){
3634
Application.init(com.genexus.gxdynamiccall.test.GXcfg.class);
37-
GXDynamicCall call = new GXDynamicCall();
35+
GXDynamicCall call = new GXDynamicCall(-1, new ModelContext(GxDynamicCallTest.class));
3836
Vector<SdtMessages_Message> errorsArray= new Vector<>();
39-
call.getProperties().setExternalName("DynamicCallExternalTestProcedure");
40-
call.getProperties().setPackageName("com.genexus.gxdynamiccall.test");
37+
call.setExternalName("com.genexus.gxdynamiccall.test.DynamicCallExternalTestProcedure");
4138
//Constructor
4239
Vector<Object> constructParamArray = new Vector<>();
4340
constructParamArray.add((int)3);
@@ -64,9 +61,8 @@ public void callExternalClass(){
6461
@Test
6562
public void callExternalClassWithStaticMethod(){
6663
Application.init(com.genexus.gxdynamiccall.test.GXcfg.class);
67-
GXDynamicCall call = new GXDynamicCall();
68-
call.getProperties().setExternalName("DynamicCallExternalTestProcedure");
69-
call.getProperties().setPackageName("com.genexus.gxdynamiccall.test");
64+
GXDynamicCall call = new GXDynamicCall(-1, new ModelContext(GxDynamicCallTest.class));
65+
call.setExternalName("com.genexus.gxdynamiccall.test.DynamicCallExternalTestProcedure");
7066
Vector<SdtMessages_Message> errorsArray= new Vector<>();
7167
//Parameters
7268
Vector<Object> paramArray = new Vector<>();

0 commit comments

Comments
 (0)