SCOUT-91
Cache the JAXBContext in a hash and pass it out rather than getting a 
newInstance every time.


git-svn-id: https://svn.apache.org/repos/asf/webservices/scout/trunk@818152 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/src/main/java/org/apache/ws/scout/registry/JAXBContextUtil.java b/src/main/java/org/apache/ws/scout/registry/JAXBContextUtil.java
new file mode 100644
index 0000000..545cbf9
--- /dev/null
+++ b/src/main/java/org/apache/ws/scout/registry/JAXBContextUtil.java
@@ -0,0 +1,34 @@
+package org.apache.ws.scout.registry;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBElement;
+import javax.xml.bind.JAXBException;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+public class JAXBContextUtil {
+
+	public static final String UDDI_V2_VERSION = "2.0";
+	public static final String UDDI_V3_VERSION = "3.0";
+	
+	private static Log log = LogFactory.getLog(JAXBContextUtil.class);
+	private static final Map<String, JAXBContext> JAXBContexts = new HashMap<String, JAXBContext>();
+
+	static {
+		try {
+			JAXBContexts.put(UDDI_V2_VERSION, JAXBContext.newInstance(new Class[] {org.apache.ws.scout.model.uddi.v2.ObjectFactory.class}));
+			JAXBContexts.put(UDDI_V3_VERSION, JAXBContext.newInstance(new Class[] {org.uddi.api_v3.ObjectFactory.class}));
+		} catch (JAXBException e) {
+			log.error("Initialization of JAXBMarshaller failed:" + e, e);
+			throw new ExceptionInInitializerError(e);
+		}
+	}
+	
+	public static JAXBContext getContext(String uddiVersion) {
+		return JAXBContexts.get(uddiVersion);
+	}
+	
+}
diff --git a/src/main/java/org/apache/ws/scout/registry/RegistryImpl.java b/src/main/java/org/apache/ws/scout/registry/RegistryImpl.java
index 709d93a..8fe222e 100644
--- a/src/main/java/org/apache/ws/scout/registry/RegistryImpl.java
+++ b/src/main/java/org/apache/ws/scout/registry/RegistryImpl.java
@@ -226,8 +226,8 @@
 		
 		try
 		{
-			JAXBContext context = JAXBContext.newInstance(new Class[] {ObjectFactory.class});
-			JAXBContext v3context = JAXBContext.newInstance(new Class[] {org.uddi.api_v3.ObjectFactory.class});
+			JAXBContext context = JAXBContextUtil.getContext(JAXBContextUtil.UDDI_V2_VERSION);
+			JAXBContext v3context = JAXBContextUtil.getContext(JAXBContextUtil.UDDI_V3_VERSION);
 			if ("3.0".equals(uddiVer)) { 
 				this.unmarshaller = v3context.createUnmarshaller(); 
 			} else {
diff --git a/src/main/java/org/apache/ws/scout/registry/RegistryV3Impl.java b/src/main/java/org/apache/ws/scout/registry/RegistryV3Impl.java
index 5f0140a..b1795c8 100644
--- a/src/main/java/org/apache/ws/scout/registry/RegistryV3Impl.java
+++ b/src/main/java/org/apache/ws/scout/registry/RegistryV3Impl.java
@@ -186,8 +186,8 @@
 		
 		try
 		{
-			JAXBContext context = JAXBContext.newInstance(new Class[] {ObjectFactory.class});
-			JAXBContext v3context = JAXBContext.newInstance(new Class[] {org.uddi.api_v3.ObjectFactory.class});
+			JAXBContext context = JAXBContextUtil.getContext(JAXBContextUtil.UDDI_V2_VERSION);
+			JAXBContext v3context = JAXBContextUtil.getContext(JAXBContextUtil.UDDI_V3_VERSION);
 			if ("3.0".equals(uddiVer)) { 
 				this.unmarshaller = v3context.createUnmarshaller(); 
 			} else {