Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use GxProperties for properties and pass context to invoked objects #916

Merged
merged 3 commits into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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<Object> parameters, Vector<SdtMessages_Message> errorsArray) {
Expand Down Expand Up @@ -73,7 +75,7 @@ public Object execute(Vector<Object> 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());
Expand All @@ -88,12 +90,10 @@ 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;
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) {
Expand All @@ -104,9 +104,9 @@ public void create(Vector<Object> constructParameters, Vector<SdtMessages_Messag
auxConstructorTypes[i] = obj.getClass();
i++;
}
} else {
auxConstParameters = new Object[] {Integer.valueOf(-1)};
auxConstructorTypes = new Class[] {int.class};
} else {
auxConstParameters = new Object[] {this.remoteHandle, this.context};
auxConstructorTypes = new Class[] {int.class, ModelContext.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)
if(sPackage != null && !sPackage.isEmpty())
classPackage+= sPackage + ".";
classPackage+= className;
Class<?> c = Class.forName(classPackage);;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<Object> paramArray = new Vector<>();
paramArray.add(Double.parseDouble("3"));
paramArray.add((short)4);
Expand All @@ -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<SdtMessages_Message> errorsArray= new Vector<>();
call.getProperties().setExternalName("DynamicCallExternalTestProcedure");
call.getProperties().setPackageName("com.genexus.gxdynamiccall.test");
call.setExternalName("com.genexus.gxdynamiccall.test.DynamicCallExternalTestProcedure");
//Constructor
Vector<Object> constructParamArray = new Vector<>();
constructParamArray.add((int)3);
Expand All @@ -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<SdtMessages_Message> errorsArray= new Vector<>();
//Parameters
Vector<Object> paramArray = new Vector<>();
Expand Down
Loading