1 16 17 package org.apache.commons.betwixt.schema; 18 19 import java.beans.IntrospectionException ; 20 21 import org.apache.commons.betwixt.BindingConfiguration; 22 import org.apache.commons.betwixt.ElementDescriptor; 23 import org.apache.commons.betwixt.IntrospectionConfiguration; 24 import org.apache.commons.betwixt.XMLBeanInfo; 25 import org.apache.commons.betwixt.XMLIntrospector; 26 27 38 public class SchemaTranscriber { 39 40 public static final String W3C_SCHEMA_URI = "http://www.w3.org/2001/XMLSchema"; 41 public static final String W3C_SCHEMA_INSTANCE_URI= "http://www.w3.org/2001/XMLSchema-instance"; 42 43 44 private XMLIntrospector introspector = new XMLIntrospector(); 45 private TranscriptionConfiguration configuration = new TranscriptionConfiguration(); 46 47 public SchemaTranscriber() {} 48 49 53 public TranscriptionConfiguration getConfiguration() { 54 return configuration; 55 } 56 57 61 public void setConfiguration(TranscriptionConfiguration configuration) { 62 this.configuration = configuration; 63 } 64 65 69 public XMLIntrospector getXMLIntrospector() { 70 return introspector; 71 } 72 73 81 public void setXMLIntrospector(XMLIntrospector introspector) { 82 this.introspector = introspector; 83 } 84 85 90 public Schema generate(Class clazz) throws IntrospectionException { 91 XMLBeanInfo beanInfo = introspector.introspect(clazz); 92 return generate(beanInfo); 93 } 94 95 100 public Schema generate(XMLBeanInfo xmlBeanInfo) throws IntrospectionException { 101 ElementDescriptor elementDescriptor = xmlBeanInfo.getElementDescriptor(); 102 Schema schema = new Schema(introspector); 103 schema.addGlobalElementType(configuration, elementDescriptor); 104 return schema; 105 } 106 107 117 public IntrospectionConfiguration createSchemaIntrospectionConfiguration() { 118 IntrospectionConfiguration configuration = new IntrospectionConfiguration(); 119 configuration.getPrefixMapper().setPrefix(W3C_SCHEMA_URI, "xsd"); 120 configuration.getPrefixMapper().setPrefix(W3C_SCHEMA_INSTANCE_URI, "xsi"); 121 return configuration; 122 } 123 124 132 public BindingConfiguration createSchemaBindingConfiguration() { 133 BindingConfiguration configuration = new BindingConfiguration(); 134 configuration.setMapIDs(false); 135 return configuration; 136 } 137 } 138 | Popular Tags |