# Using the MflObject Interface to Transform Non-XML Data Programmatically

When an MFL is imported into a Schema project folder, a corresponding MflObject Java class is generated. The name of the generated Java class file is derived from the MessageFormat name specified in the MFL file as shown in the following example StockQuotes.mfl file:

    <?xml version='1.0' encoding='UTF-8'?>
    <!DOCTYPE MessageFormat SYSTEM 'mfl.dtd'>
    <MessageFormat name='StockPrices' version='2.01'>
    	<StructFormat name='PriceQuote' repeat='*'>
    		<FieldFormat name='StockSymbol' type='String' delim=':' codepage='windows-1252'/>
    		<FieldFormat name='StockPrice' type='String' delim='|' codepage='windows-1252'/>
    	</StructFormat>
    </MessageFormat>

For example, if the preceding StockQuotes.mfl file, which specifies the MessageFormat name of StockPrices is imported into the Schemas project folder, a StockPricesMflObject.class file is generated with following methods:

    public final class StockPricesMflObject extends MflObject {
    	public StockPricesDocument convertToXml() {}
    	public static StockPricesMflObject newInstance(StockPricesDocument xml) {}
    	public static StockPricesMflObject newInstance(byte[] bytes) {}
    	public static StockPricesMflObject newInstance(InputStream in) {}
    	public static StockPricesMflObject newInstance(String in) {}
    	public static StockPricesMflObject newInstance(RawData in) {}
    }

You can use these methods to programmatically convert non-XML data to and from XML data outside the mapper functionality of WebLogic Workshop. The following table lists the available MflObject methods and describes functionality provided with each method. In the following table, MFName represents the specified MessageFormat name. (In the preceding example, the specified MessageFormat name was StockPrices.)

Method Name and Signature | Functionality
--- | ---
public MFNameDocument convertToXml() | Transforms the non-XML data, valid to the schema in the MFL file, to an instance of the associated XMLBeans Java interface. The XMLBeans Java interface can then be used to access this data in the XML document. To learn more about XMLBeans, see Getting Started with XMLBeans. For an example of using this interface see Transforming Non-XML Data to Typed XML.
public static MFNameMflObject newInstance(MFNameDocument xml) | Transforms an instance of the associated XMLBeans (XML data) to non-XML data that is valid to the schema in the MFL file.
public static MFNameMflObject newInstance(byte[] bytes) | Transforms byte non-XML data to an instance of the MflObject
public static MFNameMflObject newInstance(InputStream in) | Transforms the non-XML input stream to an instance of the MflObject.
public static MFNameMflObject newInstance(String in) | Transforms non-XML data as a string to an instance of the MflObject.
public static MFNameMflObject newInstance(RawData in) | Transforms non-XML data as raw data to an instance of the MflObject.

The following section shows three different examples of using the StockPricesMflObject class:

- Transforming Non-XML Data to Typed XML
- Create a New Instance of an MflObject From Typed XML Example
- Create a New Instance of an MflObject From Untyped Raw Data Example

### Transforming Non-XML Data to Typed XML

The example in this section shows a business process programmatically converting an incoming typed non-XML message to an typed XML representation of that data.

This example assumes the StockPrice.mfl file is imported into a Schemas project folder and the following XML Bean classes were generated:

- PriceQuoteDocument
- PriceQuoteDocument.PriceQuote
- StockPricesDocument
- StockPricesDocument.StockPrices

To learn more about the Java classes that are generated when MFL files are imported, see Java Classes Created From Importing Schemas. For a listing of the StockPrice.mfl, see Java Classes Created From Importing Schemas.

The business process executes the following steps:

