TweetFollow Us on Twitter

OpenDoc 2
Volume Number:10
Issue Number:8
Column Tag:New Technologies

Extending OpenDoc

The designer’s view on going beyond the initial design

By Kurt Piersol, Apple Computer, Inc.

OpenDoc™ is a component software architecture. It’s been designed to provide a standard, vendor neutral way to create applications that can work together to create compound documents and applications. It will work on almost any platform, and announcements have been made about Macintosh, Windows, OS/2, and UNIX versions of OpenDoc.

When we first envisioned OpenDoc, the idea of extending it was a central design goal. We knew that we couldn’t possibly design everything that might be useful in a component software environment, so we settled for creating a strong core and an equally strong set of extension mechanisms.

The result is a system that you as a developer can alter significantly. You can add new services to the OpenDoc environment or alter the behavior of the existing ones. As you might imagine, there are good ways to do this and not so good ones. We’ll try to describe the ways that we planned for you to change OpenDoc for the Macintosh.

This article assumes that you already know about writing the OpenDoc equivalent of existing applications, part editors. There have been a several descriptions of how you should go about building such editors, including a set of recipes which come as a part of the OpenDoc seed. If you haven’t seen this documentation, though, then you should know a little bit of basic information first. If you have seen this before, feel free to skip the following section.

OpenDoc Basics

First of all, you should know that OpenDoc is basically a scheme for putting software components together. In its first release OpenDoc focuses on allowing you the developer to create editors which can work together to form compound documents. More about this in a moment. However, OpenDoc does not stop with compound documents. As we’ll see in the rest of the article, OpenDoc is designed to form the foundation of an extensive component environment.

Compound Documents

The notion of a compound document is not new. People have been working on them for about 20 years now. A simple document is a collection of some content. It might be text, it might be a drawing, it might be a movie, it might be a HyperCard™ stack. A compound document is a document that has more than one kind of content in it. For example, a document with text and pictures in it counts as a compound document. Any sort of content can be the basis for a compound document. Contrary to popular opinion, a compound document is not a “plain paper” document, because even that definition is too restrictive. Any combination of different kinds of content is possible, whether or not they could ever be represented on paper.

In OpenDoc, this basic idea is carried a bit further. OpenDoc documents allow all the kinds of content in the document to be directly edited, in place, in the document. Further, there is no limit on how many kinds of content can appear together in a single document. You could combine fifty different kinds of content into an OpenDoc document, and have them all live and editable.

We call each of these bits of content a “part.” We chose the name because when we asked users what to call these things, they replied that they were “parts of the document”. Thus, the term “part.”

As a side note, we understand the natural inclination to refer to the famous chicken commercial motto: “Parts is parts.” Most members of the OpenDoc team can manage a tolerant smile when this occurs, although a few snarl and one whimpers. However, we all pretty much exhausted all the possibilities of this particular joke about a year ago.

Part Handlers

The way OpenDoc achieves this flexible ability to compose documents is through the use of special applications called part handlers. There are two kinds of part handler, editors and viewers. A viewer is nothing more than a specialized editor which doesn’t allow the user to change the content of the part. A part editor is much like an existing application: it displays the part, handles events, performs disk I/O, and accepts scripting commands.

Writing part editors and viewers is by far the most common way to extend OpenDoc. By writing one of these, you are extending the scope of information that a user can incorporate into a document.

Component Infrastructure

With the basics out of the way, we can dive into the guts of OpenDoc looking for places to extend it. First, we should spend a bit of time describing the basic design of OpenDoc. We intended for OpenDoc to provide a good basic infrastructure on which various kinds of component systems might be built. To accomplish this, we needed a way for components to find one another, negotiate about resources, and discover what other components were capable of doing.

The first requirement, components finding one another, is fairly simple to implement. In a distributed object space, one must have a method of determining whether objects are a part of a given interactive session. For example, if a hundred people are working in a distributed object environment, how does one tell which objects are associated with which people? The answer in OpenDoc is an object called the “session” object. The session is the root of the run-time object space of an OpenDoc process.

The session is the key to reaching other software components. It points to the major object services which bind the various software components together. OpenDoc components should always have a pointer to the session object in which they are active, or a pointer to some object that can reach the session.

