]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/samples/ide/activegrid/util/xmlutils.py
1 #----------------------------------------------------------------------------
3 # Purpose: XML and Marshaller Utilities
9 # Copyright: (c) 2004-2005 ActiveGrid, Inc.
10 # License: wxWindows License
11 #----------------------------------------------------------------------------
14 import activegrid
.util
.objutils
as objutils
15 import activegrid
.util
.xmlmarshaller
as xmlmarshaller
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()
27 def unmarshal(xml
, knownTypes
=None):
28 if not knownTypes
: knownTypes
= getAgKnownTypes()
29 return xmlmarshaller
.unmarshal(xml
, knownTypes
=knownTypes
)
31 def defaultSave(fileObject
, objectToSave
, prettyPrint
=True, knownTypes
=None, encoding
='utf-8'):
32 xml
= marshal(objectToSave
, prettyPrint
=prettyPrint
, knownTypes
=knownTypes
, encoding
=encoding
)
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
)
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
47 clonedObject
.initialize()
48 except AttributeError:
52 def getAgKnownTypes():
53 import activegrid
.model
.processmodel
54 import activegrid
.model
.schema
55 import activegrid
.data
.dataservice
56 import activegrid
.server
.deployment
58 if agKnownTypes
== None:
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",
120 for keyName
, className
in AG_TYPE_MAPPING
.iteritems():
122 tmpAgKnownTypes
[keyName
] = objutils
.classForName(className
)
124 print "Error mapping knownType", className
126 if len(tmpAgKnownTypes
) > 0:
127 agKnownTypes
= tmpAgKnownTypes