Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » UML2 » Re: ApplyStereotype method - issue
Re: ApplyStereotype method - issue [message #628330] Sun, 21 March 2010 06:26
Ed Merks is currently offline Ed Merks
Messages: 26014
Registered: July 2009
Senior Member
Mario,

It's best to ask UML-specific question on the UML newsgroup/forum, which
I've added to the "to" list of the reply, so no need to repost.


mario wrote:
> 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/Getti ng_Started_with_UML2/article.html
> and
> http://www.eclipse.org/modeling/mdt/uml2/docs/articles/Intro duction_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:
> mailto: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.a
> pplyStereotype(ElementOperations.java:1411)
> at org.eclipse.uml2.uml.internal.impl.ElementImpl.applyStereoty
> pe(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.METAMODEL S_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.um l2.uml.resources_3.0.0.v200906011111.jar!/ "));
>
>
> writer.saveModel(model,
> uri.appendSegment(model.getNam()).appendFileExtension(UMLRes ource.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
Previous Topic:How to use existing java classes as Types in uml
Next Topic:Re: ApplyStereotype method - issue
Goto Forum:
  


Current Time: Sat Aug 30 18:39:50 EDT 2014

Powered by FUDForum. Page generated in 0.01999 seconds