Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 356dfd775dc185482253f5e516a95bf91205364b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/*
 * Copyright (c) 2010-2012 Eike Stepper (Loehne, Germany) and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *    Eike Stepper - initial API and implementation
 */
package org.eclipse.emf.cdo.server.internal.objectivity;

import org.eclipse.emf.cdo.common.revision.delta.CDOAddFeatureDelta;
import org.eclipse.emf.cdo.common.revision.delta.CDOClearFeatureDelta;
import org.eclipse.emf.cdo.common.revision.delta.CDOContainerFeatureDelta;
import org.eclipse.emf.cdo.common.revision.delta.CDOFeatureDelta;
import org.eclipse.emf.cdo.common.revision.delta.CDOFeatureDeltaVisitor;
import org.eclipse.emf.cdo.common.revision.delta.CDOListFeatureDelta;
import org.eclipse.emf.cdo.common.revision.delta.CDOMoveFeatureDelta;
import org.eclipse.emf.cdo.common.revision.delta.CDORemoveFeatureDelta;
import org.eclipse.emf.cdo.common.revision.delta.CDOSetFeatureDelta;
import org.eclipse.emf.cdo.common.revision.delta.CDOUnsetFeatureDelta;
import org.eclipse.emf.cdo.server.internal.objectivity.db.ObjyObject;

import org.eclipse.emf.ecore.EStructuralFeature;

/**
 * @author Simon McDuff
 */
public class ObjectivityFeatureDeltaWriter implements CDOFeatureDeltaVisitor
{
  private ObjyObject objyObject = null;

  private EStructuralFeature eFeature = null;

  public ObjectivityFeatureDeltaWriter(ObjyObject objyObject)
  {
    this.objyObject = objyObject;
  }

  public void nextFeature()
  {
    eFeature = null;
  }

  protected void fillStructuralFeature(CDOFeatureDelta delta)
  {
    eFeature = delta.getFeature();
  }

  public void visit(CDOMoveFeatureDelta delta)
  {
    fillStructuralFeature(delta);
    objyObject.move(eFeature, delta.getNewPosition(), delta.getOldPosition());

  }

  public void visit(CDOAddFeatureDelta delta)
  {
    fillStructuralFeature(delta);
    objyObject.add(eFeature, delta.getIndex(), delta.getValue());
  }

  public void visit(CDORemoveFeatureDelta delta)
  {
    fillStructuralFeature(delta);
    objyObject.remove(eFeature, delta.getIndex());
  }

  public void visit(CDOSetFeatureDelta delta)
  {
    fillStructuralFeature(delta);
    Object value = delta.getValue();
    /**
     * TODO - verify if this is needed for 2.x if (delta.getType()== CDOType.CUSTOM) { value =
     * EcoreUtil.createFromString((EDataType)eFeature.getEType(), (String)value); }
     */
    objyObject.set(eFeature, delta.getIndex(), value);
  }

  public void visit(CDOUnsetFeatureDelta delta)
  {
    fillStructuralFeature(delta);
    objyObject.unset(eFeature);
  }

  public void visit(CDOListFeatureDelta deltas)
  {
    for (CDOFeatureDelta delta : deltas.getListChanges())
    {
      delta.accept(this);
    }
  }

  public void visit(CDOClearFeatureDelta delta)
  {
    fillStructuralFeature(delta);
    objyObject.clear(eFeature);

  }

  public void visit(CDOContainerFeatureDelta delta)
  {
    objyObject.setEContainer(delta.getContainerID());
    objyObject.setEContainingFeature(delta.getContainerFeatureID());
    objyObject.setEResource(delta.getResourceID());

  }
}

Back to the top