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

The following examples show how to use org.eclipse.emf.ecore.EStructuralFeature#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: PredicateHandler.java    From elexis-3-core with Eclipse Public License 1.0 6 votes vote down vote up
public String getAttributeName(EStructuralFeature feature,
	Class<? extends EntityWithId> entityClazz){
	String ret = feature.getName();
	EAnnotation mappingAnnotation =
		feature.getEAnnotation(IModelService.EANNOTATION_ENTITY_ATTRIBUTE_MAPPING);
	if (mappingAnnotation != null) {
		// test class specific first
		ret = mappingAnnotation.getDetails().get(entityClazz.getSimpleName() + "#"
			+ IModelService.EANNOTATION_ENTITY_ATTRIBUTE_MAPPING_NAME);
		if (ret == null) {
			// fallback to direct mapping
			ret = mappingAnnotation.getDetails()
				.get(IModelService.EANNOTATION_ENTITY_ATTRIBUTE_MAPPING_NAME);
		}
	}
	return ret;
}
 
Example 2
Source File: QueryClassificationsAndTypesStackFrame.java    From BIMserver with GNU Affero General Public License v3.0 5 votes vote down vote up
public List<ObjectIdentifier> getOids(EClass eClass, EStructuralFeature eStructuralFeature, Object value, DatabaseInterface databaseInterface, int pid, int rid) throws BimserverDatabaseException {
	if (eStructuralFeature.getEAnnotation("singleindex") != null) {
		List<ObjectIdentifier> result = new ArrayList<>();
		String indexTableName = eStructuralFeature.getEContainingClass().getEPackage().getName() + "_" + eClass.getName() + "_" + eStructuralFeature.getName();
		byte[] queryBytes = null;
		if (value instanceof String) {
			queryBytes = ((String)value).getBytes(Charsets.UTF_8);
		} else if (value instanceof Integer) {
			queryBytes = BinUtils.intToByteArray((Integer)value);
		} else if (value instanceof Long) {
			queryBytes = BinUtils.longToByteArray((Long)value);
		} else {
			throw new BimserverDatabaseException("Unsupported type " + value);
		}
		ByteBuffer valueBuffer = ByteBuffer.allocate(queryBytes.length + 8);
		valueBuffer.putInt(pid);
		valueBuffer.putInt(-rid);
		valueBuffer.put(queryBytes);
		List<byte[]> duplicates = databaseInterface.getDuplicates(indexTableName, valueBuffer.array());
		for (byte[] duplicate : duplicates) {
			ByteBuffer buffer = ByteBuffer.wrap(duplicate);
			buffer.getInt(); // pid
			long oid = buffer.getLong();
			
			result.add(new ObjectIdentifier(oid, (short)oid));
		}
		return result;
	} else {
		throw new UnsupportedOperationException();
	}
}
 
Example 3
Source File: Database.java    From BIMserver with GNU Affero General Public License v3.0 5 votes vote down vote up
public void initInternalStructure(DatabaseSession databaseSession) throws BimserverLockConflictException, BimserverDatabaseException {
	RecordIterator recordIterator = keyValueStore.getRecordIterator(CLASS_LOOKUP_TABLE, databaseSession);
	try {
		Record record = recordIterator.next();
		while (record != null) {
			String packageAndClassName = BinUtils.byteArrayToString(record.getValue());
			String packageName = packageAndClassName.substring(0, packageAndClassName.indexOf("_"));
			String className = packageAndClassName.substring(packageAndClassName.indexOf("_") + 1);
			EClass eClass = (EClass) getEClassifier(packageName, className);
			
			// TODO geometry?
			boolean transactional = !(eClass.getEPackage() == Ifc2x3tc1Package.eINSTANCE || eClass.getEPackage() == Ifc4Package.eINSTANCE);

			keyValueStore.openTable(databaseSession, packageAndClassName, transactional);
			
			for (EStructuralFeature eStructuralFeature : eClass.getEAllStructuralFeatures()) {
				if (eStructuralFeature.getEAnnotation("singleindex") != null) {
					String indexTableName = eClass.getEPackage().getName() + "_" + eClass.getName() + "_" + eStructuralFeature.getName();
					try {
						keyValueStore.openIndexTable(databaseSession, indexTableName, transactional);
					} catch (DatabaseNotFoundException e) {
					}
				}
			}
			
			Short cid = BinUtils.byteArrayToShort(record.getKey());
			cidToEclass[cid] = eClass;
			eClassToCid.put(eClass, cid);
			record = recordIterator.next();
		}
	} finally {
		recordIterator.close();
	}
}
 
