+    def GetAppInfo(self):
+        return self.GetModel().GetAppInfo()
+
+
+    def GetAppDocMgr(self):
+        return self.GetModel()
+        
+
+    def GetProjectName(self):
+        return os.path.splitext(os.path.basename(self.GetFilename()))[0]
+
+
+    def GetDeploymentFilepath(self):
+        projectName = self.GetProjectName()
+        return os.path.join(self.GetModel().homeDir, projectName + "RunTime_tmp" + deploymentlib.DEPLOYMENT_EXTENSION)
+        
+
+    def GenerateDeployment(self, deployFilepath=None, preview=False, productionDeployment=False):
+        if ACTIVEGRID_BASE_IDE:
+            return
+        
+        def FindOpenDoc(filePath):
+            openDocs = wx.GetApp().GetDocumentManager().GetDocuments()
+            for openDoc in openDocs:
+                if openDoc.GetFilename() == filePath:
+                    return openDoc
+            return None
+
+        if not deployFilepath:
+            deployFilepath = self.GetDeploymentFilepath()
+            
+        deployment = deploymentlib.Deployment(deployFilepath)
+
+        defaultFlagsNoView = wx.GetApp().GetDocumentManager().GetFlags()|wx.lib.docview.DOC_SILENT|wx.lib.docview.DOC_OPEN_ONCE|wx.lib.docview.DOC_NO_VIEW
+        self.GetAppInfo().CopyToDeployment(deployment)
+
+        for file in self.GetModel()._files:
+            if not file.type:
+                continue
+            elif file.type == basedocmgr.FILE_TYPE_SERVICE:  # set serviceRefs
+                doc = wx.GetApp().GetDocumentManager().CreateDocument(file.filePath, flags=defaultFlagsNoView)
+                if (doc == None):  # already open
+                    doc = FindOpenDoc(file.filePath)
+                if doc:
+                    serviceRef = doc.GetModel()
+                    if serviceRef:
+                        documentRef = copy.copy(serviceRef)
+                        deployment.serviceRefs.append(documentRef)
+
+                        if not productionDeployment:
+                            # filePath should point to location of wsdl file
+                            # wsdlag filePath points to relative path to wsdl file from wsdlag location
+                            # but deployment needs relative path from deployment location, so here's the conversion
+                            curDir = os.path.dirname(self.GetFilename()) + os.sep
+                            filePath = file.document.fileName
+                            if (filePath == None):
+                                raise Exception("Cannot find file \"%s\"" % file.filePath)
+                            if filePath.startswith(curDir):
+                                filePath = filePath[len(curDir):]
+                            if os.sep != '/':
+                                filePath = filePath.replace(os.sep, "/")
+                            documentRef.filePath = filePath
+                        
+                            documentRef.document = file.document
+                            
+                        if serviceRef.serviceType == deploymentlib.SERVICE_DATABASE and serviceRef.databaseService:
+                            dataSourceService = wx.GetApp().GetService(DataModelEditor.DataSourceService)
+                            ds = dataSourceService.getDataSource(serviceRef.databaseService.datasourceName)
+                            if ds:
+                                found = False
+                                for d in deployment.dataSources:
+                                    if d.name == ds.name:
+                                        found = True
+                                        break
+                                if not found:
+                                    deployment.dataSources.append(ds)
+            else:
+                curDir = os.path.dirname(self.GetFilename()) + os.sep
+                filePath = file.filePath
+                if filePath.startswith(curDir):
+                    filePath = filePath[len(curDir):]
+                if os.sep != '/':
+                    filePath = filePath.replace(os.sep, "/")
+                    
+                if file.type == basedocmgr.FILE_TYPE_XFORM:
+                    documentRef = deploymentlib.XFormRef()
+                    deployment.xformRefs.append(documentRef)
+                elif file.type == basedocmgr.FILE_TYPE_PROCESS:
+                    documentRef = deploymentlib.ProcessRef()
+                    deployment.processRefs.append(documentRef)
+                elif file.type == basedocmgr.FILE_TYPE_SCHEMA:
+                    # set schemaRefs
+                    documentRef = deploymentlib.SchemaRef()
+                    deployment.schemaRefs.append(documentRef)
+
+                    # set dataSources
+                    doc = wx.GetApp().GetDocumentManager().CreateDocument(file.filePath, flags=defaultFlagsNoView)
+                    if (doc == None):  # already open
+                        doc = FindOpenDoc(file.filePath)
+                    if doc:
+                        dataSourceService = wx.GetApp().GetService(DataModelEditor.DataSourceService)
+                        ds = dataSourceService.getDataSource(doc.GetModel().getDefaultDataSourceName())
+                        if ds:
+                            found = False
+                            for d in deployment.dataSources:
+                                if d.name == ds.name:
+                                    found = True
+                                    break
+                            if not found:
+                                deployment.dataSources.append(ds)
+                                
+                        # set keyServices
+                        keyServices = doc.GetModel().keyServices
+                        for keyService in keyServices:        
+                            # add default key service to deployment
+                            if not productionDeployment:
+                                mainModuleDir = sysutils.mainModuleDir
+                            else:
+                                mainModuleDir = sysutils.MAINMODULE_DIR_VAR
+                            wsdlFullPath = os.path.join(mainModuleDir, "..", "wsdl", DataModelEditor.DEFAULT_KEYSERVICE_WSDL_FILENAME)
+                            keyServiceRef = deploymentlib.ServiceRef(filePath=wsdlFullPath)
+                            deployment.serviceRefs.append(keyServiceRef)
+                            
+                            keyServiceRef.name = keyService
+                            keyServiceRef.serviceType = deploymentlib.SERVICE_LOCAL
+                            keyServiceRef.localService = deploymentlib.LocalService()
+                            if keyService == DataModelEditor.DEFAULT_KEYSERVICE:
+                                keyServiceRef.filePath = wsdlFullPath
+                                keyServiceRef.localServiceClassName = DataModelEditor.DEFAULT_KEYSERVICE_CLASSNAME
+                            
+
+                elif file.type == basedocmgr.FILE_TYPE_SKIN:
+                    documentRef = deploymentlib.SkinRef(deployment)
+                    deployment.skinref = documentRef
+                elif file.type == basedocmgr.FILE_TYPE_IDENTITY:
+                    documentRef = deploymentlib.IdentityRef()
+                    deployment.identityRefs.append(documentRef)
+                else:
+                    continue
+                        
+                documentRef.name = file.name
+                documentRef.filePath = filePath
+                doc = FindOpenDoc(file.filePath)
+                if doc and hasattr(doc, 'GetModel'):
+                    documentRef.document = doc.GetModel()
+                    if isinstance(documentRef, deploymentlib.XFormRef):
+                        doc.GetModel().linkDeployment(deployment, deployment.loader)
+       
+        if preview:
+            deployment.initialize()  # used in preview only
+            
+        if 0: # preview:  # setPrototype not working, commented this out
+            deploymentlib._deploymentCache.setPrototype(deployment.fileName, deployment)
+        else:
+            deploymentlib.saveThroughCache(deployment.fileName, deployment)
+
+        return deployFilepath        
+        
+
+    def AddNameSpaces(self, filePaths):
+        """ Add any new wsdl namespaces to bpel files """
+        """ Add any new schema namespaces to wsdl files """
+        if ACTIVEGRID_BASE_IDE:
+            return
+
+        serviceRefs = self.GetAppDocMgr().allServiceRefs  # wsdl
+
+        processRefs = self.GetAppDocMgr().findRefsByFileType(basedocmgr.FILE_TYPE_PROCESS) # bpel
+        if processRefs and serviceRefs:
+            for processRef in processRefs:
+                processDoc = processRef._GetDoc()
+                process = processDoc.GetModel()
+                
+                modified = False
+                for serviceRef in serviceRefs:
+                    wsdl = serviceRef.document
+                    if (wsdl.fileName in filePaths
+                    or serviceRef.filePath in filePaths):
+                        wsdlLongNS = wsdl.targetNamespace
+                        wsdlShortNS = self.GetAppDocMgr().findShortNS(wsdlLongNS)
+                        if not wsdlShortNS:
+                            wsdlShortNS = xmlutils.genShortNS(process, wsdlLongNS)
+                        xmlutils.addNSAttribute(process, wsdlShortNS, wsdlLongNS)
+                        modified = True
+                if modified:
+                    processDoc.OnSaveDocument(processDoc.GetFilename())
+
+        schemaRefs = self.GetAppDocMgr().findRefsByFileType(basedocmgr.FILE_TYPE_SCHEMA)
+        if schemaRefs and serviceRefs:
+            for serviceRef in serviceRefs:
+                wsdl = serviceRef.document
+                wsdlDoc = serviceRef.ideDocument
+                
+                modified = False
+                for schemaRef in schemaRefs:
+                    schema = schemaRef.document
+                    if schema.fileName in filePaths:
+                        schemaLongNS = schema.targetNamespace
+                        schemaShortNS = self.GetAppDocMgr().findShortNS(schemaLongNS)
+                        if not schemaShortNS:
+                            schemaShortNS = xmlutils.genShortNS(process, schemaLongNS)
+                        xmlutils.addNSAttribute(wsdl, schemaShortNS, schemaLongNS)
+                        modified = True
+                if modified:
+                    wsdlDoc.OnSaveDocument(wsdlDoc.GetFilename())