View | Details | Raw Unified | Return to bug 105920
Collapse All | Expand All

(-)src/org/eclipse/emf/test/core/dynamic/SimpleModelTest.java (-1 / +33 lines)
Lines 1-7 Link Here
1
/**
1
/**
2
 * <copyright>
2
 * <copyright>
3
 *
3
 *
4
 * Copyright (c) 2002-2007 IBM Corporation and others.
4
 * Copyright (c) 2002-2009 IBM Corporation and others.
5
 * All rights reserved.   This program and the accompanying materials
5
 * All rights reserved.   This program and the accompanying materials
6
 * are made available under the terms of the Eclipse Public License v1.0
6
 * are made available under the terms of the Eclipse Public License v1.0
7
 * which accompanies this distribution, and is available at
7
 * which accompanies this distribution, and is available at
Lines 33-38 Link Here
33
import org.eclipse.emf.common.EMFPlugin;
33
import org.eclipse.emf.common.EMFPlugin;
34
import org.eclipse.emf.common.util.BasicEList;
34
import org.eclipse.emf.common.util.BasicEList;
35
import org.eclipse.emf.common.util.URI;
35
import org.eclipse.emf.common.util.URI;
36
import org.eclipse.emf.ecore.EAnnotation;
36
import org.eclipse.emf.ecore.EAttribute;
37
import org.eclipse.emf.ecore.EAttribute;
37
import org.eclipse.emf.ecore.EClass;
38
import org.eclipse.emf.ecore.EClass;
38
import org.eclipse.emf.ecore.EFactory;
39
import org.eclipse.emf.ecore.EFactory;
Lines 62-67 Link Here
62
63
63
  private EAttribute employeeName;
64
  private EAttribute employeeName;
64
65
66
  private EAttribute derivedEmployeeName;
67
65
  private EAttribute employeeManager;
68
  private EAttribute employeeManager;
66
69
67
  private EClass departmentClass;
70
  private EClass departmentClass;
Lines 82-87 Link Here
82
    TestSuite ts = new TestSuite("SimpleModelTest");
85
    TestSuite ts = new TestSuite("SimpleModelTest");
83
    ts.addTest(new SimpleModelTest("testPackageAndFactory"));
86
    ts.addTest(new SimpleModelTest("testPackageAndFactory"));
84
    ts.addTest(new SimpleModelTest("testAttributes"));
87
    ts.addTest(new SimpleModelTest("testAttributes"));
88
    ts.addTest(new SimpleModelTest("testDerivedAttributes"));
85
    ts.addTest(new SimpleModelTest("testReference"));
89
    ts.addTest(new SimpleModelTest("testReference"));
86
    ts.addTest(new SimpleModelTest("testMetaData"));
90
    ts.addTest(new SimpleModelTest("testMetaData"));
87
    ts.addTest(new SimpleModelTest("testSaveAndLoad"));
91
    ts.addTest(new SimpleModelTest("testSaveAndLoad"));
Lines 111-116 Link Here
111
    employeeName.setEType(ecorePackage.getEString());
115
    employeeName.setEType(ecorePackage.getEString());
112
    employeeClass.getEStructuralFeatures().add(employeeName);
116
    employeeClass.getEStructuralFeatures().add(employeeName);
113
117
118
    derivedEmployeeName = ecoreFactory.createEAttribute();
119
    derivedEmployeeName.setName("derivedName");
120
    derivedEmployeeName.setEType(ecorePackage.getEString());
121
    derivedEmployeeName.setDerived(true);
122
    derivedEmployeeName.setTransient(true);
123
    EAnnotation eAnnotation = ecoreFactory.createEAnnotation();
124
    eAnnotation.setSource(EcorePackage.eNS_URI);
125
    eAnnotation.getDetails().put("settingDelegate", "xxx");
126
    eAnnotation.getDetails().put("path", "name");
127
    derivedEmployeeName.getEAnnotations().add(eAnnotation);
128
    employeeClass.getEStructuralFeatures().add(derivedEmployeeName);
129
114
    employeeManager = ecoreFactory.createEAttribute();
130
    employeeManager = ecoreFactory.createEAttribute();
115
    employeeManager.setName("manager");
131
    employeeManager.setName("manager");
116
    employeeManager.setEType(ecorePackage.getEBoolean());
132
    employeeManager.setEType(ecorePackage.getEBoolean());
Lines 204-209 Link Here
204
    assertEquals(123, department.eGet(departmentNumber));
220
    assertEquals(123, department.eGet(departmentNumber));
205
  }
221
  }
206
222
223
  public void testDerivedAttributes()
224
  {
225
    EFactory companyFactory = companyPackage.getEFactoryInstance();
226
227
    EObject employee1 = companyFactory.create(employeeClass);
228
    employee1.eSet(employeeName, "John");
229
    assertEquals("John", employee1.eGet(derivedEmployeeName));
230
    assertEquals(Boolean.FALSE, employee1.eGet(employeeManager));
231
232
    EObject employee2 = companyFactory.create(employeeClass);
233
    employee2.eSet(derivedEmployeeName, "Katherine");
234
    assertEquals("Katherine", employee2.eGet(employeeName));
235
    employee2.eSet(employeeManager, Boolean.TRUE);
236
    assertEquals(Boolean.TRUE, employee2.eGet(employeeManager));
237
  }
238
207
  public void testReference()
239
  public void testReference()
208
  {
240
  {
209
    EFactory companyFactory = companyPackage.getEFactoryInstance();
241
    EFactory companyFactory = companyPackage.getEFactoryInstance();
(-)src/org/eclipse/emf/ecore/xmi/impl/XMLSaveImpl.java (-20 / +62 lines)
Lines 49-54 Link Here
49
import org.eclipse.emf.ecore.resource.Resource;
49
import org.eclipse.emf.ecore.resource.Resource;
50
import org.eclipse.emf.ecore.resource.URIConverter;
50
import org.eclipse.emf.ecore.resource.URIConverter;
51
import org.eclipse.emf.ecore.util.BasicExtendedMetaData;
51
import org.eclipse.emf.ecore.util.BasicExtendedMetaData;
52
import org.eclipse.emf.ecore.util.EcoreUtil;
52
import org.eclipse.emf.ecore.util.ExtendedMetaData;
53
import org.eclipse.emf.ecore.util.ExtendedMetaData;
53
import org.eclipse.emf.ecore.util.FeatureMap;
54
import org.eclipse.emf.ecore.util.FeatureMap;
54
import org.eclipse.emf.ecore.util.InternalEList;
55
import org.eclipse.emf.ecore.util.InternalEList;
Lines 120-125 Link Here
120
  protected XMLResource xmlResource;
121
  protected XMLResource xmlResource;
121
  protected List<? extends EObject> roots;
122
  protected List<? extends EObject> roots;
122
  protected XMLResource.ElementHandler elementHandler;
123
  protected XMLResource.ElementHandler elementHandler;
124
  protected Map<EClass, Boolean> suppressedAssociations;
123
  
125
  
124
  protected static final int SKIP = 0;
126
  protected static final int SKIP = 0;
125
  protected static final int SAME_DOC = 1;
127
  protected static final int SAME_DOC = 1;
Lines 566-571 Link Here
566
      featureTable = new Lookup(map, extendedMetaData, elementHandler);
568
      featureTable = new Lookup(map, extendedMetaData, elementHandler);
567
    }
569
    }
568
    
570
    
571
    if (Boolean.TRUE.equals(options.get(XMLResource.OPTION_SUPPRESS_ASSOCIATION)))
572
    {
573
      suppressedAssociations = new HashMap<EClass, Boolean>();
574
    }
575
569
    helper.setOptions(options);
576
    helper.setOptions(options);
570
  }
577
  }
571
578
Lines 583-589 Link Here
583
    //
590
    //
584
    Object mark;
591
    Object mark;
585
592
586
    if (size == 1)
593
    if (size == 1 && suppressedAssociations == null)
587
    {
594
    {
588
      mark = writeTopObject(contents.get(0));
595
      mark = writeTopObject(contents.get(0));
589
    }
596
    }
Lines 650-675 Link Here
650
    {
657
    {
651
      if (extendedMetaData == null || featureTable.getDocumentRoot(eClass.getEPackage()) != eClass)
658
      if (extendedMetaData == null || featureTable.getDocumentRoot(eClass.getEPackage()) != eClass)
652
      {
659
      {
653
        EStructuralFeature rootFeature = null;
660
        Boolean suppressedAssociation = null;
654
        if (elementHandler != null)
661
        if (suppressedAssociations != null)
655
        {
662
        {
656
          EClassifier eClassifier =
663
          suppressedAssociation = suppressedAssociations.get(eClass);
657
            eClass == anySimpleType ?
664
          if (suppressedAssociation == null)
658
              ((SimpleAnyType)top).getInstanceType() :
665
          {
659
              eClass;
666
            suppressedAssociations.put
660
          rootFeature = featureTable.getRoot(eClassifier);
667
              (eClass,
668
               suppressedAssociation = "true".equals(EcoreUtil.getAnnotation(eClass, EcorePackage.eNS_URI, "association")));
669
          }
670
        }
671
        if (Boolean.TRUE.equals(suppressedAssociation))
672
        {
673
          for (EObject child : top.eContents())
674
          {
675
            for (EObject link : child.eContents())
676
            {
677
              writeTopObject(link);
678
            }
679
          }
680
          return null;
681
        }
682
        else
683
        {
684
          EStructuralFeature rootFeature = null;
685
          if (elementHandler != null)
686
          {
687
            EClassifier eClassifier =
688
              eClass == anySimpleType ?
689
                ((SimpleAnyType)top).getInstanceType() :
690
                eClass;
691
            rootFeature = featureTable.getRoot(eClassifier);
692
          }
693
          String name = 
694
            rootFeature != null ?
695
              helper.getQName(rootFeature) :
696
              extendedMetaData != null && roots != null && top.eContainmentFeature() != null ?
697
                helper.getQName(top.eContainmentFeature()) :
698
                helper.getQName(eClass);
699
          doc.startElement(name);
700
          Object mark = doc.mark();
701
          root = top;
702
          saveElementID(top);
703
          return mark;
661
        }
704
        }
662
        String name = 
663
          rootFeature != null ?
664
            helper.getQName(rootFeature) :
665
            extendedMetaData != null && roots != null && top.eContainmentFeature() != null ?
666
              helper.getQName(top.eContainmentFeature()) :
667
              helper.getQName(eClass);
668
        doc.startElement(name);
669
        Object mark = doc.mark();
670
        root = top;
671
        saveElementID(top);
672
        return mark;
673
      }
705
      }
674
      else
706
      else
675
      {
707
      {
Lines 2680-2685 Link Here
2680
    protected ExtendedMetaData extendedMetaData;
2712
    protected ExtendedMetaData extendedMetaData;
2681
    protected ArrayList<EObject> docRoots = new ArrayList<EObject>();
2713
    protected ArrayList<EObject> docRoots = new ArrayList<EObject>();
2682
    protected XMLResource.ElementHandler elementHandler;
2714
    protected XMLResource.ElementHandler elementHandler;
2715
    protected Set<EStructuralFeature> nonTransientFeatures;
2683
2716
2684
    protected static final class FeatureClassifierPair
2717
    protected static final class FeatureClassifierPair
2685
    {
2718
    {
Lines 2739-2744 Link Here
2739
      }
2772
      }
2740
    }
2773
    }
2741
    
2774
    
2775
    public void setNotTransient(EStructuralFeature eStructuralFeature)
2776
    {
2777
      if (nonTransientFeatures == null)
2778
      {
2779
        nonTransientFeatures = new HashSet<EStructuralFeature>();
2780
      }
2781
      nonTransientFeatures.add(eStructuralFeature);
2782
    }
2783
2742
    public EClass getDocumentRoot(EPackage epackage)
2784
    public EClass getDocumentRoot(EPackage epackage)
2743
    {
2785
    {
2744
      for (int i = 0; i < docRoots.size(); i += 2)
2786
      for (int i = 0; i < docRoots.size(); i += 2)
Lines 2890-2896 Link Here
2890
2932
2891
    protected int featureKind(EStructuralFeature f)
2933
    protected int featureKind(EStructuralFeature f)
2892
    {
2934
    {
2893
      if (f.isTransient())
2935
      if (f.isTransient() && (nonTransientFeatures == null || !nonTransientFeatures.contains(f)))
2894
      {
2936
      {
2895
        return TRANSIENT;
2937
        return TRANSIENT;
2896
      }
2938
      }
(-)src/org/eclipse/emf/ecore/xmi/impl/XMISaveImpl.java (-4 / +50 lines)
Lines 23-28 Link Here
23
import org.eclipse.emf.ecore.EClass;
23
import org.eclipse.emf.ecore.EClass;
24
import org.eclipse.emf.ecore.EObject;
24
import org.eclipse.emf.ecore.EObject;
25
import org.eclipse.emf.ecore.EReference;
25
import org.eclipse.emf.ecore.EReference;
26
import org.eclipse.emf.ecore.EcorePackage;
27
import org.eclipse.emf.ecore.util.EcoreUtil;
26
import org.eclipse.emf.ecore.util.ExtendedMetaData;
28
import org.eclipse.emf.ecore.util.ExtendedMetaData;
27
import org.eclipse.emf.ecore.xmi.XMIResource;
29
import org.eclipse.emf.ecore.xmi.XMIResource;
28
import org.eclipse.emf.ecore.xmi.XMLHelper;
30
import org.eclipse.emf.ecore.xmi.XMLHelper;
Lines 84-93 Link Here
84
        EClass eClass = top.eClass();
86
        EClass eClass = top.eClass();
85
        if (extendedMetaData == null || featureTable.getDocumentRoot(eClass.getEPackage()) != eClass)
87
        if (extendedMetaData == null || featureTable.getDocumentRoot(eClass.getEPackage()) != eClass)
86
        {
88
        {
87
          String name = helper.getQName(eClass);
89
          Boolean suppressedAssociation = null;
88
          doc.startElement(name);
90
          if (suppressedAssociations != null)
89
          root = top;
91
          {
90
          saveElementID(top);
92
            suppressedAssociation = suppressedAssociations.get(eClass);
93
            if (suppressedAssociation == null)
94
            {
95
              suppressedAssociations.put
96
                (eClass,
97
                 suppressedAssociation = "true".equals(EcoreUtil.getAnnotation(eClass, EcorePackage.eNS_URI, "association")));
98
              if (Boolean.TRUE.equals(suppressedAssociation))
99
              {
100
                EClass linkEClass = ((EReference)eClass.getEReferences().get(0).getEReferenceType().getEStructuralFeature("value")).getEReferenceType();
101
                int count = 0;
102
                for (EReference eReference : linkEClass.getEReferences())
103
                {
104
                  if (eReference.isTransient())
105
                  {
106
                    featureTable.setNotTransient(eReference);
107
                    if (++count > 2)
108
                    {
109
                      break;
110
                    }
111
                  }
112
                }
113
              }
114
            }
115
          }
116
          if (Boolean.TRUE.equals(suppressedAssociation))
117
          {
118
            for (EObject child : top.eContents())
119
            {
120
              for (EObject link : child.eContents())
121
              {
122
                eClass = link.eClass();
123
                String name = helper.getQName(eClass);
124
                doc.startElement(name);
125
                root = link;
126
                saveElementID(link);
127
              }
128
            }
129
          }
130
          else
131
          {
132
            String name = helper.getQName(eClass);
133
            doc.startElement(name);
134
            root = top;
135
            saveElementID(top);
136
          }
91
        }
137
        }
92
        else
138
        else
93
        {
139
        {
(-)src/org/eclipse/emf/ecore/xmi/impl/SAXXMIHandler.java (-1 / +11 lines)
Lines 19-24 Link Here
19
import java.util.Map;
19
import java.util.Map;
20
20
21
import org.eclipse.emf.ecore.EObject;
21
import org.eclipse.emf.ecore.EObject;
22
import org.eclipse.emf.ecore.EReference;
23
import org.eclipse.emf.ecore.EStructuralFeature;
22
import org.eclipse.emf.ecore.InternalEObject;
24
import org.eclipse.emf.ecore.InternalEObject;
23
import org.eclipse.emf.ecore.util.ExtendedMetaData;
25
import org.eclipse.emf.ecore.util.ExtendedMetaData;
24
import org.eclipse.emf.ecore.xmi.XMLHelper;
26
import org.eclipse.emf.ecore.xmi.XMLHelper;
Lines 70-76 Link Here
70
        }
72
        }
71
        else if (name.equals(hrefAttribute) && (!recordUnknownFeature || types.peek() != UNKNOWN_FEATURE_TYPE || obj.eClass() != anyType))
73
        else if (name.equals(hrefAttribute) && (!recordUnknownFeature || types.peek() != UNKNOWN_FEATURE_TYPE || obj.eClass() != anyType))
72
        {
74
        {
73
          handleProxy(internalEObject, attribs.getValue(i));
75
          EStructuralFeature feature = getFeature(obj, "", hrefAttribute, false);
76
          if (feature == null)
77
          {
78
            handleProxy(internalEObject, attribs.getValue(i));
79
          }
80
          else
81
          {
82
            setValueFromId(obj, (EReference)feature, attribs.getValue(i));
83
          }
74
        }
84
        }
75
        else if (isNamespaceAware)
85
        else if (isNamespaceAware)
76
        {
86
        {
(-)src/org/eclipse/emf/ecore/xmi/impl/XMLHandler.java (-2 / +178 lines)
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)
(-)src/org/eclipse/emf/ecore/xmi/XMLResource.java (+5 lines)
Lines 523-528 Link Here
523
   */