There’s a set of core services in OpenDoc which form the basic building blocks on which other components can be layered. The document architecture of OpenDoc is an example of the kind of system that can be built. However, the document architecture is only one point in a large space of possible architectures. You can build your own architectures using this same basic mechanism.

Name Spaces

One of the most important of the basic services available from the session object is the “name space manager”. This object gives you access to a table of “name spaces” global to the session.

A name space is really a hash table. The hash table, of course, has a list of keys and values. The key is a special kind of string called an ISOString, and the value is any four byte unsigned quantity.

ISOStrings are unique names which follow the ISO 9070 standard for creating unique segmented names. They’re really just long 7-bit ASCII strings which have enough segments to guarantee that they are different from any other name. If you follow the rules for creating an ISOString, you can be sure you’ve created a name that’s unique. OpenDoc uses this technique to create names for data types as well as names for entries in name spaces.

There’s no particular limit, other than memory, governing how large a name space can be. It could store hundreds or thousands of values.

Getting back to the name space manager, you can see that this is really a name space itself, a name space holding pointers to other name spaces.

Now, let’s talk about how to use this rather generic feature to extend OpenDoc. Let’s assume you wish to create a special interface element which is shared by many part editors. A color palette, for example. You’ll need a way to make sure the palette exists as well as find it from any editor that wants to use it.

Name spaces are the perfect tool to use. Here’s the list of steps to use to create your global palette and store it globally.

1. Choose an ISOString to serve as the name of a name space where you will store your global information.

2. Choose another ISOString to represent the global palette in the name space.

3. Check to see if a name space using the chosen name has already been created. If so, get a pointer to it. If not, create it yourself and remember the pointer to it.

4. Check to see if the name for the palette already exists in the name space. If so, get the value and use it as a pointer to the global palette. If the name does not exist, then create a new entry in the name space, create your palette, and put a pointer to the palette object into the value of that entry. You can use this technique to register global information where anyone who knows the two ISOString names can find it. By publishing this information, you can create standard name spaces filled with information being shared between OpenDoc components. If you don’t publish these names, you can still use the mechanism for private global objects. It’s a completely open architecture for making services available to other components, one that avoids naming collisions and still allows either public or private extensions to the OpenDoc object space.

Arbitrator

A second major piece of the component infrastructure can be seen in the “arbitrator” object. Once again, the arbitrator is obtained from the session object. Its purpose in life is to allow the various components to negotiate ownership of various system resources. Each of these resources is called a “focus of arbitration” or just a “focus”.

The arbitrator comes with a set of these foci pre-defined. There are foci for the keystroke stream, the menu bar, the selection, and a few other system level resources. In addition, a special focus called the “modal” focus allows components to seize all events for modal behavior such as modal dialog boxes or script execution. Every focus is defined by an ISOString name.

The interesting point about the arbitrator is that the list of foci is not fixed. Components can create new foci simply by naming them. Once added, any component can use the arbitrator to negotiate for ownership of the focus.

Even more interestingly, you can add special behavior to the negotiation for a particular focus. You can do this by creating a special object called a focus module and registering it with the arbitrator.

So what’s an example of this? Let’s go back to our global palette example. How do we determine who gets to to set the state of the palette at any given time? If it’s like a typical Macintosh palette, it will change state based on the state of the window being edited.

The arbitrator is an excellent tool to use to solve this problem. By creating a special focus for the palette, the various editors wishing to use the palette can negotiate about who “owns” the palette, and can thus change its state.

Let’s go even further, and assume that the palette manages a global hardware resource. Perhaps the palette switches between various ports on a special card to control a multimedia presentation. By adding a focus module to specialize the behavior of the arbitrator, you could prevent the transfer of focus ownership until all pending I/Os are complete.

Extensions

A last major part of the core infrastructure of OpenDoc is the ability to add “extensions” to objects. The core of OpenDoc is focused around user interface and layout tasks. However, there are limitless other modes of interaction between components.

To account for this, the OpenDoc team designed the extension mechanism for OpenDoc objects. Almost every kind of OpenDoc object can be extended using this technique.

The basis for extensions is once again the ISOString naming mechanism. Each extension an object is willing to publish must be named with this mechanism.

