lundi 12 février 2018

Passing void main arguments from one class to another

In my project I have following class with a method that takes flowName. When flowName == ONJSmartFlow then return true, else return false. It works well in Flow Controller class.

class FlowController implements ExecutorConstants {

    static void main(String[] args) {
        FlowController controller = new FlowController()
        controller.getFlowName(args)
    }


    static boolean getFlowName(args) {
        CommandLineHandler commandLineHandler = setupCommandLineHandler(args)
        if (commandLineHandler.getFlowsToExecute().contains("ONJSmart")) {
            true
        } else {
            false
        }
    }

In another class (below) I want to use method getFlowName() in order to decide about locationCode format.

class SupplyAFMSInformationDto {

    public final String locationCode

    private static getLocationCodeWithCorrectFormat(def supplyDetails) {
        String lc = supplyDetails.locationcode
        if (FlowController.getFlowName()) {
            "0" + lc
        } else {
            lc
        }
    }

SupplyAFMSInformationDto(def supplyDetails) {
this.locationCode = getLocationCodeWithCorrectFormat(supplyDetails);             
    }

Problem is that called getFlowName() method in SupplyAFMSInformationDto needs args from FlowController, otherwise is null so the questions are:

  1. How to use FlowController.getFlowName() method in SupplyAFMSInformationDTO without passing args ?
  2. Is there a way to pass args from FlowController to SupplyAFMSInformationDto withint this method like eg. FlowController.getFlowName(args from FlowController) ?

Aucun commentaire:

Enregistrer un commentaire