106
106
* listeners, and to refer to it.
107
107
*
108
108
* @author Arjen Poutsma
109
+ * @since 3.0
109
110
* @see #setContextPath(String)
110
111
* @see #setClassesToBeBound(Class[])
111
112
* @see #setJaxbContextProperties(Map)
116
117
* @see #setMarshallerListener(javax.xml.bind.Marshaller.Listener)
117
118
* @see #setUnmarshallerListener(javax.xml.bind.Unmarshaller.Listener)
118
119
* @see #setAdapters(XmlAdapter[])
119
- * @since 3.0
120
120
*/
121
121
public class Jaxb2Marshaller
122
122
implements MimeMarshaller , MimeUnmarshaller , GenericMarshaller , GenericUnmarshaller , BeanClassLoaderAware ,
@@ -225,10 +225,10 @@ public void setPackagesToScan(String[] packagesToScan) {
225
225
}
226
226
227
227
/**
228
- * Returns the packages to search for JAXB2 annotations.
228
+ * Return the packages to search for JAXB2 annotations.
229
229
*/
230
230
public String [] getPackagesToScan () {
231
- return packagesToScan ;
231
+ return this . packagesToScan ;
232
232
}
233
233
234
234
/**
@@ -317,8 +317,7 @@ public void setSchemaLanguage(String schemaLanguage) {
317
317
}
318
318
319
319
/**
320
- * Sets the resource resolver, as used to load the schema resources.
321
- *
320
+ * Set the resource resolver, as used to load the schema resources.
322
321
* @see SchemaFactory#setResourceResolver(org.w3c.dom.ls.LSResourceResolver)
323
322
* @see #setSchema(Resource)
324
323
* @see #setSchemas(Resource[])
@@ -352,7 +351,6 @@ public void setLazyInit(boolean lazyInit) {
352
351
* <p>This property is typically enabled in combination with usage of classes like
353
352
* {@link org.springframework.web.servlet.view.xml.MarshallingView MarshallingView}, since the {@code ModelAndView}
354
353
* does not offer type parameter information at runtime.
355
- *
356
354
* @see #supports(Class)
357
355
* @see #supports(Type)
358
356
*/
@@ -369,9 +367,9 @@ public void setResourceLoader(ResourceLoader resourceLoader) {
369
367
}
370
368
371
369
public final void afterPropertiesSet () throws Exception {
372
- boolean hasContextPath = StringUtils .hasLength (getContextPath () );
373
- boolean hasClassesToBeBound = !ObjectUtils .isEmpty (getClassesToBeBound () );
374
- boolean hasPackagesToScan = !ObjectUtils .isEmpty (getPackagesToScan () );
370
+ boolean hasContextPath = StringUtils .hasLength (this . contextPath );
371
+ boolean hasClassesToBeBound = !ObjectUtils .isEmpty (this . classesToBeBound );
372
+ boolean hasPackagesToScan = !ObjectUtils .isEmpty (this . packagesToScan );
375
373
376
374
if (hasContextPath && (hasClassesToBeBound || hasPackagesToScan ) ||
377
375
(hasClassesToBeBound && hasPackagesToScan )) {
@@ -393,64 +391,64 @@ public final void afterPropertiesSet() throws Exception {
393
391
protected synchronized JAXBContext getJaxbContext () {
394
392
if (this .jaxbContext == null ) {
395
393
try {
396
- if (StringUtils .hasLength (getContextPath () )) {
394
+ if (StringUtils .hasLength (this . contextPath )) {
397
395
this .jaxbContext = createJaxbContextFromContextPath ();
398
396
}
399
- else if (!ObjectUtils .isEmpty (getClassesToBeBound () )) {
397
+ else if (!ObjectUtils .isEmpty (this . classesToBeBound )) {
400
398
this .jaxbContext = createJaxbContextFromClasses ();
401
399
}
402
- else if (!ObjectUtils .isEmpty (getPackagesToScan () )) {
400
+ else if (!ObjectUtils .isEmpty (this . packagesToScan )) {
403
401
this .jaxbContext = createJaxbContextFromPackages ();
404
402
}
405
403
}
406
404
catch (JAXBException ex ) {
407
405
throw convertJaxbException (ex );
408
406
}
409
407
}
410
- return jaxbContext ;
408
+ return this . jaxbContext ;
411
409
}
412
410
413
411
private JAXBContext createJaxbContextFromContextPath () throws JAXBException {
414
412
if (logger .isInfoEnabled ()) {
415
- logger .info ("Creating JAXBContext with context path [" + getContextPath () + "]" );
413
+ logger .info ("Creating JAXBContext with context path [" + this . contextPath + "]" );
416
414
}
417
415
if (this .jaxbContextProperties != null ) {
418
416
if (this .beanClassLoader != null ) {
419
- return JAXBContext .newInstance (getContextPath () , this .beanClassLoader , this .jaxbContextProperties );
417
+ return JAXBContext .newInstance (this . contextPath , this .beanClassLoader , this .jaxbContextProperties );
420
418
}
421
419
else {
422
- return JAXBContext .newInstance (getContextPath () , ClassUtils .getDefaultClassLoader (), this .jaxbContextProperties );
420
+ return JAXBContext .newInstance (this . contextPath , ClassUtils .getDefaultClassLoader (), this .jaxbContextProperties );
423
421
}
424
422
}
425
423
else {
426
424
if (this .beanClassLoader != null ) {
427
- return JAXBContext .newInstance (getContextPath () , this .beanClassLoader );
425
+ return JAXBContext .newInstance (this . contextPath , this .beanClassLoader );
428
426
}
429
427
else {
430
- return JAXBContext .newInstance (getContextPath () );
428
+ return JAXBContext .newInstance (this . contextPath );
431
429
}
432
430
}
433
431
}
434
432
435
433
private JAXBContext createJaxbContextFromClasses () throws JAXBException {
436
434
if (logger .isInfoEnabled ()) {
437
435
logger .info ("Creating JAXBContext with classes to be bound [" +
438
- StringUtils .arrayToCommaDelimitedString (getClassesToBeBound () ) + "]" );
436
+ StringUtils .arrayToCommaDelimitedString (this . classesToBeBound ) + "]" );
439
437
}
440
438
if (this .jaxbContextProperties != null ) {
441
- return JAXBContext .newInstance (getClassesToBeBound () , this .jaxbContextProperties );
439
+ return JAXBContext .newInstance (this . classesToBeBound , this .jaxbContextProperties );
442
440
}
443
441
else {
444
- return JAXBContext .newInstance (getClassesToBeBound () );
442
+ return JAXBContext .newInstance (this . classesToBeBound );
445
443
}
446
444
}
447
445
448
446
private JAXBContext createJaxbContextFromPackages () throws JAXBException {
449
447
if (logger .isInfoEnabled ()) {
450
448
logger .info ("Creating JAXBContext by scanning packages [" +
451
- StringUtils .arrayToCommaDelimitedString (getPackagesToScan () ) + "]" );
449
+ StringUtils .arrayToCommaDelimitedString (this . packagesToScan ) + "]" );
452
450
}
453
- ClassPathJaxb2TypeScanner scanner = new ClassPathJaxb2TypeScanner (getPackagesToScan () );
451
+ ClassPathJaxb2TypeScanner scanner = new ClassPathJaxb2TypeScanner (this . packagesToScan );
454
452
scanner .setResourceLoader (this .resourceLoader );
455
453
scanner .scanPackages ();
456
454
Class <?>[] jaxb2Classes = scanner .getJaxb2Classes ();
@@ -468,7 +466,8 @@ private JAXBContext createJaxbContextFromPackages() throws JAXBException {
468
466
469
467
private Schema loadSchema (Resource [] resources , String schemaLanguage ) throws IOException , SAXException {
470
468
if (logger .isDebugEnabled ()) {
471
- logger .debug ("Setting validation schema to " + StringUtils .arrayToCommaDelimitedString (this .schemaResources ));
469
+ logger .debug ("Setting validation schema to " +
470
+ StringUtils .arrayToCommaDelimitedString (this .schemaResources ));
472
471
}
473
472
Assert .notEmpty (resources , "No resources given" );
474
473
Assert .hasLength (schemaLanguage , "No schema language provided" );
@@ -482,15 +481,15 @@ private Schema loadSchema(Resource[] resources, String schemaLanguage) throws IO
482
481
schemaSources [i ] = new SAXSource (xmlReader , inputSource );
483
482
}
484
483
SchemaFactory schemaFactory = SchemaFactory .newInstance (schemaLanguage );
485
- if (schemaResourceResolver != null ) {
486
- schemaFactory .setResourceResolver (schemaResourceResolver );
484
+ if (this . schemaResourceResolver != null ) {
485
+ schemaFactory .setResourceResolver (this . schemaResourceResolver );
487
486
}
488
487
return schemaFactory .newSchema (schemaSources );
489
488
}
490
489
491
490
492
491
public boolean supports (Class <?> clazz ) {
493
- if (supportJaxbElementClass && JAXBElement .class .isAssignableFrom (clazz )) {
492
+ if (this . supportJaxbElementClass && JAXBElement .class .isAssignableFrom (clazz )) {
494
493
return true ;
495
494
}
496
495
return supportsInternal (clazz , true );
@@ -531,18 +530,18 @@ private boolean supportsInternal(Class<?> clazz, boolean checkForXmlRootElement)
531
530
if (checkForXmlRootElement && AnnotationUtils .findAnnotation (clazz , XmlRootElement .class ) == null ) {
532
531
return false ;
533
532
}
534
- if (StringUtils .hasLength (getContextPath () )) {
533
+ if (StringUtils .hasLength (this . contextPath )) {
535
534
String packageName = ClassUtils .getPackageName (clazz );
536
- String [] contextPaths = StringUtils .tokenizeToStringArray (getContextPath () , ":" );
535
+ String [] contextPaths = StringUtils .tokenizeToStringArray (this . contextPath , ":" );
537
536
for (String contextPath : contextPaths ) {
538
537
if (contextPath .equals (packageName )) {
539
538
return true ;
540
539
}
541
540
}
542
541
return false ;
543
542
}
544
- else if (!ObjectUtils .isEmpty (getClassesToBeBound () )) {
545
- return Arrays .asList (getClassesToBeBound () ).contains (clazz );
543
+ else if (!ObjectUtils .isEmpty (this . classesToBeBound )) {
544
+ return Arrays .asList (this . classesToBeBound ).contains (clazz );
546
545
}
547
546
return false ;
548
547
}
@@ -709,7 +708,8 @@ private Object unmarshalStaxSource(Unmarshaller jaxbUnmarshaller, Source staxSou
709
708
}
710
709
711
710
/**
712
- * Return a newly created JAXB unmarshaller. JAXB unmarshallers are not necessarily thread safe.
711
+ * Return a newly created JAXB unmarshaller.
712
+ * Note: JAXB unmarshallers are not necessarily thread-safe.
713
713
*/
714
714
protected Unmarshaller createUnmarshaller () {
715
715
try {
@@ -752,7 +752,6 @@ protected void initJaxbUnmarshaller(Unmarshaller unmarshaller) throws JAXBExcept
752
752
}
753
753
}
754
754
755
-
756
755
/**
757
756
* Convert the given <code>JAXBException</code> to an appropriate exception from the
758
757
* <code>org.springframework.oxm</code> hierarchy.
@@ -819,7 +818,7 @@ private String getHost(String elementNamespace, DataHandler dataHandler) {
819
818
@ Override
820
819
public String addSwaRefAttachment (DataHandler dataHandler ) {
821
820
String contentId = UUID .randomUUID () + "@" + dataHandler .getName ();
822
- mimeContainer .addAttachment (contentId , dataHandler );
821
+ this . mimeContainer .addAttachment (contentId , dataHandler );
823
822
return contentId ;
824
823
}
825
824
0 commit comments