Java Code Examples for org.eclipse.emf.ecore.EClass#getEAnnotation()

The following examples show how to use org.eclipse.emf.ecore.EClass#getEAnnotation() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ExclusiveGroups.java    From neoscada with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Finds the annotation even on supertypes
 * 
 * @param target
 *            the object to check
 * @return the annotation or <code>null</code> the object or its supertypes
 *         don't have the annotation
 */
public static EAnnotation findAnnotation ( final EObject target )
{
    EAnnotation annotation;

    annotation = target.eClass ().getEAnnotation ( SOURCE_NAME );
    if ( annotation != null )
    {
        logger.debug ( "Found direct annotation - target: {}, annotation: {}", target, annotation );
        return annotation;
    }

    for ( final EClass clazz : target.eClass ().getEAllSuperTypes () )
    {
        logger.debug ( "Checking supertype: {}", clazz );
        annotation = clazz.getEAnnotation ( SOURCE_NAME );
        if ( annotation != null )
        {
            logger.debug ( "Found annotation - target: {}, superclass: {}, annotation: {}", target, clazz, annotation );
            return annotation;
        }
    }
    logger.debug ( "Annotation on {} not found", target );
    return null;
}
 
Example 2
Source File: NewClassBulkChange.java    From BIMserver with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
	public void change(Database database, DatabaseSession databaseSession) throws BimserverDatabaseException {
		boolean transactional = !(ePackage == Ifc2x3tc1Package.eINSTANCE || ePackage == Ifc4Package.eINSTANCE || ePackage == GeometryPackage.eINSTANCE);
		LOGGER.debug("Creating " + eClasses.size() + " " + (transactional ? "transactional" : "non transactional")  + " tables for package " + ePackage.getName());
		for (EClass eClass : eClasses) {
			String tableName = eClass.getEPackage().getName() + "_" + eClass.getName();
			if (eClass.getEAnnotation("nodatabase") == null) {
				try {
					boolean created = database.createTable(eClass, databaseSession, transactional);
					if (!created) {
						throw new BimserverDatabaseException("Could not create table " + tableName);
					}
//				for (EStructuralFeature eStructuralFeature : eClass.getEAllStructuralFeatures()) {
//					if (eStructuralFeature.getEAnnotation("index") != null) {
//						database.createIndexTable(eClass, eStructuralFeature, databaseSession);
//					}
//				}
				} catch (BimserverLockConflictException e) {
					LOGGER.error("", e);
				}
			}
		}
	}
 
Example 3
Source File: GetRevisionSummaryDatabaseAction.java    From BIMserver with GNU Affero General Public License v3.0 5 votes vote down vote up
private RevisionSummary createSummary() {
	RevisionSummary revisionSummary = StoreFactory.eINSTANCE.createRevisionSummary();
	revisionSummaryContainerEntities = StoreFactory.eINSTANCE.createRevisionSummaryContainer();
	revisionSummaryContainerEntities.setName("IFC Entities");
	revisionSummary.getList().add(revisionSummaryContainerEntities);
	revisionSummaryContainerRelations = StoreFactory.eINSTANCE.createRevisionSummaryContainer();
	revisionSummaryContainerRelations.setName("IFC Relations");
	revisionSummary.getList().add(revisionSummaryContainerRelations);
	revisionSummaryContainerPrimitives = StoreFactory.eINSTANCE.createRevisionSummaryContainer();
	revisionSummaryContainerPrimitives.setName("IFC Primitives");
	revisionSummary.getList().add(revisionSummaryContainerPrimitives);
	revisionSummaryContainerOther = StoreFactory.eINSTANCE.createRevisionSummaryContainer();
	revisionSummaryContainerOther.setName("Rest");
	revisionSummary.getList().add(revisionSummaryContainerOther);
	for (EClass eClass : map.keySet()) {
		RevisionSummaryContainer subMap = null;
		if (Ifc2x3tc1Package.eINSTANCE.getIfcObject().isSuperTypeOf(eClass)) {
			subMap = revisionSummaryContainerEntities;
		} else if (Ifc2x3tc1Package.eINSTANCE.getIfcRelationship().isSuperTypeOf(eClass)) {
			subMap = revisionSummaryContainerRelations;
		} else if (eClass.getEAnnotation("wrapped") != null) {
			subMap = revisionSummaryContainerPrimitives;
		} else {
			subMap = revisionSummaryContainerOther;
		}
		RevisionSummaryType createRevisionSummaryType = StoreFactory.eINSTANCE.createRevisionSummaryType();
		createRevisionSummaryType.setSchema(eClass.getEPackage().getName());
		createRevisionSummaryType.setCount(map.get(eClass));
		createRevisionSummaryType.setName(eClass.getName());
		subMap.getTypes().add(createRevisionSummaryType);
	}
	return revisionSummary;
}
 
