Task 747: .UMP File Format
Task 747: .UMP File Format
.UMP File Format Specifications
The .UMP file format is the Umple Model File, used by the Umple model-oriented programming language to define models in a text-based syntax that combines UML concepts with code.
1. List of All Properties Intrinsic to the .UMP File Format
The following is a comprehensive list of directives, elements, and properties that can appear in a .UMP file, based on the Umple user manual. These are the structural components that define the format.
Top-Level Directives
use: Incorporates other Umple files.namespace: Divides code into logical groups.generate: Specifies code generation targets.suboption: Sets sub-options for generation or configuration.distribute: Configures distribution settings.generate_path: Specifies output path for generated code.filter: Applies filtering during code generation.glossary: Defines a glossary for documentation.checkForUnintendedBracket: Detects mismatched brackets.requirement: Declares a system requirement.reqImplementation: Provides requirement implementation details.tracerDirective: Configures tracing.debug: Enables debugging features.strictness: Sets validation strictness level.toplevelExtracode: Inserts extra code at top level.toplevelException: Defines top-level exceptions.
Entity Definitions
classDefinition: Defines a class with attributes, methods, etc.interfaceDefinition: Defines an interface.traitDefinition: Defines a reusable trait.externalDefinition: References external classes.associationDefinition: Defines associations between classes.associationClassDefinition: Defines an association class.stateMachineDefinition: Defines a state machine.enumerationDefinition: Defines an enumeration.templateDefinition: Defines generic templates.mixsetDefinition: Defines a mixset of features.mixsetIsFeature: Marks a mixset as a feature.requireStatement: Declares dependencies.fixml: Embeds FIXML constructs.toplevelCodeInjection: Injects code at top level.
Supporting Elements and Properties
- Attributes: Data fields with properties like multiplicity, laziness, derivation, uniqueness.
- Associations: Relationships with multiplicity, roles, reflexivity, composition, sorting.
- State Machines: States, transitions, events, guards, actions, concurrency.
- Methods: User-defined operations.
- Traits Features: Attributes, associations, state machines, methods in traits.
- Comments: Inline, multiline, annotation comments.
- Namespaces Options: Configurations for namespaces.
- Grammar-Level Constructs:
program,directive,entity,useProgram,umpleProgram.
2. Two Direct Download Links for .UMP Files
- https://raw.githubusercontent.com/umple/umple/master/umplewww/cruise.umple.org/examples/AirlineExample.ump
- https://raw.githubusercontent.com/umple/umple/master/umplewww/cruise.umple.org/examples/AccessControlExample.ump
3. Ghost Blog Embedded HTML JavaScript for Drag and Drop .UMP File Dump
The following is an HTML page with embedded JavaScript that allows dragging and dropping a .UMP file. It reads the file, parses it to extract properties (such as classes, attributes, associations, and other directives), and dumps them to the screen.
4. Python Class for .UMP File Handling
The following Python class can open, decode (parse), read, write, and print properties to the console.
import re
class UMPHandler:
def __init__(self, filepath):
self.filepath = filepath
self.content = None
self.properties = None
def read(self):
with open(self.filepath, 'r') as f:
self.content = f.read()
def decode(self):
if not self.content:
self.read()
self.properties = {
'classes': re.findall(r'class\s+(\w+)\s*{', self.content),
'attributes': re.findall(r'(\w+)\s+(\w+);', self.content),
'associations': re.findall(r'(\d+)\s+--\s+(\d+)\s+(\w+);', self.content),
'other_directives': re.findall(r'(use|namespace|generate)\s+([^;]+);', self.content)
}
def print_properties(self):
if not self.properties:
self.decode()
print("Classes:", self.properties['classes'])
print("Attributes:", self.properties['attributes'])
print("Associations:", self.properties['associations'])
print("Other Directives:", self.properties['other_directives'])
def write(self, new_filepath=None):
if new_filepath is None:
new_filepath = self.filepath
with open(new_filepath, 'w') as f:
f.write(self.content)
# Example usage:
# handler = UMPHandler('example.ump')
# handler.print_properties()
5. Java Class for .UMP File Handling
The following Java class can open, decode (parse), read, write, and print properties to the console.
import java.io.*;
import java.util.regex.*;
import java.util.*;
public class UMPHandler {
private String filepath;
private String content;
private Map<String, List<Object>> properties;
public UMPHandler(String filepath) {
this.filepath = filepath;
this.content = null;
this.properties = new HashMap<>();
}
public void read() throws IOException {
BufferedReader reader = new BufferedReader(new FileReader(filepath));
StringBuilder sb = new StringBuilder();
String line;
while ((line = reader.readLine()) != null) {
sb.append(line).append("\n");
}
reader.close();
content = sb.toString();
}
public void decode() throws IOException {
if (content == null) {
read();
}
properties.put("classes", findMatches("class\\s+(\\w+)\\s*\\{", 1));
properties.put("attributes", findMatches("(\\w+)\\s+(\\w+);", 2));
properties.put("associations", findMatches("(\\d+)\\s+--\\s+(\\d+)\\s+(\\w+);", 3));
properties.put("other_directives", findMatches("(use|namespace|generate)\\s+([^;]+);", 2));
}
private List<Object> findMatches(String regex, int groups) {
List<Object> matches = new ArrayList<>();
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(content);
while (matcher.find()) {
if (groups == 1) {
matches.add(matcher.group(1));
} else {
List<String> groupList = new ArrayList<>();
for (int i = 1; i <= groups; i++) {
groupList.add(matcher.group(i));
}
matches.add(groupList);
}
}
return matches;
}
public void printProperties() throws IOException {
if (properties.isEmpty()) {
decode();
}
System.out.println("Classes: " + properties.get("classes"));
System.out.println("Attributes: " + properties.get("attributes"));
System.out.println("Associations: " + properties.get("associations"));
System.out.println("Other Directives: " + properties.get("other_directives"));
}
public void write(String newFilepath) throws IOException {
if (newFilepath == null) {
newFilepath = filepath;
}
BufferedWriter writer = new BufferedWriter(new FileWriter(newFilepath));
writer.write(content);
writer.close();
}
// Example usage:
// public static void main(String[] args) throws IOException {
// UMPHandler handler = new UMPHandler("example.ump");
// handler.printProperties();
// }
}
6. JavaScript Class for .UMP File Handling
The following JavaScript class (for Node.js) can open, decode (parse), read, write, and print properties to the console.
const fs = require('fs');
class UMPHandler {
constructor(filepath) {
this.filepath = filepath;
this.content = null;
this.properties = null;
}
read() {
this.content = fs.readFileSync(this.filepath, 'utf8');
}
decode() {
if (!this.content) {
this.read();
}
this.properties = {
classes: this.content.match(/class\s+(\w+)\s*\{/g) || [].map(m => m.replace(/class\s+(\w+)\s*\{/, '$1')),
attributes: this.content.match(/(\w+)\s+(\w+);/g) || [].map(m => m.match(/(\w+)\s+(\w+);/).slice(1)),
associations: this.content.match(/(\d+)\s+--\s+(\d+)\s+(\w+);/g) || [].map(m => m.match(/(\d+)\s+--\s+(\d+)\s+(\w+);/).slice(1)),
other_directives: this.content.match(/(use|namespace|generate)\s+([^;]+);/g) || [].map(m => m.match(/(use|namespace|generate)\s+([^;]+);/).slice(1))
};
}
printProperties() {
if (!this.properties) {
this.decode();
}
console.log('Classes:', this.properties.classes);
console.log('Attributes:', this.properties.attributes);
console.log('Associations:', this.properties.associations);
console.log('Other Directives:', this.properties.other_directives);
}
write(newFilepath = this.filepath) {
fs.writeFileSync(newFilepath, this.content);
}
}
// Example usage:
// const handler = new UMPHandler('example.ump');
// handler.printProperties();
7. C++ Class for .UMP File Handling
The following C++ class can open, decode (parse), read, write, and print properties to the console. (Uses <regex> for parsing.)
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <regex>
class UMPHandler {
private:
std::string filepath;
std::string content;
struct Properties {
std::vector<std::string> classes;
std::vector<std::vector<std::string>> attributes;
std::vector<std::vector<std::string>> associations;
std::vector<std::vector<std::string>> other_directives;
} properties;
public:
UMPHandler(const std::string& fp) : filepath(fp) {}
void read() {
std::ifstream file(filepath);
std::string line;
content.clear();
while (std::getline(file, line)) {
content += line + "\n";
}
file.close();
}
void decode() {
if (content.empty()) {
read();
}
std::regex classRegex("class\\s+(\\w+)\\s*\\{");
std::regex attrRegex("(\\w+)\\s+(\\w+);");
std::regex assocRegex("(\\d+)\\s+--\\s+(\\d+)\\s+(\\w+);");
std::regex dirRegex("(use|namespace|generate)\\s+([^;]+);");
std::smatch match;
std::string::const_iterator searchStart(content.cbegin());
while (std::regex_search(searchStart, content.cend(), match, classRegex)) {
properties.classes.push_back(match[1]);
searchStart = match.suffix().first;
}
searchStart = content.cbegin();
while (std::regex_search(searchStart, content.cend(), match, attrRegex)) {
properties.attributes.push_back({match[1], match[2]});
searchStart = match.suffix().first;
}
searchStart = content.cbegin();
while (std::regex_search(searchStart, content.cend(), match, assocRegex)) {
properties.associations.push_back({match[1], match[2], match[3]});
searchStart = match.suffix().first;
}
searchStart = content.cbegin();
while (std::regex_search(searchStart, content.cend(), match, dirRegex)) {
properties.other_directives.push_back({match[1], match[2]});
searchStart = match.suffix().first;
}
}
void printProperties() {
if (properties.classes.empty() && properties.attributes.empty()) {
decode();
}
std::cout << "Classes: ";
for (const auto& cls : properties.classes) std::cout << cls << " ";
std::cout << std::endl;
std::cout << "Attributes: ";
for (const auto& attr : properties.attributes) std::cout << "(" << attr[0] << ", " << attr[1] << ") ";
std::cout << std::endl;
std::cout << "Associations: ";
for (const auto& assoc : properties.associations) std::cout << "(" << assoc[0] << ", " << assoc[1] << ", " << assoc[2] << ") ";
std::cout << std::endl;
std::cout << "Other Directives: ";
for (const auto& dir : properties.other_directives) std::cout << "(" << dir[0] << ", " << dir[1] << ") ";
std::cout << std::endl;
}
void write(const std::string& newFilepath = "") {
std::string outPath = newFilepath.empty() ? filepath : newFilepath;
std::ofstream file(outPath);
file << content;
file.close();
}
};
// Example usage:
// int main() {
// UMPHandler handler("example.ump");
// handler.printProperties();
// return 0;
// }