523
   */
524
  String OPTION_ESCAPE_USING_CDATA = "ESCAPE_USING_CDATA";
524
  String OPTION_ESCAPE_USING_CDATA = "ESCAPE_USING_CDATA";
525
525
526
  /**
527
   * @since 2.5
528
   */
529
  String OPTION_SUPPRESS_ASSOCIATION = "SUPPRESS_ASSOCIATION";
530
526
  String HREF = "href";
531
  String HREF = "href";
527
  String NIL = "nil";
532
  String NIL = "nil";
528
  String TYPE = "type";
533
  String TYPE = "type";
(-)src/org/eclipse/emf/ecore/impl/EStructuralFeatureImpl.java (-1 / +53 lines)
Lines 17-22 Link Here
17
package org.eclipse.emf.ecore.impl;
17
package org.eclipse.emf.ecore.impl;
18
18
19
19
20
import java.io.Externalizable;
21
import java.io.IOException;
22
import java.io.ObjectInput;
23
import java.io.ObjectOutput;
24
import java.io.ObjectStreamException;
25
import java.io.Serializable;
20
import java.lang.reflect.InvocationTargetException;
26
import java.lang.reflect.InvocationTargetException;
21
import java.util.Collection;
27
import java.util.Collection;
22
import java.util.List;
28
import java.util.List;
Lines 35-40 Link Here
35
import org.eclipse.emf.ecore.EDataType;
41
import org.eclipse.emf.ecore.EDataType;
36
import org.eclipse.emf.ecore.EFactory;
42
import org.eclipse.emf.ecore.EFactory;
37
import org.eclipse.emf.ecore.EObject;
43
import org.eclipse.emf.ecore.EObject;
44
import org.eclipse.emf.ecore.EPackage;
38
import org.eclipse.emf.ecore.EReference;
45
import org.eclipse.emf.ecore.EReference;
39
import org.eclipse.emf.ecore.EStructuralFeature;
46
import org.eclipse.emf.ecore.EStructuralFeature;
40
import org.eclipse.emf.ecore.EcorePackage;
47
import org.eclipse.emf.ecore.EcorePackage;
Lines 54-59 Link Here
54
import org.eclipse.emf.ecore.util.EcoreUtil;
61
import org.eclipse.emf.ecore.util.EcoreUtil;
55
import org.eclipse.emf.ecore.util.ExtendedMetaData;
62
import org.eclipse.emf.ecore.util.ExtendedMetaData;
56
import org.eclipse.emf.ecore.util.FeatureMap;
63
import org.eclipse.emf.ecore.util.FeatureMap;
64
import org.eclipse.emf.ecore.util.FeatureMapUtil;
57
import org.eclipse.emf.ecore.util.InternalEList;
65
import org.eclipse.emf.ecore.util.InternalEList;
58
import org.eclipse.emf.ecore.xml.type.XMLTypePackage;
66
import org.eclipse.emf.ecore.xml.type.XMLTypePackage;
59
67
Lines 2919-2925 Link Here
2919
    return cachedIsFeatureMap;
