Thursday, December 10, 2009

XML Schema: Element References

Consider a xml based language consisting of elements (here: nodes) and references to elements (here: nodeRefs). In the following I want to discuss if it is possible to create a xml schema for such a language which

  • allows to express reference dependencies
  • has a base type for an arbitrary number of nodes; a node reference is a node too!
  • is aware of referential integrity

Here is an example of a xml document based on a language which consists of two different nodes and a node reference:

A node either has an unique id (and therefor is enabled to be referenced) or a reference to an id. This property can be denoted with an attributeGroup:

The type of id is not xs:ID because it is possible to omit the id. In this case the node is not enabled to be referenced. The second reason is that references are nodes too. The type xs:ID would force that all nodes have an id - even node references.

In general there are multiple types of nodes which can be referenced. The reference itself is a node too. So we need a base type for node definitions and node references which is an abstract node. In this example a node can have child nodes.

The node definition has optionally an unique id which enables it to be referenced. The ref attribute is prohibited. Because the node type is a restriction the child element has to be denoted again! The node definition is abstract because there are several concrete types of node definitions.

In this example there are two different types of concrete node definitions:

A node reference has no child elements! The id attribute is ommitted because node references cannot be referenced. This can be modeled by using direct references to concrete nodes (no need for transitivity).

The root element encapsulates an arbitrary number of nodes and defines the referential integritiy constraints.

There is one flaw: Xml schema does not allow to create a keyref where the corresponding key is a unique constraint. I don't understand that! It would make sense to allow the specification of attributes which have to be unique within a document for those elements for which they are defined. @W3C: What the reason for that restriction!?

Here is the complete example.xsd:

Of cause there are several other possibilities to model a xml schema for such a language. Here is another (which doesn't match the starting example.xml exactly but shows a different approach with choices):

If you use jaxb to unmarshall a xml file (based on a xsd) I discourage the use of choice elements. They are mapped to multiple java instance variables which are null if not used. Instead I recommend the usage of abstract elements which are mapped to abstract classes. This is a more OO like way.

Tuesday, November 24, 2009

Local Subversion repository with Eclipse

Today I installed Subversion (SVN) on my notebook. I needed versioning for local development. A simple way is to create a file-based repository and connect to it with an eclipse svn client. Follow these steps:

  • Download & install Subversion for Mac
  • Install Eclipse Subversion client plugins
  • Share an Eclipse project in a local repository

Here are the details:

Download & install Subversion for Mac

You can get Subversion for Mac (and other OS's) here. I used the universal openCollabNet binary. Just follow the install instructions of the installer...

It is recommended to add the Subversion bin directory to the system $PATH variable (if you're lazy like me). For example you can edit one of the following files:

  • /etc/profile (system wide .profile for sh)
  • /Users/<you>/.profile (users .profile, loaded at login)
  • /Users/<you>/.bash_profile (users .profile, (re-)loaded with new terminal window)

The .bash_profile was my choice but you can use all of them. Add the following lines:

Btw: Currently I use the non-commercial editor TextWrangler. It's a great tool! The shell command edit <file> opens a gui editor for <file>.

Install Eclipse Subversion client plugins

There are currently two popular SVN plugins for Eclipse: Subclipse and Subversive. The latter is my favourite:

  1. Click Help and Install New Software
  2. Install Subversive SVN Team Provider
    • Choose Site: Galileo (included in Eclipse 3.5)
    • Install: Subversive SVN Team Provider (Incubation)
  3. Install Subversive SVN Connectors
    • Choose site: http://www.polarion.org/projects/subversive/download/eclipse/2.0/update-site/
    • Install: Subversive SVN Connectors SVNKit 1.3.0 Implementation
  4. Restart Eclipse, if asked

Share an Eclipse project in a local repository

Open a terminal (current location: /Users/<you>) and create a local SVN repository:

In the Eclipse Project Explorer richt-click on a project and...

  • Choose Team -> Share Project...
  • Repository Type: SVN
  • Create a new repository location
  • Enter URL: file:///Users/<you>/svn.repository/myFirstRepository and press Finish
  • Finally add the project to repository

Use the Team Synchronization perspective to sync your changes.

Saturday, September 12, 2009

The Generic Chaining Pattern

Have a look at the following situation:

Another example:

I used Generics to get around this flaw:

The example above therefore could be handled as follows:

Used this Generic Chaining Pattern while developing an abstraction layer for database access in an old fashioned jdbc environment. It looked like this:

Thursday, September 10, 2009

0xCAFEBABE

For those who are curious about the URL of this blog (http://cafebab3.blogspot.com) take a look at this discussion.

Wednesday, September 9, 2009

Solid State Disk vs. Sudden Motion Sensor

Lucky owners of a Solid State Disk (SSD) should think about disabling their Suddden Motion Sensor (SMS) which is primary used to protect mechanic hard disks from head crashes. With SSDs head crashes are history - you can work without fear, even if your hardware rumbles.

However, follow these instructions to disable the sensor:
  • open a terminal
  • disable sensor: sudo pmset -a sms 0 (0 = disable, 1 = enable)
  • check actual settings: sudo pmset -g

Switching to Snow Leopard (SL)

Mac OS 10.6 aka Snow Leopard
Unfortunately I wasn't fast enough snatching one of the popular copies of SL at the local store. After waiting four cruelly days I got my copy and spent another day preparing my system for installation. In contrast to the opinion that only windows users have to format their hard disk when installing a new system I chose that way because I like the nerdy 'fresh' feeling of a vanilla system :)

Installation ran smoothly on my unibody MBP. In addition to the installation of several applications I manually copied settings and application data from a time machine backup:
  • Address Book (/Library/Application Support/AddressBook)
  • iCal (/Library/Calendars)
  • Mail (/Library/Mail)
  • Safari (/Library/Safari)
  • VirtualBox (/Library/VirtualBox)
- et voilĂ , it works! (basically at least)

Deleting Time Machine Backup
After manually copying the latest Time Machine backup (@see /Backups.backupdb) to a safe location I tried to purge the Time Machine backup dir. Moving that dir to trash and emptying trash results in an error. Also a simple sudo rm -rdf Backups.backupdb doesn't work. The reason is that apple uses Access Control Lists (ACLs) for Time Machine backups as you can read here and here. After spending a night trying to delete that skit I reconnected Time Machine to my Leopard backup an manually deleted each backup :-/ The remove all option didn't worked for me (nothing happened).

Activate 64-bit Kernel
SL brings 64-bit to the kernel. But you have to activate it manually! Out of the box only applications run in 64-bit mode, the kernel is 32-bit. The actual configuration can be checked by
  1. Choose Apple menu > About This Mac.
  2. Click More Info to open System Profiler. (Or open the Apple System Profiler application located in /Applications/Utilities.)
  3. Click the topic 'Software' on the left. On the right hand you can read the value of '64-bit kernel and extensions'.
To activate the 64-bit kernel follow these steps:

Test your CPU
Not every CPU is capable of running the kernel in 64-bit mode. Open a console and type
ioreg -l -p IODeviceTree | grep firmware-abi
If the output contains the string
EFI64 then your CPU is ready for the 64-bit kernel.

Testrun the 64-bit kernel
There are some secret keys with SL. When booting the machine, press 6 4 (at the same time) to boot the 64-bit kernel. (If you are using the 64-bit kernel by default you can press 3 2 (at the same time) to boot the 32-bit kernel.)

Make changes permanent
If you feel comfortable running the 64-bit kernel (here are some benchmarks) edit the file
/Library/Preferences/SystemConfiguration/com.apple.Boot.plist
to make changes permanent.
Change the key Kernel Flags to the value arch=x86_64. That's all. (but beware of the side effects)

Side Effects
Installing MySQL 5.1 x86_64 from .DMG doesn't work actually because the .DMG is packed with the HFS file system, which is a 32-bit kernel extension and doesn't run on the 64-bit kernel. Workaround: Boot with the magic keys 3 2 and install mysql. Reboot and you're fine.
Another glitch is that the Safari hack Safari Stand does not work with 64-bit (workaround). It is build on SIMBL (32-bit) which is an InputManager, but InputManagers have to be 64-bit with the 64-bit kernel. Update: Yesterday a new Snow Leopard ready beta of SIMBL was released - but I haven't tried it out yet.