1. A Client Request start node receives an non-XML message of type: stockquotes.StockPricesMflObject and stores in a typed non-XML variable called stockPriceIn.
2. In a Perform node of the business process following the Client Request start node, the typed non-XML data is transformed to the XML Beans representation of the data by calling the convertToXml function as shown in the first line of the perform method of the following Process Definition for Java (JPD) code listing:

    package processes;
    public class convertToXMLExample implements com.bea.jpd.ProcessDefinition
    {
    	public stockquotes.StockPricesDocument stockPriceXML;
    	public stockquotes.PriceQuoteDocument.PriceQuote priceQuoteXML;
    	public stockquotes.StockPricesMflObject stockPriceIn;
    ...
    	public void perform() throws Exception
    	{
    		stockPriceXML = stockPriceIn.convertToXml();
    		priceQuoteXML = stockPriceXML.getStockPrices().addNewPriceQuote();
    		priceQuoteXML.setStockPrice("10.99");
    	}

1. The second line in the perform function executes the following steps:

1. From the XML representation of the non-XML data, the stockquotes.StockPricesDocument XML Beans class gets the current instance, as shown in the following section of code:

    stockPricesXML.getStockPrices()

2. Adds a new instance of PriceQuote using the addNewPriceQuote method of the stockquotes.StockPricesDocument XML Beans class, as shown in the following section of code:

    stockPricesXML.getStockPrices().addNewPriceQuote()

2. The last line in the perform function sets the StockPrice element to the string: 10.99 using the setStockPrice method of the stockquotes.StockPricesDocument XML Beans class, as shown in the following section of code:

    priceQuoteXML.setStockPrice("10.99");

### Create a New Instance of an MflObject From Typed XML Example

The example in this section shows a business process creating a new instance of an MflObject from incoming typed XML data.

This example assumes the StockPrice.mfl file is imported into a Schemas project folder and the following XML Bean classes were generated:

- PriceQuoteDocument
- PriceQuoteDocument.PriceQuote
- StockPricesDocument
- StockPricesDocument.StockPrices

To learn more about the Java classes that are generated when MFL files are imported, see Java Classes Created From Importing Schemas. For a listing of the StockPrice.mfl, see Java Classes Created From Importing Schemas.

The business process executes the following steps:

1. The Client Request start node receives an XML message of type: StockPricesDocument and stores in a typed XML variable called stockPriceXML.
2. In the perform node, an instance of the stockquotes.StockPricesMflObject is created from the typed XML data by calling the static newInstance function which accepts a parameter of type: StockPricesDocument as shown in the following Process Definition for Java (JPD) code listing:

    package processes;
    public class newInstanceFromXMLExample implements com.bea.jpd.ProcessDefinition
    {
    	public stockquotes.StockPricesDocument stockPriceXML;
    ...
    	public void perform() throws Exception
    	{
    		stockquotes.StockPricesMflObject stockPriceMFLObj = stockquotes.StockPricesMflObject.newInstance(stockPriceXML);
    	}
    }

### Create a New Instance of an MflObject From Untyped Raw Data Example

The example in this section shows a business process creating a new instance of an MflObject from incoming raw data (a stream of non-XML data that is untyped and has no known structure).

This example assumes the StockPrice.mfl file is imported into a Schemas project folder and the following XML Bean classes were generated:

- PriceQuoteDocument
- PriceQuoteDocument.PriceQuote
- StockPricesDocument
- StockPricesDocument.StockPrices

To learn more about the Java classes that are generated when MFL files are imported, see Java Classes Created From Importing Schemas. For a listing of the StockPrice.mfl, see Java Classes Created From Importing Schemas.

The business process executes the following steps:

1. The Client Request start node receives an untyped non-XML data message and stores in a RawData variable called stockPriceRaw.
2. In the perform node, an instance of the stockquotes.StockPricesMflObject is created from the untyped non-XML data by calling the static newInstance function which accepts a parameter of type: RawData as shown in the following Process Definition for Java (JPD) code listing:

    package processes;
    public class newInstanceFromXMLExample implements com.bea.jpd.ProcessDefinition
    {
    	public com.bea.data.RawData stockPriceRaw;
    ...
    	public void perform() throws Exception
    	{
    		stockquotes.StockPricesMflObject stockPriceMFLObj = stockquotes.StockPricesMflObject.newInstance(stockPriceRaw);
    	}
    }