Class Diagram Example: Multiple Views

Vadim Nasardinov noted that an advantage of UMLGraph over many GUI-oriented UML drawing tools is the ability to generate different views of a diagram from the same source description. The following two diagrams were generated from the same source; a Makefile illustrates a way to organize this process.

Class Overview

Class overview

Detailed Class View

Detailed class view

Java Description

// Author:  Vadim Nasardinov
// Version: $Id: //users/vadim/docs/uml/notes/diagrams/jdo/class/Root.java#2 $

import java.util.List;
import java.util.Map;

/**
 * @assoc "1..1" - "0..n" Adapter
 * @assoc "" - "0..n" ObjectType
 * @assoc "" - "0..n" ObjectMap
 * @assoc "" - "0..n" Table
 * @assoc "" - "0..n" DataOperation
 **/
class Root {
    private Map m_adapters;
    private List m_types;
    private List m_maps;
    private List m_tables;
    private List m_ops;

    public Adapter getAdapter(Class klass) {}
}

class Adapter {
    public Root getRoot();
}

abstract class Element {
    Root getRoot() {}
}

class ObjectType extends Element {}

/**
 * @has "1..1" - "1..1" ObjectType
 **/
class ObjectMap extends Element {
    private ObjectType m_type;
}

class Table extends Element {}

class DataOperation extends Element {}

Makefile

# Author:  Vadim Nasardinov (vadimn@redhat.com)
# Since:   2004-05-26
# Version: $Id: //users/vadim/docs/uml/Makefile#16 $

# Requires: graphviz
# Requires: transfig
# Requires: libxslt
# Requires: javac
# Requires: javadoc
# Requires: JAVA_HOME/lib/tools.jar

.PHONY : clean all build jar dot png debug

BUILD=build

jar_dir:=$(BUILD)/jars
diagrams := notes/diagrams

java_files := $(shell find $(diagrams) -name *.java)
dot_files  := $(subst .java,.dot,$(java_files))
dot_files  := $(foreach dot, $(dot_files), $(BUILD)/$(dot))
dot_files  += $(subst .dot,-small.dot,$(dot_files))

png_files := $(subst .dot,.png,$(dot_files))

fig_files := $(shell find $(diagrams) -name *.fig)

png_files += $(subst .fig,.png,$(foreach fig, $(fig_files), $(BUILD)/$(fig)))


premade_src_png := $(shell find $(diagrams) -name *.png)
png_files += $(foreach png, $(premade_src_png), $(BUILD)/$(png))

xml_files:=$(shell find notes -name *.xml)
html_files:=$(subst notes/,$(BUILD)/notes/,$(xml_files))
html_files:=$(subst .xml,.html,$(html_files))
stylesheet:= notes/notes.xsl

javac_dest:=$(BUILD)/classes

classpath:=
javac=javac -classpath $(JAVA_HOME)/lib/tools.jar -d $(javac_dest)

timestamp:=$(BUILD)/.timestamp

uml_graph:=$(jar_dir)/UmlGraph.jar

jd:=javadoc
jd_flags := -docletpath $(uml_graph) -doclet UmlGraph -private
jd_flags += -nodefontname luxisr -nodefontabstractname luxisri
jd_flags += -edgefontname luxisr
jd_flags += -nodefontsize 8 -edgefontsize 8
jd_flags += -nodefillcolor LemonChiffon
detailed_flags := -attributes -operations -types

all: doc

clean:
        rm -rf $(BUILD)

jar: $(uml_graph)

build: $(timestamp)

$(timestamp): src/UmlGraph.java
        mkdir -p $(javac_dest)
        $(javac) $?
        touch $(timestamp)

$(uml_graph): $(timestamp)
        mkdir -p $(jar_dir)
        jar cf $(uml_graph) -C $(BUILD)/classes .
        jar i $(uml_graph)


build/%.dot : %.java $(uml_graph)
        mkdir -p $(dir $@)
        $(jd) $(jd_flags) $(detailed_flags) -output $@ $<

build/%-small.dot : %.java $(uml_graph)
        mkdir -p $(dir $@)
        $(jd) $(jd_flags) -output $@ $<

%.png : %.dot $(uml_graph)
        dot -Nheight=0.2 -Elabelfontcolor=DarkSlateBlue -Elabelfontsize=8 -Tpng -o $@ $<

build/%.png : %.fig
        mkdir -p $(dir $@)
        fig2dev -L png -S 4 $< $@

png: $(png_files)

build/%.png : %.png
        mkdir -p $(dir $@)
        cp $< $@

build/%.html: %.xml $(stylesheet)
        mkdir -p $(dir $@)
        xsltproc -o $@ $(stylesheet) $<

doc: $(html_files) $(png_files)

debug:
        @echo $(dot_files)