| 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.Arrays; |
| 15 |
import java.util.Collection; |
| 16 |
import java.util.Collections; |
| 17 |
import java.util.HashMap; |
| 18 |
import java.util.Iterator; |
| 19 |
import java.util.List; |
| 20 |
import java.util.ListIterator; |
| 21 |
import java.util.Map; |
| 22 |
|
| 23 |
import org.w3c.dom.Element; |
| 24 |
|
| 25 |
import org.eclipse.emf.common.notify.Notification; |
| 26 |
import org.eclipse.emf.ecore.EAttribute; |
| 27 |
import org.eclipse.emf.ecore.EClass; |
| 28 |
import org.eclipse.emf.ecore.impl.ENotificationImpl; |
| 29 |
import org.eclipse.emf.ecore.util.EObjectEList; |
| 30 |
import org.eclipse.emf.ecore.xml.type.util.XMLTypeUtil; |
| 31 |
|
| 32 |
import org.eclipse.xsd.XSDComplexTypeDefinition; |
| 33 |
import org.eclipse.xsd.XSDConcreteComponent; |
| 34 |
import org.eclipse.xsd.XSDNamedComponent; |
| 35 |
import org.eclipse.xsd.XSDPackage; |
| 36 |
import org.eclipse.xsd.XSDPlugin; |
| 37 |
import org.eclipse.xsd.XSDSchema; |
| 38 |
import org.eclipse.xsd.XSDSimpleTypeDefinition; |
| 39 |
import org.eclipse.xsd.XSDVariety; |
| 40 |
import org.eclipse.xsd.util.XSDConstants; |
| 41 |
|
| 42 |
|
| 43 |
/** |
| 44 |
* <!-- begin-user-doc --> |
| 45 |
* An implementation of the model object '<em><b>Named Component</b></em>'. |
| 46 |
* <!-- end-user-doc --> |
| 47 |
* <p> |
| 48 |
* The following features are implemented: |
| 49 |
* </p> |
| 50 |
* <ul> |
| 51 |
* <li>{@link org.eclipse.xsd.impl.XSDNamedComponentImpl#getName <em>Name</em>}</li> |
| 52 |
* <li>{@link org.eclipse.xsd.impl.XSDNamedComponentImpl#getTargetNamespace <em>Target Namespace</em>}</li> |
| 53 |
* <li>{@link org.eclipse.xsd.impl.XSDNamedComponentImpl#getAliasName <em>Alias Name</em>}</li> |
| 54 |
* <li>{@link org.eclipse.xsd.impl.XSDNamedComponentImpl#getURI <em>URI</em>}</li> |
| 55 |
* <li>{@link org.eclipse.xsd.impl.XSDNamedComponentImpl#getAliasURI <em>Alias URI</em>}</li> |
| 56 |
* <li>{@link org.eclipse.xsd.impl.XSDNamedComponentImpl#getQName <em>QName</em>}</li> |
| 57 |
* </ul> |
| 58 |
* |
| 59 |
* @generated |
| 60 |
*/ |
| 61 |
public abstract class XSDNamedComponentImpl |
| 62 |
extends XSDComponentImpl |
| 63 |
implements XSDNamedComponent |
| 64 |
{ |
| 65 |
/** |
| 66 |
* The default value of the '{@link #getName() <em>Name</em>}' attribute. |
| 67 |
* <!-- begin-user-doc --> |
| 68 |
* <!-- end-user-doc --> |
| 69 |
* @see #getName() |
| 70 |
* @generated |
| 71 |
* @ordered |
| 72 |
*/ |
| 73 |
protected static final String NAME_EDEFAULT = null; |
| 74 |
|
| 75 |
/** |
| 76 |
* The cached value of the '{@link #getName() <em>Name</em>}' attribute. |
| 77 |
* <!-- begin-user-doc --> |
| 78 |
* <!-- end-user-doc --> |
| 79 |
* @see #getName() |
| 80 |
* @generated |
| 81 |
* @ordered |
| 82 |
*/ |
| 83 |
protected String name = NAME_EDEFAULT; |
| 84 |
|
| 85 |
/** |
| 86 |
* The default value of the '{@link #getTargetNamespace() <em>Target Namespace</em>}' attribute. |
| 87 |
* <!-- begin-user-doc --> |
| 88 |
* <!-- end-user-doc --> |
| 89 |
* @see #getTargetNamespace() |
| 90 |
* @generated |
| 91 |
* @ordered |
| 92 |
*/ |
| 93 |
protected static final String TARGET_NAMESPACE_EDEFAULT = null; |
| 94 |
|
| 95 |
/** |
| 96 |
* The cached value of the '{@link #getTargetNamespace() <em>Target Namespace</em>}' attribute. |
| 97 |
* <!-- begin-user-doc --> |
| 98 |
* <!-- end-user-doc --> |
| 99 |
* @see #getTargetNamespace() |
| 100 |
* @generated |
| 101 |
* @ordered |
| 102 |
*/ |
| 103 |
protected String targetNamespace = TARGET_NAMESPACE_EDEFAULT; |
| 104 |
|
| 105 |
/** |
| 106 |
* The default value of the '{@link #getAliasName() <em>Alias Name</em>}' attribute. |
| 107 |
* <!-- begin-user-doc --> |
| 108 |
* <!-- end-user-doc --> |
| 109 |
* @see #getAliasName() |
| 110 |
* @generated |
| 111 |
* @ordered |
| 112 |
*/ |
| 113 |
protected static final String ALIAS_NAME_EDEFAULT = null; |
| 114 |
|
| 115 |
/** |
| 116 |
* The default value of the '{@link #getURI() <em>URI</em>}' attribute. |
| 117 |
* <!-- begin-user-doc --> |
| 118 |
* <!-- end-user-doc --> |
| 119 |
* @see #getURI() |
| 120 |
* @generated |
| 121 |
* @ordered |
| 122 |
*/ |
| 123 |
protected static final String URI_EDEFAULT = null; |
| 124 |
|
| 125 |
/** |
| 126 |
* The default value of the '{@link #getAliasURI() <em>Alias URI</em>}' attribute. |
| 127 |
* <!-- begin-user-doc --> |
| 128 |
* <!-- end-user-doc --> |
| 129 |
* @see #getAliasURI() |
| 130 |
* @generated |
| 131 |
* @ordered |
| 132 |
*/ |
| 133 |
protected static final String ALIAS_URI_EDEFAULT = null; |
| 134 |
|
| 135 |
/** |
| 136 |
* The default value of the '{@link #getQName() <em>QName</em>}' attribute. |
| 137 |
* <!-- begin-user-doc --> |
| 138 |
* <!-- end-user-doc --> |
| 139 |
* @see #getQName() |
| 140 |
* @generated |
| 141 |
* @ordered |
| 142 |
*/ |
| 143 |
protected static final String QNAME_EDEFAULT = null; |
| 144 |
|
| 145 |
public static List<XSDNamedComponent> sortNamedComponents(Collection<XSDNamedComponent> xsdNamedComponents) |
| 146 |
{ |
| 147 |
XSDNamedComponent [] objects = new XSDNamedComponent[xsdNamedComponents.size()]; |
| 148 |
xsdNamedComponents.toArray(objects); |
| 149 |
Arrays.sort(objects, Comparator.getInstance()); |
| 150 |
|
| 151 |
return Arrays.asList(objects); |
| 152 |
} |
| 153 |
|
| 154 |
public static <T extends XSDNamedComponent> void addToSortedList(List<T> xsdNamedComponents, T xsdNamedComponent) |
| 155 |
{ |
| 156 |
int index = Collections.binarySearch(xsdNamedComponents, xsdNamedComponent, Comparator.getInstance()); |
| 157 |
if (index < 0) |
| 158 |
{ |
| 159 |
xsdNamedComponents.add(-(index + 1), xsdNamedComponent); |
| 160 |
} |
| 161 |
else if (xsdNamedComponents.get(index) != xsdNamedComponent) |
| 162 |
{ |
| 163 |
xsdNamedComponents.add(index, xsdNamedComponent); |
| 164 |
} |
| 165 |
} |
| 166 |
|
| 167 |
public static class XSDNamedComponentList<E extends Object & XSDNamedComponent> extends EObjectEList<E> |
| 168 |
{ |
| 169 |
private static final long serialVersionUID = 1L; |
| 170 |
|
| 171 |
protected Map<String, XSDNamedComponent> map; |
| 172 |
protected XSDSchemaImpl xsdSchema; |
| 173 |
|
| 174 |
public XSDNamedComponentList(Class<?> dataClass, XSDSchemaImpl owner, int featureID) |
| 175 |
{ |
| 176 |
super(dataClass, owner, featureID); |
| 177 |
xsdSchema = owner; |
| 178 |
} |
| 179 |
|
| 180 |
protected boolean isFromThisNamespace(XSDNamedComponent xsdNamedComponent) |
| 181 |
{ |
| 182 |
String targetNamespace = xsdNamedComponent.getTargetNamespace(); |
| 183 |
return targetNamespace == null ? xsdSchema.getTargetNamespace() == null : targetNamespace.equals(xsdSchema.getTargetNamespace()); |
| 184 |
} |
| 185 |
|
| 186 |
@Override |
| 187 |
protected void didAdd(int index, Object newObject) |
| 188 |
{ |
| 189 |
XSDNamedComponent xsdNamedComponent = (XSDNamedComponent)newObject; |
| 190 |
if (isFromThisNamespace(xsdNamedComponent)) |
| 191 |
{ |
| 192 |
if (map == null) |
| 193 |
{ |
| 194 |
map = new HashMap<String, XSDNamedComponent>(); |
| 195 |
} |
| 196 |
map.put(xsdNamedComponent.getName(), xsdNamedComponent); |
| 197 |
} |
| 198 |
} |
| 199 |
|
| 200 |
@Override |
| 201 |
protected void didClear(int size, Object[] oldObjects) |
| 202 |
{ |
| 203 |
map = null; |
| 204 |
} |
| 205 |
|
| 206 |
@Override |
| 207 |
protected void didRemove(int index, Object oldObject) |
| 208 |
{ |
| 209 |
if (map != null) |
| 210 |
{ |
| 211 |
XSDNamedComponent xsdNamedComponent = (XSDNamedComponent)oldObject; |
| 212 |
if (isFromThisNamespace(xsdNamedComponent)) |
| 213 |
{ |
| 214 |
map.values().remove(xsdNamedComponent); |
| 215 |
} |
| 216 |
} |
| 217 |
} |
| 218 |
|
| 219 |
@Override |
| 220 |
protected void didSet(int index, Object newObject, Object oldObject) |
| 221 |
{ |
| 222 |
didRemove(index, oldObject); |
| 223 |
didAdd(index, newObject); |
| 224 |
} |
| 225 |
|
| 226 |
public XSDNamedComponent get(String targetNamespace, String localName) |
| 227 |
{ |
| 228 |
// If the list is empty, there can't be a match. |
| 229 |
// |
| 230 |
if (isEmpty()) |
| 231 |
{ |
| 232 |
return null; |
| 233 |
} |
| 234 |
|
| 235 |
// If we are looking up a name in the owning schema's namespace... |
| 236 |
// |
| 237 |
if (targetNamespace == null ? xsdSchema.getTargetNamespace() == null : targetNamespace.equals(xsdSchema.getTargetNamespace())) |
| 238 |
{ |
| 239 |
// Look up the result in the map if there is one. |
| 240 |
// |
| 241 |
if (map == null) |
| 242 |
{ |
| 243 |
return null; |
| 244 |
} |
| 245 |
XSDNamedComponent result = map.get(localName); |
| 246 |
return result; |
| 247 |
} |
| 248 |
|
| 249 |
int index = |
| 250 |
Collections.binarySearch(this, new String [] { targetNamespace, localName}, StringPairComparator.getInstance()); |
| 251 |
if (index < 0) |
| 252 |
{ |
| 253 |
return null; |
| 254 |
} |
| 255 |
else |
| 256 |
{ |
| 257 |
return this.get(index); |
| 258 |
} |
| 259 |
} |
| 260 |
} |
| 261 |
|
| 262 |
public static XSDNamedComponent findInSortedList(List<? extends XSDNamedComponent> xsdNamedComponents, String targetNamespace, String localName) |
| 263 |
{ |
| 264 |
if (xsdNamedComponents instanceof XSDNamedComponentList<?>) |
| 265 |
{ |
| 266 |
return ((XSDNamedComponentList<? extends XSDNamedComponent>)xsdNamedComponents).get(targetNamespace, localName); |
| 267 |
} |
| 268 |
int index = |
| 269 |
Collections.binarySearch(xsdNamedComponents, new String [] { targetNamespace, localName}, StringPairComparator.getInstance()); |
| 270 |
if (index < 0) |
| 271 |
{ |
| 272 |
return null; |
| 273 |
} |
| 274 |
else |
| 275 |
{ |
| 276 |
return xsdNamedComponents.get(index); |
| 277 |
} |
| 278 |
} |
| 279 |
|
| 280 |
public static <T extends XSDNamedComponent> void mergeToSortedList(List<T> xsdNamedComponentsTarget, List<T> xsdNamedComponentsSource) |
| 281 |
{ |
| 282 |
Iterator<T> sourceComponents = xsdNamedComponentsSource.iterator(); |
| 283 |
if (sourceComponents.hasNext()) |
| 284 |
{ |
| 285 |
Comparator comparator = Comparator.getInstance(); |
| 286 |
T sourceComponent = sourceComponents.next(); |
| 287 |
for (ListIterator<T> targetComponents = xsdNamedComponentsTarget.listIterator(); targetComponents.hasNext(); ) |
| 288 |
{ |
| 289 |
T targetComponent = targetComponents.next(); |
| 290 |
if (targetComponent == sourceComponent) |
| 291 |
{ |
| 292 |
// Do nothing. |
| 293 |
} |
| 294 |
else if (comparator.compare(sourceComponent, targetComponent) < 0) |
| 295 |
{ |
| 296 |
targetComponents.previous(); |
| 297 |
targetComponents.add(sourceComponent); |
| 298 |
} |
| 299 |
else |
| 300 |
{ |
| 301 |
continue; |
| 302 |
} |
| 303 |
|
| 304 |
if (sourceComponents.hasNext()) |
| 305 |
{ |
| 306 |
sourceComponent = sourceComponents.next(); |
| 307 |
} |
| 308 |
else |
| 309 |
{ |
| 310 |
sourceComponent = null; |
| 311 |
break; |
| 312 |
} |
| 313 |
} |
| 314 |
|
| 315 |
if (sourceComponent != null) |
| 316 |
{ |
| 317 |
xsdNamedComponentsTarget.add(sourceComponent); |
| 318 |
while (sourceComponents.hasNext()) |
| 319 |
{ |
| 320 |
sourceComponent = sourceComponents.next(); |
| 321 |
xsdNamedComponentsTarget.add(sourceComponent); |
| 322 |
} |
| 323 |
} |
| 324 |
} |
| 325 |
} |
| 326 |
|
| 327 |
public static class Comparator implements java.util.Comparator<XSDNamedComponent> |
| 328 |
{ |
| 329 |
protected static Comparator instance = new Comparator(); |
| 330 |
|
| 331 |
public static Comparator getInstance() |
| 332 |
{ |
| 333 |
if (instance == null) |
| 334 |
{ |
| 335 |
instance = new Comparator(); |
| 336 |
} |
| 337 |
return instance; |
| 338 |
} |
| 339 |
|
| 340 |
protected XSDPlugin.StringComparator collator = XSDPlugin.INSTANCE.getComparator(); |
| 341 |
|
| 342 |
public Comparator() |
| 343 |
{ |
| 344 |
super(); |
| 345 |
} |
| 346 |
|
| 347 |
@Override |
| 348 |
public boolean equals(Object that) |
| 349 |
{ |
| 350 |
return this == that; |
| 351 |
} |
| 352 |
|
| 353 |
public int compare(XSDNamedComponent xsdNamedComponent1, XSDNamedComponent xsdNamedComponent2) |
| 354 |
{ |
| 355 |
String name1 = xsdNamedComponent1.getName(); |
| 356 |
String name2 = xsdNamedComponent2.getName(); |
| 357 |
if (name1 == null && name2 == null) |
| 358 |
{ |
| 359 |
return xsdNamedComponent1.hashCode() - xsdNamedComponent2.hashCode(); |
| 360 |
} |
| 361 |
else if (name1 == null) |
| 362 |
{ |
| 363 |
return 1; |
| 364 |
} |
| 365 |
else if (name2 == null) |
| 366 |
{ |
| 367 |
return -1; |
| 368 |
} |
| 369 |
else |
| 370 |
{ |
| 371 |
int result = collator.compare(name1, name2); |
| 372 |
if (result == 0) |
| 373 |
{ |
| 374 |
String namespace1 = xsdNamedComponent1.getTargetNamespace(); |
| 375 |
String namespace2 = xsdNamedComponent2.getTargetNamespace(); |
| 376 |
if (namespace1 == null && namespace2 == null) |
| 377 |
{ |
| 378 |
return xsdNamedComponent1.hashCode() - xsdNamedComponent2.hashCode(); |
| 379 |
} |
| 380 |
else if (namespace1 == null) |
| 381 |
{ |
| 382 |
return 1; |
| 383 |
} |
| 384 |
else if (namespace2 == null) |
| 385 |
{ |
| 386 |
return -1; |
| 387 |
} |
| 388 |
else |
| 389 |
{ |
| 390 |
result = collator.compare(namespace1, namespace2); |
| 391 |
if (result == 0) |
| 392 |
{ |
| 393 |
result = xsdNamedComponent1.hashCode() - xsdNamedComponent2.hashCode(); |
| 394 |
} |
| 395 |
return result; |
| 396 |
} |
| 397 |
} |
| 398 |
else |
| 399 |
{ |
| 400 |
return result; |
| 401 |
} |
| 402 |
} |
| 403 |
} |
| 404 |
} |
| 405 |
|
| 406 |
public static class StringPairComparator implements java.util.Comparator<Object> |
| 407 |
{ |
| 408 |
protected static StringPairComparator instance = new StringPairComparator(); |
| 409 |
|
| 410 |
public static StringPairComparator getInstance() |
| 411 |
{ |
| 412 |
if (instance == null) |
| 413 |
{ |
| 414 |
instance = new StringPairComparator(); |
| 415 |
} |
| 416 |
return instance; |
| 417 |
} |
| 418 |
|
| 419 |
protected XSDPlugin.StringComparator collator = XSDPlugin.INSTANCE.getComparator(); |
| 420 |
|
| 421 |
public StringPairComparator() |
| 422 |
{ |
| 423 |
super(); |
| 424 |
} |
| 425 |
|
| 426 |
@Override |
| 427 |
public boolean equals(Object that) |
| 428 |
{ |
| 429 |
return this == that; |
| 430 |
} |
| 431 |
|
| 432 |
public int compare(Object o1, Object o2) |
| 433 |
{ |
| 434 |
XSDNamedComponent xsdNamedComponent = (XSDNamedComponent)o1; |
| 435 |
String [] strings = (String [])o2; |
| 436 |
String name1 = xsdNamedComponent.getName(); |
| 437 |
String name2 = strings[1]; |
| 438 |
if (name1 == null && name2 == null) |
| 439 |
{ |
| 440 |
return 0; |
| 441 |
} |
| 442 |
else if (name1 == null) |
| 443 |
{ |
| 444 |
return 1; |
| 445 |
} |
| 446 |
else if (name2 == null) |
| 447 |
{ |
| 448 |
return -1; |
| 449 |
} |
| 450 |
else |
| 451 |
{ |
| 452 |
int result = collator.compare(name1, name2); |
| 453 |
if (result == 0) |
| 454 |
{ |
| 455 |
String namespace1 = xsdNamedComponent.getTargetNamespace(); |
| 456 |
String namespace2 = strings[0]; |
| 457 |
if (namespace1 == null && namespace2 == null) |
| 458 |
{ |
| 459 |
return 0; |
| 460 |
} |
| 461 |
else if (namespace1 == null) |
| 462 |
{ |
| 463 |
return 1; |
| 464 |
} |
| 465 |
else if (namespace2 == null) |
| 466 |
{ |
| 467 |
return -1; |
| 468 |
} |
| 469 |
else |
| 470 |
{ |
| 471 |
return collator.compare(namespace1, namespace2); |
| 472 |
} |
| 473 |
} |
| 474 |
else |
| 475 |
{ |
| 476 |
return result; |
| 477 |
} |
| 478 |
} |
| 479 |
} |
| 480 |
} |
| 481 |
|
| 482 |
/** |
| 483 |
* <!-- begin-user-doc --> |
| 484 |
* <!-- end-user-doc --> |
| 485 |
* @generated |
| 486 |
*/ |
| 487 |
protected XSDNamedComponentImpl() |
| 488 |
{ |
| 489 |
super(); |
| 490 |
} |
| 491 |
|
| 492 |
/** |
| 493 |
* <!-- begin-user-doc --> |
| 494 |
* <!-- end-user-doc --> |
| 495 |
* @generated |
| 496 |
*/ |
| 497 |
@Override |
| 498 |
protected EClass eStaticClass() |
| 499 |
{ |
| 500 |
return XSDPackage.Literals.XSD_NAMED_COMPONENT; |
| 501 |
} |
| 502 |
|
| 503 |
/** |
| 504 |
* <!-- begin-user-doc --> |
| 505 |
* <!-- end-user-doc --> |
| 506 |
* @generated |
| 507 |
*/ |
| 508 |
@Override |
| 509 |
public String getName() |
| 510 |
{ |
| 511 |
return name; |
| 512 |
} |
| 513 |
|
| 514 |
/** |
| 515 |
* <!-- begin-user-doc --> |
| 516 |
* <!-- end-user-doc --> |
| 517 |
* @generated |
| 518 |
*/ |
| 519 |
@Override |
| 520 |
public void setName(String newName) |
| 521 |
{ |
| 522 |
String oldName = name; |
| 523 |
name = newName; |
| 524 |
if (eNotificationRequired()) |
| 525 |
eNotify(new ENotificationImpl(this, Notification.SET, XSDPackage.XSD_NAMED_COMPONENT__NAME, oldName, name)); |
| 526 |
} |
| 527 |
|
| 528 |
/** |
| 529 |
* <!-- begin-user-doc --> |
| 530 |
* <!-- end-user-doc --> |
| 531 |
* @generated |
| 532 |
*/ |
| 533 |
@Override |
| 534 |
public String getTargetNamespace() |
| 535 |
{ |
| 536 |
return targetNamespace; |
| 537 |
} |
| 538 |
|
| 539 |
/** |
| 540 |
* <!-- begin-user-doc --> |
| 541 |
* <!-- end-user-doc --> |
| 542 |
* @generated |
| 543 |
*/ |
| 544 |
@Override |
| 545 |
public void setTargetNamespace(String newTargetNamespace) |
| 546 |
{ |
| 547 |
String oldTargetNamespace = targetNamespace; |
| 548 |
targetNamespace = newTargetNamespace; |
| 549 |
if (eNotificationRequired()) |
| 550 |
eNotify(new ENotificationImpl(this, Notification.SET, XSDPackage.XSD_NAMED_COMPONENT__TARGET_NAMESPACE, oldTargetNamespace, targetNamespace)); |
| 551 |
} |
| 552 |
|
| 553 |
@Override |
| 554 |
protected String getURIReferenceLabel() |
| 555 |
{ |
| 556 |
return getName(); |
| 557 |
} |
| 558 |
|
| 559 |
public String getAliasName() |
| 560 |
{ |
| 561 |
String result = getName(); |
| 562 |
if (result == null) |
| 563 |
{ |
| 564 |
XSDConcreteComponent container = getContainer(); |
| 565 |
if (container instanceof XSDNamedComponent) |
| 566 |
{ |
| 567 |
XSDNamedComponent xsdNamedComponent = (XSDNamedComponent)container; |
| 568 |
String baseName = xsdNamedComponent.getAliasName(); |
| 569 |
if (container instanceof XSDSimpleTypeDefinition) |
| 570 |
{ |
| 571 |
XSDSimpleTypeDefinition xsdSimpleTypeDefinition = (XSDSimpleTypeDefinition)container; |
| 572 |
switch (xsdSimpleTypeDefinition.getVariety().getValue()) |
| 573 |
{ |
| 574 |
case XSDVariety.ATOMIC: |
| 575 |
{ |
| 576 |
result = baseName + "_._base"; |
| 577 |
break; |
| 578 |
} |
| 579 |
case XSDVariety.LIST: |
| 580 |
{ |
| 581 |
result = baseName + (XSDConstants.isURType(xsdSimpleTypeDefinition.getBaseTypeDefinition()) ? "_._item" : "_._base"); |
| 582 |
break; |
| 583 |
} |
| 584 |
case XSDVariety.UNION: |
| 585 |
{ |
| 586 |
result = |
| 587 |
baseName + |
| 588 |
(XSDConstants.isURType(xsdSimpleTypeDefinition.getBaseTypeDefinition()) ? |
| 589 |
"_._member" + "_._" + xsdSimpleTypeDefinition.getMemberTypeDefinitions().indexOf((XSDSimpleTypeDefinition)this) : |
| 590 |
"_._base"); |
| 591 |
break; |
| 592 |
} |
| 593 |
} |
| 594 |
} |
| 595 |
else if (container instanceof XSDComplexTypeDefinition) |
| 596 |
{ |
| 597 |
result = baseName + "_._base"; |
| 598 |
} |
| 599 |
else |
| 600 |
{ |
| 601 |
result = baseName + "_._type"; |
| 602 |
} |
| 603 |
} |
| 604 |
} |
| 605 |
return result; |
| 606 |
} |
| 607 |
|
| 608 |
public String getURI() |
| 609 |
{ |
| 610 |
String theTargetNamespace = getTargetNamespace(); |
| 611 |
if (theTargetNamespace == null) |
| 612 |
{ |
| 613 |
theTargetNamespace = ""; |
| 614 |
} |
| 615 |
String theName = getName(); |
| 616 |
if (theName == null) |
| 617 |
{ |
| 618 |
theName = getAliasName(); |
| 619 |
} |
| 620 |
return theTargetNamespace + "#" + theName; |
| 621 |
} |
| 622 |
|
| 623 |
/** |
| 624 |
* <!-- begin-user-doc --> |
| 625 |
* <!-- end-user-doc --> |
| 626 |
* @generated modifiable |
| 627 |
*/ |
| 628 |
public String getAliasURI() |
| 629 |
{ |
| 630 |
XSDSchema xsdSchema = getSchema(); |
| 631 |
String theTargetNamespace = xsdSchema == null ? getTargetNamespace() : xsdSchema.getTargetNamespace(); |
| 632 |
if (theTargetNamespace == null) |
| 633 |
{ |
| 634 |
theTargetNamespace = ""; |
| 635 |
} |
| 636 |
String theName = getAliasName(); |
| 637 |
if (theName == null) |
| 638 |
{ |
| 639 |
theName = getAliasName(); |
| 640 |
} |
| 641 |
return theTargetNamespace + "#" + theName; |
| 642 |
} |
| 643 |
|
| 644 |
public String getQName(XSDConcreteComponent relativeToComponent) |
| 645 |
{ |
| 646 |
String theName = getName(); |
| 647 |
if (theName != null && relativeToComponent != null) |
| 648 |
{ |
| 649 |
Element theElement = relativeToComponent.getElement(); |
| 650 |
if (theElement != null) |
| 651 |
{ |
| 652 |
String qualifier = XSDConstants.lookupQualifier(theElement, getTargetNamespace()); |
| 653 |
if (qualifier != null && qualifier.length() != 0) |
| 654 |
{ |
| 655 |
return qualifier + ":" + theName; |
| 656 |
} |
| 657 |
} |
| 658 |
} |
| 659 |
|
| 660 |
return theName; |
| 661 |
} |
| 662 |
|
| 663 |
public String getQName() |
| 664 |
{ |
| 665 |
return getQName(this); |
| 666 |
} |
| 667 |
|
| 668 |
/** |
| 669 |
* <!-- begin-user-doc --> |
| 670 |
* <!-- end-user-doc --> |
| 671 |
* @generated |
| 672 |
*/ |
| 673 |
@Override |
| 674 |
public Object eGet(int featureID, boolean resolve, boolean coreType) |
| 675 |
{ |
| 676 |
switch (featureID) |
| 677 |
{ |
| 678 |
case XSDPackage.XSD_NAMED_COMPONENT__NAME: |
| 679 |
return getName(); |
| 680 |
case XSDPackage.XSD_NAMED_COMPONENT__TARGET_NAMESPACE: |
| 681 |
return getTargetNamespace(); |
| 682 |
case XSDPackage.XSD_NAMED_COMPONENT__ALIAS_NAME: |
| 683 |
return getAliasName(); |
| 684 |
case XSDPackage.XSD_NAMED_COMPONENT__URI: |
| 685 |
return getURI(); |
| 686 |
case XSDPackage.XSD_NAMED_COMPONENT__ALIAS_URI: |
| 687 |
return getAliasURI(); |
| 688 |
case XSDPackage.XSD_NAMED_COMPONENT__QNAME: |
| 689 |
return getQName(); |
| 690 |
} |
| 691 |
return super.eGet(featureID, resolve, coreType); |
| 692 |
} |
| 693 |
|
| 694 |
/** |
| 695 |
* <!-- begin-user-doc --> |
| 696 |
* <!-- end-user-doc --> |
| 697 |
* @generated |
| 698 |
*/ |
| 699 |
@Override |
| 700 |
public void eSet(int featureID, Object newValue) |
| 701 |
{ |
| 702 |
switch (featureID) |
| 703 |
{ |
| 704 |
case XSDPackage.XSD_NAMED_COMPONENT__NAME: |
| 705 |
setName((String)newValue); |
| 706 |
return; |
| 707 |
case XSDPackage.XSD_NAMED_COMPONENT__TARGET_NAMESPACE: |
| 708 |
setTargetNamespace((String)newValue); |
| 709 |
return; |
| 710 |
} |
| 711 |
super.eSet(featureID, newValue); |
| 712 |
} |
| 713 |
|
| 714 |
/** |
| 715 |
* <!-- begin-user-doc --> |
| 716 |
* <!-- end-user-doc --> |
| 717 |
* @generated |
| 718 |
*/ |
| 719 |
@Override |
| 720 |
public void eUnset(int featureID) |
| 721 |
{ |
| 722 |
switch (featureID) |
| 723 |
{ |
| 724 |
case XSDPackage.XSD_NAMED_COMPONENT__NAME: |
| 725 |
setName(NAME_EDEFAULT); |
| 726 |
return; |
| 727 |
case XSDPackage.XSD_NAMED_COMPONENT__TARGET_NAMESPACE: |
| 728 |
setTargetNamespace(TARGET_NAMESPACE_EDEFAULT); |
| 729 |
return; |
| 730 |
} |
| 731 |
super.eUnset(featureID); |
| 732 |
} |
| 733 |
|
| 734 |
/** |
| 735 |
* <!-- begin-user-doc --> |
| 736 |
* <!-- end-user-doc --> |
| 737 |
* @generated |
| 738 |
*/ |
| 739 |
@Override |
| 740 |
public boolean eIsSet(int featureID) |
| 741 |
{ |
| 742 |
switch (featureID) |
| 743 |
{ |
| 744 |
case XSDPackage.XSD_NAMED_COMPONENT__NAME: |
| 745 |
return NAME_EDEFAULT == null ? name != null : !NAME_EDEFAULT.equals(name); |
| 746 |
case XSDPackage.XSD_NAMED_COMPONENT__TARGET_NAMESPACE: |
| 747 |
return TARGET_NAMESPACE_EDEFAULT == null ? targetNamespace != null : !TARGET_NAMESPACE_EDEFAULT.equals(targetNamespace); |
| 748 |
case XSDPackage.XSD_NAMED_COMPONENT__ALIAS_NAME: |
| 749 |
return ALIAS_NAME_EDEFAULT == null ? getAliasName() != null : !ALIAS_NAME_EDEFAULT.equals(getAliasName()); |
| 750 |
case XSDPackage.XSD_NAMED_COMPONENT__URI: |
| 751 |
return URI_EDEFAULT == null ? getURI() != null : !URI_EDEFAULT.equals(getURI()); |
| 752 |
case XSDPackage.XSD_NAMED_COMPONENT__ALIAS_URI: |
| 753 |
return ALIAS_URI_EDEFAULT == null ? getAliasURI() != null : !ALIAS_URI_EDEFAULT.equals(getAliasURI()); |
| 754 |
case XSDPackage.XSD_NAMED_COMPONENT__QNAME: |
| 755 |
return QNAME_EDEFAULT == null ? getQName() != null : !QNAME_EDEFAULT.equals(getQName()); |
| 756 |
} |
| 757 |
return super.eIsSet(featureID); |
| 758 |
} |
| 759 |
|
| 760 |
/** |
| 761 |
* <!-- begin-user-doc --> |
| 762 |
* <!-- end-user-doc --> |
| 763 |
* @generated |
| 764 |
*/ |
| 765 |
@Override |
| 766 |
public String toString() |
| 767 |
{ |
| 768 |
if (eIsProxy()) return super.toString(); |
| 769 |
|
| 770 |
StringBuilder result = new StringBuilder(super.toString()); |
| 771 |
result.append(" (name: "); |
| 772 |
result.append(name); |
| 773 |
result.append(", targetNamespace: "); |
| 774 |
result.append(targetNamespace); |
| 775 |
result.append(')'); |
| 776 |
return result.toString(); |
| 777 |
} |
| 778 |
|
| 779 |
@Override |
| 780 |
protected void patch() |
| 781 |
{ |
| 782 |
patchTargetNamespaceAttribute(); |
| 783 |
super.patch(); |
| 784 |
} |
| 785 |
|
| 786 |
protected void patchTargetNamespaceAttribute() |
| 787 |
{ |
| 788 |
XSDSchema xsdSchema = getSchema(); |
| 789 |
if (xsdSchema != null) |
| 790 |
{ |
| 791 |
patchTargetNamespaceAttribute(xsdSchema); |
| 792 |
} |
| 793 |
} |
| 794 |
|
| 795 |
protected void patchTargetNamespaceAttribute(XSDSchema xsdSchema) |
| 796 |
{ |
| 797 |
String newTargetNamespace = xsdSchema.getTargetNamespace(); |
| 798 |
if (newTargetNamespace == null ? getTargetNamespace() != null : !newTargetNamespace.equals(getTargetNamespace())) |
| 799 |
{ |
| 800 |
setTargetNamespace(newTargetNamespace); |
| 801 |
} |
| 802 |
} |
| 803 |
|
| 804 |
@Override |
| 805 |
protected void adoptBy(XSDSchema xsdSchema) |
| 806 |
{ |
| 807 |
patchTargetNamespaceAttribute(xsdSchema); |
| 808 |
super.adoptBy(xsdSchema); |
| 809 |
} |
| 810 |
|
| 811 |
@Override |
| 812 |
protected void reconcileAttributes(Element changedElement) |
| 813 |
{ |
| 814 |
super.reconcileAttributes(changedElement); |
| 815 |
if (changedElement == getElement()) |
| 816 |
{ |
| 817 |
reconcileNameAttribute(); |
| 818 |
} |
| 819 |
} |
| 820 |
|
| 821 |
protected void reconcileNameAttribute() |
| 822 |
{ |
| 823 |
Element theElement = getElement(); |
| 824 |
if (theElement.hasAttributeNS(null, XSDConstants.NAME_ATTRIBUTE)) |
| 825 |
{ |
| 826 |
String newName = XMLTypeUtil.normalize(theElement.getAttributeNS(null, XSDConstants.NAME_ATTRIBUTE), true); |
| 827 |
if (!newName.equals(getName())) |
| 828 |
{ |
| 829 |
setName(newName); |
| 830 |
} |
| 831 |
} |
| 832 |
else if (getName() != null) |
| 833 |
{ |
| 834 |
setName(null); |
| 835 |
} |
| 836 |
} |
| 837 |
|
| 838 |
@Override |
| 839 |
protected void changeAttribute(EAttribute eAttribute) |
| 840 |
{ |
| 841 |
super.changeAttribute(eAttribute); |
| 842 |
if (!isNamedComponentReference()) |
| 843 |
{ |
| 844 |
if (eAttribute == null || eAttribute == XSDPackage.Literals.XSD_NAMED_COMPONENT__NAME) |
| 845 |
{ |
| 846 |
if (eAttribute != null) |
| 847 |
{ |
| 848 |
XSDSchemaImpl xsdSchema = (XSDSchemaImpl)getSchema(); |
| 849 |
if (xsdSchema != null) |
| 850 |
{ |
| 851 |
xsdSchema.updateSortedList(this); |
| 852 |
} |
| 853 |
} |
| 854 |
|
| 855 |
Element theElement = getElement(); |
| 856 |
if (theElement != null) |
| 857 |
{ |
| 858 |
niceSetAttribute(theElement, XSDConstants.NAME_ATTRIBUTE, getName()); |
| 859 |
} |
| 860 |
if (eAttribute != null) |
| 861 |
{ |
| 862 |
traverseToRootForPatching(); |
| 863 |
} |
| 864 |
} |
| 865 |
} |
| 866 |
} |
| 867 |
|
| 868 |
public boolean isNamedComponentReference() |
| 869 |
{ |
| 870 |
return false; |
| 871 |
} |
| 872 |
|
| 873 |
public XSDNamedComponent getResolvedNamedComponent() |
| 874 |
{ |
| 875 |
return this; |
| 876 |
} |
| 877 |
|
| 878 |
public boolean hasSameNameAndTargetNamespace(XSDNamedComponent xsdNamedComponent) |
| 879 |
{ |
| 880 |
return |
| 881 |
(getTargetNamespace() == null ? |
| 882 |
xsdNamedComponent.getTargetNamespace() == null : |
| 883 |
getTargetNamespace().equals(xsdNamedComponent.getTargetNamespace())) && |
| 884 |
(getName() == null ? |
| 885 |
xsdNamedComponent.getName() == null : |
| 886 |
getName().equals(xsdNamedComponent.getName())); |
| 887 |
|
| 888 |
} |
| 889 |
|
| 890 |
public boolean hasNameAndTargetNamespace(String name, String targetNamespace) |
| 891 |
{ |
| 892 |
return |
| 893 |
(targetNamespace == null ? |
| 894 |
getTargetNamespace() == null : |
| 895 |
targetNamespace.equals(getTargetNamespace())) && |
| 896 |
(name == null ? |
| 897 |
getName() == null : |
| 898 |
name.equals(getName())); |
| 899 |
} |
| 900 |
|
| 901 |
public boolean hasURI(String uri) |
| 902 |
{ |
| 903 |
String theTargetNamespace = getTargetNamespace(); |
| 904 |
if (theTargetNamespace == null) |
| 905 |
{ |
| 906 |
theTargetNamespace = ""; |
| 907 |
} |
| 908 |
String theName = getName(); |
| 909 |
if (theName == null) |
| 910 |
{ |
| 911 |
theName = ""; |
| 912 |
} |
| 913 |
|
| 914 |
return |
| 915 |
uri.startsWith(theTargetNamespace) && |
| 916 |
uri.endsWith(theName) && |
| 917 |
uri.length() == theName.length() + theTargetNamespace.length() + 1; |
| 918 |
} |
| 919 |
} |