Click here to close now.

Welcome!

Java Authors: Pat Romanski, Elizabeth White, Liz McMillan, Esmeralda Swartz, Asad Ali

Related Topics: Java

Java: Article

Enterprise Java - Properties Editor Framework

Solving the problem of managing application properties

Property files are frequently used in systems built using Java whether it's a thick Java client, a servlet, or a business component. Java specifies the format for a property file and provides the Properties class to read from and write to these files. However, Java is silent on the aspects related to validations of a value entered in a property file, providing room for errors to creep into an application system. How many times have you started to debug a failure in an application only to realize that it's because of an incorrect value in a property file?

The Properties Editor Framework detailed in this article was developed to solve the problem of managing application properties. It provides a convenient way to define a data type for each property and have a companion component in Swing to edit the property value. The framework can be used as a standalone tool or as part of a user interface.

One of the framework's design criteria was that it should work out of a property file, i.e., no other files or databases should be required for managing the property file. This is achieved by using certain meta-attributes to describe the characteristics of each property in the properties file. These meta-attributes are embedded along with each property in the property file as comments (Any line, in a property file, starting with '#' is considered a comment in Java).

In this article, we'll describe the framework's use, the concept of meta-attributes, and the default set of the attributes supported by the framework. And then, we'll explain the framework's design and how to extend it to support a new property data type.

Using the Property Editor Framework
The first step in using the Property Editor Framework is to decide on the Parameter type of each property in the properties file. Currently the framework supports the types listed in Table 1.

The next step is to modify the properties file and add the necessary meta-attributes for each property. Listing 1 shows a sample properties file with meta-attributes.

The final step is to set up the environment for the Property Editor Framework and invoke the Property Editor Dialog to start updating the property values. Figure 1 shows the properties as rendered in the Property editor Dialog.

Meta-Attributes Explained
The basic meta-attributes speci-fied by the framework for each property are Parameter Type, Editable, and Documentation. The Parameter Type represents the type of a property. It's used to render a suitable component for editing the property value. The table below lists the components rendered for the each of the possible values of PARAMETER TYPE.

The meta-attribute EDITABLE indicates whether the user can edit the value of a property. In the Property Editor Dialog, only properties that have a true value for EDITABLE meta-attribute are displayed. This lets the application developer make certain attributes in a property file not editable through the dialog.

The DOCUMENTATION meta-attribute specifies the text (which can be specified using HTML) that provides assistance to the end user while editing any particular property. In Figure 1, this documentation is displayed below the JTable con-taining the editable properties. As HTML tags are accepted, the <A> anchor tag can be used to provide a link to more comprehensive documentation.

Apart from the basic meta-attributes, there are two special meta-attributes. First one, GROUP NAME, is used to group related properties together. In the Property Editor Dialog, each property group is displayed in a separate tab. This could be used to group your attributes into, say, 'Basic' and 'Advanced.' Note that this parameter shouldn't be specified for each property separately. Once a GROUP NAME tag appears, all the parameters till the next GROUP NAME tag are grouped together. Another special meta-attribute is ALLOWED VALUES, which is used in conjunction with the SYMBOL parameter type. This lets you specify the list of valid choices for a SYMBOL property. These values should be separated by commas.

Adding Meta-Attributes
Now that we have a good idea about meta-attributes, let's walk through the steps in adding them to the Property File. Consider the following set of Properties.

LoggingEnabled
LoggingLevel
LogFile
DatabaseURI
DatabaseUser
DatabasePassword

Step 1: Decide the Grouping of the Properties
In the example the properties can be split into two groups based on their purpose, Logging and Database connection. Let's call these groups Logging and Database.

#GROUPNAME = Database
# GROUPNAME = Logging

Step 2: Decide on the Type for Each Property
In the example above, the types to be assigned to each property are shown in Table 3.

Step 3: Add Meta-Attributes to Each Property
The complete listing of this sample is available for download along with the source (see Listing 2).

