@SuppressWarnings({ "rawtypes", "unchecked" }) public void apply(IdEObject value) { if (eStructuralFeature.isMany()) { List list = (List)newObject.eGet(eStructuralFeature); list.add(value); } else { newObject.eSet(eStructuralFeature, value); } } }
private int comparePrimitives(IdEObject o1, IdEObject o2) { EClass eClass = o1.eClass(); EStructuralFeature eStructuralFeature = eClass.getEStructuralFeature("wrappedValue"); Object val1 = o1.eGet(eStructuralFeature); Object val2 = o2.eGet(eStructuralFeature); if (eStructuralFeature.getEType() == EcorePackage.eINSTANCE.getEString()) { return ((String) val1).compareTo((String) val2); } else if (eStructuralFeature.getEType() == EcorePackage.eINSTANCE.getEInt()) { return ((Integer) val1).compareTo((Integer) val2); } else { throw new RuntimeException("ni"); } }
@Override public boolean matches(IdEObject object) { if (!attribute.getEContainingClass().isSuperTypeOf(object.eClass())) { return false; } else { if (object.eGet(attribute) == null && literal.getValue() == null) { return true; } if (object.eGet(attribute) == null && literal.getValue() != null) { return false; } if (object.eGet(attribute) != null && literal.getValue() == null) { return false; } return object.eGet(attribute).equals(literal.getValue()); } } }
@Override public boolean matches(IdEObject object) { if (object.eClass().isSuperTypeOf(reference.getEContainingClass())) { Object other = object.eGet(reference); if (other instanceof EList<?>) { EList<?> list = (EList<?>)other; for (Object eObject : list) { if (referencingObjects.contains(eObject)) { return true; } } return false; } else { return referencingObjects.contains(other); } } return false; } }
private int fixMisMatchInstance(Mismatch mismatch, IdEObject entityToBeFixed, IdEObject referenced) { int nrFixes = 0; for(EReference inverse: mismatch.inverse) if(inverse.getEContainingClass().isInstance(referenced)){ if(inverse.isMany()) ((EList<IdEObject>) referenced.eGet(inverse)).add(entityToBeFixed); else referenced.eSet(inverse, entityToBeFixed); nrFixes++; } return nrFixes; }
private void storeDeep(IdEObject object, Set<IdEObject> done) throws BimserverDatabaseException { if (object == null || done.contains(object)) { return; } done.add(object); store(object); for (EReference eReference : object.eClass().getEAllReferences()) { if (eReference.isMany()) { List<?> list = (List<?>) object.eGet(eReference); for (Object v : list) { storeDeep((IdEObject) v, done); } } else { IdEObject reference = (IdEObject) object.eGet(eReference); storeDeep(reference, done); } } }
@SuppressWarnings({ "rawtypes", "unchecked" }) private void setDoubleAsStringValues(IdEObject idEObject) { for (EAttribute eAttribute : idEObject.eClass().getEAllAttributes()) { if (eAttribute.getEType() == EcorePackage.eINSTANCE.getEDouble()) { EStructuralFeature asStringFeature = idEObject.eClass().getEStructuralFeature(eAttribute.getName() + "AsString"); if (asStringFeature != null) { if (eAttribute.isMany()) { List list = (List) idEObject.eGet(eAttribute); List listAsString = (List) idEObject.eGet(asStringFeature); for (int i = 0; i < list.size(); i++) { listAsString.set(i, "" + list.get(i)); } } else { idEObject.eSet(asStringFeature, "" + idEObject.eGet(eAttribute)); } } } } }
private void indexGuid(IdEObject idEObject) { EClass ifcRootEclass = packageMetaData.getEClass("IfcRoot"); EStructuralFeature guidFeature = ifcRootEclass.getEStructuralFeature("GlobalId"); if (ifcRootEclass.isSuperTypeOf(idEObject.eClass())) { Object guid = idEObject.eGet(guidFeature); if (guid != null) { guidIndexed.put((String)guid, idEObject); } } }
@SuppressWarnings("unchecked") public <T> T create(EClass eClass, int pid, int rid) throws BimserverDatabaseException { checkOpen(); IdEObject idEObject = createInternal(eClass, null); EStructuralFeature uuidFeature = eClass.getEStructuralFeature("uuid"); if (uuidFeature != null) { if (idEObject.eGet(uuidFeature) == null) { idEObject.eSet(uuidFeature, UUID.randomUUID().toString()); } } store(idEObject, pid, rid); return (T) idEObject; }
@SuppressWarnings("unchecked") private void createPresentationStyleAssignmentStyles(IfcModelInterface model, String representationIdentifier, IdEObject ifcPresentationStyleAssignment, IdEObject color) throws IfcModelInterfaceException { if (representationIdentifier.equals("Body")) { IdEObject ifcPresentationStyleSelect = model.create(model.getPackageMetaData().getEClass("IfcSurfaceStyle")); EStructuralFeature stylesFeature = ifcPresentationStyleAssignment.eClass().getEStructuralFeature("Styles"); List<IdEObject> list = (List<IdEObject>) ifcPresentationStyleAssignment.eGet(stylesFeature); list.add(ifcPresentationStyleSelect); createSurfaceStyleStyles(model, representationIdentifier, ifcPresentationStyleSelect, color); } else { // Unimplemented } }
@SuppressWarnings("unchecked") private void createStyledByItems(IfcModelInterface model, IdEObject ifcRepresentationItem, String representationIdentifier, IdEObject color) throws IfcModelInterfaceException { IdEObject ifcStyledItem = model.create(model.getPackageMetaData().getEClass("IfcStyledItem")); EStructuralFeature styledByItemFeature = ifcStyledItem.eClass().getEStructuralFeature("StyledByItem"); List<IdEObject> list = (List<IdEObject>) ifcRepresentationItem.eGet(styledByItemFeature); list.add(ifcStyledItem); createStyledItemStyles(model, representationIdentifier, ifcStyledItem, color); }
@SuppressWarnings("unchecked") private void createStyledItemStyles(IfcModelInterface model, String representationIdentifier, IdEObject ifcStyledItem, IdEObject color) throws IfcModelInterfaceException { IdEObject ifcPresentationStyleAssignment = model.create(model.getPackageMetaData().getEClass("IfcPresentationStyleAssignment")); EStructuralFeature stylesFeature = ifcStyledItem.eClass().getEStructuralFeature("Styles"); List<IdEObject> list = (List<IdEObject>) ifcStyledItem.eGet(stylesFeature); list.add(ifcPresentationStyleAssignment); createPresentationStyleAssignmentStyles(model, representationIdentifier, ifcPresentationStyleAssignment, color); }
private boolean useUnsetBit(EStructuralFeature feature, IdEObject object) { // TODO non-unsettable boolean values can also be stored in these bits Object value = object.eGet(feature); if (feature.isUnsettable()) { if (!object.eIsSet(feature)) { return true; } if (feature.isMany() && ((List<?>)value).isEmpty()) { return true; } } else { if (feature.isMany() && ((List<?>)value).isEmpty()) { return true; } if (feature.getDefaultValue() == value || (feature.getDefaultValue() != null && feature.getDefaultValue().equals(value))) { return true; } } return false; }
@SuppressWarnings("unchecked") private void createSurfaceStyleStyles(IfcModelInterface model, String representationIdentifier, IdEObject ifcSurfaceStyle, IdEObject color) throws IfcModelInterfaceException { EClass ifcSurfaceStyleRenderingClass = model.getPackageMetaData().getEClass("IfcSurfaceStyleRendering"); IdEObject ifcSurfaceStyleRendering = model.create(ifcSurfaceStyleRenderingClass); EStructuralFeature stylesFeature = ifcSurfaceStyle.eClass().getEStructuralFeature("Styles"); ((List<IdEObject>)(ifcSurfaceStyle.eGet(stylesFeature))).add(ifcSurfaceStyleRendering); setColour(color, ifcSurfaceStyleRendering); }
private void writeEmbeddedValue(int pid, int rid, Object value, ByteBuffer buffer, PackageMetaData packageMetaData) throws BimserverDatabaseException { IdEObject wrappedValue = (IdEObject) value; Short cid = database.getCidOfEClass(wrappedValue.eClass()); buffer.order(ByteOrder.LITTLE_ENDIAN); buffer.putShort((short) -cid); buffer.order(ByteOrder.BIG_ENDIAN); for (EStructuralFeature eStructuralFeature : wrappedValue.eClass().getEAllStructuralFeatures()) { if (eStructuralFeature.isMany()) { writeList(wrappedValue, buffer, packageMetaData, eStructuralFeature); } else { Object val = wrappedValue.eGet(eStructuralFeature); if (eStructuralFeature.getEType() instanceof EClass) { writeEmbeddedValue(pid, rid, val, buffer, packageMetaData); } else { writePrimitiveValue(eStructuralFeature, val, buffer); } } } }
private void writeEmbedded(IdEObject object) throws IOException { print("{"); print("\"_t\":\"" + object.eClass().getName() + "\","); for (EStructuralFeature eStructuralFeature : object.eClass().getEAllStructuralFeatures()) { print("\"" + eStructuralFeature.getName() + "\":"); writePrimitive(eStructuralFeature, object.eGet(eStructuralFeature)); if (object.eClass().getEAllStructuralFeatures().get(object.eClass().getEAllStructuralFeatures().size()-1) != eStructuralFeature) { print(","); } } print("}"); }
@Override public boolean matches(IdEObject object) { if (object.eClass().isSuperTypeOf(reference.getEContainingClass())) { Object other = object.eGet(reference); if (other instanceof EList<?>) { EList<?> list = (EList<?>)other; for (Object eObject : list) { // TODO Actually the first test should suffice (object id), the second should always return the same because caching of the objects should allow only 1 per database session if (eObject == referencingObject || ((IdEObject)eObject).getOid() == referencingObject.getOid()) { return true; } } return false; } else { return other == referencingObject; } } return false; } }
private void write(IdEObject object) throws IOException { if (object.eClass().getEAnnotation("wrapped") != null) { EStructuralFeature wrappedFeature = object.eClass().getEStructuralFeature("wrappedValue"); print("{"); print("\"_t\":\"" + object.eClass().getName() + "\","); print("\"_v\":"); writePrimitive(wrappedFeature, object.eGet(wrappedFeature)); print("}"); } else { print("" + object.getOid()); } }
@SuppressWarnings("unchecked") public void sortAllAggregates(ObjectIDM objectIDM, IdEObject ifcRoot) { for (EStructuralFeature eStructuralFeature : ifcRoot.eClass().getEAllStructuralFeatures()) { if (objectIDM.shouldFollowReference(ifcRoot.eClass(), ifcRoot.eClass(), eStructuralFeature)) { if (eStructuralFeature.getUpperBound() == -1 || eStructuralFeature.getUpperBound() > 1) { if (eStructuralFeature.getEType() instanceof EClass) { if (eStructuralFeature.getEType().getEAnnotation("wrapped") != null) { EList<IdEObject> list = (EList<IdEObject>) ifcRoot.eGet(eStructuralFeature); sortPrimitiveList(list); } else { EList<IdEObject> list = (EList<IdEObject>) ifcRoot.eGet(eStructuralFeature); sortComplexList(objectIDM, ifcRoot.eClass(), list, eStructuralFeature); } } } } } }
@Override public SGeometryInfo execute() throws UserException, BimserverDatabaseException, BimserverLockConflictException { Revision revision = getDatabaseSession().get(roid, OldQuery.getDefault()); Project project = revision.getProject(); PackageMetaData packageMetaData = bimServer.getMetaDataManager().getPackageMetaData(project.getSchema()); IdEObject ifcProduct = getDatabaseSession().get(oid, new OldQuery(packageMetaData, project.getId(), revision.getId(), revision.getOid())); if (ifcProduct == null) { throw new UserException("Object with oid " + oid + " not found"); } EStructuralFeature geometryFeature = packageMetaData.getEClass("IfcProduct").getEStructuralFeature("geometry"); GeometryInfo geometry = (GeometryInfo) ifcProduct.eGet(geometryFeature); SGeometryInfo convertToSObject = bimServer.getSConverter().convertToSObject(geometry); return convertToSObject; } }