diff --git a/CIMToolFeature/feature.xml b/CIMToolFeature/feature.xml index 26bb082f..1b9cabaf 100644 --- a/CIMToolFeature/feature.xml +++ b/CIMToolFeature/feature.xml @@ -2,7 +2,7 @@ @@ -69,7 +69,7 @@ info@healthmarketscience redistributed under the LGPL version 2.1. - + diff --git a/CIMToolHelp/META-INF/MANIFEST.MF b/CIMToolHelp/META-INF/MANIFEST.MF index 20806b44..886e0f49 100644 --- a/CIMToolHelp/META-INF/MANIFEST.MF +++ b/CIMToolHelp/META-INF/MANIFEST.MF @@ -3,7 +3,7 @@ Bundle-ManifestVersion: 2 Automatic-Module-Name: au.com.langdale.cimtoole.help Bundle-Name: CIMTool Help Plug-in Bundle-SymbolicName: au.com.langdale.cimtoole.help;singleton:=true -Bundle-Version: 2.1.0 +Bundle-Version: 2.2.0 Bundle-ClassPath: CIMToolHelp Bundle-Vendor: Langdale Consultants Bundle-RequiredExecutionEnvironment: JavaSE-20 diff --git a/CIMToolPlugin/META-INF/MANIFEST.MF b/CIMToolPlugin/META-INF/MANIFEST.MF index 12fbba7c..0700e05b 100644 --- a/CIMToolPlugin/META-INF/MANIFEST.MF +++ b/CIMToolPlugin/META-INF/MANIFEST.MF @@ -3,7 +3,7 @@ Bundle-ManifestVersion: 2 Automatic-Module-Name: au.com.langdale.cimtoole Bundle-Name: CIMTool Plug-in Bundle-SymbolicName: au.com.langdale.cimtoole;singleton:=true -Bundle-Version: 2.1.0 +Bundle-Version: 2.2.0 Bundle-RequiredExecutionEnvironment: JavaSE-20 Bundle-ClassPath: cimtoole.jar, lib/commons-logging-1.1.1.jar, diff --git a/CIMToolPlugin/builders/builders.json b/CIMToolPlugin/builders/builders.json index 6980d19f..bfefa005 100644 --- a/CIMToolPlugin/builders/builders.json +++ b/CIMToolPlugin/builders/builders.json @@ -56,13 +56,13 @@ "rdfs-augmented-cimcontextor": { "type": "TRANSFORM", "style": "rdfs-augmented-cimcontextor", - "datetime": "2024-01-29T00:00:00Z", + "datetime": "2024-10-01T00:00:00Z", "ext": "augmented-cimcontextor.rdfs" }, "rdfs-2020": { "type": "TRANSFORM", "style": "rdfs-2020", - "datetime": "2024-01-30T00:00:00Z", + "datetime": "2024-10-01T00:00:00Z", "ext": "rdfs-2020.rdfs" }, "linkml": { @@ -82,5 +82,23 @@ "style": "cimantic-graphs-init", "datetime": "2024-08-07T00:00:00Z", "ext": "__init__.py" + }, + "rdfs-501ed2-beta": { + "type": "TRANSFORM", + "style": "rdfs-501ed2-beta", + "datetime": "2024-09-20T00:00:00Z", + "ext": "rdfs-501ed2-beta.rdfs" + }, + "puml-t2b": { + "type": "TEXT", + "style": "puml-t2b", + "datetime": "2024-09-30T00:00:00Z", + "ext": "t2b.puml" + }, + "puml-l2r": { + "type": "TEXT", + "style": "puml-l2r", + "datetime": "2024-09-30T00:00:00Z", + "ext": "l2r.puml" } } diff --git a/CIMToolPlugin/builders/json-schema-draft-07-lite.xsl b/CIMToolPlugin/builders/json-schema-draft-07-lite.xsl index f2e09049..7068b0da 100644 --- a/CIMToolPlugin/builders/json-schema-draft-07-lite.xsl +++ b/CIMToolPlugin/builders/json-schema-draft-07-lite.xsl @@ -1,5 +1,5 @@ - + @@ -1012,7 +1012,7 @@ - + diff --git a/CIMToolPlugin/builders/json-schema-draft-07.xsl b/CIMToolPlugin/builders/json-schema-draft-07.xsl index e9b306d4..19c865ca 100644 --- a/CIMToolPlugin/builders/json-schema-draft-07.xsl +++ b/CIMToolPlugin/builders/json-schema-draft-07.xsl @@ -1,5 +1,5 @@  - + @@ -1014,7 +1014,7 @@ - + diff --git a/CIMToolPlugin/builders/json-schema-draft-2020-12-lite.xsl b/CIMToolPlugin/builders/json-schema-draft-2020-12-lite.xsl index f99dc1bf..c36d3c56 100644 --- a/CIMToolPlugin/builders/json-schema-draft-2020-12-lite.xsl +++ b/CIMToolPlugin/builders/json-schema-draft-2020-12-lite.xsl @@ -1,5 +1,5 @@ - + @@ -1012,7 +1012,7 @@ - + diff --git a/CIMToolPlugin/builders/json-schema-draft-2020-12.xsl b/CIMToolPlugin/builders/json-schema-draft-2020-12.xsl index bf53fda9..edc9dc33 100644 --- a/CIMToolPlugin/builders/json-schema-draft-2020-12.xsl +++ b/CIMToolPlugin/builders/json-schema-draft-2020-12.xsl @@ -1,5 +1,5 @@ - + @@ -1014,7 +1014,7 @@ - + diff --git a/CIMToolPlugin/builders/legacy-rdfs-augmented.xsl b/CIMToolPlugin/builders/legacy-rdfs-augmented.xsl index 51474c5c..753ccd6f 100644 --- a/CIMToolPlugin/builders/legacy-rdfs-augmented.xsl +++ b/CIMToolPlugin/builders/legacy-rdfs-augmented.xsl @@ -1,4 +1,4 @@ - + @@ -32,9 +32,9 @@ - + - + @@ -48,8 +48,8 @@ - - + + @@ -65,13 +65,13 @@ - + - + @@ -86,14 +86,13 @@ - - - - + + + @@ -106,15 +105,15 @@ - + - - - + + + @@ -127,7 +126,7 @@ - + @@ -137,13 +136,13 @@ - - - + + + - + - + @@ -151,7 +150,7 @@ - + @@ -159,13 +158,13 @@ - + - + - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + @@ -200,7 +257,7 @@ - + @@ -208,14 +265,17 @@ - - + + + + + - + diff --git a/CIMToolPlugin/builders/legacy-rdfs.xsl b/CIMToolPlugin/builders/legacy-rdfs.xsl index 25f57a64..41025d99 100644 --- a/CIMToolPlugin/builders/legacy-rdfs.xsl +++ b/CIMToolPlugin/builders/legacy-rdfs.xsl @@ -32,9 +32,9 @@ - + - + @@ -48,8 +48,8 @@ - - + + @@ -65,13 +65,13 @@ - + - + @@ -86,14 +86,13 @@ - - - - + + + @@ -106,15 +105,15 @@ - + - - - + + + @@ -127,7 +126,7 @@ - + @@ -138,12 +137,9 @@ - - - - - - + + + @@ -151,7 +147,7 @@ - + @@ -161,13 +157,10 @@ - - - - - + + @@ -181,15 +174,15 @@ - + - - + + @@ -200,7 +193,7 @@ - + @@ -208,14 +201,14 @@ - - + + - + diff --git a/CIMToolPlugin/builders/linkml.xsl b/CIMToolPlugin/builders/linkml.xsl index 30a7706d..40b42796 100644 --- a/CIMToolPlugin/builders/linkml.xsl +++ b/CIMToolPlugin/builders/linkml.xsl @@ -40,7 +40,6 @@ copyright: "" - prefixes: @@ -48,7 +47,6 @@ : - imports: - linkml:types @@ -91,6 +89,10 @@ comments: "" + annotations: + + ea_guid: "" + is_a: @@ -140,6 +142,8 @@ annotations: + ea_guid: "" + cim_data_type: true uri: @@ -160,9 +164,13 @@ comments: "" + annotations: + + ea_guid: "" + slot_uri: - + @@ -194,9 +202,13 @@ - comments: "" + comments: "" + annotations: + + ea_guid: "" + slot_uri: range: @@ -228,6 +240,10 @@ comments: "" + annotations: + + ea_guid: "" + slot_uri: range: @@ -259,6 +275,10 @@ comments: "" + annotations: + + ea_guid: "" + enum_uri: permissible_values: @@ -281,10 +301,13 @@ comments: "" + annotations: + + ea_guid: "" + - + @@ -396,13 +419,13 @@ - + + + FontSize 14 + Font Bold + + ' Add a note towards the upper left corner of the diagram + + Profile: + Namespace: + + Copyright: + + + + Profile Notes: + + + + + + + + + + + + + + + + + ' Enumeration + + + + + + + [Remaining literals hidden] + + + + + + + + + + + + + + #lightyellow + + #lightgray + + #lightyellow + + + + + + + ' inherits from + + + + + + + [Attributes hidden] + + + + + + + + + + + + + + + + + + + + + ' + + + + + + + [Attributes hidden] + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + o--> + *--> + --> + + + + + #red + + + + + + ' This abstract indicates an "orphan" reference on an invalid Reference/Instance that must be fixed in the profile + ' We highlight it by generating a color indicating it is invalid and that the user should add in the type + + ' nothing to generate + + + + + + + + + + + + + + : [] + + + + + + + + : [] + + + + + + + + : [] + + + + + + + + + + + + + + + + + , + + + + + + + + + + + + + + + + + + + + + + + + + + + + , + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/CIMToolPlugin/builders/puml-t2b.xsl b/CIMToolPlugin/builders/puml-t2b.xsl new file mode 100644 index 00000000..cd5a27b5 --- /dev/null +++ b/CIMToolPlugin/builders/puml-t2b.xsl @@ -0,0 +1,320 @@ + + + + + + + + + Profile + + + + + top to bottom direction + hide empty methods + + + + FontSize 14 + Font Bold + + ' Add a note towards the upper left corner of the diagram + + Profile: + Namespace: + + Copyright: + + + + Profile Notes: + + + + + + + + + + + + + + + + + ' Enumeration + + + + + + + [Remaining literals hidden] + + + + + + + + + + + + + + #lightyellow + + #lightgray + + #lightyellow + + + + + + + ' inherits from + + + + + + + [Attributes hidden] + + + + + + + + + + + + + + + + + + + + + ' + + + + + + + [Attributes hidden] + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + o--> + *--> + --> + + + + + #red + + + + + + ' This abstract indicates an "orphan" reference on an invalid Reference/Instance that must be fixed in the profile + ' We highlight it by generating a color indicating it is invalid and that the user should add in the type + + ' nothing to generate + + + + + + + + + + + + + + : [] + + + + + + + + : [] + + + + + + + + : [] + + + + + + + + + + + + + + + + + , + + + + + + + + + + + + + + + + + + + + + + + + + + + + , + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/CIMToolPlugin/builders/puml-xsd.xsl b/CIMToolPlugin/builders/puml-xsd.xsl new file mode 100644 index 00000000..f075a3b1 --- /dev/null +++ b/CIMToolPlugin/builders/puml-xsd.xsl @@ -0,0 +1,302 @@ + + + + + + + + + Profile + + + + + left to right direction + hide empty methods + + + + FontSize 14 + Font Bold + + ' Add a note towards the upper left corner of the diagram + + Profile: + Namespace: + + Copyright: + + + + Profile Notes: + + + + + + + + + + + + + + + ' compound class + + + + + + + [Attributes hidden] + + + + + + + + + + + + + ' Enumeration + + + + + + [Remaining literals hidden] + + + + + + + + + + + + + + #lightyellow + + #lightgray + + #lightyellow + + + + + + + ' inherits from + + + + + + + [Attributes hidden] + + + + + + + + + + + + + + + + + + + + + ' + + + + + + + [Attributes hidden] + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + o--> + *--> + --> + + + + """" #red + + + + ' This absract indicates an "orphan" reference on an invalid Reference/Instance that must be fixed in the profile + ' We highlight it by generating a color indicating it is invalid and that the user should add in the type + + ' nothing to generate + + + + + + + + + + + + + : [] + + + + + + + : [] + + + + + + + : [] + + + + + + + + + + + + + + + + + + , + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/CIMToolPlugin/builders/rdfs-2020.xsl b/CIMToolPlugin/builders/rdfs-2020.xsl index 018f849a..1b1a0c37 100644 --- a/CIMToolPlugin/builders/rdfs-2020.xsl +++ b/CIMToolPlugin/builders/rdfs-2020.xsl @@ -32,9 +32,9 @@ - + - + @@ -44,8 +44,11 @@ - - + + + + + @@ -57,13 +60,17 @@ - + + - + + + CIMDatatype + @@ -77,37 +84,28 @@ - - - - - - - - + + + + - + - - - - - - - + + + + - + @@ -119,16 +117,18 @@ - + Yes - + - + - + + @@ -136,12 +136,12 @@ - + Yes - + - + - + No - + - + - + + @@ -186,12 +188,12 @@ - + No - + - + @@ -226,13 +226,11 @@ - - - - enum - + + + enum - + @@ -278,20 +276,26 @@ --> + + - + + + + + diff --git a/CIMToolPlugin/builders/rdfs-501ed2-beta.xsl b/CIMToolPlugin/builders/rdfs-501ed2-beta.xsl new file mode 100644 index 00000000..018a3607 --- /dev/null +++ b/CIMToolPlugin/builders/rdfs-501ed2-beta.xsl @@ -0,0 +1,224 @@ + + + + + + + + Profile + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + True + + + + + + + + + + + + + + + + + + + + + + + + + + + True + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + True + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/CIMToolPlugin/builders/rdfs-augmented-cimcontextor.xsl b/CIMToolPlugin/builders/rdfs-augmented-cimcontextor.xsl index cf60a9ff..804aa3d1 100644 --- a/CIMToolPlugin/builders/rdfs-augmented-cimcontextor.xsl +++ b/CIMToolPlugin/builders/rdfs-augmented-cimcontextor.xsl @@ -1,4 +1,4 @@ - + @@ -32,9 +32,9 @@ - + - + @@ -44,8 +44,8 @@ - - + + @@ -57,13 +57,13 @@ - + - + @@ -74,15 +74,13 @@ - - - - - + + + @@ -91,15 +89,15 @@ - + - - - + + + @@ -108,7 +106,7 @@ - + @@ -120,16 +118,18 @@ - + Yes - + - + - + + @@ -137,10 +137,10 @@ - + Yes - + - + No - + - + - + + + - - No + - + - + @@ -203,22 +205,22 @@ - + - + - - + + - + - + @@ -226,10 +228,10 @@ - - + + - + diff --git a/CIMToolPlugin/builders/shacl-501ed2-beta.xsl b/CIMToolPlugin/builders/shacl-501ed2-beta.xsl new file mode 100644 index 00000000..ee80b4bb --- /dev/null +++ b/CIMToolPlugin/builders/shacl-501ed2-beta.xsl @@ -0,0 +1,310 @@ + + + + + + + + Profile + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + CIMDatatype + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Yes + + + + + + + + + + + + + + + + + + Yes + + + + + + + + + + + + + + + + + + + + + + No + + + + + + + + + + + + + + + + + + No + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + enum + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/CIMToolPlugin/src/au/com/langdale/cimtoole/CIMToolPlugin.java b/CIMToolPlugin/src/au/com/langdale/cimtoole/CIMToolPlugin.java index 0ae5cd90..e213fc79 100644 --- a/CIMToolPlugin/src/au/com/langdale/cimtoole/CIMToolPlugin.java +++ b/CIMToolPlugin/src/au/com/langdale/cimtoole/CIMToolPlugin.java @@ -60,7 +60,7 @@ public class CIMToolPlugin extends AbstractUIPlugin { */ public CIMToolPlugin() { } - + @Override public void start(BundleContext context) throws Exception { super.start(context); @@ -92,15 +92,28 @@ private void loadFirebirdEmbeddedLibraries() { unzip(zipFileInputStream, stateLocationNativePlatformDir.getAbsolutePath()); } - // Finally set the - System.setProperty("jna.library.path", stateLocationNativePlatformDir.getAbsolutePath()); - System.err.println(System.getProperty("jna.library.path")); + // Finally, append to the JNA library path... + appendJnaLibraryPath(stateLocationNativePlatformDir.getAbsolutePath()); } catch (Exception e) { e.printStackTrace(System.err); throw new RuntimeException(e); } } + private void appendJnaLibraryPath(String newPath) { + // Retrieve the current value of jna.library.path + String existingPaths = System.getProperty("jna.library.path"); + + // If there's an existing path, append the new one; otherwise, use the new path as is + if (existingPaths != null && !existingPaths.isEmpty()) { + System.setProperty("jna.library.path", existingPaths + System.getProperty("path.separator") + newPath); + } else { + System.setProperty("jna.library.path", newPath); + } + + System.out.println("New 'jna.library.path': " + System.getProperty("jna.library.path")); + } + private void unzip(InputStream zipFileInputStream, String destDirectory) throws IOException { File destDir = new File(destDirectory); if (!destDir.exists()) { @@ -121,7 +134,7 @@ private void unzip(InputStream zipFileInputStream, String destDirectory) throws } zipIn.close(); } - + private void extractFile(ZipInputStream zipIn, String filePath) throws IOException { BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(filePath)); byte[] bytesIn = new byte[4096]; @@ -161,7 +174,13 @@ public Image get(Object value, int size) { return super.get(value, size); } } - + + /* + * (non-Javadoc) + * + * @see + * org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext) + */ @Override public void stop(BundleContext context) throws Exception { plugin = null; diff --git a/CIMToolPlugin/src/au/com/langdale/cimtoole/builder/ProfileBuildlets.java b/CIMToolPlugin/src/au/com/langdale/cimtoole/builder/ProfileBuildlets.java index da041e6f..1bbe4e62 100644 --- a/CIMToolPlugin/src/au/com/langdale/cimtoole/builder/ProfileBuildlets.java +++ b/CIMToolPlugin/src/au/com/langdale/cimtoole/builder/ProfileBuildlets.java @@ -4,7 +4,6 @@ */ package au.com.langdale.cimtoole.builder; -import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.util.Collection; @@ -24,6 +23,8 @@ import org.joda.time.DateTimeZone; import org.xml.sax.SAXException; +import com.hp.hpl.jena.vocabulary.RDF; + import au.com.langdale.cimtoole.CIMToolPlugin; import au.com.langdale.cimtoole.project.Cache; import au.com.langdale.cimtoole.project.Info; @@ -31,10 +32,10 @@ import au.com.langdale.cimtoole.registries.ProfileBuildletConfigUtils; import au.com.langdale.cimtoole.registries.ProfileBuildletRegistry; import au.com.langdale.jena.OntModelProvider; +import au.com.langdale.kena.Format; import au.com.langdale.kena.OntModel; import au.com.langdale.kena.Resource; import au.com.langdale.kena.ResourceFactory; -import au.com.langdale.kena.Format; import au.com.langdale.profiles.MESSAGE; import au.com.langdale.profiles.OWLGenerator; import au.com.langdale.profiles.ProfileModel; @@ -44,8 +45,6 @@ import au.com.langdale.ui.binding.BooleanModel; import au.com.langdale.workspace.ResourceOutputStream; -import com.hp.hpl.jena.vocabulary.RDF; - /** * A series of Buildlets for building profile artifacts. */ diff --git a/CIMToolPlugin/src/au/com/langdale/cimtoole/editors/ProfileEditor.java b/CIMToolPlugin/src/au/com/langdale/cimtoole/editors/ProfileEditor.java index 3c9a8319..2e481aea 100644 --- a/CIMToolPlugin/src/au/com/langdale/cimtoole/editors/ProfileEditor.java +++ b/CIMToolPlugin/src/au/com/langdale/cimtoole/editors/ProfileEditor.java @@ -50,7 +50,7 @@ protected void createPages() { addPage(new Populate("Add/Remove", this)); addPage(new Hierarchy("Restriction", this)); addPage(new Detail("Description", this)); - addPage( new Stereotype("Stereotypes", this)); + addPage(new Stereotype("Stereotypes", this)); addPage(new Summary("Profile Summary", this)); } diff --git a/CIMToolPlugin/src/au/com/langdale/cimtoole/project/Task.java b/CIMToolPlugin/src/au/com/langdale/cimtoole/project/Task.java index 35b5f03f..3d6b7ab5 100644 --- a/CIMToolPlugin/src/au/com/langdale/cimtoole/project/Task.java +++ b/CIMToolPlugin/src/au/com/langdale/cimtoole/project/Task.java @@ -61,9 +61,9 @@ import au.com.langdale.validation.ValidatorUtil; import au.com.langdale.workspace.ResourceOutputStream; import au.com.langdale.xmi.CIMInterpreter; -import au.com.langdale.xmi.EAProjectExtractor; -import au.com.langdale.xmi.EAProjectExtractorException; -import au.com.langdale.xmi.EAProjectExtractorFactory; +import au.com.langdale.xmi.EAProjectParser; +import au.com.langdale.xmi.EAProjectParserException; +import au.com.langdale.xmi.EAProjectParserFactory; import au.com.langdale.xmi.UML; import au.com.langdale.xmi.XMIParser; @@ -313,17 +313,17 @@ private static OntModel parseXMI(IFile file) throws CoreException { } private static OntModel parseEAProject(IFile file) throws CoreException { - EAProjectExtractor extractor; + EAProjectParser parser; try { - extractor = EAProjectExtractorFactory.createExtractor(file.getLocation().toFile()); - extractor.run(); - } catch (EAProjectExtractorException e) { + parser = EAProjectParserFactory.createParser(file.getLocation().toFile()); + parser.parse(); + } catch (EAProjectParserException e) { throw error("Can't access EA project", e); } - return interpretSchema(extractor.getModel(), file); + return interpretSchema(parser.getModel(), file); } - private static OntModel interpretSchema(OntModel raw, IFile file) throws CoreException { + private static OntModel interpretSchema(OntModel raw, IFile file) throws CoreException { String base = getProperty(file, SCHEMA_NAMESPACE); if (base == null) { if (file.getName().toLowerCase().startsWith("cim")) diff --git a/CIMToolPlugin/src/au/com/langdale/cimtoole/views/ProjectModelFollower.java b/CIMToolPlugin/src/au/com/langdale/cimtoole/views/ProjectModelFollower.java index b1d70572..8ef95583 100644 --- a/CIMToolPlugin/src/au/com/langdale/cimtoole/views/ProjectModelFollower.java +++ b/CIMToolPlugin/src/au/com/langdale/cimtoole/views/ProjectModelFollower.java @@ -1,12 +1,19 @@ package au.com.langdale.cimtoole.views; +import java.util.TreeMap; + import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; +import com.hp.hpl.jena.vocabulary.OWL2; +import com.hp.hpl.jena.vocabulary.RDF; + import au.com.langdale.cimtoole.project.Cache.CacheListener; import au.com.langdale.cimtoole.project.Info; import au.com.langdale.cimtoole.project.ModelMinder; import au.com.langdale.kena.OntModel; +import au.com.langdale.kena.OntResource; +import au.com.langdale.kena.ResIterator; public abstract class ProjectModelFollower extends SelectionFollower implements CacheListener { private ModelMinder models = new ModelMinder(this); diff --git a/CIMToolPlugin/src/au/com/langdale/cimtoole/wizards/ImportSchema.java b/CIMToolPlugin/src/au/com/langdale/cimtoole/wizards/ImportSchema.java index 76625c11..cc91456e 100644 --- a/CIMToolPlugin/src/au/com/langdale/cimtoole/wizards/ImportSchema.java +++ b/CIMToolPlugin/src/au/com/langdale/cimtoole/wizards/ImportSchema.java @@ -20,7 +20,7 @@ public void init(IWorkbench workbench, IStructuredSelection selection) { setWindowTitle("Import Schema"); setNeedsProgressMonitor(true); main.setTitle(getWindowTitle()); - main.setDescription("Import an additional schema (XMI, OWL, EAP, EAPX, QEA, QEAX, or FEAP file)."); + main.setDescription("Import an additional schema (XMI or OWL)."); main.setSelected(selection); } diff --git a/CIMToolPlugin/src/au/com/langdale/cimtoole/wizards/NewProject.java b/CIMToolPlugin/src/au/com/langdale/cimtoole/wizards/NewProject.java index 19834f4a..1870e32e 100644 --- a/CIMToolPlugin/src/au/com/langdale/cimtoole/wizards/NewProject.java +++ b/CIMToolPlugin/src/au/com/langdale/cimtoole/wizards/NewProject.java @@ -52,7 +52,7 @@ public void init(IWorkbench workbench, IStructuredSelection selection) { copyrightTemplates.setSingleLineCopyrightSources(new String[]{"*.txt", "*.copyright-single-line"}); // schema.setTitle("Import Initial Schema"); - schema.setDescription("Import an XMI or OWL base schema."); + schema.setDescription("Import an XMI, OWL or EA project file as your base schema."); } @Override diff --git a/CIMToolPlugin/src/au/com/langdale/cimtoole/wizards/SchemaWizardPage.java b/CIMToolPlugin/src/au/com/langdale/cimtoole/wizards/SchemaWizardPage.java index 9a7073bc..ac68b238 100644 --- a/CIMToolPlugin/src/au/com/langdale/cimtoole/wizards/SchemaWizardPage.java +++ b/CIMToolPlugin/src/au/com/langdale/cimtoole/wizards/SchemaWizardPage.java @@ -19,13 +19,17 @@ import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.CoreException; import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.swt.widgets.Button; import au.com.langdale.cimtoole.project.Info; +import au.com.langdale.cimtoole.project.Task; import au.com.langdale.cimtoole.registries.ModelParserRegistry; -import au.com.langdale.ui.binding.RadioTextBinding; import au.com.langdale.ui.binding.TextBinding; +import au.com.langdale.ui.binding.Validator; import au.com.langdale.ui.binding.Validators; +import au.com.langdale.ui.builder.Assembly; import au.com.langdale.ui.builder.FurnishedWizardPage; import au.com.langdale.ui.builder.Template; import au.com.langdale.workspace.ResourceUI.LocalFileBinding; @@ -45,7 +49,7 @@ public SchemaWizardPage() { } private String NAMESPACE = Info.getPreference(Info.SCHEMA_NAMESPACE); - private static String[] sources = {"*.eap", "*.eapx", "*.qea", "*.qeax", "*.feap", "*.xmi", "*.owl"}; + private static String[] sources = {"*.xmi;*.owl;*.eap;*.eapx;*.feap;*.qea;*.qeax", "*.xmi", "*.owl", "*.eap", "*.eapx", "*.feap", "*.qea", "*.qeax"}; private IFile file; boolean importing; @@ -53,12 +57,57 @@ public SchemaWizardPage() { private TextBinding source = new TextBinding(Validators.OPTIONAL_EXTANT_FILE); private LocalFileBinding filename; private RadioTextBinding namespace = new RadioTextBinding(Validators.NAMESPACE, NAMESPACE); - + + private class RadioTextBinding extends TextBinding { + + private Button[] radios = new Button[0]; + private String[] values = new String[0]; + + public RadioTextBinding(Validator validator, String initial) { + super(validator, initial); + } + + public void bind(String name, String[] nameValues, Assembly plumbing) { + bind(name, plumbing, null); + radios = new Button[nameValues.length/2]; + values = new String[nameValues.length/2]; + for(int ix = 0; ix + 1 < nameValues.length; ix += 2) { + radios[ix/2] = plumbing.getButton(nameValues[ix]); + values[ix/2] = nameValues[ix+1]; + } + } + + @Override + protected String createSuggestion() { + for(int ix = 0; ix < radios.length; ix++) { + if( radios[ix].getSelection()) + return values[ix]; + } + return null; + } + + public void setExistingSchemaNSPreset(String namespace) { + if (namespace!= null && !namespace.equals(values[3])) { + values[3] = namespace; + refresh(); + } + } + + @Override + public void refresh() { + super.refresh(); + for(int ix = 0; ix < radios.length; ix++) { + radios[ix].setSelection(values[ix].equals(getValue())); + } + } + + } + private String[] presets = new String[] { - "cim15", "http://iec.ch/TC57/2010/CIM-schema-cim15#", "cim16", "http://iec.ch/TC57/2012/CIM-schema-cim16#", "cim17", "http://iec.ch/TC57/CIM100#", "cim18", "http://iec.ch/TC57/CIM101#", + "existing", "", "preset", NAMESPACE }; @@ -95,10 +144,10 @@ protected Template define() { return Grid( Group(FileField("source", "File to import:", sources)), Group( - RadioButton("cim15", "CIM 15 (2010)"), RadioButton("cim16", "CIM 16 (2012)"), RadioButton("cim17", "CIM 17 (CIM100)"), RadioButton("cim18", "CIM 18 (CIM101)"), + RadioButton("existing", "Current Schema NS"), RadioButton("preset", "Preference*")), Group(Label("Namespace URI:"), Field("namespace")), Group(Label("Project")), @@ -111,8 +160,18 @@ protected Template define() { @Override protected void addBindings() { - if( ! expectNewProject ) + if( ! expectNewProject ) { projects.bind("projects", this); + if (projects.getProject() != null) { + String ns; + try { + ns = Task.getSchemaNamespace(projects.getProject()); + presets[7] = ns; + } catch (CoreException e) { + e.printStackTrace(); + } + } + } source.bind("source", this); filename.bind("filename", this, source); namespace.bind("namespace", presets, this); @@ -121,10 +180,12 @@ protected void addBindings() { @Override public String validate() { if( source.getText().length() == 0) - if(expectNewProject) + if(expectNewProject) { return null; - else + } else { + populateCurrentSchemaNS(projects.getProject()); return "A schema XMI, OWL, EA Project or other valid schema file is required"; + } IProject project = expectNewProject? newProject: projects.getProject(); file = filename.getFile(Info.getSchemaFolder(project)); @@ -133,18 +194,32 @@ public String validate() { boolean exists = file.exists(); getButton("replace").setEnabled(exists); - if( exists && ! getButton("replace").getSelection()) + populateCurrentSchemaNS(project); + if( exists && ! getButton("replace").getSelection()) { return "A schema named " + filename.getText() + " already exists. " + "Check option to replace."; + } String check = null; - if( source.getText().endsWith(".eap") || source.getText().endsWith(".eapx")) { + if( source.getText().toLowerCase().endsWith(".eap") || source.getText().toLowerCase().endsWith(".eapx")) { check = Info.checkValidEAProject(new File(source.getText())); } if( check != null) return check; return null; } + + private void populateCurrentSchemaNS(IProject project) { + try { + String existingSchemaNamespace = Task.getSchemaNamespace(project); + if (namespace.radios[3].getSelection()) { + namespace.setText(existingSchemaNamespace); + } + namespace.setExistingSchemaNSPreset(existingSchemaNamespace); + } catch (CoreException e) { + namespace.setExistingSchemaNSPreset(""); + } + } }; } diff --git a/CIMToolPlugin/src/au/com/langdale/jena/OntModelAdapters.java b/CIMToolPlugin/src/au/com/langdale/jena/OntModelAdapters.java index b6c48bf5..29e8f572 100644 --- a/CIMToolPlugin/src/au/com/langdale/jena/OntModelAdapters.java +++ b/CIMToolPlugin/src/au/com/langdale/jena/OntModelAdapters.java @@ -72,6 +72,7 @@ private static class Annotation extends AdapterBase { private static final List NON_EDITABLE_IDENT = new ArrayList(); private static final List EDITABLE_CLASS_IDENT = new ArrayList(); private static final List EDITABLE_ASSOCIATION_IDENT = new ArrayList(); + private static final List EDITABLE_ROOT_IDENT = new ArrayList(); static { /** @@ -102,6 +103,9 @@ private static class Annotation extends AdapterBase { /** Stereotypes editable only for associations in the tree. */ EDITABLE_ASSOCIATION_IDENT.add(UML.byreference.getURI()); + + /** Stereotypes editable for the top-level "Root" of the entire profile (note this "root of the profile" element does not exist in the UML). */ + EDITABLE_ROOT_IDENT.add(UML.hideOnDiagrams.getURI()); } public Annotation(FrontsNode ident, FrontsNode prop, String comment, OntModelProvider context) { @@ -137,7 +141,7 @@ public boolean isEditable() { if((subject == null) || NON_EDITABLE_IDENT.contains(ident.asNode().getURI()) || isNonStandardStereotype || // ((subject != null) && // // Indicates it is the profile envelope that is selected...nothing is editable - (!subject.isClass() && !subject.isDatatype()) || + (!subject.isClass() && !subject.isDatatype() && !EDITABLE_ROOT_IDENT.contains(ident.asNode().getURI())) || // A subject that is a datatype indicates that a attribute of type primitive is currently selected... (subject.isDatatype() && (EDITABLE_CLASS_IDENT.contains(ident.asNode().getURI()) || EDITABLE_ASSOCIATION_IDENT.contains(ident.asNode().getURI()))) || // // This is relevant for a top-level class that is selected... diff --git a/CIMToolProduct/CIMTool.product b/CIMToolProduct/CIMTool.product index 09d80689..6660c056 100644 --- a/CIMToolProduct/CIMTool.product +++ b/CIMToolProduct/CIMTool.product @@ -1,7 +1,7 @@ - + @@ -14,8 +14,6 @@ - - -Xms40m -Xmx4G -XstartOnFirstThread -Dorg.eclipse.swt.internal.carbon.smallFonts @@ -45,6 +43,7 @@ + org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-20 @@ -91,6 +90,16 @@ See the GNU Lesser General Public License for more details. + + + + + + + + + + @@ -283,7 +292,6 @@ See the GNU Lesser General Public License for more details. - diff --git a/CIMToolProduct/META-INF/MANIFEST.MF b/CIMToolProduct/META-INF/MANIFEST.MF index 78881f15..cee5eb5c 100644 --- a/CIMToolProduct/META-INF/MANIFEST.MF +++ b/CIMToolProduct/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: CIMToolEnvironment Bundle-SymbolicName: au.com.langdale.cimtool.product;singleton:=true -Bundle-Version: 2.1.0 +Bundle-Version: 2.2.0 Bundle-ClassPath: CIMToolProduct Bundle-Vendor: Langdale Consultants Automatic-Module-Name: au.com.langdale.cimtool.product diff --git a/CIMToolProduct/plugin.xml b/CIMToolProduct/plugin.xml index 15740cac..ffde2072 100644 --- a/CIMToolProduct/plugin.xml +++ b/CIMToolProduct/plugin.xml @@ -7,7 +7,7 @@ point="org.eclipse.core.runtime.products"> + name="CIMTool 2.2.0"> @@ -30,16 +30,12 @@ + value="CIMTool 2.2.0"> - - diff --git a/CIMUtil/META-INF/MANIFEST.MF b/CIMUtil/META-INF/MANIFEST.MF index 3e3a22fe..30c1fb70 100644 --- a/CIMUtil/META-INF/MANIFEST.MF +++ b/CIMUtil/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: CIMUtil Bundle-SymbolicName: au.com.langdale.cimutil -Bundle-Version: 2.1.0 +Bundle-Version: 2.2.0 Bundle-RequiredExecutionEnvironment: JavaSE-20 Require-Bundle: au.com.langdale.kena Bundle-ClassPath: cimutil.jar, diff --git a/CIMUtil/src/au/com/langdale/profiles/ProfileSerializer.java b/CIMUtil/src/au/com/langdale/profiles/ProfileSerializer.java index cd793a5d..b0a82789 100644 --- a/CIMUtil/src/au/com/langdale/profiles/ProfileSerializer.java +++ b/CIMUtil/src/au/com/langdale/profiles/ProfileSerializer.java @@ -40,6 +40,7 @@ import au.com.langdale.jena.TreeModelBase.Node; import au.com.langdale.kena.OntResource; import au.com.langdale.kena.ResIterator; +import au.com.langdale.kena.Resource; import au.com.langdale.profiles.ProfileClass.PropertyInfo; import au.com.langdale.profiles.ProfileModel.CatalogNode; import au.com.langdale.profiles.ProfileModel.EnvelopeNode; @@ -101,10 +102,10 @@ public void setBaseURI(String baseURI) { } /** - * A URI that is passed as the onotologyURI attribute of the root element of - * the ontology from which the profile model was derived from. This is - * generally used to establish an xml:base URI that may be necessary for - * RDF-based schema that may be generated. + * A URI that is passed as the onotologyURI attribute of the root element of the + * ontology from which the profile model was derived from. This is generally + * used to establish an xml:base URI that may be necessary for RDF-based schema + * that may be generated. */ public String getOntologyURI() { return ontologyURI; @@ -119,11 +120,14 @@ public void setOntologyURI(String ontologyURI) { } /** - * A single-line copyright notification including a year. It will be passed - * as an attribute named "coyright-single-line" to the serializer therefore - * making it available to a profile builder for use as the copyright notice - * within the generated schema if the schema builder desires a single lined - * copyright as opposed to a multi-line copyright. + * A single-line copyright template that includes an embedded ${year} variable. + * The copyright template is passed to the serializer as an attribute named + * "coyright-single-line" therefore making it available to any XSLT builder for + * use as the copyright notice within the output generated by the builder. The + * template should contain a ${year} variable within it to be substituted with + * the current year during profile serialization. This is intended for use by + * any XSLT builder that required a single lined copyright as opposed to a + * multi-line copyright. */ public String getCopyrightSingleLine() { return copyrightSingleLine; @@ -137,10 +141,12 @@ public void setCopyrightSingleLine(String copyrightSingleLine) { } /** - * A multi-line copyright notification including a year. It will be passed - * as an attribute named "coyright" to the serializer therefore making it - * available to a profile builder for use as the copyright notice within the - * generated schema. + * A multi-line copyright template that includes an embedded ${year} variable. + * The copyright template is passed to the serializer as an attribute named + * "copyright" therefore making it available to any XSLT builder for use as the + * copyright notice within the output generated by the builder. The template + * should contain a ${year} variable within it to be substituted with the + * current year during profile serialization. */ public String getCopyrightMultiLine() { return copyrightMultiLine; @@ -157,8 +163,7 @@ public void setCopyrightMultiLine(String copyright) { * Install a stylesheet to transform the abstract message definition to a * schema. */ - public void setStyleSheet(InputStream s, String base) - throws TransformerConfigurationException { + public void setStyleSheet(InputStream s, String base) throws TransformerConfigurationException { templates.clear(); addStyleSheet(s, base); } @@ -166,27 +171,24 @@ public void setStyleSheet(InputStream s, String base) /** * Install a stylesheet to apply after any previously installed stylesheets. */ - public void addStyleSheet(InputStream s, String base) - throws TransformerConfigurationException { + public void addStyleSheet(InputStream s, String base) throws TransformerConfigurationException { templates.add(factory.newTemplates(new StreamSource(s, base))); } /** * Install a stylesheet from the standard set. Use null for no stylesheet. * - * When the name is null it indicates that no stylesheets are to be applied. - * In this scenario the output of a call to the ProfileSerializer's write() - * method will simply be the output of the CIMTool's internal message model - * as a formatted XML document. Therefore, any existing templates are - * "cleared" and will apply only the "indent-xml.xsl" stylesheet to format - * the XML when written. This stylesheet is for internal purposes only. + * When the name is null it indicates that no stylesheets are to be applied. In + * this scenario the output of a call to the ProfileSerializer's write() method + * will simply be the output of CIMTool's internal message model as a formatted + * XML document. Therefore, any existing templates are "cleared" and only the + * "indent-xml.xsl" stylesheet will be applied in order to format the XML when + * written out. This stylesheet is for internal purposes only. */ - public void setStyleSheet(String name) - throws TransformerConfigurationException { + public void setStyleSheet(String name) throws TransformerConfigurationException { if (name == null) { templates.clear(); - setStyleSheet(getClass().getResourceAsStream("indent-xml.xsl"), - XSDGEN); + setStyleSheet(getClass().getResourceAsStream("indent-xml.xsl"), XSDGEN); } else { setStyleSheet(getClass().getResourceAsStream(name + ".xsl"), XSDGEN); } @@ -195,22 +197,20 @@ public void setStyleSheet(String name) /** * Install a stylesheet to apply after any previously installed stylesheets. */ - public void addStyleSheet(String name) - throws TransformerConfigurationException { + public void addStyleSheet(String name) throws TransformerConfigurationException { if (name != null) addStyleSheet(getClass().getResourceAsStream(name + ".xsl"), ""); } /** - * Install a standard SAX ErrorHandler for errors in the stylesheet. This - * will be wrapped in the ErrorListener required by the transform framework. + * Install a standard SAX ErrorHandler for errors in the stylesheet. This will + * be wrapped in the ErrorListener required by the transform framework. */ @Override public void setErrorHandler(final ErrorHandler errors) { ErrorListener listener = new ErrorListener() { - public void error(TransformerException ex) - throws TransformerException { + public void error(TransformerException ex) throws TransformerException { try { errors.error(convert(ex)); } catch (SAXException e) { @@ -218,8 +218,7 @@ public void error(TransformerException ex) } } - public void warning(TransformerException ex) - throws TransformerException { + public void warning(TransformerException ex) throws TransformerException { try { errors.warning(convert(ex)); } catch (SAXException e) { @@ -227,8 +226,7 @@ public void warning(TransformerException ex) } } - public void fatalError(TransformerException ex) - throws TransformerException { + public void fatalError(TransformerException ex) throws TransformerException { try { errors.fatalError(convert(ex)); } catch (SAXException e) { @@ -243,8 +241,7 @@ private SAXParseException convert(TransformerException ex) { SourceLocator loc = ex.getLocator(); if (loc != null) - return new SAXParseException(ex.getMessage(), - loc.getPublicId(), loc.getSystemId(), + return new SAXParseException(ex.getMessage(), loc.getPublicId(), loc.getSystemId(), loc.getLineNumber(), loc.getColumnNumber()); return new SAXParseException(ex.getMessage(), "", "", 0, 0); @@ -268,8 +265,7 @@ public void write(OutputStream ostream) throws TransformerException { if (!templates.isEmpty()) { tx = new Transformer[templates.size()]; for (int ix = 0; ix < templates.size(); ix++) { - Transformer ti = ((Templates) templates.get(ix)) - .newTransformer(); + Transformer ti = ((Templates) templates.get(ix)).newTransformer(); ti.setParameter("baseURI", baseURI); ti.setParameter("ontologyURI", ontologyURI); ti.setParameter("version", version); @@ -345,6 +341,7 @@ private void emitChildren(Node node) throws SAXException { private void emit(CatalogNode node) throws SAXException { Element elem = new Element("Catalog", MESSAGE.NS); + elem.set("hideInDiagrams", (isHidden(node.getSubject()) ? "true" : "false")); elem.set("ontologyURI", ontologyURI); elem.set("baseURI", baseURI); elem.set("xmlns:m", baseURI); @@ -363,6 +360,7 @@ private void emit(CatalogNode node) throws SAXException { private void emit(EnvelopeNode node) throws SAXException { Element elem = new Element("Message", MESSAGE.NS); elem.set("name", node.getName()); + elem.set("hideInDiagrams", (isHidden(node.getSubject()) ? "true" : "false")); emitChildren(node); elem.close(); } @@ -376,6 +374,7 @@ private void emit(SuperTypeNode node) throws SAXException { private void emit(SubTypeNode node) throws SAXException { Element elem = select(node); + elem.set("hideInDiagrams", (node.getSubject() != null && isHidden(node.getSubject()) ? "true" : "false")); elem.set("name", node.getName()); elem.set("minOccurs", "1"); elem.set("maxOccurs", "1"); @@ -397,8 +396,7 @@ private Element select(SubTypeNode node) throws SAXException { if (anon) elem = new Element("Complex"); else { - if (node.getParent() instanceof ElementNode - && ((ElementNode) node.getParent()).isReference()) + if (node.getParent() instanceof ElementNode && ((ElementNode) node.getParent()).isReference()) elem = new Element("Reference"); else elem = new Element("Instance"); @@ -418,8 +416,7 @@ private void emit(ElementNode node) throws SAXException { if (node.isDatatype()) { OntResource range = node.getBaseProperty().getRange(); if (range == null) - range = model.getOntModel() - .createResource(XSD.xstring.asNode()); + range = model.getOntModel().createResource(XSD.xstring.asNode()); if (range.getNameSpace().equals(xsd)) { elem = new Element("Simple"); } else { @@ -427,45 +424,52 @@ private void emit(ElementNode node) throws SAXException { elem.set("type", range.getLocalName()); deferred.add(range); } + elem.set("hideInDiagrams", (node.getSubject() != null && isHidden(node.getSubject()) ? "true" : "false")); elem.set("dataType", range.getURI()); elem.set("xstype", xstype(range)); emit(node, elem); } else { - int size = node.getChildren().size(); if (size == 0) { OntResource range = node.getBaseProperty().getRange(); elem = new Element("Reference"); + elem.set("hideInDiagrams", (node.getSubject() != null && isHidden(node.getSubject()) ? "true" : "false")); if (range != null && range.isURIResource()) { - elem.set("baseClass", range.getURI()); + elem.set("baseClass", range.getURI()); elem.set("type", range.getLocalName()); } - emit(node, elem); - + emit(node, elem, true); + OntResource inverse = (node.getBaseProperty() != null ? node.getBaseProperty().getInverse() : null); if ((inverse != null) && (node.getProfile().getPropertyInfo(inverse) != null)) { - elem.close(); // First, close "Reference" ... + elem.close(); // First, close "Reference" ... elem = new Element("InverseReference"); + elem.set("hideInDiagrams", (node.getSubject() != null && isHidden(node.getSubject()) ? "true" : "false")); emitInverse(node, elem); } } else if (size == 1) { SubTypeNode child = (SubTypeNode) node.getChildren().get(0); elem = select(child); - emit(node, elem); + elem.set("hideInDiagrams", (node.getSubject() != null && isHidden(node.getSubject()) ? "true" : "false")); + emit(node, elem, (!child.getSubject().isAnon() && !child.isEnumerated())); if (child.getSubject().isAnon()) { emitChildren(child); } else if (!child.isEnumerated()) { - // If child is not an enumeration and not anonymous it indicates it is an Instance - // or Reference element and an InverseInstance or InverseReference must be created... + // If child is not an enumeration and not anonymous it indicates it is an + // Instance + // or Reference element and an InverseInstance or InverseReference must be + // created... OntResource inverse = (node.getBaseProperty() != null ? node.getBaseProperty().getInverse() : null); if ((inverse != null) && (node.getProfile().getPropertyInfo(inverse) != null)) { elem.close(); // First, close out the "Reference" or "Instance" element... - if (child.getParent() instanceof ElementNode && ((ElementNode) child.getParent()).isReference()) { + if (child.getParent() instanceof ElementNode + && ((ElementNode) child.getParent()).isReference()) { elem = new Element("InverseReference"); } else { elem = new Element("InverseInstance"); } + elem.set("hideInDiagrams", (node.getSubject() != null && isHidden(node.getSubject()) ? "true" : "false")); emitInverse(node, elem); } } @@ -480,78 +484,88 @@ private void emit(ElementNode node) throws SAXException { } private void emitInverse(ElementNode node, Element elem) throws SAXException { - OntResource inverse = (node.getBaseProperty() != null ? node - .getBaseProperty().getInverse() : null); - + OntResource inverse = (node.getBaseProperty() != null ? node.getBaseProperty().getInverse() : null); if ((inverse != null) && (node.getProfile().getPropertyInfo(inverse) != null)) { elem.set("baseClass", inverse.getRange().getURI()); + if (inverse.hasProperty(UML.id)) + elem.set("ea_guid", inverse.getString(UML.id)); elem.set("type", inverse.getRange().getLocalName()); if (inverse.getLabel() != null) elem.set("name", inverse.getLabel()); if (inverse.getURI() != null) elem.set("baseProperty", inverse.getURI()); - + if (inverse.getDomain() != null) + elem.set("basePropertyClass", inverse.getDomain().getURI()); + PropertyInfo info = node.getProfile().getPropertyInfo(inverse); if (!info.getProperty().isDatatypeProperty()) { int min = info.getMinCardinality(); int max = info.getMaxCardinality(); elem.set("minOccurs", ProfileModel.cardString(min)); - elem.set("maxOccurs", - ProfileModel.cardString(max, "unbounded")); + elem.set("maxOccurs", ProfileModel.cardString(max, "unbounded")); } + elem.set("inverseBasePropertyClass", node.getBaseClass().getURI()); elem.set("inverseBaseProperty", node.getBaseProperty().getURI()); - + emitComment(info.getProperty().getComment(null)); emitStereotypes(info.getProperty()); } } - + private void emit(ElementNode node, Element elem) throws SAXException { + emit(node, elem, false); + } + + private void emit(ElementNode node, Element elem, boolean includeInverseBaseClass) throws SAXException { elem.set("name", node.getName()); + if (node.getBase().hasProperty(UML.id)) + elem.set("ea_guid", node.getBase().getString(UML.id)); elem.set("baseProperty", node.getBaseProperty().getURI()); + if (node.getBaseProperty().getDomain() != null) { + elem.set("basePropertyClass", node.getBaseProperty().getDomain().getURI()); + } elem.set("minOccurs", ProfileModel.cardString(node.getMinCardinality())); - elem.set("maxOccurs", - ProfileModel.cardString(node.getMaxCardinality(), "unbounded")); - - OntResource inverse = (node.getBaseProperty() != null ? node - .getBaseProperty().getInverse() : null); + elem.set("maxOccurs", ProfileModel.cardString(node.getMaxCardinality(), "unbounded")); + + if (includeInverseBaseClass) { + OntResource inverseBaseClass = (node.getParent() != null ? node.getParent().getBase() : null); + if ((inverseBaseClass != null) && (inverseBaseClass.getURI() != null)) { + elem.set("inverseBasePropertyClass", inverseBaseClass.getURI()); + } + } + + OntResource inverse = (node.getBaseProperty() != null ? node.getBaseProperty().getInverse() : null); if ((inverse != null) && (inverse.getURI() != null)) { elem.set("inverseBaseProperty", inverse.getURI()); } - + emitComment(node.getBaseProperty().getComment(null)); emitNote(node); } private void emitChoice(ElementNode node, Element elem) throws SAXException { elem.set("name", node.getName()); + elem.set("hideInDiagrams", (node.getSubject() != null && isHidden(node.getSubject()) ? "true" : "false")); elem.set("baseProperty", node.getBaseProperty().getURI()); elem.set("minOccurs", ProfileModel.cardString(node.getMinCardinality())); - elem.set("maxOccurs", - ProfileModel.cardString(node.getMaxCardinality(), "unbounded")); - // - // We obtain the topmost class in the hierarchy via the call to - // node.getBaseClass(). - // We then loop through all of the child nodes of the choice and locate - // the one that - // matches the base class associated with the Choice property. This is - // the one we must - // use when generating the 'inheritanceBaseClass' and - // 'inheritanceBaseType' attributes - // for the Choice. These two attributes indicate the URI of the topmost - // base class in - // the hierarchy and the name of that class as specified in the context - // of the profile - // defined. - // + elem.set("maxOccurs", ProfileModel.cardString(node.getMaxCardinality(), "unbounded")); + /** + * We obtain the topmost class in the hierarchy via the call to + * node.getBaseClass(). We then loop through all of the child nodes of the + * choice and locate the one that matches the base class associated with the + * Choice property. This is the one we must use when generating the + * 'inheritanceBaseClass' and 'inheritanceBaseType' attributes for the Choice. + * These two attributes indicate the URI of the topmost base class in the + * hierarchy and the name of that class as specified in the context of the + * profile defined. + */ OntResource baseClass = node.getBaseClass(); Iterator it = node.iterator(); while (it.hasNext()) { Node childNode = (Node) it.next(); if (childNode.getBase().equals(baseClass)) { - elem.set("inheritanceBaseClass", childNode.getSubject() - .getURI()); + elem.set("inheritanceBaseClass", childNode.getSubject().getURI()); elem.set("inheritanceBaseType", childNode.getName()); break; } @@ -583,22 +597,38 @@ private void emitNote(Node node) throws SAXException { emitStereotypes(node.getSubject()); } + private boolean isHidden(OntResource subject) throws SAXException { + ResIterator it = subject.listProperties(UML.hasStereotype); + boolean isHidden = false; + while (it.hasNext()) { + OntResource stereo = it.nextResource(); + if (!stereo.isURIResource()) + continue; + if ((UML.hideOnDiagrams.getURI().equals(stereo.getURI())) || (stereo.getLocalName() != null && stereo.getLocalName().equals(UML.hideOnDiagrams.getLocalName()))) + return true; + } + return isHidden; + } + private void emitStereotypes(OntResource subject) throws SAXException { ResIterator it = subject.listProperties(UML.hasStereotype); while (it.hasNext()) { - emitStereotype(it.nextResource()); + OntResource stereotype = it.nextResource(); + emitStereotype(stereotype); } } private void emitStereotype(OntResource stereo) throws SAXException { if (!stereo.isURIResource()) return; + if ((UML.hideOnDiagrams.getURI().equals(stereo.getURI())) || (stereo.getLocalName() != null && stereo.getLocalName().equals(UML.hideOnDiagrams.getLocalName()))) + return; Element elem = new Element("Stereotype"); if (stereo.getLabel() != null) { elem.set("label", stereo.getLabel()); } else { if (stereo.getLocalName() != null) - elem.set("label", stereo.getLocalName()); + elem.set("label", stereo.getLocalName()); else elem.set("label", ""); } @@ -622,6 +652,8 @@ private void emitPackage(OntResource aPackage) throws SAXException { if (aPackage != null) { Element elem = new Element("Package"); elem.set("name", aPackage.getLabel()); + if (aPackage.hasProperty(UML.id)) + elem.set("ea_guid", aPackage.getString(UML.id)); elem.set("basePackage", aPackage.getURI()); emitComment(aPackage.getComment(null)); emitStereotypes(aPackage); @@ -648,14 +680,16 @@ else if (node.hasStereotype(UML.compound)) else elem = new Element("ComplexType"); elem.set("name", node.getName()); + elem.set("hideInDiagrams", (node.getSubject() != null && isHidden(node.getSubject()) ? "true" : "false")); + if (node.getBaseClass().hasProperty(UML.id)) + elem.set("ea_guid", node.getBaseClass().getString(UML.id)); elem.set("baseClass", node.getBaseClass().getURI()); elem.set("package", node.getPackageName()); if (node.getPackage() != null) { elem.set("packageURI", node.getPackage().getURI()); } elem.set("minOccurs", ProfileModel.cardString(node.getMinCardinality())); - elem.set("maxOccurs", - ProfileModel.cardString(node.getMaxCardinality(), "unbounded")); + elem.set("maxOccurs", ProfileModel.cardString(node.getMaxCardinality(), "unbounded")); emitComment(node.getBaseClass().getComment(null)); emitNote(node); @@ -666,6 +700,9 @@ else if (node.hasStereotype(UML.compound)) private void emit(MessageNode node) throws SAXException { Element elem = new Element("Root"); elem.set("name", node.getName()); + elem.set("hideInDiagrams", (node.getSubject() != null && isHidden(node.getSubject()) ? "true" : "false")); + if (node.getBaseClass().hasProperty(UML.id)) + elem.set("ea_guid", node.getBaseClass().getString(UML.id)); elem.set("baseClass", node.getBaseClass().getURI()); emitComment(node.getBaseClass().getComment(null)); @@ -677,11 +714,12 @@ private void emit(MessageNode node) throws SAXException { private void emit(OntResource type) throws SAXException { Element elem = new Element("SimpleType"); - elem.set("dataType", type.getURI()); elem.set("name", type.getLocalName()); + if (type.hasProperty(UML.id)) + elem.set("ea_guid", type.getString(UML.id)); OntResource defin = type.getResource(RDFS.isDefinedBy); - if(defin != null){ + if (defin != null) { elem.set("package", defin.getLabel()); elem.set("packageURI", defin.getURI()); } @@ -695,7 +733,10 @@ private void emit(OntResource type) throws SAXException { private void emit(EnumValueNode node) throws SAXException { OntResource value = node.getSubject(); Element elem = new Element("EnumeratedValue"); + elem.set("hideInDiagrams", (node.getSubject() != null && isHidden(node.getSubject()) ? "true" : "false")); elem.set("name", node.getName()); + if (node.getBase().hasProperty(UML.id)) + elem.set("ea_guid", node.getBase().getString(UML.id)); elem.set("baseResource", node.getBase().getURI()); emitComment(value.getComment(null)); elem.close(); diff --git a/CIMUtil/src/au/com/langdale/xmi/AbstractEAProjectDBExtractor.java b/CIMUtil/src/au/com/langdale/xmi/AbstractEAProjectDBExtractor.java deleted file mode 100644 index a2aff6fa..00000000 --- a/CIMUtil/src/au/com/langdale/xmi/AbstractEAProjectDBExtractor.java +++ /dev/null @@ -1,472 +0,0 @@ -/* - * This software is Copyright 2005,2006,2007,2008 Langdale Consultants. - * Langdale Consultants can be contacted at: http://www.langdale.com.au - */ -package au.com.langdale.xmi; - -import java.io.File; -import java.sql.Connection; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.sql.Statement; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; - -import au.com.langdale.kena.OntResource; - -public abstract class AbstractEAProjectDBExtractor extends AbstractEAProjectExtractor { - - // Column name constants corresponding to the EA project file SQLite DB. - private static final String COL_CLIENT = "Client"; - private static final String COL_DESCRIPTION = "Description"; - private static final String COL_PARENT_ID = "Parent_ID"; - private static final String COL_NOTE = "Note"; - private static final String COL_OBJECT_TYPE = "Object_Type"; - private static final String COL_PACKAGE_ID = "Package_ID"; - private static final String COL_VALUE = "Value"; - private static final String COL_PROPERTY = "Property"; - private static final String COL_SOURCE_ROLE = "SourceRole"; - private static final String COL_DEST_ROLE = "DestRole"; - private static final String COL_SOURCE_CARD = "SourceCard"; - private static final String COL_DEST_CARD = "DestCard"; - private static final String COL_SOURCE_ROLE_NOTE = "SourceRoleNote"; - private static final String COL_END_OBJECT_ID = "End_Object_ID"; - private static final String COL_START_OBJECT_ID = "Start_Object_ID"; - private static final String COL_DEST_ROLE_NOTE = "DestRoleNote"; - private static final String COL_DEST_IS_AGGREGATE = "DestIsAggregate"; - private static final String COL_SOURCE_IS_AGGREGATE = "SourceIsAggregate"; - private static final String COL_CONNECTOR_TYPE = "Connector_Type"; - private static final String COL_EA_GUID = "ea_guid"; - private static final String COL_DEFAULT = "Default"; - private static final String COL_NAME = "Name"; - private static final String COL_NOTES = "Notes"; - private static final String COL_OBJECT_ID = "Object_ID"; - - public AbstractEAProjectDBExtractor(File file) { - super(file); - } - - protected abstract void dbInit() throws SQLException; - - protected abstract Connection getConnection() throws SQLException; - - public void run() throws EAProjectExtractorException { - // NOTE: Connection and Statement are AutoClosable. - // Don't forget to close them both in order to avoid leaks. - try { - // We call dbInit for those databases that may need to perform - // JDBC or database related initialization such as registering - // a JDBC driver... - dbInit(); - // - loadStereotypesCache(); - loadTaggedValuesCache(); - gatherPackageIDs(); - extractPackages(); - extractClasses(); - extractAssociations(); - extractAttributes(); - } catch (EAProjectExtractorException eapException) { - eapException.printStackTrace(System.err); - throw eapException; - } catch (SQLException sqlException) { - sqlException.printStackTrace(System.err); - throw new EAProjectExtractorException("Unable to import the EA project file: " + file.getAbsolutePath(), sqlException); - } - } - - protected void loadStereotypesCache() throws EAProjectExtractorException { - stereotypesMap = new HashMap>(); - Connection connection = null; - Statement statement = null; - ResultSet rs = null; - try { - connection = getConnection(); - statement = connection.createStatement(); - rs = statement.executeQuery( - "select * from t_xref where Name = 'Stereotypes'"); - while (rs.next()) { - String eaGUID = rs.getString(COL_CLIENT); - if (stereotypesMap.containsKey(eaGUID)) { - List stereotypesList = stereotypesMap.get(eaGUID); - stereotypesList.add(rs.getString(COL_DESCRIPTION)); - } else { - List stereotypesList = new ArrayList(); - stereotypesList.add(rs.getString(COL_DESCRIPTION)); - stereotypesMap.put(eaGUID, stereotypesList); - } - } - } catch (SQLException sqlException) { - throw new EAProjectExtractorException("Unable to import the EA project file: " + file.getAbsolutePath(), sqlException); - } finally { - if (rs != null) { - try { - rs.close(); - } catch (SQLException e) { - e.printStackTrace(); - } - } - if (statement != null) { - try { - statement.close(); - } catch (SQLException e) { - e.printStackTrace(); - } - } - if (connection != null) { - try { - connection.close(); - } catch (SQLException e) { - e.printStackTrace(); - } - } - } - } - - protected void loadTaggedValuesCache() throws EAProjectExtractorException { - taggedValuesMap = new HashMap>(); - Connection connection = null; - Statement statement = null; - ResultSet rs = null; - try { - connection = getConnection(); - statement = connection.createStatement(); - rs = statement.executeQuery("select * from t_objectproperties"); - while (rs.next()) { - int objectId = rs.getInt(COL_OBJECT_ID); - if (taggedValuesMap.containsKey(objectId)) { - List taggedValuesList = taggedValuesMap.get(objectId); - taggedValuesList.add(new TaggedValue(rs.getString(COL_PROPERTY), rs.getString(COL_VALUE))); - } else { - List taggedValuesList = new ArrayList(); - taggedValuesList.add(new TaggedValue(rs.getString(COL_PROPERTY), rs.getString(COL_VALUE))); - taggedValuesMap.put(objectId, taggedValuesList); - } - } - } catch (SQLException sqlException) { - throw new EAProjectExtractorException("Unable to import the EA project file: " + file.getAbsolutePath(), sqlException); - } finally { - if (rs != null) { - try { - rs.close(); - } catch (SQLException e) { - e.printStackTrace(); - } - } - if (statement != null) { - try { - statement.close(); - } catch (SQLException e) { - e.printStackTrace(); - } - } - if (connection != null) { - try { - connection.close(); - } catch (SQLException e) { - e.printStackTrace(); - } - } - } - } - - protected void gatherPackageIDs() throws EAProjectExtractorException { - OntResource top = createGlobalPackage(); - - Connection connection = null; - Statement statement = null; - ResultSet rs = null; - try { - connection = getConnection(); - statement = connection.createStatement(); - rs = statement.executeQuery("select * from t_package order by Name"); - while (rs.next()) { - OntResource subject; - if (rs.getString(COL_NAME).equals("Model")) - subject = top; - else - subject = createIndividual(getXUID(rs), rs.getString(COL_NAME), UML.Package); - packageIDs.putID(rs.getInt(COL_PACKAGE_ID), subject); - } - } catch (SQLException sqlException) { - throw new EAProjectExtractorException("Unable to import the EA project file: " + file.getAbsolutePath(), sqlException); - } finally { - if (rs != null) { - try { - rs.close(); - } catch (SQLException e) { - e.printStackTrace(); - } - } - if (statement != null) { - try { - statement.close(); - } catch (SQLException e) { - e.printStackTrace(); - } - } - if (connection != null) { - try { - connection.close(); - } catch (SQLException e) { - e.printStackTrace(); - } - } - } - - } - - protected void extractPackages() throws EAProjectExtractorException { - Connection connection = null; - Statement statement = null; - ResultSet rs = null; - try { - connection = getConnection(); - statement = connection.createStatement(); - // For extracting packages we must perform a join to be able to pull in the - // Object_ID for the package. The Object_ID is needed to located tagged values. - rs = statement.executeQuery( - "select t_package.Package_ID AS Package_ID, t_package.Parent_ID AS Parent_ID, t_package.Notes AS Notes, t_package.ea_guid AS ea_guid, t_object.Object_ID AS Object_ID from t_package, t_object where t_package.Package_ID = t_object.Package_ID"); - while (rs.next()) { - int packageId = rs.getInt(COL_PACKAGE_ID); - String eaGUID = rs.getString(COL_EA_GUID); - OntResource subject = packageIDs.getID(packageId); - if (!subject.equals(UML.global_package)) { - int objectId = rs.getInt(COL_OBJECT_ID); - OntResource parent = packageIDs.getID(rs.getInt(COL_PARENT_ID)); - subject.addIsDefinedBy(parent == null ? UML.global_package : parent); - annotate(subject, rs.getString(COL_NOTES)); - // - addStereotypes(subject, eaGUID); - addTaggedValues(subject, objectId); - } - } - } catch (SQLException sqlException) { - throw new EAProjectExtractorException("Unable to import the EA project file: " + file.getAbsolutePath(), sqlException); - } finally { - if (rs != null) { - try { - rs.close(); - } catch (SQLException e) { - e.printStackTrace(); - } - } - if (statement != null) { - try { - statement.close(); - } catch (SQLException e) { - e.printStackTrace(); - } - } - if (connection != null) { - try { - connection.close(); - } catch (SQLException e) { - e.printStackTrace(); - } - } - } - } - - protected void extractClasses() throws EAProjectExtractorException { - Connection connection = null; - Statement statement = null; - ResultSet rs = null; - try { - connection = getConnection(); - statement = connection.createStatement(); - rs = statement.executeQuery("select * from t_object"); - while (rs.next()) { - if ("Class".equals(rs.getString(COL_OBJECT_TYPE))) { - OntResource subject = createClass(getXUID(rs), rs.getString(COL_NAME)); - int objectId = rs.getInt(COL_OBJECT_ID); - objectIDs.putID(objectId, subject); - annotate(subject, rs.getString(COL_NOTE)); - OntResource parent = packageIDs.getID(rs.getInt(COL_PACKAGE_ID)); - subject.addIsDefinedBy(parent == null ? UML.global_package : parent); - // - addStereotypes(subject, rs.getString(COL_EA_GUID)); - addTaggedValues(subject, objectId); - } - } - } catch (SQLException sqlException) { - throw new EAProjectExtractorException("Unable to import the EA project file: " + file.getAbsolutePath(), sqlException); - } finally { - if (rs != null) { - try { - rs.close(); - } catch (SQLException e) { - e.printStackTrace(); - } - } - if (statement != null) { - try { - statement.close(); - } catch (SQLException e) { - e.printStackTrace(); - } - } - if (connection != null) { - try { - connection.close(); - } catch (SQLException e) { - e.printStackTrace(); - } - } - } - } - - protected void extractAttributes() throws EAProjectExtractorException { - Connection connection = null; - Statement statement = null; - ResultSet rs = null; - try { - connection = getConnection(); - statement = connection.createStatement(); - rs = statement.executeQuery("select * from t_attribute"); - while (rs.next()) { - int objectId = rs.getInt(COL_OBJECT_ID); - OntResource id = objectIDs.getID(objectId); - if (id != null) { - String name = rs.getString(COL_NAME); - OntResource subject = createAttributeProperty(getXUID(rs), name); - subject.addDomain(id); - annotate(subject, rs.getString(COL_NOTES)); - subject.addIsDefinedBy(id.getIsDefinedBy()); - if (hasClassifier(rs)) { - int classifier = getClassifier(rs); - OntResource range = objectIDs.getID(classifier); - if (range != null) - subject.addRange(range); - else - System.out.println( - "Could not find the range of attribute " + name + ". Range ID = " + classifier); - } - String defaultValue = rs.getString(COL_DEFAULT); - if (defaultValue != null && "".equals(defaultValue)) { - subject.addProperty(UML.hasInitialValue, defaultValue); - } - // - addStereotypes(subject, rs.getString(COL_EA_GUID)); - addTaggedValues(subject, objectId); - } else - System.out.println("Could not find the domain of attribute " + rs.getString(COL_NAME) - + ". Domain ID = " + rs.getInt(COL_OBJECT_ID)); - } - } catch (SQLException sqlException) { - throw new EAProjectExtractorException("Unable to import the EA project file: " + file.getAbsolutePath(), sqlException); - } finally { - if (rs != null) { - try { - rs.close(); - } catch (SQLException e) { - e.printStackTrace(); - } - } - if (statement != null) { - try { - statement.close(); - } catch (SQLException e) { - e.printStackTrace(); - } - } - if (connection != null) { - try { - connection.close(); - } catch (SQLException e) { - e.printStackTrace(); - } - } - } - } - - protected void extractAssociations() throws EAProjectExtractorException { - Connection connection = null; - Statement statement = null; - ResultSet rs = null; - try { - connection = getConnection(); - statement = connection.createStatement(); - rs = statement.executeQuery("select * from t_connector"); - while (rs.next()) { - String type = rs.getString(COL_CONNECTOR_TYPE); - if (type.equals("Generalization") || type.equals("Association") || type.equals("Aggregation")) { - OntResource source = objectIDs.getID(rs.getInt(COL_START_OBJECT_ID)); - OntResource destin = objectIDs.getID(rs.getInt(COL_END_OBJECT_ID)); - if (source != null && destin != null) { - if (type.equals("Generalization")) { - source.addSuperClass(destin); - } else { - Role rolea = extractProperty( // - getXUID(rs), // - source, // - destin, // - rs.getString(COL_DEST_ROLE), // - rs.getString(COL_DEST_ROLE_NOTE), // - rs.getString(COL_DEST_CARD), // - rs.getInt(COL_DEST_IS_AGGREGATE), // - true); - Role roleb = extractProperty( // - getXUID(rs), // - destin, // - source, // - rs.getString(COL_SOURCE_ROLE), // - rs.getString(COL_SOURCE_ROLE_NOTE), // - rs.getString(COL_SOURCE_CARD), // - rs.getInt(COL_SOURCE_IS_AGGREGATE), // - false); - rolea.mate(roleb); - roleb.mate(rolea); - } - - // NOTE: We can and should support Stereotypes on connectors. We just need - // to determine what subject that they should be assigned to. Unsure of this. - // select Description from t_xref where Client = 'ea_guid of t_connector' and - // Name = 'Stereotypes' and Type = 'connector property'; // Stereotypes on - // connectors - } - } - } - } catch (SQLException sqlException) { - throw new EAProjectExtractorException("Unable to import the EA project file: " + file.getAbsolutePath(), sqlException); - } finally { - if (rs != null) { - try { - rs.close(); - } catch (SQLException e) { - e.printStackTrace(); - } - } - if (statement != null) { - try { - statement.close(); - } catch (SQLException e) { - e.printStackTrace(); - } - } - if (connection != null) { - try { - connection.close(); - } catch (SQLException e) { - e.printStackTrace(); - } - } - } - } - - private int getClassifier(ResultSet rs) throws SQLException { - String classifier = rs.getString("Classifier"); - return classifier != null ? Integer.parseInt(classifier) : 0; - } - - private boolean hasClassifier(ResultSet rs) throws SQLException { - return getClassifier(rs) != 0; - } - - private String getXUID(ResultSet rs) throws SQLException { - String xuid = rs.getString(COL_EA_GUID); - return "_" + xuid.substring(1, xuid.length() - 1); - } - -} diff --git a/CIMUtil/src/au/com/langdale/xmi/AbstractEAProjectDBParsor.java b/CIMUtil/src/au/com/langdale/xmi/AbstractEAProjectDBParsor.java new file mode 100644 index 00000000..a4a6a240 --- /dev/null +++ b/CIMUtil/src/au/com/langdale/xmi/AbstractEAProjectDBParsor.java @@ -0,0 +1,534 @@ +/* + * This software is Copyright 2005,2006,2007,2008 Langdale Consultants. + * Langdale Consultants can be contacted at: http://www.langdale.com.au + */ +package au.com.langdale.xmi; + +import java.io.File; +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + +import au.com.langdale.kena.OntResource; + +public abstract class AbstractEAProjectDBParsor extends AbstractEAProjectParser { + + public AbstractEAProjectDBParsor(File file) { + super(file); + } + + protected abstract void dbInit() throws EAProjectParserException; + + protected abstract Connection getConnection() throws EAProjectParserException; + + protected void loadStereotypesCache() throws EAProjectParserException { + stereotypesMap = new HashMap>(); + Connection connection = null; + Statement statement = null; + ResultSet rs = null; + try { + connection = getConnection(); + statement = connection.createStatement(); + rs = statement.executeQuery("select * from t_xref where Name = 'Stereotypes'"); + while (rs.next()) { + String eaGUID = rs.getString(COL_Client); + if (stereotypesMap.containsKey(eaGUID)) { + List stereotypesList = stereotypesMap.get(eaGUID); + stereotypesList.add(rs.getString(COL_Description)); + } else { + List stereotypesList = new ArrayList(); + stereotypesList.add(rs.getString(COL_Description)); + stereotypesMap.put(eaGUID, stereotypesList); + } + } + } catch (SQLException sqlException) { + throw new EAProjectParserException("Unable to import the EA project file: " + file.getAbsolutePath(), + sqlException); + } finally { + if (rs != null) { + try { + rs.close(); + } catch (SQLException e) { + e.printStackTrace(); + } + } + if (statement != null) { + try { + statement.close(); + } catch (SQLException e) { + e.printStackTrace(); + } + } + if (connection != null) { + try { + connection.close(); + } catch (SQLException e) { + e.printStackTrace(); + } + } + } + } + + protected void loadTaggedValuesCaches() throws EAProjectParserException { + packagesTaggedValuesMap = new HashMap>(); + classesTaggedValuesMap = new HashMap>(); + Connection connection = null; + Statement statement = null; + ResultSet rs = null; + try { + connection = getConnection(); + statement = connection.createStatement(); + + /** This query retrieves all tagged values on packages */ + rs = statement.executeQuery( + "select * from t_object o, t_objectproperties tv where (tv.Object_ID = o.Object_ID) and (o.Object_Type = 'Package' or o.Object_Type = 'Class')"); + while (rs.next()) { + if ("Package".equals(rs.getString(COL_Object_Type))) { + int packageId = rs.getInt(COL_PDATA1); + if (packagesTaggedValuesMap.containsKey(packageId)) { + List taggedValuesList = packagesTaggedValuesMap.get(packageId); + taggedValuesList.add(new TaggedValue(rs.getString(COL_Property), rs.getString(COL_Value))); + } else { + List taggedValuesList = new ArrayList(); + taggedValuesList.add(new TaggedValue(rs.getString(COL_Property), rs.getString(COL_Value))); + packagesTaggedValuesMap.put(packageId, taggedValuesList); + } + } else { + int objectId = rs.getInt(COL_Object_ID); + if (classesTaggedValuesMap.containsKey(objectId)) { + List taggedValuesList = classesTaggedValuesMap.get(objectId); + taggedValuesList.add(new TaggedValue(rs.getString(COL_Property), rs.getString(COL_Value))); + } else { + List taggedValuesList = new ArrayList(); + taggedValuesList.add(new TaggedValue(rs.getString(COL_Property), rs.getString(COL_Value))); + classesTaggedValuesMap.put(objectId, taggedValuesList); + } + } + } + } catch (SQLException sqlException) { + throw new EAProjectParserException("Unable to import the EA project file: " + file.getAbsolutePath(), + sqlException); + } finally { + if (rs != null) { + try { + rs.close(); + } catch (SQLException e) { + e.printStackTrace(); + } + } + if (statement != null) { + try { + statement.close(); + } catch (SQLException e) { + e.printStackTrace(); + } + } + if (connection != null) { + try { + connection.close(); + } catch (SQLException e) { + e.printStackTrace(); + } + } + } + + attributesTaggedValuesMap = new HashMap>(); + try { + connection = getConnection(); + statement = connection.createStatement(); + + /** This query retrieves all tagged values on attributes */ + rs = statement.executeQuery("select * from t_attribute a, t_attributetag tv where (tv.ElementID = a.ID)"); + while (rs.next()) { + int elementId = rs.getInt(COL_ElementID); + if (attributesTaggedValuesMap.containsKey(elementId)) { + List taggedValuesList = attributesTaggedValuesMap.get(elementId); + taggedValuesList.add(new TaggedValue(rs.getString(COL_Property), rs.getString(COL_Value))); + } else { + List taggedValuesList = new ArrayList(); + taggedValuesList.add(new TaggedValue(rs.getString(COL_Property), rs.getString(COL_Value))); + attributesTaggedValuesMap.put(elementId, taggedValuesList); + } + } + } catch (SQLException sqlException) { + throw new EAProjectParserException("Unable to import the EA project file: " + file.getAbsolutePath(), + sqlException); + } finally { + if (rs != null) { + try { + rs.close(); + } catch (SQLException e) { + e.printStackTrace(); + } + } + if (statement != null) { + try { + statement.close(); + } catch (SQLException e) { + e.printStackTrace(); + } + } + if (connection != null) { + try { + connection.close(); + } catch (SQLException e) { + e.printStackTrace(); + } + } + } + + associationsTaggedValuesMap = new HashMap>(); + try { + connection = getConnection(); + statement = connection.createStatement(); + + /** This query retrieves all tagged values on attributes */ + rs = statement.executeQuery( + "select * from t_connector c, t_connectortag tv where (tv.ElementID = c.Connector_ID)"); + while (rs.next()) { + int elementId = rs.getInt(COL_ElementID); + if (associationsTaggedValuesMap.containsKey(elementId)) { + List taggedValuesList = associationsTaggedValuesMap.get(elementId); + taggedValuesList.add(new TaggedValue(rs.getString(COL_Property), rs.getString(COL_Value))); + } else { + List taggedValuesList = new ArrayList(); + taggedValuesList.add(new TaggedValue(rs.getString(COL_Property), rs.getString(COL_Value))); + associationsTaggedValuesMap.put(elementId, taggedValuesList); + } + } + } catch (SQLException sqlException) { + throw new EAProjectParserException("Unable to import the EA project file: " + file.getAbsolutePath(), + sqlException); + } finally { + if (rs != null) { + try { + rs.close(); + } catch (SQLException e) { + e.printStackTrace(); + } + } + if (statement != null) { + try { + statement.close(); + } catch (SQLException e) { + e.printStackTrace(); + } + } + if (connection != null) { + try { + connection.close(); + } catch (SQLException e) { + e.printStackTrace(); + } + } + } + } + + protected void gatherPackageIDs() throws EAProjectParserException { + OntResource top = createGlobalPackage(); + + Connection connection = null; + Statement statement = null; + ResultSet rs = null; + try { + connection = getConnection(); + statement = connection.createStatement(); + rs = statement.executeQuery("select * from t_package order by Name"); + while (rs.next()) { + OntResource subject; + if (rs.getString(COL_Name).equals("Model")) + subject = top; + else + subject = createIndividual(getXUID(rs), rs.getString(COL_Name), UML.Package); + packageIDs.putID(rs.getInt(COL_Package_ID), subject); + } + } catch (SQLException sqlException) { + throw new EAProjectParserException("Unable to import the EA project file: " + file.getAbsolutePath(), + sqlException); + } finally { + if (rs != null) { + try { + rs.close(); + } catch (SQLException e) { + e.printStackTrace(); + } + } + if (statement != null) { + try { + statement.close(); + } catch (SQLException e) { + e.printStackTrace(); + } + } + if (connection != null) { + try { + connection.close(); + } catch (SQLException e) { + e.printStackTrace(); + } + } + } + + } + + protected void parsePackages() throws EAProjectParserException { + Connection connection = null; + Statement statement = null; + ResultSet rs = null; + try { + connection = getConnection(); + statement = connection.createStatement(); + // For extracting packages we must perform a join to be able to pull in the + // Object_ID for the package. The Object_ID is needed to located tagged values. + rs = statement.executeQuery("select * from t_package"); + while (rs.next()) { + int packageId = Integer.parseInt(rs.getString(COL_Package_ID)); + OntResource subject = packageIDs.getID(packageId); + if (!subject.equals(UML.global_package)) { + int parentPackageId = rs.getInt(COL_Parent_ID); + OntResource parent = packageIDs.getID(parentPackageId); + if (!parent.equals(UML.global_package)) + subject.addIsDefinedBy(parent); + annotate(subject, rs.getString(COL_Notes)); + /** + * Should we ever need to add support for Stereotypes on Packages simply uncomment the line below + * to add them. Additionally, the XMIParser.PackageMode.visit() method would need to + * have the following code uncommented: return new StereotypeMode(element, packResource); + */ + // addStereotypes(subject, rs.getString(COL_ea_guid)); + addTaggedValuesToPackage(subject, packageId); + } + } + } catch (SQLException sqlException) { + throw new EAProjectParserException("Unable to import the EA project file: " + file.getAbsolutePath(), + sqlException); + } finally { + if (rs != null) { + try { + rs.close(); + } catch (SQLException e) { + e.printStackTrace(); + } + } + if (statement != null) { + try { + statement.close(); + } catch (SQLException e) { + e.printStackTrace(); + } + } + if (connection != null) { + try { + connection.close(); + } catch (SQLException e) { + e.printStackTrace(); + } + } + } + } + + protected void parseClasses() throws EAProjectParserException { + Connection connection = null; + Statement statement = null; + ResultSet rs = null; + try { + connection = getConnection(); + statement = connection.createStatement(); + rs = statement.executeQuery("select * from t_object where Object_Type = 'Class'"); + while (rs.next()) { + OntResource subject = createClass(getXUID(rs), rs.getString(COL_Name)); + int objectId = rs.getInt(COL_Object_ID); + objectIDs.putID(objectId, subject); + annotate(subject, rs.getString(COL_Note)); + OntResource parent = packageIDs.getID(rs.getInt(COL_Package_ID)); + if (!parent.equals(UML.global_package)) + subject.addIsDefinedBy(parent); + // + addStereotypes(subject, rs.getString(COL_ea_guid)); + addTaggedValuesToClass(subject, objectId); + } + } catch (SQLException sqlException) { + throw new EAProjectParserException("Unable to import the EA project file: " + file.getAbsolutePath(), + sqlException); + } finally { + if (rs != null) { + try { + rs.close(); + } catch (SQLException e) { + e.printStackTrace(); + } + } + if (statement != null) { + try { + statement.close(); + } catch (SQLException e) { + e.printStackTrace(); + } + } + if (connection != null) { + try { + connection.close(); + } catch (SQLException e) { + e.printStackTrace(); + } + } + } + } + + protected void parseAttributes() throws EAProjectParserException { + Connection connection = null; + Statement statement = null; + ResultSet rs = null; + try { + connection = getConnection(); + statement = connection.createStatement(); + rs = statement.executeQuery("select * from t_attribute"); + while (rs.next()) { + int objectId = rs.getInt(COL_Object_ID); + OntResource id = objectIDs.getID(objectId); + if (id != null) { + String name = rs.getString(COL_Name); + OntResource subject = createAttributeProperty(getXUID(rs), name); + subject.addDomain(id); + annotate(subject, rs.getString(COL_Notes)); + subject.addIsDefinedBy(id.getIsDefinedBy()); + if (hasClassifier(rs)) { + int classifier = getClassifier(rs); + OntResource range = objectIDs.getID(classifier); + if (range != null) + subject.addRange(range); + else { + System.out.println( + "Could not find the range of attribute " + name + ". Range ID = " + classifier); + } + } + String defaultValue = rs.getString(COL_Default); + if (defaultValue != null && "".equals(defaultValue)) { + subject.addProperty(UML.hasInitialValue, defaultValue); + } + // + addStereotypes(subject, rs.getString(COL_ea_guid)); + addTaggedValuesToAttribute(subject, rs.getInt(COL_ID)); + } else { + System.out.println("Could not find the domain of attribute " + rs.getString(COL_Name) + + ". Domain ID = " + rs.getInt(COL_Object_ID)); + } + } + } catch (SQLException sqlException) { + throw new EAProjectParserException("Unable to import the EA project file: " + file.getAbsolutePath(), + sqlException); + } finally { + if (rs != null) { + try { + rs.close(); + } catch (SQLException e) { + e.printStackTrace(); + } + } + if (statement != null) { + try { + statement.close(); + } catch (SQLException e) { + e.printStackTrace(); + } + } + if (connection != null) { + try { + connection.close(); + } catch (SQLException e) { + e.printStackTrace(); + } + } + } + } + + protected void parseAssociations() throws EAProjectParserException { + Connection connection = null; + Statement statement = null; + ResultSet rs = null; + try { + connection = getConnection(); + statement = connection.createStatement(); + rs = statement.executeQuery("select * from t_connector"); + while (rs.next()) { + String type = rs.getString(COL_Connector_Type); + if (type.equals("Generalization") || type.equals("Association") || type.equals("Aggregation")) { + OntResource source = objectIDs.getID(rs.getInt(COL_Start_Object_ID)); + OntResource destin = objectIDs.getID(rs.getInt(COL_End_Object_ID)); + if (source != null && destin != null) { + if (type.equals("Generalization")) { + source.addSuperClass(destin); + } else { + Role roleA = extractProperty( // + getXUID(rs), // + source, // + destin, // + rs.getString(COL_DestRole), // + rs.getString(COL_DestRoleNote), // + rs.getString(COL_DestCard), // + rs.getInt(COL_DestIsAggregate), // + true, // + rs.getInt(COL_Connector_ID)); + Role roleB = extractProperty( // + getXUID(rs), // + destin, // + source, // + rs.getString(COL_SourceRole), // + rs.getString(COL_SourceRoleNote), // + rs.getString(COL_SourceCard), // + rs.getInt(COL_SourceIsAggregate), // + false, // + rs.getInt(COL_Connector_ID)); + roleA.mate(roleB); + roleB.mate(roleA); + } + } + } + } + } catch (SQLException sqlException) { + throw new EAProjectParserException("Unable to import the EA project file: " + file.getAbsolutePath(), + sqlException); + } finally { + if (rs != null) { + try { + rs.close(); + } catch (SQLException e) { + e.printStackTrace(); + } + } + if (statement != null) { + try { + statement.close(); + } catch (SQLException e) { + e.printStackTrace(); + } + } + if (connection != null) { + try { + connection.close(); + } catch (SQLException e) { + e.printStackTrace(); + } + } + } + } + + private int getClassifier(ResultSet rs) throws SQLException { + String classifier = rs.getString("Classifier"); + return classifier != null ? Integer.parseInt(classifier) : 0; + } + + private boolean hasClassifier(ResultSet rs) throws SQLException { + return getClassifier(rs) != 0; + } + + private String getXUID(ResultSet rs) throws SQLException { + String xuid = rs.getString(COL_ea_guid); + return "_" + xuid.substring(1, xuid.length() - 1); + } + +} diff --git a/CIMUtil/src/au/com/langdale/xmi/AbstractEAProjectExtractor.java b/CIMUtil/src/au/com/langdale/xmi/AbstractEAProjectExtractor.java deleted file mode 100644 index e459f861..00000000 --- a/CIMUtil/src/au/com/langdale/xmi/AbstractEAProjectExtractor.java +++ /dev/null @@ -1,152 +0,0 @@ -/* - * This software is Copyright 2005,2006,2007,2008 Langdale Consultants. - * Langdale Consultants can be contacted at: http://www.langdale.com.au - */ -package au.com.langdale.xmi; - -import java.io.File; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import com.hp.hpl.jena.graph.FrontsNode; - -import au.com.langdale.kena.OntResource; - -public abstract class AbstractEAProjectExtractor extends XMIModel implements EAProjectExtractor { - - protected File file; - - protected IDList packageIDs = new IDList(100); - protected IDList objectIDs = new IDList(2000); - - private static String stereoPattern = "@STEREO;(.+?)@ENDSTEREO;"; - private static String name = "(.+?)=(.+?);"; - - private static Pattern pattern = Pattern.compile(stereoPattern); - private static Pattern namePattern = Pattern.compile(name); - - protected Map> stereotypesMap = new HashMap>(); - protected Map> taggedValuesMap = new HashMap>(); - - public AbstractEAProjectExtractor(File file) { - this.file = file; - } - - protected class TaggedValue { - public String name; - public String value; - - public TaggedValue(String name, String value) { - this.name = name; - this.value = (value != null ? value.trim() : value); - } - } - - @SuppressWarnings("serial") - protected class IDList extends ArrayList { - - public IDList(int size) { - super(size); - } - - public void putID(int index, OntResource id) { - while( index >= size()) { - add(null); - } - set(index, id); - } - - public OntResource getID(int index) { - if( index >= size() ) { - return null; - } - OntResource res = (OntResource) get(index); - return res; - } - } - - protected abstract void loadStereotypesCache() throws EAProjectExtractorException; - protected abstract void loadTaggedValuesCache() throws EAProjectExtractorException; - protected abstract void gatherPackageIDs() throws EAProjectExtractorException; - protected abstract void extractPackages() throws EAProjectExtractorException; - protected abstract void extractClasses() throws EAProjectExtractorException; - protected abstract void extractAssociations() throws EAProjectExtractorException; - protected abstract void extractAttributes() throws EAProjectExtractorException; - - protected void annotate(OntResource subject, String note) { - if (note == null) - return; - - note = note.trim(); - if (note.length() == 0) - return; - - subject.addComment(note, LANG); - } - - protected void addStereotypes(OntResource subject, String eaGUID) { - if (stereotypesMap.containsKey(eaGUID)) { - List stereotypesList = stereotypesMap.get(eaGUID); - for (String stereotypes : stereotypesList) { - Matcher matcher = pattern.matcher(stereotypes); - while (matcher.find()) { - String description = matcher.group(1); - Matcher stereoNameMatcher = namePattern.matcher(description); - while (stereoNameMatcher.find()) { - String groupName = stereoNameMatcher.group(1); - if ("Name".equals(groupName)) { - String stereoName = stereoNameMatcher.group(2); - subject.addProperty(UML.hasStereotype, createStereotypeByName(stereoName)); - } - } - } - } - } - } - - protected void addTaggedValues(OntResource subject, int objectId) { - if (taggedValuesMap.containsKey(objectId)) { - List taggedValuesList = taggedValuesMap.get(objectId); - for (TaggedValue taggedValue : taggedValuesList) { - FrontsNode property = Translator.annotationResource(taggedValue.name); - if (subject != null && property != null && taggedValue.value != null) { - subject.addProperty(property, taggedValue.value); - } - } - } - } - - protected Role extractProperty(String xuid, OntResource source, OntResource destin, String name, String note, String card, int aggregate, boolean sideA) { - Role role = new Role(); - role.property = createObjectProperty(xuid, sideA, name); - annotate(role.property, note); - role.property.addIsDefinedBy(source.getIsDefinedBy()); // FIXME: the package of an association is not always that of the source class - role.range = destin; - switch (aggregate) { - case 1: // Aggregate - role.aggregate = true; - role.composite = false; - break; - case 2: // Composite - role.aggregate = false; - role.composite = true; - break; - default: - role.aggregate = false; - role.composite = false; - break; - } - if( card.equals("1") || card.endsWith("..1")) - role.upper = 1; - if( card.equals("*") || card.startsWith("0..")) - role.lower = 0; - else - role.lower = 1; - return role; - } - -} diff --git a/CIMUtil/src/au/com/langdale/xmi/AbstractEAProjectParser.java b/CIMUtil/src/au/com/langdale/xmi/AbstractEAProjectParser.java new file mode 100644 index 00000000..c453398a --- /dev/null +++ b/CIMUtil/src/au/com/langdale/xmi/AbstractEAProjectParser.java @@ -0,0 +1,303 @@ +/* + * This software is Copyright 2005,2006,2007,2008 Langdale Consultants. + * Langdale Consultants can be contacted at: http://www.langdale.com.au + */ +package au.com.langdale.xmi; + +import java.io.File; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import com.hp.hpl.jena.graph.FrontsNode; + +import au.com.langdale.kena.OntResource; + +public abstract class AbstractEAProjectParser extends XMIModel implements EAProjectParser { + + // Table name constants corresponding to the EA project file database tables. + protected static final String TABLE_t_package = "t_package"; + protected static final String TABLE_t_object = "t_object"; + protected static final String TABLE_t_connector = "t_connector"; + protected static final String TABLE_t_xref = "t_xref"; + protected static final String TABLE_t_objectproperties = "t_objectproperties"; + protected static final String TABLE_t_attribute = "t_attribute"; + protected static final String TABLE_t_attributetag = "t_attributetag"; + protected static final String TABLE_t_connectortag = "t_connectortag"; + + // Column name constants corresponding to the EA project file database columns. + // These names are case sensitive by design and should not be modified. + protected static final String COL_Client = "Client"; + protected static final String COL_Description = "Description"; + protected static final String COL_Parent_ID = "Parent_ID"; + protected static final String COL_Connector_ID = "Connector_ID"; + protected static final String COL_Note = "Note"; + protected static final String COL_Object_Type = "Object_Type"; + protected static final String COL_Package_ID = "Package_ID"; + protected static final String COL_PDATA1 = "PDATA1"; + protected static final String COL_VALUE = "VALUE"; + protected static final String COL_Value = "Value"; + protected static final String COL_Property = "Property"; + protected static final String COL_SourceRole = "SourceRole"; + protected static final String COL_DestRole = "DestRole"; + protected static final String COL_SourceCard = "SourceCard"; + protected static final String COL_DestCard = "DestCard"; + protected static final String COL_SourceRoleNote = "SourceRoleNote"; + protected static final String COL_End_Object_ID = "End_Object_ID"; + protected static final String COL_Start_Object_ID = "Start_Object_ID"; + protected static final String COL_DestRoleNote = "DestRoleNote"; + protected static final String COL_DestIsAggregate = "DestIsAggregate"; + protected static final String COL_SourceIsAggregate = "SourceIsAggregate"; + protected static final String COL_Connector_Type = "Connector_Type"; + protected static final String COL_ea_guid = "ea_guid"; + protected static final String COL_ID = "ID"; + protected static final String COL_Default = "Default"; + protected static final String COL_Name = "Name"; + protected static final String COL_Notes = "Notes"; + protected static final String COL_Object_ID = "Object_ID"; + protected static final String COL_ElementID = "ElementID"; + protected static final String COL_Classifier = "Classifier"; + + protected File file; + + protected IDList packageIDs = new IDList(100); + protected IDList objectIDs = new IDList(2000); + + private static String stereoPattern = "@STEREO;(.+?)@ENDSTEREO;"; + private static String name = "(.+?)=(.+?);"; + + private static Pattern pattern = Pattern.compile(stereoPattern); + private static Pattern namePattern = Pattern.compile(name); + + protected Map> stereotypesMap = new HashMap>(); + protected Map> packagesTaggedValuesMap = new HashMap>(); + protected Map> classesTaggedValuesMap = new HashMap>(); + protected Map> attributesTaggedValuesMap = new HashMap>(); + protected Map> associationsTaggedValuesMap = new HashMap>(); + + protected abstract void dbInit() throws EAProjectParserException; + + protected abstract void dbShutdown() throws EAProjectParserException; + + public void parse() throws EAProjectParserException { + // NOTE: Connection and Statement are AutoClosable. These should + // be closed within the dbShutdown method to avoid leaks. + try { + // We call dbInit for those databases that may need to perform + // JDBC or database related initialization such as registering + // a JDBC driver... + dbInit(); + // + loadStereotypesCache(); + loadTaggedValuesCaches(); + gatherPackageIDs(); + parsePackages(); + parseClasses(); + parseAssociations(); + parseAttributes(); + } catch (EAProjectParserException eapException) { + eapException.printStackTrace(System.err); + throw eapException; + } catch (Exception exception) { + exception.printStackTrace(System.err); + throw new EAProjectParserException("Unable to import the EA project file: " + file.getAbsolutePath(), + exception); + } finally { + dbShutdown(); + } + } + + public AbstractEAProjectParser(File file) { + this.file = file; + } + + protected class TaggedValue { + @Override + public String toString() { + return "TaggedValue [name=" + name + ", value=" + value + "]"; + } + + public String name; + public String value; + + public TaggedValue(String name, String value) { + this.name = name; + this.value = (value != null ? value.trim() : value); + } + } + + @SuppressWarnings("serial") + protected class IDList extends ArrayList { + + public IDList(int size) { + super(size); + } + + public void putID(int index, OntResource id) { + while (index >= size()) { + add(null); + } + set(index, id); + } + + public OntResource getID(int index) { + if (index >= size()) { + return null; + } + OntResource res = (OntResource) get(index); + return res; + } + } + + protected abstract void loadStereotypesCache() throws EAProjectParserException; + + protected abstract void loadTaggedValuesCaches() throws EAProjectParserException; + + protected abstract void gatherPackageIDs() throws EAProjectParserException; + + protected abstract void parsePackages() throws EAProjectParserException; + + protected abstract void parseClasses() throws EAProjectParserException; + + protected abstract void parseAssociations() throws EAProjectParserException; + + protected abstract void parseAttributes() throws EAProjectParserException; + + protected void annotate(OntResource subject, String note) { + if (note == null) + return; + + note = note.trim(); + if (note.length() == 0) + return; + + subject.addComment(note, LANG); + } + + protected void addStereotypes(OntResource subject, String eaGUID) { + if (stereotypesMap.containsKey(eaGUID)) { + List stereotypesList = stereotypesMap.get(eaGUID); + for (String stereotypes : stereotypesList) { + Matcher matcher = pattern.matcher(stereotypes); + while (matcher.find()) { + String description = matcher.group(1); + Matcher stereoNameMatcher = namePattern.matcher(description); + while (stereoNameMatcher.find()) { + String groupName = stereoNameMatcher.group(1); + if ("Name".equals(groupName)) { + String stereoName = stereoNameMatcher.group(2); + subject.addProperty(UML.hasStereotype, createStereotypeByName(stereoName)); + } + } + } + } + } + } + + protected void addTaggedValuesToPackage(OntResource subject, int packageId) { + if (packagesTaggedValuesMap.containsKey(packageId)) { + List taggedValuesList = packagesTaggedValuesMap.get(packageId); + for (TaggedValue taggedValue : taggedValuesList) { + FrontsNode property = Translator.annotationResource(taggedValue.name); + if (subject != null && property != null && taggedValue.value != null) { + subject.addProperty(property, taggedValue.value); + } + } + } + } + + protected void addTaggedValuesToClass(OntResource subject, int objectId) { + if (classesTaggedValuesMap.containsKey(objectId)) { + List taggedValuesList = classesTaggedValuesMap.get(objectId); + for (TaggedValue taggedValue : taggedValuesList) { + FrontsNode property = Translator.annotationResource(taggedValue.name); + if (subject != null && property != null && taggedValue.value != null) { + subject.addProperty(property, taggedValue.value); + } + } + } + } + + protected void addTaggedValuesToAttribute(OntResource subject, int id) { + if (attributesTaggedValuesMap.containsKey(id)) { + List taggedValuesList = attributesTaggedValuesMap.get(id); + for (TaggedValue taggedValue : taggedValuesList) { + FrontsNode property = Translator.annotationResource(taggedValue.name); + if (subject != null && property != null && taggedValue.value != null) { + subject.addProperty(property, taggedValue.value); + } + } + } + } + + protected String getTaggedValueForAssociation(au.com.langdale.kena.Property prop, int connectorId) { + if (associationsTaggedValuesMap.containsKey(connectorId)) { + List taggedValuesList = associationsTaggedValuesMap.get(connectorId); + for (TaggedValue taggedValue : taggedValuesList) { + if (taggedValue.name.equals(prop.getLocalName())) { + return taggedValue.value; + } + } + } + return null; + } + + protected Role extractProperty(String xuid, OntResource source, OntResource destin, String name, String note, + String card, int aggregate, boolean sideA, int connectorId) { + Role role = new Role(); + role.property = createObjectProperty(xuid, sideA, name); + annotate(role.property, note); + role.property.addIsDefinedBy(source.getIsDefinedBy()); // FIXME: the package of an association is not always + // that of the source class + role.range = destin; + + switch (aggregate) { + case 1: // Aggregate + role.aggregate = true; + role.composite = false; + break; + case 2: // Composite + role.aggregate = false; + role.composite = true; + break; + default: + role.aggregate = false; + role.composite = false; + break; + } + + if (card.equals("1") || card.endsWith("..1")) + role.upper = 1; + + // Keeping this around...need to test to see if it is needed and should be uncommented... + // if so we'd need to also look at the XMIModel / XMIParser classes for initializing upper bound.. + + // else if (!card.endsWith("..1") && !card.endsWith("..*")) + // role.upper = Integer.parseInt(card.substring(card.lastIndexOf(".") + 1)); + + if (card.equals("*") || card.startsWith("0..")) + role.lower = 0; + else + role.lower = 1; + + role.baseuri = getTaggedValueForAssociation(UML.baseuri, connectorId); + role.baseprefix = getTaggedValueForAssociation(UML.baseprefix, connectorId); + + /** + * NOTE: We can and should support Stereotypes on connectors. We just need to + * determine what subject that they should be assigned to. Unsure of this. + * + * select Description from t_xref where Client = 'ea_guid of t_connector' and Name = 'Stereotypes' and Type = 'connector property'; + * + * Stereotypes on connectors: + * + * addStereotypes(subject, row.getEAGUID()); + */ + + return role; + } + +} diff --git a/CIMUtil/src/au/com/langdale/xmi/CIMInterpreter.java b/CIMUtil/src/au/com/langdale/xmi/CIMInterpreter.java index 60468ff2..8fa4db14 100644 --- a/CIMUtil/src/au/com/langdale/xmi/CIMInterpreter.java +++ b/CIMUtil/src/au/com/langdale/xmi/CIMInterpreter.java @@ -9,9 +9,12 @@ import au.com.langdale.kena.ResIterator; import au.com.langdale.kena.Resource; +import java.util.TreeMap; + import com.hp.hpl.jena.graph.FrontsNode; import com.hp.hpl.jena.graph.Node; import com.hp.hpl.jena.vocabulary.OWL; +import com.hp.hpl.jena.vocabulary.OWL2; import com.hp.hpl.jena.vocabulary.RDF; import com.hp.hpl.jena.vocabulary.RDFS; import com.hp.hpl.jena.vocabulary.XSD; @@ -42,12 +45,36 @@ private OntModel postProcess(OntModel raw, String baseURI, boolean usePackageNam System.out.println("Stage 1 XMI model size: " + getModel().size()); + /** + ResIterator classes1 = raw.listSubjectsWithProperty(RDF.type, OWL2.Class); + TreeMap classMap1 = new TreeMap<>(); + classes1.forEachRemaining((c) -> { + if (((OntResource)c).getLabel() != null) + classMap1.put(((OntResource)c).getLabel(), (OntResource)c); + }); + classMap1.forEach((name, aClass) -> { + OntResource aParentPackage = aClass.getIsDefinedBy(); + System.out.println(String.format("1 - Class: %s; Package: %s", name, (aParentPackage != null ? aParentPackage.getLabel() : aParentPackage))); + }); */ + Translator translator = new Translator(getModel(), baseURI, usePackageNames); translator.run(); setModel(translator.getModel()); System.out.println("Stage 3 XMI model size: " + getModel().size()); - + + /** + ResIterator classes3 = raw.listSubjectsWithProperty(RDF.type, OWL2.Class); + TreeMap classMap3 = new TreeMap<>(); + classes3.forEachRemaining((c) -> { + if (((OntResource)c).getLabel() != null) + classMap3.put(((OntResource)c).getLabel(), (OntResource)c); + }); + classMap3.forEach((name, aClass) -> { + OntResource aParentPackage = aClass.getIsDefinedBy(); + System.out.println(String.format("3 - Class: %s; Package: %s", name, (aParentPackage != null ? aParentPackage.getLabel() : aParentPackage))); + }); */ + propagateComments(); applyStereotypes(); classifyAttributes(); @@ -57,6 +84,18 @@ private OntModel postProcess(OntModel raw, String baseURI, boolean usePackageNam System.out.println("Stage 4 XMI model size: " + getModel().size()); + /** + ResIterator classes4 = raw.listSubjectsWithProperty(RDF.type, OWL2.Class); + TreeMap classMap4 = new TreeMap<>(); + classes4.forEachRemaining((c) -> { + if (((OntResource)c).getLabel() != null) + classMap4.put(((OntResource)c).getLabel(), (OntResource)c); + }); + classMap4.forEach((name, aClass) -> { + OntResource aParentPackage = aClass.getIsDefinedBy(); + System.out.println(String.format("4 - Class: %s; Package: %s", name, (aParentPackage != null ? aParentPackage.getLabel() : aParentPackage))); + }); */ + return getModel(); } diff --git a/CIMUtil/src/au/com/langdale/xmi/EAPExtractor.java b/CIMUtil/src/au/com/langdale/xmi/EAPExtractor.java deleted file mode 100644 index acadd855..00000000 --- a/CIMUtil/src/au/com/langdale/xmi/EAPExtractor.java +++ /dev/null @@ -1,399 +0,0 @@ -/* - * This software is Copyright 2005,2006,2007,2008 Langdale Consultants. - * Langdale Consultants can be contacted at: http://www.langdale.com.au - */ -package au.com.langdale.xmi; - -import java.io.File; -import java.io.IOException; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - -import com.healthmarketscience.jackcess.Database; -import com.healthmarketscience.jackcess.DatabaseBuilder; -import com.healthmarketscience.jackcess.Table; - -import au.com.langdale.kena.OntResource; - -public class EAPExtractor extends AbstractEAProjectExtractor { - - private Database db; - - public EAPExtractor(File file) { - super(file); - } - - public void run() throws EAProjectExtractorException { - try { - db = DatabaseBuilder.open(file); - // - loadStereotypesCache(); - loadTaggedValuesCache(); - gatherPackageIDs(); - extractPackages(); - extractClasses(); - extractAssociations(); - extractAttributes(); - } catch (IOException ioException) { - ioException.printStackTrace(System.err); - throw new EAProjectExtractorException("Unable to import the EA project file: " + file.getAbsolutePath(), - ioException); - } finally { - try { - db.close(); - } catch (IOException e) { - // Do nothing... - } - } - } - - protected void loadStereotypesCache() throws EAProjectExtractorException { - stereotypesMap = new HashMap>(); - Iterator it = getXRefTable().iterator(); - while (it.hasNext()) { - Row row = new Row(it.next()); - if (row.getName().equals("Stereotypes")) { - if (stereotypesMap.containsKey(row.getClient())) { - List stereotypesList = stereotypesMap.get(row.getClient()); - stereotypesList.add(row.getDescription()); - } else { - List stereotypesList = new ArrayList(); - stereotypesList.add(row.getDescription()); - stereotypesMap.put(row.getClient(), stereotypesList); - } - } - } - } - - protected void loadTaggedValuesCache() throws EAProjectExtractorException { - taggedValuesMap = new HashMap>(); - Iterator it = getObjectPropertiesTable().iterator(); - while (it.hasNext()) { - Row row = new Row(it.next()); - if (taggedValuesMap.containsKey(row.getObjectID())) { - List taggedValuesList = taggedValuesMap.get(row.getObjectID()); - taggedValuesList.add(new TaggedValue(row.getProperty(), row.getValue())); - } else { - List taggedValuesList = new ArrayList(); - taggedValuesList.add(new TaggedValue(row.getProperty(), row.getValue())); - taggedValuesMap.put(row.getObjectID(), taggedValuesList); - } - } - } - - protected void gatherPackageIDs() throws EAProjectExtractorException { - OntResource top = createGlobalPackage(); - - Table table = getPackageTable(); - Iterator it = table.iterator(); - while (it.hasNext()) { - Row row = new Row(it.next()); - OntResource subject; - if (row.getName().equals("Model")) - subject = top; - else - subject = createIndividual(row.getXUID(), row.getName(), UML.Package); - packageIDs.putID(row.getPackageID(), subject); - } - } - - protected void extractPackages() throws EAProjectExtractorException { - Iterator it = getPackageTable().iterator(); - while (it.hasNext()) { - Row row = new Row(it.next()); - OntResource subject = packageIDs.getID(row.getPackageID()); - if (!subject.equals(UML.global_package)) { - OntResource parent = packageIDs.getID(row.getParentID()); - subject.addIsDefinedBy(parent == null ? UML.global_package : parent); - annotate(subject, row.getNotes()); - // - addStereotypes(subject, row.getEAGUID()); - // For packages the Object_ID is actually located in the t_object table so we - // must obtain that first... - // addTaggedValues(subject, objectId); - } - } - } - - protected void extractClasses() throws EAProjectExtractorException { - Iterator it = getObjectTable().iterator(); - while (it.hasNext()) { - Row row = new Row(it.next()); - if (row.getObjectType().equals("Class")) { - OntResource subject = createClass(row.getXUID(), row.getName()); - objectIDs.putID(row.getObjectID(), subject); - annotate(subject, row.getNote()); - OntResource parent = packageIDs.getID(row.getPackageID()); - subject.addIsDefinedBy(parent == null ? UML.global_package : parent); - // - addStereotypes(subject, row.getEAGUID()); - addTaggedValues(subject, row.getObjectID()); - } - } - } - - protected void extractAttributes() throws EAProjectExtractorException { - Iterator it = getAttributeTable().iterator(); - while (it.hasNext()) { - Row row = new Row(it.next()); - OntResource id = objectIDs.getID(row.getObjectID()); - if (id != null) { - OntResource subject = createAttributeProperty(row.getXUID(), row.getName()); - subject.addDomain(id); - annotate(subject, row.getNotes()); - subject.addIsDefinedBy(id.getIsDefinedBy()); - if (row.hasClassifier()) { - OntResource range = objectIDs.getID(row.getClassifier()); - if (range != null) - subject.addRange(range); - else - System.out.println("Could not find the range of attribute " + row.getName() + ". Range ID = " - + row.getClassifier()); - } - if (row.hasDefault()) { - subject.addProperty(UML.hasInitialValue, row.getDefault()); - } - // - addStereotypes(subject, row.getEAGUID()); - addTaggedValues(subject, row.getObjectID()); - } else - System.out.println("Could not find the domain of attribute " + row.getName() + ". Domain ID = " - + row.getObjectID()); - } - } - - protected void extractAssociations() throws EAProjectExtractorException { - Iterator it = getConnectorTable().iterator(); - while (it.hasNext()) { - Row row = new Row(it.next()); - String type = row.getConnectorType(); - if (type.equals("Generalization") || type.equals("Association") || type.equals("Aggregation")) { - OntResource source = objectIDs.getID(row.getStartObjectID()); - OntResource destin = objectIDs.getID(row.getEndObjectID()); - if (source != null && destin != null) { - if (type.equals("Generalization")) { - source.addSuperClass(destin); - } else { - Role rolea = extractProperty( // - row.getXUID(), // - source, // - destin, // - row.getDestRole(), // - row.getDestRoleNote(), // - row.getDestCard(), // - row.getDestIsAggregate(), // - true); - Role roleb = extractProperty( // - row.getXUID(), // - destin, // - source, // - row.getSourceRole(), // - row.getSourceRoleNote(), // - row.getSourceCard(), // - row.getSourceIsAggregate(), // - false); - rolea.mate(roleb); - roleb.mate(rolea); - } - } - } - } - } - - private Table getPackageTable() throws EAProjectExtractorException { - Table table = null; - try { - table = db.getTable("t_package"); - } catch (IOException ioe) { - throw new EAProjectExtractorException(ioe); - } - return table; - } - - private Table getObjectTable() throws EAProjectExtractorException { - Table table = null; - try { - table = db.getTable("t_object"); - } catch (IOException ioe) { - throw new EAProjectExtractorException(ioe); - } - return table; - } - - private Table getObjectPropertiesTable() throws EAProjectExtractorException { - Table table = null; - try { - table = db.getTable("t_objectproperties"); - } catch (IOException ioe) { - throw new EAProjectExtractorException(ioe); - } - return table; - } - - private Table getConnectorTable() throws EAProjectExtractorException { - Table table = null; - try { - table = db.getTable("t_connector"); - } catch (IOException ioe) { - throw new EAProjectExtractorException(ioe); - } - return table; - } - - private Table getXRefTable() throws EAProjectExtractorException { - Table table = null; - try { - table = db.getTable("t_xref"); - } catch (IOException ioe) { - throw new EAProjectExtractorException(ioe); - } - return table; - } - - private Table getAttributeTable() throws EAProjectExtractorException { - Table table = null; - try { - table = db.getTable("t_attribute"); - } catch (IOException ioe) { - throw new EAProjectExtractorException(ioe); - } - return table; - } - - private class Row { - private Map fields; - - Row(Object raw) { - fields = (Map) raw; - } - - public String getDescription() { - return getString("Description"); - } - - int getObjectID() { - return getInt("Object_ID"); - } - - int getPackageID() { - return getInt("Package_ID"); - } - - int getParentID() { - return getInt("Parent_ID"); - } - - int getStartObjectID() { - return getInt("Start_Object_ID"); - } - - int getEndObjectID() { - return getInt("End_Object_ID"); - } - - int getClassifier() { - Object raw = fields.get("Classifier"); - return raw != null ? Integer.parseInt(raw.toString()) : 0; - } - - boolean hasClassifier() { - return getClassifier() != 0; - } - - String getEAGUID() { - String eaGUID = fields.get("ea_guid").toString(); - return eaGUID; - } - - String getXUID() { - String xuid = fields.get("ea_guid").toString(); - return "_" + xuid.substring(1, xuid.length() - 1); - } - - public String getClient() { - return getString("Client"); - } - - String getName() { - return getString("Name"); - } - - String getObjectType() { - return getString("Object_Type"); - } - - String getConnectorType() { - return getString("Connector_Type"); - } - - String getNote() { - return getString("Note"); - } - - String getNotes() { - return getString("Notes"); - } - - boolean hasDefault() { - return fields.get("Default") != null; - } - - String getDefault() { - return fields.get("Default").toString(); - } - - String getDestRole() { - return getString("DestRole"); - } - - String getDestRoleNote() { - return getString("DestRoleNote"); - } - - String getDestCard() { - return getString("DestCard"); - } - - int getDestIsAggregate() { - return getInt("DestIsAggregate"); - } - - String getSourceRole() { - return getString("SourceRole"); - } - - String getSourceRoleNote() { - return getString("SourceRoleNote"); - } - - String getSourceCard() { - return getString("SourceCard"); - } - - int getSourceIsAggregate() { - return getInt("SourceIsAggregate"); - } - - public String getProperty() { - return getString("Property"); - } - - public String getValue() { - return getString("Value"); - } - - int getInt(String name) { - Object raw = fields.get(name); - return (raw instanceof Integer) ? ((Integer) raw).intValue() : 0; - } - - String getString(String name) { - Object raw = fields.get(name); - return raw != null ? raw.toString() : ""; - } - } - -} diff --git a/CIMUtil/src/au/com/langdale/xmi/EAPParser.java b/CIMUtil/src/au/com/langdale/xmi/EAPParser.java new file mode 100644 index 00000000..696042a6 --- /dev/null +++ b/CIMUtil/src/au/com/langdale/xmi/EAPParser.java @@ -0,0 +1,518 @@ +/* + * This software is Copyright 2005,2006,2007,2008 Langdale Consultants. + * Langdale Consultants can be contacted at: http://www.langdale.com.au + */ +package au.com.langdale.xmi; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.TreeSet; + +import com.healthmarketscience.jackcess.Database; +import com.healthmarketscience.jackcess.DatabaseBuilder; +import com.healthmarketscience.jackcess.Table; + +import au.com.langdale.kena.OntResource; + +public class EAPParser extends AbstractEAProjectParser { + + private Database db; + + public EAPParser(File file) { + super(file); + } + + protected void dbInit() throws EAProjectParserException { + try { + db = DatabaseBuilder.open(file); + } catch (IOException ioException) { + ioException.printStackTrace(System.err); + throw new EAProjectParserException("Unable to import the EA project file: " + file.getAbsolutePath(), + ioException); + } + } + + protected void dbShutdown() throws EAProjectParserException { + try { + db.close(); + } catch (IOException e) { + // Do nothing... + } + } + + protected void loadStereotypesCache() throws EAProjectParserException { + stereotypesMap = new HashMap>(); + Iterator it = getXRefTable().iterator(); + while (it.hasNext()) { + Row row = new Row(it.next()); + if (row.getName().equals("Stereotypes")) { + if (stereotypesMap.containsKey(row.getClient())) { + List stereotypesList = stereotypesMap.get(row.getClient()); + stereotypesList.add(row.getDescription()); + } else { + List stereotypesList = new ArrayList(); + stereotypesList.add(row.getDescription()); + stereotypesMap.put(row.getClient(), stereotypesList); + } + } + } + } + + protected void loadTaggedValuesCaches() throws EAProjectParserException { + /** + * Jackess doesn't support joins. This is a "poor man's join" to associate the + * package id to the object id... + */ + Map objectIdToPackageMap = new HashMap(); + Set classIds = new TreeSet(); + Iterator it = getObjectTable().iterator(); + while (it.hasNext()) { + Row row = new Row(it.next()); + switch (row.getObjectType()) { + case "Class": + classIds.add(row.getObjectID()); + break; + case "Package": + objectIdToPackageMap.put(row.getObjectID(), Integer.parseInt(row.getPDATA1())); + break; + } + } + + packagesTaggedValuesMap = new HashMap>(); + classesTaggedValuesMap = new HashMap>(); + it = getObjectPropertiesTable().iterator(); + while (it.hasNext()) { + Row row = new Row(it.next()); + int objectId = row.getObjectID(); + if (classIds.contains(objectId)) { + if (classesTaggedValuesMap.containsKey(objectId)) { + List taggedValuesList = classesTaggedValuesMap.get(objectId); + taggedValuesList.add(new TaggedValue(row.getProperty(), row.getValue())); + } else { + List taggedValuesList = new ArrayList(); + taggedValuesList.add(new TaggedValue(row.getProperty(), row.getValue())); + classesTaggedValuesMap.put(objectId, taggedValuesList); + } + } else if (objectIdToPackageMap.containsKey(objectId)) { + int packageId = objectIdToPackageMap.get(objectId); + if (packagesTaggedValuesMap.containsKey(packageId)) { + List taggedValuesList = packagesTaggedValuesMap.get(packageId); + taggedValuesList.add(new TaggedValue(row.getProperty(), row.getValue())); + } else { + List taggedValuesList = new ArrayList(); + taggedValuesList.add(new TaggedValue(row.getProperty(), row.getValue())); + packagesTaggedValuesMap.put(packageId, taggedValuesList); + } + } + } + + /** This query retrieves all tagged values on attributes */ + attributesTaggedValuesMap = new HashMap>(); + it = getAttributeTagTable().iterator(); + while (it.hasNext()) { + Row row = new Row(it.next()); + int elementId = row.getElementID(); + if (attributesTaggedValuesMap.containsKey(elementId)) { + List taggedValuesList = attributesTaggedValuesMap.get(elementId); + taggedValuesList.add(new TaggedValue(row.getProperty(), row.getVALUE())); + } else { + List taggedValuesList = new ArrayList(); + taggedValuesList.add(new TaggedValue(row.getProperty(), row.getVALUE())); + attributesTaggedValuesMap.put(elementId, taggedValuesList); + } + } + + /** This query retrieves all tagged values on associations */ + associationsTaggedValuesMap = new HashMap>(); + it = getConnectorTagTable().iterator(); + while (it.hasNext()) { + Row row = new Row(it.next()); + int elementId = row.getElementID(); + if (associationsTaggedValuesMap.containsKey(elementId)) { + List taggedValuesList = associationsTaggedValuesMap.get(elementId); + taggedValuesList.add(new TaggedValue(row.getProperty(), row.getVALUE())); + } else { + List taggedValuesList = new ArrayList(); + taggedValuesList.add(new TaggedValue(row.getProperty(), row.getVALUE())); + associationsTaggedValuesMap.put(elementId, taggedValuesList); + } + } + } + + protected void gatherPackageIDs() throws EAProjectParserException { + OntResource top = createGlobalPackage(); + + Table table = getPackageTable(); + Iterator it = table.iterator(); + while (it.hasNext()) { + Row row = new Row(it.next()); + OntResource subject; + if (row.getName().equals("Model")) + subject = top; + else + subject = createIndividual(row.getXUID(), row.getName(), UML.Package); + packageIDs.putID(row.getPackageID(), subject); + } + } + + protected void parsePackages() throws EAProjectParserException { + Iterator it = getPackageTable().iterator(); + while (it.hasNext()) { + Row row = new Row(it.next()); + int packageId = row.getPackageID(); + OntResource subject = packageIDs.getID(packageId); + if (!subject.equals(UML.global_package)) { + int parentPackageId = row.getParentID(); + OntResource parent = packageIDs.getID(parentPackageId); + if (!parent.equals(UML.global_package)) + subject.addIsDefinedBy(parent); + annotate(subject, row.getNotes()); + /** + * Should we ever need to add support for Stereotypes on Packages simply uncomment the line + * below to add them. Additionally, the XMIParser.PackageMode.visit() method would need to + * have the following code uncommented: return new StereotypeMode(element, packResource); + * as well as code in the AbstractEAProjectDBExtractor.extractPackages() method. + */ + // addStereotypes(subject, row.getEAGUID()); + addTaggedValuesToPackage(subject, packageId); + } + } + } + + protected void parseClasses() throws EAProjectParserException { + Iterator it = getObjectTable().iterator(); + while (it.hasNext()) { + Row row = new Row(it.next()); + if (row.getObjectType().equals("Class")) { + OntResource subject = createClass(row.getXUID(), row.getName()); + objectIDs.putID(row.getObjectID(), subject); + annotate(subject, row.getNote()); + OntResource parent = packageIDs.getID(row.getPackageID()); + if (!parent.equals(UML.global_package)) + subject.addIsDefinedBy(parent); + // + addStereotypes(subject, row.getEAGUID()); + addTaggedValuesToClass(subject, row.getObjectID()); + } + } + } + + protected void parseAttributes() throws EAProjectParserException { + Iterator it = getAttributeTable().iterator(); + while (it.hasNext()) { + Row row = new Row(it.next()); + OntResource id = objectIDs.getID(row.getObjectID()); + if (id != null) { + OntResource subject = createAttributeProperty(row.getXUID(), row.getName()); + subject.addDomain(id); + annotate(subject, row.getNotes()); + subject.addIsDefinedBy(id.getIsDefinedBy()); + if (row.hasClassifier()) { + OntResource range = objectIDs.getID(row.getClassifier()); + if (range != null) + subject.addRange(range); + else + System.out.println("Could not find the range of attribute " + row.getName() + ". Range ID = " + + row.getClassifier()); + } + if (row.hasDefault()) { + subject.addProperty(UML.hasInitialValue, row.getDefault()); + } + // + addStereotypes(subject, row.getEAGUID()); + addTaggedValuesToAttribute(subject, row.getID()); + } else + System.out.println("Could not find the domain of attribute " + row.getName() + ". Domain ID = " + + row.getObjectID()); + } + } + + protected void parseAssociations() throws EAProjectParserException { + Iterator it = getConnectorTable().iterator(); + while (it.hasNext()) { + Row row = new Row(it.next()); + String type = row.getConnectorType(); + if (type.equals("Generalization") || type.equals("Association") || type.equals("Aggregation")) { + OntResource source = objectIDs.getID(row.getStartObjectID()); + OntResource destin = objectIDs.getID(row.getEndObjectID()); + if (source != null && destin != null) { + if (type.equals("Generalization")) { + source.addSuperClass(destin); + } else { + Role roleA = extractProperty( // + row.getXUID(), // + source, // + destin, // + row.getDestRole(), // + row.getDestRoleNote(), // + row.getDestCard(), // + row.getDestIsAggregate(), // + true, // + row.getConnectorID()); + Role roleB = extractProperty( // + row.getXUID(), // + destin, // + source, // + row.getSourceRole(), // + row.getSourceRoleNote(), // + row.getSourceCard(), // + row.getSourceIsAggregate(), // + false, // + row.getConnectorID()); + roleA.mate(roleB); + roleB.mate(roleA); + } + } + } + } + } + + private Table getPackageTable() throws EAProjectParserException { + Table table = null; + try { + table = db.getTable(TABLE_t_package); + } catch (IOException ioe) { + throw new EAProjectParserException(ioe); + } + return table; + } + + private Table getObjectTable() throws EAProjectParserException { + Table table = null; + try { + table = db.getTable(TABLE_t_object); + } catch (IOException ioe) { + throw new EAProjectParserException(ioe); + } + return table; + } + + private Table getObjectPropertiesTable() throws EAProjectParserException { + Table table = null; + try { + table = db.getTable(TABLE_t_objectproperties); + } catch (IOException ioe) { + throw new EAProjectParserException(ioe); + } + return table; + } + + private Table getAttributeTagTable() throws EAProjectParserException { + Table table = null; + try { + table = db.getTable(TABLE_t_attributetag); + } catch (IOException ioe) { + throw new EAProjectParserException(ioe); + } + return table; + } + + private Table getConnectorTagTable() throws EAProjectParserException { + Table table = null; + try { + table = db.getTable(TABLE_t_connectortag); + } catch (IOException ioe) { + throw new EAProjectParserException(ioe); + } + return table; + } + + private Table getConnectorTable() throws EAProjectParserException { + Table table = null; + try { + table = db.getTable(TABLE_t_connector); + } catch (IOException ioe) { + throw new EAProjectParserException(ioe); + } + return table; + } + + private Table getXRefTable() throws EAProjectParserException { + Table table = null; + try { + table = db.getTable(TABLE_t_xref); + } catch (IOException ioe) { + throw new EAProjectParserException(ioe); + } + return table; + } + + private Table getAttributeTable() throws EAProjectParserException { + Table table = null; + try { + table = db.getTable(TABLE_t_attribute); + } catch (IOException ioe) { + throw new EAProjectParserException(ioe); + } + return table; + } + + private class Row { + private Map fields; + + Row(Object raw) { + fields = (Map) raw; + } + + public String getDescription() { + return getString(COL_Description); + } + + int getObjectID() { + return getInt(COL_Object_ID); + } + + int getElementID() { + return getInt(COL_ElementID); + } + + int getPackageID() { + return getInt(COL_Package_ID); + } + + String getPDATA1() { + return getString(COL_PDATA1); + } + + int getParentID() { + return getInt(COL_Parent_ID); + } + + int getConnectorID() { + return getInt(COL_Connector_ID); + } + + int getStartObjectID() { + return getInt(COL_Start_Object_ID); + } + + int getEndObjectID() { + return getInt(COL_End_Object_ID); + } + + int getClassifier() { + Object raw = fields.get(COL_Classifier); + return raw != null ? Integer.parseInt(raw.toString()) : 0; + } + + boolean hasClassifier() { + return getClassifier() != 0; + } + + int getID() { + return getInt(COL_ID); + } + + String getEAGUID() { + String eaGUID = fields.get(COL_ea_guid).toString(); + return eaGUID; + } + + String getXUID() { + String xuid = fields.get(COL_ea_guid).toString(); + return "_" + xuid.substring(1, xuid.length() - 1); + } + + public String getClient() { + return getString(COL_Client); + } + + String getName() { + return getString(COL_Name); + } + + String getObjectType() { + return getString(COL_Object_Type); + } + + String getConnectorType() { + return getString(COL_Connector_Type); + } + + String getNote() { + return getString(COL_Note); + } + + String getNotes() { + return getString(COL_Notes); + } + + boolean hasDefault() { + return fields.get(COL_Default) != null; + } + + String getDefault() { + return fields.get(COL_Default).toString(); + } + + String getDestRole() { + return getString(COL_DestRole); + } + + String getDestRoleNote() { + return getString(COL_DestRoleNote); + } + + String getDestCard() { + return getString(COL_DestCard); + } + + int getDestIsAggregate() { + return getInt(COL_DestIsAggregate); + } + + String getSourceRole() { + return getString(COL_SourceRole); + } + + String getSourceRoleNote() { + return getString(COL_SourceRoleNote); + } + + String getSourceCard() { + return getString(COL_SourceCard); + } + + int getSourceIsAggregate() { + return getInt(COL_SourceIsAggregate); + } + + public String getProperty() { + return getString(COL_Property); + } + + /** + * Yes, this looks wonky having two getValueXxxxCase() methods. The reason is + * that the Jackcess APIs that we utilize for accessing the EA 15.x project + * files are case sensitive when retrieving the column name as the key into the + * Row's column/value map. This causes an issue between two separate tables that + * manage tag values. Specifically, the t_attributetag.VALUE and + * t_objectproperties.Value columns in the EA database. Therefore, we have, + * oddly, two distinct methods to retrieve them from the respective tables. + */ + public String getVALUE() { + return getString(COL_VALUE); + } + + public String getValue() { + return getString(COL_Value); + } + + int getInt(String name) { + Object raw = fields.get(name); + return (raw instanceof Integer) ? ((Integer) raw).intValue() : 0; + } + + String getString(String name) { + Object raw = fields.get(name); + return raw != null ? raw.toString() : ""; + } + } + +} diff --git a/CIMUtil/src/au/com/langdale/xmi/EAProjectExtractor.java b/CIMUtil/src/au/com/langdale/xmi/EAProjectParser.java similarity index 73% rename from CIMUtil/src/au/com/langdale/xmi/EAProjectExtractor.java rename to CIMUtil/src/au/com/langdale/xmi/EAProjectParser.java index f9b40dbd..d1c4397c 100644 --- a/CIMUtil/src/au/com/langdale/xmi/EAProjectExtractor.java +++ b/CIMUtil/src/au/com/langdale/xmi/EAProjectParser.java @@ -6,9 +6,9 @@ import au.com.langdale.kena.OntModel; -public interface EAProjectExtractor { +public interface EAProjectParser { - public void run() throws EAProjectExtractorException; + public void parse() throws EAProjectParserException; public OntModel getModel(); diff --git a/CIMUtil/src/au/com/langdale/xmi/EAProjectExtractorException.java b/CIMUtil/src/au/com/langdale/xmi/EAProjectParserException.java similarity index 52% rename from CIMUtil/src/au/com/langdale/xmi/EAProjectExtractorException.java rename to CIMUtil/src/au/com/langdale/xmi/EAProjectParserException.java index 78f44fd6..d6b15155 100644 --- a/CIMUtil/src/au/com/langdale/xmi/EAProjectExtractorException.java +++ b/CIMUtil/src/au/com/langdale/xmi/EAProjectParserException.java @@ -4,26 +4,26 @@ */ package au.com.langdale.xmi; -public class EAProjectExtractorException extends Exception { +public class EAProjectParserException extends Exception { private static final long serialVersionUID = 1L; - public EAProjectExtractorException() { + public EAProjectParserException() { } - public EAProjectExtractorException(String message) { + public EAProjectParserException(String message) { super(message); } - public EAProjectExtractorException(Throwable cause) { + public EAProjectParserException(Throwable cause) { super(cause); } - public EAProjectExtractorException(String message, Throwable cause) { + public EAProjectParserException(String message, Throwable cause) { super(message, cause); } - public EAProjectExtractorException(String message, Throwable cause, boolean enableSuppression, + public EAProjectParserException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { super(message, cause, enableSuppression, writableStackTrace); } diff --git a/CIMUtil/src/au/com/langdale/xmi/EAProjectExtractorFactory.java b/CIMUtil/src/au/com/langdale/xmi/EAProjectParserFactory.java similarity index 64% rename from CIMUtil/src/au/com/langdale/xmi/EAProjectExtractorFactory.java rename to CIMUtil/src/au/com/langdale/xmi/EAProjectParserFactory.java index 78fd2d66..cdc327a8 100644 --- a/CIMUtil/src/au/com/langdale/xmi/EAProjectExtractorFactory.java +++ b/CIMUtil/src/au/com/langdale/xmi/EAProjectParserFactory.java @@ -7,23 +7,23 @@ import java.io.File; /** - * Static factory class for creating extractors specialized for specific EA + * Static factory class for creating parsers specialized for specific EA * Project files. * */ -public class EAProjectExtractorFactory { +public class EAProjectParserFactory { - public static EAProjectExtractor createExtractor(File file) { + public static EAProjectParser createParser(File file) { String ext = file.getName().substring(file.getName().lastIndexOf(".") + 1).toLowerCase(); switch (ext) { case "eap": case "eapx": - return new EAPExtractor(file); + return new EAPParser(file); case "qea": case "qeax": - return new QEAExtractor(file); + return new QEAParser(file); case "feap": - return new FEAPExtractor(file); + return new FEAPParser(file); default: throw new IllegalArgumentException("Unsupported EA project file type: " + ext); } diff --git a/CIMUtil/src/au/com/langdale/xmi/FEAPExtractor.java b/CIMUtil/src/au/com/langdale/xmi/FEAPExtractor.java deleted file mode 100644 index d8b32dea..00000000 --- a/CIMUtil/src/au/com/langdale/xmi/FEAPExtractor.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * This software is Copyright 2005,2006,2007,2008 Langdale Consultants. - * Langdale Consultants can be contacted at: http://www.langdale.com.au - */ -package au.com.langdale.xmi; - -import java.io.File; -import java.sql.Connection; -import java.sql.DriverManager; -import java.sql.SQLException; - -public class FEAPExtractor extends AbstractEAProjectDBExtractor { - - private static final String USERNAME = "SYSDBA"; - private static final String PASSWORD = "masterkey"; - - public FEAPExtractor(File file) { - super(file); - } - - @Override - protected void dbInit() throws SQLException { - try { - Class.forName("org.firebirdsql.jdbc.FBDriver"); - } catch (ClassNotFoundException e) { - System.err.println("Firebird JDBC driver not found."); - e.printStackTrace(System.err); - throw new RuntimeException(e); - } - } - - @Override - protected Connection getConnection() throws SQLException { - /** - * The default Firebird DB administrator credentials are SYSDBA/masterkey. EA - * Firebird project files (.feap) can be accessed with these defaults. - */ - String connectionURL = "jdbc:firebirdsql:embedded:" + file.getAbsolutePath(); - return DriverManager.getConnection(connectionURL, USERNAME, PASSWORD); - } - -} diff --git a/CIMUtil/src/au/com/langdale/xmi/FEAPParser.java b/CIMUtil/src/au/com/langdale/xmi/FEAPParser.java new file mode 100644 index 00000000..7085b430 --- /dev/null +++ b/CIMUtil/src/au/com/langdale/xmi/FEAPParser.java @@ -0,0 +1,54 @@ +/* + * This software is Copyright 2005,2006,2007,2008 Langdale Consultants. + * Langdale Consultants can be contacted at: http://www.langdale.com.au + */ +package au.com.langdale.xmi; + +import java.io.File; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.SQLException; + +public class FEAPParser extends AbstractEAProjectDBParsor { + + private static final String USERNAME = "SYSDBA"; + private static final String PASSWORD = "masterkey"; + + public FEAPParser(File file) { + super(file); + } + + @Override + protected void dbInit() throws EAProjectParserException { + try { + Class.forName("org.firebirdsql.jdbc.FBDriver"); + } catch (ClassNotFoundException e) { + System.err.println("Firebird JDBC driver not found."); + e.printStackTrace(System.err); + throw new EAProjectParserException("Unable to import the EA project file: " + file.getAbsolutePath(), + e); + } + } + + @Override + protected void dbShutdown() throws EAProjectParserException { + // Do nothing... + } + + @Override + protected Connection getConnection() throws EAProjectParserException { + /** + * The default Firebird DB administrator credentials are SYSDBA/masterkey. EA + * Firebird project files (.feap) can be accessed with these defaults. + */ + try { + String connectionURL = "jdbc:firebirdsql:embedded:" + file.getAbsolutePath(); + return DriverManager.getConnection(connectionURL, USERNAME, PASSWORD); + } catch (SQLException sqlException) { + sqlException.printStackTrace(System.err); + throw new EAProjectParserException("Unable to import the EA project file: " + file.getAbsolutePath(), + sqlException); + } + } + +} diff --git a/CIMUtil/src/au/com/langdale/xmi/QEAExtractor.java b/CIMUtil/src/au/com/langdale/xmi/QEAExtractor.java deleted file mode 100644 index add014ae..00000000 --- a/CIMUtil/src/au/com/langdale/xmi/QEAExtractor.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * This software is Copyright 2005,2006,2007,2008 Langdale Consultants. - * Langdale Consultants can be contacted at: http://www.langdale.com.au - */ -package au.com.langdale.xmi; - -import java.io.File; -import java.sql.Connection; -import java.sql.DriverManager; -import java.sql.SQLException; - -public class QEAExtractor extends AbstractEAProjectDBExtractor { - - public QEAExtractor(File file) { - super(file); - } - - @Override - protected void dbInit() { - // Nothing to initialize for SQLite as the JDBC Driver is self-registering - } - - @Override - protected Connection getConnection() throws SQLException { - String connectionURL = "jdbc:sqlite:" + file.getAbsolutePath(); - return DriverManager.getConnection(connectionURL); - } -} diff --git a/CIMUtil/src/au/com/langdale/xmi/QEAParser.java b/CIMUtil/src/au/com/langdale/xmi/QEAParser.java new file mode 100644 index 00000000..b88a278d --- /dev/null +++ b/CIMUtil/src/au/com/langdale/xmi/QEAParser.java @@ -0,0 +1,39 @@ +/* + * This software is Copyright 2005,2006,2007,2008 Langdale Consultants. + * Langdale Consultants can be contacted at: http://www.langdale.com.au + */ +package au.com.langdale.xmi; + +import java.io.File; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.SQLException; + +public class QEAParser extends AbstractEAProjectDBParsor { + + public QEAParser(File file) { + super(file); + } + + @Override + protected void dbInit() throws EAProjectParserException { + // Nothing to initialize for SQLite as the JDBC Driver is self-registering + } + + @Override + protected void dbShutdown() throws EAProjectParserException { + // Do nothing... + } + + @Override + protected Connection getConnection() throws EAProjectParserException { + try { + String connectionURL = "jdbc:sqlite:" + file.getAbsolutePath(); + return DriverManager.getConnection(connectionURL); + } catch (SQLException sqlException) { + sqlException.printStackTrace(System.err); + throw new EAProjectParserException("Unable to import the EA project file: " + file.getAbsolutePath(), + sqlException); + } + } +} diff --git a/CIMUtil/src/au/com/langdale/xmi/Translator.java b/CIMUtil/src/au/com/langdale/xmi/Translator.java index 33aa6765..63eea022 100644 --- a/CIMUtil/src/au/com/langdale/xmi/Translator.java +++ b/CIMUtil/src/au/com/langdale/xmi/Translator.java @@ -8,11 +8,6 @@ import org.apache.xerces.util.XMLChar; -import au.com.langdale.kena.ModelFactory; -import au.com.langdale.kena.OntModel; -import au.com.langdale.kena.OntResource; -import au.com.langdale.kena.ResIterator; - import com.hp.hpl.jena.graph.FrontsNode; import com.hp.hpl.jena.graph.Node; import com.hp.hpl.jena.graph.Triple; @@ -21,59 +16,64 @@ import com.hp.hpl.jena.vocabulary.RDFS; import com.hp.hpl.jena.vocabulary.XSD; +import au.com.langdale.kena.ModelFactory; +import au.com.langdale.kena.OntModel; +import au.com.langdale.kena.OntResource; +import au.com.langdale.kena.ResIterator; + /** - * A translator which produces a OWL model with CIM/XML standard naming from - * a OWL model derived from CIM UML. + * A translator which produces a OWL model with CIM/XML standard naming from a + * OWL model derived from CIM UML. */ public class Translator implements Runnable { - + private OntModel model; private OntModel result; private String defaultNamespace; private boolean extraDecoration; private boolean uniqueNamespaces; - + /** * Construct from input model and the namespace for renamed resources. * * @param input the model to be translated. */ - public Translator(OntModel model, String namespace, boolean usePackageNames ) { + public Translator(OntModel model, String namespace, boolean usePackageNames) { this.model = model; OntResource ont = model.getValidOntology(); - if( ont != null ) { + if (ont != null) { defaultNamespace = ont.getURI() + "#"; uniqueNamespaces = true; } else { - defaultNamespace = namespace; - uniqueNamespaces = usePackageNames; - extraDecoration = true; + defaultNamespace = namespace; + uniqueNamespaces = usePackageNames; + extraDecoration = true; } } - + /** * @return Returns the result model. */ public OntModel getModel() { return result; } - + /** * Apply translation to input model, populating the result model. * - * Each statement in the input model is transcribed to the - * result model with some resources substituted. + * Each statement in the input model is transcribed to the result model with + * some resources substituted. */ public void run() { pass1.run(); - + System.out.println("Stage 2 XMI model size: " + getModel().size()); - + propagateAnnotation(UML.baseuri); pass2.run(); } - + private abstract class Pass implements Runnable { protected abstract FrontsNode renameResource(OntResource r, String l); @@ -83,12 +83,10 @@ private abstract class Pass implements Runnable { public void run() { result = ModelFactory.createMem(); Iterator it = model.getGraph().find(Node.ANY, Node.ANY, Node.ANY); - while( it.hasNext()) { + while (it.hasNext()) { Triple s = (Triple) it.next(); - add( - renameResource(model.createResource(s.getSubject())), - renameResource(model.createResource(s.getPredicate())), - renameObject(s.getObject())); + add(renameResource(model.createResource(s.getSubject())), + renameResource(model.createResource(s.getPredicate())), renameObject(s.getObject())); } model = result; } @@ -96,48 +94,47 @@ public void run() { /** * Substitute a single node. * - * If the node is a resource then it is substituted as - * required. If the node is a literal it is preserved. + * If the node is a resource then it is substituted as required. If the node is + * a literal it is preserved. */ protected Node renameObject(Node n) { - if( n.isLiteral()) { + if (n.isLiteral()) { return n; - } - else { + } else { FrontsNode r = renameResource(model.createResource(n)); - return r == null? null: r.asNode(); + return r == null ? null : r.asNode(); } } + /** * Substitute a a single resource. * * @param r the resource to be (possibly) replaced. - * @return the resource that should appear in result - * or null if the resource should not appear in the result. + * @return the resource that should appear in result or null if the resource + * should not appear in the result. */ protected FrontsNode renameResource(OntResource r) { if (r.isAnon()) return r; - + if (!r.getNameSpace().equals(XMI.NS)) return r; - + String ls = r.getString(RDFS.label); if (ls == null) return r; String l = escapeNCName(ls); - if( l.length()==0 ) + if (l.length() == 0) return null; - + return renameResource(r, l); - } + } } - + /** - * This pass translates annotations and stereotypes - * to resources in the UML namespace and packages - * to resources in the defaultNamespace. + * This pass translates annotations and stereotypes to resources in the UML + * namespace and packages to resources in the defaultNamespace. * * These are then available in later passes. */ @@ -146,64 +143,66 @@ protected FrontsNode renameResource(OntResource r) { * Substitute a a single resource. * * @param r the resource to be (possibly) replaced. - * @return the resource that should appear in result - * or null if the resource should not appear in the result. + * @return the resource that should appear in result or null if the resource + * should not appear in the result. */ @Override protected FrontsNode renameResource(OntResource r, String l) { - if (r.hasProperty(RDF.type, UML.Stereotype)) - return result.createResource(UML.NS + l.toLowerCase()); + if (r.hasProperty(RDF.type, UML.Stereotype)) { + OntResource stereotype = result.createResource(UML.NS + l.toLowerCase()); + stereotype.addLabel(l, null); + return stereotype; + } else if (r.hasProperty(RDF.type, OWL.AnnotationProperty)) { return annotationResource(l); } - - else if( r.hasProperty(RDF.type, UML.Package)) { - // there are three strategies evolved over time to assign package URI's - if( uniqueNamespaces ) { - if( extraDecoration ) - return result.createResource(stripHash(defaultNamespace) + "/Global" + pathName(r) + "#Package_" + l); + + else if (r.hasProperty(RDF.type, UML.Package)) { + // there are three strategies evolved over time to assign package URI's + if (uniqueNamespaces) { + if (extraDecoration) + return result.createResource( + stripHash(defaultNamespace) + "/Global" + pathName(r) + "#Package_" + l); else return result.createResource(stripHash(defaultNamespace) + prefixPath(r) + "#" + l); - } - else + } else return result.createResource(defaultNamespace + "Package_" + l); - } - else + } else return r; } }; - + public static String stripHash(String uri) { - while( uri.endsWith("#") || uri.endsWith("/")) - uri = uri.substring(0, uri.length()-1); + while (uri.endsWith("#") || uri.endsWith("/")) + uri = uri.substring(0, uri.length() - 1); return uri; } public static boolean powercc = true;; /** - * Determine whether we are interested in a UML tag of given name - * and return an annotation resource for it. + * Determine whether we are interested in a UML tag of given name and return an + * annotation resource for it. */ public static FrontsNode annotationResource(String l) { if (l.equals("documentation") || l.equals("description")) return RDFS.comment; - else if(l.equals(UML.baseuri.getLocalName())) + else if (l.equals(UML.baseuri.getLocalName())) return UML.baseuri; - else if(l.equals(UML.baseprefix.getLocalName())) + else if (l.equals(UML.baseprefix.getLocalName())) return UML.baseprefix; - else if( powercc ) { - if(l.equals("RationalRose$PowerCC:RdfRoleA")) + else if (powercc) { + if (l.equals("RationalRose$PowerCC:RdfRoleA")) return UML.roleALabel; - else if(l.equals("RationalRose$PowerCC:RdfRoleB")) + else if (l.equals("RationalRose$PowerCC:RdfRoleB")) return UML.roleBLabel; - else if(l.equals("RationalRose$PowerCC:Namespace")) + else if (l.equals("RationalRose$PowerCC:Namespace")) return UML.baseprefix; } return null; // omit other annotations eg 'transient' defined in the UML } - + private static String pathName(OntResource r) { String prefix = prefixPath(r); String ls = r.getString(RDFS.label); @@ -211,46 +210,43 @@ private static String pathName(OntResource r) { return prefix; String l = escapeNCName(ls); - if( l.length()==0 ) + if (l.length() == 0) return prefix; - + return prefix + "/" + l; - + } private static String prefixPath(OntResource r) { OntResource ps = r.getResource(RDFS.isDefinedBy); - if( ps != null && ! ps.equals(UML.global_package)) { + if (ps != null && !ps.equals(UML.global_package)) { return pathName(ps); - } - else { + } else { return ""; } } - /** - * This pass translates anything found with a label and an XMI namespace, - * which would exclude resources translated in earlier passes. - * Special naming rules apply to classes, properties and enumeration members. + * This pass translates anything found with a label and an XMI namespace, which + * would exclude resources translated in earlier passes. Special naming rules + * apply to classes, properties and enumeration members. */ Runnable pass2 = new Pass() { /** * Substitute a a single resource. * * @param r the resource to be (possibly) replaced. - * @return the resource that should appear in result - * or null if the resource should not appear in the result. + * @return the resource that should appear in result or null if the resource + * should not appear in the result. */ @Override protected FrontsNode renameResource(OntResource r, String l) { String namespace = findBaseURI(r); if (r.hasProperty(RDF.type, OWL.Class)) { - if ((r.hasProperty(UML.hasStereotype, UML.datatype) || - r.hasProperty(UML.hasStereotype, UML.cimdatatype) || - r.hasProperty(UML.hasStereotype, UML.primitive)) && - ! r.hasProperty(UML.hasStereotype, UML.enumeration)) { + if ((r.hasProperty(UML.hasStereotype, UML.datatype) || r.hasProperty(UML.hasStereotype, UML.cimdatatype) + || r.hasProperty(UML.hasStereotype, UML.primitive)) + && !r.hasProperty(UML.hasStereotype, UML.enumeration)) { FrontsNode x = selectXSDType(l); if (x != null) return x; @@ -258,8 +254,7 @@ protected FrontsNode renameResource(OntResource r, String l) { return result.createResource(namespace + l); } - if (r.hasProperty(RDF.type, OWL.ObjectProperty) - || r.hasProperty(RDF.type, OWL.DatatypeProperty) + if (r.hasProperty(RDF.type, OWL.ObjectProperty) || r.hasProperty(RDF.type, OWL.DatatypeProperty) || r.hasProperty(RDF.type, RDF.Property)) { OntResource ds = r.getResource(RDFS.domain); if (ds != null) { @@ -271,137 +266,179 @@ protected FrontsNode renameResource(OntResource r, String l) { } return result.createResource(namespace + "_." + l); } - + for (ResIterator it = r.listProperties(RDF.type); it.hasNext();) { OntResource ts = it.nextResource(); - if( ts.hasProperty(UML.hasStereotype, UML.enumeration)) { + if (ts.hasProperty(UML.hasStereotype, UML.enumeration)) { String ls = ts.getString(RDFS.label); if (ls != null) { - String c = escapeNCName(ls); + String c = escapeNCName(ls); return result.createResource(namespace + c + "." + l); } } } - //System.out.println("Unrecognised UML element name: " + l + " uri: " + r.getURI()); + // System.out.println("Unrecognised UML element name: " + l + " uri: " + + // r.getURI()); // this is almost certainly a top level datatype declaration FrontsNode x = selectXSDType(l); - if( x != null) + if (x != null) return x; - + return result.createResource(namespace + l); } }; - + /** - * Regenerate a statement in the result model with given - * subject, predicate and object. + * Regenerate a statement in the result model with given subject, predicate and + * object. * - * s, p, o are the resources from an input model statement - * with possible substitutions. If any are null (no substitution) - * the original statement is negated. + * s, p, o are the resources from an input model statement with possible + * substitutions. If any are null (no substitution) the original statement is + * negated. */ protected void add(FrontsNode s, FrontsNode p, Node o) { - if(s != null && p != null && o != null ) { + if (s != null && p != null && o != null) { result.add(s, p, o); } } + /** * Select XSD datatypes for UML attributes. * - * @param l A simple name for the datatype received from the UML. + * @param l A simple name for the datatype received from the UML. * @return A resource representing one of the XSD datatypes recommended for OWL. */ protected FrontsNode selectXSDType(String l) { // TODO: add more XSD datatypes here - if( l.equalsIgnoreCase("integer")) + if (l.equalsIgnoreCase("integer")) return XSD.integer; - else if( l.equalsIgnoreCase("int")) + else if (l.equalsIgnoreCase("int")) return XSD.xint; - else if( l.equalsIgnoreCase("unsigned")) + else if (l.equalsIgnoreCase("unsigned")) return XSD.unsignedInt; - else if( l.equalsIgnoreCase("ulong") || - l.equalsIgnoreCase("ulonglong")) + else if (l.equalsIgnoreCase("ulong") || l.equalsIgnoreCase("ulonglong")) return XSD.unsignedLong; - else if( l.equalsIgnoreCase("short")) + else if (l.equalsIgnoreCase("short")) return XSD.xshort; - else if( l.equalsIgnoreCase("long")|| - l.equalsIgnoreCase("longlong")) + else if (l.equalsIgnoreCase("long") || l.equalsIgnoreCase("longlong")) return XSD.xlong; - else if( l.equalsIgnoreCase("string") || - l.equalsIgnoreCase("char")) + else if (l.equalsIgnoreCase("string") || l.equalsIgnoreCase("char")) return XSD.xstring; - else if( l.equalsIgnoreCase("float")) + else if (l.equalsIgnoreCase("float")) return XSD.xfloat; - else if( l.equalsIgnoreCase("double") || - l.equalsIgnoreCase("longdouble")) + else if (l.equalsIgnoreCase("double") || l.equalsIgnoreCase("longdouble")) return XSD.xdouble; - else if( l.equalsIgnoreCase("boolean") || - l.equalsIgnoreCase("bool")) + else if (l.equalsIgnoreCase("boolean") || l.equalsIgnoreCase("bool")) return XSD.xboolean; - else if( l.equalsIgnoreCase("decimal")) + else if (l.equalsIgnoreCase("decimal")) return XSD.decimal; - else if( l.equalsIgnoreCase("nonNegativeInteger")) + else if (l.equalsIgnoreCase("nonNegativeInteger")) return XSD.nonNegativeInteger; - else if( l.equalsIgnoreCase("date")) + else if (l.equalsIgnoreCase("date")) return XSD.date; - else if( l.equalsIgnoreCase("time")) + else if (l.equalsIgnoreCase("time")) return XSD.time; - else if( l.equalsIgnoreCase("datetime")) + else if (l.equalsIgnoreCase("datetime")) return XSD.dateTime; - else if( l.equalsIgnoreCase("absolutedatetime")) + else if (l.equalsIgnoreCase("absolutedatetime")) return XSD.dateTime; - else if( l.equalsIgnoreCase("duration")) + else if (l.equalsIgnoreCase("duration")) return XSD.duration; + else if (l.equalsIgnoreCase("monthday")) + return XSD.gMonthDay; + /** + * Below reflects the introduction of the URI primitive domain type in CIM18. + */ + else if (l.equalsIgnoreCase("uri")) + return XSD.anyURI; + /** + * Below reflects the introduction of the UUID primitive domain type in CIM18. + * + * We are using XSD.xstring and not XSD:ID datatype here. This is due to the + * fact that xsd:ID in XML Schema Definition (XSD) is not suitable for + * representing a UUID. Here's why: + * + * Purpose and Constraints: + * + * - xsd:ID is intended to represent a unique identifier within an XML document. + * It must be unique within the document and is generally used for linking with + * xsd:IDREF. + * + * - xsd:ID must follow the rules for XML names, meaning it must start with a + * letter or underscore and cannot contain certain characters, such as hyphens + * (-) or numbers at the beginning. This makes it incompatible with the typical + * structure of UUIDs, which are typically in the form 8-4-4-4-12 hexadecimal + * digits separated by hyphens. + * + * UUID Format: + * + * - A UUID (Universally Unique Identifier) is typically represented as a + * 36-character string, including 32 hexadecimal digits and 4 hyphens. This + * format does not conform to the XML name rules required by xsd:ID. + * + * Alternative: + * + * - Instead of using xsd:ID, we need to use xsd:string with a pattern (i.e. + * facet) or define a custom type with a pattern that matches the UUID format + * such as in this example: + * + * + * + * + * + */ + else if (l.equalsIgnoreCase("uuid")) + return XSD.xstring; else return null; } - + /** - * Convert a string to an NCNAME by substituting underscores for - * invalid characters. + * Convert a string to an NCNAME by substituting underscores for invalid + * characters. */ public static String escapeNCName(String label) { StringBuffer result = new StringBuffer(label.trim()); - for(int ix = 0; ix < result.length(); ix++) { - if( ! XMLChar.isNCName(result.charAt(ix))) + for (int ix = 0; ix < result.length(); ix++) { + if (!XMLChar.isNCName(result.charAt(ix))) result.setCharAt(ix, '_'); } - if(result.length() > 0 && ! XMLChar.isNCNameStart(result.charAt(0))) + if (result.length() > 0 && !XMLChar.isNCNameStart(result.charAt(0))) result.insert(0, '_'); return result.toString(); } - - + /** * Discover the base URI, if given, for a model element. - * @param r an untranslated resource + * + * @param r an untranslated resource * @return a URI */ protected String findBaseURI(OntResource r) { String b = r.getString(UML.baseuri); - if( b != null ) + if (b != null) return b; - + String x = r.getString(UML.baseprefix); - if( x != null ) { + if (x != null) { ResIterator it = model.listSubjectsWithProperty(UML.uriHasPrefix, x); - if( it.hasNext() ) { + if (it.hasNext()) { b = it.nextResource().getURI(); - if( ! b.contains("#")) + if (!b.contains("#")) b += "#"; return b; } } - OntResource p = r.getResource(RDFS.isDefinedBy); - if( p != null ) { + if (p != null) { b = p.getString(UML.baseuri); - if( b != null ) + if (b != null) return b; - if( uniqueNamespaces ) - if( extraDecoration ) + if (uniqueNamespaces) + if (extraDecoration) return p.getNameSpace(); else return stripHash(p.getNameSpace()) + "/" + p.getLocalName() + "#"; @@ -416,7 +453,7 @@ protected String findBaseURI(OntResource r) { */ private void propagateAnnotation(FrontsNode a) { ResIterator it = model.listSubjectsWithProperty(RDF.type, UML.Package); - while( it.hasNext()) + while (it.hasNext()) propagateAnnotation(it.nextResource(), a); } @@ -426,18 +463,19 @@ private void propagateAnnotation(FrontsNode a) { */ private String propagateAnnotation(OntResource p, FrontsNode a) { String v = p.getString(a); - if( v != null ) + if (v != null) { return v; - + } + OntResource s = p.getResource(RDFS.isDefinedBy); - if( s != null ) { - v = propagateAnnotation(s, a); - if( v != null) { + if (s != null) { + v = propagateAnnotation(s, a); + if (v != null) { p.addProperty(a, v); return v; } } - + return null; } } diff --git a/CIMUtil/src/au/com/langdale/xmi/UML.java b/CIMUtil/src/au/com/langdale/xmi/UML.java index 77d952ed..a8710559 100644 --- a/CIMUtil/src/au/com/langdale/xmi/UML.java +++ b/CIMUtil/src/au/com/langdale/xmi/UML.java @@ -51,6 +51,7 @@ public class UML { public final static Resource compound = ResourceFactory.createResource(NS + "compound"); public final static Resource preserve = ResourceFactory.createResource(NS + "preserve"); public final static Resource description = ResourceFactory.createResource(NS + "description"); + public final static Resource hideOnDiagrams = ResourceFactory.createResource(NS + "hideondiagrams"); // stereotype the two forms of aggregation, each in two directions public final static Resource ofComposite = ResourceFactory.createResource(NS + "ofComposite"); @@ -79,6 +80,7 @@ public class UML { stereotypes.put(compound.getLocalName(), compound); stereotypes.put(preserve.getLocalName(), preserve); stereotypes.put(description.getLocalName(), description); + stereotypes.put(hideOnDiagrams.getLocalName(), hideOnDiagrams); stereotypes.put(ofComposite.getLocalName(), ofComposite); stereotypes.put(ofAggregate.getLocalName(), ofAggregate); stereotypes.put(compositeOf.getLocalName(), compositeOf); @@ -126,26 +128,27 @@ public static void loadOntology( OntModel model ) { model.createIndividual(global_package.getURI(), Package); // well known stereotypes - model.createIndividual(enumeration.getURI(), Stereotype).addLabel("Enumeration", null); + model.createIndividual(enumeration.getURI(), Stereotype).addLabel("enumeration", null); model.createIndividual(enumliteral.getURI(), Stereotype).addLabel("enum", null); model.createIndividual(union.getURI(), Stereotype).addLabel("Union", null); - model.createIndividual(extendedBy.getURI(), Stereotype).addLabel("Extended By", null); + model.createIndividual(extendedBy.getURI(), Stereotype).addLabel("ExtendedBy", null); model.createIndividual(extension.getURI(), Stereotype).addLabel("Extension", null); model.createIndividual(primitive.getURI(), Stereotype).addLabel("Primitive", null); model.createIndividual(base.getURI(), Stereotype).addLabel("Base", null); model.createIndividual(cimdatatype.getURI(), Stereotype).addLabel("CIMDatatype", null); model.createIndividual(datatype.getURI(), Stereotype).addLabel("Datatype", null); model.createIndividual(attribute.getURI(), Stereotype).addLabel("Attribute", null); - model.createIndividual(xmlelement.getURI(), Stereotype).addLabel("XML Element", null); - model.createIndividual(xmlattribute.getURI(), Stereotype).addLabel("XML Attribute", null); - model.createIndividual(byreference.getURI(), Stereotype).addLabel("By Reference", null); + model.createIndividual(xmlelement.getURI(), Stereotype).addLabel("XMLElement", null); + model.createIndividual(xmlattribute.getURI(), Stereotype).addLabel("XMLAttribute", null); + model.createIndividual(byreference.getURI(), Stereotype).addLabel("ByReference", null); model.createIndividual(concrete.getURI(), Stereotype).addLabel("Concrete", null); model.createIndividual(compound.getURI(), Stereotype).addLabel("Compound", null); model.createIndividual(preserve.getURI(), Stereotype).addLabel("Preserve", null); - model.createIndividual(ofComposite.getURI(), Stereotype).addLabel("Of Composite", null); - model.createIndividual(ofAggregate.getURI(), Stereotype).addLabel("Of Aggregate", null); - model.createIndividual(compositeOf.getURI(), Stereotype).addLabel("Composite Of", null); - model.createIndividual(aggregateOf.getURI(), Stereotype).addLabel("Aggregate Of", null); + model.createIndividual(hideOnDiagrams.getURI(), Stereotype).addLabel("HideOnDiagrams", null); + model.createIndividual(ofComposite.getURI(), Stereotype).addLabel("OfComposite", null); + model.createIndividual(ofAggregate.getURI(), Stereotype).addLabel("OfAggregate", null); + model.createIndividual(compositeOf.getURI(), Stereotype).addLabel("CompositeOf", null); + model.createIndividual(aggregateOf.getURI(), Stereotype).addLabel("AggregateOf", null); model.createIndividual(description.getURI(), Stereotype).addLabel("Description", null); model.createAnnotationProperty(baseuri.getURI()); diff --git a/CIMUtil/src/au/com/langdale/xmi/XMIModel.java b/CIMUtil/src/au/com/langdale/xmi/XMIModel.java index 7dba736c..c40e2272 100644 --- a/CIMUtil/src/au/com/langdale/xmi/XMIModel.java +++ b/CIMUtil/src/au/com/langdale/xmi/XMIModel.java @@ -176,9 +176,9 @@ protected OntResource createObjectProperty(String xuid, boolean sideA, String na } return null; } - + /** - *Create and label an OWL annotation property + * Create and label an OWL annotation property * for an XMI tag declaration. * * @param element in XMI declaring the property. @@ -231,11 +231,9 @@ protected OntResource createStereotype(String xuid) { * Create or reference a stereotype by name. */ protected OntResource createStereotypeByName(String name) { - if (UML.stereotypes.containsKey(name.toLowerCase())) { - return model.createIndividual(UML.NS + name.toLowerCase(), UML.Stereotype); - } else { - return model.createIndividual(UML.NS + name, UML.Stereotype); - } + OntResource stereotype = model.createIndividual(UML.NS + name.toLowerCase().replaceAll("\\s", ""), UML.Stereotype); + stereotype.addLabel(name, LANG); + return stereotype; } /** @@ -297,7 +295,7 @@ protected OntResource createUnknown(XMLElement element) { String name = atts.getValue("name"); if( xuid != null && name != null ) { OntResource subject = model.createResource(XMI.NS + xuid); - subject.addLabel(name, null); + subject.addLabel(name, LANG); if(keepID) subject.addProperty(UML.id, xuid); return subject; @@ -363,7 +361,7 @@ protected boolean matchDef(XMLElement element, String type) { protected OntResource createGlobalPackage() { OntResource packResource = model.createIndividual(UML.global_package.getURI(), UML.Package); - packResource.addLabel("Global", null); + packResource.addLabel("Global", LANG); return packResource; } @@ -377,6 +375,8 @@ public class Role { public int lower =-1, upper=-1; public boolean composite; public boolean aggregate; + public String baseuri; + public String baseprefix; /** * Interpret this association role in the context of its mate. @@ -405,7 +405,10 @@ public void mate(Role other) { property.addProperty(UML.hasStereotype, UML.compositeOf); if( other.aggregate ) property.addProperty(UML.hasStereotype, UML.aggregateOf); - + if (baseuri != null && !"".equals(baseuri)) + property.addProperty(UML.baseuri, baseuri); + if (baseprefix != null && !"".equals(baseprefix)) + property.addProperty(UML.baseprefix, baseprefix); } } diff --git a/CIMUtil/src/au/com/langdale/xmi/XMIParser.java b/CIMUtil/src/au/com/langdale/xmi/XMIParser.java index 55d60c7e..22e79c6a 100644 --- a/CIMUtil/src/au/com/langdale/xmi/XMIParser.java +++ b/CIMUtil/src/au/com/langdale/xmi/XMIParser.java @@ -7,6 +7,8 @@ import java.io.IOException; import java.io.InputStream; import java.io.StringReader; +import java.util.HashMap; +import java.util.Map; import javax.xml.parsers.FactoryConfigurationError; import javax.xml.parsers.ParserConfigurationException; @@ -20,8 +22,10 @@ import org.xml.sax.XMLReader; import com.hp.hpl.jena.graph.FrontsNode; +import com.hp.hpl.jena.vocabulary.RDF; import au.com.langdale.kena.OntResource; +import au.com.langdale.kena.ResIterator; import au.com.langdale.sax.XMLElement; import au.com.langdale.sax.XMLInterpreter; import au.com.langdale.sax.XMLMode; @@ -31,19 +35,21 @@ public class XMIParser extends XMIModel { /** * Parse the given file as XMI producing an OWL model. */ - public void parse(String fileName) throws IOException, SAXException, ParserConfigurationException, FactoryConfigurationError { + public void parse(String fileName) + throws IOException, SAXException, ParserConfigurationException, FactoryConfigurationError { parse(new InputSource(fileName)); } - public void parse(InputStream stream) throws IOException, SAXException, ParserConfigurationException, FactoryConfigurationError { + public void parse(InputStream stream) + throws IOException, SAXException, ParserConfigurationException, FactoryConfigurationError { parse(new InputSource(stream)); } - + public void parse(InputSource source) throws ParserConfigurationException, SAXException, IOException { - + SAXParserFactory factory = SAXParserFactory.newInstance(); factory.setNamespaceAware(true); - + // trying to stop parser read DTD's // factory.setValidating(false); // factory.setFeature("http://xml.org/sax/features/external-general-entities", false); @@ -51,352 +57,575 @@ public void parse(InputSource source) throws ParserConfigurationException, SAXEx SAXParser parser = factory.newSAXParser(); XMLReader reader = parser.getXMLReader(); - + // still trying to kill attempts to read DTD reader.setEntityResolver(new EntityResolver() { public InputSource resolveEntity(String arg0, String arg1) throws SAXException, IOException { return new InputSource(new StringReader("")); - }}); - - // kick off in global package mode - can vacuum up elements that + } + }); + + // kick off in global package mode - can vacuum up elements that // slip outside the Model element in some XMI dialects reader.setContentHandler(new XMLInterpreter(new PackageMode())); reader.parse(source); } /** - * Base class for all parser modes. + * Base class for all parser modes. */ private abstract class BaseMode implements XMLMode { + + static Map taggedValueNamesMap = new HashMap(); + static Map> packageTaggedValues = new HashMap>(); + + static int indentLevel = 0; + static boolean debug = false; + + protected BaseMode() { + enter(); + } + + protected void enter() { + if (debug) { + indentLevel++; + String spaces = ""; + for (int i = 1; i < indentLevel; i++) + spaces += " "; + System.out.println(spaces + "Start: " + + (getClass().getName().contains("$") + ? getClass().getName().substring(getClass().getName().lastIndexOf("$") + 1) + : getClass().getName())); + } + } + + protected void exit() { + if (debug) { + String spaces = ""; + for (int i = 1; i < indentLevel; i++) + spaces += " "; + System.out.print(spaces + "End: " + + (getClass().getName().contains("$") + ? getClass().getName().substring(getClass().getName().lastIndexOf("$") + 1) + : getClass().getName()) + + " "); + appendText(); + indentLevel--; + } + } + + protected void appendText() { + System.out.println(); // default is just a carriage return... + } + /** - * Common part of visit() for most model elements - * collects annotations and stereotypes. + * Common part of visit() for most model elements collects annotations and + * stereotypes. */ protected XMLMode visit(XMLElement element, OntResource resource) { - - if ( element.matches("TaggedValue")) { + + if (element.matches("TaggedValue")) { return new TaggedValueMode(element, resource); - } - else if( element.matches("Stereotype")) { + } else if (element.matches("Stereotype")) { return new StereotypeMode(element, resource); - } - else if( element.matches("Comment")) { + } else if (element.matches("Comment")) { String comment = element.getAttributes().getValue("body"); - if( comment != null) + if (comment != null) resource.addComment(comment, null); return null; - } - else if( element.matches("Operation")) - return null; + } else if (element.matches("Operation")) + return null; else return this; - + } public void visit(XMLElement element, String text) { // ignore text nodes } - + + /** Default implementation */ + public void leave() { + exit(); + } + + } + + private class ClassifierRoleMode extends BaseMode { + + String name; + + ClassifierRoleMode(XMLElement element) { + name = element.getAttributes().getValue("name"); + if (name != null && !packageTaggedValues.containsKey(name)) + packageTaggedValues.put(name, new HashMap()); + } + + @Override + public XMLMode visit(XMLElement element) { + if (element.matches("TaggedValue")) { + return new TaggedValueMode(element, (OntResource) null); + } else + return visit(element, (OntResource) null); + } + public void leave() { - // no action + super.leave(); + } + + private class TaggedValueMode extends BaseMode { + OntResource subject; + String tagValue; + FrontsNode property; + + TaggedValueMode(XMLElement element) { + this(element, null); + } + + TaggedValueMode(XMLElement element, OntResource resource) { + super(); + subject = resource; + tagValue = element.getAttributes().getValue("value"); + + // in UML 1.3 documentation tags carry the comments + String type = element.getAttributes().getValue("tag"); + + // in UML 1.4 the type is in the name attribute + if (type == null) + type = element.getAttributes().getValue("name"); + + if (type != null) + property = Translator.annotationResource(type); + + // we override the default subject here and in visit() + OntResource ref = createUnknown(element.getAttributes().getValue("modelElement")); + if (ref != null) + subject = ref; + } + + public XMLMode visit(XMLElement element) { + // handle a tag definition or a reference to one + if (element.matches("TagDefinition")) { + OntResource prop = createAnnotationProperty(element); + /** The call to Translator.annotationResource() filters out unused tagged values. */ + if (prop != null) { + if (prop.getLabel() != null) { + if (Translator.annotationResource(prop.getLabel()) != null) + property = prop; + } else if (prop.getLocalName() != null) { + property = prop; + } + } + return null; + } else if (element.matches("TaggedValue.dataValue") || element.matches("TaggedValue.value")) { + return new TaggedValueDataValueMode(); + } else if (element.matches("ModelElement")) { + subject = createUnknown(element.getAttributes().getValue("xmi.idref")); + return null; + } else + return this; + } + + private class TaggedValueDataValueMode extends BaseMode { + + @Override + public void visit(XMLElement element, String text) { + if (tagValue == null) + tagValue = text; + else + tagValue += text; + } + + public XMLMode visit(XMLElement element) { + return this; + } + + } + + @Override + public void leave() { + if (name != null && property != null && tagValue != null) { + packageTaggedValues.get(name).put((OntResource) property, tagValue); + } + super.leave(); + } } } /** - * Interpret a UML tag instance as an owl annotation. + * Interpret a UML tag instance as an owl annotation. */ private class TaggedValueMode extends BaseMode { - OntResource subject; - String tagValue; - FrontsNode property; - - /** - * Construct for an unknown subject (expect a modelElement reference) - */ - TaggedValueMode(XMLElement element) { - this(element, null); - } - - /** - * Construct for a known subject. - */ - TaggedValueMode(XMLElement element, OntResource resource) { - subject = resource; - tagValue = element.getAttributes().getValue("value"); - - // in UML 1.3 documentation tags carry the comments + OntResource subject; + String tagValue; + FrontsNode property; + + /** + * Constructor for an unknown subject (expect a modelElement reference) + */ + TaggedValueMode(XMLElement element) { + this(element, null); + } + + /** + * Construct for a known subject. + */ + TaggedValueMode(XMLElement element, OntResource resource) { + super(); + subject = resource; + tagValue = element.getAttributes().getValue("value"); + + // in UML 1.3 documentation tags carry the comments String type = element.getAttributes().getValue("tag"); - + // in UML 1.4 the type is in the name attribute - if(type == null) + if (type == null) type = element.getAttributes().getValue("name"); - if( type != null ) + if (type != null) property = Translator.annotationResource(type); // we override the default subject here and in visit() - OntResource ref = createUnknown(element.getAttributes().getValue("modelElement")); - if( ref != null) - subject = ref; - } - - public XMLMode visit(XMLElement element) { - - // handle a tag definition or a reference to one - if ( element.matches("TagDefinition")) { - property = createAnnotationProperty(element); - return null; - } - else if ( element.matches("TaggedValue.dataValue") - || element.matches("TaggedValue.value")) { - return new TaggedValueDataValueMode(); - } - else if( element.matches("ModelElement")) { - subject = createUnknown(element.getAttributes().getValue("xmi.idref")); - return null; - } - else - return this; - } - - private class TaggedValueDataValueMode extends BaseMode { - - @Override + OntResource ref = createUnknown(element.getAttributes().getValue("modelElement")); + if (ref != null) + subject = ref; + } + + public XMLMode visit(XMLElement element) { + + // handle a tag definition or a reference to one + if (element.matches("TagDefinition")) { + OntResource prop = createAnnotationProperty(element); + /** The call to Translator.annotationResource() filters out unneeded tagged values. */ + if (prop != null) { + if (prop.getLabel() != null) { + if (Translator.annotationResource(prop.getLabel()) != null) + property = prop; + } else if (prop.getLocalName() != null) { + property = prop; + } + } + return null; + } else if (element.matches("TaggedValue.dataValue") || element.matches("TaggedValue.value")) { + return new TaggedValueDataValueMode(); + } else if (element.matches("ModelElement")) { + subject = createUnknown(element.getAttributes().getValue("xmi.idref")); + return null; + } else + return this; + } + + private class TaggedValueDataValueMode extends BaseMode { + + @Override public void visit(XMLElement element, String text) { - if( tagValue == null ) - tagValue = text; - else - tagValue += text; - } - public XMLMode visit(XMLElement element) { - return this; - } - } - - @Override + if (tagValue == null) + tagValue = text; + else + tagValue += text; + } + + public XMLMode visit(XMLElement element) { + return this; + } + + } + + @Override public void leave() { - if ( tagValue != null && subject != null && property != null) { - subject.addProperty(property, tagValue.trim()); - } - } + if (subject != null && property != null && tagValue != null) { + subject.addProperty(property, tagValue.trim()); + } + super.leave(); + } + } - + /** * Interpret an UML stereotype */ private class StereotypeMode extends BaseMode { private OntResource subject; private OntResource stereo; - + private StereotypeMode(XMLElement element) { this(element, null); } - + private StereotypeMode(XMLElement element, OntResource subject) { this.subject = subject; stereo = createStereotype(element); extend(element); } - + /** * Multiple stereotyped elements */ protected void extend(XMLElement element) { String list = element.getAttributes().getValue("extendedElement"); - if( stereo != null && list != null) { + if (stereo != null && list != null) { subject = null; // forget subject - + // parse list of subjects String[] xuids = list.split(" +"); - for(int ix = 0; ix < xuids.length; ix++) { + for (int ix = 0; ix < xuids.length; ix++) { OntResource given = createUnknown(xuids[ix]); - if( given != null) + if (given != null) given.addProperty(UML.hasStereotype, stereo); } } } - - public XMLMode visit(XMLElement element) { - if( element.matches("ModelElement")) { - subject = null; // forget the given subject - OntResource given = createUnknown(element.getAttributes().getValue("xmi.idref")); - if(stereo != null && given != null) { - given.addProperty(UML.hasStereotype, stereo); - } - } - return this; - } - - /** - * Apply the stereotype to the default subject, if possible. - */ + + public XMLMode visit(XMLElement element) { + if (element.matches("ModelElement")) { + subject = null; // forget the given subject + OntResource given = createUnknown(element.getAttributes().getValue("xmi.idref")); + if (stereo != null && given != null) { + given.addProperty(UML.hasStereotype, stereo); + } + } + return this; + } + + /** + * Apply the stereotype to the default subject, if possible. + */ @Override public void leave() { - if(stereo != null && subject != null) { + if (stereo != null && subject != null) { subject.addProperty(UML.hasStereotype, stereo); } - } + super.leave(); + } + + protected void appendText() { + if (stereo != null && subject != null) { + System.err.println(String.format("%s: stereotype -> %s", subject.getLabel(), stereo)); + } + } + } /** * Parse a UML package and the classes and associations it contains. */ private class PackageMode extends BaseMode { - OntResource packResource; - - /** - * Construct for the top-level package. - */ - PackageMode() { - packResource = createGlobalPackage(); - } - - /** - * Construct for a subordinate package. - */ - PackageMode(XMLElement element, PackageMode parent) { - packResource = createPackage(element); - parent.packageDefines(packResource); - } - - void packageDefines(OntResource res) { - if( ! packResource.equals(UML.global_package)) - res.addIsDefinedBy(packResource); - } - + + OntResource packResource; + + /** + * Construct for the top-level package. + */ + PackageMode() { + packResource = createGlobalPackage(); + packageTaggedValues.clear(); // Reset when global package initialized. + } + + /** + * Construct for a subordinate package. + */ + PackageMode(XMLElement element, PackageMode parent) { + packResource = createPackage(element); + parent.packageDefines(packResource); + /** + * Initialize with an empty taggedValues map keyed off of the package's name. + */ + if (packResource.getLabel() != null && !packageTaggedValues.containsKey(packResource.getLabel())) { + packageTaggedValues.put(packResource.getLabel(), new HashMap()); + } + } + + void packageDefines(OntResource res) { + if (!packResource.equals(UML.global_package)) + res.addIsDefinedBy(packResource); + } + public XMLMode visit(XMLElement element) { - if ( element.matches("Association")) { + if (element.matches("ClassifierRole")) { + return new ClassifierRoleMode(element); + } else if (element.matches("Association")) { return new AssociationMode(element); - } - else if ( matchDef( element, "Class")) { + } else if (matchDef(element, "Class")) { return new ClassMode(element); - } - else if ( matchDef( element, "Enumeration")) { - return new EnumerationMode(element); - } - else if ( matchDef( element, "Package")) { + } else if (matchDef(element, "Enumeration")) { + return new EnumerationMode(element); + } else if (matchDef(element, "Package")) { return new PackageMode(element, this); - } - else if ( matchDef( element, "Component")) { + } else if (matchDef(element, "Component")) { createUnknown(element); return null; - } - else if( matchDef( element, "AssociationClass")) { + } else if (matchDef(element, "AssociationClass")) { // TODO: implement association classes return null; - } - else if ( matchDef(element, "DataType")) { - if(packResource.equals(UML.global_package)) { - createUnknown( element ); // top level datatypes are generally garbage - return null; + } else if (matchDef(element, "DataType")) { + if (packResource.equals(UML.global_package)) { + createUnknown(element); // top level datatypes are generally garbage + return null; + } else + return new DatatypeMode(element); + } else if (element.matches("Generalization")) { + return new GeneralizationMode(element); + } else if (matchDef(element, "TagDefinition")) { + OntResource prop = createAnnotationProperty(element); + String name = element.getAttributes().getValue("name"); + if (name != null && Translator.annotationResource(name) != null) { + if (!taggedValueNamesMap.containsKey(name)) + taggedValueNamesMap.put(name, prop); } - else - return new DatatypeMode( element ); - } - else if ( element.matches("Generalization")) { - return new GeneralizationMode(element); - } - else if ( matchDef( element, "TagDefinition")) { - createAnnotationProperty(element); - return null; - } - else if( element.matches("Stereotype")) { + return null; + } else if (element.matches("Stereotype")) { return new StereotypeMode(element); // pick up stereotype but don't apply to package + /** + * Should we ever need to add support for Stereotypes on Packages simply comment + * out the line above and uncomment the line below to add them to the package. + * Additionally, the AbstractEAProjectDBExtractor.extractPackages() method + * should have the call to addStereotypes(subject, rs.getString(COL_ea_guid)) + * uncommented. + */ + // return new StereotypeMode(element, packResource); // pick up stereotype but don't apply to package + } else if (element.matches("Diagram")) { + return null; // chop off any diagrams + } else if (element.matches("Subsystem")) { + return null; // chop off subsystem definitions + } else + return visit(element, packResource); + } + + public void leave() { + if (packResource.equals(UML.global_package)) { + ResIterator packages = model.listSubjectsWithProperty(RDF.type, UML.Package); + packages.forEachRemaining((p) -> { + OntResource aPackage = (OntResource) p; + String packageName = aPackage.getLabel(); + Map map = packageTaggedValues.get(packageName); + if (map != null && map.size() > 0) { + map.forEach((property, tagValue) -> { + if (property.getLabel() != null) { + aPackage.addProperty(property, tagValue); + } else { + property.setLabel(tagValue, LANG); + } + }); + } + }); } - else if( element.matches("Diagram")) { - return null; //chop off any diagrams - } - else if( element.matches("Subsystem")) { - return null; // chop off subsystem definitions - } - else - return visit(element, packResource); + super.leave(); } /** * Interpret an XMI generalisation as an OWL subClass. */ private class GeneralizationMode extends BaseMode { - OntResource ontChild; - OntResource ontParent; - - GeneralizationMode(XMLElement element) { - ontChild = findClass(element, "child"); - ontParent = findClass(element, "parent"); - } - - public XMLMode visit(XMLElement element) { - if ( element.matches("Generalization.child")) - return new GeneralizationChildMode(); - else if ( element.matches("Generalization.parent")) - return new GeneralizationParentMode(); - else - return this; - } - - private class GeneralizationChildMode extends BaseMode { - public XMLMode visit(XMLElement element) { - if ( element.matches("Class")) { - ontChild = findClass(element); - return null; + OntResource ontChild; + OntResource ontParent; + + GeneralizationMode(XMLElement element) { + ontChild = findClass(element, "child"); + ontParent = findClass(element, "parent"); + } + + public XMLMode visit(XMLElement element) { + if (element.matches("Generalization.child")) + return new GeneralizationChildMode(); + else if (element.matches("Generalization.parent")) + return new GeneralizationParentMode(); + else + return this; + } + + private class GeneralizationChildMode extends BaseMode { + public XMLMode visit(XMLElement element) { + if (element.matches("Class")) { + ontChild = findClass(element); + return null; } return this; } - } - - private class GeneralizationParentMode extends BaseMode { - - public XMLMode visit(XMLElement element) { - if ( element.matches("Class")) { - ontParent = findClass(element); - return null; + } + + private class GeneralizationParentMode extends BaseMode { + + public XMLMode visit(XMLElement element) { + if (element.matches("Class")) { + ontParent = findClass(element); + return null; } return this; } } - - @Override - public void leave() {; - if ( ontChild != null && ontParent != null) { - ontParent.addSubClass(ontChild); - } - } + + @Override + public void leave() { + if (ontChild != null && ontParent != null) { + ontParent.addSubClass(ontChild); + } + super.leave(); + } + } - + /** - * Interpret a UML association as a pair of OWL ObjectProperties. + * Interpret a UML association as a pair of OWL ObjectProperties. */ private class AssociationMode extends BaseMode { - AssociationEndMode endA, endB; - String associd; - OntResource assoc; - - public AssociationMode(XMLElement element) { - associd = element.getAttributes().getValue("xmi.id"); - assoc = createAssocation(associd); - } - + AssociationEndMode endA, endB; + String associd; + OntResource assoc; + + public AssociationMode(XMLElement element) { + associd = element.getAttributes().getValue("xmi.id"); + assoc = createAssocation(associd); + } + public XMLMode visit(XMLElement element) { - if ( element.matches("AssociationEnd")) { + if (element.matches("TaggedValue")) { + return new TaggedValueMode(element, assoc) { + @Override + public void leave() { + if (subject != null && property != null && tagValue != null) { + subject.addProperty(property, tagValue.trim()); + if (UML.baseuri.getLocalName().equals(((OntResource) property).getLabel())) { + subject.addProperty(UML.baseuri, tagValue.trim()); + } else if (UML.baseprefix.getLocalName().equals(((OntResource) property).getLabel())) { + subject.addProperty(UML.baseuri, tagValue.trim()); + } else { + subject.addProperty(property, tagValue.trim()); + } + } + super.leave(); + } + }; + } else if (element.matches("AssociationEnd")) { AssociationEndMode mode = new AssociationEndMode(element, endA == null); - if( endA == null ) - endA = mode; - else - endB = mode; - return mode; + if (endA == null) + endA = mode; + else + endB = mode; + return mode; } return visit(element, assoc); } - + /** * Once recognised, mate the OWL properties. */ @Override public void leave() { - if( endA != null && endB != null) { + if (endA != null && endB != null) { + String baseprefix = assoc.getString(UML.baseprefix); + if (baseprefix != null) { + endA.role.baseprefix = baseprefix; + endB.role.baseprefix = baseprefix; + } + String baseuri = assoc.getString(UML.baseuri); + if (baseuri != null) { + endA.role.baseuri = baseuri; + endB.role.baseuri = baseuri; + } endA.role.mate(endB.role); endB.role.mate(endA.role); } + super.leave(); } /** @@ -404,72 +633,69 @@ public void leave() { */ private class AssociationEndMode extends BaseMode { Role role = new Role(); - - AssociationEndMode( XMLElement element, boolean sideA ) { - role.property = createObjectProperty(element); - if( role.property == null) - role.property = createObjectProperty(element, associd, sideA); - if( role.property != null ) { - packageDefines(role.property); - if( assoc != null ) - role.property.addProperty(sideA? UML.roleAOf: UML.roleBOf, assoc); - } - role.range = findClass( element, "type"); - if( role.range == null ) - role.range = findClass( element, "participant"); - - String agg = element.getAttributes().getValue("aggregation"); - if( agg != null) { - role.composite = agg.equals("composite"); - role.aggregate = agg.equals("aggregate"); - } - } - + + AssociationEndMode(XMLElement element, boolean sideA) { + role.property = createObjectProperty(element); + if (role.property == null) + role.property = createObjectProperty(element, associd, sideA); + if (role.property != null) { + packageDefines(role.property); + if (assoc != null) + role.property.addProperty(sideA ? UML.roleAOf : UML.roleBOf, assoc); + } + role.range = findClass(element, "type"); + if (role.range == null) + role.range = findClass(element, "participant"); + + String agg = element.getAttributes().getValue("aggregation"); + if (agg != null) { + role.composite = agg.equals("composite"); + role.aggregate = agg.equals("aggregate"); + } + } + public XMLMode visit(XMLElement element) { - if ( element.matches("Multiplicity")) + if (element.matches("Multiplicity")) return new MultiplicityMode(); - - else if ( element.matches("Class")) { - role.range = findClass(element); - return null; - } - else if( role.property != null) - return visit(element, role.property); - else - return null; + + else if (element.matches("Class")) { + role.range = findClass(element); + return null; + } else if (role.property != null) + return visit(element, role.property); + else + return null; } - - + /** * Collect multiplicity information for one association end. */ private class MultiplicityMode extends BaseMode { public XMLMode visit(XMLElement element) { - if ( element.matches("MultiplicityRange")) { - Attributes attrs = element.getAttributes(); - role.lower = number(attrs, "lower"); - role.upper = number(attrs, "upper"); + if (element.matches("MultiplicityRange")) { + Attributes attrs = element.getAttributes(); + role.lower = number(attrs, "lower"); + role.upper = number(attrs, "upper"); return null; } return this; } - + /** - * Interpret a multiplicity attribute as a decimal. + * Interpret a multiplicity attribute as a decimal. */ int number(Attributes atts, String name) { String value = atts.getValue(name); - if( value != null ) { + if (value != null) { try { return Integer.parseInt(value); - } catch( NumberFormatException e) { + } catch (NumberFormatException e) { return -1; } - } - else + } else return -1; } - } + } } } @@ -477,24 +703,25 @@ int number(Attributes atts, String name) { * Interpret a UML enumeration as an OWL Class plus individuals. */ private class EnumerationMode extends BaseMode { - OntResource classResource; + OntResource classResource; + public EnumerationMode(XMLElement element) { classResource = createClass(element); classResource.addProperty(UML.hasStereotype, UML.enumeration); packageDefines(classResource); } - + public XMLMode visit(XMLElement element) { - if ( matchDef( element, "EnumerationLiteral")) + if (matchDef(element, "EnumerationLiteral")) return new IndividualMode(element); - else + else return visit(element, classResource); } - + private class IndividualMode extends BaseMode { OntResource indivResource; - + public IndividualMode(XMLElement element) { indivResource = createIndividual(element, classResource); } @@ -504,89 +731,85 @@ public XMLMode visit(XMLElement element) { } } } - + /** * Interpret a UML class as an OWL class. */ private class ClassMode extends BaseMode { - OntResource classResource; - - ClassMode (XMLElement element) { + OntResource classResource; + + ClassMode(XMLElement element) { classResource = createClass(element); Attributes atts = element.getAttributes(); String sxuid = atts.getValue("stereotype"); - if( sxuid != null ) { + if (sxuid != null) { classResource.addProperty(UML.hasStereotype, createStereotype(sxuid)); } packageDefines(classResource); } - + public XMLMode visit(XMLElement element) { - if ( matchDef( element, "Attribute")) + if (matchDef(element, "Attribute")) return new AttributeMode(element); - else if ( element.matches("Generalization")) - return new GeneralizationMode(element); + else if (element.matches("Generalization")) + return new GeneralizationMode(element); - else + else return visit(element, classResource); } /** * Interpret a UML attribute as an OWL property. * - * Make this a datatype property if the - * object is marked as a UML data type. - * Otherwise, leave the propertype open - * for later assignment in stereotype processing. + * Make this a datatype property if the object is marked as a UML data type. + * Otherwise, leave the propertype open for later assignment in stereotype + * processing. */ private class AttributeMode extends BaseMode { - OntResource attrResource; - + OntResource attrResource; + AttributeMode(XMLElement element) { - attrResource =createAttributeProperty(element); + attrResource = createAttributeProperty(element); attrResource.addDomain(classResource); packageDefines(attrResource); OntResource type = findResource(element, "type"); - if( type != null) + if (type != null) attrResource.addRange(type); } - + public XMLMode visit(XMLElement element) { - if ( element.matches("Class") || element.matches("Classifier") || element.matches("DataType")) { + if (element.matches("Class") || element.matches("Classifier") || element.matches("DataType")) { OntResource type = findResource(element); - if( type != null) + if (type != null) attrResource.addRange(type); - if ( element.matches("DataType")) + if (element.matches("DataType")) attrResource.convertToDatatypeProperty(); return null; - } - else if( element.matches("Expression")) { - String value = element.getAttributes().getValue("body"); - if( value != null ) { - value = value.trim(); - while( value.startsWith("\"") && value.endsWith("\"") - || value.endsWith("'") && value.endsWith("'")) { - value = value.substring(1, value.length()-1).trim(); - } - if(value.length() > 0) - attrResource.addProperty(UML.hasInitialValue, value); - } - return null; - } - else + } else if (element.matches("Expression")) { + String value = element.getAttributes().getValue("body"); + if (value != null) { + value = value.trim(); + while (value.startsWith("\"") && value.endsWith("\"") + || value.endsWith("'") && value.endsWith("'")) { + value = value.substring(1, value.length() - 1).trim(); + } + if (value.length() > 0) + attrResource.addProperty(UML.hasInitialValue, value); + } + return null; + } else return visit(element, attrResource); } } } - + private class DatatypeMode extends ClassMode { DatatypeMode(XMLElement element) { super(element); classResource.addProperty(UML.hasStereotype, UML.datatype); } - } } diff --git a/Kena/META-INF/MANIFEST.MF b/Kena/META-INF/MANIFEST.MF index f7df5837..a59fc8ae 100644 --- a/Kena/META-INF/MANIFEST.MF +++ b/Kena/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: Kena Bundle-SymbolicName: au.com.langdale.kena -Bundle-Version: 3.3.2.qualifier +Bundle-Version: 3.3.3 Bundle-Vendor: Langdale Consultants Bundle-RequiredExecutionEnvironment: JavaSE-20 Bundle-ClassPath: kena.jar, diff --git a/Kena/src/au/com/langdale/sax/XMLInterpreter.java b/Kena/src/au/com/langdale/sax/XMLInterpreter.java index bd670995..af50597d 100644 --- a/Kena/src/au/com/langdale/sax/XMLInterpreter.java +++ b/Kena/src/au/com/langdale/sax/XMLInterpreter.java @@ -9,24 +9,32 @@ import org.xml.sax.helpers.DefaultHandler; /** - * A SAX Content handler that delegates to an XMLMode - * object or objects, and maintains a stack of XMLElements. + * A SAX Content handler that delegates to an XMLMode object or objects, and + * maintains a stack of XMLElements. * - */ + */ public class XMLInterpreter extends DefaultHandler { private Element top; + private XMLMode initialMode; private XMLMode mode; - public XMLInterpreter(XMLMode initialMode) { - mode = initialMode; + + public XMLInterpreter(XMLMode mode) { + this.initialMode = mode; + this.mode = initialMode; + } + + @Override + public void endDocument() throws SAXException { + this.initialMode.leave(); } - + protected class Element implements XMLElement { private String name; private String namespace; private Attributes atts; private Element parent; private XMLMode creation_mode; - + public Element(String namespace, String name, Attributes atts) { this.name = name; this.namespace = namespace; @@ -34,96 +42,70 @@ public Element(String namespace, String name, Attributes atts) { parent = top; creation_mode = mode; } - + public XMLElement getParent() { return parent; } - - /* (non-Javadoc) - * @see au.com.Langdale.sax.XMLElement#getAttributes() - */ + public Attributes getAttributes() { return atts; } - /* (non-Javadoc) - * @see au.com.Langdale.sax.XMLElement#getName() - */ public String getName() { return name; } - /* (non-Javadoc) - * @see au.com.Langdale.sax.XMLElement#getNameSpace() - */ public String getNameSpace() { return namespace; } - /* (non-Javadoc) - * @see au.com.Langdale.sax.XMLElement#getValue(java.lang.String, java.lang.String) - */ public String getValue(String namespace, String name) { return atts.getValue(namespace, name); } public void pop() { - if( mode != creation_mode) { - if ( mode != null ) + if (mode != creation_mode) { + if (mode != null) mode.leave(); mode = creation_mode; } top = parent; } - + public boolean matches(String ns, String local) { - return namespace.equals( ns ) && name.equals( local ); + return namespace.equals(ns) && name.equals(local); } public boolean matches(String local) { - return name.equals( local ); + return name.equals(local); } - /* (non-Javadoc) - * @see au.com.Langdale.sax.XMLElement#matches(au.com.Langdale.sax.XMLElement, java.lang.String, java.lang.String) - */ public boolean matches(XMLElement parent, String namespace, String name) { - // TODO Auto-generated method stub return false; } - /* (non-Javadoc) - * @see au.com.Langdale.sax.XMLElement#matches(au.com.Langdale.sax.XMLElement, java.lang.String) - */ + public boolean matches(XMLElement parent, String name) { - // TODO Auto-generated method stub return false; } } @Override - public void startElement( - String uri, - String localName, - String qName, - Attributes attributes) - throws SAXException { - top = new Element( uri, localName, attributes ); - if( mode != null) - mode = mode.visit( top ); + public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { + top = new Element(uri, localName, attributes); + if (mode != null) + mode = mode.visit(top); } - + @Override - public void characters(char[] ch, int start, int length) - throws SAXException { - if( mode != null ) { + public void characters(char[] ch, int start, int length) throws SAXException { + if (mode != null) { String text = String.copyValueOf(ch, start, length); - mode.visit( top, text); + mode.visit(top, text); } } @Override - public void endElement(String uri, String localName, String qName) - throws SAXException { + public void endElement(String uri, String localName, String qName) throws SAXException { top.pop(); } } diff --git a/RCPUtil/META-INF/MANIFEST.MF b/RCPUtil/META-INF/MANIFEST.MF index 543a3703..3ae1d376 100644 --- a/RCPUtil/META-INF/MANIFEST.MF +++ b/RCPUtil/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: RCPUtil Bundle-SymbolicName: au.com.langdale.rcputil -Bundle-Version: 2.3.1.qualifier +Bundle-Version: 2.2.0 Bundle-Vendor: Langdale Consultants Require-Bundle: org.eclipse.core.runtime, org.eclipse.jface;bundle-version="3.5.0", diff --git a/README.md b/README.md index e2212ab2..1af11d36 100644 --- a/README.md +++ b/README.md @@ -36,9 +36,9 @@ For further details on how to use CIMTool to create and edit profiles based on t ## Latest Release - - 2.1.0 + - 2.2.0 - - The latest release is available here on GitHub at [CIMTool-2.1.0](https://github.com/ucaiug/CIMTool/releases) and is delivered as a ZIP file. Releases are also made available in the CIMug [tools download folder](https://cimug.ucaiug.org/Standards%20Artifacts/Forms/AllItems.aspx?RootFolder=%2FStandards%20Artifacts%2FUCA%20TF%20Tools&FolderCTID=0x0120001062F2F1DF27704DBB748ABBDC3B3AA2&View=%7BFEBD8EE1%2D6B40%2D42F6%2DB228%2DCCF131291FBE%7D) on the UCAIug website. + - The latest release is available here on GitHub at [CIMTool-2.2.0](https://github.com/ucaiug/CIMTool/releases) and is delivered as a ZIP file. Releases are also made available in the CIMug [tools download folder](https://cimug.ucaiug.org/Standards%20Artifacts/Forms/AllItems.aspx?RootFolder=%2FStandards%20Artifacts%2FUCA%20TF%20Tools&FolderCTID=0x0120001062F2F1DF27704DBB748ABBDC3B3AA2&View=%7BFEBD8EE1%2D6B40%2D42F6%2DB228%2DCCF131291FBE%7D) on the UCAIug website. - Information on features and fixes for the release can be found [here](https://cimtool.ucaiug.io/release-notes). ## Installation & Setup diff --git a/com.cimphony.cimtoole/META-INF/MANIFEST.MF b/com.cimphony.cimtoole/META-INF/MANIFEST.MF index 2bc9e071..0ffb197a 100644 --- a/com.cimphony.cimtoole/META-INF/MANIFEST.MF +++ b/com.cimphony.cimtoole/META-INF/MANIFEST.MF @@ -8,7 +8,7 @@ Bundle-RequiredExecutionEnvironment: JavaSE-20 Require-Bundle: org.eclipse.emf.ecore;bundle-version="2.5.0", org.eclipse.emf;bundle-version="2.5.0", au.com.langdale.cimutil;bundle-version="1.8.2", - au.com.langdale.rcputil;bundle-version="2.1.0", + au.com.langdale.rcputil;bundle-version="2.2.0", org.eclipse.core.resources, org.eclipse.core.runtime, au.com.langdale.kena,