#!/usr/bin/python
# This file is part of the Coral project.
# Please read the copyright notice in the LICENSE file.
#
# generate_huge_package_hierarchy - Simple UML 1.4 model generator
#
# SYNOPSIS
#
# generate_huge_package_hierarchy filename [depth [children]]
#
#
# DESCRIPTION
#
# generate_huge_package_hierarchy creates a top-level UML 1.4
# Model element, which consists of a hierarchy of Pacakage elements.
# The depth of the hierarchy can be chosen with the @depth parameter,
# and the width (amount of children per parent Package) can be
# chosen with the @children parameter.
#
# The file is always saved in Coral's default format (currently XMI 2.0).
#
# The program is intended for generating models for speed and scalability
# tests.
#
# EXAMPLES
#
# generate_huge_package_hierarchy test.xmi 6 6
# (creates a file with 55986 Package elements)
# 
# AUTHORS
#
# Marcus Alanen <maalanen@abo.fi> 2003
#
#

import sys
import coral
UML14 = coral.lang.UML14


prj = coral.Project()

m = UML14.getElement("Model")()
m.__setProject__(prj)


filename = sys.argv[1]

n_elements = 1
children_per_namespace = 3
depth = 3

if len(sys.argv) > 2:
    depth = int(sys.argv[2])
if len(sys.argv) > 3:
    children_per_namespace = int(sys.argv[3])

def gen(p, n_children, r, maximum, nameprefix):
    global n_elements
    if r >= maximum:
        return
    for i in xrange(n_children):
        n_elements += 1
        child = UML14.getElement("Package")();
        new_nameprefix = nameprefix + str(i+1)
        child.name = new_nameprefix
        p.ownedElement.add(child)
        gen(child, n_children, r+1, maximum, new_nameprefix + "-")

gen(m, children_per_namespace, 1, depth+1, "Package-")

m.name = "Top-Level Model with " + str(n_elements) + " children"

prj.setFilename(filename)
coral.saveDocument(prj)
