1 22 package org.jboss.xb.binding; 23 24 import java.io.InputStream ; 25 import java.io.Reader ; 26 27 import org.jboss.xb.binding.parser.JBossXBParser; 28 import org.jboss.xb.binding.parser.sax.SaxJBossXBParser; 29 import org.jboss.xb.binding.sunday.unmarshalling.SchemaBinding; 30 import org.jboss.xb.binding.sunday.unmarshalling.SchemaBindingResolver; 31 import org.jboss.xb.binding.sunday.unmarshalling.SundayContentHandler; 32 import org.jboss.xb.binding.metadata.unmarshalling.DocumentBinding; 33 import org.xml.sax.EntityResolver ; 34 import org.xml.sax.ErrorHandler ; 35 36 43 public class UnmarshallerImpl implements Unmarshaller 44 { 45 private ObjectModelBuilder builder = new ObjectModelBuilder(); 46 private final JBossXBParser parser; 47 48 50 53 public UnmarshallerImpl() throws JBossXBException 54 { 55 parser = new SaxJBossXBParser(); 56 } 57 58 public void setValidation(boolean validation) throws JBossXBException 59 { 60 parser.setFeature(VALIDATION, validation); 61 } 62 63 public void setSchemaValidation(boolean validation) throws JBossXBException 64 { 65 parser.setFeature(SCHEMA_VALIDATION, validation); 66 } 67 68 public void setFeature(String feature, boolean value) throws JBossXBException 69 { 70 parser.setFeature(feature, value); 71 } 72 73 public void setNamespaceAware(boolean namespaces) throws JBossXBException 74 { 75 parser.setFeature(NAMESPACES, namespaces); 76 } 77 78 public void setEntityResolver(EntityResolver entityResolver) throws JBossXBException 79 { 80 parser.setEntityResolver(entityResolver); 81 } 82 83 public void setErrorHandler(ErrorHandler errorHandler) 84 { 85 } 87 88 public void mapFactoryToNamespace(ObjectModelFactory factory, String namespaceUri) 89 { 90 if(builder == null) 91 { 92 builder = new ObjectModelBuilder(); 93 } 94 builder.mapFactoryToNamespace(factory, namespaceUri); 95 } 96 97 public Object unmarshal(String xmlFile) throws JBossXBException 98 { 99 throw new UnsupportedOperationException (); 101 } 102 103 public Object unmarshal(String xmlFile, JBossXBParser.ContentHandler handler) throws JBossXBException 104 { 105 parser.parse(xmlFile, handler); 106 return handler.getRoot(); 107 } 108 109 public Object unmarshal(String xml, SchemaBinding schemaBinding) throws JBossXBException 110 { 111 JBossXBParser.ContentHandler cHandler = new SundayContentHandler(schemaBinding); 112 parser.parse(xml, cHandler); 113 return cHandler.getRoot(); 114 } 115 116 public Object unmarshal(Reader xmlReader, SchemaBinding schemaBinding) throws JBossXBException 117 { 118 JBossXBParser.ContentHandler cHandler = new SundayContentHandler(schemaBinding); 119 parser.parse(xmlReader, cHandler); 120 return cHandler.getRoot(); 121 } 122 123 public Object unmarshal(InputStream xmlStream, SchemaBinding schemaBinding) throws JBossXBException 124 { 125 JBossXBParser.ContentHandler cHandler = new SundayContentHandler(schemaBinding); 126 parser.parse(xmlStream, cHandler); 127 return cHandler.getRoot(); 128 } 129 130 public Object unmarshal(String xml, SchemaBindingResolver schemaResolver) throws JBossXBException 131 { 132 JBossXBParser.ContentHandler cHandler = new SundayContentHandler(schemaResolver); 133 parser.parse(xml, cHandler); 134 return cHandler.getRoot(); 135 } 136 137 public Object unmarshal(Reader xmlReader, SchemaBindingResolver schemaResolver) throws JBossXBException 138 { 139 JBossXBParser.ContentHandler cHandler = new SundayContentHandler(schemaResolver); 140 parser.parse(xmlReader, cHandler); 141 return cHandler.getRoot(); 142 } 143 144 public Object unmarshal(InputStream xmlStream, SchemaBindingResolver schemaResolver) throws JBossXBException 145 { 146 JBossXBParser.ContentHandler cHandler = new SundayContentHandler(schemaResolver); 147 parser.parse(xmlStream, cHandler); 148 return cHandler.getRoot(); 149 } 150 151 public Object unmarshal(Reader reader, ObjectModelFactory factory, Object root) throws JBossXBException 152 { 153 if(builder == null) 154 { 155 builder = new ObjectModelBuilder(); 156 } 157 builder.init(factory, root); 158 parser.parse(reader, builder); 159 return builder.getRoot(); 160 } 161 162 public Object unmarshal(InputStream is, ObjectModelFactory factory, Object root) throws JBossXBException 163 { 164 if(builder == null) 165 { 166 builder = new ObjectModelBuilder(); 167 } 168 builder.init(factory, root); 169 parser.parse(is, builder); 170 return builder.getRoot(); 171 } 172 173 public Object unmarshal(String systemId, ObjectModelFactory factory, Object root) throws JBossXBException 174 { 175 if(builder == null) 176 { 177 builder = new ObjectModelBuilder(); 178 } 179 builder.init(factory, root); 180 parser.parse(systemId, builder); 181 return builder.getRoot(); 182 } 183 184 public Object unmarshal(String systemId, ObjectModelFactory factory, DocumentBinding binding) 185 throws JBossXBException 186 { 187 if(binding != null) 188 { 189 throw new IllegalStateException ("DocumentBinding API is not supported anymore!"); 190 } 191 return unmarshal(systemId, factory, (Object )null); 192 } 193 194 public Object unmarshal(Reader reader, ObjectModelFactory factory, DocumentBinding binding) throws JBossXBException 195 { 196 if(binding != null) 197 { 198 throw new IllegalStateException ("DocumentBinding API is not supported anymore!"); 199 } 200 return unmarshal(reader, factory, (Object )null); 201 } 202 203 JBossXBParser getParser() 204 { 205 return parser; 206 } 207 } 208 | Popular Tags |