Example 4
Source File: GenerateUtils.java    From BIMserver with GNU Affero General Public License v3.0 5 votes vote down vote up
public static String makeGetter(EStructuralFeature eStructuralFeature) {
	StringBuilder sb = new StringBuilder();
	if (eStructuralFeature.getEType() == EcorePackage.eINSTANCE.getEBoolean()) {
		sb.append("is");
	} else {
		sb.append("get");
	}
	sb.append(firstLetterUpperCase(eStructuralFeature.getName()));
	if (eStructuralFeature instanceof EReference && !eStructuralFeature.isMany() && eStructuralFeature.getEAnnotation("embedsreference") == null) {
		sb.append("Id");
	}
	return sb.toString();
}
 
Example 5
Source File: GenerateUtils.java    From BIMserver with GNU Affero General Public License v3.0 5 votes vote down vote up
public static String makeSetter(EStructuralFeature eStructuralFeature) {
	StringBuilder sb = new StringBuilder();
	sb.append("set" + firstLetterUpperCase(eStructuralFeature.getName()));
	if (eStructuralFeature instanceof EReference && !eStructuralFeature.isMany() && eStructuralFeature.getEAnnotation("embedsreference") == null) {
		sb.append("Id");
	}
	return sb.toString();
}
 
Example 6
Source File: PackageMetaData.java    From BIMserver with GNU Affero General Public License v3.0 5 votes vote down vote up
private void buildUseForDatabaseStorage(EClass eClass) {
	if (this.getSchemaDefinition() != null) {
		Set<EStructuralFeature> set = new HashSet<>();
		for (EStructuralFeature eStructuralFeature : eClass.getEAllStructuralFeatures()) {
			EntityDefinition entityBN = this.getSchemaDefinition().getEntityBN(eClass.getName());
			if (entityBN == null) {
				set.add(eStructuralFeature);
			} else {
				if (!entityBN.isDerived(eStructuralFeature.getName())) {
					boolean derived = false;
					if (eStructuralFeature.getEAnnotation("hidden") != null) {
						if (eStructuralFeature.getEAnnotation("asstring") == null) {
						} else {
							if (entityBN.isDerived(eStructuralFeature.getName().substring(0, eStructuralFeature.getName().length() - 8))) {
								derived = true;
							} else {
								set.add(eStructuralFeature);
							}
						}
					}
					Attribute attribute = entityBN.getAttributeBNWithSuper(eStructuralFeature.getName());
					if (attribute == null) {
						// geometry, *AsString
						if (!derived) {
							set.add(eStructuralFeature);
						}
					} else {
						if (attribute instanceof ExplicitAttribute || attribute instanceof InverseAttribute) {
							if (!entityBN.isDerived(attribute.getName())) {
								set.add(eStructuralFeature);
							}
						}
					}
				}
			}
		}
		useForDatabaseStorage.put(eClass, set);
	}
}
 
Example 7
Source File: Configurations.java    From neoscada with Eclipse Public License 1.0 4 votes vote down vote up
public static void encode ( final Map<String, String> data, final String prefix, final EObject object )
{
    if ( object == null )
    {
        return;
    }

    for ( final EStructuralFeature sf : object.eClass ().getEAllStructuralFeatures () )
    {
        if ( sf.isMany () )
        {
            continue;
        }

        final EAnnotation an = sf.getEAnnotation ( "http://eclipse.org/SCADA/CA/Descriptor" ); //$NON-NLS-1$
        if ( an == null )
        {
            continue;
        }
        final String name = an.getDetails ().get ( "name" ); //$NON-NLS-1$
        if ( name == null )
        {
            continue;
        }
        final String format = an.getDetails ().get ( "format" ); //$NON-NLS-1$

        String key;
        String value;

        if ( prefix != null )
        {
            key = prefix + "." + name;
        }
        else
        {
            key = name;
        }

        final Object v = object.eGet ( sf );
        if ( v == null )
        {
            continue;
        }

        if ( format != null )
        {
            value = String.format ( format, v );
        }
        else
        {
            value = v == null ? null : v.toString ();
        }

        data.put ( key, value );
    }
}
 
