// Decompiled by Jad v1.5.8e. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/kpdus/jad.html
// Decompiler options: packimports(3) deadcode 
// Source File Name:   WTDocumentWithContextDelegate.java

package com.ptc.windchill.pdmlink.doc.server;

import com.ptc.core.foundation.type.server.impl.TypeHelper;
import com.ptc.core.meta.common.TypeIdentifier;
import com.ptc.core.meta.server.TypeIdentifierUtility;
import com.ptc.windchill.enterprise.copy.server.CoreMetaUtility;
import com.ptc.windchill.enterprise.doc.server.DocumentUtility;
import com.ptc.windchill.enterprise.doc.server.WTDocumentDelegate;
import com.ptc.windchill.enterprise.nativeapp.server.ClientConfiguration;
import java.io.PrintStream;
import java.util.HashMap;
import java.util.Locale;
import wt.doc.WTDocument;
import wt.doc.WTDocumentMaster;
import wt.fc.*;
import wt.inf.container.WTContainer;
import wt.inf.container.WTContainerRef;
import wt.rule.util.InitRuleHelper;
import wt.util.*;

/**
 * @deprecated Class WTDocumentWithContextDelegate is deprecated
 */

public class WTDocumentWithContextDelegate extends WTDocumentDelegate
{

    public WTDocumentWithContextDelegate()
    {
    }

    /**
     * @deprecated Method createDocument is deprecated
     */

    public WTDocument createDocument(TypeIdentifier objType, HashMap nameValueData, Locale locale)
        throws WTException
    {
        if(VERBOSE)
            System.out.println("Entering " + CLASSNAME + ".createDocument");
        String title = null;
        title = (String)nameValueData.get("title");
        if(title != null)
        {
            title = title.trim();
            if(VERBOSE)
                System.out.println("Title = " + title);
        }
        WTDocument document = getNewWTDocument(objType);
        Class doc_class = document.getClass();
        Class obj_class = CoreMetaUtility.getTypeClass(objType);
        if(!doc_class.equals(obj_class))
        {
            Object args[] = {
                obj_class
            };
            throw new WTException("com.ptc.windchill.pdmlink.doc.server.serverResource", "1", args);
        }
        if(VERBOSE)
            System.out.println("Type of new document is " + objType.getTypename());
        try
        {
            if(title != null)
                document.setTitle(title);
        }
        catch(WTPropertyVetoException wtpve)
        {
            throw new WTException(wtpve, "com.ptc.windchill.pdmlink.doc.server.serverResource", "2", null);
        }
        document = setStandardCreateAttributes(document, nameValueData, locale);
        document = DocumentUtility.setOldAttributes(document);
        document = (WTDocument)PersistenceHelper.manager.store(document);
        if(VERBOSE)
            System.out.println("I am done with creating the document.");
        return document;
    }

    /**
     * @deprecated Method updateDocument is deprecated
     */

    public WTDocument updateDocument(WTDocument document, HashMap nameValueData, Locale locale)
        throws WTException
    {
        if(VERBOSE)
            System.out.println("Entering " + CLASSNAME + ".updateDocument");
        document = setStandardUpdateAttributes(document, nameValueData, locale);
        try
        {
            String title = (String)nameValueData.get("title");
            String old_title = document.getTitle();
            if(title != null && title.length() > 0)
            {
                if(old_title == null || !title.equals(old_title))
                    document.setTitle(title);
            } else
            if((title == null || title.length() == 0) && old_title != null)
                document.setTitle(title);
        }
        catch(WTPropertyVetoException wtpve)
        {
            throw new WTException(wtpve, "com.ptc.windchill.pdmlink.doc.server.serverResource", "2", null);
        }
        TypeIdentifier tid = TypeIdentifierUtility.getTypeIdentifier(document);
        String baseType = TypeHelper.getBaseType(tid);
        if(TypeHelper.hasCustomModeledAttributes(tid.toString(), baseType))
        {
            WTDocumentMaster theMaster = (WTDocumentMaster)document.getMaster();
            PersistenceHelper.manager.save(theMaster);
        }
        if(document != null)
            document = (WTDocument)PersistenceHelper.manager.save(document);
        if(VERBOSE)
            System.out.println("I am done with updating the document.");
        return document;
    }

    /**
     * @deprecated Method getDocumentType is deprecated
     */

    public TypeIdentifier[] getDocumentType(Class objClass, String context)
        throws WTException
    {
        return super.getDocumentType(objClass, context);
    }

