// 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:   WTDocumentTemplateDelegate.java

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

import com.ptc.core.foundation.container.common.FdnWTContainerHelper;
import com.ptc.core.foundation.container.common.FdnWTContainerService;
import com.ptc.core.foundation.type.server.impl.TypeHelper;
import com.ptc.core.meta.common.*;
import com.ptc.core.meta.server.TypeIdentifierUtility;
import com.ptc.windchill.enterprise.copy.server.CoreMetaUtility;
import com.ptc.windchill.enterprise.copy.server.TemplateObjectDelegate;
import com.ptc.windchill.enterprise.nativeapp.server.*;
import com.ptc.windchill.enterprise.templates.TemplatesFactory;
import com.ptc.windchill.enterprise.templates.TemplatesUtility;
import java.io.PrintStream;
import java.util.*;
import wt.adapter.attribute.AttributeHelper;
import wt.doc.*;
import wt.enterprise.*;
import wt.fc.*;
import wt.inf.container.*;
import wt.lifecycle.LifeCycleManaged;
import wt.lifecycle.LifeCycleTemplateReference;
import wt.org.WTOrganization;
import wt.org.WTUser;
import wt.query.*;
import wt.recent.RecentlyVisitedHelper;
import wt.recent.RecentlyVisitedService;
import wt.services.applicationcontext.UnableToCreateServiceException;
import wt.services.applicationcontext.implementation.DefaultServiceProvider;
import wt.session.SessionHelper;
import wt.session.SessionManager;
import wt.team.TeamManaged;
import wt.team.TeamTemplateReference;
import wt.util.*;
import wt.vc.*;

// Referenced classes of package com.ptc.windchill.enterprise.doc.server:
//            DocumentUtility

/**
 * @deprecated Class WTDocumentTemplateDelegate is deprecated
 */

