Getting Started

« Return to page index

Plone Developer Manual is a comprehensive guide to Plone programming.

1. Introduction

An introduction to ArchGenXML - what it is, reasons to use it, who made it.

What is ArchGenXML

With ArchGenXML you can create working python code without writing one single line of python. It is a command-line utility that generates fully functional Zope Products, based on the Archetypes framework, from UML models using XMI (.xmi, .zargo, .zuml) files. The most common use-case is to generate a set of custom content types and folders, possibly with a few tools, a member type and some workflows thrown in.

In practice, you draw your UML diagrams in a tool like ArgoUML or Poseidon which has the ability to generate XMI files. Once you are ready to test your product, you run ArchGenXML on the XMI file, which will generate the product directory. After generation, you will be able to install your product in Plone and have your new content types, tools and workflows available.

At present, round-trip support is not implemented: custom code can't be converted back into XMI (and thus diagrams). However, you can re-generate your product over existing code; method bodies and certain "protected" code sections will be preserved. This means that you can evolve your product's public interfaces, its methods and its attributes in the UML model, without fear of losing your hand-written code.

ArchGenXML is hosted at svn.plone.org as a subproject of the Archetypes project. It is released under GNU General Public Licence 2 or later.

Eyecatcher: UML Model, small image as an example, from a real life project of BlueDynamics

Why should I use ArchGenXML?

Major reasons:

  • You want to save time
  • You are a lazy programmer
  • You don't like to reinvent the wheel
  • You don't like copying and pasting code (and bugs)
  • You make heavy use of references and interfaces
  • You have big projects with many different custom types
  • You want or need a well-documented interface to your product
  • You like structured model- and pattern-driven software development
  • You want to maintain your project in future without getting a headache

and many other good and odd reasons.

Contributors

The project was initially started by Phil Auersperg. Thanks to his laziness :-)

Authors

Phil Auersperg (Project Leader)
BlueDynamics Alliance, Auersperg-Castell KEG, phil@bluedynamics.com,
Jens Klein (Release Manager, Developer and Doc-Writer)
BlueDynamics Alliance, Klein & Partner KEG, jens@bluedynamics.com,
Reinout van Rees (Co-Release Manager, Developer and Doc-Writer)
ZestSoftware
Fabiano Weimar dos Santos (Ideas, Testing, Bugfixing, Workflow)
Weimar Desenvolvimento e Consultoria em Informatica Ltda., xiru@xiru.org,
Martin Aspeli (Improvements, bug fixes and documentation)
Martin Aspeli
Robert Niederreiter (Lots of base work on AGX 2.0)
Robert Niederreiter
and others
thanks to everybody who contributed with testing, doc-writing or code-pieces!

Sponsors

  • Xiru.org, Brazil (Fabiano Weimar dos Santos) sponsors a valuable amount of money into workflow support (State diagrams -> DCWorkflow, will go into release 1.2),
  • PilotSystems, Paris, France (David Sapiro),
  • OpenSource.ag, Innsbruck, Austria (Georg Pleger).

If you want to contribute ArchGenXML by improving the code, helping with documentation or sponsoring money to make us improve it, please contact one of us.

2. Installation

How to install ArchGenXML and get up and running.

Installation

ArchGenXML has a dependency on some zope 3 eggs. To not mess up your global site-packages directory, using buildout or virtualenv is recommended.

Note: In an older version of AGX, a Zope 3 installation could be configured in a ~/.agx_zope_path file. This case is not supported anymore. You can delete this file if you have it.

On Windows, I assume you installed Python 2.4.4 from the msi installer and installed it in the default location. If you have not already done, configure the Path environment variable to include your python path and scripts directory. For this, got to Control Panel, Advanced, Environment Variables, edit Path, append ;C:\\Python24;C:\\Python24\Scripts to the existing string.

Installing stable version

