What's going on in PropertiesWindow.initialize()?

There’s this bit of code in PropertiesWindow.initialize() which I’m trying
to understand right now:

    Node child = originalState.getFirstChild();
    while (child != null) {
      Node nextChild = child.getNextSibling();
      if (Node.ELEMENT_NODE == child.getNodeType()) {
        try {
          Class.forName(((Element)child).getTagName());
          originalState.removeChild(child);
        }
        catch (ClassNotFoundException e1) {
          // If the child element isn't a Buildable component, leave it there.
        }
      }
      child = nextChild;
    }

What’s the purpose of the call to Class.forName()? How does failing to
be a Buildable have any connection with the class named by the tag not
being found?

Some Buildable components are represented by XML elements in which some of the child elements don’t correspond to Buildable VASSAL components. I’m trying to think of an example. Maybe PlayerRoster? In any case, it’s not true that every XML element corresponds to an object in the Buildable tree. This code is assuming that any XML element whose name is the same as a Java class does in fact represent a Buildable component and treats them differently from non-Buildable elements.

rk

Post generated using Mail2Forum (mail2forum.com)

Thus spake “Rodney Kinney”:

Shouldn’t we test whether Buildable.isAssignableFrom() is true for
that class, then?


J.


Messages mailing list
Messages@forums.vassalengine.org
forums.vassalengine.org/mailman/ … engine.org

Post generated using Mail2Forum (mail2forum.com)

Strictly speaking, we should, although I don’t think there are any cases where a buildFile contains elements that correspond to classes that don’t implement Buildable. If a buildFile had them, they would get skipped when the module is built and won’t be present when this code gets executed.

rk

Post generated using Mail2Forum (mail2forum.com)

Thus spake “Rodney Kinney”:

I’ve added a test for that and a brief comment about what’s happening there,
in uckelman-cur@3971.


J.


Messages mailing list
Messages@forums.vassalengine.org
forums.vassalengine.org/mailman/ … engine.org

Post generated using Mail2Forum (mail2forum.com)