public EObject createLayoutInformationModelElement(eu.hyvar.feature.expression.resource.hyexpression.mopp.HyexpressionLayoutInformation layoutInformation, EPackage layoutPackage) { EFactory factory = layoutPackage.getEFactoryInstance(); Object object = layoutInformation.getObject(null, false); eu.hyvar.feature.expression.resource.hyexpression.grammar.HyexpressionSyntaxElement syntaxElement = layoutInformation.getSyntaxElement(); EClass layoutInformationEClass = null; EObject layoutInformationModelElement = null; if (object == null) { // keyword layoutInformationEClass = (EClass) layoutPackage.getEClassifier(KEYWORD_LAYOUT_INFORMATION_ECLASS_NAME); layoutInformationModelElement = factory.create(layoutInformationEClass); } else if (object instanceof EObject) { // reference layoutInformationEClass = (EClass) layoutPackage.getEClassifier(REFERENCE_LAYOUT_INFORMATION_ECLASS_NAME); layoutInformationModelElement = factory.create(layoutInformationEClass); layoutInformationModelElement.eSet(layoutInformationEClass.getEStructuralFeature(OBJECT_EATTRIBUTE_NAME), object); } else { // attribute layoutInformationEClass = (EClass) layoutPackage.getEClassifier(ATTRIBUTE_LAYOUT_INFORMATION_ECLASS_NAME); layoutInformationModelElement = factory.create(layoutInformationEClass); } layoutInformationModelElement.eSet(layoutInformationEClass.getEStructuralFeature(START_OFFSET_EATTRIBUTE_NAME), layoutInformation.getStartOffset()); layoutInformationModelElement.eSet(layoutInformationEClass.getEStructuralFeature(HIDDEN_TOKEN_TEXT_EATTRIBUTE_NAME), layoutInformation.getHiddenTokenText()); layoutInformationModelElement.eSet(layoutInformationEClass.getEStructuralFeature(VISIBLE_TOKEN_TEXT_EATTRIBUTE_NAME), layoutInformation.getVisibleTokenText()); layoutInformationModelElement.eSet(layoutInformationEClass.getEStructuralFeature(SYNTAX_ELEMENT_ID_EATTRIBUTE_NAME), eu.hyvar.feature.expression.resource.hyexpression.grammar.HyexpressionGrammarInformationProvider.getSyntaxElementID(syntaxElement)); return layoutInformationModelElement; }
public EObject createLayoutInformationModelElement(eu.hyvar.mspl.manifest.resource.hymanifest.mopp.HymanifestLayoutInformation layoutInformation, EPackage layoutPackage) { EFactory factory = layoutPackage.getEFactoryInstance(); Object object = layoutInformation.getObject(null, false); eu.hyvar.mspl.manifest.resource.hymanifest.grammar.HymanifestSyntaxElement syntaxElement = layoutInformation.getSyntaxElement(); EClass layoutInformationEClass = null; EObject layoutInformationModelElement = null; if (object == null) { // keyword layoutInformationEClass = (EClass) layoutPackage.getEClassifier(KEYWORD_LAYOUT_INFORMATION_ECLASS_NAME); layoutInformationModelElement = factory.create(layoutInformationEClass); } else if (object instanceof EObject) { // reference layoutInformationEClass = (EClass) layoutPackage.getEClassifier(REFERENCE_LAYOUT_INFORMATION_ECLASS_NAME); layoutInformationModelElement = factory.create(layoutInformationEClass); layoutInformationModelElement.eSet(layoutInformationEClass.getEStructuralFeature(OBJECT_EATTRIBUTE_NAME), object); } else { // attribute layoutInformationEClass = (EClass) layoutPackage.getEClassifier(ATTRIBUTE_LAYOUT_INFORMATION_ECLASS_NAME); layoutInformationModelElement = factory.create(layoutInformationEClass); } layoutInformationModelElement.eSet(layoutInformationEClass.getEStructuralFeature(START_OFFSET_EATTRIBUTE_NAME), layoutInformation.getStartOffset()); layoutInformationModelElement.eSet(layoutInformationEClass.getEStructuralFeature(HIDDEN_TOKEN_TEXT_EATTRIBUTE_NAME), layoutInformation.getHiddenTokenText()); layoutInformationModelElement.eSet(layoutInformationEClass.getEStructuralFeature(VISIBLE_TOKEN_TEXT_EATTRIBUTE_NAME), layoutInformation.getVisibleTokenText()); layoutInformationModelElement.eSet(layoutInformationEClass.getEStructuralFeature(SYNTAX_ELEMENT_ID_EATTRIBUTE_NAME), eu.hyvar.mspl.manifest.resource.hymanifest.grammar.HymanifestGrammarInformationProvider.getSyntaxElementID(syntaxElement)); return layoutInformationModelElement; }
public EObject createLayoutInformationModelElement(eu.hyvar.feature.mapping.resource.hymapping.mopp.HymappingLayoutInformation layoutInformation, EPackage layoutPackage) { EFactory factory = layoutPackage.getEFactoryInstance(); Object object = layoutInformation.getObject(null, false); eu.hyvar.feature.mapping.resource.hymapping.grammar.HymappingSyntaxElement syntaxElement = layoutInformation.getSyntaxElement(); EClass layoutInformationEClass = null; EObject layoutInformationModelElement = null; if (object == null) { // keyword layoutInformationEClass = (EClass) layoutPackage.getEClassifier(KEYWORD_LAYOUT_INFORMATION_ECLASS_NAME); layoutInformationModelElement = factory.create(layoutInformationEClass); } else if (object instanceof EObject) { // reference layoutInformationEClass = (EClass) layoutPackage.getEClassifier(REFERENCE_LAYOUT_INFORMATION_ECLASS_NAME); layoutInformationModelElement = factory.create(layoutInformationEClass); layoutInformationModelElement.eSet(layoutInformationEClass.getEStructuralFeature(OBJECT_EATTRIBUTE_NAME), object); } else { // attribute layoutInformationEClass = (EClass) layoutPackage.getEClassifier(ATTRIBUTE_LAYOUT_INFORMATION_ECLASS_NAME); layoutInformationModelElement = factory.create(layoutInformationEClass); } layoutInformationModelElement.eSet(layoutInformationEClass.getEStructuralFeature(START_OFFSET_EATTRIBUTE_NAME), layoutInformation.getStartOffset()); layoutInformationModelElement.eSet(layoutInformationEClass.getEStructuralFeature(HIDDEN_TOKEN_TEXT_EATTRIBUTE_NAME), layoutInformation.getHiddenTokenText()); layoutInformationModelElement.eSet(layoutInformationEClass.getEStructuralFeature(VISIBLE_TOKEN_TEXT_EATTRIBUTE_NAME), layoutInformation.getVisibleTokenText()); layoutInformationModelElement.eSet(layoutInformationEClass.getEStructuralFeature(SYNTAX_ELEMENT_ID_EATTRIBUTE_NAME), eu.hyvar.feature.mapping.resource.hymapping.grammar.HymappingGrammarInformationProvider.getSyntaxElementID(syntaxElement)); return layoutInformationModelElement; }
public EObject createLayoutInformationModelElement(eu.hyvar.feature.constraint.resource.hyconstraints.mopp.HyconstraintsLayoutInformation layoutInformation, EPackage layoutPackage) { EFactory factory = layoutPackage.getEFactoryInstance(); Object object = layoutInformation.getObject(null, false); eu.hyvar.feature.constraint.resource.hyconstraints.grammar.HyconstraintsSyntaxElement syntaxElement = layoutInformation.getSyntaxElement(); EClass layoutInformationEClass = null; EObject layoutInformationModelElement = null; if (object == null) { // keyword layoutInformationEClass = (EClass) layoutPackage.getEClassifier(KEYWORD_LAYOUT_INFORMATION_ECLASS_NAME); layoutInformationModelElement = factory.create(layoutInformationEClass); } else if (object instanceof EObject) { // reference layoutInformationEClass = (EClass) layoutPackage.getEClassifier(REFERENCE_LAYOUT_INFORMATION_ECLASS_NAME); layoutInformationModelElement = factory.create(layoutInformationEClass); layoutInformationModelElement.eSet(layoutInformationEClass.getEStructuralFeature(OBJECT_EATTRIBUTE_NAME), object); } else { // attribute layoutInformationEClass = (EClass) layoutPackage.getEClassifier(ATTRIBUTE_LAYOUT_INFORMATION_ECLASS_NAME); layoutInformationModelElement = factory.create(layoutInformationEClass); } layoutInformationModelElement.eSet(layoutInformationEClass.getEStructuralFeature(START_OFFSET_EATTRIBUTE_NAME), layoutInformation.getStartOffset()); layoutInformationModelElement.eSet(layoutInformationEClass.getEStructuralFeature(HIDDEN_TOKEN_TEXT_EATTRIBUTE_NAME), layoutInformation.getHiddenTokenText()); layoutInformationModelElement.eSet(layoutInformationEClass.getEStructuralFeature(VISIBLE_TOKEN_TEXT_EATTRIBUTE_NAME), layoutInformation.getVisibleTokenText()); layoutInformationModelElement.eSet(layoutInformationEClass.getEStructuralFeature(SYNTAX_ELEMENT_ID_EATTRIBUTE_NAME), eu.hyvar.feature.constraint.resource.hyconstraints.grammar.HyconstraintsGrammarInformationProvider.getSyntaxElementID(syntaxElement)); return layoutInformationModelElement; }
public EObject createLayoutInformationModelElement(eu.hyvar.context.contextValidity.resource.hyvalidityformula.mopp.HyvalidityformulaLayoutInformation layoutInformation, EPackage layoutPackage) { EFactory factory = layoutPackage.getEFactoryInstance(); Object object = layoutInformation.getObject(null, false); eu.hyvar.context.contextValidity.resource.hyvalidityformula.grammar.HyvalidityformulaSyntaxElement syntaxElement = layoutInformation.getSyntaxElement(); EClass layoutInformationEClass = null; EObject layoutInformationModelElement = null; if (object == null) { // keyword layoutInformationEClass = (EClass) layoutPackage.getEClassifier(KEYWORD_LAYOUT_INFORMATION_ECLASS_NAME); layoutInformationModelElement = factory.create(layoutInformationEClass); } else if (object instanceof EObject) { // reference layoutInformationEClass = (EClass) layoutPackage.getEClassifier(REFERENCE_LAYOUT_INFORMATION_ECLASS_NAME); layoutInformationModelElement = factory.create(layoutInformationEClass); layoutInformationModelElement.eSet(layoutInformationEClass.getEStructuralFeature(OBJECT_EATTRIBUTE_NAME), object); } else { // attribute layoutInformationEClass = (EClass) layoutPackage.getEClassifier(ATTRIBUTE_LAYOUT_INFORMATION_ECLASS_NAME); layoutInformationModelElement = factory.create(layoutInformationEClass); } layoutInformationModelElement.eSet(layoutInformationEClass.getEStructuralFeature(START_OFFSET_EATTRIBUTE_NAME), layoutInformation.getStartOffset()); layoutInformationModelElement.eSet(layoutInformationEClass.getEStructuralFeature(HIDDEN_TOKEN_TEXT_EATTRIBUTE_NAME), layoutInformation.getHiddenTokenText()); layoutInformationModelElement.eSet(layoutInformationEClass.getEStructuralFeature(VISIBLE_TOKEN_TEXT_EATTRIBUTE_NAME), layoutInformation.getVisibleTokenText()); layoutInformationModelElement.eSet(layoutInformationEClass.getEStructuralFeature(SYNTAX_ELEMENT_ID_EATTRIBUTE_NAME), eu.hyvar.context.contextValidity.resource.hyvalidityformula.grammar.HyvalidityformulaGrammarInformationProvider.getSyntaxElementID(syntaxElement)); return layoutInformationModelElement; }
public EObject createLayoutInformationModelElement(eu.hyvar.dataValues.resource.hydatavalue.mopp.HydatavalueLayoutInformation layoutInformation, EPackage layoutPackage) { EFactory factory = layoutPackage.getEFactoryInstance(); Object object = layoutInformation.getObject(null, false); eu.hyvar.dataValues.resource.hydatavalue.grammar.HydatavalueSyntaxElement syntaxElement = layoutInformation.getSyntaxElement(); EClass layoutInformationEClass = null; EObject layoutInformationModelElement = null; if (object == null) { // keyword layoutInformationEClass = (EClass) layoutPackage.getEClassifier(KEYWORD_LAYOUT_INFORMATION_ECLASS_NAME); layoutInformationModelElement = factory.create(layoutInformationEClass); } else if (object instanceof EObject) { // reference layoutInformationEClass = (EClass) layoutPackage.getEClassifier(REFERENCE_LAYOUT_INFORMATION_ECLASS_NAME); layoutInformationModelElement = factory.create(layoutInformationEClass); layoutInformationModelElement.eSet(layoutInformationEClass.getEStructuralFeature(OBJECT_EATTRIBUTE_NAME), object); } else { // attribute layoutInformationEClass = (EClass) layoutPackage.getEClassifier(ATTRIBUTE_LAYOUT_INFORMATION_ECLASS_NAME); layoutInformationModelElement = factory.create(layoutInformationEClass); } layoutInformationModelElement.eSet(layoutInformationEClass.getEStructuralFeature(START_OFFSET_EATTRIBUTE_NAME), layoutInformation.getStartOffset()); layoutInformationModelElement.eSet(layoutInformationEClass.getEStructuralFeature(HIDDEN_TOKEN_TEXT_EATTRIBUTE_NAME), layoutInformation.getHiddenTokenText()); layoutInformationModelElement.eSet(layoutInformationEClass.getEStructuralFeature(VISIBLE_TOKEN_TEXT_EATTRIBUTE_NAME), layoutInformation.getVisibleTokenText()); layoutInformationModelElement.eSet(layoutInformationEClass.getEStructuralFeature(SYNTAX_ELEMENT_ID_EATTRIBUTE_NAME), eu.hyvar.dataValues.resource.hydatavalue.grammar.HydatavalueGrammarInformationProvider.getSyntaxElementID(syntaxElement)); return layoutInformationModelElement; }
public EObject createLayoutInformationModelElement(de.darwinspl.preferences.resource.dwprofile.mopp.DwprofileLayoutInformation layoutInformation, EPackage layoutPackage) { EFactory factory = layoutPackage.getEFactoryInstance(); Object object = layoutInformation.getObject(null, false); de.darwinspl.preferences.resource.dwprofile.grammar.DwprofileSyntaxElement syntaxElement = layoutInformation.getSyntaxElement(); EClass layoutInformationEClass = null; EObject layoutInformationModelElement = null; if (object == null) { // keyword layoutInformationEClass = (EClass) layoutPackage.getEClassifier(KEYWORD_LAYOUT_INFORMATION_ECLASS_NAME); layoutInformationModelElement = factory.create(layoutInformationEClass); } else if (object instanceof EObject) { // reference layoutInformationEClass = (EClass) layoutPackage.getEClassifier(REFERENCE_LAYOUT_INFORMATION_ECLASS_NAME); layoutInformationModelElement = factory.create(layoutInformationEClass); layoutInformationModelElement.eSet(layoutInformationEClass.getEStructuralFeature(OBJECT_EATTRIBUTE_NAME), object); } else { // attribute layoutInformationEClass = (EClass) layoutPackage.getEClassifier(ATTRIBUTE_LAYOUT_INFORMATION_ECLASS_NAME); layoutInformationModelElement = factory.create(layoutInformationEClass); } layoutInformationModelElement.eSet(layoutInformationEClass.getEStructuralFeature(START_OFFSET_EATTRIBUTE_NAME), layoutInformation.getStartOffset()); layoutInformationModelElement.eSet(layoutInformationEClass.getEStructuralFeature(HIDDEN_TOKEN_TEXT_EATTRIBUTE_NAME), layoutInformation.getHiddenTokenText()); layoutInformationModelElement.eSet(layoutInformationEClass.getEStructuralFeature(VISIBLE_TOKEN_TEXT_EATTRIBUTE_NAME), layoutInformation.getVisibleTokenText()); layoutInformationModelElement.eSet(layoutInformationEClass.getEStructuralFeature(SYNTAX_ELEMENT_ID_EATTRIBUTE_NAME), de.darwinspl.preferences.resource.dwprofile.grammar.DwprofileGrammarInformationProvider.getSyntaxElementID(syntaxElement)); return layoutInformationModelElement; }
@Test public void testFillIdToEObjectMap() { EPackage pack = EcoreFactory.eINSTANCE.createEPackage(); EClass root = createEClass(pack, "Root"); EClass someType = createEClass(pack, "SomeType"); EReference ref1 = addEReference(root, someType, "ref1", false); EReference ref2 = addEReference(root, someType, "ref2", true); EFactory factory = pack.getEFactoryInstance(); EObject rootObject = factory.create(root); EObject someTypeObject1 = factory.create(someType); EObject someTypeObject2 = factory.create(someType); rootObject.eSet(ref1, someTypeObject1); rootObject.eSet(ref2, someTypeObject2); List<EObject> map = new ArrayList<>(); SerializationUtil.fillIdToEObjectMap(rootObject, map); assertTrue(map.contains(rootObject)); assertTrue(map.contains(someTypeObject1)); assertFalse(map.contains(someTypeObject2)); assertEquals(2, map.size()); }
@Before public void init() { EcoreFactory modelFactory = EcoreFactory.eINSTANCE; testModelPackage = modelFactory.createEPackage(); testModelPackage.setName("TypeProviderTestEPackage"); testModelPackage.setNsPrefix("typeprovidertestpackage"); testModelPackage.setNsURI("http://testabstracttype"); EFactory instanceFactory = testModelPackage.getEFactoryInstance(); EClass clazz = createEClass("ExpressionContainer"); expressionContainerReference = modelFactory.createEReference(); clazz.getEStructuralFeatures().add(expressionContainerReference); expressionContainerReference.setName("expression"); expressionContainerReference.setEType(typeModelPackage.getIExpression()); expressionContainerReference.setContainment(true); expression1Container = instanceFactory.create(clazz); expression1Container.eSet(expressionContainerReference, expression1); expression2Container = instanceFactory.create(clazz); expression2Container.eSet(expressionContainerReference, expression2); expression3Container = instanceFactory.create(clazz); expression3Container.eSet(expressionContainerReference, expression3); }
public static Object setFromSlot(final EFactory eFactory, final EClass eClass, final EObject eObject, final AttributeSlot slot) throws IOException { final EStructuralFeature feature = eClass.getEStructuralFeature(slot.name); if (feature == null) { return null; } if (!feature.isChangeable() || feature.isDerived() && !(eObject instanceof DynamicEStoreEObjectImpl)) { return null; } if (!slot.isSetValue()) { return null; } // isSet=true and many=false means that we should have exactly one value final EClassifier eType = feature.getEType(); if (eType.eContainer() == EcorePackage.eINSTANCE) { return fromEcoreType(eClass, eObject, slot, feature, eType); } else if (eType instanceof EEnum) { return fromEnum(eFactory, eClass, eObject, slot, feature, (EEnum)eType); } else { return fromInstanceClass(eClass, eObject, slot, feature, eType); } }
private static Object fromEnum(final EFactory eFactory, final EClass eClass, final EObject eObject, final AttributeSlot slot, final EStructuralFeature feature, final EEnum enumType) throws IOException { if (!slot.value.isSetVStrings() && !slot.value.isSetVString()) { throw new IOException( String.format( "Expected to receive strings for feature '%s' in type '%s' with many='%s', but did not", feature.getName(), eClass.getName(), feature.isMany())); } else if (feature.isMany()) { final List<Object> literals = new ArrayList<>(); if (slot.value.isSetVStrings()) { for (final String s : slot.value.getVStrings()) { literals.add(eFactory.createFromString(enumType, s)); } } else { literals.add(eFactory.createFromString(enumType, slot.value.getVString())); } eObject.eSet(feature, literals); return literals; } else { final Object enumLiteral = eFactory.createFromString(enumType, slot.value.getVString()); eObject.eSet(feature, enumLiteral); return enumLiteral; } }
public void fetchAttributes(final Map<String, EObject> objects) throws IOException, HawkInstanceNotFound, HawkInstanceNotRunning, TException { final HawkQueryOptions options = new HawkQueryOptions(); options.setIncludeAttributes(true); options.setIncludeReferences(false); setEffectiveMetamodelOptions(options, descriptor.getEffectiveMetamodel()); final List<ModelElement> elems = client.resolveProxies( descriptor.getHawkInstance(), new ArrayList<>(objects.keySet()), options); for (ModelElement me : elems) { final EObject object = objects.get(me.id); final EFactory eFactory = getResourceSet().getPackageRegistry().getEFactory(me.getMetamodelUri()); final EClass eClass = getEClass( me.getMetamodelUri(), me.getTypeName(), getResourceSet().getPackageRegistry()); for (final AttributeSlot s : me.attributes) { SlotDecodingUtils.setFromSlot(eFactory, eClass, object, s); } } }
private static Object setScalarAttribute(final EFactory eFactory, final EObject eObject, final Object value, final EStructuralFeature feature) { final Object singleValue = normalizeIntoScalar(value); if (singleValue == null) { eObject.eUnset(feature); return null; } final EClassifier eType = feature.getEType(); if (eType instanceof EEnum) { final EEnum enumType = (EEnum)eType; final Object literal = eFactory.createFromString(enumType, singleValue.toString()); eObject.eSet(feature, literal); return literal; } else { eObject.eSet(feature, singleValue); return singleValue; } }
private static Object setListAttribute(final EFactory eFactory, final EObject eObject, final Object value, final EStructuralFeature feature) { final EList<Object> manyValue = normalizeIntoList(value); if (manyValue == null) { eObject.eUnset(feature); return null; } final EClassifier eType = feature.getEType(); if (eType instanceof EEnum) { final EEnum enumType = (EEnum)eType; final EList<Object> literals = new BasicEList<>(); for (final Object o : manyValue) { literals.add(eFactory.createFromString(enumType, o.toString())); } eObject.eSet(feature, literals); return literals; } else { eObject.eSet(feature, manyValue); return manyValue; } }
public void testJSFormulaEngine() throws Exception { AD.load(URI.createPlatformPluginURI("/gov.nasa.ensemble.core.plan.formula.js/datafiles/TestJSFormulaEngine.dictionary", true)); EActivityDef referencingActivityDef = AD.getActivityDef("ReferencingActivity"); assertNotNull(referencingActivityDef); EStructuralFeature crewMemberFeature = referencingActivityDef.getEStructuralFeature("crewMember"); assertNotNull(crewMemberFeature); EClass crewMemberDef = (EClass) AD.getEClassifier("CrewMember"); assertNotNull(crewMemberDef); EStructuralFeature busyFeature = crewMemberDef.getEStructuralFeature("busy"); assertNotNull(busyFeature); EFactory factory = crewMemberDef.getEPackage().getEFactoryInstance(); EObject crewMember = factory.create(crewMemberDef); EActivity referencingActivity = PlanFactory.getInstance().createActivity(referencingActivityDef); referencingActivity.getData().eSet(crewMemberFeature, crewMember); assertReferenceValue(referencingActivity, crewMember, busyFeature, 0); crewMember.eSet(busyFeature, 1); assertReferenceValue(referencingActivity, crewMember, busyFeature, 1); }
private ResourceSet createResourceSet() { EFactory factory = AD.getEFactoryInstance(); ResourceSet resourceSet = sharedResourceSet; Resource resourceAsInAFile = resourceSet.createResource(URI.createURI("http://junit/foo.resource")); ObjectDef referenceDefinition = AD.getDefinitions(ObjectDef.class).get(0); EStructuralFeature idFeature = getEStructuralFeature(referenceDefinition, "id"); EStructuralFeature nameFeature = getEStructuralFeature(referenceDefinition, "name"); { int id = 0; for (char digitChar : referenceNames) { String name = String.valueOf(digitChar); EObject referenceInstance = factory.create(referenceDefinition); referenceInstance.eSet(idFeature, "Resource id#" + id++); referenceInstance.eSet(nameFeature, name); resourceAsInAFile.getContents().add(referenceInstance); referenceNameToObject.put(name, referenceInstance); } } return resourceSet; }
@Override public EClassifier getType(EFactory eFactory, String typeName) { if (eFactory != null) { EPackage ePackage = eFactory.getEPackage(); if (extendedMetaData != null) { return extendedMetaData.getType(ePackage, typeName); } else { EClassifier eClass = ePackage.getEClassifier(typeName); if (eClass == null && xmlMap != null) { return xmlMap.getClassifier(ePackage.getNsURI(), typeName); } return eClass; } } return null; }
/** * Get the value of the named AD parameter for the activity as a string. * Works with several types, not just strings -- enums, for example. * @param element * @param parameterName * @return null if the parameter is not found */ public static String getParameterString(EPlanElement element, String parameterName) { EObject data = element.getData(); if (data==null) return null; EStructuralFeature feature; try { feature = getParameterFeature(data, parameterName); } catch (UndefinedParameterException e) { return null; } Object object = data.eGet(feature); if (object instanceof EEnumLiteral) { EEnumLiteral literal = (EEnumLiteral) object; return literal.getName(); } EClassifier type = feature.getEType(); if (type instanceof EDataType) { EDataType dataType = (EDataType) type; EPackage typePackage = dataType.getEPackage(); EFactory factory = typePackage.getEFactoryInstance(); String string = factory.convertToString(dataType, object); return string; } LogUtil.warnOnce("feature type '" + type + "'is not EDataType: " + parameterName); return String.valueOf(object); }
public static String getObjectString(EObject object, String parameterName) { EStructuralFeature feature; try { feature = getParameterFeature(object, parameterName); } catch (UndefinedParameterException e) { return null; } Object value = object.eGet(feature); if (value instanceof EEnumLiteral) { EEnumLiteral literal = (EEnumLiteral) value; return literal.getName(); } EClassifier type = feature.getEType(); if (type instanceof EDataType) { EDataType dataType = (EDataType) type; EPackage typePackage = dataType.getEPackage(); EFactory factory = typePackage.getEFactoryInstance(); String string = factory.convertToString(dataType, value); return string; } LogUtil.warnOnce("feature type '" + type + "'is not EDataType: " + parameterName); return String.valueOf(value); }
/** Use setParameterString instead, unless calling from an XML loader that has not yet created the plan element. */ public static void setParameterStringInData(EObject data, String parameterName, String newValue) throws UndefinedParameterException { EStructuralFeature feature = getParameterFeature(data, parameterName); EClassifier type = feature.getEType(); Object object; if (type instanceof EEnum) { EEnum enumType = (EEnum) type; object = enumType.getEEnumLiteral(newValue); } else if (type instanceof EDataType) { EDataType dataType = (EDataType) type; EPackage typePackage = dataType.getEPackage(); EFactory factory = typePackage.getEFactoryInstance(); object = factory.createFromString(dataType, newValue); } else { Logger logger = Logger.getLogger(ADParameterUtils.class); logger.warn("feature type '" + type + "'is not EDataType: " + parameterName); object = newValue; } data.eSet(feature, object); }
/** * Add a value to a named AD multi-select EEnum parameter for the activity * @param element * @param parameterName * @param newValue * @throws UndefinedParameterException */ @SuppressWarnings("unchecked") public static void addParameterStringToList(EPlanElement element, String parameterName, String newValue) throws UndefinedParameterException { EObject data = element.getData(); EStructuralFeature feature = getParameterFeature(data, parameterName); EClassifier type = feature.getEType(); Object object; if (type instanceof EEnum) { EEnum enumType = (EEnum) type; object = enumType.getEEnumLiteral(newValue); } else if (type instanceof EDataType) { EDataType dataType = (EDataType) type; EPackage typePackage = dataType.getEPackage(); EFactory factory = typePackage.getEFactoryInstance(); object = factory.createFromString(dataType, newValue); } else { Logger logger = Logger.getLogger(ADParameterUtils.class); logger.warn("feature type '" + type + "'is not EDataType: " + parameterName); object = newValue; } addParameterObjectToList(element, parameterName, object); }
/** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ public void setEFactoryInstance(EFactory newEFactoryInstance) { if (newEFactoryInstance != eFactoryInstance) { NotificationChain msgs = null; if (eFactoryInstance != null) msgs = ((InternalEObject)eFactoryInstance).eInverseRemove(this, EcorePackage.EFACTORY__EPACKAGE, EFactory.class, msgs); if (newEFactoryInstance != null) msgs = ((InternalEObject)newEFactoryInstance).eInverseAdd(this, EcorePackage.EFACTORY__EPACKAGE, EFactory.class, msgs); msgs = basicSetEFactoryInstance(newEFactoryInstance, msgs); if (msgs != null) msgs.dispatch(); } else if (eNotificationRequired()) eNotify(new ENotificationImpl(this, Notification.SET, EcorePackage.EPACKAGE__EFACTORY_INSTANCE, newEFactoryInstance, newEFactoryInstance)); }
/** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ @SuppressWarnings("unchecked") @Override public NotificationChain eInverseAdd(InternalEObject otherEnd, int featureID, NotificationChain msgs) { switch (featureID) { case EcorePackage.EPACKAGE__EANNOTATIONS: return ((InternalEList<InternalEObject>)(InternalEList<?>)getEAnnotations()).basicAdd(otherEnd, msgs); case EcorePackage.EPACKAGE__EFACTORY_INSTANCE: if (eFactoryInstance != null) msgs = ((InternalEObject)eFactoryInstance).eInverseRemove(this, EcorePackage.EFACTORY__EPACKAGE, EFactory.class, msgs); return basicSetEFactoryInstance((EFactory)otherEnd, msgs); case EcorePackage.EPACKAGE__ECLASSIFIERS: return ((InternalEList<InternalEObject>)(InternalEList<?>)getEClassifiers()).basicAdd(otherEnd, msgs); case EcorePackage.EPACKAGE__ESUBPACKAGES: return ((InternalEList<InternalEObject>)(InternalEList<?>)getESubpackages()).basicAdd(otherEnd, msgs); case EcorePackage.EPACKAGE__ESUPER_PACKAGE: if (eInternalContainer() != null) msgs = eBasicRemoveFromContainer(msgs); return eBasicSetContainer(otherEnd, EcorePackage.EPACKAGE__ESUPER_PACKAGE, msgs); } return eDynamicInverseAdd(otherEnd, featureID, msgs); }
public void evaluateEClassQuery(String kQuery, OCLReasoningEngine oclReasoner, EObject kRootModelObj, EClass kModelElemTypeClass, EFactory kModelTypeFactory, Map<String, Map<EObject, EObject>> queryUnion) { for (String kQueryRow : kQuery.split(ROW_SEPARATOR)) { String[] kQueryAssignment = kQueryRow.split(UNION_ASSIGNMENT); String oclQuery = kQueryAssignment[1].trim(); String unionName = kQueryAssignment[0].substring(kQueryAssignment[0].indexOf(UNION_KEYWORD)+UNION_KEYWORD.length(), kQueryAssignment[0].length()).trim(); Map<EObject, EObject> queryRow = new LinkedHashMap<EObject, EObject>(); queryUnion.put(unionName, queryRow); Object queryObjs = oclReasoner.evaluateQuery(kRootModelObj, oclQuery); if (!(queryObjs instanceof Collection<?>)) { continue; } for (Object queryObj : (Collection<?>) queryObjs) { EObject modelObj = (EObject) queryObj; EObject kModelObj = kModelTypeFactory.create(kModelElemTypeClass); for (EStructuralFeature feature : modelObj.eClass().getEAllStructuralFeatures()) { // copy shared non-containment features EStructuralFeature kFeature = kModelObj.eClass().getEStructuralFeature(feature.getName()); if ((feature instanceof EReference && ((EReference) feature).isContainment()) || kFeature == null) { continue; } kModelObj.eSet(kFeature, modelObj.eGet(feature)); } queryRow.put(modelObj, kModelObj); } } }
protected ResourceSet createAndConfigureAResourceSet(IDataStore dataStore, EPackage... metaModels) { ResourceSet resourceSet = new ResourceSetImpl(); boolean saveOriginalFactories = false; if (this.originalFactories == null) { this.metaModels = metaModels; this.originalFactories = new EFactory[metaModels.length]; saveOriginalFactories = true; } int i = 0; for (EPackage metaModel : metaModels) { resourceSet.getPackageRegistry().put(metaModel.getNsURI(), metaModel); if (saveOriginalFactories) { originalFactories[i++] = metaModel.getEFactoryInstance(); } metaModel.setEFactoryInstance(new org.eclipse.emf.ecore.impl.EFactoryImpl() { @Override public EObject create(EClass eClass) { return new FInternalObjectImpl(eClass); } }); } resourceSet.getURIConverter().getURIHandlers().add(0, new DataStoreURIHandler(dataStore)); resourceSet.getResourceFactoryRegistry().getProtocolToFactoryMap().put(dataStore.getURI().scheme(), createResourceFactoryImpl()); return resourceSet; }
/** * Create an entity of a given kind. * * @param kind * The kind of the entity to create. * @return The created entity, else null. */ public static Entity createEntity(Kind kind) { Entity createdEntity = null; // Get the name space of the Ecore package for this kind. String epackageNS = Occi2Ecore.convertOcciScheme2EcoreNamespace(kind.getScheme()); // Get the Ecore package associated to the kind. EPackage epackage = EPackage.Registry.INSTANCE.getEPackage(epackageNS); if (epackage == null) { LOGGER.warn("EPackage " + epackageNS + " not found!"); } else { String classname = Occi2Ecore.convertOcciCategoryTerm2EcoreClassName(kind.getTerm()); // Get the Ecore class associated to the kind. EClass eclass = (EClass) epackage.getEClassifier(classname); if (eclass == null) { LOGGER.warn("EClass " + classname + " not found!"); } else { // Get the Ecore factory associated to the kind. EFactory efactory = EPackage.Registry.INSTANCE.getEFactory(epackageNS); if (efactory == null) { LOGGER.warn("EFactory " + epackageNS + " not found!"); } else { // Create the EObject for this kind. createdEntity = (Entity) efactory.create(eclass); } } } if (createdEntity == null) { LOGGER.warn("Create OCCI Core Resource!"); createdEntity = OCCIFactory.eINSTANCE.createResource(); createdEntity.setKind(kind); } LOGGER.debug("created entity=" + createdEntity); // Return the new entity. return createdEntity; }
@Override public String convertToString(EFactory factory, EDataType dataType, Object value) { if (dataType == ModelPackage.Literals.URI_DATA_TYPE && value != null) { value = deresolve((URI) value); } return super.convertToString(factory, dataType, value); }
@Override protected Object createFromString(EFactory factory, EDataType dataType, String value) { Object actualValue = super.createFromString(factory, dataType, value); if (dataType == ModelPackage.Literals.URI_DATA_TYPE && actualValue != null) { actualValue = resolve((URI) actualValue, resourceURI); } return actualValue; }
@Override public EObject createObject(EFactory factory, EClassifier type) { // Fix the missing xsi:type attribute for master refs in old screen files if(type == ModelPackage.Literals.WIDGET_CONTAINER) return ModelFactory.eINSTANCE.createScreen(); return super.createObject(factory, type); }
private EObject createEObject(final ModelElement me) throws IOException { final Registry registry = getResourceSet().getPackageRegistry(); final EClass eClass = getEClass(me.metamodelUri, me.typeName, registry); final EObject obj = createInstance(eClass); if (me.isSetId()) { nodeIdToEObjectMap.put(me.id, obj); synchronized(classToEObjectsMap) { final EList<EObject> instances = classToEObjectsMap.get(eClass); if (instances != null) { instances.add(obj); } } } if (me.isSetAttributes()) { final EFactory factory = registry.getEFactory(eClass.getEPackage().getNsURI()); for (final AttributeSlot s : me.attributes) { SlotDecodingUtils.setFromSlot(factory, eClass, obj, s); } } else if (!descriptor.getLoadingMode().isGreedyAttributes()) { getLazyResolver().putLazyAttributes(me.id, obj); } return obj; }
public EObject createInstance(final EClass eClass) { final String nsURI = eClass.getEPackage().getNsURI(); final EFactory factory = packageRegistry.getEFactory(nsURI); if (factory == null) { throw new NoSuchElementException(String.format("Could not find the EFactory for nsURI '%s' in the resource set's package registry", nsURI)); } final EObject obj = factory.create(eClass); return createLazyLoadingInstance(eClass, obj.getClass()); }