Design of the Property Editor Framework
In this section, we will detail the design of the Properties Editor Framework. To reduce complexity, we'll break the discussion into: Creating the model of the Properties Editor component, creating the UI of the Properties Editor component, and the framework's persistence mechanism for the properties file.

Creating the Model
The classes involved in reading the properties file into memory and creating the data model are depicted in Figure 2.

The EditorFile class, which ex-tends the File class, is used as a thin wrapper for the Properties file. The EditorFile class provides the facility to add an Observer, which will be notified when changes are made to the property values.

The Parser class is a simple line parser that reads data from the EditorFile instance line-by-line and creates an in-memory model of the property file. It also defines the regular expression patterns to match the different meta-attributes supported by the framework. This class creates a new instance of Group class each time the meta-attribute '#GROUP NAME = <Group Name>' is encountered.

For each property key-value that falls under the same #GROUP NAME, an instance of one of the sub-classes of the Parameter class hierarchy is created. The exact sub-class is decided by the value of the meta-attribute #PARAMETER TYPE, which also keeps track of the value of meta-attribute EDITABLE that's used later by the view to decide whether to make it visible.

Creating the User Interface
The classes involved in rendering the user interface of the component are depicted Figure 3.

Referring to Figure 1, the visual area of the dialog is split between the Panel used to render the table of property key-value pairs and the JEditorPane showing the documentation text of different properties.

More Stories By David Bismut

David Bismut is a third-year student at the Ecole des Mines in Nantes (EMN), a French engineering school. He specializes in information management technologies. He was part of InStep, Infosys's global internship program in 2004.

More Stories By Krishnakumar Pooloth

Krishnakumar Pooloth is a senior technical architect with Infosys Technologies. His areas of expertise include object design, component technology, Java, and expert systems. He holds a Bachelor's degree in electronics and communication from Calicut University, India.

More Stories By Swaminathan Natarajan

Swaminathan Natarajan is a technical architect with Infosys Technologies. His area of expertise is Java, repository technologies, and metadata management.

Comments (1) View Comments

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.


Most Recent Comments
Java Developer's Journal 07/31/05 06:42:09 PM EDT

Enterprise Java - Properties Editor Framework
Property files are frequently used in systems built using Java whether it's a thick Java client, a servlet, or a business component. Java specifies the format for a property file and provides the Properties class to read from and write to these files. However, Java is silent on the aspects related to validations of a value entered in a property file, providing room for errors to creep into an application system. How many times have you started to debug a failure in an application only to realize that it's because of an incorrect value in a property file?

