/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package org.ai4fm.proofprocess.zeves.impl;

import net.sourceforge.czt.base.ast.Term;
import org.ai4fm.proofprocess.zeves.*;
import org.ai4fm.proofprocess.zeves.parse.ZmlTermParser;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EDataType;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EPackage;

import org.eclipse.emf.ecore.impl.EFactoryImpl;

import org.eclipse.emf.ecore.plugin.EcorePlugin;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model <b>Factory</b>.
 * <!-- end-user-doc -->
 * @generated
 */
public class ZEvesProofProcessFactoryImpl extends EFactoryImpl implements ZEvesProofProcessFactory {
	/**
	 * Creates the default factory implementation.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public static ZEvesProofProcessFactory init() {
		try {
			ZEvesProofProcessFactory theZEvesProofProcessFactory = (ZEvesProofProcessFactory)EPackage.Registry.INSTANCE.getEFactory("http://org/ai4fm/proofprocess/zeves/v1.0.0"); 
			if (theZEvesProofProcessFactory != null) {
				return theZEvesProofProcessFactory;
			}
		}
		catch (Exception exception) {
			EcorePlugin.INSTANCE.log(exception);
		}
		return new ZEvesProofProcessFactoryImpl();
	}

	/**
	 * Creates an instance of the factory.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public ZEvesProofProcessFactoryImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public EObject create(EClass eClass) {
		switch (eClass.getClassifierID()) {
			case ZEvesProofProcessPackage.UNPARSED_TERM: return (EObject)createUnparsedTerm();
			case ZEvesProofProcessPackage.CZT_TERM: return (EObject)createCztTerm();
			case ZEvesProofProcessPackage.ZEVES_TRACE: return (EObject)createZEvesTrace();
			default:
				throw new IllegalArgumentException("The class '" + eClass.getName() + "' is not a valid classifier");
		}
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object createFromString(EDataType eDataType, String initialValue) {
		switch (eDataType.getClassifierID()) {
			case ZEvesProofProcessPackage.ZML_TERM:
				return createZmlTermFromString(eDataType, initialValue);
			default:
				throw new IllegalArgumentException("The datatype '" + eDataType.getName() + "' is not a valid classifier");
		}
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public String convertToString(EDataType eDataType, Object instanceValue) {
		switch (eDataType.getClassifierID()) {
			case ZEvesProofProcessPackage.ZML_TERM:
				return convertZmlTermToString(eDataType, instanceValue);
			default:
				throw new IllegalArgumentException("The datatype '" + eDataType.getName() + "' is not a valid classifier");
		}
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public UnparsedTerm createUnparsedTerm() {
		UnparsedTermImpl unparsedTerm = new UnparsedTermImpl();
		return unparsedTerm;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public CztTerm createCztTerm() {
		CztTermImpl cztTerm = new CztTermImpl();
		return cztTerm;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public ZEvesTrace createZEvesTrace() {
		ZEvesTraceImpl zEvesTrace = new ZEvesTraceImpl();
		return zEvesTrace;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated NOT
	 */
	public Term createZmlTermFromString(EDataType eDataType, String initialValue) {
		return ZmlTermParser.parseZml(initialValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated NOT
	 */
	public String convertZmlTermToString(EDataType eDataType, Object instanceValue) {
		return ZmlTermParser.convertToZml((Term) instanceValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public ZEvesProofProcessPackage getZEvesProofProcessPackage() {
		return (ZEvesProofProcessPackage)getEPackage();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @deprecated
	 * @generated
	 */
	@Deprecated
	public static ZEvesProofProcessPackage getPackage() {
		return ZEvesProofProcessPackage.eINSTANCE;
	}

} //ZEvesProofProcessFactoryImpl

@@ -128,16 +128,72 @@
 st.Term;
+%0A%0Aimport org.ai4fm.proofprocess.parse.StringCompression;
 %0Aimport 
@@ -3720,50 +3720,294 @@
 %7B%0A%09%09
-return ZmlTermParser.parseZml(initialValue
+%0A%09%09// check if uncompressed ZML value (backwards compatibility) or a compressed one%0A%09%09String zml;%0A%09%09if (initialValue.startsWith(%22%3C?xml%22)) %7B%0A%09%09%09zml = initialValue;%0A%09%09%7D else %7B%0A%09%09%09// compressed%0A%09%09%09zml = StringCompression.decompress(initialValue);%0A%09%09%7D%0A%09%09%0A%09%09return ZmlTermParser.parseZml(zml
 );%0A%09
@@ -4177,22 +4177,28 @@
 ue) %7B%0A%09%09
-return
+String zml =
  ZmlTerm
@@ -4240,16 +4240,208 @@
 Value);%0A
+%09%09// compress the ZML string, since it tends to occupy the majority of storage space%0A%09%09// the compression can be up to 95%25 efficient on large Strings%0A%09%09return StringCompression.compress(zml);%0A
 %09%7D%0A%0A%09/**

compress CZT terms when serializing (saves up to 95% space for large terms)