use of org.bimserver.emf.IdEObject in project BIMserver by opensourceBIM.
the class DatabaseSession method getWrappedValueSize.
private int getWrappedValueSize(Object val, EReference eReference, PackageMetaData packageMetaData) {
if (val == null) {
return 2;
}
if (val instanceof EObject) {
IdEObject eObject = (IdEObject) val;
if (eReference.getEAnnotation("twodimensionalarray") != null) {
int refSize = 4;
EStructuralFeature eStructuralFeature = eObject.eClass().getEStructuralFeature("List");
List<?> l = (List<?>) eObject.eGet(eStructuralFeature);
for (Object o : l) {
if (o instanceof EObject) {
refSize += getWrappedValueSize(o, (EReference) eStructuralFeature, packageMetaData);
} else {
refSize += getPrimitiveSize((EDataType) eStructuralFeature.getEType(), o);
}
}
return refSize;
} else if (eReference.getEAnnotation("dbembed") != null) {
int refSize = 2;
refSize += getExactSize(eObject, packageMetaData, false);
return refSize;
} else if (eObject.eClass().getEAnnotation("wrapped") != null) {
IdEObject wrappedValue = (IdEObject) val;
EStructuralFeature wrappedValueFeature = wrappedValue.eClass().getEStructuralFeature("wrappedValue");
Object wrappedVal = eObject.eGet(wrappedValueFeature);
int refSize = 2 + getPrimitiveSize((EDataType) wrappedValueFeature.getEType(), wrappedVal);
if (wrappedValueFeature.getEType() == EcorePackage.eINSTANCE.getEDouble() || wrappedValueFeature.getEType() == EcorePackage.eINSTANCE.getEDoubleObject()) {
EStructuralFeature wrappedStringFeature = wrappedValue.eClass().getEStructuralFeature("wrappedValueAsString");
String str = (String) eObject.eGet(wrappedStringFeature);
refSize += getPrimitiveSize(EcorePackage.eINSTANCE.getEString(), str);
}
return refSize;
} else {
return 8;
}
} else {
throw new RuntimeException("Programming error, cannot happen");
}
}
use of org.bimserver.emf.IdEObject in project BIMserver by opensourceBIM.
the class ClientIfcModel method set.
@Override
public void set(IdEObject idEObject, EStructuralFeature eFeature, Object newValue) {
if (!recordChanges) {
return;
}
if (!eFeature.isMany()) {
if (getModelState() != ModelState.LOADING && ((IdEObjectImpl) idEObject).getLoadingState() != State.LOADING) {
try {
if (newValue != EStructuralFeature.Internal.DynamicValueHolder.NIL) {
LowLevelInterface lowLevelInterface = getBimServerClient().getLowLevelInterface();
if (eFeature.getName().equals("wrappedValue")) {
// Wrapped objects get the same oid as their
// "parent" object, so we know which object the
// client wants to update. That's why we can use
// idEObject.getOid() here
// We are making this crazy hack ever crazier, let's
// iterate over our parents features, and see if
// there is one matching our wrapped type...
// Seriously, when there are multiple fields of the
// same type, this fails miserably, a real fix
// should probably store the parent-oid + feature
// name in the wrapped object (requires two extra,
// volatile, fields),
// or we just don't support this (just create a new
// wrapped object too), we could even throw some
// sort of exception. Hack morally okay because it's
// client-side...
EReference foundReference = null;
if (contains(idEObject.getOid())) {
IdEObject parentObject = get(idEObject.getOid());
int found = 0;
foundReference = null;
for (EReference testReference : parentObject.eClass().getEAllReferences()) {
if (((EClass) testReference.getEType()).isSuperTypeOf(idEObject.eClass())) {
foundReference = testReference;
found++;
if (found > 1) {
throw new RuntimeException("Sorry, crazy hack could not resolve the right field, please let BIMserver developer know (debug info: " + parentObject.eClass().getName() + ", " + idEObject.eClass().getName() + ")");
}
}
}
if (eFeature.getEType() == EcorePackage.eINSTANCE.getEString()) {
lowLevelInterface.setWrappedStringAttribute(getTransactionId(), idEObject.getOid(), foundReference.getName(), idEObject.eClass().getName(), (String) newValue);
} else if (eFeature.getEType() == EcorePackage.eINSTANCE.getELong() || eFeature.getEType() == EcorePackage.eINSTANCE.getELongObject()) {
lowLevelInterface.setWrappedLongAttribute(getTransactionId(), idEObject.getOid(), foundReference.getName(), idEObject.eClass().getName(), (Long) newValue);
} else if (eFeature.getEType() == EcorePackage.eINSTANCE.getEDouble() || eFeature.getEType() == EcorePackage.eINSTANCE.getEDoubleObject()) {
lowLevelInterface.setWrappedDoubleAttribute(getTransactionId(), idEObject.getOid(), foundReference.getName(), idEObject.eClass().getName(), (Double) newValue);
} else if (eFeature.getEType() == EcorePackage.eINSTANCE.getEBoolean() || eFeature.getEType() == EcorePackage.eINSTANCE.getEBooleanObject()) {
lowLevelInterface.setWrappedBooleanAttribute(getTransactionId(), idEObject.getOid(), foundReference.getName(), idEObject.eClass().getName(), (Boolean) newValue);
} else if (eFeature.getEType() == EcorePackage.eINSTANCE.getEInt() || eFeature.getEType() == EcorePackage.eINSTANCE.getEIntegerObject()) {
lowLevelInterface.setWrappedIntegerAttribute(getTransactionId(), idEObject.getOid(), foundReference.getName(), idEObject.eClass().getName(), (Integer) newValue);
} else if (eFeature.getEType() == EcorePackage.eINSTANCE.getEByteArray()) {
throw new RuntimeException("Unimplemented " + eFeature.getEType().getName() + " " + newValue);
}
} else {
if (eFeature.getEType() == EcorePackage.eINSTANCE.getEString()) {
lowLevelInterface.setStringAttribute(getTransactionId(), idEObject.getOid(), eFeature.getName(), (String) newValue);
} else if (eFeature.getEType() == EcorePackage.eINSTANCE.getELong() || eFeature.getEType() == EcorePackage.eINSTANCE.getELongObject()) {
lowLevelInterface.setLongAttribute(getTransactionId(), idEObject.getOid(), eFeature.getName(), (Long) newValue);
} else if (eFeature.getEType() == EcorePackage.eINSTANCE.getEDouble() || eFeature.getEType() == EcorePackage.eINSTANCE.getEDoubleObject()) {
lowLevelInterface.setDoubleAttribute(getTransactionId(), idEObject.getOid(), eFeature.getName(), (Double) newValue);
} else if (eFeature.getEType() == EcorePackage.eINSTANCE.getEBoolean() || eFeature.getEType() == EcorePackage.eINSTANCE.getEBooleanObject()) {
lowLevelInterface.setBooleanAttribute(getTransactionId(), idEObject.getOid(), eFeature.getName(), (Boolean) newValue);
} else if (eFeature.getEType() == EcorePackage.eINSTANCE.getEInt() || eFeature.getEType() == EcorePackage.eINSTANCE.getEIntegerObject()) {
lowLevelInterface.setIntegerAttribute(getTransactionId(), idEObject.getOid(), eFeature.getName(), (Integer) newValue);
} else if (eFeature.getEType() == EcorePackage.eINSTANCE.getEByteArray()) {
lowLevelInterface.setByteArrayAttribute(getTransactionId(), idEObject.getOid(), eFeature.getName(), (Byte[]) newValue);
} else if (eFeature.getEType() instanceof EEnum) {
lowLevelInterface.setEnumAttribute(getTransactionId(), idEObject.getOid(), eFeature.getName(), ((Enum<?>) newValue).toString());
} else if (eFeature instanceof EReference) {
if (newValue == null) {
lowLevelInterface.setReference(getTransactionId(), idEObject.getOid(), eFeature.getName(), -1L);
} else {
lowLevelInterface.setReference(getTransactionId(), idEObject.getOid(), eFeature.getName(), ((IdEObject) newValue).getOid());
}
} else {
throw new RuntimeException("Unimplemented " + eFeature.getEType().getName() + " " + newValue);
}
}
} else {
if (eFeature.getEType() == EcorePackage.eINSTANCE.getEString()) {
lowLevelInterface.setStringAttribute(getTransactionId(), idEObject.getOid(), eFeature.getName(), (String) newValue);
} else if (eFeature.getEType() == EcorePackage.eINSTANCE.getELong() || eFeature.getEType() == EcorePackage.eINSTANCE.getELongObject()) {
lowLevelInterface.setLongAttribute(getTransactionId(), idEObject.getOid(), eFeature.getName(), (Long) newValue);
} else if (eFeature.getEType() == EcorePackage.eINSTANCE.getEDouble() || eFeature.getEType() == EcorePackage.eINSTANCE.getEDoubleObject()) {
lowLevelInterface.setDoubleAttribute(getTransactionId(), idEObject.getOid(), eFeature.getName(), (Double) newValue);
} else if (eFeature.getEType() == EcorePackage.eINSTANCE.getEBoolean() || eFeature.getEType() == EcorePackage.eINSTANCE.getEBooleanObject()) {
lowLevelInterface.setBooleanAttribute(getTransactionId(), idEObject.getOid(), eFeature.getName(), (Boolean) newValue);
} else if (eFeature.getEType() == EcorePackage.eINSTANCE.getEInt() || eFeature.getEType() == EcorePackage.eINSTANCE.getEIntegerObject()) {
lowLevelInterface.setIntegerAttribute(getTransactionId(), idEObject.getOid(), eFeature.getName(), (Integer) newValue);
} else if (eFeature.getEType() == EcorePackage.eINSTANCE.getEByteArray()) {
if (newValue instanceof byte[]) {
Byte[] n = new Byte[((byte[]) newValue).length];
for (int i = 0; i < n.length; i++) {
n[i] = ((byte[]) newValue)[i];
}
newValue = n;
}
lowLevelInterface.setByteArrayAttribute(getTransactionId(), idEObject.getOid(), eFeature.getName(), (Byte[]) newValue);
} else if (eFeature.getEType() instanceof EEnum) {
lowLevelInterface.setEnumAttribute(getTransactionId(), idEObject.getOid(), eFeature.getName(), ((Enum<?>) newValue).toString());
} else if (eFeature instanceof EReference) {
if (newValue == null) {
lowLevelInterface.setReference(getTransactionId(), idEObject.getOid(), eFeature.getName(), -1L);
} else {
lowLevelInterface.setReference(getTransactionId(), idEObject.getOid(), eFeature.getName(), ((IdEObject) newValue).getOid());
}
} else {
throw new RuntimeException("Unimplemented " + eFeature.getEType().getName() + " " + newValue);
}
}
}
} catch (ServiceException e) {
LOGGER.error("", e);
} catch (PublicInterfaceNotFoundException e) {
LOGGER.error("", e);
}
}
}
}
use of org.bimserver.emf.IdEObject in project BIMserver by opensourceBIM.
the class LowLevelServiceImpl method getAttributeAtIndex.
private Object getAttributeAtIndex(Long tid, Long oid, String attributeName, int index) throws ServerException, UserException {
requireAuthenticationAndRunningServer();
DatabaseSession session = getBimServer().getDatabase().createSession();
try {
LongTransaction transaction = getBimServer().getLongTransactionManager().get(tid);
EClass eClass = session.getEClassForOid(oid);
IdEObject object = session.get(eClass, oid, new OldQuery(transaction.getPackageMetaData(), transaction.getPid(), transaction.getRid(), transaction.getRoid(), null, Deep.NO));
if (object == null) {
throw new UserException("No object of type " + eClass.getName() + " with oid " + oid + " found");
}
Object eGet = object.eGet(object.eClass().getEStructuralFeature(attributeName));
if (eGet instanceof List) {
List<?> list = (List<?>) eGet;
return list.get(index);
}
return eGet;
} catch (Exception e) {
return handleException(e);
} finally {
session.close();
}
}
use of org.bimserver.emf.IdEObject in project BIMserver by opensourceBIM.
the class LowLevelServiceImpl method getAttribute.
private Object getAttribute(Long tid, Long oid, String attributeName) throws ServerException, UserException {
requireAuthenticationAndRunningServer();
DatabaseSession session = getBimServer().getDatabase().createSession();
try {
LongTransaction transaction = getBimServer().getLongTransactionManager().get(tid);
EClass eClass = session.getEClassForOid(oid);
IdEObject object = session.get(eClass, oid, new OldQuery(transaction.getPackageMetaData(), transaction.getPid(), transaction.getRid(), transaction.getRoid(), null, Deep.NO));
if (object == null) {
throw new UserException("No object of type " + eClass.getName() + " with oid " + oid + " found");
}
Object eGet = object.eGet(object.eClass().getEStructuralFeature(attributeName));
if (eGet instanceof IdEObject) {
IdEObject refObject = (IdEObject) eGet;
return refObject.eGet(refObject.eClass().getEStructuralFeature("wrappedValue"));
}
return eGet;
} catch (Exception e) {
return handleException(e);
} finally {
session.close();
}
}
use of org.bimserver.emf.IdEObject in project BIMserver by opensourceBIM.
the class IfcUtils method getAllPaths.
public static int getAllPaths(Path basePath, IdEObject otherObject, Set<Path> paths, Set<EObject> noConnectionPaths) {
int connectionsFound = 0;
if (noConnectionPaths.contains(basePath.getLastObject())) {
return 0;
}
for (EReference eReference : basePath.getLastObject().eClass().getEAllReferences()) {
Object reference = basePath.getLastObject().eGet(eReference);
if (reference != null) {
if (eReference.isMany()) {
@SuppressWarnings("rawtypes") List list = (List) reference;
for (int index = 0; index < list.size(); index++) {
Object refObject = list.get(index);
IdEObject refIdEObject = (IdEObject) refObject;
if (basePath.contains(refIdEObject)) {
// do nothing
} else if (refIdEObject == otherObject) {
paths.add(new Path(basePath, eReference, index, refIdEObject));
System.out.println(paths.size());
} else {
connectionsFound += getAllPaths(new Path(basePath, eReference, index, (IdEObject) refObject), otherObject, paths, noConnectionPaths);
}
}
} else {
if (basePath.contains((IdEObject) reference)) {
// do nothing
} else if (reference == otherObject) {
paths.add(new Path(basePath, eReference, -1, (IdEObject) reference));
System.out.println(paths.size());
} else {
connectionsFound += getAllPaths(new Path(basePath, eReference, -1, (IdEObject) reference), otherObject, paths, noConnectionPaths);
}
}
}
}
if (connectionsFound == 0) {
noConnectionPaths.add(basePath.getLastObject());
}
return connectionsFound;
}
Aggregations