public class WTDocumentTemplateDelegate
    implements TemplateObjectDelegate
{

    public WTDocumentTemplateDelegate()
    {
    }

    /**
     * @deprecated Method createFromTemplate is deprecated
     */

    public Templateable createFromTemplate(Templateable objTemplate, HashMap nameValueData, Locale locale, String applicationName)
        throws WTException
    {
        if(VERBOSE)
            System.out.println("Entering " + CLASSNAME + ".createFromTemplate");
        WTDocument template = (WTDocument)objTemplate;
        WTDocument document = getUnpersistedDocumentFromTemplate(template, nameValueData, "Enterprise", locale);
        String dept = (String)nameValueData.get("department");
        String type = (String)nameValueData.get("docType");
        try
        {
            if(dept != null)
                document.setDepartment(DepartmentList.toDepartmentList(dept));
            else
                document.setDepartment(DepartmentList.getDepartmentListDefault());
            if(type != null)
                document.setDocType(DocumentType.toDocumentType(type));
            else
                document.setDocType(DocumentType.getDocumentTypeDefault());
        }
        catch(WTPropertyVetoException wtpve)
        {
            throw new WTException(wtpve, "com.ptc.windchill.enterprise.doc.server.serverResource", "5", null);
        }
        String lifeCycle = (String)nameValueData.get("lifeCycleTemplate");
        if(lifeCycle == null)
            lifeCycle = (String)nameValueData.get("lifeCycle");
        if(lifeCycle != null)
        {
            document = DocumentUtility.setLifeCycleTemplate(document, lifeCycle);
            if(VERBOSE)
                System.out.println("lifecycle = " + lifeCycle);
        }
        String teamTemplate = (String)nameValueData.get("teamTemplateName");
        if(teamTemplate == null)
            teamTemplate = (String)nameValueData.get("teamTemplate");
        if(teamTemplate != null)
        {
            document = DocumentUtility.setTeamTemplate(document, teamTemplate);
            if(VERBOSE)
                System.out.println("teamTemplate = " + teamTemplate);
        }
        HashMap postCreateInfo = new HashMap();
        String submit = (String)nameValueData.get("submitToLifecycle");
        if(submit != null && VERBOSE)
            System.out.println("submit = " + submit);
        postCreateInfo.put("submit", submit);
        document = persistDocumentFromTemplate(template, document, nameValueData, postCreateInfo, "Enterprise", locale);
        if(VERBOSE)
            System.out.println("I am done with creating the document from a template.");
        return document;
    }

    /**
     * @deprecated Method createTemplate is deprecated
     */

    public Templateable createTemplate(TypeIdentifier objType, HashMap nameValueData, Locale locale)
        throws WTException
    {
        if(VERBOSE)
            System.out.println("Entering " + CLASSNAME + ".createTemplate");
        WTDocument document = getUnpersistedTemplate(nameValueData, objType, "Enterprise", locale);
        String dept = (String)nameValueData.get("department");
        String type = (String)nameValueData.get("docType");
        try
        {
            if(dept != null)
                document.setDepartment(DepartmentList.toDepartmentList(dept));
            else
                document.setDepartment(DepartmentList.getDepartmentListDefault());
            if(type != null)
                document.setDocType(DocumentType.toDocumentType(type));
            else
                document.setDocType(DocumentType.getDocumentTypeDefault());
        }
        catch(WTPropertyVetoException wtpve)
        {
            throw new WTException(wtpve, "com.ptc.windchill.enterprise.doc.server.serverResource", "5", null);
        }
        String lifeCycle = (String)nameValueData.get("lifeCycleTemplate");
        if(lifeCycle == null)
            lifeCycle = (String)nameValueData.get("lifeCycle");
        if(VERBOSE)
            System.out.println("lifeCycle" + lifeCycle);
        document = DocumentUtility.setLifeCycleTemplate(document, lifeCycle);
        String teamTemplate = (String)nameValueData.get("teamTemplateName");
        if(teamTemplate == null)
            teamTemplate = (String)nameValueData.get("teamTemplate");
        if(VERBOSE)
            System.out.println("teamTemplate" + teamTemplate);
        document = DocumentUtility.setTeamTemplate(document, teamTemplate);
        HashMap postCreateInfo = new HashMap();
        document = persistDocumentTemplate(document, postCreateInfo, "Enterprise", locale);
        if(VERBOSE)
            System.out.println("I am done with creating the template.");
        return document;
    }

    /**
     * @deprecated Method getTemplates is deprecated
     */

    public Persistable[] getTemplates(Class objClass, String context, Locale locale)
        throws WTException
    {
        if(VERBOSE)
            System.out.println("Starting " + CLASSNAME + ".getTemplates...");
        ReferenceFactory referenceFactory = new ReferenceFactory();
        WTContainer container = (WTContainer)referenceFactory.getReference(context).getObject();
        if(VERBOSE)
            System.out.println("Base type = " + FdnWTContainerHelper.toTypeIdentifier(objClass).toString());
        QuerySpec qs = new QuerySpec(objClass);
        ClassAttribute classAttrName = new ClassAttribute(wt.doc.WTDocument.class, "master>name");
        OrderBy orderByName = new OrderBy(SQLFunction.newSQLFunction("UPPER", classAttrName), false, locale);
        QueryResult qr = EnterpriseHelper.service.getTemplates(container, qs, new OrderBy[] {
            orderByName
        }, true, true, true);
        Persistable templates[] = new Persistable[qr.size()];
        for(int i = 0; i < qr.size(); i++)
            templates[i] = (Persistable)qr.nextElement();

        return templates;
    }

    /**
     * @deprecated Method getTemplateTypes is deprecated
     */

    public TypeIdentifier[] getTemplateTypes(Class objClass, String context, Locale locale)
        throws WTException
    {
        if(VERBOSE)
            System.out.println("Starting " + CLASSNAME + ".getTemplateTypes...");
        ReferenceFactory referenceFactory = new ReferenceFactory();
        WTContainer container = (WTContainer)referenceFactory.getReference(context).getObject();
        if(WTContainerHelper.isClassicContainer(container))
        {
            String class_list = DOC_TYPES;
            StringTokenizer st = new StringTokenizer(class_list, ",");
            Vector list = new Vector();
            String class_name;
            for(; st.hasMoreElements(); list.add(CoreMetaUtility.getTypeIdentifier(class_name)))
                class_name = st.nextToken();

            int size = list.size();
            TypeIdentifier class_array[] = new TypeIdentifier[size];
            for(int i = 0; i < size; i++)
                class_array[i] = (TypeIdentifier)list.get(i);

            return class_array;
        }
        TypeIdentifier base_type = FdnWTContainerHelper.toTypeIdentifier(objClass);
        if(VERBOSE)
            System.out.println("Base type = " + base_type.toString());
        return FdnWTContainerHelper.service.getCreatableDocTemplateTypesForWTContainer(container, base_type);
    }

    /**
     * @deprecated Method getCreateTemplateAttributes is deprecated
     */

    public HashMap getCreateTemplateAttributes(WTContainer context, TypeIdentifier objType, HashMap hashMap, Locale locale)
        throws WTException
    {
        String list[] = getPDMSpecificAttributes("create_template");
        Class obj_class = CoreMetaUtility.getTypeClass(objType);
        boolean autonumber = EnterpriseHelper.isAutoNumber(obj_class, WTContainerRef.newWTContainerRef(context));
        hashMap = getCreateTemplateAttributes(list, context, objType, hashMap, autonumber, locale);
        WindchillAttributeInformation attrib = (WindchillAttributeInformation)hashMap.get("location");
        try
        {
            attrib.setRequired(true);
        }
        catch(WTPropertyVetoException wtpve)
        {
            throw new WTException(wtpve);
        }
        return hashMap;
    }

    /**
     * @deprecated Method getCreateFromTemplateAttributes is deprecated
     */

    public HashMap getCreateFromTemplateAttributes(WTContainer context, Templateable objTemplate, HashMap hashMap, Locale locale)
        throws WTException
    {
        String list[] = getPDMSpecificAttributes("create");
        boolean autonumber = EnterpriseHelper.isAutoNumber(objTemplate, WTContainerRef.newWTContainerRef(context));
        hashMap = getCreateFromTemplateAttributes(list, context, objTemplate, hashMap, autonumber, locale);
        WindchillAttributeInformation attrib = (WindchillAttributeInformation)hashMap.get("location");
        try
        {
            attrib.setRequired(true);
        }
        catch(WTPropertyVetoException wtpve)
        {
            throw new WTException(wtpve);
        }
        return hashMap;
    }

    /**
     * @deprecated Method getUpdateTemplateAttributes is deprecated
     */

    public HashMap getUpdateTemplateAttributes(Templateable object, HashMap hashMap, Locale locale)
        throws WTException
    {
        String list[] = getPDMSpecificAttributes("update_template");
        return getUpdateDocumentAttributes(list, object, hashMap, locale);
    }

    /**
     * @deprecated Method getDetailsTemplateAttributes is deprecated
     */

    public HashMap getDetailsTemplateAttributes(Templateable object, HashMap hashMap, ClientConfiguration clientInfo, Locale locale)
        throws WTException
    {
        String list[] = getPDMSpecificAttributes("display_template");
        return getDetailsDocumentAttributes(list, object, hashMap, clientInfo, locale);
    }

    /**
     * @deprecated Method getCheckinTemplateAttributes is deprecated
     */

    public HashMap getCheckinTemplateAttributes(Templateable object, HashMap hashMap, Locale locale)
        throws WTException
    {
        String list[] = getPDMSpecificAttributes("checkin_template");
        return getCheckinDocumentAttributes(list, object, hashMap, locale);
    }

    /**
     * @deprecated Method getUnpersistedDocumentFromTemplate is deprecated
     */

    protected WTDocument getUnpersistedDocumentFromTemplate(WTDocument template, HashMap nameValueData, String solution, Locale locale)
        throws WTException
    {
        if(VERBOSE)
            System.out.println("Entering " + CLASSNAME + ".getUnpersistedDocumentFromTemplate");
        String number = null;
        String name = null;
        String title = null;
        String desc = null;
        String context = null;
        String org = null;
        String folderRef = null;
        String location = null;
        number = (String)nameValueData.get("number");
        if(number != null && VERBOSE)
            System.out.println("Number = " + number);
        name = (String)nameValueData.get("name");
        if(name != null && VERBOSE)
            System.out.println("Name = " + name);
        title = (String)nameValueData.get("title");
        if(title != null && VERBOSE)
            System.out.println("Title = " + title);
        desc = (String)nameValueData.get("description");
        if(desc != null && VERBOSE)
            System.out.println("Description = " + desc);
        context = (String)nameValueData.get("context");
        if(context == null || context.equals(""))
            context = (String)nameValueData.get("container");
        if(context != null && VERBOSE)
            System.out.println("Context = " + context);
        org = (String)nameValueData.get("OrganizationDN");
        if(org == null || org.equals(""))
        {
            String org_ref = (String)nameValueData.get("organization");
            if(org_ref != null && !org_ref.equals(""))
            {
                ReferenceFactory referenceFactory = new ReferenceFactory();
                WTOrganization wtorg = (WTOrganization)referenceFactory.getReference(org_ref).getObject();
                org = wtorg.getDn();
                RecentlyVisitedHelper.service.addCustomStackObject(wtorg, (wt.org.WTOrganization.class).getName());
            }
        }
        if(org != null && VERBOSE)
            System.out.println("org = " + org);
        folderRef = (String)nameValueData.get("folderRef");
        location = (String)nameValueData.get("location");
        if(folderRef != null && VERBOSE)
            System.out.println("folderRef = " + folderRef);
        if(location != null && VERBOSE)
            System.out.println("location = " + location);
        WTDocument document = null;
        try
        {
            document = (WTDocument)TemplatesFactory.newObjFromTemplate(template, context);
            HashMap mapCreate = new HashMap();
            mapCreate.put("context", context);
            mapCreate.put("OrganizationDN", org);
            if(folderRef != null && folderRef.length() > 0)
                mapCreate.put("folderRef", folderRef);
            if(location != null && location.length() > 0)
                mapCreate.put("location", location);
            document = (WTDocument)TemplatesFactory.doCreateFromTemplateContextTasks(solution, document, document, template, mapCreate);
            document = DocumentUtility.setName(document, name);
            document = DocumentUtility.setTitle(document, title);
            document = DocumentUtility.setDescription(document, desc);
            document = DocumentUtility.setNumber(document, number);
            template = DocumentUtility.setCustomAttributes(template, nameValueData, locale);
            String baseType = TypeHelper.getBaseType(TypeHelper.getTypeIdentifier(document.getClass().getName()));
            try
            {
                TypeHelper.copyCustomModeledAttributes(template, document, baseType, locale);
            }
            catch(ClassNotFoundException cnfe)
            {
                cnfe.printStackTrace(System.err);
            }
        }
        catch(WTException wte)
        {
            throw new WTException(wte, "com.ptc.windchill.enterprise.doc.server.serverResource", "5", null);
        }
        return document;
    }

    /**
     * @deprecated Method persistDocumentFromTemplate is deprecated
     */

    protected WTDocument persistDocumentFromTemplate(WTDocument template, WTDocument document, HashMap nameValueData, HashMap postCreateInfo, String solution, Locale locale)
        throws WTException
    {
        if(VERBOSE)
            System.out.println("Entering " + CLASSNAME + ".persistDocumentFromTemplate");
        if(postCreateInfo == null)
            postCreateInfo = new HashMap();
        String keepCkedOut = null;
        keepCkedOut = (String)nameValueData.get("keepCheckedOut");
        if(keepCkedOut != null && VERBOSE)
            System.out.println("KeepCheckedOut = " + keepCkedOut);
        postCreateInfo.put("keepCheckedOut", keepCkedOut);
        try
        {
            if(VERBOSE)
                System.out.println("Call server to persist and finish copy.");
            document = (WTDocument)TemplatesUtility.saveObjFromTemplate(document, template);
            document = (WTDocument)TemplatesFactory.doPostCreateFromTemplateContextTasks(solution, document, document, template, postCreateInfo);
            RecentlyVisitedHelper.service.addRecentlyVisitedContainer(document.getContainer());
        }
        catch(WTException wte)
        {
            Object param[] = {
                template.getName(), document.getName()
            };
            throw new WTException(wte, "com.ptc.windchill.enterprise.doc.server.serverResource", "11", null);
        }
        if(VERBOSE)
            System.out.println("I am done with creating the document from a template.");
        return document;
    }

    /**
     * @deprecated Method getUnpersistedTemplate is deprecated
     */

    protected WTDocument getUnpersistedTemplate(HashMap nameValueData, TypeIdentifier objType, String solution, Locale locale)
        throws WTException
    {
        String number = null;
        String name = null;
        String title = null;
        String desc = null;
        String enabled = null;
        String context = null;
        String obj_type = null;
        String org = null;
        String folRef = null;
        String location = null;
        number = (String)nameValueData.get("number");
        if(number != null && VERBOSE)
            System.out.println("Number = " + number);
        name = (String)nameValueData.get("name");
        if(name != null && VERBOSE)
            System.out.println("Name = " + name);
        title = (String)nameValueData.get("title");
        if(title != null && VERBOSE)
            System.out.println("Title = " + title);
        desc = (String)nameValueData.get("description");
        if(desc != null && VERBOSE)
            System.out.println("Description = " + desc);
        enabled = (String)nameValueData.get("enabled");
        if(enabled == null || enabled.equals(""))
            enabled = (String)nameValueData.get("template.enabled");
        if(enabled != null && VERBOSE)
            System.out.println("enabled = " + enabled);
        context = (String)nameValueData.get("context");
        if(context == null || context.equals(""))
            context = (String)nameValueData.get("container");
        if(context != null && VERBOSE)
            System.out.println("Context = " + context);
        org = (String)nameValueData.get("OrganizationDN");
        if(org == null || org.equals(""))
        {
            String org_ref = (String)nameValueData.get("organization");
            if(org_ref != null && !org_ref.equals(""))
            {
                ReferenceFactory referenceFactory = new ReferenceFactory();
                WTOrganization wtorg = (WTOrganization)referenceFactory.getReference(org_ref).getObject();
                org = wtorg.getDn();
                RecentlyVisitedHelper.service.addCustomStackObject(wtorg, (wt.org.WTOrganization.class).getName());
            }
        }
        if(org != null && VERBOSE)
            System.out.println("org = " + org);
        folRef = (String)nameValueData.get("folderRef");
        if(folRef != null && VERBOSE)
            System.out.println("folRef = " + folRef);
        location = (String)nameValueData.get("location");
        if(location != null && VERBOSE)
            System.out.println("location = " + location);
        WTDocument document = null;
        obj_type = (String)nameValueData.get("objType");
        if(obj_type != null)
        {
            if(VERBOSE)
                System.out.println("obj_type = " + obj_type);
            document = (WTDocument)TemplatesFactory.newTemplate(obj_type, context);
        } else
        {
            ReferenceFactory referenceFactory = new ReferenceFactory();
            WTContainer container = (WTContainer)referenceFactory.getReference(context).getObject();
            document = (WTDocument)TemplatesFactory.newTemplate(objType, container);
        }
        HashMap mapCreate = new HashMap();
        mapCreate.put("context", context);
        mapCreate.put("OrganizationDN", org);
        mapCreate.put("folderRef", folRef);
        mapCreate.put("location", location);
        document = (WTDocument)TemplatesFactory.doCreateTemplateContextTasks(solution, document, document, mapCreate);
        document = DocumentUtility.setName(document, name);
        document = DocumentUtility.setTitle(document, title);
        document = DocumentUtility.setDescription(document, desc);
        document = DocumentUtility.setNumber(document, number);
        document = DocumentUtility.setEnabled(document, Boolean.valueOf(enabled).booleanValue());
        document = DocumentUtility.setCustomAttributes(document, nameValueData, locale);
        return document;
    }

    /**
     * @deprecated Method persistDocumentTemplate is deprecated
     */

    protected WTDocument persistDocumentTemplate(WTDocument document, HashMap postCreateInfo, String solution, Locale locale)
        throws WTException
    {
        if(VERBOSE)
            System.out.println("Entering " + CLASSNAME + ".persistDocumentTemplate");
        if(document != null)
            document = (WTDocument)PersistenceHelper.manager.save(document);
        document = (WTDocument)TemplatesFactory.doPostCreateTemplateContextTasks(solution, document, document, postCreateInfo);
        RecentlyVisitedHelper.service.addRecentlyVisitedContainer(document.getContainer());
        if(VERBOSE)
            System.out.println("I am done with creating the document template.");
        return document;
    }

    /**
     * @deprecated Method getCreateTemplateAttributes is deprecated
     */

    protected HashMap getCreateTemplateAttributes(String solutionList[], WTContainer context, TypeIdentifier objType, HashMap hashMap, boolean autoNumber, Locale locale)
        throws WTException
    {
        AttributeHelper attribute_helper = new AttributeHelper();
        TypeInstanceIdentifier tii = null;
        if(hashMap == null)
        {
            hashMap = new HashMap();
            tii = objType.newTypeInstanceIdentifier();
        } else
        {
            try
            {
                tii = getTypeInstanceIdentifier(hashMap);
                if(tii == null)
                    tii = objType.newTypeInstanceIdentifier();
            }
            catch(IllegalFormatException ife)
            {
                tii = objType.newTypeInstanceIdentifier();
            }
            catch(UnableToCreateServiceException utcse)
            {
                tii = objType.newTypeInstanceIdentifier();
            }
        }
        int size = solutionList.length;
        int j = 1;
        for(int i = 0; i < size; i++)
        {
            if(autoNumber && solutionList[i].equals("number"))
                continue;
            ReferenceFactory rfac = new ReferenceFactory();
            String cstring = rfac.getReferenceString(ObjectReference.newObjectReference(context.getPersistInfo().getObjectIdentifier()));
            Templateable doc = TemplatesFactory.newTemplate(objType, context);
            WindchillAttributeInformation attrib = WindchillAttributeUtility.getWindchillAttributeInformation(doc, solutionList[i], j, true, attribute_helper, locale);
            try
            {
                if(solutionList[i].equals("name"))
                    attrib.setRequired(true);
                else
                if(solutionList[i].equals("number"))
                    attrib.setRequired(true);
                else
                if(solutionList[i].equals("organization"))
                    attrib.setRequired(true);
                else
                if(solutionList[i].equals("container"))
                {
                    attrib.setRequired(true);
                    attrib.setEditable(false);
                } else
                if(solutionList[i].equals("department"))
                    attrib.setRequired(true);
                else
                if(solutionList[i].equals("lifeCycle"))
                    attrib.setRequired(true);
                else
                if(solutionList[i].equals("template.enabled"))
                    attrib.setValue("true");
            }
            catch(WTPropertyVetoException wtpve)
            {
                throw new WTException(wtpve);
            }
            hashMap.put(attrib.getName(), attrib);
            j++;
        }

        return hashMap;
    }

    /**
     * @deprecated Method getCreateFromTemplateAttributes is deprecated
     */

    protected HashMap getCreateFromTemplateAttributes(String solutionList[], WTContainer context, Templateable template, HashMap hashMap, boolean autoNumber, Locale locale)
        throws WTException
    {
        AttributeHelper attribute_helper = new AttributeHelper();
        TypeInstanceIdentifier tii = null;
        TypeIdentifier type_id = TypeIdentifierUtility.getTypeIdentifier(template);
        if(hashMap == null)
        {
            hashMap = new HashMap();
            tii = type_id.newTypeInstanceIdentifier();
        } else
        {
            try
            {
                tii = getTypeInstanceIdentifier(hashMap);
                if(tii == null)
                    tii = type_id.newTypeInstanceIdentifier();
            }
            catch(IllegalFormatException ife)
            {
                tii = type_id.newTypeInstanceIdentifier();
            }
            catch(UnableToCreateServiceException utcse)
            {
                tii = type_id.newTypeInstanceIdentifier();
            }
        }
        int size = solutionList.length;
        int j = 1;
        for(int i = 0; i < size; i++)
        {
            if(autoNumber && solutionList[i].equals("number"))
                continue;
            WindchillAttributeInformation attrib = WindchillAttributeUtility.getWindchillAttributeInformation(template, solutionList[i], j, true, attribute_helper, locale);
            try
            {
                if(solutionList[i].equals("name"))
                {
                    attrib.setRequired(true);
                    attrib.setValue("");
                } else
                if(solutionList[i].equals("number"))
                    attrib.setRequired(true);
                else
                if(solutionList[i].equals("organization"))
                {
                    OrgContainer org_cont = WTContainerHelper.service.getOrgContainer(context);
                    WTOrganization org = org_cont.getOrganization();
                    attrib = WindchillAttributeUtility.setOrgInAttribInfo(attrib, org, locale);
                    attrib.setRequired(true);
                } else
                if(solutionList[i].equals("container"))
                {
                    attrib.setDisplayValue(context.getName());
                    ReferenceFactory rf = new ReferenceFactory();
                    String cf = rf.getReferenceString(ObjectReference.newObjectReference(context.getPersistInfo().getObjectIdentifier()));
                    attrib.setValue(cf);
                    attrib.setEditable(false);
                    attrib.setRequired(true);
                } else
                if(solutionList[i].equals("docType"))
                {
                    String value = ((WTDocument)template).getDocType().getDisplay();
                    if(value != null)
                        attrib.setDisplayValue(value);
                } else
                if(solutionList[i].equals("department"))
                {
                    String value = ((WTDocument)template).getDepartment().getDisplay();
                    if(value != null)
                        attrib.setDisplayValue(value);
                    attrib.setRequired(true);
                } else
                if(solutionList[i].equals("lifeCycle"))
                {
                    String value = "";
                    LifeCycleTemplateReference lifeCycleTemplate = ((LifeCycleManaged)template).getLifeCycleTemplate();
                    if(lifeCycleTemplate != null)
                    {
                        value = lifeCycleTemplate.getName();
                        attrib.setValue(value);
                        attrib.setDisplayValue(value);
                    }
                    attrib.setRequired(true);
                } else
                if(solutionList[i].equals("teamTemplate"))
                {
                    String value = "";
                    String displayValue = "";
                    TeamTemplateReference teamTemplateID = ((TeamManaged)template).getTeamTemplateId();
                    if(teamTemplateID != null)
                    {
                        displayValue = teamTemplateID.getName();
                        ReferenceFactory rf = new ReferenceFactory();
                        value = rf.getReferenceString(teamTemplateID);
                        attrib.setValue(value);
                        attrib.setDisplayValue(displayValue);
                    }
                } else
                if(solutionList[i].equals("title"))
                    attrib.setValue(((WTDocument)template).getTitle());
                else
                if(solutionList[i].equals("description"))
                    attrib.setValue(((WTDocument)template).getDescription());
                else
                if(solutionList[i].equals("location"))
                {
                    boolean isTemplate = false;
                    Vector folders = ApplicationIntegrationFactory.getOneLevelFolderList(type_id, isTemplate, context, locale, "msoi");
                    String selection_list = (String)folders.get(0);
                    String display_list = (String)folders.get(1);
                    attrib.setList(selection_list);
                    attrib.setDisplayList(display_list);
                }
            }
            catch(WTPropertyVetoException wtpve)
            {
                throw new WTException(wtpve);
            }
            hashMap.put(attrib.getName(), attrib);
            j++;
        }

        return hashMap;
    }

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

    protected HashMap getUpdateDocumentAttributes(String solutionList[], Persistable object, HashMap hashMap, Locale locale)
        throws WTException
    {
        AttributeHelper attribute_helper = new AttributeHelper();
        if(hashMap == null)
            hashMap = new HashMap();
        int size = solutionList.length;
        int j = 1;
        for(int i = 0; i < size; i++)
        {
            String name = solutionList[i];
            boolean editable = true;
            if(name.equals("name") || name.equals("number"))
                editable = false;
            WindchillAttributeInformation attrib = WindchillAttributeUtility.getWindchillAttributeInformation(object, solutionList[i], j++, editable, attribute_helper, locale);
            try
            {
                if(solutionList[i].equals("department"))
                    attrib.setRequired(true);
            }
            catch(WTPropertyVetoException wtpve)
            {
                throw new WTException(wtpve);
            }
            hashMap.put(attrib.getName(), attrib);
        }

        return hashMap;
    }

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

    protected HashMap getCheckinDocumentAttributes(String solutionList[], Persistable object, HashMap hashMap, Locale locale)
        throws WTException
    {
        AttributeHelper attribute_helper = new AttributeHelper();
        if(hashMap == null)
            hashMap = new HashMap();
        int size = solutionList.length;
        int j = 1;
        for(int i = 0; i < size; i++)
        {
            String name = solutionList[i];
            boolean editable = true;
            if(name.equals("name") || name.equals("number"))
                editable = false;
            if(name.equals("template.enabled"))
            {
                WTDocument latestVerIter = (WTDocument)TemplatesUtility.getLatestVersionIteration((WTDocument)object);
                String docVersion = VersionControlHelper.getVersionIdentifier((WTDocument)object).getValue();
                String docIteration = VersionControlHelper.getIterationIdentifier((WTDocument)object).getValue();
                String latestVersion = VersionControlHelper.getVersionIdentifier(latestVerIter).getValue();
                String latestIteration = VersionControlHelper.getIterationIdentifier(latestVerIter).getValue();
                WTUser user = (WTUser)SessionHelper.manager.getPrincipal();
                boolean isadmin = WTContainerHelper.service.isAdministrator(((WTContained)object).getContainerReference(), user);
                if(VERBOSE)
                    System.out.println("isadmin" + isadmin);
                if(!docVersion.equals(latestVersion) || !docIteration.equals(latestIteration) || !isadmin)
                    continue;
            }
            WindchillAttributeInformation attrib = WindchillAttributeUtility.getWindchillAttributeInformation(object, solutionList[i], j++, editable, attribute_helper, locale);
            try
            {
                if(solutionList[i].equals("department"))
                    attrib.setRequired(true);
            }
            catch(WTPropertyVetoException wtpve)
            {
                throw new WTException(wtpve);
            }
            hashMap.put(attrib.getName(), attrib);
        }

        return hashMap;
    }

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

    protected HashMap getDetailsDocumentAttributes(String solutionList[], Persistable object, HashMap hashMap, ClientConfiguration clientInfo, Locale locale)
        throws WTException
    {
        AttributeHelper attribute_helper = new AttributeHelper();
        if(hashMap == null)
            hashMap = new HashMap();
        int size = solutionList.length;
        int j = 1;
        WindchillAttributeInformation context = WindchillAttributeUtility.getShortWindchillAttributeInformation(object, "context", j++, attribute_helper, clientInfo, locale);
        hashMap.put(context.getName(), context);
        for(int i = 0; i < size; i++)
        {
            WindchillAttributeInformation attrib = WindchillAttributeUtility.getShortWindchillAttributeInformation(object, solutionList[i], j++, attribute_helper, clientInfo, locale);
            hashMap.put(attrib.getName(), attrib);
        }

        return hashMap;
    }

    private TypeInstanceIdentifier getTypeInstanceIdentifier(HashMap hashMap)
        throws IllegalFormatException, UnableToCreateServiceException
    {
        Set key_set = hashMap.keySet();
        if(hashMap != null && key_set.size() > 0)
        {
            Iterator iterator = key_set.iterator();
            String attrib_name = (String)iterator.next();
            WindchillAttributeInformation attrib = (WindchillAttributeInformation)hashMap.get(attrib_name);
            String tii_strg = attrib.getTypeInstanceIdentifier();
            IdentifierFactory i_factory = null;
            i_factory = (IdentifierFactory)DefaultServiceProvider.getService(com.ptc.core.meta.common.IdentifierFactory.class, "default");
            return (TypeInstanceIdentifier)i_factory.get(tii_strg);
        } else
        {
            return null;
        }
    }

    private String[] getPDMSpecificAttributes(String operation)
    {
        String list[];
        if(operation.equals("checkin_template"))
        {
            list = (new String[] {
                "number", "name", "department", "title", "description", "template.enabled"
            });
            return list;
        }
        if(operation.equals("update_template"))
        {
            list = (new String[] {
                "number", "name", "department", "title", "description"
            });
            return list;
        }
        String orglist[];
        if(operation.equals("create"))
        {
            list = (new String[] {
                "number", "name", "docType", "department", "title", "location", "lifeCycle", "teamTemplate", "description", "container", 
                "submitToLifecycle"
            });
            orglist = (new String[] {
                "number", "name", "docType", "department", "title", "location", "lifeCycle", "teamTemplate", "description", "container", 
                "organization", "submitToLifecycle"
            });
            if(SHOWORG)
                return orglist;
            else
                return list;
        }
        if(operation.equals("create_template"))
        {
            list = (new String[] {
                "number", "name", "docType", "department", "title", "location", "lifeCycle", "teamTemplate", "description", "container", 
                "template.enabled"
            });
            orglist = (new String[] {
                "number", "name", "docType", "department", "title", "location", "lifeCycle", "teamTemplate", "description", "container", 
                "organization", "template.enabled"
            });
            if(SHOWORG)
                return orglist;
            else
                return list;
        }
        list = (new String[] {
            "type", "number", "name", "department", "title", "description", "versionInfo", "docType", "checkoutInfo", "location", 
            "lifeCycleTemplate", "teamName", "lifeCycleState", "awaitingPromotion", "templated", "template.enabled", "enabledVersion", "primaryName", "primaryFormat", "primarySize", 
            "primaryUpdated", "creator", "createTimestamp", "modifier", "modifyTimestamp", "obid"
        });
        orglist = (new String[] {
            "type", "organizationName", "number", "name", "department", "title", "description", "versionInfo", "docType", "checkoutInfo", 
            "location", "lifeCycleTemplate", "teamName", "lifeCycleState", "awaitingPromotion", "templated", "template.enabled", "enabledVersion", "primaryName", "primaryFormat", 
            "primarySize", "primaryUpdated", "creator", "createTimestamp", "modifier", "modifyTimestamp", "obid"
        });
        if(SHOWORG)
            return orglist;
        else
            return list;
    }

    private static final String RESOURCE = "com.ptc.windchill.enterprise.doc.server.serverResource";
    private static final String CLASSNAME;
    private static final String CREATE_FROM_TEMPLATE = "create";
    private static final String CREATE_TEMPLATE = "create_template";
    private static final String UPDATE_TEMPLATE = "update_template";
    private static final String DISPLAY_TEMPLATE = "display_template";
    private static final String CHECKIN_TEMPLATE = "checkin_template";
    private static boolean VERBOSE = false;
    private static final boolean SHOWORG;
    private static final String DOC_TYPES;

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