/*
 * The MIT License (MIT)
 *
 * Copyright (c) 2015 Lachlan Dowding
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

package permafrost.tundra.tn.document;

import com.wm.app.tn.db.BizDocTypeStore;
import com.wm.app.tn.doc.BizDocType;
import com.wm.data.IData;
import com.wm.data.IDataCursor;
import permafrost.tundra.data.IDataHelper;

/**
 * A collection of convenience methods for working with Trading Networks BizDocType objects.
 */
public final class BizDocTypeHelper {
    /**
     * Disallow instantiation of this class.
     */
    private BizDocTypeHelper() {}

    /**
     * Returns the BizDocType object associated with the given the ID.
     *
     * @param id The ID that identifies the BizDocType to be returned.
     * @return   The BizDocType object identified by the given ID.
     */
    public static BizDocType get(String id) {
        return BizDocTypeStore.get(id, true, true);
    }

    /**
     * Returns the BizDocType object associated with the given name.
     *
     * @param name The name of the BizDocType to be returned.
     * @return     The BizDocType object with the given name.
     */
    public static BizDocType getByName(String name) {
        return BizDocTypeStore.getByName(name, true, true);
    }

    /**
     * Returns the given IData if its already a BizDocType, otherwise converts it to a BizDocType object.
     *
     * @param input The IData object to be converted to a BizDocType object.
     * @return      The BizDocType object that represents the given IData object.
     */
    public static BizDocType normalize(IData input) {
        if (input == null) return null;

        BizDocType output;

        if (input instanceof BizDocType) {
            output = (BizDocType)input;
        } else {
            IDataCursor cursor = input.getCursor();
            try {
                String id = IDataHelper.get(cursor, "TypeID", String.class);
                if (id == null) throw new IllegalArgumentException("TypeID is required");
                output = get(id);
            } finally {
                cursor.destroy();
            }
        }

        return output;
    }
}

@@ -1278,50 +1278,186 @@
 .wm.
-data.IData;%0Aimport com.wm.data.IDataCursor
+app.tn.doc.FFDocType;%0Aimport com.wm.app.tn.doc.XMLDocType;%0Aimport com.wm.data.IData;%0Aimport com.wm.data.IDataCursor;%0Aimport com.wm.data.IDataFactory;%0Aimport com.wm.lang.ns.NSName
 ;%0Aim
@@ -2399,32 +2399,1414 @@
 , true);%0A    %7D%0A%0A
+    /**%0A     * Returns the content schema used to parse this content for this BizDocType.%0A     *%0A     * @param type  The BizDocType whose content schema is to be returned.%0A     * @return      The content schema for the given BizDocType.%0A     */%0A    public static String getContentSchema(BizDocType type) %7B%0A        if (type == null) return null;%0A%0A        String contentSchema = null;%0A%0A        if (type instanceof XMLDocType) %7B%0A            NSName recordBlueprint = ((XMLDocType)type).getRecordBlueprint();%0A            if (recordBlueprint != null) contentSchema = recordBlueprint.getFullName();%0A        %7D else if (type instanceof FFDocType) %7B%0A            contentSchema = ((FFDocType)type).getParsingSchema();%0A        %7D%0A%0A        return contentSchema;%0A    %7D%0A%0A    /**%0A     * Returns the content schema type used to parse this content for this BizDocType.%0A     *%0A     * @param type  The BizDocType whose content schema is to be returned.%0A     * @return      The content schema type for the given BizDocType.%0A     */%0A    public static String getContentSchemaType(BizDocType type) %7B%0A        if (type == null) return null;%0A%0A        String contentSchemaType = null;%0A%0A        if (type instanceof XMLDocType) %7B%0A            contentSchemaType = %22XML%22;%0A        %7D else if (type instanceof FFDocType) %7B%0A            contentSchemaType = %22Flat File%22;%0A        %7D%0A%0A        return contentSchemaType;%0A    %7D%0A%0A
     /**%0A     * R

Add BizDocTypeHelper.getContentSchema and .getContentSchemaType methods