You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ni...@apache.org on 2014/04/08 16:47:20 UTC
git commit: CAMEL-7349 polish the code as Claus suggested
Repository: camel
Updated Branches:
refs/heads/master 41d7eca93 -> ce8844f05
CAMEL-7349 polish the code as Claus suggested
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/ce8844f0
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/ce8844f0
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/ce8844f0
Branch: refs/heads/master
Commit: ce8844f055767b0ac521f35ba6a592540fba5ab3
Parents: 41d7eca
Author: Willem Jiang <wi...@gmail.com>
Authored: Tue Apr 8 22:46:17 2014 +0800
Committer: Willem Jiang <wi...@gmail.com>
Committed: Tue Apr 8 22:46:17 2014 +0800
----------------------------------------------------------------------
.../camel/converter/jaxb/JaxbDataFormat.java | 20 ++++++--------------
1 file changed, 6 insertions(+), 14 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/ce8844f0/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/JaxbDataFormat.java
----------------------------------------------------------------------
diff --git a/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/JaxbDataFormat.java b/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/JaxbDataFormat.java
index d34836d..f63d91d 100644
--- a/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/JaxbDataFormat.java
+++ b/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/JaxbDataFormat.java
@@ -91,7 +91,7 @@ public class JaxbDataFormat extends ServiceSupport implements DataFormat, CamelC
private JaxbNamespacePrefixMapper namespacePrefixMapper;
private JaxbXmlStreamWriterWrapper xmlStreamWriterWrapper;
private TypeConverter typeConverter;
- private volatile Schema cachedSchema;
+ private Schema cachedSchema;
public JaxbDataFormat() {
}
@@ -341,6 +341,9 @@ public class JaxbDataFormat extends ServiceSupport implements DataFormat, CamelC
namespacePrefixMapper = NamespacePrefixMapperFactory.newNamespacePrefixMapper(camelContext, namespacePrefix);
}
typeConverter = camelContext.getTypeConverter();
+ if (schema != null) {
+ cachedSchema = createSchema(getSources());
+ }
}
@Override
@@ -372,7 +375,7 @@ public class JaxbDataFormat extends ServiceSupport implements DataFormat, CamelC
MalformedURLException {
Unmarshaller unmarshaller = getContext().createUnmarshaller();
if (schema != null) {
- unmarshaller.setSchema(getCachedSchema());
+ unmarshaller.setSchema(cachedSchema);
unmarshaller.setEventHandler(new ValidationEventHandler() {
public boolean handleEvent(ValidationEvent event) {
// stop unmarshalling if the event is an ERROR or FATAL
@@ -390,7 +393,7 @@ public class JaxbDataFormat extends ServiceSupport implements DataFormat, CamelC
MalformedURLException {
Marshaller marshaller = getContext().createMarshaller();
if (schema != null) {
- marshaller.setSchema(getCachedSchema());
+ marshaller.setSchema(cachedSchema);
marshaller.setEventHandler(new ValidationEventHandler() {
public boolean handleEvent(ValidationEvent event) {
// stop marshalling if the event is an ERROR or FATAL ERROR
@@ -403,17 +406,6 @@ public class JaxbDataFormat extends ServiceSupport implements DataFormat, CamelC
return marshaller;
}
- private Schema getCachedSchema() throws FileNotFoundException, MalformedURLException, SAXException {
- if (cachedSchema == null) {
- synchronized (this) {
- if (cachedSchema == null) {
- cachedSchema = createSchema(getSources());
- }
- }
- }
- return cachedSchema;
- }
-
private Schema createSchema(Source[] sources) throws SAXException {
SchemaFactory factory = getOrCreateSchemaFactory();
try {