@@ -69,77 +69,81 @@ public InspectModule(final XQueryContext context, final FunctionSignature signat
69
69
public Sequence eval (final Sequence [] args , final Sequence contextSequence ) throws XPathException {
70
70
71
71
final XQueryContext tempContext = new XQueryContext (context .getBroker ().getBrokerPool ());
72
- tempContext .setModuleLoadPath (context .getModuleLoadPath ());
73
- final Module [] modules ;
74
- if (isCalledAs (FN_INSPECT_MODULE_NAME )) {
75
- modules = tempContext .importModule (null , null , new AnyURIValue [] { (AnyURIValue ) args [0 ].itemAt (0 ) });
76
- } else {
77
- modules = tempContext .importModule (args [0 ].getStringValue (), null , null );
78
- }
79
-
80
- if (modules == null || modules .length == 0 ) {
81
- return Sequence .EMPTY_SEQUENCE ;
82
- }
83
-
84
- // this function only supports working with a singular module for a namespace!
85
- final Module module = modules [0 ];
86
-
87
72
try {
88
- context .pushDocumentContext ();
89
- final MemTreeBuilder builder = context .getDocumentBuilder ();
90
- final AttributesImpl attribs = new AttributesImpl ();
91
- attribs .addAttribute ("" , "uri" , "uri" , "CDATA" , module .getNamespaceURI ());
92
- attribs .addAttribute ("" , "prefix" , "prefix" , "CDATA" , module .getDefaultPrefix ());
93
- if (module .isInternalModule ()) {
94
- attribs .addAttribute ("" , "location" , "location" , "CDATA" , "java:" + module .getClass ().getName ());
95
- } else if (isCalledAs ("inspect-module" )) {
96
- attribs .addAttribute ("" , "location" , "location" , "CDATA" , args [0 ].getStringValue ());
73
+ tempContext .setModuleLoadPath (context .getModuleLoadPath ());
74
+ final Module [] modules ;
75
+ if (isCalledAs (FN_INSPECT_MODULE_NAME )) {
76
+ modules = tempContext .importModule (null , null , new AnyURIValue []{(AnyURIValue ) args [0 ].itemAt (0 )});
77
+ } else {
78
+ modules = tempContext .importModule (args [0 ].getStringValue (), null , null );
97
79
}
98
- final int nodeNr = builder .startElement (MODULE_QNAME , attribs );
99
- if (!module .isInternalModule ()) {
100
- XQDocHelper .parse ((ExternalModule ) module );
101
- }
102
- if (module .getDescription () != null ) {
103
- builder .startElement (InspectFunctionHelper .DESCRIPTION_QNAME , null );
104
- builder .characters (module .getDescription ());
105
- builder .endElement ();
80
+
81
+ if (modules == null || modules .length == 0 ) {
82
+ return Sequence .EMPTY_SEQUENCE ;
106
83
}
107
- if (!module .isInternalModule ()) {
108
- final ExternalModule externalModule = (ExternalModule ) module ;
109
- if (externalModule .getMetadata () != null ) {
110
- for (final Map .Entry <String , String > entry : externalModule .getMetadata ().entrySet ()) {
111
- builder .startElement (new QName (entry .getKey (), XMLConstants .NULL_NS_URI ), null );
112
- builder .characters (entry .getValue ());
113
- builder .endElement ();
114
- }
84
+
85
+ // this function only supports working with a singular module for a namespace!
86
+ final Module module = modules [0 ];
87
+
88
+ try {
89
+ context .pushDocumentContext ();
90
+ final MemTreeBuilder builder = context .getDocumentBuilder ();
91
+ final AttributesImpl attribs = new AttributesImpl ();
92
+ attribs .addAttribute ("" , "uri" , "uri" , "CDATA" , module .getNamespaceURI ());
93
+ attribs .addAttribute ("" , "prefix" , "prefix" , "CDATA" , module .getDefaultPrefix ());
94
+ if (module .isInternalModule ()) {
95
+ attribs .addAttribute ("" , "location" , "location" , "CDATA" , "java:" + module .getClass ().getName ());
96
+ } else if (isCalledAs ("inspect-module" )) {
97
+ attribs .addAttribute ("" , "location" , "location" , "CDATA" , args [0 ].getStringValue ());
115
98
}
116
- // variables
117
- for (final VariableDeclaration var : externalModule .getVariableDeclarations ()) {
118
- attribs .clear ();
119
- attribs .addAttribute ("" , "name" , "name" , "CDATA" , var .getName ().toString ());
120
- final SequenceType type = var .getSequenceType ();
121
- if (type != null ) {
122
- attribs .addAttribute ("" , "type" , "type" , "CDATA" , Type .getTypeName (type .getPrimaryType ()));
123
- attribs .addAttribute ("" , "cardinality" , "cardinality" , "CDATA" , type .getCardinality ().getHumanDescription ());
124
- }
125
- builder .startElement (VARIABLE_QNAME , attribs );
99
+ final int nodeNr = builder .startElement (MODULE_QNAME , attribs );
100
+ if (!module .isInternalModule ()) {
101
+ XQDocHelper .parse ((ExternalModule ) module );
102
+ }
103
+ if (module .getDescription () != null ) {
104
+ builder .startElement (InspectFunctionHelper .DESCRIPTION_QNAME , null );
105
+ builder .characters (module .getDescription ());
126
106
builder .endElement ();
127
107
}
128
- }
129
- // functions
130
- for (final FunctionSignature sig : module .listFunctions ()) {
131
- if (!sig .isPrivate ()) {
132
- UserDefinedFunction func = null ;
133
- if (!module .isInternalModule ()) {
134
- func = ((ExternalModule ) module ).getFunction (sig .getName (), sig .getArgumentCount (), null );
108
+ if (!module .isInternalModule ()) {
109
+ final ExternalModule externalModule = (ExternalModule ) module ;
110
+ if (externalModule .getMetadata () != null ) {
111
+ for (final Map .Entry <String , String > entry : externalModule .getMetadata ().entrySet ()) {
112
+ builder .startElement (new QName (entry .getKey (), XMLConstants .NULL_NS_URI ), null );
113
+ builder .characters (entry .getValue ());
114
+ builder .endElement ();
115
+ }
116
+ }
117
+ // variables
118
+ for (final VariableDeclaration var : externalModule .getVariableDeclarations ()) {
119
+ attribs .clear ();
120
+ attribs .addAttribute ("" , "name" , "name" , "CDATA" , var .getName ().toString ());
121
+ final SequenceType type = var .getSequenceType ();
122
+ if (type != null ) {
123
+ attribs .addAttribute ("" , "type" , "type" , "CDATA" , Type .getTypeName (type .getPrimaryType ()));
124
+ attribs .addAttribute ("" , "cardinality" , "cardinality" , "CDATA" , type .getCardinality ().getHumanDescription ());
125
+ }
126
+ builder .startElement (VARIABLE_QNAME , attribs );
127
+ builder .endElement ();
135
128
}
136
- InspectFunctionHelper .generateDocs (sig , func , builder );
137
129
}
130
+ // functions
131
+ for (final FunctionSignature sig : module .listFunctions ()) {
132
+ if (!sig .isPrivate ()) {
133
+ UserDefinedFunction func = null ;
134
+ if (!module .isInternalModule ()) {
135
+ func = ((ExternalModule ) module ).getFunction (sig .getName (), sig .getArgumentCount (), null );
136
+ }
137
+ InspectFunctionHelper .generateDocs (sig , func , builder );
138
+ }
139
+ }
140
+ builder .endElement ();
141
+ return builder .getDocument ().getNode (nodeNr );
142
+ } finally {
143
+ context .popDocumentContext ();
138
144
}
139
- builder .endElement ();
140
- return builder .getDocument ().getNode (nodeNr );
141
145
} finally {
142
- context .popDocumentContext ( );
146
+ context .addImportedContext ( tempContext );
143
147
}
144
148
}
145
149
}
0 commit comments