Example 8
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 9
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 10
Source File: DatabaseSession.java    From BIMserver with GNU Affero General Public License v3.0 4 votes vote down vote up
private IdEObject readReference(EClass originalQueryClass, ByteBuffer buffer, IfcModelInterface model, IdEObject object, EStructuralFeature feature, EClass eClass,
		QueryInterface query, TodoList todoList) throws BimserverDatabaseException {
	// TODO next bit seems to make no sense, why detect a deleted record when reading a reference??
	if (buffer.capacity() == 1 && buffer.get(0) == -1) {
		buffer.position(buffer.position() + 1);
		return null;
	}
	buffer.order(ByteOrder.LITTLE_ENDIAN);
	long oid = buffer.getLong();
	buffer.order(ByteOrder.BIG_ENDIAN);
	IdEObject foundInCache = objectCache.get(oid);
	if (foundInCache != null) {
		return foundInCache;
	}
	if (model.contains(oid)) {
		return model.get(oid);
	}
	IdEObjectImpl newObject = createInternal(eClass, query);
	newObject.setOid(oid);
	if (perRecordVersioning(newObject)) {
		newObject.setPid(Database.STORE_PROJECT_ID);
	} else {
		newObject.setPid(query.getPid());
	}
	newObject.setRid(query.getRid());
	newObject.setModel(model);
	objectCache.put(oid, newObject);
	if (query.isDeep() && object.eClass().getEAnnotation("wrapped") == null) {
		if (feature.getEAnnotation("nolazyload") == null) {
			todoList.add(newObject);
		}
	} else {
		if (object.eClass().getEAnnotation("wrapped") == null) {
			try {
				model.addAllowMultiModel(oid, newObject);
			} catch (IfcModelInterfaceException e) {
				throw new BimserverDatabaseException(e);
			}
		}
	}
	return newObject;
}
 
Example 11
Source File: GenerateUtils.java    From BIMserver with GNU Affero General Public License v3.0 4 votes vote down vote up
public static String getType(EStructuralFeature eStructuralFeature) {
	boolean embedsReference = eStructuralFeature.getEAnnotation("embedsreference") != null;
	EClassifier eType = eStructuralFeature.getEType();
	if (eStructuralFeature.isMany()) {
		if (eType instanceof EDataType) {
			if (eType == EcorePackage.eINSTANCE.getEString()) {
				return "List<String>";
			} else if (eType == EcorePackage.eINSTANCE.getEInt() || eType == EcorePackage.eINSTANCE.getEIntegerObject()) {
				return "List<Integer>";
			} else if (eType == EcorePackage.eINSTANCE.getELong() || eType == EcorePackage.eINSTANCE.getELongObject()) {
				return "List<Long>";
			} else if (eType == EcorePackage.eINSTANCE.getEDouble() || eType == EcorePackage.eINSTANCE.getEDoubleObject()) {
				return "List<Double>";
			} else if (eType == EcorePackage.eINSTANCE.getEBoolean() || eType == EcorePackage.eINSTANCE.getEBooleanObject()) {
				return "List<Boolean>";
			} else if (eType == EcorePackage.eINSTANCE.getEFloat() || eType == EcorePackage.eINSTANCE.getEFloatObject()) {
				return "List<Float>";
			} else if (eType == EcorePackage.eINSTANCE.getEDate()) {
				return "List<Date>";
			}
		} else if (eType instanceof EClass) {
			if (embedsReference) {
				return "List<S" + eType.getName() + ">";
			} else {
				return "List<Long>";
			}
		}
	} else {
		if (eType instanceof EDataType) {
			if (eType == EcorePackage.eINSTANCE.getEString()) {
				return "String";
			} else if (eType == EcorePackage.eINSTANCE.getEInt() || eType == EcorePackage.eINSTANCE.getEIntegerObject()) {
				return "Integer";
			} else if (eType == EcorePackage.eINSTANCE.getELong() || eType == EcorePackage.eINSTANCE.getELongObject()) {
				return "Long";
			} else if (eType == EcorePackage.eINSTANCE.getEShort() || eType == EcorePackage.eINSTANCE.getEShortObject()) {
				return "Short";
			} else if (eType == EcorePackage.eINSTANCE.getEDouble() || eType == EcorePackage.eINSTANCE.getEDoubleObject()) {
				return "Double";
			} else if (eType == EcorePackage.eINSTANCE.getEBoolean() || eType == EcorePackage.eINSTANCE.getEBooleanObject()) {
				return "Boolean";
			} else if (eType == EcorePackage.eINSTANCE.getEFloat() || eType == EcorePackage.eINSTANCE.getEFloatObject()) {
				return "Float";
			} else if (eType == EcorePackage.eINSTANCE.getEDate()) {
				return "Date";
			} else if (eType == EcorePackage.eINSTANCE.getEByteArray()) {
				return "byte[]";
			} else if (eType.getInstanceClass() == DataHandler.class) {
				return "DataHandler";
			}
		} else if (eType instanceof EClass) {
			if (embedsReference) {
				return "S" + eType.getName();
			} else {
				return "Long";
			}
		}
	}
	return "S" + eType.getName();
}
 
