Skip to content

Commit

Permalink
Fixes #5316 - Review <Map> element in Jetty XML.
Browse files Browse the repository at this point in the history
Added class attribute and element to Map.

Signed-off-by: Simone Bordet <[email protected]>
  • Loading branch information
sbordet committed Sep 23, 2020
1 parent 90e61eb commit 7fe9fe5
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@
import org.eclipse.jetty.util.annotation.Name;
import org.eclipse.jetty.util.component.LifeCycle;
import org.eclipse.jetty.util.resource.Resource;
import org.eclipse.jetty.util.thread.AutoLock;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.xml.sax.SAXException;
Expand Down Expand Up @@ -1071,11 +1070,16 @@ private Object newArray(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");
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)
_configuration.getIdMap().put(id, map);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,8 +259,8 @@ This is equivalent to:
Map m = new HashMap();
m.put("keyName", new String("value1"));
-->
<!ELEMENT Map (Id?,Entry*) >
<!ATTLIST Map %ID_ATTR; >
<!ELEMENT Map (Id?,Class?,Entry*) >
<!ATTLIST Map %ID_ATTR; %CLASS_ATTR; >
<!ELEMENT Entry (Item,Item) >


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -172,6 +173,11 @@ public void testPassedObject(String configure) throws Exception
Map<String, String> map = (Map<String, String>)configuration.getIdMap().get("map");
assertEquals(map.get("key0"), "value0");
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,13 @@
</Entry>
</Map>

<Map id="concurrentMap" class="java.util.concurrent.ConcurrentHashMap">
<Entry>
<Item>KEY</Item>
<Item>ITEM</Item>
</Entry>
</Map>

</Configure>


Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,15 @@
</Entry>
</Map>

<Map>
<Id>concurrentMap</Id>
<Class>java.util.concurrent.ConcurrentHashMap</Class>
<Entry>
<Item>KEY</Item>
<Item>ITEM</Item>
</Entry>
</Map>

</Configure>


0 comments on commit 7fe9fe5

Please sign in to comment.