Every OpenDoc object must be willing to say whether it supports any given extension. If it claims to support an extension, then it must pass out a secondary object with the appropriate set of member functions for that extension. This object is passed to the requester, who must release the object when it is no longer needed.

This mechanism can be used for a wide variety of purposes. Groups are already at work to define standard extensions for OpenDoc part editors. Spelling and grammar checking extensions are in the works, as well as extensions for extended layout control.

Going back to our global palette example, the extension mechanism is the perfect way to let the palette talk to the editors which make use of it. The code running the palette can check the arbitrator to find the owner of its focus, and then ask that editor for an extension to let it communicate with that editor. For instance, if the palette was a color picker, it could use the extension to notify the owning editor whenever the user decided to pick a new color.

Storage System

OpenDoc’s document architecture is based on a sophisticated storage model. This storage model is designed to be implemented in a number of different ways, by different organizations. The initial container suite implementation for the Macintosh is based on Bento, a multimedia storage format designed for cross-platform use. A number of vendors already use Bento for storage in shipping products.

However, Bento is not the optimal container suite for all possible applications. A more powerful solution, one which supported more efficient space reuse, automatic compression, encryption, or automatic indexing features, would be a welcome addition to OpenDoc. This represents a significant business opportunity for developers of utility software.

The mechanism for adding a container suite in OpenDoc is straightforward. When OpenDoc opens a document, it uses a combination of several objects which together form a “container suite.” Each of these container suites implements a version of the classes XMPStorageUnit, XMPDraft, XMPDocument, and XMPContainer. Each individual document can be controlled by a different container suite. The selection of the appropriate container suite is performed by the binding object, which we’ll discuss in a moment.

Several different kinds of containers can be open in a single session. These container suites are all by definition interoperable. This means that when you follow the OpenDoc API for container suites, OpenDoc itself handles any differences between implementations when data is moved between containers.

At this point, it’s traditional to say that there’s good news and bad news about container suites. First, the bad news. It’s not particularly easy to write a container suite from scratch. In fact, it would be pretty darned hard to do so.

The good news, though, is that you probably don’t need to rewrite from scratch at all. You can get your hands on both the OpenDoc source and the Bento source, and you can use them to subclass the existing behavior! This means that you can do a lot of good stuff without the hassle of rewriting the storage code of OpenDoc.

In particular, you can take advantage of a feature of Bento called “dynamic values”. To understand it, you must first understand the part of Bento called the I/O handler. Bento is designed so that all of its I/O goes through a small set of bottleneck routines called the I/O handler. These routines are pretty simple, just the basic read, write, position, and truncate calls common to almost all file systems. You needn’t even talk to a file system through the handler. In fact, a lot of OpenDoc’s data transfer uses Bento sitting on a special handler which reads and writes to RAM instead of the disk.

Now, this feature would be fairly neat all by itself, but it goes even further. Bento handlers can be layered. That means you can start with basic I/O, layer in encryption or compression or both as independent modules! By layering handlers, you can add significant extra value to Bento without touching the main Bento code.

So now we can get back to the original point. By altering the container suite so that it layers additional handlers under Bento when documents are opened, you could create a plug-in utility that encrypts or compresses every OpenDoc document. You could also create a special version that works directly from a database or document repository. You can do any of these things without rewriting the OpenDoc storage code, simply by creating a subclass that opens documents using layered I/O handlers instead of the standard OpenDoc handler.

Binding

When OpenDoc opens a document, it chooses the appropriate editor based on the type of information it finds in the document. These instructions are contained in a single object, called the “binding” object because it binds editors and data together. The interface is extremely simple: the binding object is passed a data type and returns a class identifier for the correct editor. The intelligence inside the object makes sophisticated use of both user and editor based information to choose the correct editor.

The binding object represents another opportunity to add value to OpenDoc. Just like with storage, you probably don’t want to write one of these objects from scratch. Just as before, you can create a replacement from our sources, and deliver added value. What sort of added value? Well, there are several possibilities.

The first of these is adding a method of checking licensing information during the binding process. Probably this would involve a server request. The result would be a way for users working in a corporate setting to check that they have licenses for every editor run in an OpenDoc document.

A second possibility is to check to see if a later version is available from the group server, and to update the software if needed. This would give IS managers a way to manage software versions and distribution automatically.

