Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 8003b091252fc9233d37508693c230f6dc49ed9f (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
/***************************************************************************
 * Copyright (c) 2004 - 2009 Eike Stepper (Berlin, 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
 *    Simon McDuff - http://bugs.eclipse.org/201266
 *    Simon McDuff - http://bugs.eclipse.org/212958
 *    Simon McDuff - http://bugs.eclipse.org/213402
 **************************************************************************/
package org.eclipse.emf.cdo.internal.common.revision;

import org.eclipse.emf.cdo.common.id.CDOID;
import org.eclipse.emf.cdo.common.io.CDODataInput;
import org.eclipse.emf.cdo.common.model.CDOClass;
import org.eclipse.emf.cdo.common.model.CDOFeature;
import org.eclipse.emf.cdo.common.model.CDOType;
import org.eclipse.emf.cdo.common.revision.CDORevision;
import org.eclipse.emf.cdo.spi.common.revision.AbstractCDORevision;
import org.eclipse.emf.cdo.spi.common.revision.InternalCDOList;

import java.io.IOException;

/**
 * @author Eike Stepper
 */
public class CDORevisionImpl extends AbstractCDORevision
{
  private Object[] values;

  public CDORevisionImpl(CDOClass cdoClass, CDOID id)
  {
    super(cdoClass, id);
  }

  public CDORevisionImpl(CDODataInput in) throws IOException
  {
    super(in);
  }

  public CDORevisionImpl(CDORevisionImpl source)
  {
    super(source);
    CDOFeature[] features = getCDOClass().getAllFeatures();
    initValues(features.length);
    for (int i = 0; i < features.length; i++)
    {
      CDOFeature feature = features[i];
      CDOType type = feature.getType();
      if (feature.isMany())
      {
        InternalCDOList sourceList = (InternalCDOList)source.values[i];
        if (sourceList != null)
        {
          setValue(i, sourceList.clone(type));
        }
      }
      else
      {
        setValue(i, type.copyValue(source.values[i]));
      }
    }
  }

  public CDORevision copy()
  {
    return new CDORevisionImpl(this);
  }

  @Override
  protected void initValues(int size)
  {
    values = new Object[size];
  }

  @Override
  protected Object getValue(int i)
  {
    return values[i];
  }

  @Override
  protected void setValue(int i, Object value)
  {
    values[i] = value;
  }
}

Back to the top