+
+def AddWsdlAgToProjectFromWsdlRegistration(wsdlRegistration):
+ """Add wsdl ag for registry entry."""
+
+ wsdlPath = wsdlRegistration.path
+ rootPath = None
+ serviceRefName = wsdlRegistration.name
+
+ agwsDoc = _InitWsdlAg(wsdlPath, rootPath, serviceRefName)
+
+ if (agwsDoc == None):
+ return
+
+ serviceRef = agwsDoc.GetModel()
+
+ serviceRef.serviceType = wsdlRegistration.type
+
+ import activegrid.server.deployment as deployment
+
+ if (serviceRef.serviceType == deployment.SERVICE_LOCAL):
+ serviceRef.localService = deployment.LocalService(
+ wsdlRegistration.codeFile)
+
+ elif (serviceRef.serviceType == deployment.SERVICE_DATABASE):
+ serviceRef.databaseService = deployment.DatabaseService(
+ wsdlRegistration.datasourceName)
+
+ elif (serviceRef.serviceType == deployment.SERVICE_SOAP):
+ pass
+
+ elif (serviceRef.serviceType == deployment.SERVICE_RSS):
+ serviceRef.rssService = deployment.RssService(wsdlRegistration.feedUrl)
+
+ elif (serviceRef.serviceType == deployment.SERVICE_REST):
+ serviceRef.restService = deployment.RestService(
+ wsdlRegistration.baseUrl)
+ else:
+ raise AssertionError("Unknown service type")
+
+ _AddToProject(agwsDoc, addWsdl=True)
+
+
+def AddWsdlAgToProject(wsdlPath, rootPath=fileutils.AG_SYSTEM_STATIC_VAR_REF,
+ serviceRefName=None, className=None, serviceType=None,
+ dataSourceName=None):
+ """
+ wsdlPath: path to wsdl from rootPath. If wsdlPath is absolute, rootPath
+ is ignored. rootPath is also ignored when rootPath is set to None.
+ rootPath: defaults to ${AG_SYSTEM_STATIC}.
+ serviceRefName: If None, it will be set to the wsdl file name without
+ the .wsdl file extension.
+ className: if not None, will be used for the the wsdlag's ClassName.
+ serviceType: defaults to local.
+ dataSourceName: if serviceType is deployment.DATABASE, the ds must be
+ provided.
+ """
+ import WsdlAgEditor
+ import XFormWizard
+ import activegrid.model.basedocmgr as basedocmgr
+ import activegrid.server.deployment as deployment
+
+ if (serviceType == None):
+ serviceType = deployment.SERVICE_LOCAL
+
+
+ agwsDoc = _InitWsdlAg(wsdlPath, rootPath, serviceRefName)
+
+ if (agwsDoc == None):
+ return
+
+ serviceRef = agwsDoc.GetModel()
+
+ serviceRef.serviceType = serviceType
+
+ if (serviceType == deployment.SERVICE_DATABASE and dataSourceName != None):
+ serviceRef.databaseService = deployment.DatabaseService(dataSourceName)
+ else:
+ serviceRef.localService = deployment.LocalService(className=className)
+
+ _AddToProject(agwsDoc)
+
+
+def _AddToProject(agwsDoc, addWsdl=False):
+ import activegrid.model.basedocmgr as basedocmgr
+ projectDoc = GetCurrentProject()
+ agwsDoc.OnSaveDocument(agwsDoc.GetFilename())
+
+ files = [agwsDoc.fileName]
+ types = [basedocmgr.FILE_TYPE_SERVICE]
+ names = [agwsDoc.GetModel().name]
+ if (addWsdl):
+ m = agwsDoc.GetModel()
+ wsdlName = os.path.splitext(os.path.basename(m.filePath))[0]
+ appDocMgr = projectDoc.GetAppDocMgr()
+ if (appDocMgr.findService(wsdlName) == None):
+ m = agwsDoc.GetModel()
+ files.append(m.filePath)
+ types.append(None)
+ names.append(wsdlName)
+
+ ProjectEditor.ProjectAddFilesCommand(projectDoc, files, types=types,
+ names=names).Do()
+
+
+def _InitWsdlAg(wsdlPath, rootPath=fileutils.AG_SYSTEM_STATIC_VAR_REF,
+ serviceRefName=None):
+
+ projectDoc = GetCurrentProject()
+ appDocMgr = projectDoc.GetAppDocMgr()
+
+ if (serviceRefName == None):
+ serviceRefName = os.path.splitext(os.path.basename(wsdlPath))[0]
+
+ if (appDocMgr.findServiceRef(serviceRefName) != None):
+ return None
+
+ import WsdlAgEditor
+ import XFormWizard
+ import activegrid.server.deployment as deployment
+
+ template = XFormWizard.GetTemplate(WsdlAgEditor.WsdlAgDocument)
+ ext = template.GetDefaultExtension()
+ fullPath = os.path.join(appDocMgr.homeDir, serviceRefName + ext)
+
+ agwsDoc = template.CreateDocument(
+ fullPath, flags=(wx.lib.docview.DOC_NO_VIEW|wx.lib.docview.DOC_NEW|
+ wx.lib.docview.DOC_OPEN_ONCE))
+
+ serviceRef = agwsDoc.GetModel()
+ serviceRef.name = serviceRefName
+
+ if (rootPath == None or os.path.isabs(wsdlPath)):
+ serviceRef.filePath = wsdlPath
+ else:
+ # make sure to use forward slashes for the path to the .wsdl
+ wsdlPath = wsdlPath.replace("\\", "/")
+
+ if not wsdlPath.startswith("/"):
+ wsdlPath = "/%s" % wsdlPath
+ serviceRef.filePath = "%s%s" % (rootPath, wsdlPath)
+
+ agwsDoc.fileName = fullPath
+
+ return agwsDoc
+
+
+def GetSchemaName(schema):
+ return os.path.basename(schema.fileName)
+
+
+class AGChoice(wx.Choice):
+ """Extension to wx.Choice that fixes linux bug where first item of choices
+ passed into ctor would be visible, but not selected."""
+ def __init__(self, parent, id, choices=[]):
+ super(AGChoice, self).__init__(parent=parent, id=id)
+ self.AppendItems(choices)