Example 4
Source File: SummaryMap.java    From BIMserver with GNU Affero General Public License v3.0 5 votes vote down vote up
public RevisionSummary toRevisionSummary(DatabaseSession databaseSession) throws BimserverDatabaseException {
	RevisionSummary revisionSummary = databaseSession.create(RevisionSummary.class);
	RevisionSummaryContainer revisionSummaryContainerEntities = databaseSession.create(RevisionSummaryContainer.class);
	revisionSummaryContainerEntities.setName("IFC Entities");
	revisionSummary.getList().add(revisionSummaryContainerEntities);
	RevisionSummaryContainer revisionSummaryContainerRelations = databaseSession.create(RevisionSummaryContainer.class);
	revisionSummaryContainerRelations.setName("IFC Relations");
	revisionSummary.getList().add(revisionSummaryContainerRelations);
	RevisionSummaryContainer revisionSummaryContainerPrimitives = databaseSession.create(RevisionSummaryContainer.class);
	revisionSummaryContainerPrimitives.setName("IFC Primitives");
	revisionSummary.getList().add(revisionSummaryContainerPrimitives);
	RevisionSummaryContainer revisionSummaryContainerOther = databaseSession.create(RevisionSummaryContainer.class);
	revisionSummaryContainerOther.setName("Rest");
	revisionSummary.getList().add(revisionSummaryContainerOther);
	
	for (EClass eClass : summaryMap.keySet()) {
		RevisionSummaryContainer subMap = null;
		if (((EClass) packageMetaData.getEPackage().getEClassifier("IfcObject")).isSuperTypeOf(eClass)) {
			subMap = revisionSummaryContainerEntities;
		} else if (((EClass) packageMetaData.getEPackage().getEClassifier("IfcRelationship")).isSuperTypeOf(eClass)) {
			subMap = revisionSummaryContainerRelations;
		} else if (eClass.getEAnnotation("wrapped") != null) {
			subMap = revisionSummaryContainerPrimitives;
		} else {
			subMap = revisionSummaryContainerOther;
		}
		RevisionSummaryType createRevisionSummaryType = databaseSession.create(RevisionSummaryType.class);
		createRevisionSummaryType.setSchema(eClass.getEPackage().getName());
		createRevisionSummaryType.setCount(summaryMap.get(eClass));
		createRevisionSummaryType.setName(eClass.getName());
		subMap.getTypes().add(createRevisionSummaryType);
	}
	return revisionSummary;
}
 
Example 5
Source File: GenerateGeometryLibrary.java    From BIMserver with GNU Affero General Public License v3.0 5 votes vote down vote up
private void process(EClass eClass, EReference eReferencedFrom) {
		if (definesNode.has(eClass.getName())) {
			return;
		}
//		if (eReferencedFrom != null) {
//			System.out.println(eReferencedFrom.getEContainingClass().getName() + "." + eReferencedFrom.getName() + " -> " + eClass.getName());
//		}
		ObjectNode defineNode = OBJECT_MAPPER.createObjectNode();
		definesNode.set(eClass.getName(), defineNode);
		
		// TODO no type node required, subclasses always used
		ObjectNode typeNode = OBJECT_MAPPER.createObjectNode();
		typeNode.put("name", eClass.getName());
		typeNode.put("includeAllSubTypes", true);
		defineNode.set("type", typeNode);
		
		ArrayNode fieldsNode = OBJECT_MAPPER.createArrayNode();
		defineNode.set("fields", fieldsNode);
		
		ArrayNode includesNode = OBJECT_MAPPER.createArrayNode();
		defineNode.set("includes", includesNode);
		for (EReference eReference : eClass.getEAllReferences()) {
			if (!packageMetaData.isInverse(eReference) || isException(eReference)) {
				EClass eType = (EClass) eReference.getEType();
				if (eType.getEPackage() == ePackage) {
					for (EClass eClass2 : packageMetaData.getAllSubClassesIncludingSelf(eType)) {
						if (eClass2.getEAnnotation("wrapped") == null) {
							process(eClass2);
							includesNode.add(eClass2.getName());
						}
					}
					fieldsNode.add(eReference.getName());
				}
			}
		}
	}
 
