use of org.bimserver.emf.IdEObjectImpl in project BIMserver by opensourceBIM.
the class AbstractSchemaConverter method copy.
@SuppressWarnings("unchecked")
protected IdEObject copy(IdEObject original) throws IfcModelInterfaceException, ObjectAlreadyExistsException {
if (!((IdEObjectImpl) original).isLoadedOrLoading()) {
return null;
}
if (converted.containsKey(original)) {
return converted.get(original);
}
if (original.eClass().getName().equals("GeometryInfo") || original.eClass().getName().equals("GeometryData") || original.eClass().getName().equals("Vector3f")) {
return null;
}
EClass eClass = (EClass) target.getPackageMetaData().getEPackage().getEClassifier(original.eClass().getName());
if (eClass == null) {
LOGGER.info("No class " + original.eClass().getName() + " in " + target.getPackageMetaData().getEPackage().getName());
return null;
}
IdEObject newObject = (IdEObject) eClass.getEPackage().getEFactoryInstance().create(eClass);
((IdEObjectImpl) newObject).setOid(original.getOid());
converted.put(original, newObject);
if (newObject.eClass().getEAnnotation("wrapped") == null) {
target.add(newObject.getOid(), newObject);
}
for (EStructuralFeature eStructuralFeature : original.eClass().getEAllStructuralFeatures()) {
EStructuralFeature targetFeature = newObject.eClass().getEStructuralFeature(eStructuralFeature.getName());
if (targetFeature == null) {
continue;
}
Object get = original.eGet(eStructuralFeature);
if (eStructuralFeature instanceof EAttribute) {
if (get instanceof Double) {
EStructuralFeature doubleStringFeature = original.eClass().getEStructuralFeature("wrappedValueAsString");
EStructuralFeature targetDoubleStringFeature = newObject.eClass().getEStructuralFeature("wrappedValueAsString");
if (doubleStringFeature != null && targetDoubleStringFeature != null) {
Object doubleString = original.eGet(doubleStringFeature);
newObject.eSet(targetDoubleStringFeature, doubleString);
} else {
newObject.eSet(targetFeature, get);
}
} else {
if (eStructuralFeature.getEType() instanceof EEnum) {
EEnum targetEnum = (EEnum) targetFeature.getEType();
EEnumLiteral newLiteral = targetEnum.getEEnumLiteral(get.toString());
if (newLiteral != null) {
newObject.eSet(targetFeature, newLiteral.getInstance());
}
} else {
if (targetFeature instanceof EAttribute) {
newObject.eSet(targetFeature, get);
}
}
}
} else if (eStructuralFeature instanceof EReference) {
if (get == null) {
} else {
if (eStructuralFeature.isMany()) {
EList<EObject> list = (EList<EObject>) get;
AbstractEList<EObject> toList = (AbstractEList<EObject>) newObject.eGet(targetFeature);
if (toList != null) {
for (Object o : list) {
IdEObject ref = (IdEObject) o;
if (targetFeature.getEType().isInstance(ref)) {
if (converted.containsKey(o)) {
toList.addUnique(converted.get(o));
} else {
IdEObject result = copy((IdEObject) o);
if (result != null) {
toList.addUnique(result);
}
}
}
}
}
} else {
if (targetFeature.isMany()) {
LOGGER.info("Different multiplicity");
} else {
if (converted.containsKey(get)) {
newObject.eSet(targetFeature, converted.get(get));
} else {
newObject.eSet(targetFeature, copy((IdEObject) get));
}
}
}
}
}
}
return newObject;
}
use of org.bimserver.emf.IdEObjectImpl in project BIMserver by opensourceBIM.
the class ClientIfcModel method loadExplicit.
public void loadExplicit(long oid) {
try {
IdEObjectImpl idEObjectImpl = (IdEObjectImpl) super.get(oid);
if (idEObjectImpl != null && !idEObjectImpl.isLoadedOrLoading()) {
idEObjectImpl.setLoadingState(State.LOADING);
modelState = ModelState.LOADING;
Query query = new Query(getPackageMetaData());
QueryPart queryPart = query.createQueryPart();
queryPart.addOid(oid);
JsonQueryObjectModelConverter converter = new JsonQueryObjectModelConverter(getPackageMetaData());
long topicId = bimServerClient.getServiceInterface().download(Collections.singleton(roid), converter.toJson(query).toString(), getJsonSerializerOid(), false);
waitForDonePreparing(topicId);
processDownload(topicId);
bimServerClient.getServiceInterface().cleanupLongAction(topicId);
idEObjectImpl.setLoadingState(State.LOADED);
modelState = ModelState.NONE;
}
} catch (Exception e) {
LOGGER.error("", e);
}
}
use of org.bimserver.emf.IdEObjectImpl in project BIMserver by opensourceBIM.
the class DatabaseSession method createInternal.
private IdEObjectImpl createInternal(EClass eClass, QueryInterface queryInterface) {
IdEObjectImpl object = (IdEObjectImpl) eClass.getEPackage().getEFactoryInstance().create(eClass);
object.setQueryInterface(queryInterface);
return object;
}
use of org.bimserver.emf.IdEObjectImpl in project BIMserver by opensourceBIM.
the class DatabaseSession method readWrappedValue.
private IdEObject readWrappedValue(EStructuralFeature feature, ByteBuffer buffer, EClass eClass, QueryInterface query) {
EStructuralFeature eStructuralFeature = eClass.getEStructuralFeature("wrappedValue");
Object primitiveValue = readPrimitiveValue(eStructuralFeature.getEType(), buffer, query);
IdEObject eObject = createInternal(eClass, query);
// We don't want to go lazy load
((IdEObjectImpl) eObject).setLoaded();
// this
eObject.eSet(eStructuralFeature, primitiveValue);
if (eStructuralFeature.getEType() == EcorePackage.eINSTANCE.getEDouble() || eStructuralFeature.getEType() == EcorePackage.eINSTANCE.getEDoubleObject()) {
EStructuralFeature strFeature = eClass.getEStructuralFeature("wrappedValueAsString");
Object stringVal = readPrimitiveValue(EcorePackage.eINSTANCE.getEString(), buffer, query);
eObject.eSet(strFeature, stringVal);
}
return eObject;
}
use of org.bimserver.emf.IdEObjectImpl in project BIMserver by opensourceBIM.
the class DownloadByNewJsonQueryDatabaseAction method convertWrapped.
private IdEObject convertWrapped(Revision revision, IfcModelInterface ifcModel, HashMapWrappedVirtualObject hashMapWrappedVirtualObject) throws IfcModelInterfaceException {
IdEObject embeddedObject = ifcModel.create(hashMapWrappedVirtualObject.eClass());
((IdEObjectImpl) embeddedObject).setOid(-1);
((IdEObjectImpl) embeddedObject).setPid(revision.getProject().getId());
for (EAttribute eAttribute : hashMapWrappedVirtualObject.eClass().getEAllAttributes()) {
embeddedObject.eSet(eAttribute, hashMapWrappedVirtualObject.eGet(eAttribute));
}
return embeddedObject;
}
Aggregations