2927
    return cachedIsFeatureMap;
2920
  }
2928
  }
2921
  
2929
  
2922
  public static abstract class BasicFeatureMapEntry implements FeatureMap.Entry.Internal
2930
  public static abstract class BasicFeatureMapEntry implements FeatureMap.Entry.Internal, Serializable
2923
  {
2931
  {
2924
    protected final EStructuralFeature.Internal eStructuralFeature;
2932
    protected final EStructuralFeature.Internal eStructuralFeature;
2925
2933
Lines 3000-3005 Link Here
3000
            eStructuralFeature.getName()) + 
3008
            eStructuralFeature.getName()) + 
3001
           "=" + getValue();
3009
           "=" + getValue();
3002
    }
3010
    }
3011
        
3012
    protected static class WriteReplacement implements Externalizable
3013
    {
3014
      FeatureMap.Entry featureMapEntry;
3015
3016
      public WriteReplacement()
3017
      {
3018
        super();
3019
      }
3020
3021
      public WriteReplacement(FeatureMap.Entry featureMapEntry)
3022
      {
3023
        this.featureMapEntry = featureMapEntry;
3024
      }
3025
3026
      public void writeExternal(ObjectOutput out) throws IOException
3027
      {
3028
        EStructuralFeature eStructuralFeature = featureMapEntry.getEStructuralFeature();
3029
        EClass eClass = eStructuralFeature.getEContainingClass();
3030
        out.writeUTF(eClass.getEPackage().getNsURI());
3031
        out.writeUTF(eClass.getName());
3032
        out.writeUTF(eStructuralFeature.getName());
3033
        out.writeObject(featureMapEntry.getValue());
3034
      }
3035
3036
      public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
3037
      {
3038
        EPackage ePackage = EPackage.Registry.INSTANCE.getEPackage(in.readUTF());
3039
        EClass eClass = (EClass)ePackage.getEClassifier(in.readUTF());
3040
        EStructuralFeature eStructuralFeature = eClass.getEStructuralFeature(in.readUTF());
3041
        Object value = in.readObject();
3042
        featureMapEntry = FeatureMapUtil.createRawEntry(eStructuralFeature, value);
3043
      }
3044
3045
      private Object readResolve()
3046
      {
3047
        return featureMapEntry;
3048
      }
3049
    }