Attention: adding archgenxml egg to a Plone buildout is not supported! Plone 3.x buildout is shipped with old Zope 3.3. ArchGenXML depends on latest version of zope 3 eggs. So please create a buildout only for archgenxml like described below.

If you want to install archgenxml via buildout (recommended), read Using buildout and skip the Using easy_install in a virtualenv part.

It can happen ArchGenXML version on plone.org is older than Pypi because the release manager forgot to upload it on plone.org or for another reason. easy_install and buildout will get by default the latest ArchGenXML version on Pypi, so it's fine.

Using buildout

Create a fresh directory and go into it:

$ mkdir archgenxml_buildout
$ cd archgenxml_buildout

Download the normal bootstrap.py and put it in this directory. You can copy an existing bootstrap.py file of one of your buildout, it's the same file.

Then create a buildout.cfg file in this directory with the following snippet:

[buildout]
parts =
    archgenxml

[archgenxml]
recipe = zc.recipe.egg:scripts
eggs = archgenxml

Finally bootstrap the buildout and run it:

$ python bootstrap.py
$ ./bin/buildout

On Windows, it's bin\buildout, you have to replace '/' by '\' in all following examples.

archgenxml is now available in ./bin/archgenxml.

To update archgenxml later, go in your directory and run buildout again:

$ ./bin/buildout

It will download latest version of archgenxml all all its dependencies.

I call below <path to archgenxml> the archgenxml_buildout directory.

Using easy_install in a virtualenv

If you don't want to use buildout, you can use virtualenv to create an isolated environment. You have to install setuptools egg to have the easy_install command available. On Ubuntu you can do it with apt-get install python-setuptools. On Windows, go to the setuptools pypi page, download the exe which match the Python version you are using and execute it to install it.

Install virtualenv with easy_install:

$ easy_install virtualenv

On Windows easy_install.exe is in C:\Python24\Scripts, so you have to invoke it with the full path if you don't have added this directory in your PATH.

Create the virtualenv with --no-site-packages option to not see packages installed globally:

$ virtualenv --no-site-packages agx
$ cd agx/
$ source bin/activate
$ easy_install archgenxml

Everytime you want use archgenxml, you have to go in the agx directory and type source bin/activate to activate the environment. To deactivate the environment, type deactivate.

To update archgenxml, you have to update each egg, the most important one are archgenxml and xmiparser:

$ easy_install -U archgenxml
$ easy_install -U xmiparser

If you have a problem with archgenxml, please be sure to recreate the virtualenv completly so you have latest versions of all eggs before asking on the archetypes-users mailing-list.

I call below <path to archgenxml> the path to the virtualenv agx directory.

Installing development version

ArchGenXML's svn trunk is for the 2.x development version.

As usual, the goal is to keep trunk workable. Some of the developers work and develop on the edge: trunk.

If you need stability, use the latest release.

The only supported way to use ArchGenXML trunk is with buildout. You install it like this:

$ svn co https://svn.plone.org/svn/archetypes/ArchGenXML/buildout archgenxml_buildout
$ cd archgenxml_buildout
$ python bootstrap.py
$ bin/buildout

To update your buildout:

$ cd archgenxml_buildout
$ svn up
$ bin/buildout

If you are intersted in AGX 3 development, see http://dev.plone.org/archetypes/browser/AGX

I call below <path to archgenxml> the archgenxml_buildout directory.

Get the ArchGenXML profile

The archgenxml_profile.xmi file contains information about stereotypes, fields, and other stuff that AGX needs to generate valid Python code from your model. You can get the profile from subversion.

Or you can regenerate it with <path to archgenxml>/bin/agx_argouml_profile. A archgenxml_profile.xmi file is generated in the current directory.

Create a "<path to archgenxml>/profiles" directory and put the file here.

Note: In an older version of AGX, this file was called 'argouml_profile.xmi'. You should not use it with ArgoUML > 0.24.

Troubleshooting

On Windows, you may have to install and configure the mingw32 compiler to compile the zope.proxy egg, an indirect dependency of archgenxml. Now zope.proxy eggs are built for Windows, so you should not have this problem anymore.

