/*
 *
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 *
 */

package org.apache.airavata.commons.gfac.util;

import java.beans.XMLDecoder;
import java.beans.XMLEncoder;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;

import org.apache.airavata.commons.gfac.type.Type;

public class SchemaUtil {
    public static Type parseFromXML(String xml) {
        ByteArrayInputStream bs = new ByteArrayInputStream(xml.getBytes());
        XMLDecoder d = new XMLDecoder(bs);
        Object result = d.readObject();
        d.close();
        return (Type) result;
    }

    public static String toXML(Type type) {
        ByteArrayOutputStream x = new ByteArrayOutputStream();
        XMLEncoder e = new XMLEncoder(x);
        e.writeObject(type);
        e.close();
        return x.toString();
    }
}

@@ -1042,16 +1042,265 @@
 pe.Type;
+%0Aimport org.apache.airavata.schemas.gfac.BatchApplicationDeploymentDescriptionDocument;%0Aimport org.apache.airavata.schemas.gfac.BatchApplicationDeploymentDescriptionType;%0Aimport org.apache.xmlbeans.XmlException;%0Aimport org.apache.xmlbeans.XmlObject;
 %0A%0Apublic
@@ -1816,10 +1816,691 @@
 ;%0A    %7D%0A
+    %0A    %0A    public static void main(String%5B%5D args) throws XmlException %7B%0A        %0A        BatchApplicationDeploymentDescriptionDocument t = BatchApplicationDeploymentDescriptionDocument.Factory.newInstance();%0A        %0A        BatchApplicationDeploymentDescriptionType t2 = BatchApplicationDeploymentDescriptionType.Factory.newInstance();%0A        %0A        t.setBatchApplicationDeploymentDescription(t2 );%0A        %0A        t2.setCpuCount(4);%0A        System.out.println(t);%0A        %0A        %0A        XmlObject k = XmlObject.Factory.parse(t.toString());%0A        if (k instanceof BatchApplicationDeploymentDescriptionDocument )%7B%0A            System.out.println(%22ooo%22);%0A        %7D%0A    %7D%0A
 %7D%0A

test main class