Issue #5324 - Jetty XML <Get> should support nested elements.
<Get> "name" attribute is not mandatory anymore. Added handling of nested elements, including <Name>. Added support for calling isXxx() methods. Signed-off-by: Simone Bordet <simone.bordet@gmail.com>
This commit is contained in:
parent
9c00826105
commit
921121afe5
|
@ -798,20 +798,33 @@ public class XmlConfiguration
|
|||
*/
|
||||
private Object get(Object obj, XmlParser.Node node) throws Exception
|
||||
{
|
||||
Class<?> oClass = nodeClass(node);
|
||||
if (oClass != null)
|
||||
obj = null;
|
||||
else
|
||||
oClass = obj.getClass();
|
||||
AttrOrElementNode aoeNode = new AttrOrElementNode(obj, node, "Id", "Name", "Class");
|
||||
String id = aoeNode.getString("Id");
|
||||
String name = aoeNode.getString("Name");
|
||||
String clazz = aoeNode.getString("Class");
|
||||
|
||||
Class<?> oClass;
|
||||
if (clazz != null)
|
||||
{
|
||||
// static call
|
||||
oClass = Loader.loadClass(clazz);
|
||||
obj = null;
|
||||
}
|
||||
else if (obj != null)
|
||||
{
|
||||
oClass = obj.getClass();
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new IllegalArgumentException(node.toString());
|
||||
}
|
||||
|
||||
String name = node.getAttribute("name");
|
||||
String id = node.getAttribute("id");
|
||||
if (LOG.isDebugEnabled())
|
||||
LOG.debug("XML get {}", name);
|
||||
|
||||
try
|
||||
{
|
||||
// Handle getClass explicitly
|
||||
// Handle getClass() explicitly.
|
||||
if ("class".equalsIgnoreCase(name))
|
||||
{
|
||||
obj = oClass;
|
||||
|
@ -824,20 +837,27 @@ public class XmlConfiguration
|
|||
}
|
||||
if (id != null)
|
||||
_configuration.getIdMap().put(id, obj);
|
||||
configure(obj, node, 0);
|
||||
configure(obj, node, aoeNode.getNext());
|
||||
}
|
||||
catch (NoSuchMethodException nsme)
|
||||
catch (NoSuchMethodException nsme1)
|
||||
{
|
||||
try
|
||||
{
|
||||
// Try calling a isXxx() method.
|
||||
Method method = oClass.getMethod("is" + name.substring(0, 1).toUpperCase(Locale.ENGLISH) + name.substring(1));
|
||||
obj = invokeMethod(method, obj);
|
||||
if (id != null)
|
||||
_configuration.getIdMap().put(id, obj);
|
||||
configure(obj, node, aoeNode.getNext());
|
||||
}
|
||||
catch (NoSuchMethodException nsme2)
|
||||
{
|
||||
// Try the field.
|
||||
Field field = oClass.getField(name);
|
||||
obj = getField(field, obj);
|
||||
configure(obj, node, 0);
|
||||
}
|
||||
catch (NoSuchFieldException nsfe)
|
||||
{
|
||||
throw nsme;
|
||||
if (id != null)
|
||||
_configuration.getIdMap().put(id, obj);
|
||||
configure(obj, node, aoeNode.getNext());
|
||||
}
|
||||
}
|
||||
return obj;
|
||||
|
@ -873,7 +893,9 @@ public class XmlConfiguration
|
|||
oClass = obj.getClass();
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new IllegalArgumentException(node.toString());
|
||||
}
|
||||
|
||||
if (LOG.isDebugEnabled())
|
||||
LOG.debug("XML call {}", name);
|
||||
|
|
|
@ -79,8 +79,8 @@ which act on the object returned by the get call.
|
|||
|
||||
A Get with a class attribute is treated as a static get method or field.
|
||||
-->
|
||||
<!ELEMENT Get (Id?,Class?,(%CONFIG;)*) >
|
||||
<!ATTLIST Get %ID_ATTR; %CLASS_ATTR; %NAME_ATTR_REQUIRED; >
|
||||
<!ELEMENT Get (Id?,Name?,Class?,(%CONFIG;)*) >
|
||||
<!ATTLIST Get %ID_ATTR; %NAME_ATTR; %CLASS_ATTR; >
|
||||
|
||||
|
||||
<!--
|
||||
|
|
|
@ -125,8 +125,11 @@
|
|||
</Call>
|
||||
</Call>
|
||||
|
||||
<Get name="String">
|
||||
<Call name="toString"/>
|
||||
<Get>
|
||||
<Name>String</Name>
|
||||
<Call>
|
||||
<Name>toString</Name>
|
||||
</Call>
|
||||
</Get>
|
||||
|
||||
<Call>
|
||||
|
|
Loading…
Reference in New Issue