Debian Codegraph @

plugins/org.eclipse.xsd/src/org/eclipse/xsd/impl/XSDFacetImpl.java

raw
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.List;
15
16 import org.w3c.dom.Element;
17
18 import org.eclipse.emf.common.notify.Notification;
19 import org.eclipse.emf.common.notify.NotificationChain;
20 import org.eclipse.emf.ecore.EAttribute;
21 import org.eclipse.emf.ecore.EClass;
22 import org.eclipse.emf.ecore.InternalEObject;
23 import org.eclipse.emf.ecore.impl.ENotificationImpl;
24 import org.eclipse.xsd.XSDAnnotation;
25 import org.eclipse.xsd.XSDConcreteComponent;
26 import org.eclipse.xsd.XSDFacet;
27 import org.eclipse.xsd.XSDPackage;
28 import org.eclipse.xsd.XSDSimpleTypeDefinition;
29 import org.eclipse.xsd.util.XSDConstants;
30
31
32 /**
33 * <!-- begin-user-doc -->
34 * An implementation of the model object '<em><b>Facet</b></em>'.
35 * <!-- end-user-doc -->
36 * <p>
37 * The following features are implemented:
38 * </p>
39 * <ul>
40 * <li>{@link org.eclipse.xsd.impl.XSDFacetImpl#getLexicalValue <em>Lexical Value</em>}</li>
41 * <li>{@link org.eclipse.xsd.impl.XSDFacetImpl#getFacetName <em>Facet Name</em>}</li>
42 * <li>{@link org.eclipse.xsd.impl.XSDFacetImpl#getEffectiveValue <em>Effective Value</em>}</li>
43 * <li>{@link org.eclipse.xsd.impl.XSDFacetImpl#getAnnotation <em>Annotation</em>}</li>
44 * <li>{@link org.eclipse.xsd.impl.XSDFacetImpl#getSimpleTypeDefinition <em>Simple Type Definition</em>}</li>
45 * </ul>
46 *
47 * @generated
48 */
49 public abstract class XSDFacetImpl
50 extends XSDComponentImpl
51 implements XSDFacet
52 {
53 /**
54 * The default value of the '{@link #getLexicalValue() <em>Lexical Value</em>}' attribute.
55 * <!-- begin-user-doc -->
56 * <!-- end-user-doc -->
57 * @see #getLexicalValue()
58 * @generated
59 * @ordered
60 */
61 protected static final String LEXICAL_VALUE_EDEFAULT = null;
62
63 /**
64 * The cached value of the '{@link #getLexicalValue() <em>Lexical Value</em>}' attribute.
65 * <!-- begin-user-doc -->
66 * <!-- end-user-doc -->
67 * @see #getLexicalValue()
68 * @generated
69 * @ordered
70 */
71 protected String lexicalValue = LEXICAL_VALUE_EDEFAULT;
72
73 /**
74 * The default value of the '{@link #getFacetName() <em>Facet Name</em>}' attribute.
75 * <!-- begin-user-doc -->
76 * <!-- end-user-doc -->
77 * @see #getFacetName()
78 * @generated
79 * @ordered
80 */
81 protected static final String FACET_NAME_EDEFAULT = null;
82
83 /**
84 * The default value of the '{@link #getEffectiveValue() <em>Effective Value</em>}' attribute.
85 * <!-- begin-user-doc -->
86 * <!-- end-user-doc -->
87 * @see #getEffectiveValue()
88 * @generated
89 * @ordered
90 */
91 protected static final Object EFFECTIVE_VALUE_EDEFAULT = null;
92
93 /**
94 * The cached value of the '{@link #getAnnotation() <em>Annotation</em>}' containment reference.
95 * <!-- begin-user-doc -->
96 * <!-- end-user-doc -->
97 * @see #getAnnotation()
98 * @generated
99 * @ordered
100 */
101 protected XSDAnnotation annotation;
102
103 /**
104 * <!-- begin-user-doc -->
105 * <!-- end-user-doc -->
106 * @generated
107 */
108 protected XSDFacetImpl()
109 {
110 super();
111 }
112
113 /**
114 * <!-- begin-user-doc -->
115 * <!-- end-user-doc -->
116 * @generated
117 */
118 @Override
119 protected EClass eStaticClass()
120 {
121 return XSDPackage.Literals.XSD_FACET;
122 }
123
124 /**
125 * <!-- begin-user-doc -->
126 * <!-- end-user-doc -->
127 * @generated
128 */
129 @Override
130 public String getLexicalValue()
131 {
132 return lexicalValue;
133 }
134
135 /**
136 * <!-- begin-user-doc -->
137 * <!-- end-user-doc -->
138 * @generated
139 */
140 @Override
141 public void setLexicalValue(String newLexicalValue)
142 {
143 String oldLexicalValue = lexicalValue;
144 lexicalValue = newLexicalValue;
145 if (eNotificationRequired())
146 eNotify(new ENotificationImpl(this, Notification.SET, XSDPackage.XSD_FACET__LEXICAL_VALUE, oldLexicalValue, lexicalValue));
147 }
148
149 @Override
150 public void validate()
151 {
152 super.validate();
153
154 Element theElement = getElement();
155 if (theElement != null)
156 {
157 checkComplexContent("annotated", XSDConstants.PART2, "element-" + getFacetName(), theElement);
158 }
159 validateValue();
160 }
161
162 protected void validateValue()
163 {
164 // Do nothing.
165 }
166
167 @Override
168 protected void reconcileAttributes(Element changedElement)
169 {
170 super.reconcileAttributes(changedElement);
171
172 if (changedElement.hasAttributeNS(null, XSDConstants.VALUE_ATTRIBUTE))
173 {
174 String newLexicalValue = changedElement.getAttributeNS(null, XSDConstants.VALUE_ATTRIBUTE);
175 if (newLexicalValue == null || !newLexicalValue.equals(getLexicalValue()))
176 {
177 setLexicalValue(newLexicalValue);
178 }
179 }
180 else if (getLexicalValue() != null)
181 {
182 setLexicalValue(null);
183 }
184 }
185
186 @Override
187 protected void handleUnreconciledElement(Element child, List<XSDConcreteComponent> newContents, List<XSDConcreteComponent> remainingContents)
188 {
189 if (XSDConstants.nodeType(child) == XSDConstants.ANNOTATION_ELEMENT)
190 {
191 XSDAnnotation xsdAnnotation = XSDAnnotationImpl.createAnnotation(child);
192 newContents.add(xsdAnnotation);
193 }
194 }
195
196 @Override
197 protected void handleReconciliation(List<XSDConcreteComponent> newContents, List<XSDConcreteComponent> remainingContents)
198 {
199 handleAnnotationReconciliation(XSDPackage.Literals.XSD_FACET__ANNOTATION, newContents, remainingContents);
200 }
201
202 @Override
203 protected void changeAttribute(EAttribute eAttribute)
204 {
205 if (isReconciling)
206 {
207 return;
208 }
209
210 super.changeAttribute(eAttribute);
211 Element theElement = getElement();
212 if (theElement != null)
213 {
214 if (eAttribute == null || eAttribute == XSDPackage.Literals.XSD_FACET__LEXICAL_VALUE)
215 {
216 niceSetAttribute(theElement, XSDConstants.VALUE_ATTRIBUTE, getLexicalValue());
217 }
218 }
219 }
220
221 public String getFacetName()
222 {
223 String name = eClass().getName();
224 return Character.toLowerCase(name.charAt(3)) + name.substring(4, name.length() - 5);
225 }
226
227 public Object getEffectiveValue()
228 {
229 return null;
230 }
231 /**
232 * <!-- begin-user-doc -->
233 * <!-- end-user-doc -->
234 * @generated
235 */
236 @Override
237 public XSDAnnotation getAnnotation()
238 {
239 return annotation;
240 }
241
242 /**
243 * <!-- begin-user-doc -->
244 * <!-- end-user-doc -->
245 * @generated
246 */
247 @Override
248 public void setAnnotation(XSDAnnotation newAnnotation)
249 {
250 if (newAnnotation != annotation)
251 {
252 NotificationChain msgs = null;
253 if (annotation != null)
254 msgs = ((InternalEObject)annotation).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - XSDPackage.XSD_FACET__ANNOTATION, null, msgs);
255 if (newAnnotation != null)
256 msgs = ((InternalEObject)newAnnotation).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - XSDPackage.XSD_FACET__ANNOTATION, null, msgs);
257 msgs = basicSetAnnotation(newAnnotation, msgs);
258 if (msgs != null) msgs.dispatch();
259 }
260 else if (eNotificationRequired())
261 eNotify(new ENotificationImpl(this, Notification.SET, XSDPackage.XSD_FACET__ANNOTATION, newAnnotation, newAnnotation));
262 }
263
264 /**
265 * <!-- begin-user-doc -->
266 * <!-- end-user-doc -->
267 * @generated
268 */
269 public NotificationChain basicSetAnnotation(XSDAnnotation newAnnotation, NotificationChain msgs)
270 {
271 XSDAnnotation oldAnnotation = annotation;
272 annotation = newAnnotation;
273 if (eNotificationRequired())
274 {
275 ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, XSDPackage.XSD_FACET__ANNOTATION, oldAnnotation, newAnnotation);
276 if (msgs == null) msgs = notification; else msgs.add(notification);
277 }
278 return msgs;
279 }
280
281 /**
282 * <!-- begin-user-doc -->
283 * <!-- end-user-doc -->
284 * @generated modifiable
285 */
286 public XSDSimpleTypeDefinition getSimpleTypeDefinition()
287 {
288 XSDConcreteComponent result = getContainer();
289 return result instanceof XSDSimpleTypeDefinition ? (XSDSimpleTypeDefinition)result : null;
290 }
291
292 /**
293 * <!-- begin-user-doc -->
294 * <!-- end-user-doc -->
295 * @generated
296 */
297 @Override
298 public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs)
299 {
300 switch (featureID)
301 {
302 case XSDPackage.XSD_FACET__ANNOTATION:
303 return basicSetAnnotation(null, msgs);
304 }
305 return super.eInverseRemove(otherEnd, featureID, msgs);
306 }
307
308 /**
309 * <!-- begin-user-doc -->
310 * <!-- end-user-doc -->
311 * @generated
312 */
313 @Override
314 public Object eGet(int featureID, boolean resolve, boolean coreType)
315 {
316 switch (featureID)
317 {
318 case XSDPackage.XSD_FACET__LEXICAL_VALUE:
319 return getLexicalValue();
320 case XSDPackage.XSD_FACET__FACET_NAME:
321 return getFacetName();
322 case XSDPackage.XSD_FACET__EFFECTIVE_VALUE:
323 return getEffectiveValue();
324 case XSDPackage.XSD_FACET__ANNOTATION:
325 return getAnnotation();
326 case XSDPackage.XSD_FACET__SIMPLE_TYPE_DEFINITION:
327 return getSimpleTypeDefinition();
328 }
329 return super.eGet(featureID, resolve, coreType);
330 }
331
332 /**
333 * <!-- begin-user-doc -->
334 * <!-- end-user-doc -->
335 * @generated
336 */
337 @Override
338 public void eSet(int featureID, Object newValue)
339 {
340 switch (featureID)
341 {
342 case XSDPackage.XSD_FACET__LEXICAL_VALUE:
343 setLexicalValue((String)newValue);
344 return;
345 case XSDPackage.XSD_FACET__ANNOTATION:
346 setAnnotation((XSDAnnotation)newValue);
347 return;
348 }
349 super.eSet(featureID, newValue);
350 }
351
352 /**
353 * <!-- begin-user-doc -->
354 * <!-- end-user-doc -->
355 * @generated
356 */
357 @Override
358 public void eUnset(int featureID)
359 {
360 switch (featureID)
361 {
362 case XSDPackage.XSD_FACET__LEXICAL_VALUE:
363 setLexicalValue(LEXICAL_VALUE_EDEFAULT);
364 return;
365 case XSDPackage.XSD_FACET__ANNOTATION:
366 setAnnotation((XSDAnnotation)null);
367 return;
368 }
369 super.eUnset(featureID);
370 }
371
372 /**
373 * <!-- begin-user-doc -->
374 * <!-- end-user-doc -->
375 * @generated
376 */
377 @Override
378 public boolean eIsSet(int featureID)
379 {
380 switch (featureID)
381 {
382 case XSDPackage.XSD_FACET__LEXICAL_VALUE:
383 return LEXICAL_VALUE_EDEFAULT == null ? lexicalValue != null : !LEXICAL_VALUE_EDEFAULT.equals(lexicalValue);
384 case XSDPackage.XSD_FACET__FACET_NAME:
385 return FACET_NAME_EDEFAULT == null ? getFacetName() != null : !FACET_NAME_EDEFAULT.equals(getFacetName());
386 case XSDPackage.XSD_FACET__EFFECTIVE_VALUE:
387 return EFFECTIVE_VALUE_EDEFAULT == null ? getEffectiveValue() != null : !EFFECTIVE_VALUE_EDEFAULT.equals(getEffectiveValue());
388 case XSDPackage.XSD_FACET__ANNOTATION:
389 return annotation != null;
390 case XSDPackage.XSD_FACET__SIMPLE_TYPE_DEFINITION:
391 return getSimpleTypeDefinition() != null;
392 }
393 return super.eIsSet(featureID);
394 }
395
396 /**
397 * <!-- begin-user-doc -->
398 * <!-- end-user-doc -->
399 * @generated
400 */
401 @Override
402 public String toString()
403 {
404 if (eIsProxy()) return super.toString();
405
406 StringBuilder result = new StringBuilder(super.toString());
407 result.append(" (lexicalValue: ");
408 result.append(lexicalValue);
409 result.append(')');
410 return result.toString();
411 }
412
413 }