Thu, 31 Aug 2017 15:18:52 +0800
merge
aoqi@0 | 1 | /* |
aoqi@0 | 2 | * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved. |
aoqi@0 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
aoqi@0 | 4 | * |
aoqi@0 | 5 | * This code is free software; you can redistribute it and/or modify it |
aoqi@0 | 6 | * under the terms of the GNU General Public License version 2 only, as |
aoqi@0 | 7 | * published by the Free Software Foundation. Oracle designates this |
aoqi@0 | 8 | * particular file as subject to the "Classpath" exception as provided |
aoqi@0 | 9 | * by Oracle in the LICENSE file that accompanied this code. |
aoqi@0 | 10 | * |
aoqi@0 | 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
aoqi@0 | 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
aoqi@0 | 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
aoqi@0 | 14 | * version 2 for more details (a copy is included in the LICENSE file that |
aoqi@0 | 15 | * accompanied this code). |
aoqi@0 | 16 | * |
aoqi@0 | 17 | * You should have received a copy of the GNU General Public License version |
aoqi@0 | 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
aoqi@0 | 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
aoqi@0 | 20 | * |
aoqi@0 | 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
aoqi@0 | 22 | * or visit www.oracle.com if you need additional information or have any |
aoqi@0 | 23 | * questions. |
aoqi@0 | 24 | */ |
aoqi@0 | 25 | |
aoqi@0 | 26 | package javax.xml.bind.helpers; |
aoqi@0 | 27 | |
aoqi@0 | 28 | import javax.xml.bind.JAXBException; |
aoqi@0 | 29 | import javax.xml.bind.Marshaller; |
aoqi@0 | 30 | import javax.xml.bind.PropertyException; |
aoqi@0 | 31 | import javax.xml.bind.ValidationEventHandler; |
aoqi@0 | 32 | import javax.xml.bind.annotation.adapters.XmlAdapter; |
aoqi@0 | 33 | import javax.xml.bind.attachment.AttachmentMarshaller; |
aoqi@0 | 34 | import javax.xml.stream.XMLEventWriter; |
aoqi@0 | 35 | import javax.xml.stream.XMLStreamWriter; |
aoqi@0 | 36 | import javax.xml.transform.dom.DOMResult; |
aoqi@0 | 37 | import javax.xml.transform.sax.SAXResult; |
aoqi@0 | 38 | import javax.xml.transform.stream.StreamResult; |
aoqi@0 | 39 | import javax.xml.validation.Schema; |
aoqi@0 | 40 | import java.io.UnsupportedEncodingException; |
aoqi@0 | 41 | import java.io.File; |
aoqi@0 | 42 | import java.io.OutputStream; |
aoqi@0 | 43 | import java.io.FileOutputStream; |
aoqi@0 | 44 | import java.io.BufferedOutputStream; |
aoqi@0 | 45 | import java.io.IOException; |
aoqi@0 | 46 | // J2SE1.4 feature |
aoqi@0 | 47 | // import java.nio.charset.Charset; |
aoqi@0 | 48 | // import java.nio.charset.UnsupportedCharsetException; |
aoqi@0 | 49 | |
aoqi@0 | 50 | /** |
aoqi@0 | 51 | * Partial default <tt>Marshaller</tt> implementation. |
aoqi@0 | 52 | * |
aoqi@0 | 53 | * <p> |
aoqi@0 | 54 | * This class provides a partial default implementation for the |
aoqi@0 | 55 | * {@link javax.xml.bind.Marshaller} interface. |
aoqi@0 | 56 | * |
aoqi@0 | 57 | * <p> |
aoqi@0 | 58 | * The only methods that a JAXB Provider has to implement are |
aoqi@0 | 59 | * {@link Marshaller#marshal(Object, javax.xml.transform.Result) marshal(Object, javax.xml.transform.Result)}, |
aoqi@0 | 60 | * {@link Marshaller#marshal(Object, javax.xml.transform.Result) marshal(Object, javax.xml.stream.XMLStreamWriter)}, and |
aoqi@0 | 61 | * {@link Marshaller#marshal(Object, javax.xml.transform.Result) marshal(Object, javax.xml.stream.XMLEventWriter)}. |
aoqi@0 | 62 | * |
aoqi@0 | 63 | * @author <ul><li>Kohsuke Kawaguchi, Sun Microsystems, Inc.</li></ul> |
aoqi@0 | 64 | * @see javax.xml.bind.Marshaller |
aoqi@0 | 65 | * @since JAXB1.0 |
aoqi@0 | 66 | */ |
aoqi@0 | 67 | public abstract class AbstractMarshallerImpl implements Marshaller |
aoqi@0 | 68 | { |
aoqi@0 | 69 | /** handler that will be used to process errors and warnings during marshal */ |
aoqi@0 | 70 | private ValidationEventHandler eventHandler = |
aoqi@0 | 71 | new DefaultValidationEventHandler(); |
aoqi@0 | 72 | |
aoqi@0 | 73 | //J2SE1.4 feature |
aoqi@0 | 74 | //private Charset encoding = null; |
aoqi@0 | 75 | |
aoqi@0 | 76 | /** store the value of the encoding property. */ |
aoqi@0 | 77 | private String encoding = "UTF-8"; |
aoqi@0 | 78 | |
aoqi@0 | 79 | /** store the value of the schemaLocation property. */ |
aoqi@0 | 80 | private String schemaLocation = null; |
aoqi@0 | 81 | |
aoqi@0 | 82 | /** store the value of the noNamespaceSchemaLocation property. */ |
aoqi@0 | 83 | private String noNSSchemaLocation = null; |
aoqi@0 | 84 | |
aoqi@0 | 85 | /** store the value of the formattedOutput property. */ |
aoqi@0 | 86 | private boolean formattedOutput = false; |
aoqi@0 | 87 | |
aoqi@0 | 88 | /** store the value of the fragment property. */ |
aoqi@0 | 89 | private boolean fragment = false; |
aoqi@0 | 90 | |
aoqi@0 | 91 | public final void marshal( Object obj, java.io.OutputStream os ) |
aoqi@0 | 92 | throws JAXBException { |
aoqi@0 | 93 | |
aoqi@0 | 94 | checkNotNull( obj, "obj", os, "os" ); |
aoqi@0 | 95 | marshal( obj, new StreamResult(os) ); |
aoqi@0 | 96 | } |
aoqi@0 | 97 | |
aoqi@0 | 98 | public void marshal(Object jaxbElement, File output) throws JAXBException { |
aoqi@0 | 99 | checkNotNull(jaxbElement, "jaxbElement", output, "output" ); |
aoqi@0 | 100 | try { |
aoqi@0 | 101 | OutputStream os = new BufferedOutputStream(new FileOutputStream(output)); |
aoqi@0 | 102 | try { |
aoqi@0 | 103 | marshal( jaxbElement, new StreamResult(os) ); |
aoqi@0 | 104 | } finally { |
aoqi@0 | 105 | os.close(); |
aoqi@0 | 106 | } |
aoqi@0 | 107 | } catch (IOException e) { |
aoqi@0 | 108 | throw new JAXBException(e); |
aoqi@0 | 109 | } |
aoqi@0 | 110 | } |
aoqi@0 | 111 | |
aoqi@0 | 112 | public final void marshal( Object obj, java.io.Writer w ) |
aoqi@0 | 113 | throws JAXBException { |
aoqi@0 | 114 | |
aoqi@0 | 115 | checkNotNull( obj, "obj", w, "writer" ); |
aoqi@0 | 116 | marshal( obj, new StreamResult(w) ); |
aoqi@0 | 117 | } |
aoqi@0 | 118 | |
aoqi@0 | 119 | public final void marshal( Object obj, org.xml.sax.ContentHandler handler ) |
aoqi@0 | 120 | throws JAXBException { |
aoqi@0 | 121 | |
aoqi@0 | 122 | checkNotNull( obj, "obj", handler, "handler" ); |
aoqi@0 | 123 | marshal( obj, new SAXResult(handler) ); |
aoqi@0 | 124 | } |
aoqi@0 | 125 | |
aoqi@0 | 126 | public final void marshal( Object obj, org.w3c.dom.Node node ) |
aoqi@0 | 127 | throws JAXBException { |
aoqi@0 | 128 | |
aoqi@0 | 129 | checkNotNull( obj, "obj", node, "node" ); |
aoqi@0 | 130 | marshal( obj, new DOMResult(node) ); |
aoqi@0 | 131 | } |
aoqi@0 | 132 | |
aoqi@0 | 133 | /** |
aoqi@0 | 134 | * By default, the getNode method is unsupported and throw |
aoqi@0 | 135 | * an {@link java.lang.UnsupportedOperationException}. |
aoqi@0 | 136 | * |
aoqi@0 | 137 | * Implementations that choose to support this method must |
aoqi@0 | 138 | * override this method. |
aoqi@0 | 139 | */ |
aoqi@0 | 140 | public org.w3c.dom.Node getNode( Object obj ) throws JAXBException { |
aoqi@0 | 141 | |
aoqi@0 | 142 | checkNotNull( obj, "obj", Boolean.TRUE, "foo" ); |
aoqi@0 | 143 | |
aoqi@0 | 144 | throw new UnsupportedOperationException(); |
aoqi@0 | 145 | } |
aoqi@0 | 146 | |
aoqi@0 | 147 | /** |
aoqi@0 | 148 | * Convenience method for getting the current output encoding. |
aoqi@0 | 149 | * |
aoqi@0 | 150 | * @return the current encoding or "UTF-8" if it hasn't been set. |
aoqi@0 | 151 | */ |
aoqi@0 | 152 | protected String getEncoding() { |
aoqi@0 | 153 | return encoding; |
aoqi@0 | 154 | } |
aoqi@0 | 155 | |
aoqi@0 | 156 | /** |
aoqi@0 | 157 | * Convenience method for setting the output encoding. |
aoqi@0 | 158 | * |
aoqi@0 | 159 | * @param encoding a valid encoding as specified in the Marshaller class |
aoqi@0 | 160 | * documentation |
aoqi@0 | 161 | */ |
aoqi@0 | 162 | protected void setEncoding( String encoding ) { |
aoqi@0 | 163 | this.encoding = encoding; |
aoqi@0 | 164 | } |
aoqi@0 | 165 | |
aoqi@0 | 166 | /** |
aoqi@0 | 167 | * Convenience method for getting the current schemaLocation. |
aoqi@0 | 168 | * |
aoqi@0 | 169 | * @return the current schemaLocation or null if it hasn't been set |
aoqi@0 | 170 | */ |
aoqi@0 | 171 | protected String getSchemaLocation() { |
aoqi@0 | 172 | return schemaLocation; |
aoqi@0 | 173 | } |
aoqi@0 | 174 | |
aoqi@0 | 175 | /** |
aoqi@0 | 176 | * Convenience method for setting the schemaLocation. |
aoqi@0 | 177 | * |
aoqi@0 | 178 | * @param location the schemaLocation value |
aoqi@0 | 179 | */ |
aoqi@0 | 180 | protected void setSchemaLocation( String location ) { |
aoqi@0 | 181 | schemaLocation = location; |
aoqi@0 | 182 | } |
aoqi@0 | 183 | |
aoqi@0 | 184 | /** |
aoqi@0 | 185 | * Convenience method for getting the current noNamespaceSchemaLocation. |
aoqi@0 | 186 | * |
aoqi@0 | 187 | * @return the current noNamespaceSchemaLocation or null if it hasn't |
aoqi@0 | 188 | * been set |
aoqi@0 | 189 | */ |
aoqi@0 | 190 | protected String getNoNSSchemaLocation() { |
aoqi@0 | 191 | return noNSSchemaLocation; |
aoqi@0 | 192 | } |
aoqi@0 | 193 | |
aoqi@0 | 194 | /** |
aoqi@0 | 195 | * Convenience method for setting the noNamespaceSchemaLocation. |
aoqi@0 | 196 | * |
aoqi@0 | 197 | * @param location the noNamespaceSchemaLocation value |
aoqi@0 | 198 | */ |
aoqi@0 | 199 | protected void setNoNSSchemaLocation( String location ) { |
aoqi@0 | 200 | noNSSchemaLocation = location; |
aoqi@0 | 201 | } |
aoqi@0 | 202 | |
aoqi@0 | 203 | /** |
aoqi@0 | 204 | * Convenience method for getting the formatted output flag. |
aoqi@0 | 205 | * |
aoqi@0 | 206 | * @return the current value of the formatted output flag or false if |
aoqi@0 | 207 | * it hasn't been set. |
aoqi@0 | 208 | */ |
aoqi@0 | 209 | protected boolean isFormattedOutput() { |
aoqi@0 | 210 | return formattedOutput; |
aoqi@0 | 211 | } |
aoqi@0 | 212 | |
aoqi@0 | 213 | /** |
aoqi@0 | 214 | * Convenience method for setting the formatted output flag. |
aoqi@0 | 215 | * |
aoqi@0 | 216 | * @param v value of the formatted output flag. |
aoqi@0 | 217 | */ |
aoqi@0 | 218 | protected void setFormattedOutput( boolean v ) { |
aoqi@0 | 219 | formattedOutput = v; |
aoqi@0 | 220 | } |
aoqi@0 | 221 | |
aoqi@0 | 222 | |
aoqi@0 | 223 | /** |
aoqi@0 | 224 | * Convenience method for getting the fragment flag. |
aoqi@0 | 225 | * |
aoqi@0 | 226 | * @return the current value of the fragment flag or false if |
aoqi@0 | 227 | * it hasn't been set. |
aoqi@0 | 228 | */ |
aoqi@0 | 229 | protected boolean isFragment() { |
aoqi@0 | 230 | return fragment; |
aoqi@0 | 231 | } |
aoqi@0 | 232 | |
aoqi@0 | 233 | /** |
aoqi@0 | 234 | * Convenience method for setting the fragment flag. |
aoqi@0 | 235 | * |
aoqi@0 | 236 | * @param v value of the fragment flag. |
aoqi@0 | 237 | */ |
aoqi@0 | 238 | protected void setFragment( boolean v ) { |
aoqi@0 | 239 | fragment = v; |
aoqi@0 | 240 | } |
aoqi@0 | 241 | |
aoqi@0 | 242 | |
aoqi@0 | 243 | static String[] aliases = { |
aoqi@0 | 244 | "UTF-8", "UTF8", |
aoqi@0 | 245 | "UTF-16", "Unicode", |
aoqi@0 | 246 | "UTF-16BE", "UnicodeBigUnmarked", |
aoqi@0 | 247 | "UTF-16LE", "UnicodeLittleUnmarked", |
aoqi@0 | 248 | "US-ASCII", "ASCII", |
aoqi@0 | 249 | "TIS-620", "TIS620", |
aoqi@0 | 250 | |
aoqi@0 | 251 | // taken from the project-X parser |
aoqi@0 | 252 | "ISO-10646-UCS-2", "Unicode", |
aoqi@0 | 253 | |
aoqi@0 | 254 | "EBCDIC-CP-US", "cp037", |
aoqi@0 | 255 | "EBCDIC-CP-CA", "cp037", |
aoqi@0 | 256 | "EBCDIC-CP-NL", "cp037", |
aoqi@0 | 257 | "EBCDIC-CP-WT", "cp037", |
aoqi@0 | 258 | |
aoqi@0 | 259 | "EBCDIC-CP-DK", "cp277", |
aoqi@0 | 260 | "EBCDIC-CP-NO", "cp277", |
aoqi@0 | 261 | "EBCDIC-CP-FI", "cp278", |
aoqi@0 | 262 | "EBCDIC-CP-SE", "cp278", |
aoqi@0 | 263 | |
aoqi@0 | 264 | "EBCDIC-CP-IT", "cp280", |
aoqi@0 | 265 | "EBCDIC-CP-ES", "cp284", |
aoqi@0 | 266 | "EBCDIC-CP-GB", "cp285", |
aoqi@0 | 267 | "EBCDIC-CP-FR", "cp297", |
aoqi@0 | 268 | |
aoqi@0 | 269 | "EBCDIC-CP-AR1", "cp420", |
aoqi@0 | 270 | "EBCDIC-CP-HE", "cp424", |
aoqi@0 | 271 | "EBCDIC-CP-BE", "cp500", |
aoqi@0 | 272 | "EBCDIC-CP-CH", "cp500", |
aoqi@0 | 273 | |
aoqi@0 | 274 | "EBCDIC-CP-ROECE", "cp870", |
aoqi@0 | 275 | "EBCDIC-CP-YU", "cp870", |
aoqi@0 | 276 | "EBCDIC-CP-IS", "cp871", |
aoqi@0 | 277 | "EBCDIC-CP-AR2", "cp918", |
aoqi@0 | 278 | |
aoqi@0 | 279 | // IANA also defines two that JDK 1.2 doesn't handle: |
aoqi@0 | 280 | // EBCDIC-CP-GR --> CP423 |
aoqi@0 | 281 | // EBCDIC-CP-TR --> CP905 |
aoqi@0 | 282 | }; |
aoqi@0 | 283 | |
aoqi@0 | 284 | /** |
aoqi@0 | 285 | * Gets the corresponding Java encoding name from an IANA name. |
aoqi@0 | 286 | * |
aoqi@0 | 287 | * This method is a helper method for the derived class to convert |
aoqi@0 | 288 | * encoding names. |
aoqi@0 | 289 | * |
aoqi@0 | 290 | * @exception UnsupportedEncodingException |
aoqi@0 | 291 | * If this implementation couldn't find the Java encoding name. |
aoqi@0 | 292 | */ |
aoqi@0 | 293 | protected String getJavaEncoding( String encoding ) throws UnsupportedEncodingException { |
aoqi@0 | 294 | try { |
aoqi@0 | 295 | "1".getBytes(encoding); |
aoqi@0 | 296 | return encoding; |
aoqi@0 | 297 | } catch( UnsupportedEncodingException e ) { |
aoqi@0 | 298 | // try known alias |
aoqi@0 | 299 | for( int i=0; i<aliases.length; i+=2 ) { |
aoqi@0 | 300 | if(encoding.equals(aliases[i])) { |
aoqi@0 | 301 | "1".getBytes(aliases[i+1]); |
aoqi@0 | 302 | return aliases[i+1]; |
aoqi@0 | 303 | } |
aoqi@0 | 304 | } |
aoqi@0 | 305 | |
aoqi@0 | 306 | throw new UnsupportedEncodingException(encoding); |
aoqi@0 | 307 | } |
aoqi@0 | 308 | /* J2SE1.4 feature |
aoqi@0 | 309 | try { |
aoqi@0 | 310 | this.encoding = Charset.forName( _encoding ); |
aoqi@0 | 311 | } catch( UnsupportedCharsetException uce ) { |
aoqi@0 | 312 | throw new JAXBException( uce ); |
aoqi@0 | 313 | } |
aoqi@0 | 314 | */ |
aoqi@0 | 315 | } |
aoqi@0 | 316 | |
aoqi@0 | 317 | /** |
aoqi@0 | 318 | * Default implementation of the setProperty method handles |
aoqi@0 | 319 | * the four defined properties in Marshaller. If a provider |
aoqi@0 | 320 | * needs to handle additional properties, it should override |
aoqi@0 | 321 | * this method in a derived class. |
aoqi@0 | 322 | */ |
aoqi@0 | 323 | public void setProperty( String name, Object value ) |
aoqi@0 | 324 | throws PropertyException { |
aoqi@0 | 325 | |
aoqi@0 | 326 | if( name == null ) { |
aoqi@0 | 327 | throw new IllegalArgumentException( |
aoqi@0 | 328 | Messages.format( Messages.MUST_NOT_BE_NULL, "name" ) ); |
aoqi@0 | 329 | } |
aoqi@0 | 330 | |
aoqi@0 | 331 | // recognize and handle four pre-defined properties. |
aoqi@0 | 332 | if( JAXB_ENCODING.equals(name) ) { |
aoqi@0 | 333 | checkString( name, value ); |
aoqi@0 | 334 | setEncoding( (String)value ); |
aoqi@0 | 335 | return; |
aoqi@0 | 336 | } |
aoqi@0 | 337 | if( JAXB_FORMATTED_OUTPUT.equals(name) ) { |
aoqi@0 | 338 | checkBoolean( name, value ); |
aoqi@0 | 339 | setFormattedOutput((Boolean) value ); |
aoqi@0 | 340 | return; |
aoqi@0 | 341 | } |
aoqi@0 | 342 | if( JAXB_NO_NAMESPACE_SCHEMA_LOCATION.equals(name) ) { |
aoqi@0 | 343 | checkString( name, value ); |
aoqi@0 | 344 | setNoNSSchemaLocation( (String)value ); |
aoqi@0 | 345 | return; |
aoqi@0 | 346 | } |
aoqi@0 | 347 | if( JAXB_SCHEMA_LOCATION.equals(name) ) { |
aoqi@0 | 348 | checkString( name, value ); |
aoqi@0 | 349 | setSchemaLocation( (String)value ); |
aoqi@0 | 350 | return; |
aoqi@0 | 351 | } |
aoqi@0 | 352 | if( JAXB_FRAGMENT.equals(name) ) { |
aoqi@0 | 353 | checkBoolean(name, value); |
aoqi@0 | 354 | setFragment((Boolean) value ); |
aoqi@0 | 355 | return; |
aoqi@0 | 356 | } |
aoqi@0 | 357 | |
aoqi@0 | 358 | throw new PropertyException(name, value); |
aoqi@0 | 359 | } |
aoqi@0 | 360 | |
aoqi@0 | 361 | /** |
aoqi@0 | 362 | * Default implementation of the getProperty method handles |
aoqi@0 | 363 | * the four defined properties in Marshaller. If a provider |
aoqi@0 | 364 | * needs to support additional provider specific properties, |
aoqi@0 | 365 | * it should override this method in a derived class. |
aoqi@0 | 366 | */ |
aoqi@0 | 367 | public Object getProperty( String name ) |
aoqi@0 | 368 | throws PropertyException { |
aoqi@0 | 369 | |
aoqi@0 | 370 | if( name == null ) { |
aoqi@0 | 371 | throw new IllegalArgumentException( |
aoqi@0 | 372 | Messages.format( Messages.MUST_NOT_BE_NULL, "name" ) ); |
aoqi@0 | 373 | } |
aoqi@0 | 374 | |
aoqi@0 | 375 | // recognize and handle four pre-defined properties. |
aoqi@0 | 376 | if( JAXB_ENCODING.equals(name) ) |
aoqi@0 | 377 | return getEncoding(); |
aoqi@0 | 378 | if( JAXB_FORMATTED_OUTPUT.equals(name) ) |
aoqi@0 | 379 | return isFormattedOutput()?Boolean.TRUE:Boolean.FALSE; |
aoqi@0 | 380 | if( JAXB_NO_NAMESPACE_SCHEMA_LOCATION.equals(name) ) |
aoqi@0 | 381 | return getNoNSSchemaLocation(); |
aoqi@0 | 382 | if( JAXB_SCHEMA_LOCATION.equals(name) ) |
aoqi@0 | 383 | return getSchemaLocation(); |
aoqi@0 | 384 | if( JAXB_FRAGMENT.equals(name) ) |
aoqi@0 | 385 | return isFragment()?Boolean.TRUE:Boolean.FALSE; |
aoqi@0 | 386 | |
aoqi@0 | 387 | throw new PropertyException(name); |
aoqi@0 | 388 | } |
aoqi@0 | 389 | /** |
aoqi@0 | 390 | * @see javax.xml.bind.Marshaller#getEventHandler() |
aoqi@0 | 391 | */ |
aoqi@0 | 392 | public ValidationEventHandler getEventHandler() throws JAXBException { |
aoqi@0 | 393 | return eventHandler; |
aoqi@0 | 394 | } |
aoqi@0 | 395 | |
aoqi@0 | 396 | /** |
aoqi@0 | 397 | * @see javax.xml.bind.Marshaller#setEventHandler(ValidationEventHandler) |
aoqi@0 | 398 | */ |
aoqi@0 | 399 | public void setEventHandler(ValidationEventHandler handler) |
aoqi@0 | 400 | throws JAXBException { |
aoqi@0 | 401 | |
aoqi@0 | 402 | if( handler == null ) { |
aoqi@0 | 403 | eventHandler = new DefaultValidationEventHandler(); |
aoqi@0 | 404 | } else { |
aoqi@0 | 405 | eventHandler = handler; |
aoqi@0 | 406 | } |
aoqi@0 | 407 | } |
aoqi@0 | 408 | |
aoqi@0 | 409 | |
aoqi@0 | 410 | |
aoqi@0 | 411 | |
aoqi@0 | 412 | /* |
aoqi@0 | 413 | * assert that the given object is a Boolean |
aoqi@0 | 414 | */ |
aoqi@0 | 415 | private void checkBoolean( String name, Object value ) throws PropertyException { |
aoqi@0 | 416 | if(!(value instanceof Boolean)) |
aoqi@0 | 417 | throw new PropertyException( |
aoqi@0 | 418 | Messages.format( Messages.MUST_BE_BOOLEAN, name ) ); |
aoqi@0 | 419 | } |
aoqi@0 | 420 | |
aoqi@0 | 421 | /* |
aoqi@0 | 422 | * assert that the given object is a String |
aoqi@0 | 423 | */ |
aoqi@0 | 424 | private void checkString( String name, Object value ) throws PropertyException { |
aoqi@0 | 425 | if(!(value instanceof String)) |
aoqi@0 | 426 | throw new PropertyException( |
aoqi@0 | 427 | Messages.format( Messages.MUST_BE_STRING, name ) ); |
aoqi@0 | 428 | } |
aoqi@0 | 429 | |
aoqi@0 | 430 | /* |
aoqi@0 | 431 | * assert that the parameters are not null |
aoqi@0 | 432 | */ |
aoqi@0 | 433 | private void checkNotNull( Object o1, String o1Name, |
aoqi@0 | 434 | Object o2, String o2Name ) { |
aoqi@0 | 435 | |
aoqi@0 | 436 | if( o1 == null ) { |
aoqi@0 | 437 | throw new IllegalArgumentException( |
aoqi@0 | 438 | Messages.format( Messages.MUST_NOT_BE_NULL, o1Name ) ); |
aoqi@0 | 439 | } |
aoqi@0 | 440 | if( o2 == null ) { |
aoqi@0 | 441 | throw new IllegalArgumentException( |
aoqi@0 | 442 | Messages.format( Messages.MUST_NOT_BE_NULL, o2Name ) ); |
aoqi@0 | 443 | } |
aoqi@0 | 444 | } |
aoqi@0 | 445 | |
aoqi@0 | 446 | public void marshal(Object obj, XMLEventWriter writer) |
aoqi@0 | 447 | throws JAXBException { |
aoqi@0 | 448 | |
aoqi@0 | 449 | throw new UnsupportedOperationException(); |
aoqi@0 | 450 | } |
aoqi@0 | 451 | |
aoqi@0 | 452 | public void marshal(Object obj, XMLStreamWriter writer) |
aoqi@0 | 453 | throws JAXBException { |
aoqi@0 | 454 | |
aoqi@0 | 455 | throw new UnsupportedOperationException(); |
aoqi@0 | 456 | } |
aoqi@0 | 457 | |
aoqi@0 | 458 | public void setSchema(Schema schema) { |
aoqi@0 | 459 | throw new UnsupportedOperationException(); |
aoqi@0 | 460 | } |
aoqi@0 | 461 | |
aoqi@0 | 462 | public Schema getSchema() { |
aoqi@0 | 463 | throw new UnsupportedOperationException(); |
aoqi@0 | 464 | } |
aoqi@0 | 465 | |
aoqi@0 | 466 | public void setAdapter(XmlAdapter adapter) { |
aoqi@0 | 467 | if(adapter==null) |
aoqi@0 | 468 | throw new IllegalArgumentException(); |
aoqi@0 | 469 | setAdapter((Class)adapter.getClass(),adapter); |
aoqi@0 | 470 | } |
aoqi@0 | 471 | |
aoqi@0 | 472 | public <A extends XmlAdapter> void setAdapter(Class<A> type, A adapter) { |
aoqi@0 | 473 | throw new UnsupportedOperationException(); |
aoqi@0 | 474 | } |
aoqi@0 | 475 | |
aoqi@0 | 476 | public <A extends XmlAdapter> A getAdapter(Class<A> type) { |
aoqi@0 | 477 | throw new UnsupportedOperationException(); |
aoqi@0 | 478 | } |
aoqi@0 | 479 | |
aoqi@0 | 480 | public void setAttachmentMarshaller(AttachmentMarshaller am) { |
aoqi@0 | 481 | throw new UnsupportedOperationException(); |
aoqi@0 | 482 | } |
aoqi@0 | 483 | |
aoqi@0 | 484 | public AttachmentMarshaller getAttachmentMarshaller() { |
aoqi@0 | 485 | throw new UnsupportedOperationException(); |
aoqi@0 | 486 | } |
aoqi@0 | 487 | |
aoqi@0 | 488 | public void setListener(Listener listener) { |
aoqi@0 | 489 | throw new UnsupportedOperationException(); |
aoqi@0 | 490 | } |
aoqi@0 | 491 | |
aoqi@0 | 492 | public Listener getListener() { |
aoqi@0 | 493 | throw new UnsupportedOperationException(); |
aoqi@0 | 494 | } |
aoqi@0 | 495 | } |