/*
 * $Revision$
 * $Date$
 * $Author$
 *
 * Copyright (c) 2008 by PROS Revenue Management.  All Rights Reserved.
 * This software is the confidential and proprietary information of
 * PROS Revenue Management ("Confidential Information").
 * You shall not disclose such Confidential Information and shall use it
 * only in accordance with the terms of the license agreement you entered
 * into with PROS.
 */
package com.test.xsd;

import org.apache.xmlbeans.XmlObject;
import org.example.inheritType.RemoteTypeDocument.RemoteType;
import org.example.xsdTest.BaseType;
import org.example.xsdTest.LocalType;
import org.example.xsdTest.MainDocument;
import org.example.xsdTest.MainDocument.Main;

/**
 * @author cschmidt
 *
 */
public class XsdTest
{

    /**
     * @param args
     */
    public static void main(String[] args) throws Exception
    {
        MainDocument doc = MainDocument.Factory.newInstance();
        RemoteType remote = RemoteType.Factory.newInstance();
        remote.setRemoteProp("subProp");
        remote.setBaseAttr("baseAttr");
        LocalType local = LocalType.Factory.newInstance();
        local.setBaseAttr("base");
        local.setAnotherAttr("another");
        Main main = doc.addNewMain();
        BaseType [] types = { remote, local };
        main.setBaseArray(types);

        System.out.println("Doc = " + doc.toString());
        System.out.println("\n\n");

        // Create model from the xml
        MainDocument newDoc = MainDocument.Factory.parse(doc.toString());
        Main newMain = newDoc.getMain();
        BaseType [] newBases = newMain.getBaseArray();

        // Output the 'remote' element
        System.out.println("Base type is: " + newBases[0].getClass().toString());
        System.out.println("Base is: " + newBases[0].toString());
        System.out.println("Base schema type is: " + newBases[0].schemaType());
        XmlObject remoteType = newBases[0].changeType(RemoteType.type);
        System.out.println("Remote type class after changeType is: " + remoteType.getClass());
        System.out.println("\n\n");

        // Output the 'local' element'
        System.out.println("Base type is: " + newBases[1].getClass().toString());
        System.out.println("Base is: " + newBases[1].toString());
        System.out.println("Base schema type is: " + newBases[1].schemaType());
        XmlObject localType = newBases[1].changeType(LocalType.type);
        System.out.println("Local type class after changeType is: " + localType.getClass());
    }

}
