You are viewing a plain text version of this content. The canonical link for it is here.
Posted to axis-cvs@ws.apache.org by di...@apache.org on 2006/10/27 03:48:32 UTC
svn commit: r468227 -
/webservices/axis2/branches/java/1_1/modules/jaxbri/src/org/apache/axis2/jaxbri/template/JaxbRIDatabindingTemplate.xsl
Author: dims
Date: Thu Oct 26 18:48:32 2006
New Revision: 468227
URL: http://svn.apache.org/viewvc?view=rev&rev=468227
Log:
Fix for AXIS2-1436 - In JAXB RI, construction of JAXBContext is expensive - only do it once.
Modified:
webservices/axis2/branches/java/1_1/modules/jaxbri/src/org/apache/axis2/jaxbri/template/JaxbRIDatabindingTemplate.xsl
Modified: webservices/axis2/branches/java/1_1/modules/jaxbri/src/org/apache/axis2/jaxbri/template/JaxbRIDatabindingTemplate.xsl
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/java/1_1/modules/jaxbri/src/org/apache/axis2/jaxbri/template/JaxbRIDatabindingTemplate.xsl?view=diff&rev=468227&r1=468226&r2=468227
==============================================================================
--- webservices/axis2/branches/java/1_1/modules/jaxbri/src/org/apache/axis2/jaxbri/template/JaxbRIDatabindingTemplate.xsl (original)
+++ webservices/axis2/branches/java/1_1/modules/jaxbri/src/org/apache/axis2/jaxbri/template/JaxbRIDatabindingTemplate.xsl Thu Oct 26 18:48:32 2006
@@ -17,10 +17,38 @@
<xsl:for-each select="param[not(@type = preceding-sibling::param/@type)]">
<xsl:if test="@type!=''">
+ private static final javax.xml.bind.JAXBContext <xsl:value-of select="translate(@type,'.','_')"/>;
+ </xsl:if>
+ </xsl:for-each>
+
+ private static final java.util.HashMap<Class,javax.xml.bind.JAXBContext> classContextMap = new java.util.HashMap<Class,javax.xml.bind.JAXBContext>();
+
+ static {
+ javax.xml.bind.JAXBContext jc;
+ <xsl:for-each select="param[not(@type = preceding-sibling::param/@type)]">
+ <xsl:if test="@type!=''">
+ jc = null;
+ try {
+ jc = javax.xml.bind.JAXBContext.newInstance(<xsl:value-of select="@type"/>.class);
+ }
+ catch ( javax.xml.bind.JAXBException ex ) {
+ System.err.println("Unable to create JAXBContext for class: <xsl:value-of select='@type'/>");
+ Runtime.getRuntime().exit(-1);
+ }
+ finally {
+ <xsl:value-of select="translate(@type,'.','_')"/> = jc;
+ classContextMap.put(<xsl:value-of select="@type"/>.class, jc);
+ }
+ </xsl:if>
+ </xsl:for-each>
+ }
+
+ <xsl:for-each select="param[not(@type = preceding-sibling::param/@type)]">
+ <xsl:if test="@type!=''">
private org.apache.axiom.om.OMElement toOM(<xsl:value-of select="@type"/> param, org.apache.axiom.soap.SOAPFactory factory, boolean optimizeContent) {
try {
- javax.xml.bind.JAXBContext context = javax.xml.bind.JAXBContext.newInstance(<xsl:value-of select="@type"/>.class);
+ javax.xml.bind.JAXBContext context = <xsl:value-of select="translate(@type,'.','_')"/>;
javax.xml.bind.Marshaller marshaller = context.createMarshaller();
marshaller.setProperty(javax.xml.bind.Marshaller.JAXB_FRAGMENT, Boolean.TRUE);
@@ -56,7 +84,7 @@
java.lang.Class type,
java.util.Map extraNamespaces) {
try {
- javax.xml.bind.JAXBContext context = javax.xml.bind.JAXBContext.newInstance( type );
+ javax.xml.bind.JAXBContext context = classContextMap.get(type);
javax.xml.bind.Unmarshaller unmarshaller = context.createUnmarshaller();
return unmarshaller.unmarshal(param.getXMLStreamReader(), type).getValue();
@@ -119,7 +147,7 @@
public javax.xml.stream.XMLStreamReader getReader() throws javax.xml.stream.XMLStreamException {
try {
- javax.xml.bind.JAXBContext context = javax.xml.bind.JAXBContext.newInstance(outClazz);
+ javax.xml.bind.JAXBContext context = classContextMap.get(outClazz);
org.apache.axiom.om.impl.builder.SAXOMBuilder builder = new org.apache.axiom.om.impl.builder.SAXOMBuilder();
javax.xml.bind.Marshaller marshaller = context.createMarshaller();
marshaller.marshal(outObject, builder);
---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org