On Wed, Jan 14, 2009 at 3:06 PM, Thomas N. <[hidden email]> wrote:
So the real question then is: since which version AGX is able to resolve
hrefs? (It has to!) It does not. I checked the code. There is no reference to hrefs or
including profiles. More! *.zargo does not even contain the profile
path, only the profile filename (*.xmi does not contain even that). So
AGX cannot find the profile based on the information provided.
When looking into the code, I have found out that modifying agx to
include profiles is not that hard. It took me a day to modify it, but
it works. I attached a patch against agx-2.1. tarball (I was not able
to install current svn of agx). Apply with:
patch -p0 <agx_profiles.diff
in the a directory with the unpacked tarball.
What does the patch change:
You can specify a directory, where your profiles are stored, on the command line.
All used profiles must be in the directory. Even the default uml1.4
profile. I didn't search for that one, I just removed the uml1.4
profile from my project and used only AGX types (tagged values,
stereotypes).
When supplying a .zargo file, the .zargo archive is searched for
profile description and for profile filenames. So this only works for
the .zargo files. For regular xmi files you will have to modify the agx
a bit more. But this is not my problem anymore, I'm happy with argouml
:-)
I hope this change will reach AGX-2.2 (in this form or another).
Cheers,
Martin
--
View this message in context: http://n2.nabble.com/on-archgenxml-and-argouml_profile.xmi-tp2101053p2157002.html
[agx-profiles.diff] --- archgenxml-2.1./src/archgenxml/ArchetypesGenerator.py 2009-01-21 13:35:05.000000000 +0100
+++ archgenxml-2.1./src/archgenxml/ArchetypesGenerator.py 2009-01-19 16:45:36.000000000 +0100
@@ -46,6 +46,8 @@
from archgenxml.plone.interfaces import IConfigPyView
from archgenxml.uml.interfaces import *
+import ZargoParser
+
_marker = []
log = logging.getLogger('generator')
@@ -3966,10 +3968,19 @@
zf=ZipFile(self.xschemaFileName)
xmis=[n for n in zf.namelist() if os.path.splitext(n)[1].lower()in ['.xmi','.xml']]
assert(len(xmis)==1)
+ # search for profiles includes in *.zargo zipfile
+ profile_files = {}
+ if self.profile_dir != '':
+ profiles=[n for n in zf.namelist() if os.path.splitext(n)[1].lower() in ['.profile']]
+ assert(len(profiles)==1)
+ for fn in ZargoParser.getProfileFilenames(zf.read(profiles[0])):
+ profile_files[fn] = os.path.join(self.profile_dir, fn)
+ print "Profile files: '"+str(profile_files)+"'"
buf=zf.read(xmis[0])
self.root=root=XMIParser.parse(xschema=buf,
packages=self.generate_packages, generator=self,
- generate_datatypes=self.generate_datatypes)
+ generate_datatypes=self.generate_datatypes,
+ profile_files=profile_files)
else:
raise TypeError,'input file not of type .xmi, .xml, .zargo, .zuml'
--- archgenxml-2.1./src/archgenxml/ArchGenXML.py 2009-01-21 13:35:05.000000000 +0100
+++ archgenxml-2.1./src/archgenxml/ArchGenXML.py 2009-01-19 15:49:10.000000000 +0100
@@ -99,6 +99,10 @@
if options['pdb_on_exception']:
sys.excepthook = info
+ # check if profile_dir options was set
+ if options['profile_dir']:
+ print "profile_dir: '"+options['profile_dir']+"'"
+
# start generation
try:
# for standalone use
--- archgenxml-2.1./src/archgenxml/OptionParser.py 2009-01-21 13:35:05.000000000 +0100
+++ archgenxml-2.1./src/archgenxml/OptionParser.py 2009-01-19 15:57:59.000000000 +0100
@@ -319,6 +319,15 @@
default='',
)
+parser.add_option("-p",
+ "--profile-dir",
+ dest="profile_dir",
+ help="Directory, where xmi profiles are stored. No other xmi files should be there",
+ section="GENERAL",
+ type="string",
+ default='',
+ )
+
#----------------------------------------------------------------------------
# Config File options
--- archgenxml-2.1./src/archgenxml/XMIParser.py 2009-01-21 13:35:05.000000000 +0100
+++ archgenxml-2.1./src/archgenxml/XMIParser.py 2009-01-20 12:21:37.000000000 +0100
@@ -40,7 +40,6 @@
# Tag constants
clean_trans = string.maketrans(':-. /$', '______')
-
class XMI1_0(object):
XMI_CONTENT = "XMI.content"
OWNED_ELEMENT = "Foundation.Core.Namespace.ownedElement"
@@ -161,6 +160,15 @@
def getIdRef(self, domElement):
return domElement.getAttribute('xmi.idref').strip()
+ def getHrefId(self, domElement):
+ href = domElement.getAttribute('href').strip()
+ splitted = href.rsplit('/',1)
+ if not len(splitted) == 2: return ''
+ return splitted[1]
+
+ def getIdRefOrHrefId(self, domElement):
+ return self.getIdRef(domElement) or self.getHrefId(domElement)
+
def getAssocEndParticipantId(self, el):
assocend = getElementByTagName(el, self.ASSOCEND_PARTICIPANT, None)
@@ -432,7 +440,7 @@
if len(typeinfos):
classifiers = typeinfos[0].getElementsByTagName(XMI.CLASSIFIER)
if len(classifiers):
- typeid = str(classifiers[0].getAttribute('xmi.idref'))
+ typeid = str(self.getIdRefOrHrefId(classifiers[0]))
typeElement = datatypes[typeid]
att.type = XMI.getName(typeElement)
# Collects all datatype names (to prevent pure datatype
@@ -626,19 +634,19 @@
# Fix for http://plone.org/products/archgenxml/issues/62
return None, None
# Fetch the name from the global tagDefinitions (weird)
- idref = tdef.getAttribute('xmi.idref')
- tagname = normalize(self.tagDefinitions[idref].getAttribute('name'))
+ id = self.getIdRefOrHrefId(tdef)
+ tagname = normalize(self.tagDefinitions[id].getAttribute('name'))
tagvalue = normalize(getAttributeValue(el, self.TAGGED_VALUE_VALUE,
default=None))
return tagname, tagvalue
- def collectTagDefinitions(self, el):
+ def collectTagDefinitions(self, el, prefix=''):
tagdefs = el.getElementsByTagName(self.TAG_DEFINITION)
if self.tagDefinitions is None:
self.tagDefinitions = {}
for t in tagdefs:
if t.hasAttribute('name'):
- self.tagDefinitions[t.getAttribute('xmi.id')] = t
+ self.tagDefinitions[prefix+t.getAttribute('xmi.id')] = t
def calculateStereoType(self, o):
# In xmi its weird, because all objects to which a stereotype
@@ -649,7 +657,7 @@
for st in sts:
strefs = getSubElements(st)
for stref in strefs:
- id = stref.getAttribute('xmi.idref').strip()
+ id = self.getIdRefOrHrefId(stref)
if id:
st = stereotypes[id]
o.addStereoType(self.getName(st).strip())
@@ -679,7 +687,7 @@
classifiers = [cn for cn in typeinfos[0].childNodes
if cn.nodeType == cn.ELEMENT_NODE]
if len(classifiers):
- typeid = str(classifiers[0].getAttribute('xmi.idref'))
+ typeid = self.getIdRefOrHrefId(classifiers[0])
try:
typeElement = datatypes[typeid]
except KeyError:
@@ -2679,6 +2687,51 @@
XMI.collectTagDefinitions(doc)
+def buildProfileDataTypes(profile_docs):
+ global datatypes
+ for key in profile_docs.keys():
+ print "DataType profile: "+key
+ doc = profile_docs[key]
+
+ getId = lambda dt: key+"#"+str(dt.getAttribute('xmi.id'))
+
+ dts = doc.getElementsByTagName(XMI.DATATYPE)
+
+ for dt in dts:
+ datatypes[getId(dt)] = dt
+
+ classes = [c for c in doc.getElementsByTagName(XMI.CLASS)]
+
+ for dt in classes:
+ datatypes[getId(dt)] = dt
+
+ interfaces = [c for c in doc.getElementsByTagName(XMI.INTERFACE)]
+
+ for dt in interfaces:
+ datatypes[getId(dt)] = dt
+
+ interfaces = [c for c in doc.getElementsByTagName(XMI.ACTOR)]
+
+ for dt in interfaces:
+ datatypes[getId(dt)] = dt
+ XMI.collectTagDefinitions(doc, prefix=(key+"#"))
+
+def buildProfileStereoTypes(profile_docs):
+ global stereotypes
+
+ for key in profile_docs.keys():
+ print "Stereotype profile: "+key
+ doc = profile_docs[key]
+ getId = lambda dt: key+"#"+str(dt.getAttribute('xmi.id'))
+
+ sts = doc.getElementsByTagName(XMI.STEREOTYPE)
+
+ for st in sts:
+ id = st.getAttribute('xmi.id')
+ if not id:continue
+ stereotypes[getId(st)] = st
+ #print 'stereotype:', id, XMI.getName(st)
+
def buildStereoTypes(doc):
global stereotypes
sts = doc.getElementsByTagName(XMI.STEREOTYPE)
@@ -2689,7 +2742,7 @@
stereotypes[str(id)] = st
#print 'stereotype:', id, XMI.getName(st)
-def buildHierarchy(doc, packagenames):
+def buildHierarchy(doc, packagenames, profile_docs = {}):
"""Builds Hierarchy out of the doc."""
global datatypes
global stereotypes
@@ -2700,8 +2753,12 @@
stereotypes = {}
datatypenames = ['int', 'void', 'string']
+ buildProfileDataTypes(profile_docs)
+ buildProfileStereoTypes(profile_docs)
+
buildDataTypes(doc)
buildStereoTypes(doc)
+
res = XMIModel(doc)
packageElements = doc.getElementsByTagName(XMI.PACKAGE)
@@ -2737,7 +2794,7 @@
return res
-def parse(xschemaFileName=None, xschema=None, packages=[], generator=None,**kw):
+def parse(xschemaFileName=None, xschema=None, packages=[], generator=None, profile_files = {}, **kw):
""" """
global XMI
@@ -2746,6 +2803,10 @@
else:
doc = minidom.parseString(xschema)
+ profile_docs = {}
+ for f in profile_files.keys():
+ profile_docs[f] = minidom.parse(profile_files[f])
+
try:
xmi = doc.getElementsByTagName('XMI')[0]
xmiver = str(xmi.getAttribute('xmi.version'))
@@ -2764,6 +2825,6 @@
XMI.generator = generator
- root = buildHierarchy(doc, packages)
+ root = buildHierarchy(doc, packages, profile_docs = profile_docs)
return root
--- archgenxml-2.1./src/archgenxml/ZargoParser.py 1970-01-01 01:00:00.000000000 +0100
+++ archgenxml-2.1./src/archgenxml/ZargoParser.py 2009-01-19 16:40:03.000000000 +0100
@@ -0,0 +1,8 @@
+from xml.dom import minidom
+
+def getProfileFilenames(xml_string):
+ doc = minidom.parseString(xml_string)
+ filenames = []
+ for el in doc.getElementsByTagName('filename'):
+ filenames.append( el.childNodes[0].data )
+ return filenames
------------------------------------------------------------------------------
This SF.net email is sponsored by:
SourcForge Community
SourceForge wants to tell your story.
http://p.sf.net/sfu/sf-spreadtheword_______________________________________________
Archetypes-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/archetypes-users
|