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

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

import com.ptc.windchill.enterprise.templates.doc.server.TemplatesEnterpriseWTDocumentDelegate;
import java.io.*;
import java.util.HashMap;
import wt.admin.AdminDomainRef;
import wt.doc.WTDocument;
import wt.enterprise.RevisionControlled;
import wt.enterprise.Templateable;
import wt.fc.*;
import wt.folder.*;
import wt.inf.container.WTContainer;
import wt.inf.container.WTContainerRef;
import wt.org.*;
import wt.pds.PDSObjectInput;
import wt.util.*;

public class TemplatesPDMLinkWTDocumentDelegate extends TemplatesEnterpriseWTDocumentDelegate
    implements Externalizable
{

    public TemplatesPDMLinkWTDocumentDelegate()
    {
    }

    public void writeExternal(ObjectOutput output)
        throws IOException
    {
        output.writeLong(0x36556656af2b3adL);
        super.writeExternal(output);
    }

    public void readExternal(ObjectInput input)
        throws IOException, ClassNotFoundException
    {
        long readSerialVersionUID = input.readLong();
        readVersion(this, input, readSerialVersionUID, false, false);
    }

    protected boolean readVersion(TemplatesPDMLinkWTDocumentDelegate thisObject, ObjectInput input, long readSerialVersionUID, boolean passThrough, boolean superDone)
        throws IOException, ClassNotFoundException
    {
        boolean success = true;
        if(readSerialVersionUID == 0x36556656af2b3adL)
        {
            if(!superDone)
                super.readExternal(input);
        } else
        {
            success = readOldVersion(input, readSerialVersionUID, passThrough, superDone);
            if(input instanceof PDSObjectInput)
                EvolvableHelper.requestRewriteOfEvolvedBlobbedObject();
        }
        return success;
    }

    private boolean readOldVersion(ObjectInput input, long readSerialVersionUID, boolean passThrough, boolean superDone)
        throws IOException, ClassNotFoundException
    {
        boolean success = true;
        if(readSerialVersionUID != 0x6c1f46b7942fad65L)
            if(!superDone)
            {
                success = super.readVersion(this, input, readSerialVersionUID, false, false);
                if(success && !passThrough && readSerialVersionUID != 0xd4b6b5eeea339daL)
                    readVersion(this, input, input.readLong(), false, true);
            } else
            {
                throw new InvalidClassException(CLASSNAME, "Local class not compatible: stream classdesc externalizationVersionUID=" + readSerialVersionUID + " local class externalizationVersionUID=" + 0x36556656af2b3adL);
            }
        return success;
    }

    public Templateable doCreateTemplateContextTasks(Templateable object, HashMap inputHash)
        throws WTException
    {
        String context = null;
        try
        {
            WTContainer container = null;
            context = (String)inputHash.get("context");
            if(context != null)
                container = (WTContainer)referenceFactory.getReference(context).getObject();
            ((WTDocument)object).setContainer(container);
            WTContainerRef containerRef = ((WTDocument)object).getContainerReference();
            Folder docTempLoc = null;
            ((WTDocument)object).setDomainRef(AdminDomainRef.newAdminDomainRef(((WTContainer)containerRef.getObject()).getSystemDomain()));
            docTempLoc = ((WTContainer)containerRef.getObject()).getSystemCabinet();
            FolderingInfo folderInfo = FolderingInfo.newFolderingInfo(docTempLoc);
            ((WTDocument)object).setFolderingInfo(folderInfo);
            String org = (String)inputHash.get("OrganizationDN");
            WTOrganization wtorg = null;
            if(org != null)
            {
                org = org.trim();
                wt.org.WTPrincipal p = OrganizationServicesHelper.manager.getPrincipalByDN(org);
                wtorg = (WTOrganization)p;
                if(VERBOSE)
                    System.out.println("Organization = " + wtorg.getName());
                ((WTDocument)object).setOrganization(wtorg);
            }
        }
        catch(WTException wte)
        {
            throw new WTException(wte, "com.ptc.windchill.pdmlink.templates.doc.server.serverResource", "0", null);
        }
        catch(WTPropertyVetoException wtpve)
        {
            throw new WTException(wtpve, "com.ptc.windchill.pdmlink.templates.doc.server.serverResource", "0", null);
        }
        return object;
    }

    public RevisionControlled doCreateFromTemplateContextTasks(RevisionControlled object, Templateable template, HashMap inputHash)
        throws WTException
    {
        String context = null;
        try
        {
            WTContainer container = null;
            context = (String)inputHash.get("context");
            if(context != null)
                container = (WTContainer)referenceFactory.getReference(context).getObject();
            ((WTDocument)object).setContainer(container);
            String org = (String)inputHash.get("OrganizationDN");
            WTOrganization wtorg = null;
            if(org != null)
            {
                org = org.trim();
                wt.org.WTPrincipal p = OrganizationServicesHelper.manager.getPrincipalByDN(org);
                wtorg = (WTOrganization)p;
                if(VERBOSE)
                    System.out.println("Organization = " + wtorg.getName());
                ((WTDocument)object).setOrganization(wtorg);
            }
            String folRef = (String)inputHash.get("folderRef");
            if(folRef == null)
                folRef = (String)inputHash.get("location");
            Folder folder = null;
            if(folRef != null)
            {
                folder = (Folder)referenceFactory.getReference(folRef.trim()).getObject();
                if(VERBOSE)
                    System.out.println("folderRef = " + folder.getName());
                FolderHelper.assignLocation((WTDocument)object, folder);
            }
        }
        catch(WTException wte)
        {
            throw new WTException(wte, "com.ptc.windchill.pdmlink.templates.doc.server.serverResource", "1", null);
        }
        catch(WTPropertyVetoException wtpve)
        {
            throw new WTException(wtpve, "com.ptc.windchill.pdmlink.templates.doc.server.serverResource", "1", null);
        }
        return object;
    }

    public Templateable doPostCreateTemplateContextTasks(Templateable object, HashMap inputHash)
        throws WTException
    {
        return object;
    }

    public RevisionControlled doPostCreateFromTemplateContextTasks(RevisionControlled object, Templateable template, HashMap inputHash)
        throws WTException
    {
        return super.doPostCreateFromTemplateContextTasks(object, template, inputHash);
    }

    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.templates.doc.server.serverResource";
    private static final String CLASSNAME;
    static final long serialVersionUID = 1L;
    public static final long EXTERNALIZATION_VERSION_UID = 0x36556656af2b3adL;
    protected static final long OLD_FORMAT_VERSION_UID = 0x6c1f46b7942fad65L;
    private static final ReferenceFactory referenceFactory = new ReferenceFactory();
    private static boolean VERBOSE = false;

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