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

org.eclipse.xsd.impl.XSDFractionDigitsFacetImpl Maven / Gradle / Ivy

/**
 * Copyright (c) 2002-2006 IBM Corporation and others.
 * All rights reserved.   This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v2.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v20.html
 * 
 * Contributors: 
 *   IBM - Initial API and implementation
 */
package org.eclipse.xsd.impl;


import java.math.BigDecimal;
import org.w3c.dom.Element;
import org.w3c.dom.Node;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.ecore.EAttribute;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.impl.ENotificationImpl;

import org.eclipse.xsd.XSDAnnotation;
import org.eclipse.xsd.XSDConcreteComponent;
import org.eclipse.xsd.XSDDiagnostic;
import org.eclipse.xsd.XSDFactory;
import org.eclipse.xsd.XSDFixedFacet;
import org.eclipse.xsd.XSDFractionDigitsFacet;
import org.eclipse.xsd.XSDPackage;
import org.eclipse.xsd.XSDSimpleTypeDefinition;
import org.eclipse.xsd.XSDTotalDigitsFacet;
import org.eclipse.xsd.util.XSDConstants;


/**
 * 
 * An implementation of the model object 'Fraction Digits Facet'.
 * 
 * 

* The following features are implemented: *

*
    *
  • {@link org.eclipse.xsd.impl.XSDFractionDigitsFacetImpl#getValue Value}
  • *
* * @generated */ public class XSDFractionDigitsFacetImpl extends XSDFixedFacetImpl implements XSDFractionDigitsFacet { /** * The default value of the '{@link #getValue() Value}' attribute. * * * @see #getValue() * @generated * @ordered */ protected static final int VALUE_EDEFAULT = 0; /** * The cached value of the '{@link #getValue() Value}' attribute. * * * @see #getValue() * @generated * @ordered */ protected int value = VALUE_EDEFAULT; public static XSDFractionDigitsFacet createFractionDigitsFacet(Node node) { if (XSDConstants.nodeType(node) == XSDConstants.FRACTIONDIGITS_ELEMENT) { XSDFractionDigitsFacet xsdFractionDigitsFacet = XSDFactory.eINSTANCE.createXSDFractionDigitsFacet(); xsdFractionDigitsFacet.setElement((Element)node); return xsdFractionDigitsFacet; } return null; } /** * * * @generated */ protected XSDFractionDigitsFacetImpl() { super(); } /** * * * @generated */ @Override protected EClass eStaticClass() { return XSDPackage.Literals.XSD_FRACTION_DIGITS_FACET; } /** * * * @generated */ @Override public int getValue() { return value; } /** * * * @generated */ @Override public void setValue(int newValue) { int oldValue = value; value = newValue; if (eNotificationRequired()) eNotify(new ENotificationImpl(this, Notification.SET, XSDPackage.XSD_FRACTION_DIGITS_FACET__VALUE, oldValue, value)); } /** * * * @generated */ @Override public Object eGet(int featureID, boolean resolve, boolean coreType) { switch (featureID) { case XSDPackage.XSD_FRACTION_DIGITS_FACET__VALUE: return getValue(); } return super.eGet(featureID, resolve, coreType); } /** * * * @generated */ @Override public void eSet(int featureID, Object newValue) { switch (featureID) { case XSDPackage.XSD_FRACTION_DIGITS_FACET__VALUE: setValue((Integer)newValue); return; } super.eSet(featureID, newValue); } /** * * * @generated */ @Override public void eUnset(int featureID) { switch (featureID) { case XSDPackage.XSD_FRACTION_DIGITS_FACET__VALUE: setValue(VALUE_EDEFAULT); return; } super.eUnset(featureID); } /** * * * @generated */ @Override public boolean eIsSet(int featureID) { switch (featureID) { case XSDPackage.XSD_FRACTION_DIGITS_FACET__VALUE: return value != VALUE_EDEFAULT; } return super.eIsSet(featureID); } /** * * * @generated */ @Override public String toString() { if (eIsProxy()) return super.toString(); StringBuilder result = new StringBuilder(super.toString()); result.append(" (value: "); result.append(value); result.append(')'); return result.toString(); } @Override public Element createElement() { Element newElement = createElement(XSDConstants.FRACTIONDIGITS_ELEMENT); setElement(newElement); return newElement; } @Override public void validate() { super.validate(); XSDSimpleTypeDefinition xsdSimpleTypeDefinition = getSimpleTypeDefinition(); XSDTotalDigitsFacet xsdTotalDigitsFacet = xsdSimpleTypeDefinition.getTotalDigitsFacet(); if (xsdTotalDigitsFacet != null && getValue() > xsdTotalDigitsFacet.getValue()) { XSDDiagnostic xsdDiagnostic = reportConstraintViolation (XSDConstants.PART2, "fractionDigits-less-than-equal-to-totalDigits", getElement(), XSDConstants.VALUE_ATTRIBUTE, new Object [] { getValue(), xsdTotalDigitsFacet.getValue() }); xsdDiagnostic.getComponents().add(xsdTotalDigitsFacet); } } @Override protected void validateValue() { checkBuiltInTypeConstraint ("nonNegativeInteger", getLexicalValue(), XSDConstants.PART2, "element-totalDigits", getElement(), XSDConstants.VALUE_ATTRIBUTE, true); } @Override protected void validateRestriction(XSDFixedFacet xsdFixedFacet) { if (getValue() > ((XSDFractionDigitsFacet)xsdFixedFacet).getValue()) { XSDDiagnostic xsdDiagnostic = reportConstraintViolation (XSDConstants.PART2, "fractionDigits-valid-restriction", getElement(), XSDConstants.VALUE_ATTRIBUTE, new Object [] { getValue(), xsdFixedFacet.getEffectiveValue(), xsdFixedFacet.getSimpleTypeDefinition().getURI() }); xsdDiagnostic.getComponents().add(xsdFixedFacet); } } @Override protected void changeAttribute(EAttribute eAttribute) { super.changeAttribute(eAttribute); if (eAttribute == XSDPackage.Literals.XSD_FACET__LEXICAL_VALUE) { if (getLexicalValue() == null) { setValue(0); } else { try { int newValue = Integer.parseInt(getLexicalValue()); if (newValue != getValue()) { setValue(newValue); } } catch (NumberFormatException exception) { setValue(0); } } traverseToRootForAnalysis(); } } @Override public boolean isConstraintSatisfied(Object value) { return value instanceof BigDecimal && ((BigDecimal)value).scale() <= getValue(); } @Override public Object getEffectiveValue() { return getValue(); } @Override public XSDConcreteComponent cloneConcreteComponent(boolean deep, boolean shareDOM) { XSDFractionDigitsFacetImpl clonedFractionDigitsFacet = (XSDFractionDigitsFacetImpl)getXSDFactory().createXSDFractionDigitsFacet(); clonedFractionDigitsFacet.isReconciling = true; if (getLexicalValue() != null) { clonedFractionDigitsFacet.setLexicalValue(getLexicalValue()); } if (isSetFixed()) { clonedFractionDigitsFacet.setFixed(isFixed()); } if (deep) { if (getAnnotation() != null) { clonedFractionDigitsFacet.setAnnotation((XSDAnnotation)getAnnotation().cloneConcreteComponent(deep, shareDOM)); } } if (shareDOM && getElement() != null) { clonedFractionDigitsFacet.setElement(getElement()); } clonedFractionDigitsFacet.isReconciling = shareDOM; return clonedFractionDigitsFacet; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy