Fixes #5316 - Review <Map> element in Jetty XML.
Added class attribute and element to Map. Signed-off-by: Simone Bordet <simone.bordet@gmail.com>
This commit is contained in:
parent
90e61eb07f
commit
7fe9fe5dea
|
@ -64,7 +64,6 @@ import org.eclipse.jetty.util.TypeUtil;
|
||||||
import org.eclipse.jetty.util.annotation.Name;
|
import org.eclipse.jetty.util.annotation.Name;
|
||||||
import org.eclipse.jetty.util.component.LifeCycle;
|
import org.eclipse.jetty.util.component.LifeCycle;
|
||||||
import org.eclipse.jetty.util.resource.Resource;
|
import org.eclipse.jetty.util.resource.Resource;
|
||||||
import org.eclipse.jetty.util.thread.AutoLock;
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.xml.sax.SAXException;
|
import org.xml.sax.SAXException;
|
||||||
|
@ -1071,11 +1070,16 @@ public class XmlConfiguration
|
||||||
*/
|
*/
|
||||||
private Object newMap(Object obj, XmlParser.Node node) throws Exception
|
private Object newMap(Object obj, XmlParser.Node node) throws Exception
|
||||||
{
|
{
|
||||||
AttrOrElementNode aoeNode = new AttrOrElementNode(node, "Id", "Entry");
|
AttrOrElementNode aoeNode = new AttrOrElementNode(node, "Id", "Entry", "Class");
|
||||||
String id = aoeNode.getString("Id");
|
String id = aoeNode.getString("Id");
|
||||||
List<XmlParser.Node> entries = aoeNode.getNodes("Entry");
|
List<XmlParser.Node> entries = aoeNode.getNodes("Entry");
|
||||||
|
String clazz = aoeNode.getString("Class");
|
||||||
|
if (clazz == null)
|
||||||
|
clazz = HashMap.class.getName();
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
Class<? extends Map<Object, Object>> oClass = Loader.loadClass(clazz);
|
||||||
|
|
||||||
Map<Object, Object> map = new HashMap<>();
|
Map<Object, Object> map = oClass.getConstructor().newInstance();
|
||||||
if (id != null)
|
if (id != null)
|
||||||
_configuration.getIdMap().put(id, map);
|
_configuration.getIdMap().put(id, map);
|
||||||
|
|
||||||
|
|
|
@ -259,8 +259,8 @@ This is equivalent to:
|
||||||
Map m = new HashMap();
|
Map m = new HashMap();
|
||||||
m.put("keyName", new String("value1"));
|
m.put("keyName", new String("value1"));
|
||||||
-->
|
-->
|
||||||
<!ELEMENT Map (Id?,Entry*) >
|
<!ELEMENT Map (Id?,Class?,Entry*) >
|
||||||
<!ATTLIST Map %ID_ATTR; >
|
<!ATTLIST Map %ID_ATTR; %CLASS_ATTR; >
|
||||||
<!ELEMENT Entry (Item,Item) >
|
<!ELEMENT Entry (Item,Item) >
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -33,6 +33,7 @@ import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.ConcurrentMap;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
@ -172,6 +173,11 @@ public class XmlConfigurationTest
|
||||||
Map<String, String> map = (Map<String, String>)configuration.getIdMap().get("map");
|
Map<String, String> map = (Map<String, String>)configuration.getIdMap().get("map");
|
||||||
assertEquals(map.get("key0"), "value0");
|
assertEquals(map.get("key0"), "value0");
|
||||||
assertEquals(map.get("key1"), "value1");
|
assertEquals(map.get("key1"), "value1");
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
Map<String, String> concurrentMap = (Map<String, String>)configuration.getIdMap().get("concurrentMap");
|
||||||
|
assertThat(concurrentMap, instanceOf(ConcurrentMap.class));
|
||||||
|
assertEquals(concurrentMap.get("KEY"), "ITEM");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
|
|
|
@ -132,6 +132,13 @@
|
||||||
</Entry>
|
</Entry>
|
||||||
</Map>
|
</Map>
|
||||||
|
|
||||||
|
<Map id="concurrentMap" class="java.util.concurrent.ConcurrentHashMap">
|
||||||
|
<Entry>
|
||||||
|
<Item>KEY</Item>
|
||||||
|
<Item>ITEM</Item>
|
||||||
|
</Entry>
|
||||||
|
</Map>
|
||||||
|
|
||||||
</Configure>
|
</Configure>
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -172,6 +172,15 @@
|
||||||
</Entry>
|
</Entry>
|
||||||
</Map>
|
</Map>
|
||||||
|
|
||||||
|
<Map>
|
||||||
|
<Id>concurrentMap</Id>
|
||||||
|
<Class>java.util.concurrent.ConcurrentHashMap</Class>
|
||||||
|
<Entry>
|
||||||
|
<Item>KEY</Item>
|
||||||
|
<Item>ITEM</Item>
|
||||||
|
</Entry>
|
||||||
|
</Map>
|
||||||
|
|
||||||
</Configure>
|
</Configure>
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue