Hello all,
I got question concerning programatic approach to defing EMF models and
applying profiles.
I have problem with applying UML2 profile stereotypes to an Elements of
the UML2 Model.
Based on the following specifications:
http://www.eclipse.org/modeling/mdt/uml2/docs/articles/Getting_Started_with_UML2/article.html
and
http://www.eclipse.org/modeling/mdt/uml2/docs/articles/Introduction_to_UML2_Profiles/article.html
I've defined:
1. Model with: package1, package2 in package1, class in package1,
attributes and operations in class.
2. and a Profile with stereotypes.
Every time when I want to apply stereotype using
'applyStereotype(UMLElement, Stereotype)' I got an error:
"java.lang.IllegalArgumentException:
org.eclipse.uml2.uml.internal.impl.StereotypeImpl@19f332b (
name: @Stereotype, visibility: <unset>) (isLeaf: false, isAbstract:
true) (isActive: false)
at
org.eclipse.uml2.uml.internal.operations.ElementOperations.applyStereotype(ElementOperations.java:1411)
at
org.eclipse.uml2.uml.internal.impl.ElementImpl.applyStereotype(ElementImpl.java:499)
...."
The following code snipped shows what Im doing now :
protected static void registerPathmaps(URI uri) {
URIConverter.URI_MAP.put(URI.createURI(UMLResource.LIBRARIES_PATHMAP),
uri.appendSegment("libraries").appendSegment(""));
URIConverter.URI_MAP.put(URI.createURI(UMLResource.METAMODELS_PATHMAP),
uri.appendSegment("metamodels").appendSegment(""));
URIConverter.URI_MAP.put(URI.createURI(UMLResource.PROFILES_PATHMAP),
uri.appendSegment("profiles").appendSegment(""));
}
protected static void registerResourceFactories() {
Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put(
UMLResource.FILE_EXTENSION, UMLResource.Factory.INSTANCE);
}
-------------------------------------------------------------------
URI uri = URI.createURI("file://home/mario/model.profile/resource");
/* Part1: MODEL - model was creating properly */
// creating model, packages, class, attributes and operations
Model model = createModel("Model"); //Model
createPackages("package1"); //Model::package1
createPackages("package2"); //Model::package1::package2
createClass("Class"); //Model::package1:package2::Class
createAttribute("attribute1")
//Model::package1:package2::Class::attribute1
createAttribute("attribute2")
//Model::package1:package2::Class::attribute2
createMethods("method1"); //Model::package1:package2::Class::method1
createMethods("method2"); ////Model::package1:package2::Class::method2
registerResourceFactories();
registerPathmaps(URI.createURI("jar:file:/home/mario/Programy/eclipse/plugins/org.eclipse.uml2.uml.resources_3.0.0.v200906011111.jar!/"));
writer.saveModel(model,
uri.appendSegment(model.getNam()).appendFileExtension(UMLResource.FILE_EXTENSION));
/* Part2: PROFILE - I got also properly generated and saved Profile*/
// creating Profile
Profile profileFromReader = createProfile("Profile");
// importing primitive Type
Type stringType = importPrimitiveType(profileFromReader, "String");
Type boolType = importPrimitiveType(profileFromReader, "Boolean");
// meta-classes
Class propertyMetaClass = referenceMetaclass(profileFromReader,
UMLPackage.Literals.PROPERTY.getName());
Class packageMetaClass = referenceMetaclass(profileFromReader,
UMLPackage.Literals.PACKAGE.getName());
// stereotype examplewith with with
Stereotype stereotype = createStereotype(profileFromReader,
"@Stereotype", true);
// stereotype property
Property stereotypeProperty1 = stereotypeProperty =
writer.writeAttribute(stereotype, "attributeStereo1", boolType, 0, 1);
Property stereotypeProperty = writer.writeAttribute(stereotype,
"attributeStereo2", stringType, 0, 1);
// creating extensions
createExtension(propertyMetaClass, stereotype, false);
createExtension(packageMetaClass, stereotype, false);
// defining Profile
writer.defineProfile(profileFromReader);
// saving Profile
saveProfile(profileFromReader,
uri.appendSegment("ProfileEx").appendFileExtension(UMLResource.PROFILE_FILE_EXTENSION));
// loading model and standard profiles (ecore and standard)
Model modelLoaded = (Model)
load(uri.appendSegment(model.getName()).appendFileExtension(UMLResource.FILE_EXTENSION));
Profile ecoreProfile = (Profile)
load(URI.createURI("pathmap://UML_PROFILES/Ecore.profile.uml"));
Profile standardProfile = (Profile)
load(URI.createURI("pathmap://UML_PROFILES/Standard.profile.uml"));
// applying ecore, standard and my profiles
if(!model.isProfileApplied(ecoreProfile))
writer.applyProfile(modelLoaded, ecoreProfile);
if(!model.isProfileApplied(standardProfile))
writer.applyProfile(modelLoaded, standardProfile);
if(!modelLoaded.isProfileApplied(profileFromReader))
writer.applyProfile(modelLoaded, profileFromReader);
// HERE IS AN ISSUE :/
// no matter if first parameter is Package, Class or Attribute... I got
IllegalArgumentException
applyStereotype(package1, stereotype)
applyStereotype(class, stereotype)
applyStereotype(attribute1, stereotype)
I've no idea what's wrong.... I've beed checking and comparing code with
introduction from website several time. obviously I've searching for the
answer on the forums but coudn't find for that case....
Could someone help me? Maybe I'm doing sth with wrong order?
Cheers,
Mario
_______________________________________________
emf-dev mailing list
emf-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/emf-dev