Skip to main content
summaryrefslogtreecommitdiffstats
blob: 3e02bde70e341e27bb043bc4e565a6c63e34082e (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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
/**
 * Copyright (c) 2004 - 2011 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 - bug 226778
 *    Simon McDuff - bug 213402
 */
package org.eclipse.emf.cdo.common.id;

import org.eclipse.emf.cdo.common.CDOCommonRepository;

import org.eclipse.net4j.util.ImplementationError;

import java.io.Serializable;
import java.lang.reflect.Array;

/**
 * Identifies CDO objects uniquely in a CDO {@link CDOCommonRepository repository}.
 * 
 * @author Eike Stepper
 * @noextend This interface is not intended to be extended by clients.
 * @noimplement This interface is not intended to be implemented by clients.
 */
public interface CDOID extends Serializable, Comparable<CDOID>
{
  public static final CDOID NULL = org.eclipse.emf.cdo.internal.common.id.CDOIDNullImpl.INSTANCE;

  public Type getType();

  public boolean isNull();

  public boolean isObject();

  public boolean isTemporary();

  /**
   * @since 3.0
   */
  public boolean isDangling();

  /**
   * @since 2.0
   */
  public boolean isExternal();

  /**
   * @since 2.0
   */
  public String toURIFragment();

  /**
   * Enumerates the possible types of CDO {@link CDOID IDs}.
   * 
   * @author Eike Stepper
   */
  public enum Type
  {
    NULL('N'), //
    OBJECT(' '), // Superceded by ObjectType.getID()

    /**
     * @since 2.0
     */
    EXTERNAL_OBJECT('E'),

    /**
     * @since 3.0
     */
    DANGLING_OBJECT('D'),

    /**
     * @since 2.0
     */
    EXTERNAL_TEMP_OBJECT('e'), //
    TEMP_OBJECT('t');

    private static Enum<?>[] chars;

    private char id;

    private Type(char id)
    {
      registerChar(id, this);
      this.id = id;
    }

    private static void registerChar(char id, Enum<?> literal)
    {
      if (chars == null)
      {
        chars = (Enum<?>[])Array.newInstance(Enum.class, id + 1);
      }
      else if (chars.length < id)
      {
        Enum<?>[] newChars = (Enum<?>[])Array.newInstance(Enum.class, id + 1);
        System.arraycopy(chars, 0, newChars, 0, chars.length);
        chars = newChars;
      }

      if (chars[id] != null)
      {
        throw new ImplementationError("Duplicate id: " + id);
      }

      chars[id] = literal;
    }

    /**
     * @since 4.0
     */
    public static Enum<?> getLiteral(char id)
    {
      return chars[id];
    }

    /**
     * @since 4.0
     */
    public char getID()
    {
      return id;
    }
  }

  /**
   * Enumerates the possible <b>sub</b> types of CDO {@link CDOID IDs} with the main type {@link Type#OBJECT OBJECT}.
   * 
   * @author Eike Stepper
   * @since 3.0
   */
  public enum ObjectType
  {
    LONG('L'), //
    STRING('S'), //
    LONG_WITH_CLASSIFIER('l'), //
    STRING_WITH_CLASSIFIER('s'), //
    UUID('U');

    private char id;

    private ObjectType(char id)
    {
      Type.registerChar(id, this);
      this.id = id;
    }

    /**
     * @since 4.0
     */
    public char getID()
    {
      return id;
    }
  }
}

Back to the top