Search in sources :

Example 56 with IdEObject

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");
    }
}
Also used : IdEObject(org.bimserver.emf.IdEObject) EDataType(org.eclipse.emf.ecore.EDataType) EObject(org.eclipse.emf.ecore.EObject) IdEObject(org.bimserver.emf.IdEObject) EStructuralFeature(org.eclipse.emf.ecore.EStructuralFeature) List(java.util.List) BasicEList(org.eclipse.emf.common.util.BasicEList) ArrayList(java.util.ArrayList) EList(org.eclipse.emf.common.util.EList) AbstractEList(org.eclipse.emf.common.util.AbstractEList) VirtualObject(org.bimserver.shared.VirtualObject) HashMapVirtualObject(org.bimserver.shared.HashMapVirtualObject) EObject(org.eclipse.emf.ecore.EObject) IdEObject(org.bimserver.emf.IdEObject) EReference(org.eclipse.emf.ecore.EReference)

Example 57 with IdEObject

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);
            }
        }
    }
}
Also used : IdEObjectImpl(org.bimserver.emf.IdEObjectImpl) IdEObject(org.bimserver.emf.IdEObject) EEnum(org.eclipse.emf.ecore.EEnum) EClass(org.eclipse.emf.ecore.EClass) ServiceException(org.bimserver.shared.exceptions.ServiceException) PublicInterfaceNotFoundException(org.bimserver.shared.exceptions.PublicInterfaceNotFoundException) LowLevelInterface(org.bimserver.shared.interfaces.LowLevelInterface) EReference(org.eclipse.emf.ecore.EReference)

Example 58 with IdEObject

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();
    }
}
Also used : EClass(org.eclipse.emf.ecore.EClass) DatabaseSession(org.bimserver.database.DatabaseSession) IdEObject(org.bimserver.emf.IdEObject) IdEObject(org.bimserver.emf.IdEObject) SDataObject(org.bimserver.interfaces.objects.SDataObject) DataObject(org.bimserver.models.store.DataObject) ArrayList(java.util.ArrayList) List(java.util.List) UserException(org.bimserver.shared.exceptions.UserException) LongTransaction(org.bimserver.webservices.LongTransaction) UserException(org.bimserver.shared.exceptions.UserException) NoTransactionException(org.bimserver.webservices.NoTransactionException) ServerException(org.bimserver.shared.exceptions.ServerException) BimserverDatabaseException(org.bimserver.BimserverDatabaseException) OldQuery(org.bimserver.database.OldQuery)

Example 59 with IdEObject

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();
    }
}
Also used : EClass(org.eclipse.emf.ecore.EClass) DatabaseSession(org.bimserver.database.DatabaseSession) IdEObject(org.bimserver.emf.IdEObject) IdEObject(org.bimserver.emf.IdEObject) SDataObject(org.bimserver.interfaces.objects.SDataObject) DataObject(org.bimserver.models.store.DataObject) UserException(org.bimserver.shared.exceptions.UserException) LongTransaction(org.bimserver.webservices.LongTransaction) UserException(org.bimserver.shared.exceptions.UserException) NoTransactionException(org.bimserver.webservices.NoTransactionException) ServerException(org.bimserver.shared.exceptions.ServerException) BimserverDatabaseException(org.bimserver.BimserverDatabaseException) OldQuery(org.bimserver.database.OldQuery)

Example 60 with IdEObject

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;
}
Also used : IdEObject(org.bimserver.emf.IdEObject) EObject(org.eclipse.emf.ecore.EObject) IdEObject(org.bimserver.emf.IdEObject) IfcObject(org.bimserver.models.ifc2x3tc1.IfcObject) List(java.util.List) ArrayList(java.util.ArrayList) EList(org.eclipse.emf.common.util.EList) IfcCartesianPoint(org.bimserver.models.ifc2x3tc1.IfcCartesianPoint) EReference(org.eclipse.emf.ecore.EReference)

Aggregations

IdEObject (org.bimserver.emf.IdEObject)68 List (java.util.List)25 EStructuralFeature (org.eclipse.emf.ecore.EStructuralFeature)25 EClass (org.eclipse.emf.ecore.EClass)20 EReference (org.eclipse.emf.ecore.EReference)18 IdEObjectImpl (org.bimserver.emf.IdEObjectImpl)15 UserException (org.bimserver.shared.exceptions.UserException)15 BimserverDatabaseException (org.bimserver.BimserverDatabaseException)14 EList (org.eclipse.emf.common.util.EList)14 EObject (org.eclipse.emf.ecore.EObject)14 ArrayList (java.util.ArrayList)12 AbstractEList (org.eclipse.emf.common.util.AbstractEList)12 HashSet (java.util.HashSet)10 IfcModelInterface (org.bimserver.emf.IfcModelInterface)10 HashMapVirtualObject (org.bimserver.shared.HashMapVirtualObject)10 OldQuery (org.bimserver.database.OldQuery)9 IfcModelInterfaceException (org.bimserver.emf.IfcModelInterfaceException)9 VirtualObject (org.bimserver.shared.VirtualObject)9 EAttribute (org.eclipse.emf.ecore.EAttribute)9 Project (org.bimserver.models.store.Project)8