A third possibility is to examine the editor itself before binding it. This might be used to check for an authorizing digital signature, or look for virus code, before the editor is loaded. It might even check the editor against a list of approved editors supplied by the IS department as a part of the object.

Each of these options could be implemented by a simple subclassing or delegation technique. We suggest delegating to the system provided binding object or inheriting from it, rather than replacing this object.You could combine any or all of these techniques in a single binding object. The result would be a valuable addition to OpenDoc which might find extensive use in scholastic, workgroup or enterprise settings.

Event System

Possibly the most extensive area available for extension in OpenDoc is a mechanism for altering or enhancing how events are dispatched. All OS and high-level events in OpenDoc pass through a single object called the “dispatcher.” The job of the dispatcher is to make sure the event is delivered to the correct editor.

The dispatcher itself has none of the needed intelligence to perform this task, but instead calls on “dispatch modules” which are registered to handle events or groups of events. As with other parts of OpenDoc, this can be a fairly complex task.

The dispatcher is specifically designed to allow you to perform the equivalent of patching. You can add behavior to dispatching any class of event by getting the dispatch module for that event from the dispatcher, remembering it, and then installing a new replacement module of your own that calls the original dispatch module.

The interface to dispatch modules is extremely simple. They have one interesting member function, “dispatch”, which takes an event record as its parameter. It can either consume the event or pass it along to the remembered dispatch module. It returns a Boolean which signifies whether the event was handled.

As you can see, this makes it easy to install special handlers for certain event combinations. The arbitrator can also provide you with useful information. Remember, though, that you’re sharing the dispatcher with everyone else, so try to be at least a bit polite in how you butcher the event stream.

In this spirit of politeness, we added a way for you to “monitor” the event stream without necessarily interfering with it or being interfered with yourself. By registering a dispatch module as a monitor for a given class of event, you guarantee that OpenDoc will always notify you of any event of that type. However, you cannot decide to stop further processing of the event as a monitor.

In general, we suggest you install monitors and not patch the dispatcher. However, we recognize that there are some cases where nothing but a patch will do. This is really up to you as developers to decide, but remember that you are doing something every bit as dangerous as patching the OS when you patch the dispatcher.

Document extensions

We’ve talked about a number of methods for extending OpenDoc, but we haven’t talked about how to install these mechanisms. To extend the arbitrator or dispatcher, you’ll probably want to install code before any part editors are instantiated. OpenDoc provides a mechanism for this called “document extensions.”

Document extensions are much like the INIT 31 mechanism built into Mac system software. When a OpenDoc shell starts up, it gives each of these extension objects a chance to run before it loads any part editors into the environment. They are passed a pointer to the session object, and can use this opportunity to install special dispatch handlers, arbitrator focus modules, or create objects and populate name spaces with them.

This capability will allow you to install new component architectures into the OpenDoc run-time environment. You can easily add new services or patch OpenDoc in clean and easy to maintain ways.

Parting thoughts

So this ends our short tour of extension opportunities in OpenDoc. You’ll find that this list is far from exhaustive. For instance, you can add a completely new graphics model to OpenDoc, one complementary to existing models like QuickDraw Classic and GX, including new notions of drawing canvas, transformations, and shapes. There are opportunities to provide frameworks to help other developers create OpenDoc part editors. The possibilities are just about endless.

Nonetheless, we think you will find the possibilities presented here are enough to keep you busy for a while. We welcome the opportunity to work with you to create new extensions to the environment. As mentioned above, there are already groups working to provide extensions for spell checking, extended layout, and human interface sharing. A good way to get in touch with them is to get in touch with CILabs, the vendor neutral forum for component software systems. You can reach them on the Internet at cil@cil.org. If you want to talk to some at Apple about an idea or give us a suggestion, there’s a talk group on AppleLink, or you can send us mail at OPENDOC@AppleLink.apple.com.

 
AAPL
$108.00
Apple Inc.
+1.02
MSFT
$46.95
Microsoft Corpora
+0.90
GOOG
$559.08
Google Inc.
+8.77

MacTech Search:
Community Search:

Software Updates via MacUpdate

