mirror of
https://github.com/jetty/jetty.project.git
synced 2025-02-23 07:37:55 +00:00
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
|
private Object get(Object obj, XmlParser.Node node) throws Exception
|
||||||
{
|
{
|
||||||
Class<?> oClass = nodeClass(node);
|
AttrOrElementNode aoeNode = new AttrOrElementNode(obj, node, "Id", "Name", "Class");
|
||||||
if (oClass != null)
|
String id = aoeNode.getString("Id");
|
||||||
obj = null;
|
String name = aoeNode.getString("Name");
|
||||||
else
|
String clazz = aoeNode.getString("Class");
|
||||||
oClass = obj.getClass();
|
|
||||||
|
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())
|
if (LOG.isDebugEnabled())
|
||||||
LOG.debug("XML get {}", name);
|
LOG.debug("XML get {}", name);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Handle getClass explicitly
|
// Handle getClass() explicitly.
|
||||||
if ("class".equalsIgnoreCase(name))
|
if ("class".equalsIgnoreCase(name))
|
||||||
{
|
{
|
||||||
obj = oClass;
|
obj = oClass;
|
||||||
@ -824,20 +837,27 @@ public class XmlConfiguration
|
|||||||
}
|
}
|
||||||
if (id != null)
|
if (id != null)
|
||||||
_configuration.getIdMap().put(id, obj);
|
_configuration.getIdMap().put(id, obj);
|
||||||
configure(obj, node, 0);
|
configure(obj, node, aoeNode.getNext());
|
||||||
}
|
}
|
||||||
catch (NoSuchMethodException nsme)
|
catch (NoSuchMethodException nsme1)
|
||||||
{
|
{
|
||||||
try
|
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.
|
// Try the field.
|
||||||
Field field = oClass.getField(name);
|
Field field = oClass.getField(name);
|
||||||
obj = getField(field, obj);
|
obj = getField(field, obj);
|
||||||
configure(obj, node, 0);
|
if (id != null)
|
||||||
}
|
_configuration.getIdMap().put(id, obj);
|
||||||
catch (NoSuchFieldException nsfe)
|
configure(obj, node, aoeNode.getNext());
|
||||||
{
|
|
||||||
throw nsme;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return obj;
|
return obj;
|
||||||
@ -873,7 +893,9 @@ public class XmlConfiguration
|
|||||||
oClass = obj.getClass();
|
oClass = obj.getClass();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
throw new IllegalArgumentException(node.toString());
|
throw new IllegalArgumentException(node.toString());
|
||||||
|
}
|
||||||
|
|
||||||
if (LOG.isDebugEnabled())
|
if (LOG.isDebugEnabled())
|
||||||
LOG.debug("XML call {}", name);
|
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.
|
A Get with a class attribute is treated as a static get method or field.
|
||||||
-->
|
-->
|
||||||
<!ELEMENT Get (Id?,Class?,(%CONFIG;)*) >
|
<!ELEMENT Get (Id?,Name?,Class?,(%CONFIG;)*) >
|
||||||
<!ATTLIST Get %ID_ATTR; %CLASS_ATTR; %NAME_ATTR_REQUIRED; >
|
<!ATTLIST Get %ID_ATTR; %NAME_ATTR; %CLASS_ATTR; >
|
||||||
|
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
|
@ -125,8 +125,11 @@
|
|||||||
</Call>
|
</Call>
|
||||||
</Call>
|
</Call>
|
||||||
|
|
||||||
<Get name="String">
|
<Get>
|
||||||
<Call name="toString"/>
|
<Name>String</Name>
|
||||||
|
<Call>
|
||||||
|
<Name>toString</Name>
|
||||||
|
</Call>
|
||||||
</Get>
|
</Get>
|
||||||
|
|
||||||
<Call>
|
<Call>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user