use of org.eclipse.emf.ecore.EDataType in project BIMserver by opensourceBIM.
the class DatabaseReadingStackFrame method readEmbeddedValue.
private HashMapWrappedVirtualObject readEmbeddedValue(EStructuralFeature feature, ByteBuffer buffer, EClass eClass) throws BimserverDatabaseException {
HashMapWrappedVirtualObject eObject = new HashMapWrappedVirtualObject(eClass);
for (EStructuralFeature eStructuralFeature : eClass.getEAllStructuralFeatures()) {
if (eStructuralFeature.isMany()) {
} else {
if (eStructuralFeature.getEType() instanceof EDataType) {
Object primitiveValue = readPrimitiveValue(eStructuralFeature.getEType(), buffer);
eObject.setAttribute((EAttribute) eStructuralFeature, primitiveValue);
} else {
buffer.order(ByteOrder.LITTLE_ENDIAN);
short cid = buffer.getShort();
buffer.order(ByteOrder.BIG_ENDIAN);
if (cid == -1) {
// null, do nothing
} else if (cid < 0) {
// negative cid means value is embedded in
// record
EClass referenceClass = queryObjectProvider.getDatabaseSession().getEClass((short) (-cid));
eObject.setReference((EReference) eStructuralFeature, readEmbeddedValue(eStructuralFeature, buffer, referenceClass));
}
}
}
}
return eObject;
}
use of org.eclipse.emf.ecore.EDataType in project BIMserver by opensourceBIM.
the class DatabaseReadingStackFrame method convertByteArrayToObject.
protected HashMapVirtualObject convertByteArrayToObject(EClass eClass, long oid, ByteBuffer buffer, int rid) throws BimserverDatabaseException {
try {
int unsettedLength = getPackageMetaData().getUnsettedLength(eClass);
byte[] unsetted = new byte[unsettedLength];
buffer.get(unsetted);
int fieldCounter = 0;
HashMapVirtualObject idEObject = new HashMapVirtualObject(reusable, eClass, oid, new UUID(buffer.getLong(), buffer.getLong()));
for (EStructuralFeature feature : eClass.getEAllStructuralFeatures()) {
try {
if (getPackageMetaData().useForDatabaseStorage(eClass, feature)) {
boolean isUnsetted = (unsetted[fieldCounter / 8] & (1 << (fieldCounter % 8))) != 0;
if (isUnsetted) {
if (feature.isUnsettable()) {
idEObject.eUnset(feature);
} else if (feature.isMany()) {
// do nothing
} else if (feature.getDefaultValue() != null) {
idEObject.setAttribute((EAttribute) feature, feature.getDefaultValue());
}
} else {
Object newValue = null;
if (feature.isMany()) {
newValue = readList(idEObject, buffer, feature);
} else {
if (feature.getEType() instanceof EEnum) {
int enumOrdinal = buffer.getInt();
if (enumOrdinal == -1) {
newValue = null;
} else {
EClassifier eType = feature.getEType();
EEnumLiteral enumLiteral = ((EEnumImpl) eType).getEEnumLiteral(enumOrdinal);
if (enumLiteral != null) {
newValue = enumLiteral.getInstance();
}
}
} else if (feature.getEType() instanceof EClass) {
// EReference eReference = (EReference) feature;
buffer.order(ByteOrder.LITTLE_ENDIAN);
short cid = buffer.getShort();
buffer.order(ByteOrder.BIG_ENDIAN);
if (cid == -1) {
// null, do nothing
} else if (cid < 0) {
// negative cid means value is embedded in
// record
EClass referenceClass = queryObjectProvider.getDatabaseSession().getEClass((short) (-cid));
if (feature.getEAnnotation("dbembed") != null) {
newValue = readEmbeddedValue(feature, buffer, referenceClass);
} else {
newValue = readWrappedValue(feature, buffer, referenceClass);
}
} else if (cid > 0) {
// positive cid means value is reference to
// other record
EClass referenceClass = queryObjectProvider.getDatabaseSession().getEClass(cid);
if (referenceClass == null) {
throw new BimserverDatabaseException("No eClass found for cid " + cid);
}
buffer.position(buffer.position() - 2);
newValue = readReference(buffer, feature, referenceClass);
if ((Long) newValue != -1) {
if (queryObjectProvider.hasReadOrIsGoingToRead(((Long) newValue)) || queryObjectProvider.hasReadOrIsGoingToRead(referenceClass)) {
idEObject.addUseForSerialization(feature);
}
}
// if (eReference.getEOpposite() != null &&
// ((IdEObjectImpl)
// newValue).isLoadedOrLoading()) {
// newValue = null;
// }
}
} else if (feature.getEType() instanceof EDataType) {
newValue = readPrimitiveValue(feature.getEType(), buffer);
}
if (newValue != null) {
if (feature instanceof EAttribute) {
idEObject.setAttribute((EAttribute) feature, newValue);
} else {
if (newValue instanceof Long) {
idEObject.setReference((EReference) feature, (Long) newValue);
} else {
idEObject.setReference((EReference) feature, (WrappedVirtualObject) newValue);
}
}
}
}
}
fieldCounter++;
}
} catch (StringIndexOutOfBoundsException e) {
throw new BimserverDatabaseException("Reading " + eClass.getName() + "." + feature.getName(), e);
} catch (BufferUnderflowException e) {
throw new BimserverDatabaseException("Reading " + eClass.getName() + "." + feature.getName() + " " + buffer.capacity(), e);
} catch (BufferOverflowException e) {
throw new BimserverDatabaseException("Reading " + eClass.getName() + "." + feature.getName(), e);
}
}
return idEObject;
} catch (BufferUnderflowException e) {
throw new BimserverDatabaseException("Reading " + eClass.getName(), e);
} catch (BufferOverflowException e) {
throw new BimserverDatabaseException("Reading " + eClass.getName(), e);
}
}
use of org.eclipse.emf.ecore.EDataType in project BIMserver by opensourceBIM.
the class GenerateUtils method getType.
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();
}
use of org.eclipse.emf.ecore.EDataType in project BIMserver by opensourceBIM.
the class HashMapVirtualObject method writeList.
@SuppressWarnings("rawtypes")
private void writeList(VirtualObject virtualObject, ByteBuffer buffer, PackageMetaData packageMetaData, EStructuralFeature feature) throws BimserverDatabaseException {
if (feature.getEType() instanceof EEnum) {
// Aggregate relations to enums never occur... at this
// moment
} else if (feature.getEType() instanceof EClass) {
List list = (List) virtualObject.eGet(feature);
buffer.putInt(list.size());
for (Object o : list) {
if (o == null) {
buffer.order(ByteOrder.LITTLE_ENDIAN);
buffer.putShort((short) -1);
buffer.order(ByteOrder.BIG_ENDIAN);
} else {
if (o instanceof VirtualObject) {
VirtualObject listObject = (VirtualObject) o;
if (feature.getEAnnotation("twodimensionalarray") != null) {
Short cid = getDatabaseInterface().getCidOfEClass((EClass) feature.getEType());
buffer.order(ByteOrder.LITTLE_ENDIAN);
buffer.putShort((short) -cid);
buffer.order(ByteOrder.BIG_ENDIAN);
EStructuralFeature lf = listObject.eClass().getEStructuralFeature("List");
writeList(listObject, buffer, packageMetaData, lf);
} else {
if (listObject.eClass().getEAnnotation("wrapped") != null || listObject.eClass().getEStructuralFeature("wrappedValue") != null) {
writeWrappedValue(getPid(), getRid(), listObject, buffer, packageMetaData);
}
}
} else if (o instanceof Long) {
long listObjectOid = (Long) o;
writeReference(listObjectOid, buffer, feature);
} else if (o instanceof HashMapWrappedVirtualObject) {
HashMapWrappedVirtualObject hashMapWrappedVirtualObject = (HashMapWrappedVirtualObject) o;
writeWrappedValue(-1, -1, hashMapWrappedVirtualObject, buffer, packageMetaData);
}
}
}
} else if (feature.getEType() instanceof EDataType) {
List list = (List) virtualObject.eGet(feature);
if (list == null) {
buffer.putInt(-1);
} else {
buffer.putInt(list.size());
for (Object o : list) {
writePrimitiveValue(feature, o, buffer);
}
}
}
}
use of org.eclipse.emf.ecore.EDataType in project BIMserver by opensourceBIM.
the class HashMapVirtualObject method writeWrappedValue.
private void writeWrappedValue(int pid, int rid, WrappedVirtualObject wrappedValue, ByteBuffer buffer, PackageMetaData packageMetaData) throws BimserverDatabaseException {
Short cid = getDatabaseInterface().getCidOfEClass(wrappedValue.eClass());
buffer.order(ByteOrder.LITTLE_ENDIAN);
buffer.putShort((short) -cid);
buffer.order(ByteOrder.BIG_ENDIAN);
for (EStructuralFeature eStructuralFeature : wrappedValue.eClass().getEAllStructuralFeatures()) {
Object val = wrappedValue.eGet(eStructuralFeature);
if (eStructuralFeature.isMany()) {
List list = (List) val;
buffer.putInt(list.size());
for (Object o : list) {
if (o instanceof HashMapWrappedVirtualObject) {
writeWrappedValue(pid, rid, (VirtualObject) o, buffer, packageMetaData);
}
}
} else {
if (eStructuralFeature.getEType() instanceof EDataType) {
writePrimitiveValue(eStructuralFeature, val, buffer);
} else {
writeWrappedValue(pid, rid, (HashMapWrappedVirtualObject) val, buffer, packageMetaData);
}
}
}
}
Aggregations