Skip to content

Commit

Permalink
Revert "Use GxProperties for properties and pass context to invoked o…
Browse files Browse the repository at this point in the history
…bjects (#916)"

This reverts commit e4cd483.
  • Loading branch information
anaiberta committed Jan 21, 2025
1 parent 2f668ae commit 059c338
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 31 deletions.
Original file line number Diff line number Diff line change
@@ -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;
}




}
Original file line number Diff line number Diff line change
Expand Up @@ -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<Object> parameters, Vector<SdtMessages_Message> errorsArray) {
Expand Down Expand Up @@ -75,7 +73,7 @@ public Object execute(Vector<Object> 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());
Expand All @@ -90,10 +88,12 @@ public Object execute(Vector<Object> parameters, GXDynCallMethodConf methodConfi

public void create(Vector<Object> constructParameters, Vector<SdtMessages_Message> errors) {
GXBaseCollection<SdtMessages_Message> error =new GXBaseCollection<SdtMessages_Message>();
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) {
Expand All @@ -104,9 +104,9 @@ public void create(Vector<Object> constructParameters, Vector<SdtMessages_Messag
auxConstructorTypes[i] = obj.getClass();
i++;
}
} else {
auxConstParameters = new Object[] {this.remoteHandle, this.context};
auxConstructorTypes = new Class[] {int.class, ModelContext.class};
} else {
auxConstParameters = new Object[] {Integer.valueOf(-1)};
auxConstructorTypes = new Class[] {int.class};
}
try{
constructor = objClass.getConstructor(auxConstructorTypes);
Expand Down Expand Up @@ -258,7 +258,7 @@ private static void updateParams(Vector<Object> 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);;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<Object> paramArray = new Vector<>();
paramArray.add(Double.parseDouble("3"));
paramArray.add((short)4);
Expand All @@ -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<SdtMessages_Message> errorsArray= new Vector<>();
call.setExternalName("com.genexus.gxdynamiccall.test.DynamicCallExternalTestProcedure");
call.getProperties().setExternalName("DynamicCallExternalTestProcedure");
call.getProperties().setPackageName("com.genexus.gxdynamiccall.test");
//Constructor
Vector<Object> constructParamArray = new Vector<>();
constructParamArray.add((int)3);
Expand All @@ -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<SdtMessages_Message> errorsArray= new Vector<>();
//Parameters
Vector<Object> paramArray = new Vector<>();
Expand Down

0 comments on commit 059c338

Please sign in to comment.