itSpice
Subscribe:       RSS    Twitter    EMail
 














Using XML Namespace to Determine a Java Package Name at Runtime

By Joseph Pescatello

An object represents the basic unit of operation in a Java program and in other object-oriented programming languages. Most programs consist of many objects which act in concert to provide the prescribed functionality. When a program executes, all objects are created and initialized (instantiated) to the ‘state’ they are required to assume before any work is done. As the program executes, the objects’ states change as different operations are performed. For example, a Bank Account object might start out with a given balance as part of its state. A program that processes deposits could update that balance and thereby change the state of the Bank Account.

A common requirement for any program is to save (or persist) the state of its objects before shutting down. The program will typically write the objects’ state to a persistent storage device such as a computer disk. The program will use that data to later initialize its objects the next time that it runs.

Extensible Markup Language (XML) is frequently used to define the data structures required for persisting a program’s state. An XML document uses namespaces to distinguish the elements contained within it thereby allowing elements to use non-unique names. The elements in the XML document correspond to the objects persisted from an executing program.

Java package names are analogous to XML namespaces. A package name provides a unique identifying prefix for objects in a Java program. This allows a program to contain objects with non-unique names, differentiated by each object’s package name.

When a program persists the state of an object, it frequently needs to define a unique namespace to associate with the corresponding XML element. Conversely, when a program instantiates an object from an XML document, it frequently needs to determine and assign the Java package name to the new object. By using the Java package name to create the XML namespace when an object is persisted, that namespace can later be used to instantiate the object when needed by the program. This saves the programmer from having to concoct an artificial namespace convention when persisting a program’s state. And it provides the programmer with an object’s package name when a program instantiates its objects from a persisted data store.

Joe Pescatello is an author and commercial software developer. Visit http://UncleBobsAttic.com for a sample of his work. You can reach him at joe-p@unclebobsattic.com.

Article Source: http://EzineArticles.com/?expert=Joseph_Pescatello


Tags: [ ]


Related Posts

Random Posts



Comments

2 Responses to “Using XML Namespace to Determine a Java Package Name at Runtime”

  1. 'generic cialis 10mg' on November 27th, 2008 1:25 pm

    Yes I agree with you!

  2. cheap levitra on December 4th, 2008 1:31 am

    Yes I agree with you!






Latest ArticlesLatest News