@ThingsExpo Stories
The WebRTC Summit 2014 New York, to be held June 9-11, 2015, at the Javits Center in New York, NY, announces that its Call for Papers is open. Topics include all aspects of improving IT delivery by eliminating waste through automated business models leveraging cloud technologies. WebRTC Summit is co-located with 16th International Cloud Expo, @ThingsExpo, Big Data Expo, and DevOps Summit.
Temasys has announced senior management additions to its team. Joining are David Holloway as Vice President of Commercial and Nadine Yap as Vice President of Product. Over the past 12 months Temasys has doubled in size as it adds new customers and expands the development of its Skylink platform. Skylink leads the charge to move WebRTC, traditionally seen as a desktop, browser based technology, to become a ubiquitous web communications technology on web and mobile, as well as Internet of Things compatible devices.
SYS-CON Events announced today that robomq.io will exhibit at SYS-CON's @ThingsExpo, which will take place on June 9-11, 2015, at the Javits Center in New York City, NY. robomq.io is an interoperable and composable platform that connects any device to any application. It helps systems integrators and the solution providers build new and innovative products and service for industries requiring monitoring or intelligence from devices and sensors.
Docker is an excellent platform for organizations interested in running microservices. It offers portability and consistency between development and production environments, quick provisioning times, and a simple way to isolate services. In his session at DevOps Summit at 16th Cloud Expo, Shannon Williams, co-founder of Rancher Labs, will walk through these and other benefits of using Docker to run microservices, and provide an overview of RancherOS, a minimalist distribution of Linux designed expressly to run Docker. He will also discuss Rancher, an orchestration and service discovery platf...
Wearable technology was dominant at this year’s International Consumer Electronics Show (CES) , and MWC was no exception to this trend. New versions of favorites, such as the Samsung Gear (three new products were released: the Gear 2, the Gear 2 Neo and the Gear Fit), shared the limelight with new wearables like Pebble Time Steel (the new premium version of the company’s previously released smartwatch) and the LG Watch Urbane. The most dramatic difference at MWC was an emphasis on presenting wearables as fashion accessories and moving away from the original clunky technology associated with t...
SYS-CON Events announced today that Vitria Technology, Inc. will exhibit at SYS-CON’s @ThingsExpo, which will take place on June 9-11, 2015, at the Javits Center in New York City, NY. Vitria will showcase the company’s new IoT Analytics Platform through live demonstrations at booth #330. Vitria’s IoT Analytics Platform, fully integrated and powered by an operational intelligence engine, enables customers to rapidly build and operationalize advanced analytics to deliver timely business outcomes for use cases across the industrial, enterprise, and consumer segments.
SYS-CON Events announced today that Solgenia will exhibit at SYS-CON's 16th International Cloud Expo®, which will take place on June 9-11, 2015, at the Javits Center in New York City, NY, and the 17th International Cloud Expo®, which will take place on November 3–5, 2015, at the Santa Clara Convention Center in Santa Clara, CA. Solgenia is the global market leader in Cloud Collaboration and Cloud Infrastructure software solutions. Designed to “Bridge the Gap” between Personal and Professional Social, Mobile and Cloud user experiences, our solutions help large and medium-sized organizations dr...
SYS-CON Events announced today that Liaison Technologies, a leading provider of data management and integration cloud services and solutions, has been named "Silver Sponsor" of SYS-CON's 16th International Cloud Expo®, which will take place on June 9-11, 2015, at the Javits Center in New York, NY. Liaison Technologies is a recognized market leader in providing cloud-enabled data integration and data management solutions to break down complex information barriers, enabling enterprises to make smarter decisions, faster.
@ThingsExpo has been named the Top 5 Most Influential M2M Brand by Onalytica in the ‘Machine to Machine: Top 100 Influencers and Brands.' Onalytica analyzed the online debate on M2M by looking at over 85,000 tweets to provide the most influential individuals and brands that drive the discussion. According to Onalytica the "analysis showed a very engaged community with a lot of interactive tweets. The M2M discussion seems to be more fragmented and driven by some of the major brands present in the M2M space. This really allows some room for influential individuals to create more high value inter...
After making a doctor’s appointment via your mobile device, you receive a calendar invite. The day of your appointment, you get a reminder with the doctor’s location and contact information. As you enter the doctor’s exam room, the medical team is equipped with the latest tablet containing your medical history – he or she makes real time updates to your medical file. At the end of your visit, you receive an electronic prescription to your preferred pharmacy and can schedule your next appointment.
The world's leading Cloud event, Cloud Expo has launched Microservices Journal on the SYS-CON.com portal, featuring over 19,000 original articles, news stories, features, and blog entries. DevOps Journal is focused on this critical enterprise IT topic in the world of cloud computing. Microservices Journal offers top articles, news stories, and blog posts from the world's well-known experts and guarantees better exposure for its authors than any other publication. Follow new article posts on Twitter at @MicroservicesE
The list of ‘new paradigm’ technologies that now surrounds us appears to be at an all time high. From cloud computing and Big Data analytics to Bring Your Own Device (BYOD) and the Internet of Things (IoT), today we have to deal with what the industry likes to call ‘paradigm shifts’ at every level of IT. This is disruption; of course, we understand that – change is almost always disruptive.
SYS-CON Events announced today the IoT Bootcamp – Jumpstart Your IoT Strategy, being held June 9–10, 2015, in conjunction with 16th Cloud Expo and Internet of @ThingsExpo at the Javits Center in New York City. This is your chance to jumpstart your IoT strategy. Combined with real-world scenarios and use cases, the IoT Bootcamp is not just based on presentations but includes hands-on demos and walkthroughs. We will introduce you to a variety of Do-It-Yourself IoT platforms including Arduino, Raspberry Pi, BeagleBone, Spark and Intel Edison. You will also get an overview of cloud technologies s...
SYS-CON Events announced today that SafeLogic has been named “Bag Sponsor” of SYS-CON's 16th International Cloud Expo® New York, which will take place June 9-11, 2015, at the Javits Center in New York City, NY. SafeLogic provides security products for applications in mobile and server/appliance environments. SafeLogic’s flagship product CryptoComply is a FIPS 140-2 validated cryptographic engine designed to secure data on servers, workstations, appliances, mobile devices, and in the Cloud.
SOA Software has changed its name to Akana. With roots in Web Services and SOA Governance, Akana has established itself as a leader in API Management and is expanding into cloud integration as an alternative to the traditional heavyweight enterprise service bus (ESB). The company recently announced that it achieved more than 90% year-over-year growth. As Akana, the company now addresses the evolution and diversification of SOA, unifying security, management, and DevOps across SOA, APIs, microservices, and more.
GENBAND has announced that SageNet is leveraging the Nuvia platform to deliver Unified Communications as a Service (UCaaS) to its large base of retail and enterprise customers. Nuvia’s cloud-based solution provides SageNet’s customers with a full suite of business communications and collaboration tools. Two large national SageNet retail customers have recently signed up to deploy the Nuvia platform and the company will continue to sell the service to new and existing customers. Nuvia’s capabilities include HD voice, video, multimedia messaging, mobility, conferencing, Web collaboration, deskt...
SYS-CON Media announced today that @WebRTCSummit Blog, the largest WebRTC resource in the world, has been launched. @WebRTCSummit Blog offers top articles, news stories, and blog posts from the world's well-known experts and guarantees better exposure for its authors than any other publication. @WebRTCSummit Blog can be bookmarked ▸ Here @WebRTCSummit conference site can be bookmarked ▸ Here
SYS-CON Events announced today that Cisco, the worldwide leader in IT that transforms how people connect, communicate and collaborate, has been named “Gold Sponsor” of SYS-CON's 16th International Cloud Expo®, which will take place on June 9-11, 2015, at the Javits Center in New York City, NY. Cisco makes amazing things happen by connecting the unconnected. Cisco has shaped the future of the Internet by becoming the worldwide leader in transforming how people connect, communicate and collaborate. Cisco and our partners are building the platform for the Internet of Everything by connecting the...
SYS-CON Events announced today that Akana, formerly SOA Software, has been named “Bronze Sponsor” of SYS-CON's 16th International Cloud Expo® New York, which will take place June 9-11, 2015, at the Javits Center in New York City, NY. Akana’s comprehensive suite of API Management, API Security, Integrated SOA Governance, and Cloud Integration solutions helps businesses accelerate digital transformation by securely extending their reach across multiple channels – mobile, cloud and Internet of Things. Akana enables enterprises to share data as APIs, connect and integrate applications, drive part...
Cloud is not a commodity. And no matter what you call it, computing doesn’t come out of the sky. It comes from physical hardware inside brick and mortar facilities connected by hundreds of miles of networking cable. And no two clouds are built the same way. SoftLayer gives you the highest performing cloud infrastructure available. One platform that takes data centers around the world that are full of the widest range of cloud computing options, and then integrates and automates everything. Join SoftLayer on June 9 at 16th Cloud Expo to learn about IBM Cloud's SoftLayer platform, explore se...