Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "EclipseLink/UserGuide/MOXy/Runtime/Bootstrapping/Generating Schema"

m
m
 
Line 1: Line 1:
 
'''[[Image:Elug_draft_icon.png|Warning]] For the current release, see [http://www.eclipse.org/eclipselink/documentation/2.4/moxy Developing JAXB Applications Using EclipseLink MOXy, EclipseLink 2.4]
 
'''[[Image:Elug_draft_icon.png|Warning]] For the current release, see [http://www.eclipse.org/eclipselink/documentation/2.4/moxy Developing JAXB Applications Using EclipseLink MOXy, EclipseLink 2.4]
 
'''
 
'''
----
 
  
{{EclipseLink_UserGuide
 
|info=y
 
|api=y
 
|apis= * [http://www.eclipse.org/eclipselink/api/2.1/index.html?org/eclipse/persistence/jaxb/JAXBContextFactory.html *.jaxb.JAXBContextFactory]
 
|eclipselink=y
 
|eclipselinktype=MOXy
 
|examples=y
 
|example=* [[EclipseLink/Examples/MOXy/JAXB/GenerateSchema|Generate Schema]]
 
}}
 
=Generating an XML Schema=
 
  
To generate an XML schema from a Java object model:
+
http://www.eclipse.org/eclipselink/documentation/2.4/moxy/runtime005.htm
 
+
<ol>
+
<li>Create a class that extends '''javax.xml.bind.SchemaOutputResolver'''.
+
<source lang="java">
+
private class MySchemaOutputResolver extends SchemaOutputResolver {
+
+
  public Result createOutput(String uri, String suggestedFileName) throws IOException {
+
      File file = new File(suggestedFileName);
+
      StreamResult result = new StreamResult(file);
+
      result.setSystemId(file.toURI().toURL().toString());
+
      return result;
+
  }
+
+
}
+
</source></li>
+
<li>Use an instance of this class with '''JAXBContext''' to capture the generated XML Schema.
+
<source lang="java">
+
Class[] classes = new Class[4];
+
classes[0] = org.example.customer_example.AddressType.class;
+
classes[1] = org.example.customer_example.ContactInfo.class;
+
classes[2] = org.example.customer_example.CustomerType.class;
+
classes[3] = org.example.customer_example.PhoneNumber.class;
+
JAXBContext jaxbContext = JAXBContext.newInstance(classes);
+
+
SchemaOutputResolver sor = new MySchemaOutputResolver();
+
jaxbContext.generateSchema(sor);
+
</source></li>
+
</ol>
+
 
+
 
+
 
+
{{EclipseLink_MOXy
+
|previous=[[EclipseLink/UserGuide/MOXy/Runtime/Bootstrapping|Bootstrapping]]
+
|next= [[EclipseLink/UserGuide/MOXy/Runtime/Validating Against an XML Schema|Validating Against an XML Schema]]
+
}}
+

Latest revision as of 16:28, 6 November 2012

Warning For the current release, see Developing JAXB Applications Using EclipseLink MOXy, EclipseLink 2.4


http://www.eclipse.org/eclipselink/documentation/2.4/moxy/runtime005.htm

Back to the top