Example 6
Source File: Express2EMF.java    From BIMserver with GNU Affero General Public License v3.0 5 votes vote down vote up
private void clean() {
		Iterator<EClassifier> iterator = schemaPack.getEClassifiers().iterator();
		while (iterator.hasNext()) {
			EClassifier eClassifier = iterator.next();
			if (eClassifier instanceof EClass) {
				EClass eClass = (EClass) eClassifier;
				if (eClass.getEAnnotation("wrapped") != null) {
					if (eClass.getESuperTypes().size() == 1) {
//						iterator.remove();
					}
				}
			}
		}
	}
 
Example 7
Source File: Express2EMF.java    From BIMserver with GNU Affero General Public License v3.0 5 votes vote down vote up
private boolean superTypeIsWrapped(EClass eType) {
	if (eType.getEAnnotation("wrapped") != null) {
		return true;
	}
	for (EClass superClass : eType.getESuperTypes()) {
		if (superTypeIsWrapped(superClass)) {
			return true;
		}
	}
	return false;
}
 
Example 8
Source File: ModelValidator.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Validate OCL constraints and return true if OCL constraint holds, false
 * otherwise.
 */
private boolean validate_EveryInvariant(Instance instance,
	DiagnosticChain diagnostics, Map<Object, Object> context) {
	final EClass eClass = instance.getEClass();
	final EAnnotation annotation = eClass.getEAnnotation(OCL_SOURCE_URI);
	if (annotation != null) {
		for (final Entry<String, String> entry : annotation.getDetails()) {
			try {
				final String expression = entry.getValue();
				if (!(Boolean) evaluate(instance, expression)) {
					if (diagnostics != null) {
						diagnostics.add(new BasicDiagnostic(
							Diagnostic.ERROR, DIAGNOSTIC_SOURCE, 0,
							EcorePlugin.INSTANCE.getString(
								"_UI_GenericConstraint_diagnostic", //$NON-NLS-1$
								new Object[] {
									entry.getKey(),
									getObjectLabel(
										(EObject) instance,
										context) }),
							new Object[] { instance }));
					}
					return false;
				}
			} catch (final ParserException e) {
				System.out.println(e);
			}
		}
	}
	return true;
}
 
Example 9
Source File: IfcStepSerializer.java    From IfcPlugins with GNU Affero General Public License v3.0 4 votes vote down vote up
private void write(IdEObject object) throws SerializerException, IOException {
	EClass eClass = object.eClass();
	if (eClass.getEAnnotation("hidden") != null) {
		return;
	}
	if (eClass.getEPackage() != getPackageMetaData().getEPackage()) {
		return;
	}
	print(DASH);
	long convertedKey = getExpressId(object);
	if (convertedKey == -1) {
		throw new SerializerException("Going to serialize an object with id -1 (" + object.eClass().getName() + ")");
	}
	print(String.valueOf(convertedKey));
	print("= ");
	String upperCase = getPackageMetaData().getUpperCase(eClass);
	if (upperCase == null) {
		throw new SerializerException("Type not found: " + eClass.getName());
	}
	print(upperCase);
	print(OPEN_PAREN);
	boolean isFirst = true;
	EntityDefinition entityBN = getPackageMetaData().getSchemaDefinition().getEntityBN(object.eClass().getName());
	for (EStructuralFeature feature : eClass.getEAllStructuralFeatures()) {
		if (feature.getEAnnotation("hidden") == null && (entityBN != null && (!entityBN.isDerived(feature.getName()) || entityBN.isDerivedOverride(feature.getName())))) {
			EClassifier type = feature.getEType();
			if (type instanceof EEnum) {
				if (!isFirst) {
					print(COMMA);
				}
				writeEnum(object, feature);
				isFirst = false;
			} else if (type instanceof EClass) {
				EReference eReference = (EReference)feature;
				if (!getPackageMetaData().isInverse(eReference)) {
					if (!isFirst) {
						print(COMMA);
					}
					writeEClass(object, feature);
					isFirst = false;
				}
			} else if (type instanceof EDataType) {
				if (!isFirst) {
					print(COMMA);
				}
				writeEDataType(object, entityBN, feature);
				isFirst = false;
			}
		}
	}
	println(PAREN_CLOSE_SEMICOLON);
}
 
