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; }
wrapperAttrib.setName("wrappedValue"); if (type.getDomain() instanceof IntegerType) { wrapperAttrib.setEType(ePackage.getELong()); } else if (type.getDomain() instanceof RealType) { wrapperAttrib.setEType(ePackage.getEDouble()); } else if (type.getDomain() instanceof StringType) { wrapperAttrib.setEType(ePackage.getEString()); } else if (type.getDomain() instanceof BooleanType) { wrapperAttrib.setEType(schemaPack.getEClassifier("Tristate")); } else if (type.getDomain() instanceof NumberType) { wrapperAttrib.setEType(ePackage.getEDouble()); } else if (type.getDomain() instanceof BinaryType) { wrapperAttrib.setEType(ePackage.getEByteArray()); } else if (type.getDomain() instanceof LogicalType) { wrapperAttrib.setEType(schemaPack.getEClassifier("Tristate")); if (wrapperAttrib.getEType() == ePackage.getEDouble()) { EAttribute doubleStringAttribute = eFactory.createEAttribute(); doubleStringAttribute.setEType(ePackage.getEString()); doubleStringAttribute.setName("wrappedValueAsString"); doubleStringAttribute.getEAnnotations().add(createAsStringAnnotation());
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);
wrappedValue.setEType(ifcNullStyleEnum); ifcNullStyleWrapper.getEAnnotations().add(createWrappedAnnotation()); ifcNullStyleWrapper.getEStructuralFeatures().add(wrappedValue);
eAttribute.setUpperBound(-1); eAttribute.setUnique(false); eAttribute.setEType(EcorePackage.eINSTANCE.getELong()); eAttribute.setUnsettable(expAttrib.isOptional()); cls.getEStructuralFeatures().add(eAttribute); 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.setEType(type); cls.getEStructuralFeatures().add(eAttribute); if (type == EcorePackage.eINSTANCE.getEDouble()) { doubleStringAttribute.getEAnnotations().add(createAsStringAnnotation()); doubleStringAttribute.getEAnnotations().add(createHiddenAnnotation()); doubleStringAttribute.setEType(EcorePackage.eINSTANCE.getEString()); doubleStringAttribute.setUnsettable(expAttrib.isOptional()); cls.getEStructuralFeatures().add(doubleStringAttribute); eAttribute.setEType(type); eAttribute.setUnsettable(expAttrib.isOptional()); eAttribute.setUnique(false); doubleStringAttribute.getEAnnotations().add(createAsStringAnnotation()); doubleStringAttribute.getEAnnotations().add(createHiddenAnnotation()); doubleStringAttribute.setEType(EcorePackage.eINSTANCE.getEString());
/** * @since 2.0 */ public static EAttribute createEAttribute(EClass eClass, String name, EClassifier type) { EAttribute eAttribute = EcoreFactory.eINSTANCE.createEAttribute(); eAttribute.setName(name); eAttribute.setEType(type); eClass.getEStructuralFeatures().add(eAttribute); return eAttribute; }
private static EAttribute createSuperTypeAttribute() { EAttribute superTypesAttribute = EcoreFactory.eINSTANCE.createEAttribute(); superTypesAttribute.setEType(getEClassifier("ELong")); superTypesAttribute.setLowerBound(0); superTypesAttribute.setUpperBound(-1); superTypesAttribute.setName("superTypes"); return superTypesAttribute; }
/** * Converting a {@link Field} to {@link EAttribute} Works only for * {@link Field} where {@link Field#getComponents()} is empty * * @param field * @return */ public static EAttribute fieldToEAttribute(Field field) { if (!field.getComponents().isEmpty()) { throw new IllegalArgumentException( "Can't convert field with components to " + "EAttribute, use fieldToEReference"); } EAttribute attr = EcoreFactory.eINSTANCE.createEAttribute(); attr.setName(toJavaName(field.getXmltag(), false)); attr.setLowerBound(field.isRequired() ? 1 : 0); attr.setUpperBound(1); if (field.getTypeClass() != null) { attr.setEType(toEType(field.getTypeClass())); } else { log.warn("Field " + field.getXmltag() + " has no type! Setting it's type to String"); attr.setEType(XMLTypePackage.Literals.STRING); } addMappingInformation(attr, field); annotateField(field, attr); return attr; }
/** * Converting a {@link Field} to {@link EAttribute} Works only for * {@link Field} where {@link Field#getComponents()} is empty * * @param field * @return */ public static EAttribute fieldToEAttribute(Field field) { if (!field.getComponents().isEmpty()) { throw new IllegalArgumentException( "Can't convert field with components to " + "EAttribute, use fieldToEReference"); } EAttribute attr = EcoreFactory.eINSTANCE.createEAttribute(); attr.setName(toJavaName(field.getXmltag(), false)); attr.setLowerBound(field.isRequired() ? 1 : 0); attr.setUpperBound(1); if (field.getTypeClass() != null) { attr.setEType(toEType(field.getTypeClass())); } else { log.warn("Field " + field.getXmltag() + " has no type! Setting it's type to String"); attr.setEType(XMLTypePackage.Literals.STRING); } addMappingInformation(attr, field); annotateField(field, attr); return attr; }
/*Use the Ecore factory*/ EcoreFactory ecoreFactory = EcoreFactory.eINSTANCE; /*Create your EPackage*/ EPackage myPackage = ecoreFactory.createEPackage(); /*set EPackage properties*/ myPackage.setName("myTest"); myPackage.setNsPrefix("myTest"); myPackage.setNsURI("http://com.myTest"); /*Create your first EClass*/ EClass myFirstEClass = ecoreFactory.createEClass(); myFirstEClass.setName("myClass"); /*Add to your EPackage's EClassifiers*/ /*EClasses and EDatatypes implement both EClassifiers*/ myPackage.getEClassifiers().add(myFirstEClass); /*Create your first EAtttribute*/ EAttribute myFirstEAtt = ecoreFactory.createEAttribute(); myFirstEAtt.setName("name"); /*Use the EcorePackage Datatypes -> here EString*/ myFirstEAtt.setEType(EcorePackage.eINSTANCE.getEString()); /*use EStructuralFeatures to add your EAtt*/ /*EReferences and EAttributes are both EStructuralfeatures*/ myFirstEClass.getEStructuralFeatures().add(myFirstEAtt);
/** * Converts {@link Component} to {@link EAttribute} * * @param component * @return */ private static EStructuralFeature componentToEAttribute(Component component) { if (!component.getSubComponents().isEmpty()) { throw new IllegalArgumentException( "Sub-components are not supported yet for component " + component.getXmltag()); } EAttribute result = EcoreFactory.eINSTANCE.createEAttribute(); result.setName(toJavaName(component.getXmltag(), false)); result.setLowerBound(component.isRequired() ? 1 : 0); result.setUpperBound(1); result.setEType(toEType(component.getTypeClass())); annotate(result, "truncable", String.valueOf(component.isTruncatable())); annotate(result, "required", String.valueOf(component.isRequired())); annotate(result, ANNOTATION_TYPE_KEY, SmooksMetadata.COMPONENT_TYPE); annotateValueNode(result, component); addMappingInformation(result, component); return result; }
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); }
/** * Converts {@link Component} to {@link EAttribute} * * @param component * @return */ private static EStructuralFeature componentToEAttribute(Component component) { if (!component.getSubComponents().isEmpty()) { throw new IllegalArgumentException( "Sub-components are not supported yet for component " + component.getXmltag()); } EAttribute result = EcoreFactory.eINSTANCE.createEAttribute(); result.setName(toJavaName(component.getXmltag(), false)); result.setLowerBound(component.isRequired() ? 1 : 0); result.setUpperBound(1); result.setEType(toEType(component.getTypeClass())); annotate(result, "truncable", String.valueOf(component.isTruncatable())); annotate(result, "required", String.valueOf(component.isRequired())); annotate(result, ANNOTATION_TYPE_KEY, SmooksMetadata.COMPONENT_TYPE); annotateValueNode(result, component); addMappingInformation(result, component); return result; }
public EAttribute convert() throws LoadModelException { EAttribute result = EcoreFactory.eINSTANCE.createEAttribute(); result.setName(getXmlElement().getName()); EDataType type = EMFUtil.findType(getXmlElement().getType()); if (type == null) { throw new LoadModelException(xmlElement, "Can''t find mapping for Java class: {0}", getXmlElement().getType()); } result.setEType(type); return result; }
private void createEPackageMultiplicityManyContainmentNoOpposite() { 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"); EAttribute eAttribute = EcoreFactory.eINSTANCE.createEAttribute(); eAttribute.setName("MyAttribute"); eAttribute.setEType(EcorePackage.Literals.ESTRING); eAttribute.setLowerBound(0); eAttribute.setUpperBound(1); eClass.getEStructuralFeatures().add(eAttribute); EReference eReference = EcoreFactory.eINSTANCE.createEReference(); eReference.setName("children"); 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); }
private EPackage createSimpleEPackage() { EPackage ePackage = EcoreFactory.eINSTANCE.createEPackage(); ePackage.setName("MyEPackage"); ePackage.setNsURI("http://com.example.model.MyEPackage"); ePackage.setNsPrefix("com.example"); 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); EAttribute eaName = EcoreFactory.eINSTANCE.createEAttribute(); eaName.setName("name"); eaName.setLowerBound(0); eaName.setUpperBound(1); eaName.setEType(EcorePackage.Literals.ESTRING); eClass.getEStructuralFeatures().add(eaName); ePackage.getEClassifiers().add(eClass); ePackage.getEClassifiers().add(eOtherClass); return ePackage; }
eaName.setLowerBound(0); eaName.setUpperBound(1); eaName.setEType(EcorePackage.Literals.ESTRING); eClass.getEStructuralFeatures().add(eaName);
EAttribute eAttribute = EcoreFactory.eINSTANCE.createEAttribute(); eAttribute.setName("MyAttribute"); eAttribute.setEType(EcorePackage.Literals.ESTRING); eAttribute.setLowerBound(0); eAttribute.setUpperBound(1);