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

fr.lip6.move.pnml.symmetricnet.finiteEnumerations.impl.FEConstantImpl Maven / Gradle / Ivy

/**
 *  Copyright 2009-2016 Université Paris Ouest and Sorbonne Universités,
 * 							Univ. Paris 06 - CNRS UMR 7606 (LIP6)
 *
 *  All rights reserved.   This program and the accompanying materials
 *  are made available under the terms of the Eclipse Public License v1.0
 *  which accompanies this distribution, and is available at
 *  http://www.eclipse.org/legal/epl-v10.html
 *
 *  Project leader / Initial Contributor:
 *    Lom Messan Hillah - 
 *
 *  Contributors:
 *    ${ocontributors} - <$oemails}>
 *
 *  Mailing list:
 *    [email protected]
 */
/**
 * (C) Sorbonne Universités, UPMC Univ Paris 06, UMR CNRS 7606 (LIP6/MoVe)
 * All rights reserved.   This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *  
 *  Contributors: 
 *    Lom HILLAH (LIP6) - Initial models and implementation
 *    Rachid Alahyane (UPMC) - Infrastructure and continuous integration
 *    Bastien Bouzerau (UPMC) - Architecture 
 *    Guillaume Giffo (UPMC) - Code generation refactoring, High-level API
 */
package fr.lip6.move.pnml.symmetricnet.finiteEnumerations.impl;

import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.charset.Charset;
import java.util.List;

import javax.xml.namespace.QName;

import org.apache.axiom.om.OMElement;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;
import org.eclipse.emf.common.util.DiagnosticChain;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;
import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.emf.ecore.util.EcoreUtil;

import fr.lip6.move.pnml.framework.general.PnmlExport;
import fr.lip6.move.pnml.framework.utils.IdRefLinker;
import fr.lip6.move.pnml.framework.utils.ModelRepository;
import fr.lip6.move.pnml.framework.utils.PNMLEncoding;
import fr.lip6.move.pnml.framework.utils.PrettyPrintData;
import fr.lip6.move.pnml.framework.utils.exception.InnerBuildException;
import fr.lip6.move.pnml.framework.utils.exception.InvalidIDException;
import fr.lip6.move.pnml.framework.utils.exception.VoidRepositoryException;
import fr.lip6.move.pnml.symmetricnet.finiteEnumerations.FEConstant;
import fr.lip6.move.pnml.symmetricnet.finiteEnumerations.FiniteEnumeration;
import fr.lip6.move.pnml.symmetricnet.finiteEnumerations.FiniteEnumerationsFactory;
import fr.lip6.move.pnml.symmetricnet.finiteEnumerations.FiniteEnumerationsPackage;
import fr.lip6.move.pnml.symmetricnet.terms.impl.OperatorDeclImpl;