    /**
     * @deprecated Method getCreateDocumentAttributes is deprecated
     */

    public HashMap getCreateDocumentAttributes(WTContainer context, TypeIdentifier objType, HashMap hashMap, Locale locale)
        throws WTException
    {
        String list[] = getPDMLinkSpecificAttributes("create");
        boolean autonumber = InitRuleHelper.isAutoNumber(objType.getTypename(), WTContainerRef.newWTContainerRef(context));
        return getCreateDocumentAttributes(list, context, objType, hashMap, autonumber, locale);
    }

    /**
     * @deprecated Method getUpdateDocumentAttributes is deprecated
     */

    public HashMap getUpdateDocumentAttributes(Persistable object, HashMap hashMap, Locale locale)
        throws WTException
    {
        String list[] = getPDMLinkSpecificAttributes("update");
        return getUpdateDocumentAttributes(list, object, hashMap, locale);
    }

    /**
     * @deprecated Method getDetailsDocumentAttributes is deprecated
     */

    public HashMap getDetailsDocumentAttributes(Persistable object, HashMap hashMap, ClientConfiguration clientInfo, Locale locale)
        throws WTException
    {
        String list[] = getPDMLinkSpecificAttributes("display");
        return getDetailsDocumentAttributes(list, object, hashMap, clientInfo, locale);
    }

    /**
     * @deprecated Method getCheckinDocumentAttributes is deprecated
     */

    public HashMap getCheckinDocumentAttributes(Persistable object, HashMap hashMap, Locale locale)
        throws WTException
    {
        String list[] = getPDMLinkSpecificAttributes("checkin");
        return getCheckinDocumentAttributes(list, object, hashMap, locale);
    }

    private String[] getPDMLinkSpecificAttributes(String operation)
    {
        String list[];
        if(operation.equals("checkin"))
        {
            list = (new String[] {
                "number", "name", "title", "description"
            });
            return list;
        }
        if(operation.equals("update"))
        {
            list = (new String[] {
                "number", "name", "title", "description"
            });
            return list;
        }
        String orglist[];
        if(operation.equals("create"))
        {
            list = (new String[] {
                "number", "name", "title", "location", "description", "container"
            });
            orglist = (new String[] {
                "number", "name", "title", "location", "description", "container", "organization"
            });
            if(SHOWORG)
                return orglist;
            else
                return list;
        }
        list = (new String[] {
            "type", "number", "name", "title", "description", "versionInfo", "checkoutInfo", "location", "teamName", "lifeCycleState", 
            "primaryName", "primaryFormat", "primarySize", "primaryUpdated", "creator", "createTimestamp", "modifier", "modifyTimestamp", "obid"
        });
        orglist = (new String[] {
            "type", "organizationName", "number", "name", "title", "description", "versionInfo", "checkoutInfo", "location", "teamName", 
            "lifeCycleState", "primaryName", "primaryFormat", "primarySize", "primaryUpdated", "creator", "createTimestamp", "modifier", "modifyTimestamp", "obid"
        });
        if(SHOWORG)
            return orglist;
        else
            return list;
    }

    static Class _mthclass$(String x0)
    {
        return Class.forName(x0);
        ClassNotFoundException x1;
        x1;
        throw (new NoClassDefFoundError()).initCause(x1);
    }

    private static final String RESOURCE = "com.ptc.windchill.pdmlink.doc.server.serverResource";
    private static final String CLASSNAME;
    private static final String CREATE = "create";
    private static final String UPDATE = "update";
    private static final String DISPLAY = "display";
    private static final String CHECKIN = "checkin";
    private static boolean VERBOSE = false;
    private static final boolean SHOWORG;

    static 
    {
        CLASSNAME = (com.ptc.windchill.pdmlink.doc.server.WTDocumentWithContextDelegate.class).getName();
        try
        {
            WTProperties properties = WTProperties.getLocalProperties();
            VERBOSE = properties.getProperty("com.ptc.windchill.enterprise.verbose", false);
            SHOWORG = properties.getProperty("wt.org.OrganizationOwned.displayOrganization", false);
        }
        catch(Throwable t)
        {
            System.err.println("com.ptc.windchill.pdmlink.doc.server.WTDocumentWithContextDelegate : Error reading com.ptc.windchill.enterprise.* properties");
            t.printStackTrace(System.err);
            throw new ExceptionInInitializerError(t);
        }
    }
}
