All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.bimserver.serializers.objectinfo.ObjectInfoSerializer Maven / Gradle / Ivy

There is a newer version: 1.5.9
Show newest version
package org.bimserver.serializers.objectinfo;

/******************************************************************************
 * Copyright (C) 2009-2016  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.OutputStream;
import java.io.PrintWriter;
import java.util.List;

import org.bimserver.plugins.serializers.EmfSerializer;
import org.bimserver.plugins.serializers.ProgressReporter;
import org.bimserver.plugins.serializers.SerializerException;
import org.eclipse.emf.ecore.EAttribute;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EReference;
import org.eclipse.emf.ecore.EStructuralFeature;

public class ObjectInfoSerializer extends EmfSerializer {

	@Override
	public void reset() {
		setMode(Mode.BODY);
	}
	
	@Override
	public boolean write(OutputStream outputStream, ProgressReporter progressReporter) throws SerializerException {
		if (getMode() == Mode.BODY) {
			PrintWriter out = new PrintWriter(outputStream);
			for (EObject eObject : model.getObjects().values()) {
				if (eObject.eClass().getEAnnotation("hidden") == null) {
					writeTable(out, eObject);
				}
			}
			out.flush();
			setMode(Mode.FINISHED);
			return true;
		} else if (getMode() == Mode.FINISHED) {
			return false;
		}
		return false;
	}

	@SuppressWarnings("unchecked")
	private void writeTable(PrintWriter out, EObject eObject) {
		out.println("

" + eObject.eClass().getName() + "

"); out.println(""); for (EStructuralFeature eStructuralFeature : eObject.eClass().getEAllStructuralFeatures()) { if (eStructuralFeature.getEAnnotation("hidden") == null) { out.println(""); out.println(""); Object eGet = eObject.eGet(eStructuralFeature); if (eStructuralFeature instanceof EAttribute) { if (eStructuralFeature.getUpperBound() == 1) { out.println(""); } else { List list = (List) eGet; out.println(""); } } else if (eStructuralFeature instanceof EReference) { if (eStructuralFeature.getUpperBound() == 1) { if (eStructuralFeature.getEType().getEAnnotation("wrapped") != null) { EObject value = (EObject) eGet; if (value != null) { out.println(""); } } else { } } else { if (eStructuralFeature.getEType().getEAnnotation("wrapped") != null) { List list = (List) eGet; out.println(""); } out.println(""); } else { } } } } out.println(""); } out.println("
" + eStructuralFeature.getName() + "" + eGet + ""); for (Object object : list) { out.println(object + " "); } out.println("" + value.eGet(value.eClass().getEStructuralFeature("wrappedValue")) + ""); for (EObject object : list) { out.println("" + object.eGet(object.eClass().getEStructuralFeature("wrappedValue")) + "
"); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy