]> git.saurik.com Git - wxWidgets.git/blob - wxPython/samples/ide/activegrid/util/xmlutils.py
Docview and IDE patch from Morag Hua with fix for bug #1217890
[wxWidgets.git] / wxPython / samples / ide / activegrid / util / xmlutils.py
1 #----------------------------------------------------------------------------
2 # Name: xmlutils.py
3 # Purpose: XML and Marshaller Utilities
4 #
5 # Author: Jeff Norton
6 #
7 # Created: 6/2/05
8 # CVS-ID: $Id$
9 # Copyright: (c) 2004-2005 ActiveGrid, Inc.
10 # License: wxWindows License
11 #----------------------------------------------------------------------------
12
13 import os
14 import activegrid.util.objutils as objutils
15 import activegrid.util.xmlmarshaller as xmlmarshaller
16
17 agKnownTypes = None
18
19 def defaultLoad(fileObject, knownTypes=None):
20 xml = fileObject.read()
21 loadedObject = unmarshal(xml, knownTypes=knownTypes)
22 if hasattr(fileObject, 'name'):
23 loadedObject.fileName = os.path.abspath(fileObject.name)
24 loadedObject.initialize()
25 return loadedObject
26
27 def unmarshal(xml, knownTypes=None):
28 if not knownTypes: knownTypes = getAgKnownTypes()
29 return xmlmarshaller.unmarshal(xml, knownTypes=knownTypes)
30
31 def defaultSave(fileObject, objectToSave, prettyPrint=True, knownTypes=None, encoding='utf-8'):
32 xml = marshal(objectToSave, prettyPrint=prettyPrint, knownTypes=knownTypes, encoding=encoding)
33 fileObject.write(xml)
34 fileObject.flush()
35
36 def marshal(objectToSave, prettyPrint=True, knownTypes=None, encoding='utf-8'):
37 if not knownTypes: knownTypes = getAgKnownTypes()
38 return xmlmarshaller.marshal(objectToSave, prettyPrint=prettyPrint, knownTypes=knownTypes, encoding=encoding)
39
40 def cloneObject(objectToClone, knownTypes=None, encoding='utf-8'):
41 if not knownTypes: knownTypes = getAgKnownTypes()
42 xml = xmlmarshaller.marshal(objectToClone, prettyPrint=True, knownTypes=knownTypes, encoding=encoding)
43 clonedObject = xmlmarshaller.unmarshal(xml, knownTypes=knownTypes)
44 if hasattr(objectToClone, 'fileName'):
45 clonedObject.fileName = objectToClone.fileName
46 try:
47 clonedObject.initialize()
48 except AttributeError:
49 pass
50 return clonedObject
51
52 def getAgKnownTypes():
53 import activegrid.model.processmodel
54 import activegrid.model.schema
55 import activegrid.data.dataservice
56 import activegrid.server.deployment
57 global agKnownTypes
58 if agKnownTypes == None:
59 tmpAgKnownTypes = {}
60 AG_TYPE_MAPPING = {
61 "ag:append" : "activegrid.model.processmodel.AppendOperation",
62 "ag:body" : "activegrid.model.processmodel.Body",
63 "ag:cssRule" : "activegrid.model.processmodel.CssRule",
64 "ag:datasource" : "activegrid.data.dataservice.DataSource",
65 "ag:debug" : "activegrid.model.processmodel.DebugOperation",
66 "ag:deployment" : "activegrid.server.deployment.Deployment",
67 "ag:glue" : "activegrid.model.processmodel.Glue",
68 "ag:hr" : "activegrid.model.processmodel.HorizontalRow",
69 "ag:image" : "activegrid.model.processmodel.Image",
70 "ag:inputs" : "activegrid.model.processmodel.Inputs",
71 "ag:label" : "activegrid.model.processmodel.Label",
72 "ag:processmodel" : "activegrid.model.processmodel.ProcessModel",
73 "ag:processmodelref" : "activegrid.server.deployment.ProcessModelRef",
74 "ag:query" : "activegrid.model.processmodel.Query",
75 "ag:restParameter" : "activegrid.server.deployment.RestParameter",
76 "ag:restService" : "activegrid.server.deployment.RestService",
77 "ag:schemaOptions" : "activegrid.model.schema.SchemaOptions",
78 "ag:schemaref" : "activegrid.server.deployment.SchemaRef",
79 "ag:serviceref" : "activegrid.server.deployment.ServiceRef",
80 "ag:set" : "activegrid.model.processmodel.SetOperation",
81 "ag:text" : "activegrid.model.processmodel.Text",
82 "ag:title" : "activegrid.model.processmodel.Title",
83 "ag:view" : "activegrid.model.processmodel.View",
84 "bpws:case" : "activegrid.model.processmodel.BPELCase",
85 "bpws:catch" : "activegrid.model.processmodel.BPELCatch",
86 "bpws:faultHandlers" : "activegrid.model.processmodel.BPELFaultHandlers",
87 "bpws:invoke" : "activegrid.model.processmodel.BPELInvoke",
88 "bpws:onMessage" : "activegrid.model.processmodel.BPELOnMessage",
89 "bpws:otherwise" : "activegrid.model.processmodel.BPELOtherwise",
90 "bpws:pick" : "activegrid.model.processmodel.BPELPick",
91 "bpws:process" : "activegrid.model.processmodel.BPELProcess",
92 "bpws:receive" : "activegrid.model.processmodel.BPELReceive",
93 "bpws:reply" : "activegrid.model.processmodel.BPELReply",
94 "bpws:scope" : "activegrid.model.processmodel.BPELScope",
95 "bpws:sequence" : "activegrid.model.processmodel.BPELSequence",
96 "bpws:switch" : "activegrid.model.processmodel.BPELSwitch",
97 "bpws:terminate" : "activegrid.model.processmodel.BPELTerminate",
98 "bpws:variable" : "activegrid.model.processmodel.BPELVariable",
99 "bpws:variables" : "activegrid.model.processmodel.BPELVariables",
100 "bpws:while" : "activegrid.model.processmodel.BPELWhile",
101 "wsdl:message" : "activegrid.model.processmodel.WSDLMessage",
102 "wsdl:part" : "activegrid.model.processmodel.WSDLPart",
103 "xforms:group" : "activegrid.model.processmodel.XFormsGroup",
104 "xforms:input" : "activegrid.model.processmodel.XFormsInput",
105 "xforms:label" : "activegrid.model.processmodel.XFormsLabel",
106 "xforms:output" : "activegrid.model.processmodel.XFormsOutput",
107 "xforms:secret" : "activegrid.model.processmodel.XFormsSecret",
108 "xforms:submit" : "activegrid.model.processmodel.XFormsSubmit",
109 "xs:all" : "activegrid.model.schema.XsdSequence",
110 "xs:complexType" : "activegrid.model.schema.XsdComplexType",
111 "xs:element" : "activegrid.model.schema.XsdElement",
112 "xs:field" : "activegrid.model.schema.XsdKeyField",
113 "xs:key" : "activegrid.model.schema.XsdKey",
114 "xs:keyref" : "activegrid.model.schema.XsdKeyRef",
115 "xs:schema" : "activegrid.model.schema.Schema",
116 "xs:selector" : "activegrid.model.schema.XsdKeySelector",
117 "xs:sequence" : "activegrid.model.schema.XsdSequence",
118 }
119
120 for keyName, className in AG_TYPE_MAPPING.iteritems():
121 try:
122 tmpAgKnownTypes[keyName] = objutils.classForName(className)
123 except KeyError:
124 print "Error mapping knownType", className
125 pass
126 if len(tmpAgKnownTypes) > 0:
127 agKnownTypes = tmpAgKnownTypes
128 return agKnownTypes