Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 5ce24b2bd4e259ab3813953c01933a6758487e25 (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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
/*
 * Copyright (c) 2008-2014 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.
 * @apiviz.landmark
 * @apiviz.has {@link CDOID.Type}
 */
public interface CDOID extends Comparable<CDOID>, Serializable
{
  public static final CDOID NULL = org.eclipse.emf.cdo.internal.common.id.CDOIDNullImpl.INSTANCE;

  /**
   * @since 4.6
   */
  public static final CDOID NIL = org.eclipse.emf.cdo.internal.common.id.CDOIDNilImpl.INSTANCE;

  public Type getType();

  public boolean isNull();

  /**
   * @since 4.6
   */
  public boolean isNil();

  public boolean isObject();

  public boolean isTemporary();

  /**
   * @since 3.0
   * @deprecated
   */
  @Deprecated
  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'), //

    /**
     * @since 4.6
     */
    NIL('I'), //

    OBJECT(' '), // Superseded 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 final char FRAGMENT_PATH_PREFIX = '/';

    private static Enum<?>[] chars;

    private char id;

    private Type(char id)
    {
      if (id == FRAGMENT_PATH_PREFIX)
      {
        // @see CDOResourceImpl.getEObject(String uriFragment)
        throw new IllegalArgumentException("id=" + 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)
    {
      try
      {
        return chars[id];
      }
      catch (ArrayIndexOutOfBoundsException ex)
      {
        return null;
      }
    }

    /**
     * @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