Skip to content

Commit c1ef05d

Browse files
author
dalvarellos
committed
Use GxProperties for properties and pass context to invoked objects
1 parent 878b5a2 commit c1ef05d

File tree

3 files changed

+29
-66
lines changed

3 files changed

+29
-66
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: 21 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -7,36 +7,37 @@
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;
2225
}
2326

24-
public GXDynCallProperties getProperties() {
27+
public GXProperties getProperties() {
2528
return properties;
2629
}
2730

28-
public void setProperties(GXDynCallProperties properties) {
31+
public void setProperties(GXProperties properties) {
2932
this.properties = properties;
3033
}
3134

32-
public String getObjectName(){
33-
return objectName;
34-
35+
public String getExternalName(){
36+
return externalName;
3537
}
3638

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

4243
public void execute(Vector<Object> parameters, Vector<SdtMessages_Message> errorsArray) {
@@ -73,7 +74,7 @@ public Object execute(Vector<Object> parameters, GXDynCallMethodConf methodConfi
7374
{
7475
Class<?> auxClass=null;
7576
try {
76-
auxClass = loadClass(properties.getExternalName(),properties.getPackageName());
77+
auxClass = Class.forName(this.externalName);
7778
} catch (ClassNotFoundException e) {
7879
CommonUtil.ErrorToMessages("Load class Error", e.getMessage(), errors);
7980
errorsArray.addAll(errors.getStruct());
@@ -88,12 +89,10 @@ public Object execute(Vector<Object> parameters, GXDynCallMethodConf methodConfi
8889

8990
public void create(Vector<Object> constructParameters, Vector<SdtMessages_Message> errors) {
9091
GXBaseCollection<SdtMessages_Message> error =new GXBaseCollection<SdtMessages_Message>();
91-
String objectNameToInvoke;
9292
Constructor<?> constructor=null;
93-
objectNameToInvoke = constructParameters==null?objectName:properties.getExternalName();
94-
if (!objectNameToInvoke.isEmpty()) {
93+
if (!this.externalName.isEmpty()) {
9594
try {
96-
Class<?> objClass = loadClass(objectNameToInvoke, properties.getPackageName());
95+
Class<?> objClass = Class.forName(this.externalName);
9796
Object[] auxConstParameters;
9897
Class<?>[] auxConstructorTypes;
9998
if (constructParameters != null && constructParameters.size() > 0) {
@@ -104,9 +103,9 @@ public void create(Vector<Object> constructParameters, Vector<SdtMessages_Messag
104103
auxConstructorTypes[i] = obj.getClass();
105104
i++;
106105
}
107-
} else {
108-
auxConstParameters = new Object[] {Integer.valueOf(-1)};
109-
auxConstructorTypes = new Class[] {int.class};
106+
} else {
107+
auxConstParameters = new Object[] {this.remoteHandle, this.context};
108+
auxConstructorTypes = new Class[] {int.class, ModelContext.class};
110109
}
111110
try{
112111
constructor = objClass.getConstructor(auxConstructorTypes);
@@ -255,13 +254,4 @@ private static void updateParams(Vector<Object> originalParameter, Object[] call
255254
originalParameter.set(i, objectToUpdate);
256255
}
257256
}
258-
259-
private Class<?> loadClass(String className, String sPackage) throws ClassNotFoundException {
260-
String classPackage="";
261-
if(sPackage != null)
262-
classPackage+= sPackage + ".";
263-
classPackage+= className;
264-
Class<?> c = Class.forName(classPackage);;
265-
return c;
266-
}
267257
}

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)