Example 10
Source File: IfcStepStreamingSerializer.java    From IfcPlugins with GNU Affero General Public License v3.0 4 votes vote down vote up
private void write(HashMapVirtualObject object) throws SerializerException, IOException {
	EClass eClass = object.eClass();

	if (eClass.getEPackage() == GeometryPackage.eINSTANCE) {
		return;
	}
	if (eClass.getEAnnotation("hidden") != null) {
		return;
	}
	print(DASH);
	long convertedKey = getExpressId(object);
	if (convertedKey == -1) {
		throw new SerializerException("Going to serialize an object with id -1 (" + object.eClass().getName() + ")");
	}
	print(String.valueOf(convertedKey));
	print("= ");
	String upperCase = packageMetaData.getUpperCase(eClass);
	if (upperCase == null) {
		throw new SerializerException("Type not found: " + eClass.getName());
	}
	print(upperCase);
	print(OPEN_PAREN);
	boolean isFirst = true;
	
	EntityDefinition entityBN = getSchemaDefinition().getEntityBN(object.eClass().getName());
	for (EStructuralFeature feature : eClass.getEAllStructuralFeatures()) {

		if (feature.getEAnnotation("hidden") == null && (entityBN != null && (!entityBN.isDerived(feature.getName()) || entityBN.isDerivedOverride(feature.getName())))) {
			EClassifier type = feature.getEType();
			if (type instanceof EEnum) {
				if (!isFirst) {
					print(COMMA);
				}
				writeEnum(object, feature);
				isFirst = false;
			} else if (type instanceof EClass) {
				EReference eReference = (EReference)feature;
				if (!packageMetaData.isInverse(eReference)) {
					if (!isFirst) {
						print(COMMA);
					}
					writeEClass(object, feature);
					isFirst = false;
				}
			} else if (type instanceof EDataType) {
				if (!isFirst) {
					print(COMMA);
				}
				writeEDataType(object, entityBN, feature);
				isFirst = false;
			}
		}
	}
	println(PAREN_CLOSE_SEMICOLON);
}
 
Example 11
Source File: NewReferenceChange.java    From BIMserver with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public void change(Database database, DatabaseSession databaseSession) throws NotImplementedException, BimserverDatabaseException {
	EClass eClass = eReference.getEContainingClass();
	KeyValueStore keyValueStore = database.getKeyValueStore();
	for (EClass subClass : schema.getSubClasses(eClass)) {
		try {
			if (subClass.getEAnnotation("nodatabase") == null) {
				RecordIterator recordIterator = keyValueStore.getRecordIterator(subClass.getEPackage().getName() + "_" + subClass.getName(), databaseSession);
				try {
					Record record = recordIterator.next();
					while (record != null) {
						ByteBuffer buffer = ByteBuffer.wrap(record.getValue());

						int nrStartBytesBefore = (int) Math.ceil(nrFeaturesBefore / 8.0);
						int newIndex = nrFeaturesBefore + 1;
						int nrStartBytesAfter = (int) Math.ceil(newIndex / 8.0);
						
						byte[] unsetted = new byte[nrStartBytesAfter];
						buffer.get(unsetted, 0, nrStartBytesBefore);
						
						if (eReference.isUnsettable()) {
							unsetted[newIndex / 8] |= (1 << (newIndex % 8));
						}
						
						int extra = 0;
						
						if (!eReference.isUnsettable()) {
							if (eReference.isMany()) {
								extra = 4;
							} else {
								extra = 2;
							}
						}
						
						ByteBuffer newBuffer = ByteBuffer.allocate(record.getValue().length + (nrStartBytesAfter - nrStartBytesBefore) + extra);
						newBuffer.put(unsetted);
						buffer.position(nrStartBytesBefore);
						newBuffer.put(buffer);
						
						if (!eReference.isUnsettable()) {
							if (eReference.isMany()) {
								newBuffer.putInt(0);
							} else {
								buffer.order(ByteOrder.LITTLE_ENDIAN);
								newBuffer.putShort((short)-1);
								buffer.order(ByteOrder.BIG_ENDIAN);
							}
						}
						
						keyValueStore.store(subClass.getEPackage().getName() + "_" + subClass.getName(), record.getKey(), newBuffer.array(), databaseSession);
						record = recordIterator.next();
					}
				} finally {
					recordIterator.close();
				}
			}
		} catch (BimserverLockConflictException e) {
			LOGGER.error("", e);
		}
	}
}
 
