Applying "Digital Hub" Concepts to Enterprise Software Design, Part 5by Adam Behringer
Creating a Data-Entry Tool With Cocoa
Welcome to the "Digital Hub" concepts article series, whether you have just joined us or have been following along since the beginning. So far, we have covered an enterprise software architecture based on a flexible "hub" that stores and vends data to a number of cross-platform tools and applications using a standard XML "spoke." If you have been doing all of the tutorials, you have built a database along with a WebObjects application that transforms the data back and forth between the database and XML.
In this article, we are going to build the first client module that will work with the XML spoke data. We are going to using my favorite development environment on the Macintosh, which is Cocoa. If you have not programmed in Cocoa before, this will be a whirlwind tour that will whet your appetite to the potential of this great resource. However, no matter what you experience, you will learn how to quickly create an independent application that participates and adapts to a larger enterprise software system.
The client module we are going to build works with an XML file created and consumed by other components in the larger enterprise system. While I encourage you to start at the beginning and go through each article of this series in order, you may choose to complete this one on its own by using this XML file. If you have completed the series to date, you can generate your own XML using the WeatherHub application that we built in part four.
Here is the XML template from part four that we are going to use for our design:
<?xml version="1.0" encoding="UTF-8"?> <weather> <measureTypes> <type id="0" name="Temperature" dataType="number" /> <type id="1" name="Wind Speed" dataType="number" /> </measureTypes> <data> <item id="0" time="2004-04-17 00:00:00 -0700" typeId="0" data="60" /> <item id="1" time="2004-04-17 00:00:00 -0700" typeId="1" data="3.2" /> </data> </weather>
As a quick review, the
measureTypes represent types of weather data that can be measured. In this case,
Wind Speed can be measured. New
measureTypes could be added by other components in the system (such as an administration tool). The
data node contains specifically measured instances of weather data. Each
data item stores the time at which the data was measured, a
typeId to match the data to a
measureType, and the actual data itself. Note that every element extracted from the database has an
id attribute that maps to its database
What we need now is an intuitive application for field scientists to use to record the data from their gauges and thermometers. After the data is recorded, it can be uploaded to the central hub. For now, we will assume that each scientist has been issued an Apple iBook and has Internet connectivity at his or her office, but may not have connectivity in the field when they are taking their readings. It goes without saying that you do not want to deploy a new version of the application every time a new
measureType is added, so the user interface of the application should update dynamically based on the XML. Finally, the application is not for viewing old data or for modifying data that has already been uploaded to the database. We will only allow the creation of new data and the editing of that new data.
Here is what the finished application will look like:
We are going to use the Cocoa developing environment because it is the coolest language for creating Macintosh applications. Our user interface will consist of a drop-down menu to select a
measureType and a text box in which to type the data. As new data is added, it will be displayed in a table view so that it can be modified or deleted. The application will read XML that has been downloaded through the WeatherHub web interface and will also save XML that can be uploaded through the WeatherHub web interface.
Create a Cocoa Application
Launch Xcode and choose New Project... from the File menu.
Choose Cocoa Document-based Application as the project type and click Next.
Name the project
EnterDataand click Finish.