File tree Expand file tree Collapse file tree 2 files changed +18
-21
lines changed
main/java/org/springframework/xml/xsd/commons
test/java/org/springframework/xml/xsd/commons Expand file tree Collapse file tree 2 files changed +18
-21
lines changed Original file line number Diff line number Diff line change 2323import java .util .List ;
2424import javax .xml .namespace .QName ;
2525import javax .xml .transform .Source ;
26+ import javax .xml .transform .dom .DOMSource ;
2627import javax .xml .transform .stream .StreamSource ;
2728
2829import org .apache .ws .commons .schema .XmlSchema ;
30+ import org .apache .ws .commons .schema .XmlSchemaSerializer ;
31+ import org .w3c .dom .Document ;
2932
33+ import org .springframework .beans .BeanInstantiationException ;
34+ import org .springframework .beans .BeanUtils ;
3035import org .springframework .util .Assert ;
3136import org .springframework .xml .xsd .XsdSchema ;
3237
@@ -67,6 +72,19 @@ public QName[] getElementNames() {
6772 }
6873
6974 public Source getSource () {
75+ // try to use the the package-friendly XmlSchemaSerializer first, fall back to slower stream-based version
76+ try {
77+ XmlSchemaSerializer serializer =
78+ (XmlSchemaSerializer ) BeanUtils .instantiateClass (XmlSchemaSerializer .class );
79+ Document [] serializesSchemas = serializer .serializeSchema (schema , false );
80+ return new DOMSource (serializesSchemas [0 ]);
81+ }
82+ catch (BeanInstantiationException ex ) {
83+ // ignore
84+ }
85+ catch (XmlSchemaSerializer .XmlSchemaSerializerException ex ) {
86+ // ignore
87+ }
7088 ByteArrayOutputStream bos = new ByteArrayOutputStream ();
7189 schema .write (bos );
7290 ByteArrayInputStream bis = new ByteArrayInputStream (bos .toByteArray ());
Original file line number Diff line number Diff line change @@ -32,25 +32,4 @@ protected XsdSchema createSchema(Resource resource) throws Exception {
3232 return new CommonsXsdSchema (schema );
3333 }
3434
35- /*
36- public void testInline() throws Exception {
37- Resource resource = new ClassPathResource("A.xsd", AbstractXsdSchemaTestCase.class);
38- CommonsXsdSchema schema = new CommonsXsdSchema(resource);
39- XsdSchema[] inlined = schema.inline();
40- for (int i = 0; i < inlined.length; i++) {
41- transformer.transform(inlined[i].getSource(), new StreamResult(System.out));
42- System.out.println();
43- }
44- }
45-
46- public void testCircular() throws Exception {
47- Resource resource = new ClassPathResource("circular-1.xsd", AbstractXsdSchemaTestCase.class);
48- CommonsXsdSchema schema = new CommonsXsdSchema(resource);
49- XsdSchema[] inlined = schema.inline();
50- for (int i = 0; i < inlined.length; i++) {
51- transformer.transform(inlined[i].getSource(), new StreamResult(System.out));
52- System.out.println();
53- }
54- }
55- */
5635}
You can’t perform that action at this time.
0 commit comments