Search in sources :

Example 1 with ReferenceDataValue

use of org.bimserver.models.store.ReferenceDataValue in project BIMserver by opensourceBIM.

the class GetDataObjectByOidDatabaseAction method fillDataObject.

@SuppressWarnings({ "unchecked", "rawtypes" })
public static void fillDataObject(BiMap<? extends Long, ? extends EObject> mapResult, EObject eObject, DataObject dataObject) {
    for (EStructuralFeature eStructuralFeature : eObject.eClass().getEAllStructuralFeatures()) {
        Object eGet = eObject.eGet(eStructuralFeature);
        if (eStructuralFeature.getEAnnotation("hidden") == null) {
            if (eStructuralFeature instanceof EAttribute) {
                if (eStructuralFeature.isMany()) {
                    ListDataValue listDataValue = StoreFactory.eINSTANCE.createListDataValue();
                    listDataValue.setFieldName(eStructuralFeature.getName());
                    dataObject.getValues().add(listDataValue);
                    if (eStructuralFeature.getEType() == EcorePackage.eINSTANCE.getEDoubleObject() || eStructuralFeature.getEType() == EcorePackage.eINSTANCE.getEDouble()) {
                        EStructuralFeature asStringFeature = eObject.eClass().getEStructuralFeature(eStructuralFeature.getName() + "AsString");
                        List list = (List) eObject.eGet(asStringFeature);
                        for (Object o : list) {
                            SimpleDataValue dataValue = StoreFactory.eINSTANCE.createSimpleDataValue();
                            dataValue.setStringValue(o.toString());
                            listDataValue.getValues().add(dataValue);
                        }
                    } else {
                        if (eGet != null) {
                            List list = (List) eGet;
                            for (Object o : list) {
                                SimpleDataValue dataValue = StoreFactory.eINSTANCE.createSimpleDataValue();
                                if (eGet != null) {
                                    dataValue.setStringValue(o.toString());
                                } else {
                                    dataValue.setStringValue(null);
                                }
                                listDataValue.getValues().add(dataValue);
                            }
                        }
                    }
                } else {
                    SimpleDataValue dataValue = StoreFactory.eINSTANCE.createSimpleDataValue();
                    if (eObject.eIsSet(eStructuralFeature)) {
                        if (eGet instanceof byte[]) {
                            dataValue.setStringValue(new String(((byte[]) eGet), Charsets.UTF_8));
                        } else {
                            dataValue.setStringValue(eGet.toString());
                        }
                    } else {
                        dataValue.setStringValue(null);
                    }
                    dataValue.setFieldName(eStructuralFeature.getName());
                    dataObject.getValues().add(dataValue);
                }
            } else if (eStructuralFeature instanceof EReference) {
                if (eStructuralFeature.isMany()) {
                    if (eStructuralFeature.getEType() == EcorePackage.eINSTANCE.getEDouble() || eStructuralFeature.getEType() == EcorePackage.eINSTANCE.getEDoubleObject()) {
                        List list = (List) eObject.eGet(eObject.eClass().getEStructuralFeature(eStructuralFeature.getName() + "AsString"));
                        ListDataValue dataValue = StoreFactory.eINSTANCE.createListDataValue();
                        dataValue.setFieldName(eStructuralFeature.getName());
                        dataObject.getValues().add(dataValue);
                        for (Object o : list) {
                            SimpleDataValue simpleDataValue = StoreFactory.eINSTANCE.createSimpleDataValue();
                            simpleDataValue.setStringValue(o.toString());
                            dataValue.getValues().add(simpleDataValue);
                        }
                    } else {
                        EList<? extends EObject> list = (EList<EObject>) eGet;
                        ListDataValue dataValue = StoreFactory.eINSTANCE.createListDataValue();
                        dataObject.getValues().add(dataValue);
                        dataValue.setFieldName(eStructuralFeature.getName());
                        for (EObject item : list) {
                            if (item.eClass().getEAnnotation("wrapped") != null) {
                                EObject referenceEObject = item;
                                SimpleDataValue simpleDataValue = StoreFactory.eINSTANCE.createSimpleDataValue();
                                simpleDataValue.setStringValue(referenceEObject.eGet(referenceEObject.eClass().getEStructuralFeature("wrappedValue")).toString());
                                dataValue.getValues().add(simpleDataValue);
                            } else {
                                Long oid = ((IdEObject) item).getOid();
                                ReferenceDataValue referenceDataValue = StoreFactory.eINSTANCE.createReferenceDataValue();
                                if (item instanceof IfcRoot) {
                                    IfcRoot ifcRoot = (IfcRoot) item;
                                    String guid = ifcRoot.getGlobalId();
                                    referenceDataValue.setGuid(guid);
                                }
                                referenceDataValue.setTypeName(item.eClass().getName());
                                ((IdEObjectImpl) referenceDataValue).setOid(oid);
                                dataValue.getValues().add(referenceDataValue);
                            }
                        }
                    }
                } else {
                    EObject eObject2 = (EObject) eGet;
                    if (eObject2 != null) {
                        if (eObject2.eClass().getEAnnotation("wrapped") != null) {
                            EObject referenceEObject = (EObject) eGet;
                            SimpleDataValue e = StoreFactory.eINSTANCE.createSimpleDataValue();
                            EStructuralFeature wrappedValueFeature = referenceEObject.eClass().getEStructuralFeature("wrappedValue");
                            Object eGet2 = referenceEObject.eGet(wrappedValueFeature);
                            // } else {
                            if (eGet2 != null) {
                                e.setStringValue(eGet2.toString());
                            } else {
                                e.setStringValue(null);
                            }
                            // }
                            e.setFieldName(eStructuralFeature.getName());
                            dataObject.getValues().add(e);
                        } else {
                            Long oid = ((IdEObject) eObject2).getOid();
                            ReferenceDataValue reference = StoreFactory.eINSTANCE.createReferenceDataValue();
                            if (eObject2 instanceof IfcRoot) {
                                IfcRoot ifcRoot = (IfcRoot) eObject2;
                                String guid = ifcRoot.getGlobalId();
                                reference.setGuid(guid);
                            }
                            reference.setTypeName(eObject2.eClass().getName());
                            ((IdEObjectImpl) reference).setOid(oid);
                            reference.setFieldName(eStructuralFeature.getName());
                            dataObject.getValues().add(reference);
                        }
                    }
                }
            }
        }
    }
}
Also used : ListDataValue(org.bimserver.models.store.ListDataValue) SimpleDataValue(org.bimserver.models.store.SimpleDataValue) IfcRoot(org.bimserver.models.ifc2x3tc1.IfcRoot) EStructuralFeature(org.eclipse.emf.ecore.EStructuralFeature) EAttribute(org.eclipse.emf.ecore.EAttribute) EList(org.eclipse.emf.common.util.EList) IdEObject(org.bimserver.emf.IdEObject) EObject(org.eclipse.emf.ecore.EObject) ReferenceDataValue(org.bimserver.models.store.ReferenceDataValue) IdEObject(org.bimserver.emf.IdEObject) EObject(org.eclipse.emf.ecore.EObject) DataObject(org.bimserver.models.store.DataObject) EList(org.eclipse.emf.common.util.EList) List(java.util.List) EReference(org.eclipse.emf.ecore.EReference)

Aggregations

List (java.util.List)1 IdEObject (org.bimserver.emf.IdEObject)1 IfcRoot (org.bimserver.models.ifc2x3tc1.IfcRoot)1 DataObject (org.bimserver.models.store.DataObject)1 ListDataValue (org.bimserver.models.store.ListDataValue)1 ReferenceDataValue (org.bimserver.models.store.ReferenceDataValue)1 SimpleDataValue (org.bimserver.models.store.SimpleDataValue)1 EList (org.eclipse.emf.common.util.EList)1 EAttribute (org.eclipse.emf.ecore.EAttribute)1 EObject (org.eclipse.emf.ecore.EObject)1 EReference (org.eclipse.emf.ecore.EReference)1 EStructuralFeature (org.eclipse.emf.ecore.EStructuralFeature)1