1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
| ResourceSet metaResourceSet = new ResourceSetImpl();
metaResourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap()
.put("uml", new UMLResourceFactoryImpl());
Resource metaResource = metaResourceSet.createResource(URI.createURI("./bookUML.uml"));
Model model = UMLFactory.eINSTANCE.createModel();
String name = "test";
model.setName(name);
String packageName = "library";
org.eclipse.uml2.uml.Package package_ = model.createNestedPackage(packageName);
Profile profile = UMLFactory.eINSTANCE.createProfile();
profile.setName("profile");
System.out.println("Profile '" + profile.getQualifiedName() + "' created.");
Stereotype stereotype = profile.createOwnedStereotype("type");
Stereotype stereotype2 = profile.createOwnedStereotype("type2");
org.eclipse.uml2.uml.Class metaclass = package_.createOwnedClass("Type", true);
org.eclipse.uml2.uml.Class metaclass2 = package_.createOwnedClass("Type2", true);
profile.createMetaclassReference(metaclass);
profile.createMetaclassReference(metaclass2);
List list = profile.getMetaclassReferences();
for (Iterator iterator = list.iterator(); iterator.hasNext();) {
ElementImport object = (ElementImport)iterator.next();
System.out.println("Stereotype : " + object.getName());
}
Extension extension = stereotype.createExtension(metaclass, Boolean.TRUE);
Extension extension2 = stereotype2.createExtension(metaclass2, true);
System.out.println("Stereotype '" + stereotype.getQualifiedName() + "' created.");
System.out.println("Stereotype '" + profile.getOwnedStereotype("type").getQualifiedName() + "' created.");
org.eclipse.uml2.uml.Class class_ = package_.createOwnedClass("Conteneur", false);
PrimitiveType primitiveType = (PrimitiveType) package_.createOwnedPrimitiveType("primitiveType");
Property attribute = class_.createOwnedAttribute("book", primitiveType, 0, 1);
Property attribute2 = class_.createOwnedAttribute("movie", primitiveType, 0, 1);
metaResource.getContents().add(profile);
metaResource.getContents().add(model);
profile.define();
list = profile.getApplicableStereotypes();
for (Iterator iterator = list.iterator(); iterator.hasNext();) {
Stereotype object = (Stereotype)iterator.next();
System.out.println("Stereotype : " + object.getName());
}
model.applyProfile(profile);
System.out.println("Model.isStereotypeApplicable : " + model.isStereotypeApplicable(stereotype2));
System.out.println("Class_.isStereotypeApplicable : " + class_.isStereotypeApplicable(stereotype2));
class_.applyStereotype(stereotype);
//attribute.applyStereotype(stereotype);
try {
if(metaResource == null)
System.out.println("pas de resource");
metaResource.save(null);
} catch (IOException ioe) {
ioe.printStackTrace();
} |
Partager