Example 12
Source File: Ecore2UimaTypeSystem.java    From uima-uimaj with Apache License 2.0 4 votes vote down vote up
/**
 * E structural feature 2 uima feature.
 *
 * @param aStructuralFeature the a structural feature
 * @param aOptions the a options
 * @return -
 * @throws URISyntaxException the URI syntax exception
 */
private static FeatureDescription eStructuralFeature2UimaFeature(
        EStructuralFeature aStructuralFeature, Map aOptions) throws URISyntaxException {
  FeatureDescription feat = uimaFactory.createFeatureDescription();
  feat.setName(aStructuralFeature.getName());
  String rangeTypeName = null;
  String elementTypeName = null;
  EAnnotation eannot = aStructuralFeature.getEAnnotation("http://uima.apache.org");
  if (eannot != null) {
    feat.setDescription((String) eannot.getDetails().get("description"));
    // the UIMA type name to use may be recorded as an EAnnotation; this is
    // particularly important for arrays and lists, since Ecore doesn't distinguish between
    // these two possible implementations for a multi-valued property
    rangeTypeName = (String) eannot.getDetails().get("uimaType");
    // the elemnt type may also be specified as an EAnnotation; this is
    // used for the case where an FSArray or FSList is NOT represented
    // as a multi-valued property
    elementTypeName = (String) eannot.getDetails().get("elementType");
  }
  EClassifier attrRangeType = aStructuralFeature.getEType();

  // if range type wasn't specified in an EAnnotation, compute it ourselves
  if (rangeTypeName == null) {
    rangeTypeName = getUimaTypeName(attrRangeType, aStructuralFeature.isMany(), aOptions);
  }
  feat.setRangeTypeName(rangeTypeName);

  if (aStructuralFeature.isMany()) {
    // set the element type of the array/list to the EType of the structural feature
    // (except primitive, or TOP, which are assumed)
    String uimaElementType = getUimaTypeName(attrRangeType, false, aOptions);
    if (!CAS.TYPE_NAME_INTEGER.equals(uimaElementType)
            && !CAS.TYPE_NAME_FLOAT.equals(uimaElementType)
            && !CAS.TYPE_NAME_STRING.equals(uimaElementType)
            && !CAS.TYPE_NAME_TOP.equals(uimaElementType)
            && !CAS.TYPE_NAME_BYTE.equals(uimaElementType)
            && !CAS.TYPE_NAME_SHORT.equals(uimaElementType)
            && !CAS.TYPE_NAME_LONG.equals(uimaElementType)
            && !CAS.TYPE_NAME_DOUBLE.equals(uimaElementType)
            && !CAS.TYPE_NAME_BOOLEAN.equals(uimaElementType)) {
      feat.setElementType(uimaElementType);
    }
  } else if (!aStructuralFeature.getEType().equals(EcorePackage.eINSTANCE.getEByteArray())) {
    // if in Ecore we have a single-valued property whose range type is an array or list,
    // we need to set "multiple references allowed" to true in the UIMA type system
    // (exception: don't do this for the EByteArray data type, which is implicilty a
    // multi-valued type)
    if (isArrayOrList(rangeTypeName)) {
      feat.setMultipleReferencesAllowed(Boolean.TRUE);
      // also, set element type if one was contained in the EAnnotation
      feat.setElementType(elementTypeName);
    }
  }
  return feat;
}