Support

For any questions or problems, please ask on the archetypes-users mailing-list. Please don't use comments on the manual pages. Not everybody is alerted when a comment is added.

If you want to contribute to this documentation, please post on the plone-docs mailing-list.

3. Configure ArgoUML to use the archgenxml profile

ArgoUML can load a "definition" file with predefined tagged values and stereotypes. So you have all the custom tagged values and stereotypes used by ArchGenXML available in dropdown menus.

Background and Notes

The screenshot below shows ArgoUML with the custom tags from the definition file. Having many of the possible options available from a menu has the following benefits:

  • saves time - sometimes clicking is faster than typing
  • reduces errors - no more mispelled tags
  • presents a learning opportunity - seeing new tags and stereotypes provides a springboard for further investigation
taggedvalues-argouml.png

ArgoUML with ArchGenXML profile

This walks you through how a setup of ArgoUML on an Ubuntu desktop system. The methodology should be easily adjusted to other platforms.

Assumptions

These are my assumptions:

  • You already have latest sun java JRE installed. You can get it on Ubuntu with:

    apt-get install sun-java6-jdk
    

    If:

    update-alternatives --list java
    

    don't give you /usr/lib/jvm/java-6-sun/jre/bin/java, you can set java sun as the default java implementation like this:

    update-alternatives --set java /usr/lib/jvm/java-6-sun/jre/bin/java
    
  • You have copied archgenxml_profile.xmi in the <path to archgenxml>/profiles directory like described in the previous section.

Install ArgoUML

Go to http://argouml.tigris.org and download the latest stable version of ArgoUML (0.28 when these lines are written). Download the exe for Windows, the tar.gz archive for Linux.

On Windows, execute the downloaded exe to install it.

On Linux, unpack the archive somewhere, a good location is '/opt':

$ sudo mkdir /opt
$ cd /opt
$ sudo tar xvf /tmp/ArgoUML-0.28.tar.gz

It should create a argouml-0.28 directory.

It is handy to symlink 'argouml.sh' to '/usr/local/bin/argouml':

$ sudo ln -s /opt/argouml-0.28/argouml.sh /usr/local/bin/argouml

Configure ArgoUML to use the definition file

Note: ArgoUML 0.24 used to use the argo.defaultModel option to specify a profile to use like this:

java -Dargo.defaultModel=<path to archgenxml>/profiles/archgenxml_profile.xmi -jar /opt/ArgoUML/argouml.jar

It's not the case anymore with latest ArgoUML version. Please read on.

  • Launch ArgoUML and go to Edit -> Settings... -> Profiles

  • Click on Add and specify your <path to archgenxml>/profiles directory.

    Note: archgenxml will use the list of profiles directories configured on ArgoUML.

  • Close ArgoUML and launch it again.

  • Go again in Edit -> Settings... -> Profiles AGXProfile should be visible now in "Available Profiles".

  • Click on ">>" to add it to "Default profiles".

  • You should remove the Java profile from the "Default profiles" list to be sure to not use stereotypes and tag definitions from this one. You should only have AGXProfile and UML 1.4 in this list. You can't remove the UML 1.4 here, but you remove it by project.

The global configuration is now done.

Now for every new project you create:

  • Click on the fourth icon in the toolbar to configure Profiles for this project. Delete UML 1.4. You should really only have AGXProfile is this list.

Note: if you want to generate Plone 2.5 compatible code, set on the model root the plone_target_version tag definition with value 2.5.

Why ArgoUML?

Just a few notes on why using ArgoUML.

  • Mature - it supports the important stuff (at least as far as ArchGenXML goes), state diagrams, tagged-values, stereotypes.
  • It is pretty lightweight, which is important when your laptop only has 256 MB of RAM and a PIII 700 Mhz processor. Poseidon Community Edition, though nice, is just too memory hungry.
  • Price is good (free and open source)

