Lines 35-40
Link Here
|
35 |
import java.util.StringTokenizer; |
35 |
import java.util.StringTokenizer; |
36 |
|
36 |
|
37 |
import org.eclipse.emf.common.util.BasicEList; |
37 |
import org.eclipse.emf.common.util.BasicEList; |
|
|
38 |
import org.eclipse.emf.common.util.BasicEMap; |
38 |
import org.eclipse.emf.common.util.EMap; |
39 |
import org.eclipse.emf.common.util.EMap; |
39 |
import org.eclipse.emf.common.util.URI; |
40 |
import org.eclipse.emf.common.util.URI; |
40 |
import org.eclipse.emf.ecore.EAttribute; |
41 |
import org.eclipse.emf.ecore.EAttribute; |
Lines 52-57
Link Here
|
52 |
import org.eclipse.emf.ecore.resource.URIConverter; |
53 |
import org.eclipse.emf.ecore.resource.URIConverter; |
53 |
import org.eclipse.emf.ecore.resource.impl.ExtensibleURIConverterImpl; |
54 |
import org.eclipse.emf.ecore.resource.impl.ExtensibleURIConverterImpl; |
54 |
import org.eclipse.emf.ecore.util.BasicExtendedMetaData; |
55 |
import org.eclipse.emf.ecore.util.BasicExtendedMetaData; |
|
|
56 |
import org.eclipse.emf.ecore.util.PathSettingDelegate; |
55 |
import org.eclipse.emf.ecore.util.EcoreUtil; |
57 |
import org.eclipse.emf.ecore.util.EcoreUtil; |
56 |
import org.eclipse.emf.ecore.util.ExtendedMetaData; |
58 |
import org.eclipse.emf.ecore.util.ExtendedMetaData; |
57 |
import org.eclipse.emf.ecore.util.FeatureMap; |
59 |
import org.eclipse.emf.ecore.util.FeatureMap; |
Lines 339-344
Link Here
|
339 |
protected boolean isNamespaceAware; |
341 |
protected boolean isNamespaceAware; |
340 |
protected boolean suppressDocumentRoot; |
342 |
protected boolean suppressDocumentRoot; |
341 |
protected boolean laxWildcardProcessing; |
343 |
protected boolean laxWildcardProcessing; |
|
|
344 |
protected Map<EClass, LinkRecord> linkClasses; |
345 |
protected Map<EReference, EReference> linkEnds; |
342 |
|
346 |
|
343 |
/** |
347 |
/** |
344 |
*/ |
348 |
*/ |
Lines 501-506
Link Here
|
501 |
{ |
505 |
{ |
502 |
laxWildcardProcessing = true; |
506 |
laxWildcardProcessing = true; |
503 |
} |
507 |
} |
|
|
508 |
|
509 |
if (Boolean.TRUE.equals(options.get(XMLResource.OPTION_SUPPRESS_ASSOCIATION))) |
510 |
{ |
511 |
linkClasses = new HashMap<EClass, LinkRecord>(); |
512 |
linkEnds = new HashMap<EReference, EReference>(); |
513 |
} |
504 |
} |
514 |
} |
505 |
|
515 |
|
506 |
protected void setExtendedMetaDataOption(Object extendedMetaDataOption) |
516 |
protected void setExtendedMetaDataOption(Object extendedMetaDataOption) |
Lines 1475-1487
Link Here
|
1475 |
{ |
1485 |
{ |
1476 |
if (object != null) |
1486 |
if (object != null) |
1477 |
{ |
1487 |
{ |
|
|
1488 |
boolean checkContains = false; |
1489 |
EObject addedObject = object; |
1490 |
if (linkClasses != null) |
1491 |
{ |
1492 |
LinkRecord linkRecord = linkClasses.get(object.eClass()); |
1493 |
if (linkRecord != null && linkRecord.instance != null) |
1494 |
{ |
1495 |
addedObject = linkRecord.instance; |
1496 |
checkContains = true; |
1497 |
} |
1498 |
} |
1478 |
if (deferredExtent != null) |
1499 |
if (deferredExtent != null) |
1479 |
{ |
1500 |
{ |
1480 |
deferredExtent.add(object); |
1501 |
if (!checkContains || !deferredExtent.contains(addedObject)) |
|
|
1502 |
{ |
1503 |
deferredExtent.add(addedObject); |
1504 |
} |
1481 |
} |
1505 |
} |
1482 |
else |
1506 |
else |
1483 |
{ |
1507 |
{ |
1484 |
extent.addUnique(object); |
1508 |
if (checkContains) |
|
|
1509 |
{ |
1510 |
extent.add(addedObject); |
1511 |
} |
1512 |
else |
1513 |
{ |
1514 |
extent.addUnique(addedObject); |
1515 |
} |
1485 |
} |
1516 |
} |
1486 |
|
1517 |
|
1487 |
if (extendedMetaData != null && !mixedTargets.isEmpty()) |
1518 |
if (extendedMetaData != null && !mixedTargets.isEmpty()) |
Lines 2170-2175
Link Here
|
2170 |
return obj; |
2201 |
return obj; |
2171 |
} |
2202 |
} |
2172 |
|
2203 |
|
|
|
2204 |
protected static class LinkRecord |
2205 |
{ |
2206 |
public EClass association; |
2207 |
public EReference endA; |
2208 |
public EReference mapA; |
2209 |
public EReference endB; |
2210 |
public EReference mapB; |
2211 |
public EMap<EObject, Object> eMapA; |
2212 |
public EMap<EObject, Object> eMapB; |
2213 |
public Map<Object, BasicEMap.Entry<EObject, Object>> mapEntriesA = new HashMap<Object, BasicEMap.Entry<EObject,Object>>(); |
2214 |
public Map<Object, BasicEMap.Entry<EObject, Object>> mapEntriesB = new HashMap<Object, BasicEMap.Entry<EObject,Object>>(); |
2215 |
public EObject instance; |
2216 |
|
2217 |
public static final LinkRecord NONE = new LinkRecord(); |
2218 |
} |
2219 |
|
2173 |
/** |
2220 |
/** |
2174 |
* @deprecated since 2.2 |
2221 |
* @deprecated since 2.2 |
2175 |
* Create an object given a content helper, a factory, and a type name, |
2222 |
* Create an object given a content helper, a factory, and a type name, |
Lines 2189-2194
Link Here
|
2189 |
if (disableNotify) |
2236 |
if (disableNotify) |
2190 |
newObject.eSetDeliver(false); |
2237 |
newObject.eSetDeliver(false); |
2191 |
|
2238 |
|
|
|
2239 |
if (linkClasses != null) |
2240 |
{ |
2241 |
EClass eClass = newObject.eClass(); |
2242 |
LinkRecord linkRecord = linkClasses.get(eClass); |
2243 |
if (linkRecord == null) |
2244 |
{ |
2245 |
if ("true".equals(EcoreUtil.getAnnotation(eClass, EcorePackage.eNS_URI, "link"))) |
2246 |
{ |
2247 |
linkRecord = new LinkRecord(); |
2248 |
linkClasses.put(eClass, linkRecord); |
2249 |
int count = 0; |
2250 |
for (EReference eReference : eClass.getEReferences()) |
2251 |
{ |
2252 |
EClass eReferenceType = eReference.getEReferenceType(); |
2253 |
if ("java.util.Map$Entry".equals(eReferenceType.getInstanceClassName())) |
2254 |
{ |
2255 |
if (linkRecord.mapA == null) |
2256 |
{ |
2257 |
linkRecord.mapA = eReference; |
2258 |
} |
2259 |
else |
2260 |
{ |
2261 |
linkRecord.mapB = eReference; |
2262 |
} |
2263 |
if (linkRecord.association == null) |
2264 |
{ |
2265 |
LOOP: |
2266 |
for (EClassifier eClassifier : eClass.getEPackage().getEClassifiers()) |
2267 |
{ |
2268 |
if (eClassifier != eClass && eClassifier instanceof EClass) |
2269 |
{ |
2270 |
EClass otherEClass = (EClass)eClassifier; |
2271 |
for (EReference otherEReference : otherEClass.getEReferences()) |
2272 |
{ |
2273 |
if (otherEReference.getEType() == eReferenceType) |
2274 |
{ |
2275 |
linkRecord.association = otherEClass; |
2276 |
linkRecord.instance = helper.createObject(otherEClass.getEPackage().getEFactoryInstance(), otherEClass); |
2277 |
break LOOP; |
2278 |
} |
2279 |
} |
2280 |
} |
2281 |
} |
2282 |
} |
2283 |
String name = eReference.getName() + "/"; |
2284 |
for (EReference linkEndEReference : eClass.getEReferences()) |
2285 |
{ |
2286 |
String settingDelegate = EcoreUtil.getAnnotation(linkEndEReference, EcorePackage.eNS_URI, "settingDelegate"); |
2287 |
String path = settingDelegate == null ? null : URI.createURI(settingDelegate).fragment(); |
2288 |
if (path != null && path.startsWith(name)) |
2289 |
{ |
2290 |
if (linkRecord.endA == null) |
2291 |
{ |
2292 |
linkRecord.endA = linkEndEReference; |
2293 |
} |
2294 |
else |
2295 |
{ |
2296 |
linkRecord.endB = linkEndEReference; |
2297 |
} |
2298 |
break; |
2299 |
} |
2300 |
} |
2301 |
for (EReference otherEReference : linkRecord.association.getEReferences()) |
2302 |
{ |
2303 |
if (otherEReference.getEType() == eReferenceType) |
2304 |
{ |
2305 |
if (linkRecord.eMapA == null) |
2306 |
{ |
2307 |
linkRecord.eMapA = (EMap<EObject, Object>)linkRecord.instance.eGet(otherEReference); |
2308 |
linkEnds.put(linkRecord.endA, otherEReference); |
2309 |
} |
2310 |
else |
2311 |
{ |
2312 |
linkRecord.eMapB = (EMap<EObject, Object>)linkRecord.instance.eGet(otherEReference); |
2313 |
linkEnds.put(linkRecord.endB, otherEReference); |
2314 |
} |
2315 |
break; |
2316 |
} |
2317 |
} |
2318 |
// featureTable.setNotTransient(eReference); |
2319 |
if (++count >= 2) |
2320 |
{ |
2321 |
break; |
2322 |
} |
2323 |
} |
2324 |
} |
2325 |
} |
2326 |
else |
2327 |
{ |
2328 |
linkClasses.put(eClass, LinkRecord.NONE); |
2329 |
} |
2330 |
} |
2331 |
} |
2192 |
handleObjectAttribs(newObject); |
2332 |
handleObjectAttribs(newObject); |
2193 |
} |
2333 |
} |
2194 |
} |
2334 |
} |
Lines 2654-2659
Link Here
|
2654 |
{ |
2794 |
{ |
2655 |
try |
2795 |
try |
2656 |
{ |
2796 |
{ |
|
|
2797 |
if (linkEnds != null) |
2798 |
{ |
2799 |
EReference x = linkEnds.get(feature); |
2800 |
if (x != null) |
2801 |
{ |
2802 |
System.err.println("###" ); |
2803 |
LinkRecord linkRecord = linkClasses.get(object.eClass()); |
2804 |
InternalEObject eObjectValue = (InternalEObject)value; |
2805 |
Object key = eObjectValue.eProxyURI(); |
2806 |
if (key == null) |
2807 |
{ |
2808 |
key = value; |
2809 |
} |
2810 |
EClass mapEntryEClass = (linkRecord.endA == feature ? linkRecord.mapA : linkRecord.mapB).getEReferenceType(); |
2811 |
EMap<EObject, Object> eMap = linkRecord.endA == feature ? linkRecord.eMapA : linkRecord.eMapB; |
2812 |
Map<Object, BasicEMap.Entry<EObject, Object>> map = linkRecord.endA == feature ? linkRecord.mapEntriesA : linkRecord.mapEntriesB; |
2813 |
BasicEMap.Entry<EObject, Object> entry = map.get(key); |
2814 |
if (entry == null) |
2815 |
{ |
2816 |
entry = (BasicEMap.Entry<EObject, Object>)helper.createObject(mapEntryEClass.getEPackage().getEFactoryInstance(), mapEntryEClass); |
2817 |
eMap.add(entry); |
2818 |
map.put(key, entry); |
2819 |
} |
2820 |
entry.setKey(eObjectValue); |
2821 |
if (mapEntryEClass.getEStructuralFeature("value").isMany()) |
2822 |
{ |
2823 |
((List)entry.getValue()).add(object); |
2824 |
} |
2825 |
else |
2826 |
{ |
2827 |
entry.setValue(object); |
2828 |
} |
2829 |
|
2830 |
return; |
2831 |
} |
2832 |
} |
2657 |
helper.setValue(object, feature, value, position); |
2833 |
helper.setValue(object, feature, value, position); |
2658 |
} |
2834 |
} |
2659 |
catch (RuntimeException e) |
2835 |
catch (RuntimeException e) |