# Passing paramateres to the custom component

**URL:** <https://forum.cloverdx.com/t/passing-paramateres-to-the-custom-component/825>\
**Category:** CloverDX Platform\
**Created:** [February 18, 2011, 12:00am UTC](https://forum.cloverdx.com/t/passing-paramateres-to-the-custom-component/825 "2011-02-18T00:00:00Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![venkata](https://avatars.discourse-cdn.com/v4/letter/v/f4b2a3/32.png) [@venkata](https://forum.cloverdx.com/u/venkata)\
**Post date:** [February 18, 2011, 12:00am UTC](https://forum.cloverdx.com/t/passing-paramateres-to-the-custom-component/825/1 "2011-02-18T00:00:00Z")

</div>

I have requirement like, i have to take the Value objects as input and i have to wirte those value objects to XLS.

For that i have devloped a custom Component

```auto

public Result execute() throws Exception {
		InputPortDirect inPort = (InputPortDirect) getInputPort(READ_FROM_PORT);;
		List<DealDetailsVO> dealDetailsVOList = new PMIFacade().processDealExtract();
		Iterator<DealDetailsVO> iterator = dealDetailsVOList.iterator();
		
		while (iterator.hasNext() && runIt) {
				DealDetailsVO dealDetailsVO = (DealDetailsVO) iterator.next();
				outRecord.getField("ACCOUNTID").setValue(dealDetailsVO.getAccountId());
				outRecord.getField("DEALID").setValue(dealDetailsVO.getDealId());
				outRecord.getField("DEALNAME").setValue(dealDetailsVO.getDealName());
				outRecord.getField("BUSINESSSEGMENT").setValue(dealDetailsVO.getBusinessSegment());
				outRecord.getField("BUSINESSSUBSEGMENT").setValue(dealDetailsVO.getBusinessSubSegment());
				outRecord.getField("ORIGINATINGLOCATION").setValue(dealDetailsVO.getOriginatingLocation());
				outRecord.getField("BOOKINGLOCATION").setValue(dealDetailsVO.getBookingLocation());
				outRecord.getField("DATEFIRSTINPIPELINE").setValue(dealDetailsVO.getDateFirstInPipeline());
				outRecord.getField("CLOSEDDATE").setValue(dealDetailsVO.getClosedDate());
				outRecord.getField("LOSTDATE").setValue(dealDetailsVO.getLostDate());
				outRecord.getField("SALESSTAGE").setValue(dealDetailsVO.getSalesStage());
				outRecord.getField("UPDATEDTOTALANNUALREVENUE").setValue(dealDetailsVO.getUpdatedTotalAnnualRevenue());
				outRecord.getField("PRODUCTTYPE").setValue(dealDetailsVO.getProductType());
				outRecord.getField("SUBPRODUCTTYPE").setValue(dealDetailsVO.getSubProductType());
				outRecord.getField("ACCOUNTNAME").setValue(dealDetailsVO.getAccountName());
				outRecord.getField("ACCTGROUPID").setValue(dealDetailsVO.getAcctGroupId());
				outRecord.getField("ACCTLEID").setValue(dealDetailsVO.getAcctLEId());
				outRecord.getField("ACCTSUBPROFILEID").setValue(dealDetailsVO.getAcctSubProfileId());
				outRecord.getField("CREATEDDATE").setValue(dealDetailsVO.getCreatedDate());
				getOutputPort(0).writeRecord(outRecord);
		
			SynchronizeUtils.cloverYield();
		}
		
        return runIt ? Result.FINISHED_OK : Result.ABORTED;
	}

```

And i have created the grf file based on the custom component. i calling the graph file through java like this

```auto

                        EngineInitializer.initEngine("C:\\cloverETL.rel-3-0-0\\cloverETL\\plugins", null, null);
			String graphPath = "c:\\cloverETL.rel-3-0-0\\cloverETL\\bin\\graph\\tets.grf";
			InputStream is = new BufferedInputStream(new FileInputStream(graphPath));

			TransformationGraph graph = null;
			// engine customizationnm
			GraphRuntimeContext runtimeContext = new GraphRuntimeContext();
			// graph loading
			graph = TransformationGraphXMLReaderWriter.loadGraph(is,runtimeContext);
			// engine initialization
			EngineInitializer.initGraph(graph, runtimeContext);

			// graph running
			IThreadManager threadManager = new SimpleThreadManager();
			WatchDog watchDog = new WatchDog(graph, runtimeContext);
			threadManager.executeWatchDog(watchDog);

```

it is execeuting fine.

But right now my requirement is like. While calling the graph it self i need to pass some input parameters. i.e what ever the method i am calling in execute() (new PMIFacade().processDealExtract() ) requires some input parameter. i .e the new method will looks like new PMIFacade().processDealExtract(int a, string b). i nned to pass those inputs while calling the grah.

can anyone help on this.

Thanks in advance  
Venkat

---

<div class="post-metadata">

**Author:** ![avackova](https://avatars.discourse-cdn.com/v4/letter/a/65b543/32.png) [@avackova](https://forum.cloverdx.com/u/avackova)\
**Post date:** [February 18, 2011, 1:19pm UTC](https://forum.cloverdx.com/t/passing-paramateres-to-the-custom-component/825/2 "2011-02-18T13:19:01Z")

</div>

What about adding the attributes to your component? Something like that:

```auto

public class MyComponent extends Node

        public static String XML_A_PARAMETER_ATTRIBUTE = "aParameter";
        public static String XML_B_PARAMETER_ATTRIBUTE = "bParameter";

        int a;
        String b;
   
        .
        .

        public static Node fromXML(TransformationGraph graph, Element xmlElement) throws XMLConfigurationException {
                ComponentXMLAttributes xattribs = new ComponentXMLAttributes(xmlElement, graph);
                MyComponent component;
                .
                .
                .
                int aAttribute = xattribs.getInteger(XML_A_PARAMETER_ATTRIBUTE);
                String bAttribute = xattribs.getString(XML_B_PARAMETER_ATTRIBUTE);
                component.setAAttribute(aAttribute);
                component.setBAttribute(bAttribute);
                .
                .
                .
         }

         public Result execute() throws Exception {  
                 InputPortDirect inPort = (InputPortDirect) getInputPort(READ_FROM_PORT);;
                 List<DealDetailsVO> dealDetailsVOList = new PMIFacade().processDealExtract(a,b);
                 Iterator<DealDetailsVO> iterator = dealDetailsVOList.iterator();
                .
                .
                .
         }
}

```

---

<div class="post-metadata">

**Author:** ![venkata](https://avatars.discourse-cdn.com/v4/letter/v/f4b2a3/32.png) [@venkata](https://forum.cloverdx.com/u/venkata)\
**Post date:** [February 21, 2011, 8:53am UTC](https://forum.cloverdx.com/t/passing-paramateres-to-the-custom-component/825/3 "2011-02-21T08:53:34Z")

</div>

Thank you very much for your reply.

I haven’t tried yet. I will try this and i will update you. I have one more doubt. To call the grf file using the follwing code.

EngineInitializer.initEngine(“C:\\cloverETL.rel-3-0-0\\cloverETL\\plugins”, null, null);  
String graphPath = “c:\\cloverETL.rel-3-0-0\\cloverETL\\bin\\graph\\scbcdh.grf”;  
InputStream is = new BufferedInputStream(new FileInputStream(graphPath));

TransformationGraph graph = null;  
// engine customizationnm  
GraphRuntimeContext runtimeContext = new GraphRuntimeContext();  
// graph loading  
graph = TransformationGraphXMLReaderWriter.loadGraph(is,runtimeContext);  
// engine initialization  
EngineInitializer.initGraph(graph, runtimeContext);

// graph running  
IThreadManager threadManager = new SimpleThreadManager();  
WatchDog watchDog = new WatchDog(graph, runtimeContext);  
threadManager.executeWatchDog(watchDog);

here where i need to pass those parameters.

Thanks  
Venkat

---

<div class="post-metadata">

**Author:** ![avackova](https://avatars.discourse-cdn.com/v4/letter/a/65b543/32.png) [@avackova](https://forum.cloverdx.com/u/avackova)\
**Post date:** [February 21, 2011, 10:00am UTC](https://forum.cloverdx.com/t/passing-paramateres-to-the-custom-component/825/4 "2011-02-21T10:00:46Z")

</div>

Hello Venkat,  
define these attributes by parameters in your graph, eg:

```auto

<Node aParameter="${a}" bParameter="${b}" id="MY_COMPONENT0" type="MY_COMPONENT"/>

```

and paste the values to the _GraphRuntimeContext_ object:

```auto

runtimeContext.addAdditionalProperty("a", "1");
runtimeContext.addAdditionalProperty("b", "b");

```

---

<div class="post-metadata">

**Author:** ![venkata](https://avatars.discourse-cdn.com/v4/letter/v/f4b2a3/32.png) [@venkata](https://forum.cloverdx.com/u/venkata)\
**Post date:** [February 21, 2011, 4:07pm UTC](https://forum.cloverdx.com/t/passing-paramateres-to-the-custom-component/825/5 "2011-02-21T16:07:43Z")

</div>

Hi avackova,

Thank you very much. It is working fine.  
I have another question like is it possible to pass the List of object’s as input. If it is how can we do that.

Thank you  
Venkat

---

<div class="post-metadata">

**Author:** ![avackova](https://avatars.discourse-cdn.com/v4/letter/a/65b543/32.png) [@avackova](https://forum.cloverdx.com/u/avackova)\
**Post date:** [February 22, 2011, 8:14am UTC](https://forum.cloverdx.com/t/passing-paramateres-to-the-custom-component/825/6 "2011-02-22T08:14:34Z")

</div>

Hello Venkat,  
List object can’t be passed to the graph. You need to split the string, eg.:

```auto

   component.setListAttribute(Arrays.asList(xattribs.getString(XML_LIST_ATTRIBUTE).split(Defaults.Component.KEY_FIELDS_DELIMITER_REGEX)));

```

---

<div class="post-metadata">

**Author:** ![venkata](https://avatars.discourse-cdn.com/v4/letter/v/f4b2a3/32.png) [@venkata](https://forum.cloverdx.com/u/venkata)\
**Post date:** [February 24, 2011, 9:54am UTC](https://forum.cloverdx.com/t/passing-paramateres-to-the-custom-component/825/7 "2011-02-24T09:54:36Z")

</div>

THANK YOU VERY MUCH avackova I am PAASING STRING ALONE
