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

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

import com.ptc.core.meta.common.TypeIdentifier;
import com.ptc.windchill.enterprise.copy.server.ContextUtility;
import com.ptc.windchill.enterprise.copy.server.CoreMetaUtility;
import com.ptc.windchill.enterprise.nativeapp.server.ClientConfiguration;
import java.util.HashMap;
import java.util.Locale;
import wt.doc.WTDocument;
import wt.fc.*;
import wt.inf.container.WTContainer;
import wt.services.applicationcontext.*;
import wt.util.WTException;
import wt.util.WTPropertyVetoException;

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

public class DocumentFactory
    implements ApplicationContextChild
{

    public DocumentFactory()
    {
    }

    public static WTDocument createDocument(TypeIdentifier objType, HashMap nameValueData, Locale locale)
        throws WTException
    {
        WTObject document = CoreMetaUtility.newInstance(objType);
        String uiselector = ContextUtility.getUIType(ContextUtility.getContainer(nameValueData));
        DocumentDelegate delegate = getDocumentDelegate(document, uiselector);
        return delegate.createDocument(objType, nameValueData, locale);
    }

    public static WTDocument createDocument(String objType, HashMap nameValueData, Locale locale)
        throws WTException
    {
        if(objType == null || objType.length() == 0)
        {
            throw new WTException("com.ptc.windchill.enterprise.doc.server.serverResource", "0", null);
        } else
        {
            TypeIdentifier type_id = CoreMetaUtility.getTypeIdentifier(objType);
            return createDocument(type_id, nameValueData, locale);
        }
    }

    public static WTDocument updateDocument(WTDocument document, HashMap nameValueData, Locale locale)
        throws WTException
    {
        String uiselector = ContextUtility.getUIType(document.getContainer());
        DocumentDelegate delegate = getDocumentDelegate(document, uiselector);
        return delegate.updateDocument(document, nameValueData, locale);
    }

    public static TypeIdentifier[] getDocumentType(Class objClass, String context)
        throws WTException
    {
        WTObject document = getDummyObject(objClass);
        ReferenceFactory rf = new ReferenceFactory();
        String uiselector = ContextUtility.getUIType((WTContainer)rf.getReference(context).getObject());
        DocumentDelegate delegate = getDocumentDelegate(document, uiselector);
        return delegate.getDocumentType(objClass, context);
    }

    public static HashMap getCreateDocumentAttributes(WTContainer context, TypeIdentifier objType, HashMap hashMap, Locale locale)
        throws WTException
    {
        WTObject doc = CoreMetaUtility.newInstance(objType);
        String uiselector = ContextUtility.getUIType(context);
        DocumentDelegate delegate = getDocumentDelegate(doc, uiselector);
        return delegate.getCreateDocumentAttributes(context, objType, hashMap, locale);
    }

    public static HashMap getUpdateDocumentAttributes(Persistable object, HashMap hashMap, Locale locale)
        throws WTException
    {
        String uiselector = ContextUtility.getUIType(object);
        DocumentDelegate delegate = getDocumentDelegate(object, uiselector);
        return delegate.getUpdateDocumentAttributes(object, hashMap, locale);
    }

    public static HashMap getDetailsDocumentAttributes(Persistable object, HashMap hashMap, ClientConfiguration clientInfo, Locale locale)
        throws WTException
    {
        String uiselector = ContextUtility.getUIType(object);
        DocumentDelegate delegate = getDocumentDelegate(object, uiselector);
        return delegate.getDetailsDocumentAttributes(object, hashMap, clientInfo, locale);
    }

    public static HashMap getCheckinDocumentAttributes(Persistable object, HashMap hashMap, Locale locale)
        throws WTException
    {
        String uiselector = ContextUtility.getUIType(object);
        DocumentDelegate delegate = getDocumentDelegate(object, uiselector);
        return delegate.getCheckinDocumentAttributes(object, hashMap, locale);
    }

    public ApplicationContext getApplicationContext()
    {
        return applicationContext;
    }

    public void setApplicationContext(ApplicationContext a_ApplicationContext)
        throws WTPropertyVetoException
    {
        applicationContext = a_ApplicationContext;
    }

    public ApplicationContextServices getApplicationContextServices()
    {
        return (ApplicationContextServices)applicationContext;
    }

    private static DocumentDelegate getDocumentDelegate(Object object, String selector)
    {
        DocumentFactory instance = new DocumentFactory();
        instance.applicationContext = ApplicationContextFactory.getTypedApplicationContextServices();
        DocumentDelegate delegate = null;
        delegate = (DocumentDelegate)instance.getApplicationContextServices().getService(instance, object, "com.ptc.windchill.enterprise.doc.server.DocumentDelegate", selector);
        return delegate;
    }

    private static WTObject getDummyObject(Class objClass)
        throws WTException
    {
        WTObject document = null;
        try
        {
            document = (WTObject)objClass.newInstance();
        }
        catch(IllegalAccessException iae)
        {
            Object params[] = {
                objClass.toString()
            };
            throw new WTException(iae, "com.ptc.windchill.enterprise.doc.server.serverResource", "2", params);
        }
        catch(InstantiationException ie)
        {
            Object params[] = {
                objClass.toString()
            };
            throw new WTException(ie, "com.ptc.windchill.enterprise.doc.server.serverResource", "2", params);
        }
        return document;
    }

    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.enterprise.doc.server.serverResource";
    private static final String CLASSNAME;
    private ApplicationContext applicationContext;

    static 
    {
        CLASSNAME = (com.ptc.windchill.enterprise.doc.server.DocumentFactory.class).getName();
    }
}
