[jbossws-commits] JBossWS SVN: r9770 - common/trunk/src/main/java/org/jboss/ws/core/utils.

jbossws-commits at lists.jboss.org jbossws-commits at lists.jboss.org
Thu Apr 9 08:41:31 EDT 2009


Author: richard.opalka at jboss.com
Date: 2009-04-09 08:41:31 -0400 (Thu, 09 Apr 2009)
New Revision: 9770

Modified:
   common/trunk/src/main/java/org/jboss/ws/core/utils/JBossWSEntityResolver.java
Log:
[JBWS-2598] fix

Modified: common/trunk/src/main/java/org/jboss/ws/core/utils/JBossWSEntityResolver.java
===================================================================
--- common/trunk/src/main/java/org/jboss/ws/core/utils/JBossWSEntityResolver.java	2009-04-08 15:32:16 UTC (rev 9769)
+++ common/trunk/src/main/java/org/jboss/ws/core/utils/JBossWSEntityResolver.java	2009-04-09 12:41:31 UTC (rev 9770)
@@ -25,6 +25,8 @@
 import java.io.InputStream;
 import java.net.MalformedURLException;
 import java.net.URL;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
 import java.util.Enumeration;
 import java.util.Properties;
 
@@ -37,7 +39,7 @@
  * Dynamically register the JBossWS entities.
  *
  * @author Thomas.Diesler at jboss.org
- * @since 02-Aug-2006
+ * @author Richard.Opalka at jboss.org
  */
 public class JBossWSEntityResolver extends JBossEntityResolver
 {
@@ -52,40 +54,54 @@
    public JBossWSEntityResolver(final String entitiesResource)
    {
       super();
-	   // get stream
-      InputStream is = this.getClass().getClassLoader().getResourceAsStream(entitiesResource);
-	   if (is == null)
-		   throw new IllegalArgumentException("Resource " + entitiesResource + " not found");
-
-	   // load props
-	   Properties props = new Properties();
-	   try
-	   {
-	       props.load(is);
-	   }
-	   catch (IOException ioe)
-	   {
-		   log.error("Cannot read resource: " + entitiesResource, ioe);
-	   }
-	   finally
-	   {
-		   try { is.close(); } catch (IOException ioe) {} // ignore
-	   }
-
-	   if (props.size() == 0)
-		   throw new IllegalArgumentException("Resource " + entitiesResource + " have no mappings defined");
-	   
+    
+      // load entities
+      Properties props = loadEntitiesMappingFromClasspath(entitiesResource);
+      if (props.size() == 0)
+         throw new IllegalArgumentException("No entities mapping defined in resource file: " + entitiesResource);
+      
 	   // register entities
 	   String key = null, val = null;
 	   for (Enumeration<Object> keys = props.keys(); keys.hasMoreElements();)
 	   {
 		   key = (String)keys.nextElement();
 		   val = props.getProperty(key);
+		   
 		   registerEntity(key, val);
 	   }
    }
    
+   private Properties loadEntitiesMappingFromClasspath(final String entitiesResource)
+   {
+      return AccessController.doPrivileged(new PrivilegedAction<Properties>()
+      {
+         public Properties run()
+         {
+            InputStream is = this.getClass().getClassLoader().getResourceAsStream(entitiesResource);
+            // get stream
+            if (is == null)
+               throw new IllegalArgumentException("Resource " + entitiesResource + " not found");
 
+            // load props
+            Properties props = new Properties();
+            try
+            {
+               props.load(is);
+            }
+            catch (IOException ioe)
+            {
+               log.error("Cannot read resource: " + entitiesResource, ioe);
+            }
+            finally
+            {
+               try { is.close(); } catch (IOException ioe) {} // ignore
+            }
+
+            return props;
+         }
+      });
+   }
+
    public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException
    {
       if(log.isDebugEnabled()) log.debug("resolveEntity: [pub=" + publicId + ",sysid=" + systemId + "]");




More information about the jbossws-commits mailing list