3050
3051
    public Object writeReplace() throws ObjectStreamException
3052
    {
3053
      return new WriteReplacement(this);
3054
    }
3003
  }
3055
  }
3004
3056
3005
  public final static class SimpleFeatureMapEntry extends BasicFeatureMapEntry
3057
  public final static class SimpleFeatureMapEntry extends BasicFeatureMapEntry
(-)src/org/eclipse/emf/ecore/util/PathSettingDelegate.java (+115 lines)
Added Link Here
1
/**
2
 * <copyright>
3
 *
4
 * Copyright (c) 2008 IBM Corporation and others.
5
 * All rights reserved.   This program and the accompanying materials
6
 * are made available under the terms of the Eclipse Public License v1.0
7
 * which accompanies this distribution, and is available at
8
 * http://www.eclipse.org/legal/epl-v10.html
9
 * 
10
 * Contributors: 
11
 *   IBM - Initial API and implementation
12
 *
13
 * </copyright>
14
 *
15
 * $Id$
16
 */
17
package org.eclipse.emf.ecore.util;
18
19
20
import java.util.ArrayList;
21
import java.util.List;
22
23
import org.eclipse.emf.common.util.URI;
24
import org.eclipse.emf.ecore.EClass;
25
import org.eclipse.emf.ecore.EObject;
26
import org.eclipse.emf.ecore.EStructuralFeature;
27
import org.eclipse.emf.ecore.EcorePackage;
28
import org.eclipse.emf.ecore.InternalEObject;
29
30
public class PathSettingDelegate extends BasicSettingDelegate.Stateless
31
{
32
  protected EStructuralFeature[] path;
33
34
  public PathSettingDelegate(EStructuralFeature eStructuralFeature)
35
  {
36
    super(eStructuralFeature);
37
    String namePath = URI.createURI(eStructuralFeature.getEAnnotation(EcorePackage.eNS_URI).getDetails().get("settingDelegate")).fragment();
38
    String[] segments = namePath.split("/");
39
    path = new EStructuralFeature[segments.length];
40
    for (int i = 0; i < segments.length; ++i)
41
    {
42
      String featureName = segments[i];
43
      EClass eClass = i == 0 ? eStructuralFeature.getEContainingClass() : (EClass)path[i - 1].getEType();
44
      path[i] = eClass.getEStructuralFeature(featureName);
45
    }
46
  }
47
48
  public PathSettingDelegate(EStructuralFeature eStructuralFeature, EStructuralFeature[] path)
49
  {
50
    super(eStructuralFeature);
51
    this.path = path;
52
  }
53
54
  @Override
55
  protected Object get(InternalEObject owner, boolean resolve, boolean coreType)
56
  {
57
    InternalEObject eObject = owner;
58
    for (int i = 0, limit = path.length - 1; i < limit; ++i)
59
    {
60
      EStructuralFeature feature = path[i];
61
      if (feature.isMany())
62
      {
63
        ArrayList<Object> result = new ArrayList<Object>();
64
        @SuppressWarnings("unchecked")
65
        List<EObject> elements = (List<EObject>)eObject.eGet(feature, resolve, coreType);
66
        for (EObject element : elements)
67
        {
68
          Object value = element.eGet(path[i + 1]);
69
          result.add(value);
70
        }
71
        return
72
          new EcoreEList.UnmodifiableEList.FastCompare<Object>
73
            (owner, eStructuralFeature, result.size(), result.toArray());
74
      }
75
      else
76
      {
77
        eObject = (InternalEObject)eObject.eGet(feature);
78
      }
79
    }
80
    return eObject.eGet(path[path.length - 1], resolve, coreType);
81
  }
82
83
  @Override
84
  protected boolean isSet(InternalEObject owner)
85
  {
86
    InternalEObject eObject = owner;
87
    for (int i = 0, limit = path.length - 1; i < limit; ++i)
88
    {
89
      eObject = (InternalEObject)eObject.eGet(path[i]);
90
    }
91
    return eObject.eIsSet(path[path.length - 1]);
92
  }
93
94
  @Override
95
  protected void set(InternalEObject owner, Object newValue)
96
  {
97
    InternalEObject eObject = owner;
98
    for (int i = 0, limit = path.length - 1; i < limit; ++i)
99
    {
100
      eObject = (InternalEObject)eObject.eGet(path[i]);
101
    }
102
    eObject.eSet(path[path.length - 1], newValue);
103
  }
104
105
  @Override
106
  protected void unset(InternalEObject owner)
107
  {
108
    InternalEObject eObject = owner;
109
    for (int i = 0, limit = path.length - 1; i < limit; ++i)
110
    {
111
      eObject = (InternalEObject)eObject.eGet(path[i]);
112
    }
113
    eObject.eUnset(path[path.length - 1]);
114
  }
115
}

Return to bug 105920