4. UML

A brief introduction to UML and pointers to further readings.

UML - the Unified Modeling Language - is a graphical language designed to
describe software through diagrams. There are several different types of
diagrams available, but the ones most relevant to ArchGenXML are:

* The class diagram

* The state diagram

Class diagrams are used to draw interfaces, content types (represented as
classes) and tools (represented as classes with the 'portal_tool' stereotype),
as well as the attributes and public operations on these. In addition,
associations in the diagram show how objects are aggregated within or referenced
from one another.

The goal of model-driven development is to create the "blueprints" for your
software in a well-defined, easily-communicated format: the UML model and
diagram thereof. You can design your model using visual tools until you have a
structure which adequately represents your needs, and ArchGenXML will generate
the necessary code.

You probably have to customise that code somewhat, filling in method bodies,
creating new page templates etc., but ArchGenXML takes care of all the
boilerplate for you. With tagged values and stereotypes you can customise the
generated code with a surprising degree of flexibility and control, and when
you need to hand-code something, ArchGenXML won't overwrite your changes
(provided you stick to the protected code sections, clearly marked in the
source code).

This manual does not aim to teach you UML and object-oriented, model-driven
software development. There are several other fine manuals about that on the
web. A very good starting point is the "OMG UML Resource Page":http://www.uml.org/
including its web-links to tutorials.

For a quick-start read "Practical-UML":http://bdn.borland.com/article/0,1410,31863,00.html
chapters 'class-diagram' and 'state-chart-diagram'.

5. Hello World

Create your first minimal content type with ArchGenXML

Open the UML tool of your choice. Make a new UML model and give it a name
'HelloWorld'. Then add a class diagram (most UML tools do this automatically).

Choose the tool for class creation and add a class to the diagram. Give it a
name such as "HelloType" and add an attribute 'HelloText' with type
'string'. The "helloworld3.zargo":helloworld3.zargo (Plone 3.0) / "helloworld25.zargo":helloworld25.zargo (Plone 2.5) was created with ArgoUML
and contains the type as described above.

"Example: HelloWorld with HelloType in UML":img:helloworld.png



Generating the product

Save your model as helloworld.zargo (ArgoUML) or helloworld.zuml (Poseidon), or export it as an XMI file with the name helloworld.xmi. Then go to the command line
and execute::

$ archgenxml helloworld.zargo

ArchGenXML will begin code generation. When it completes, you will have a new
folder 'HelloWorld' on your file system. Its contents looks like::

HelloWorld/
|-- Extensions (only with plone_target_version=2.5)
| |-- Install.py
| `-- __init__.py
|-- HelloType.py
|-- __init__.py
|-- config.py
|-- configure.zcml
|-- i18n
| `-- generated.pot
|-- interfaces.py
|-- locales
|-- profiles
| `-- default
| |-- HelloWorld_marker.txt
| |-- cssregistry.xml
| |-- factorytool.xml
| |-- import_steps.xml
| |-- jsregistry.xml
| |-- metadata.xml
| |-- skins.xml
| |-- types
| | `-- HelloType.xml
| `-- types.xml
|-- profiles.zcml
|-- refresh.txt
|-- setuphandlers.py
`-- skins
|-- helloworld_images
| `-- HelloType.gif
|-- helloworld_styles
`-- helloworld_templates


Installing and using the generated product

Move the whole folder 'HelloWorld' to your Zope/Plone 3 instance's 'Products'
folder. Restart Zope, open Plone in a browser and log in as Manager. Choose
'Plone Setup' from the personal bar and choose 'Add/Remove Products'. A new
product 'HelloWorld' should now appear in the list of products
available for install. Choose it and click 'install'. Go to your personal
folder. In the list of addable items you'll find the new product as an
addable content type. Add a test instance to see if it works.

"Plone: HelloType in action":img:helloworld-plone-shot.png

Thats the trick. By the way: the title is always part of the schema. But don't worry: you can hide or recycle it later.