/*----------------------------------------------------------------------------
Copyright (c)2000 TogetherSoft Corporation. Patents pending. All rights reserved.
----------------------------------------------------------------------------*/
package com.togethersoft.modules.patterns.JAVA.CLASS.HP_E_Speak.Service_Provider;

import com.togethersoft.openapi.sci.*;
import com.togethersoft.openapi.sci.enum.*;
import com.togethersoft.openapi.sci.pattern.*;
import com.togethersoft.openapi.rwi.*;
import com.togethersoft.openapi.rwi.enum.*;
import com.togethersoft.openapi.ide.progress.*;
import com.togethersoft.openapi.util.propertyMap.*;
//
import com.togethersoft.openapi.ide.IdeAccess;
import com.togethersoft.openapi.ide.message.*;
import com.togethersoft.modules.patterns.UNIVERSAL.PatternBase;
import com.togethersoft.modules.patterns.UNIVERSAL.CLASS.ClassPatternBase;
//import com.togethersoft.modules.patterns.JAVA.CLASS.HP_E_Speak.Client.impl.ESClientProperty;
//
import java.util.Enumeration;
//
import COM.objectspace.jgl.*;

/**
 * Pattern for creating and managing both Entity and Session EJBeans.
 * Even the transition from one EJBean type to another is possible.
 * @author TogetherSoft
 * @version 3.0.0
 */
public class Pattern extends ClassPatternBase implements SciPattern {

        public Pattern() {
                this.template = new com.togethersoft.modules.patterns.JAVA.CLASS.HP_E_Speak.Service_Provider.code.ServiceClassTemplate(getProperties());
                new com.togethersoft.modules.patterns.JAVA.CLASS.HP_E_Speak.Service_Provider.ui.AllPages(getProperties());
                }
        /*
         * Puts the Wizard data right to code.
         */
        public void apply() {
                super.apply();
                if (this.template != null) {
                        this.template.generate(getContainingPackage());
                        }
                }
        /*
         * Checks the Wizard data to make sure valid EJB will be produced upon them.
         */
        public boolean canApply() {
                if (this.template != null) {
                        return this.template.canGenerate();
                        }

                return true;
                }
        /*
         * Implementation of the method, declared in superinterface.
         */
        public boolean prepare() {
                SciObject sciObject = getContainingPackage();
                if (getSelectedClass() != null) {
                        sciObject = getSelectedClass();
                        }

                if (this.template == null) {
                        return super.prepare();
                        }

                if (!this.template.prepare(sciObject)) {
                        return false;
                        }

                return super.prepare();
                }

        private SciPackage getContainingPackage() {
                SciContainer container = (SciContainer) getProperties().getPropertyValue(SciPatternProperty.CONTAINER);
                if (container instanceof SciPackage) {
                        return (SciPackage) container;
                        }

                return null;
                }

        private SciTemplate template;
        }


