From 670b6a964cf637e4de2045213ff3116bff245f77 Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Mon, 3 Jun 2013 11:31:07 -0700 Subject: [PATCH] 408945 XML Args ignored without DTD + Semi-reverting prior commit as it broke with DTD use + Fixing up logic to allow for with and without DTD + Adding testcase that uses default constructor with calls to setup a class --- .../eclipse/jetty/xml/XmlConfiguration.java | 49 ++++++------ .../jetty/xml/DefaultTestConfiguration.java | 74 +++++++++++++++++++ .../jetty/xml/XmlConfigurationTest.java | 36 ++++++++- 3 files changed, 132 insertions(+), 27 deletions(-) create mode 100644 jetty-xml/src/test/java/org/eclipse/jetty/xml/DefaultTestConfiguration.java diff --git a/jetty-xml/src/main/java/org/eclipse/jetty/xml/XmlConfiguration.java b/jetty-xml/src/main/java/org/eclipse/jetty/xml/XmlConfiguration.java index fc798536913..f68a308b3ae 100644 --- a/jetty-xml/src/main/java/org/eclipse/jetty/xml/XmlConfiguration.java +++ b/jetty-xml/src/main/java/org/eclipse/jetty/xml/XmlConfiguration.java @@ -742,39 +742,42 @@ public class XmlConfiguration { Class oClass = nodeClass(node); int argIndex = node.size(); + + Map namedArgMap = new HashMap<>(); + List arguments = new LinkedList<>(); + XmlParser.Node child; + + // Find the elements for (int i = 0; i < node.size(); i++) { Object o = node.get(i); if (o instanceof String) - continue; - if (!((XmlParser.Node)o).getTag().equals("Arg")) { + // Skip raw String nodes + continue; + } + + child = (XmlParser.Node)o; + if(child.getTag().equals("Arg")) + { + String namedAttribute = child.getAttribute("name"); + Object value=value(obj,child); + if (namedAttribute != null) + { + // named arguments + namedArgMap.put(namedAttribute,value); + } + // raw arguments + arguments.add(value); + } else { + // The first non child is the start of + // elements that configure the class, such as + // and nodes argIndex = i; break; } } - Map namedArgMap = new HashMap<>(); - List arguments = new LinkedList<>(); - - for (int i = 0; i < node.size(); i++) - { - Object o = node.get(i); - - if (o instanceof String) - { - continue; - } - - XmlParser.Node argNode = (XmlParser.Node)o; - - String namedAttribute = argNode.getAttribute("name"); - Object value=value(obj,(XmlParser.Node)o); - if (namedAttribute != null) - namedArgMap.put(namedAttribute,value); - arguments.add(value); - } - if (LOG.isDebugEnabled()) LOG.debug("XML new " + oClass); diff --git a/jetty-xml/src/test/java/org/eclipse/jetty/xml/DefaultTestConfiguration.java b/jetty-xml/src/test/java/org/eclipse/jetty/xml/DefaultTestConfiguration.java new file mode 100644 index 00000000000..40c0927b89a --- /dev/null +++ b/jetty-xml/src/test/java/org/eclipse/jetty/xml/DefaultTestConfiguration.java @@ -0,0 +1,74 @@ +// +// ======================================================================== +// Copyright (c) 1995-2013 Mort Bay Consulting Pty. Ltd. +// ------------------------------------------------------------------------ +// All rights reserved. This program and the accompanying materials +// are made available under the terms of the Eclipse Public License v1.0 +// and Apache License v2.0 which accompanies this distribution. +// +// The Eclipse Public License is available at +// http://www.eclipse.org/legal/epl-v10.html +// +// The Apache License v2.0 is available at +// http://www.opensource.org/licenses/apache2.0.php +// +// You may elect to redistribute this code under either of these licenses. +// ======================================================================== +// + +package org.eclipse.jetty.xml; + +public class DefaultTestConfiguration +{ + private String first; + private String second; + private String third; + + DefaultTestConfiguration nested; + + public DefaultTestConfiguration() + { + /* default constructor */ + } + + public String getFirst() + { + return first; + } + + public void setFirst(String first) + { + this.first = first; + } + + public String getSecond() + { + return second; + } + + public void setSecond(String second) + { + this.second = second; + } + + public String getThird() + { + return third; + } + + public void setThird(String third) + { + this.third = third; + } + + public DefaultTestConfiguration getNested() + { + return nested; + } + + public void setNested(DefaultTestConfiguration nested) + { + this.nested = nested; + } + +} diff --git a/jetty-xml/src/test/java/org/eclipse/jetty/xml/XmlConfigurationTest.java b/jetty-xml/src/test/java/org/eclipse/jetty/xml/XmlConfigurationTest.java index 22267cfdd4d..f4b76f1fca2 100644 --- a/jetty-xml/src/test/java/org/eclipse/jetty/xml/XmlConfigurationTest.java +++ b/jetty-xml/src/test/java/org/eclipse/jetty/xml/XmlConfigurationTest.java @@ -552,10 +552,10 @@ public class XmlConfigurationTest " arg2 " + " arg3 " + " " + - " \n" + - " arg1\n" + - " arg2\n" + - " arg3\n" + + " \n" + + " arg1\n" + + " arg2\n" + + " arg3\n" + " " + " " + "").getBytes("ISO-8859-1"))); @@ -571,6 +571,34 @@ public class XmlConfigurationTest Assert.assertEquals("nested third parameter not wired correctly","arg3", atc.getNested().getThird()); } + @Test + public void testSetGetIgnoredMissingDTD() throws Exception + { + XmlConfiguration xmlConfiguration = new XmlConfiguration(new ByteArrayInputStream(("" + + "" + + " arg1 " + + " arg2 " + + " arg3 " + + " " + + " \n" + + " arg1 " + + " arg2 " + + " arg3 " + + " " + + " " + + "").getBytes("ISO-8859-1"))); +// XmlConfiguration xmlConfiguration = new XmlConfiguration(url); + + DefaultTestConfiguration atc = (DefaultTestConfiguration)xmlConfiguration.configure(); + + Assert.assertEquals("first parameter not wired correctly","arg1", atc.getFirst()); + Assert.assertEquals("second parameter not wired correctly","arg2", atc.getSecond()); + Assert.assertEquals("third parameter not wired correctly","arg3", atc.getThird()); + Assert.assertEquals("nested first parameter not wired correctly","arg1", atc.getNested().getFirst()); + Assert.assertEquals("nested second parameter not wired correctly","arg2", atc.getNested().getSecond()); + Assert.assertEquals("nested third parameter not wired correctly","arg3", atc.getNested().getThird()); + } + @Test public void testNestedConstructorNamedInjectionUnorderedMixed() throws Exception {