| 1 |
/** |
| 2 |
* Copyright (c) 2002-2006 IBM Corporation and others. |
| 3 |
* All rights reserved. This program and the accompanying materials |
| 4 |
* are made available under the terms of the Eclipse Public License v2.0 |
| 5 |
* which accompanies this distribution, and is available at |
| 6 |
* http://www.eclipse.org/legal/epl-v20.html |
| 7 |
* |
| 8 |
* Contributors: |
| 9 |
* IBM - Initial API and implementation |
| 10 |
*/ |
| 11 |
package org.eclipse.xsd.impl; |
| 12 |
|
| 13 |
|
| 14 |
import java.util.Collection; |
| 15 |
|
| 16 |
import org.w3c.dom.Element; |
| 17 |
import org.w3c.dom.Node; |
| 18 |
|
| 19 |
import org.eclipse.emf.common.util.EList; |
| 20 |
import org.eclipse.emf.ecore.EClass; |
| 21 |
import org.eclipse.emf.ecore.util.EObjectEList; |
| 22 |
|
| 23 |
import org.eclipse.xsd.XSDAnnotation; |
| 24 |
import org.eclipse.xsd.XSDPackage; |
| 25 |
import org.eclipse.xsd.XSDRepeatableFacet; |
| 26 |
import org.eclipse.xsd.util.XSDConstants; |
| 27 |
|
| 28 |
|
| 29 |
/** |
| 30 |
* <!-- begin-user-doc --> |
| 31 |
* An implementation of the model object '<em><b>Repeatable Facet</b></em>'. |
| 32 |
* <!-- end-user-doc --> |
| 33 |
* <p> |
| 34 |
* The following features are implemented: |
| 35 |
* </p> |
| 36 |
* <ul> |
| 37 |
* <li>{@link org.eclipse.xsd.impl.XSDRepeatableFacetImpl#getAnnotations <em>Annotations</em>}</li> |
| 38 |
* </ul> |
| 39 |
* |
| 40 |
* @generated |
| 41 |
*/ |
| 42 |
public abstract class XSDRepeatableFacetImpl |
| 43 |
extends XSDConstrainingFacetImpl |
| 44 |
implements XSDRepeatableFacet |
| 45 |
{ |
| 46 |
/** |
| 47 |
* The cached value of the '{@link #getAnnotations() <em>Annotations</em>}' reference list. |
| 48 |
* <!-- begin-user-doc --> |
| 49 |
* <!-- end-user-doc --> |
| 50 |
* @see #getAnnotations() |
| 51 |
* @generated |
| 52 |
* @ordered |
| 53 |
*/ |
| 54 |
protected EList<XSDAnnotation> annotations; |
| 55 |
|
| 56 |
public static XSDRepeatableFacet createRepeatableFacet(Node node) |
| 57 |
{ |
| 58 |
switch (XSDConstants.nodeType(node)) |
| 59 |
{ |
| 60 |
case XSDConstants.PATTERN_ELEMENT: |
| 61 |
{ |
| 62 |
return XSDPatternFacetImpl.createPatternFacet(node); |
| 63 |
} |
| 64 |
case XSDConstants.ENUMERATION_ELEMENT: |
| 65 |
{ |
| 66 |
return XSDEnumerationFacetImpl.createEnumerationFacet(node); |
| 67 |
} |
| 68 |
} |
| 69 |
|
| 70 |
return null; |
| 71 |
} |
| 72 |
|
| 73 |
/** |
| 74 |
* <!-- begin-user-doc --> |
| 75 |
* <!-- end-user-doc --> |
| 76 |
* @generated |
| 77 |
*/ |
| 78 |
protected XSDRepeatableFacetImpl() |
| 79 |
{ |
| 80 |
super(); |
| 81 |
} |
| 82 |
|
| 83 |
/** |
| 84 |
* <!-- begin-user-doc --> |
| 85 |
* <!-- end-user-doc --> |
| 86 |
* @generated |
| 87 |
*/ |
| 88 |
@Override |
| 89 |
protected EClass eStaticClass() |
| 90 |
{ |
| 91 |
return XSDPackage.Literals.XSD_REPEATABLE_FACET; |
| 92 |
} |
| 93 |
|
| 94 |
/** |
| 95 |
* <!-- begin-user-doc --> |
| 96 |
* <!-- end-user-doc --> |
| 97 |
* @generated |
| 98 |
*/ |
| 99 |
@Override |
| 100 |
public EList<XSDAnnotation> getAnnotations() |
| 101 |
{ |
| 102 |
if (annotations == null) |
| 103 |
{ |
| 104 |
annotations = new EObjectEList<XSDAnnotation>(XSDAnnotation.class, this, XSDPackage.XSD_REPEATABLE_FACET__ANNOTATIONS); |
| 105 |
} |
| 106 |
return annotations; |
| 107 |
} |
| 108 |
|
| 109 |
/** |
| 110 |
* <!-- begin-user-doc --> |
| 111 |
* <!-- end-user-doc --> |
| 112 |
* @generated |
| 113 |
*/ |
| 114 |
@Override |
| 115 |
public Object eGet(int featureID, boolean resolve, boolean coreType) |
| 116 |
{ |
| 117 |
switch (featureID) |
| 118 |
{ |
| 119 |
case XSDPackage.XSD_REPEATABLE_FACET__ANNOTATIONS: |
| 120 |
return getAnnotations(); |
| 121 |
} |
| 122 |
return super.eGet(featureID, resolve, coreType); |
| 123 |
} |
| 124 |
|
| 125 |
/** |
| 126 |
* <!-- begin-user-doc --> |
| 127 |
* <!-- end-user-doc --> |
| 128 |
* @generated |
| 129 |
*/ |
| 130 |
@SuppressWarnings("unchecked") |
| 131 |
@Override |
| 132 |
public void eSet(int featureID, Object newValue) |
| 133 |
{ |
| 134 |
switch (featureID) |
| 135 |
{ |
| 136 |
case XSDPackage.XSD_REPEATABLE_FACET__ANNOTATIONS: |
| 137 |
getAnnotations().clear(); |
| 138 |
getAnnotations().addAll((Collection<? extends XSDAnnotation>)newValue); |
| 139 |
return; |
| 140 |
} |
| 141 |
super.eSet(featureID, newValue); |
| 142 |
} |
| 143 |
|
| 144 |
/** |
| 145 |
* <!-- begin-user-doc --> |
| 146 |
* <!-- end-user-doc --> |
| 147 |
* @generated |
| 148 |
*/ |
| 149 |
@Override |
| 150 |
public void eUnset(int featureID) |
| 151 |
{ |
| 152 |
switch (featureID) |
| 153 |
{ |
| 154 |
case XSDPackage.XSD_REPEATABLE_FACET__ANNOTATIONS: |
| 155 |
getAnnotations().clear(); |
| 156 |
return; |
| 157 |
} |
| 158 |
super.eUnset(featureID); |
| 159 |
} |
| 160 |
|
| 161 |
/** |
| 162 |
* <!-- begin-user-doc --> |
| 163 |
* <!-- end-user-doc --> |
| 164 |
* @generated |
| 165 |
*/ |
| 166 |
@Override |
| 167 |
public boolean eIsSet(int featureID) |
| 168 |
{ |
| 169 |
switch (featureID) |
| 170 |
{ |
| 171 |
case XSDPackage.XSD_REPEATABLE_FACET__ANNOTATIONS: |
| 172 |
return annotations != null && !annotations.isEmpty(); |
| 173 |
} |
| 174 |
return super.eIsSet(featureID); |
| 175 |
} |
| 176 |
|
| 177 |
@Override |
| 178 |
public void validate() |
| 179 |
{ |
| 180 |
super.validate(); |
| 181 |
|
| 182 |
Element theElement = getElement(); |
| 183 |
|
| 184 |
checkAttributes |
| 185 |
(XSDConstants.PART2, |
| 186 |
"element-length", |
| 187 |
theElement, |
| 188 |
new String [] |
| 189 |
{ |
| 190 |
XSDConstants.VALUE_ATTRIBUTE, |
| 191 |
XSDConstants.ID_ATTRIBUTE |
| 192 |
}); |
| 193 |
|
| 194 |
checkBuiltInTypeConstraint |
| 195 |
("ID", |
| 196 |
null, |
| 197 |
XSDConstants.PART2, |
| 198 |
"element-" + getFacetName(), |
| 199 |
theElement, |
| 200 |
XSDConstants.ID_ATTRIBUTE, |
| 201 |
false); |
| 202 |
} |
| 203 |
|
| 204 |
@Override |
| 205 |
protected void validateValue() |
| 206 |
{ |
| 207 |
checkBuiltInTypeConstraint |
| 208 |
("nonNegativeInteger", |
| 209 |
getLexicalValue(), |
| 210 |
XSDConstants.PART2, |
| 211 |
"element-" + getFacetName(), |
| 212 |
getElement(), |
| 213 |
XSDConstants.VALUE_ATTRIBUTE, |
| 214 |
true); |
| 215 |
} |
| 216 |
} |