This discussion is archived
1 Reply Latest reply: Jul 9, 2012 6:24 AM by 903917 RSS

Use Enum to keep config attributes.

920854 Newbie
Currently Being Moderated
Hi Guys,

There´s some restrictions to keep config atributes on enum??? Thanks !! I have an xml and use the folow code to retrieve data, and i think to replace this with a enum ...

 public static Map loadFolderConfig()
  {

    if (xmlConfig != null)
    {
      return xmlConfig;
    }

    try
    {
      String docFullPath = "/my-config.xml";
      DocumentBuilder db = JAXPFactory.getInstance().getFactory();
      Document xml = db.parse(DocumentoHelper.class
          .getResourceAsStream(docFullPath));
      NodeList nodeListPrincipal = xml.getElementsByTagName("myconfig");
      NodeList nodeList = nodeListPrincipal.item(0).getChildNodes();
      Node nodeAtual = nodeListPrincipal.item(0).getFirstChild();
      xmlConfig = new LinkedHashMap();
      for (int f = 0; f < nodeList.getLength(); f++)
      {

        NamedNodeMap attributes = nodeAtual.getAttributes();

        if (nodeAtual != null && attributes != null)
        {
          String value = attributes.item(0).getNodeValue();
          xmlConfig.put(attributes.item(0).getNodeName(), value);
        }
        nodeAtual = nodeAtual.getNextSibling();
      }
    }
Edited by: PaulH on 30/03/2012 12:09
  • 1. Re: Use Enum to keep config attributes.
    903917 Newbie
    Currently Being Moderated
    An XML file is the better way to go in my opinion.

    If you use an Enum to store your config attributes, you have to compile your Java code any time an attribute needs to be changed.

    Using an XML config file, you don't need to recompile your code so it makes for easier modifications of config attributes.

    Another option might be keeping your config attributes in a database table as that makes for easy modification without recompiling as well.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points