Refine search
public Express2EMF(File schemaFileName, String modelName, String nsUri) { schema = new SchemaLoader(schemaFileName.getAbsolutePath()).getSchema(); eFactory = EcoreFactory.eINSTANCE; ePackage = EcorePackage.eINSTANCE; schemaPack = eFactory.createEPackage(); try { new DerivedReader(schemaFileName, schema); } catch (FileNotFoundException e) { LOGGER.error("", e); } schemaPack.setName(modelName); schemaPack.setNsPrefix("iai"); schemaPack.setNsURI(nsUri); createTristate(); addClasses(); addSupertypes(); addSimpleTypes(); addDerivedTypes(); addEnumerations(); addHackedTypes(); addSelects(); addAttributes(); addInverses(); EClass ifcBooleanClass = (EClass) schemaPack.getEClassifier("IfcBoolean"); ifcBooleanClass.getESuperTypes().add((EClass) schemaPack.getEClassifier("IfcValue")); doRealDerivedAttributes(); clean(); }
containerClass = EcoreFactory.eINSTANCE.createEClass(); containerClass.setName("ListOf" + finalType.getName()); EAttribute finalAttribute = EcoreFactory.eINSTANCE.createEAttribute(); finalAttribute.setName("List"); finalAttribute.setEType(finalType); finalAttribute.setUpperBound(-1); containerClass.getEAttributes().add(finalAttribute); EAttribute stringAttribute = EcoreFactory.eINSTANCE.createEAttribute(); stringAttribute.setName("ListAsString"); stringAttribute.setEType(EcorePackage.eINSTANCE.getEString()); stringAttribute.setUpperBound(-1); containerClass.getEAttributes().add(stringAttribute); EReference finalReference = EcoreFactory.eINSTANCE.createEReference(); finalReference.setName("List"); finalReference.setEType(finalType); finalReference.setUpperBound(-1); containerClass.getEReferences().add(finalReference); EReference eReference = EcoreFactory.eINSTANCE.createEReference();
public void addIndex(EStructuralFeature eStructuralFeature) { for (EAnnotation eAnnotation : eStructuralFeature.getEAnnotations()) { if (eAnnotation.getSource().equals("singleindex")) { throw new RuntimeException(eStructuralFeature + " already has an index"); } } changes.add(new AddIndexChange(this, eStructuralFeature)); EAnnotation index = EcoreFactory.eINSTANCE.createEAnnotation(); index.setSource("singleindex"); eStructuralFeature.getEAnnotations().add(index); }
private void createTristate() { tristate = eFactory.createEEnum(); tristate.setName("Tristate"); EEnumLiteral trueLiteral = eFactory.createEEnumLiteral(); trueLiteral.setName("TRUE"); trueLiteral.setValue(0); EEnumLiteral falseLiteral = eFactory.createEEnumLiteral(); falseLiteral.setName("FALSE"); falseLiteral.setValue(1); EEnumLiteral undefinedLiteral = eFactory.createEEnumLiteral(); undefinedLiteral.setName("UNDEFINED"); undefinedLiteral.setValue(2); tristate.getELiterals().add(trueLiteral); tristate.getELiterals().add(falseLiteral); tristate.getELiterals().add(undefinedLiteral); schemaPack.getEClassifiers().add(tristate); }
private void doRealDerivedAttributes() { for (EntityDefinition entityDefinition : schema.getEntities()) { for (DerivedAttribute2 attributeName : entityDefinition.getDerivedAttributes().values()) { EClass eClass = (EClass) schemaPack.getEClassifier(entityDefinition.getName()); EAttribute eAttribute = eFactory.createEAttribute(); eAttribute.setDerived(true); eAttribute.setName(attributeName.getName()); eAttribute.setUnique(false); EClassifier type = ((EClass) eType).getEStructuralFeature("wrappedValue").getEType(); eAttribute.setEType(type); eAttribute.setUnsettable(true); // TODO find out eClass.getEStructuralFeatures().add(eAttribute); if (type == EcorePackage.eINSTANCE.getEDouble()) { EAttribute doubleStringAttribute = eFactory.createEAttribute(); doubleStringAttribute.setName(attributeName.getName() + "AsString"); doubleStringAttribute.getEAnnotations().add(createAsStringAnnotation()); doubleStringAttribute.getEAnnotations().add(createHiddenAnnotation()); doubleStringAttribute.setUnsettable(true); // TODO EReference eReference = eFactory.createEReference(); eReference.setName(attributeName.getName()); eReference.setDerived(true); eReference.setUnsettable(true); eReference.setEType(eType); eClass.getEStructuralFeatures().add(eReference);
private void addInverseAttribute(Attribute attrib, EClass cls) { InverseAttribute inverseAttribute = (InverseAttribute) attrib; EReference eRef = eFactory.createEReference(); eRef.setUnsettable(true); // Inverses are always optional? eRef.getEAnnotations().add(createInverseAnnotation()); eRef.setName(attrib.getName()); if (inverseAttribute.getMax_cardinality() != null) { IntegerBound max_cardinality = (IntegerBound) inverseAttribute.getMax_cardinality(); EClass classifier = (EClass) schemaPack.getEClassifier(type); eRef.setEType(classifier); String reverseName = inverseAttribute.getInverted_attr().getName(); EReference reference = (EReference) classifier.getEStructuralFeature(reverseName); reference.getEAnnotations().add(createInverseAnnotation()); if (eRef.getEType() == classifier && reference.getEType() == cls) { if (eRef.isMany()) { } else { System.out.println("Inverse mismatch"); System.out.println(classifier.getName() + "." + reference.getName() + " => " + cls.getName() + "." + eRef.getName()); cls.getEStructuralFeatures().add(eRef);
private void createEPackageMultiplicityOneContainmentNoOpposite() { EPackage ePackage = this.createNewEPackage("MyEPackage", "http://www.example.com/model", "model"); EClass eClass = EcoreFactory.eINSTANCE.createEClass(); eClass.setName("MyEClass"); EClass eOtherClass = EcoreFactory.eINSTANCE.createEClass(); eOtherClass.setName("YourEClass"); EReference eReference = EcoreFactory.eINSTANCE.createEReference(); eReference.setName("child"); eReference.setEType(eOtherClass); eReference.setLowerBound(0); eReference.setUpperBound(1); eReference.setContainment(true); eClass.getEStructuralFeatures().add(eReference); ePackage.getEClassifiers().add(eClass); ePackage.getEClassifiers().add(eOtherClass); this.registerEPackages(ePackage); }
public EReference createEReference(EClass eClass, String name, EClass type, Multiplicity multiplicity) { EReference eReference = EcoreFactory.eINSTANCE.createEReference(); eReference.setName(name); if (multiplicity == Multiplicity.MANY) { eReference.setUpperBound(-1); } if (!isNew(eClass)) { changes.add(new NewReferenceChange(this, eClass.getEAllStructuralFeatures().size(), eReference)); } eReference.setEType(type); eClass.getEStructuralFeatures().add(eReference); return eReference; }
protected EOperation addEOperation(EClass owner, EClassifier type, String name) { EOperation o = ecoreFactory.createEOperation(); initEOperation(o, type, name); owner.getEOperations().add(o); return o; }
public EAttribute createEAttribute(EClass eClass, String name, EDataType eDataType, Multiplicity multiplicity) { EAttribute eAttribute = EcoreFactory.eINSTANCE.createEAttribute(); eAttribute.setName(name); if (multiplicity == Multiplicity.MANY) { eAttribute.setUpperBound(-1); } if (!isNew(eClass)) { changes.add(new NewAttributeChange(this, eClass.getEAllStructuralFeatures().size(), eAttribute)); } eAttribute.setEType(eDataType); eClass.getEStructuralFeatures().add(eAttribute); return eAttribute; }
protected void createEAttribute(EClass owner, int id) { EAttributeImpl a = (EAttributeImpl)ecoreFactory.createEAttribute(); a.setFeatureID(id); owner.getEStructuralFeatures().add(a); }
protected void addAnnotation(ENamedElement eNamedElement, int depth, String source, String [] details, URI [] references) { EAnnotation eAnnotation = ecoreFactory.createEAnnotation(); eAnnotation.setSource(source); EMap<String, String> theDetails = eAnnotation.getDetails(); for (int i = 1; i < details.length; i += 2) { theDetails.put(details[i - 1], details[i]); } EList<EAnnotation> annotations = eNamedElement.getEAnnotations(); for (int i = 0; i < depth; ++i) { @SuppressWarnings("unchecked") EList<EAnnotation> childAnnotations = (EList<EAnnotation>)(EList<?>)annotations.get(annotations.size() - 1).getContents(); annotations = childAnnotations; } annotations.add(eAnnotation); if (references != null) { InternalEList<EObject> eAnnotationReferences = (InternalEList<EObject>)eAnnotation.getReferences(); for (URI reference : references) { InternalEObject internalEObject = (InternalEObject)ecoreFactory.createEObject(); internalEObject.eSetProxyURI(reference); eAnnotationReferences.addUnique(internalEObject); } } }
private EParameter internalAddEParameter(EOperation owner, EClassifier type, String name) { EParameter p = ecoreFactory.createEParameter(); p.setEType(type); p.setName(name); owner.getEParameters().add(p); return p; }
public static void setDocumentation(EModelElement eModelElement, String documentation) { EAnnotation eAnnotation = eModelElement.getEAnnotation(GEN_MODEL_PACKAGE_NS_URI); if (documentation == null) { if (eAnnotation != null) { eAnnotation.getDetails().removeKey("documentation"); } } else { if (eAnnotation == null) { eAnnotation = EcoreFactory.eINSTANCE.createEAnnotation(); eAnnotation.setSource(GEN_MODEL_PACKAGE_NS_URI); eModelElement.getEAnnotations().add(eAnnotation); } eAnnotation.getDetails().put("documentation", documentation); } }
public EClass createEClass(EPackage ePackage, String name, EClass... superClasses) { EClass eClass = EcoreFactory.eINSTANCE.createEClass(); eClass.setName(name); changes.add(new NewClassChange(eClass)); for (EClass superClass : superClasses) { eClass.getESuperTypes().add(superClass); } ePackage.getEClassifiers().add(eClass); return eClass; }
EClass cls = (EClass) schemaPack.getEClassifier(ent.getName()); EAttribute eAttribute = eFactory.createEAttribute(); eAttribute.setName(attrib.getName()); eAttribute.setUpperBound(-1); NamedType nt = (NamedType) domain; if (nt instanceof EnumerationType) { EAttribute enumAttrib = eFactory.createEAttribute(); enumAttrib.setUnsettable(expAttrib.isOptional()); enumAttrib.setName(attrib.getName()); EClassifier eType = schemaPack.getEClassifier(nt.getName()); enumAttrib.setEType(eType); EClass cls = (EClass) schemaPack.getEClassifier(ent.getName()); cls.getEStructuralFeatures().add(enumAttrib); EAttribute eAttribute = eFactory.createEAttribute(); eAttribute.setUnsettable(expAttrib.isOptional()); eAttribute.setName(attrib.getName()); EClassifier type = ((EClass) eType).getEStructuralFeature("wrappedValue").getEType(); eAttribute.setEType(type); cls.getEStructuralFeatures().add(eAttribute); if (type == EcorePackage.eINSTANCE.getEDouble()) { EAttribute doubleStringAttribute = eFactory.createEAttribute(); EReference eRef = eFactory.createEReference(); eRef.setName(attrib.getName()); EAttribute eAttribute = eFactory.createEAttribute();
private static void evolvePersonEPackage(final EPackage personEPackage) { EClass ecPerson = (EClass) personEPackage.getEClassifier("Person"); EAttribute eaFirstName = (EAttribute) ecPerson.getEStructuralFeature("firstName"); EAttribute eaLastName = (EAttribute) ecPerson.getEStructuralFeature("lastName"); ecPerson.getEStructuralFeatures().remove(eaFirstName); ecPerson.getEStructuralFeatures().remove(eaLastName); EAttribute eaName = EcoreFactory.eINSTANCE.createEAttribute(); eaName.setName("name"); eaName.setLowerBound(0); eaName.setUpperBound(1); eaName.setEType(EcorePackage.Literals.ESTRING); ecPerson.getEStructuralFeatures().add(eaName); }
protected void createEReference(EClass owner, int id) { EReferenceImpl r = (EReferenceImpl)ecoreFactory.createEReference(); r.setFeatureID(id); owner.getEStructuralFeatures().add(r); }
@BeforeAll static void initMocks() { EcoreFactory coreFactory = EcoreFactory.eINSTANCE; EPackage ePackage = coreFactory.createEPackage(); ePackage.setName("MyPackage"); ePackage.setNsPrefix("my"); ePackage.setNsURI("http://example.org/my"); eClass = coreFactory.createEClass(); eClass.setName("MyClass"); ePackage.getEClassifiers().add(eClass); assertThat(eClass.getEPackage()).isEqualTo(ePackage); PersistenceFactory.updateIfDynamic(ePackage); }
realType.setDomain(new RealType()); EAttribute attribute = modifySimpleType(realType, ifcComplexNumber); ifcComplexNumber.getEStructuralFeature("wrappedValueAsString").setUpperBound(2); attribute.setUpperBound(2); ifcComplexNumber.getEAnnotations().add(createWrappedAnnotation()); } else if (type.getName().equals("IfcNullStyle")) { EClassifier ifcNullStyleEnum = schemaPack.getEClassifier("IfcNullStyle"); ifcNullStyleEnum.setName("IfcNullStyleEnum"); EAttribute wrappedValue = eFactory.createEAttribute(); wrappedValue.setName("wrappedValue"); wrappedValue.setEType(ifcNullStyleEnum); ifcNullStyleWrapper.getEAnnotations().add(createWrappedAnnotation()); ifcNullStyleWrapper.getEStructuralFeatures().add(wrappedValue); } else if (type.getName().equals("IfcLineIndex")) { EClass ifcLineIndex = getOrCreateEClass(type.getName());