Example 12
Source File: SetWrappedAttributeChange.java    From BIMserver with GNU Affero General Public License v3.0 4 votes vote down vote up
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public void execute(Transaction transaction) throws UserException, BimserverLockConflictException,
		BimserverDatabaseException, IOException, QueryException {
	PackageMetaData packageMetaData = transaction.getDatabaseSession().getMetaDataManager().getPackageMetaData(transaction.getProject().getSchema());
	
	Query query = new Query(packageMetaData);
	QueryPart queryPart = query.createQueryPart();
	queryPart.addOid(oid);
	
	HashMapVirtualObject object = transaction.get(oid);
	
	if (object == null) {
		QueryObjectProvider queryObjectProvider = new QueryObjectProvider(transaction.getDatabaseSession(), transaction.getBimServer(), query, Collections.singleton(transaction.getPreviousRevision().getOid()), packageMetaData);
		object = queryObjectProvider.next();
		transaction.updated(object);
	}
	
	EClass eClass = transaction.getDatabaseSession().getEClassForOid(oid);
	if (!ChangeHelper.canBeChanged(eClass)) {
		throw new UserException("Only objects from the following schemas are allowed to be changed: Ifc2x3tc1 and IFC4, this object (" + eClass.getName() + ") is from the \"" + eClass.getEPackage().getName() + "\" package");
	}

	if (object == null) {
		throw new UserException("No object of type \"" + eClass.getName() + "\" with oid " + oid + " found in project with pid " + transaction.getProject().getId());
	}
	EReference eReference = packageMetaData.getEReference(eClass.getName(), attributeName);
	if (eReference == null) {
		throw new UserException("No reference with the name \"" + attributeName + "\" found in class \"" + eClass.getName() + "\"");
	}
	if (value instanceof List && eReference.isMany()) {
		List sourceList = (List)value;
		if (!eReference.isMany()) {
			throw new UserException("Attribute is not of type 'many'");
		}
		List list = (List)object.eGet(eReference);
		for (Object o : sourceList) {
			if (eReference.getEType() == EcorePackage.eINSTANCE.getEDouble()) {
				List asStringList = (List)object.eGet(object.eClass().getEStructuralFeature(attributeName + "AsString"));
				asStringList.add(String.valueOf(o));
			}
			list.add(o);
		}
	} else {
		if (eReference.isMany()) {
			throw new UserException("Attribute is not of type 'single'");
		}
		if (eReference.getEType() instanceof EEnum) {
			EEnum eEnum = (EEnum) eReference.getEType();
			object.set(eReference.getName(), eEnum.getEEnumLiteral(((String) value).toUpperCase()).getInstance());
		} else {
			EClass typeEClass = (EClass) packageMetaData.getEClassifier(type);
			if (typeEClass.getEAnnotation("wrapped") == null) {
				throw new UserException("Not a wrapped type");
			}
			HashMapWrappedVirtualObject wrappedObject = new HashMapWrappedVirtualObject(typeEClass);
			if (typeEClass == Ifc2x3tc1Package.eINSTANCE.getIfcBoolean()) {
				if ((Boolean)value == true) {
					value = Tristate.TRUE;
				} else {
					value = Tristate.FALSE;
				}
			}
			wrappedObject.set(wrappedObject.eClass().getEStructuralFeature("wrappedValue").getName(), value);
			object.set(eReference.getName(), wrappedObject);
			if (value instanceof Double) {
				wrappedObject.set(wrappedObject.eClass().getEStructuralFeature("wrappedValueAsString").getName(), String.valueOf((Double)value));
			}
		}
	}
}