Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
package org.bimserver.emf;
/******************************************************************************
* Copyright (C) 2009-2017 BIMserver.org
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see {@literal}.
*****************************************************************************/
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.bimserver.emf.IdEObjectImpl.State;
import org.bimserver.models.ifc2x3tc1.Ifc2x3tc1Factory;
import org.bimserver.models.ifc2x3tc1.IfcGloballyUniqueId;
import org.bimserver.models.store.IfcHeader;
import org.bimserver.models.store.StoreFactory;
import org.bimserver.models.store.StorePackage;
import org.bimserver.plugins.deserializers.DeserializeException;
import org.bimserver.shared.ListWaitingObject;
import org.bimserver.shared.SingleWaitingObject;
import org.bimserver.shared.WaitingList;
import org.bimserver.shared.exceptions.BimServerClientException;
import org.eclipse.emf.common.util.AbstractEList;
import org.eclipse.emf.ecore.EAttribute;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EClassifier;
import org.eclipse.emf.ecore.EEnum;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EReference;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.ecore.EcorePackage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.common.base.Charsets;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonToken;
import nl.tue.buildingsmart.schema.Attribute;
import nl.tue.buildingsmart.schema.EntityDefinition;
import nl.tue.buildingsmart.schema.InverseAttribute;
public class SharedJsonDeserializer {
private static final Logger LOGGER = LoggerFactory.getLogger(SharedJsonDeserializer.class);
private boolean skipInverses;
public SharedJsonDeserializer(boolean skipInverses) {
this.skipInverses = skipInverses;
}
@SuppressWarnings("rawtypes")
public IfcModelInterface read(InputStream in, IfcModelInterface model, boolean checkWaitingList) throws DeserializeException {
if (model.getPackageMetaData().getSchemaDefinition() == null) {
throw new DeserializeException("No SchemaDefinition available");
}
WaitingList waitingList = new WaitingList();
final boolean log = false;
if (log) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try {
IOUtils.copy(in, baos);
File file = new File("debug.json");
System.out.println(file.getAbsolutePath());
FileUtils.writeByteArrayToFile(file, baos.toByteArray());
} catch (IOException e) {
e.printStackTrace();
}
in = new ByteArrayInputStream(baos.toByteArray());
}
JsonReader jsonReader = new JsonReader(new InputStreamReader(in, Charsets.UTF_8));
int nrObjects = 0;
try {
JsonToken peek = jsonReader.peek();
if (peek != null && peek == JsonToken.BEGIN_OBJECT) {
jsonReader.beginObject();
peek = jsonReader.peek();
while (peek == JsonToken.NAME) {
String nextName = jsonReader.nextName();
if (nextName.equals("objects")) {
jsonReader.beginArray();
while (jsonReader.hasNext()) {
nrObjects++;
processObject(model, waitingList, jsonReader, null);
}
jsonReader.endArray();
} else if (nextName.equals("header")) {
IfcHeader ifcHeader = (IfcHeader) processObject(model, waitingList, jsonReader, StorePackage.eINSTANCE.getIfcHeader());
model.getModelMetaData().setIfcHeader(ifcHeader);
}
peek = jsonReader.peek();
}
jsonReader.endObject();
}
} catch (IOException e) {
LOGGER.error("", e);
} catch (IfcModelInterfaceException e) {
LOGGER.error("", e);
} finally {
LOGGER.info("# Objects: " + nrObjects);
try {
jsonReader.close();
} catch (IOException e) {
LOGGER.error("", e);
}
}
boolean checkUnique = false;
if (checkUnique) {
for (IdEObject idEObject : model.getValues()) {
for (EStructuralFeature eStructuralFeature : idEObject.eClass().getEAllStructuralFeatures()) {
Object value = idEObject.eGet(eStructuralFeature);
if (eStructuralFeature instanceof EReference) {
if (eStructuralFeature.isMany()) {
List list = (List)value;
if (eStructuralFeature.isUnique()) {
Set