Vitamin-R 2.20b1 - Personal productivity...
Vitamin-R creates the optimal conditions for your brain to work at its best by structuring your work into short bursts of distraction-free, highly focused activity alternating with opportunities for... Read more
Dropbox 2.10.44 - Cloud synchronization...
Dropbox is an application that creates a special Finder folder that automatically syncs online and between your computers. It allows you to both backup files and keep them up-to-date between systems... Read more
Sandvox 2.9.2 - Easily build eye-catchin...
Sandvox is for Mac users who want to create a professional looking website quickly and easily. With Sandvox, you don't need to be a Web genius to build a stylish, feature-rich, standards-compliant... Read more
Cocktail 8.0.1 - General maintenance and...
Cocktail is a general purpose utility for OS X that lets you clean, repair and optimize your Mac. It is a powerful digital toolset that helps hundreds of thousands of Mac users around the world get... Read more
LibreOffice 4.3.3.2 - Free Open Source o...
LibreOffice is an office suite (word processor, spreadsheet, presentations, drawing tool) compatible with other major office suites. The Document Foundation is coordinating development and... Read more
VMware Fusion 7.0.1 - Run Windows apps a...
VMware Fusion allows you to create a Virtual Machine on your Mac and run Windows (including Windows 8.1) and Windows software on your Mac. Run your favorite Windows applications alongside Mac... Read more
OneNote 15.3.2 - Free digital notebook f...
OneNote is your very own digital notebook. With OneNote, you can capture that flash of genius, that moment of inspiration, or that list of errands that's too important to forget. Whether you're at... Read more
Audio Hijack Pro 2.11.4 - Record and enh...
Audio Hijack Pro drastically changes the way you use audio on your computer, giving you the freedom to listen to audio when you want and how you want. Record and enhance any audio with Audio Hijack... Read more
Iridient Developer 3.0.0 beta 3 - Powerf...
Iridient Developer (was RAW Developer) is a powerful image conversion application designed specifically for OS X. Iridient Developer gives advanced photographers total control over every aspect of... Read more
TextWrangler 4.5.11 - Free general purpo...
TextWrangler is the powerful general purpose text editor, and Unix and server administrator's tool. Oh, and also, like the best things in life, it's free. TextWrangler is the "little brother" to... Read more

Latest Forum Discussions

See All

Monster Flash Review
Monster Flash Review By Jordan Minor on October 31st, 2014 Our Rating: :: ALONE IN THE DARKUniversal App - Designed for iPhone and iPad Solid shooting and a surprising amount of spooky tension make Monster Flash a great portable... | Read more »
Retry Review
Retry Review By Rob Thomas on October 31st, 2014 Our Rating: :: SOARING HIGHUniversal App - Designed for iPhone and iPad Flappy who? Let Retry wash all those bad bird-related memories away on a cool retro-flavored flight… right... | Read more »
Dementia: Book of the Dead Review
Dementia: Book of the Dead Review By Lee Hamlet on October 31st, 2014 Our Rating: :: A TOUGH READUniversal App - Designed for iPhone and iPad A witch hunter is sent after a demonic book in the spooky but short-lived Dementia: Book... | Read more »
Card Dungeon, the Semi-Board Game Roguel...
Card Dungeon, the Semi-Board Game Roguelike, Has Been Renovated Posted by Jessica Fisher on October 31st, 2014 [ permalink ] | Read more »
Logitech Protection + Power iPhone5/5S C...
Made by: Logitech Price: $99.99 Hardware/iOS Integration Rating: 3 out of 5 stars Usability Rating: 0.5 out of 5 stars Reuse Value Rating: 0.75 out of 5 stars Build Quality Rating: 0.75 out of 5 stars Overall Rating: 1.25 out of 5 stars | Read more »
This Is Not a Test Goes Free, Permanentl...
This Is Not a Test Goes Free, Permanently Posted by Jessica Fisher on October 31st, 2014 [ permalink ] Universal App - Designed for iPhone and iPad | Read more »
Swap Heroes Review
Swap Heroes Review By Campbell Bird on October 31st, 2014 Our Rating: :: STRATEGIC SWAPPINGUniversal App - Designed for iPhone and iPad Rotate a cast of heroes to fend of waves of monsters in this difficult, puzzle rpg.   | Read more »
Night Sky Pro™ (Reference)
Night Sky Pro™ 3.0.1 Device: iOS Universal Category: Reference Price: $2.99, Version: 3.0.1 (iTunes) Description: Night Sky Pro™Wonder No More™ Night Sky Pro™ is the ultimate stargazing experience. From the creators of the original... | Read more »
Audio Defence : Zombie Arena (Games)
Audio Defence : Zombie Arena 1.0 Device: iOS Universal Category: Games Price: $4.99, Version: 1.0 (iTunes) Description: A zombie shooter audio game. Made from gut-wrenching 3D binaural sound, for a new kind of weird immersion. You... | Read more »
RPG Asdivine Hearts (Games)
RPG Asdivine Hearts 1.1.0 Device: iOS Universal Category: Games Price: $3.99, Version: 1.1.0 (iTunes) Description: SPECIAL PRICE50% OFF (USD 7.99 -> USD 3.99)!!! Travel alongside four companions and a cat in the adventure of a... | Read more »

