Skip to content

Commit 049b944

Browse files
jhoellerunknown
authored and
unknown
committed
polishing (at the occasion of a backport)
1 parent 30de87a commit 049b944

File tree

1 file changed

+33
-34
lines changed

1 file changed

+33
-34
lines changed

spring-oxm/src/main/java/org/springframework/oxm/jaxb/Jaxb2Marshaller.java

Lines changed: 33 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@
106106
* listeners, and to refer to it.
107107
*
108108
* @author Arjen Poutsma
109+
* @since 3.0
109110
* @see #setContextPath(String)
110111
* @see #setClassesToBeBound(Class[])
111112
* @see #setJaxbContextProperties(Map)
@@ -116,7 +117,6 @@
116117
* @see #setMarshallerListener(javax.xml.bind.Marshaller.Listener)
117118
* @see #setUnmarshallerListener(javax.xml.bind.Unmarshaller.Listener)
118119
* @see #setAdapters(XmlAdapter[])
119-
* @since 3.0
120120
*/
121121
public class Jaxb2Marshaller
122122
implements MimeMarshaller, MimeUnmarshaller, GenericMarshaller, GenericUnmarshaller, BeanClassLoaderAware,
@@ -225,10 +225,10 @@ public void setPackagesToScan(String[] packagesToScan) {
225225
}
226226

227227
/**
228-
* Returns the packages to search for JAXB2 annotations.
228+
* Return the packages to search for JAXB2 annotations.
229229
*/
230230
public String[] getPackagesToScan() {
231-
return packagesToScan;
231+
return this.packagesToScan;
232232
}
233233

234234
/**
@@ -317,8 +317,7 @@ public void setSchemaLanguage(String schemaLanguage) {
317317
}
318318

319319
/**
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.
322321
* @see SchemaFactory#setResourceResolver(org.w3c.dom.ls.LSResourceResolver)
323322
* @see #setSchema(Resource)
324323
* @see #setSchemas(Resource[])
@@ -352,7 +351,6 @@ public void setLazyInit(boolean lazyInit) {
352351
* <p>This property is typically enabled in combination with usage of classes like
353352
* {@link org.springframework.web.servlet.view.xml.MarshallingView MarshallingView}, since the {@code ModelAndView}
354353
* does not offer type parameter information at runtime.
355-
*
356354
* @see #supports(Class)
357355
* @see #supports(Type)
358356
*/
@@ -369,9 +367,9 @@ public void setResourceLoader(ResourceLoader resourceLoader) {
369367
}
370368

371369
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);
375373

