Home > Articles > Programming > Java

Java Properties Purgatory Part 2

  • Print
  • + Share This
Nonstandard component configuration interfaces (CCIs) for Java lead to wasted time and wasted code. Stuart Halloway looks at problems with the current XML CCIs and proposes a common CCI architecture for all Java components.
Copyright 2002 by Stuart Halloway and DevelopMentor. This article originally appeared in DevelopMentor’s free white paper collection and is reprinted here with the permission of DevelopMentor and the author.
Like this article? We recommend

Abstract: In Part 1 I looked at the sad state of component configuration in the Java world. Today, component developers often rely on property files to configure and manage their components. Unfortunately, this is done in an ad hoc way, with each component developer reinventing the wheel. As a result, Java components are unnecessarily difficult to develop, learn, deploy, and maintain. This is an industry-wide problem, costing countless hours of developer time.

To provide a common vocabulary for discussing component configuration, I introduced the notion of a Component Configuration Interface (CCI). A CCI is any configuration contract specified by a component developer. A CCI is typically not a Java interface, and can take a variety of forms: properties files, serialized Java objects, system properties, XML documents, etc.

I proposed four criteria for designing a standard CCI for Java components: support for structure, lookup, scope, and metadata. In this second part I will use these criteria to

  • Introduce XML as a configuration option

  • Examine the weaknesses of current XML CCIs: the Preferences API and J2EE container configuration

  • Propose a common CCI architecture for all Java components

Using XML for configuration

As of SDK version 1.4, XML parser support is now a standard part of the Java language. Using XML as a configuration format provides an immediate and obvious answer for one of the four CCI criteria--structure. In Part 1 we looked at the difficulty in representing even simple multi-valued strings in property files. With XML, this problem disappears. For example, multiple values for security providers might be specified as


This looks so simple that it is difficult to believe the power and benefit to be gained by adopting XML for component configuration. The advantages are overwhelming:

  • There is only one syntax to learn, so there is no need to remember that some properties delimit values with spaces, others with colons, etc.

  • There is no need to write special parsers for configuration data--the XML parser is built-in.

  • XML parsers can validate that the basic syntax of configuration data is correct.

  • Component developers can use an XML Schema or Document Type Declaration (DTD) to specify the exact structure they expect to receive. This is to CCIs what strongly-typed languages are to APIs.

  • There are an enormous number of tools available to create and manage XML data.

  • XML is language neutral, so the same concepts can be applied to non-Java applications. This is important in the real world where most complex applications are not 100% Java (or anything else).

Given all these benefits, you should make XML your standard for all component configuration. However, there are a few potential counterarguments to consider as you choose this course. Here are three (weak) arguments against XML for component configuration in Java:

  1. XML has considerable potential for ambiguity and confusion.

  2. XML is overkill for simple configuration.

  3. XML-based configuration is not backwards-compatible with existing code.

We will look at each of these in turn.

XML: Potential for confusion?

The concern here is that XML is no better than property files, since there are many ways to encode the same data in XML. For example, the following two XML fragments convey the same basic semantics:

<server codeurl="http://www.develop.com">
            etc. -->
            etc. -->

If a deployer specifies codeurl as an attribute, but the component was expecting a codeurl element, then things will break down. How is this any better than misspelling a property name or choosing the wrong delimiter? In three ways:

  1. Even though errors can occur, they are now being detected by an XML parser, which is presumably thoroughly tested, instead of a one-off configuration parser written by a component developer.

  2. Schemas and DTDs can be used to automatically detect a wide range of incorrect information.

  3. XML-aware tools can help prevent these errors from occurring in the first place.

In short, XML provides a full-fledged type system. Yes, confusion is still possible. However, XML gives you a vocabulary that is as rich for CCIs as the Java language is for APIs.

XML: Overkill for simple configuration?

It is true that XML may be more than you need. There is nothing quite as simple as setting a property on the command line, e.g.:

java -Djava.security.policy=my.policy 

However, there is nothing to say that command-line properties, property files, and XML cannot coexist as configuration options for the same component--as long as there are well-defined rules for precedence that apply to all components. More on this later.

XML and backward compatibility?

The current installed based of Java applications includes thousands of shell scripts to correctly set various CCI properties. A wholesale industry switch to XML would require rewriting these scripts. Also, such a switch would be problematic where pre-1.4 versions of Java are still in use. So, XML cannot be a complete solution. A general-purpose CCI will need a backwards-compatibility mode that includes the various ad hoc solutions currently in place, without encouraging their continued use in the future.

Where are we?

XML alone solves exactly one of the four problems for component configuration, providing structure and type for configuration data. Next we will look at some existing XML CCIs to see how they deal with the other three elements of CCI: lookup, scope, and metadata.

  • + Share This
  • 🔖 Save To Your Account