Price Scanner via MacPrices.net

Tablets Ascendent Again; Global Tablet Market...
The worldwide tablet grew 11.5% year over year in the third quarter of 2014 (3Q14) with shipments reaching 53.8 million units according to preliminary data from the International Data Corporation (... Read more
Apple now offering refurbished 2014 13-inch R...
The Apple Store is now offering Apple Certified Refurbished 2014 13″ Retina MacBook Pros for up to $270 off the cost of new models. An Apple one-year warranty is included with each model, and... Read more
Apple Regains Momentum As Windows Stutters An...
The latest smartphone sales data from Kantar Worldpanel ComTech, for the three months to March 2014, shows Apple performing strongly in the first quarter of the year, with sales bouncing back in... Read more
Worldwide Smartphone Shipments Increase 25.2%...
New smartphone releases and an increased emphasis on emerging markets drove global smartphone shipments above 300 million units for the second consecutive quarter, according to preliminary data from... Read more
Apple now offering refurbished 2014 15-inch M...
The Apple Store is now offering Apple Certified Refurbished 2014 15″ Retina MacBook Pros for up to $400 off the cost of new models. An Apple one-year warranty is included with each model, and... Read more
Apple drops prices on refurbished 2013 Retina...
The Apple Store has dropped prices on 2013 Apple Certified Refurbished 13″ and 15″ Retina MacBook Pros, with Retina models now available starting at $999. Apple’s one-year warranty is standard, and... Read more
New 2.8GHz Mac mini on sale for $949, save $5...
Abt Electronics has the new 2.8GHz Mac mini in stock and on sale for $949.05 including free shipping. Their price is $50 off MSRP, and it’s the lowest price available for this model from any reseller... Read more
Sale! 3.7GHz Quad Core Mac Pro available for...
 B&H Photo has the 3.7GHz Quad Core Mac Pro on sale for $2649 including free shipping plus NY sales tax only. Their price is $350 off MSRP, and it’s the lowest price for this model from any... Read more
Mujjo Steps Up The Game With Refined Touchscr...
Netherlands based Mujjo have just launched their Refined Touchscreen Gloves, stepping up their game. The gloves feature a updated elegant design that takes these knitted gloves to the next level. A... Read more
Sale! Preorder the new 27-inch 5K iMac for $2...
 Abt Electronics has the new 27″ 3.5GHz 5K iMac on sale and available for preorder for $2374.05 including free shipping. Their price is $125 off MSRP, and it’s the lowest price available for this... Read more

Jobs Board

Position Opening at *Apple* - Apple (United...
…Summary** As a Specialist, you help create the energy and excitement around Apple products, providing the right solutions and getting products into customers' hands. You Read more
Position Opening at *Apple* - Apple (United...
**Job Summary** Being a Business Manager at an Apple Store means you're the catalyst for businesses to discover and leverage the power, ease, and flexibility of Apple Read more
Position Opening at *Apple* - Apple (United...
**Job Summary** As more and more people discover Apple , they visit our stores seeking ways to incorporate our products into their lives. It's your job, as a Store Read more
Position Opening at *Apple* - Apple (United...
**Job Summary** At the Apple Store, you connect business professionals and entrepreneurs with the tools they need in order to put Apple solutions to work in their Read more
Solutions Specialist with *Apple* Knowledge...
Company Description: We are an Apple Authorized Sales and Service Provider. We have been selling and servicing Apple computers in the Fairfield County area for over Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.