/**
 * 
 * An implementation of the model object 'FE Constant'.
 * 
 * 

* The following features are implemented: *

    *
  • {@link fr.lip6.move.pnml.symmetricnet.finiteEnumerations.impl.FEConstantImpl#getSort Sort}
  • *
*

* * @generated */ public class FEConstantImpl extends OperatorDeclImpl implements FEConstant { /** * * * @generated */ protected FEConstantImpl() { super(); } /** * * * @generated */ @Override protected EClass eStaticClass() { return FiniteEnumerationsPackage.Literals.FE_CONSTANT; } /** * * * @generated */ @Override public FiniteEnumeration getSort() { if (eContainerFeatureID() != FiniteEnumerationsPackage.FE_CONSTANT__SORT) return null; return (FiniteEnumeration) eInternalContainer(); } /** * * * @generated */ public NotificationChain basicSetSort(FiniteEnumeration newSort, NotificationChain msgs) { msgs = eBasicSetContainer((InternalEObject) newSort, FiniteEnumerationsPackage.FE_CONSTANT__SORT, msgs); return msgs; } /** * * * @generated */ @Override public void setSort(FiniteEnumeration newSort) { if (newSort != eInternalContainer() || (eContainerFeatureID() != FiniteEnumerationsPackage.FE_CONSTANT__SORT && newSort != null)) { if (EcoreUtil.isAncestor(this, newSort)) throw new IllegalArgumentException("Recursive containment not allowed for " + toString()); NotificationChain msgs = null; if (eInternalContainer() != null) msgs = eBasicRemoveFromContainer(msgs); if (newSort != null) msgs = ((InternalEObject) newSort).eInverseAdd(this, FiniteEnumerationsPackage.FINITE_ENUMERATION__ELEMENTS, FiniteEnumeration.class, msgs); msgs = basicSetSort(newSort, msgs); if (msgs != null) msgs.dispatch(); } else if (eNotificationRequired()) eNotify(new ENotificationImpl(this, Notification.SET, FiniteEnumerationsPackage.FE_CONSTANT__SORT, newSort, newSort)); } /** * * * @generated */ @Override public NotificationChain eInverseAdd(InternalEObject otherEnd, int featureID, NotificationChain msgs) { switch (featureID) { case FiniteEnumerationsPackage.FE_CONSTANT__SORT: if (eInternalContainer() != null) msgs = eBasicRemoveFromContainer(msgs); return basicSetSort((FiniteEnumeration) otherEnd, msgs); } return super.eInverseAdd(otherEnd, featureID, msgs); } /** * * * @generated */ @Override public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) { switch (featureID) { case FiniteEnumerationsPackage.FE_CONSTANT__SORT: return basicSetSort(null, msgs); } return super.eInverseRemove(otherEnd, featureID, msgs); } /** * * * @generated */ @Override public NotificationChain eBasicRemoveFromContainerFeature(NotificationChain msgs) { switch (eContainerFeatureID()) { case FiniteEnumerationsPackage.FE_CONSTANT__SORT: return eInternalContainer().eInverseRemove(this, FiniteEnumerationsPackage.FINITE_ENUMERATION__ELEMENTS, FiniteEnumeration.class, msgs); } return super.eBasicRemoveFromContainerFeature(msgs); } /** * * * @generated */ @Override public Object eGet(int featureID, boolean resolve, boolean coreType) { switch (featureID) { case FiniteEnumerationsPackage.FE_CONSTANT__SORT: return getSort(); } return super.eGet(featureID, resolve, coreType); } /** * * * @generated */ @Override public void eSet(int featureID, Object newValue) { switch (featureID) { case FiniteEnumerationsPackage.FE_CONSTANT__SORT: setSort((FiniteEnumeration) newValue); return; } super.eSet(featureID, newValue); } /** * * * @generated */ @Override public void eUnset(int featureID) { switch (featureID) { case FiniteEnumerationsPackage.FE_CONSTANT__SORT: setSort((FiniteEnumeration) null); return; } super.eUnset(featureID); } /** * * * @generated */ @Override public boolean eIsSet(int featureID) { switch (featureID) { case FiniteEnumerationsPackage.FE_CONSTANT__SORT: return getSort() != null; } return super.eIsSet(featureID); } /** * Return the string containing the pnml output */ @Override public String toPNML() { //id 1 //idref 0 //attributes 1 //sons 0 Boolean prettyPrintStatus = ModelRepository.getInstance().isPrettyPrintActive(); String retline = ""; String headline = ""; PrettyPrintData prpd = null; if (prettyPrintStatus) { retline = "\n"; prpd = ModelRepository.getInstance().getPrettyPrintData(); headline = prpd.getCurrentLineHeader(); } StringBuilder sb = new StringBuilder(); sb.append(headline); sb.append(""); sb.append(retline); //sons, follow processing /****/ if (prettyPrintStatus) { headline = prpd.decreaseLineHeaderLevel(); } return sb.toString(); } @Override @SuppressWarnings("unchecked") public void fromPNML(OMElement locRoot, IdRefLinker idr) throws InnerBuildException, InvalidIDException, VoidRepositoryException { //1 //0 //1 //0 @SuppressWarnings("unused") FiniteEnumerationsFactory fact = FiniteEnumerationsFactory.eINSTANCE; //processing id if (locRoot.getAttributeValue(new QName("id")) != null) { this.setId(new java.lang.String(locRoot.getAttributeValue(new QName("id")))); ModelRepository.getInstance().getCurrentIdRepository() .checkId(new java.lang.String(locRoot.getAttributeValue(new QName("id"))).toString(), this); } //processing idref //processing attributes if (locRoot.getAttributeValue(new QName("name")) != null) { try { this.setName(new String(locRoot.getAttributeValue(new QName("name")))); } catch (Exception e) { throw new fr.lip6.move.pnml.framework.utils.exception.InnerBuildException(e); } } //processing sons } /** * Return the string containing the pnml output */ @Override public void toPNML(FileChannel fc) { //id 1 //idref 0 //attributes 1 //sons 0 final int bufferSizeKB = 8; final int bufferSize = bufferSizeKB * 1024; final ByteBuffer bytebuf = ByteBuffer.allocateDirect(bufferSize); final String charsetEncoding = PNMLEncoding.ISO_8859_1.getName(); Boolean prettyPrintStatus = ModelRepository.getInstance().isPrettyPrintActive(); String retline = ""; String headline = ""; PrettyPrintData prpd = null; if (prettyPrintStatus) { retline = "\n"; prpd = ModelRepository.getInstance().getPrettyPrintData(); headline = prpd.getCurrentLineHeader(); } StringBuilder sb = new StringBuilder(); sb.append(headline); sb.append(""); sb.append(retline); //sons, follow processing /****/ if (prettyPrintStatus) { headline = prpd.decreaseLineHeaderLevel(); } try { writeIntoStream(bytebuf, fc, sb.toString().getBytes(Charset.forName(charsetEncoding))); } catch (IOException io) { io.printStackTrace(); // fail fast return; } sb = null; } /** * Writes buffer of a given max size into file channel. */ private static final void writeIntoStream(final ByteBuffer bytebuf, final FileChannel fc, final byte[] contents) throws IOException { final int chopSize = 6 * 1024; if (contents.length >= bytebuf.capacity()) { List chops = PnmlExport.chopBytes(contents, chopSize); for (byte[] buf : chops) { bytebuf.put(buf); bytebuf.flip(); fc.write(bytebuf); bytebuf.clear(); } } else { bytebuf.put(contents); bytebuf.flip(); fc.write(bytebuf); bytebuf.clear(); } } /** * - */ @Override public boolean validateOCL(DiagnosticChain diagnostics) { //this package has no validator class return true; } } //FEConstantImpl




© 2015 - 2025 Weber Informatics LLC | Privacy Policy