376374
if (hasContextPath && (hasClassesToBeBound || hasPackagesToScan) ||
377375
(hasClassesToBeBound && hasPackagesToScan)) {
@@ -393,64 +391,64 @@ public final void afterPropertiesSet() throws Exception {
393391
protected synchronized JAXBContext getJaxbContext() {
394392
if (this.jaxbContext == null) {
395393
try {
396-
if (StringUtils.hasLength(getContextPath())) {
394+
if (StringUtils.hasLength(this.contextPath)) {
397395
this.jaxbContext = createJaxbContextFromContextPath();
398396
}
399-
else if (!ObjectUtils.isEmpty(getClassesToBeBound())) {
397+
else if (!ObjectUtils.isEmpty(this.classesToBeBound)) {
400398
this.jaxbContext = createJaxbContextFromClasses();
401399
}
402-
else if (!ObjectUtils.isEmpty(getPackagesToScan())) {
400+
else if (!ObjectUtils.isEmpty(this.packagesToScan)) {
403401
this.jaxbContext = createJaxbContextFromPackages();
404402
}
405403
}
406404
catch (JAXBException ex) {
407405
throw convertJaxbException(ex);
408406
}
409407
}
410-
return jaxbContext;
408+
return this.jaxbContext;
411409
}
412410

413411
private JAXBContext createJaxbContextFromContextPath() throws JAXBException {
414412
if (logger.isInfoEnabled()) {
415-
logger.info("Creating JAXBContext with context path [" + getContextPath() + "]");
413+
logger.info("Creating JAXBContext with context path [" + this.contextPath + "]");
416414
}
417415
if (this.jaxbContextProperties != null) {
418416
if (this.beanClassLoader != null) {
419-
return JAXBContext.newInstance(getContextPath(), this.beanClassLoader, this.jaxbContextProperties);
417+
return JAXBContext.newInstance(this.contextPath, this.beanClassLoader, this.jaxbContextProperties);
420418
}
421419
else {
422-
return JAXBContext.newInstance(getContextPath(), ClassUtils.getDefaultClassLoader(), this.jaxbContextProperties);
420+
return JAXBContext.newInstance(this.contextPath, ClassUtils.getDefaultClassLoader(), this.jaxbContextProperties);
423421
}
424422
}
425423
else {
426424
if (this.beanClassLoader != null) {
427-
return JAXBContext.newInstance(getContextPath(), this.beanClassLoader);
425+
return JAXBContext.newInstance(this.contextPath, this.beanClassLoader);
428426
}
429427
else {
430-
return JAXBContext.newInstance(getContextPath());
428+
return JAXBContext.newInstance(this.contextPath);
431429
}
432430
}
433431
}
434432

435433
private JAXBContext createJaxbContextFromClasses() throws JAXBException {
436434
if (logger.isInfoEnabled()) {
437435
logger.info("Creating JAXBContext with classes to be bound [" +
438-
StringUtils.arrayToCommaDelimitedString(getClassesToBeBound()) + "]");
436+
StringUtils.arrayToCommaDelimitedString(this.classesToBeBound) + "]");
439437
}
440438
if (this.jaxbContextProperties != null) {
441-
return JAXBContext.newInstance(getClassesToBeBound(), this.jaxbContextProperties);
439+
return JAXBContext.newInstance(this.classesToBeBound, this.jaxbContextProperties);
442440
}
443441
else {
444-
return JAXBContext.newInstance(getClassesToBeBound());
442+
return JAXBContext.newInstance(this.classesToBeBound);
445443
}
446444
}
447445

448446
private JAXBContext createJaxbContextFromPackages() throws JAXBException {
449447
if (logger.isInfoEnabled()) {
450448
logger.info("Creating JAXBContext by scanning packages [" +
451-
StringUtils.arrayToCommaDelimitedString(getPackagesToScan()) + "]");
449+
StringUtils.arrayToCommaDelimitedString(this.packagesToScan) + "]");
452450
}
453-
ClassPathJaxb2TypeScanner scanner = new ClassPathJaxb2TypeScanner(getPackagesToScan());
451+
ClassPathJaxb2TypeScanner scanner = new ClassPathJaxb2TypeScanner(this.packagesToScan);
454452
scanner.setResourceLoader(this.resourceLoader);
455453
scanner.scanPackages();
456454
Class<?>[] jaxb2Classes = scanner.getJaxb2Classes();
@@ -468,7 +466,8 @@ private JAXBContext createJaxbContextFromPackages() throws JAXBException {
468466

469467
private Schema loadSchema(Resource[] resources, String schemaLanguage) throws IOException, SAXException {
470468
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));
472471
}
473472
Assert.notEmpty(resources, "No resources given");
474473
Assert.hasLength(schemaLanguage, "No schema language provided");
@@ -482,15 +481,15 @@ private Schema loadSchema(Resource[] resources, String schemaLanguage) throws IO
482481
schemaSources[i] = new SAXSource(xmlReader, inputSource);
483482
}
484483
SchemaFactory schemaFactory = SchemaFactory.newInstance(schemaLanguage);
485-
if (schemaResourceResolver != null) {
486-
schemaFactory.setResourceResolver(schemaResourceResolver);
484+
if (this.schemaResourceResolver != null) {
485+
schemaFactory.setResourceResolver(this.schemaResourceResolver);
487486
}
488487
return schemaFactory.newSchema(schemaSources);
489488
}
490489

491490

492491
public boolean supports(Class<?> clazz) {
493-
if (supportJaxbElementClass && JAXBElement.class.isAssignableFrom(clazz)) {
492+
if (this.supportJaxbElementClass && JAXBElement.class.isAssignableFrom(clazz)) {
494493
return true;
495494
}
496495
return supportsInternal(clazz, true);
@@ -531,18 +530,18 @@ private boolean supportsInternal(Class<?> clazz, boolean checkForXmlRootElement)
531530
if (checkForXmlRootElement && AnnotationUtils.findAnnotation(clazz, XmlRootElement.class) == null) {
532531
return false;
533532
}
534-
if (StringUtils.hasLength(getContextPath())) {
533+
if (StringUtils.hasLength(this.contextPath)) {
535534
String packageName = ClassUtils.getPackageName(clazz);
536-
String[] contextPaths = StringUtils.tokenizeToStringArray(getContextPath(), ":");
535+
String[] contextPaths = StringUtils.tokenizeToStringArray(this.contextPath, ":");
537536
for (String contextPath : contextPaths) {
538537
if (contextPath.equals(packageName)) {
539538
return true;
540539
}
541540
}
542541
return false;
543542
}
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);
546545
}
547546
return false;
548547
}
@@ -709,7 +708,8 @@ private Object unmarshalStaxSource(Unmarshaller jaxbUnmarshaller, Source staxSou
709708
}
710709

711710
/**
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.
713713
*/
714714
protected Unmarshaller createUnmarshaller() {
715715
try {
@@ -752,7 +752,6 @@ protected void initJaxbUnmarshaller(Unmarshaller unmarshaller) throws JAXBExcept
752752
}
753753
}
754754

755-
756755
/**
757756
* Convert the given <code>JAXBException</code> to an appropriate exception from the
758757
* <code>org.springframework.oxm</code> hierarchy.
@@ -819,7 +818,7 @@ private String getHost(String elementNamespace, DataHandler dataHandler) {
819818
@Override
820819
public String addSwaRefAttachment(DataHandler dataHandler) {
821820
String contentId = UUID.randomUUID() + "@" + dataHandler.getName();
822-
mimeContainer.addAttachment(contentId, dataHandler);
821+
this.mimeContainer.addAttachment(contentId, dataHandler);
823822
return contentId;
824823
}
825824

0 commit comments

Comments
 (0)