Author: jim.ma
Date: 2012-11-13 09:56:55 -0500 (Tue, 13 Nov 2012)
New Revision: 16973
Modified:
common/branches/jbossws-common-1.1.0/src/main/java/org/jboss/ws/core/utils/JBossWSEntityResolver.java
Log:
[JBPAPP-10380]:Fix JBWS2526TestCase
Modified:
common/branches/jbossws-common-1.1.0/src/main/java/org/jboss/ws/core/utils/JBossWSEntityResolver.java
===================================================================
---
common/branches/jbossws-common-1.1.0/src/main/java/org/jboss/ws/core/utils/JBossWSEntityResolver.java 2012-11-13
14:56:46 UTC (rev 16972)
+++
common/branches/jbossws-common-1.1.0/src/main/java/org/jboss/ws/core/utils/JBossWSEntityResolver.java 2012-11-13
14:56:55 UTC (rev 16973)
@@ -56,73 +56,78 @@
// provide logging
private static final Logger log = Logger.getLogger(JBossWSEntityResolver.class);
+
public JBossWSEntityResolver()
{
- this("META-INF/jbossws-entities.properties");
+ super();
+ loadEntity(getClass().getClassLoader(),
"META-INF/jbossws-entities.properties");
+ loadEntity(Thread.currentThread().getContextClassLoader(),
"jbossws-entities.properties");
+
}
- public JBossWSEntityResolver(final String entitiesResource)
- {
- super();
-
+ private void loadEntity(final ClassLoader loader, final String entityResource) {
+ Map<String, Properties> map = propertiesMap.get(loader);
Properties props = null;
- ClassLoader loader = this.getClass().getClassLoader();
- Map<String, Properties> map = propertiesMap.get(loader);
- if (map != null && map.containsKey(entitiesResource))
+ if (map != null && map.containsKey(entityResource))
{
- props = map.get(entitiesResource);
+ props = map.get(entityResource);
}
else
{
- if (map == null)
+ props = loadEntitiesMappingFromClasspath(loader, entityResource);
+ if (map == null && props.size() > 1)
{
map = new ConcurrentHashMap<String, Properties>();
propertiesMap.put(loader, map);
}
- // load entities
- props = loadEntitiesMappingFromClasspath(entitiesResource);
- if (props.size() == 0)
- throw new IllegalArgumentException("No entities mapping defined in
resource file: " + entitiesResource);
- map.put(entitiesResource, props);
+ if (map != null && props.size() > 1)
+ map.put(entityResource, props);
}
-
- // 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);
- }
+
+ // 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)
+ private Properties loadEntitiesMappingFromClasspath(final ClassLoader loader, final
String entitiesResource)
{
return AccessController.doPrivileged(new PrivilegedAction<Properties>()
{
public Properties run()
{
- InputStream is =
this.getClass().getClassLoader().getResourceAsStream(entitiesResource);
+ Properties props = new Properties();
+ InputStream is = loader.getResourceAsStream(entitiesResource);
// get stream
- if (is == null)
- throw new IllegalArgumentException("Resource " +
entitiesResource + " not found");
+ if (is != null)
+ {
- // load props
- Properties props = new Properties();
- try
- {
- props.load(is);
+ // load props
+
+ try
+ {
+ props.load(is);
+ }
+ catch (IOException ioe)
+ {
+ log.error("Cannot read resource: " + entitiesResource, ioe);
+ }
+ finally
+ {
+ try
+ {
+ is.close();
+ }
+ catch (IOException ioe)
+ {
+ } // ignore
+ }
}
- catch (IOException ioe)
- {
- log.error("Cannot read resource: " + entitiesResource, ioe);
- }
- finally
- {
- try { is.close(); } catch (IOException ioe) {} // ignore
- }
-
return props;
}
});
Show replies by date