Skip to main content
summaryrefslogtreecommitdiffstats
blob: 186d4223760bd60b6f98964d600b54963a31f9b6 (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
/*
 * Copyright (c) 2004 - 2012 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:
 *    Simon McDuff - initial API and implementation
 *    Ibrahim Sallam - code refactoring for CDO 3.0
 */
package org.eclipse.emf.cdo.server.internal.objectivity.utils;

import org.eclipse.emf.cdo.common.id.CDOID;
import org.eclipse.emf.cdo.server.internal.objectivity.db.ObjyObject;

import com.objy.as.app.Class_Object;
import com.objy.db.app.ooId;
import com.objy.db.app.ooObj;

/**
 * Originally EOOUtil TBD: verify if we really need this class...
 * 
 * @author ibrahim
 */
public class TypeConvert
{

  static public ooId toOoId(Object target)
  {
    if (target == null)
    {
      return null;
    }
    if (target instanceof CDOID)
    {
      if ((CDOID)target == CDOID.NULL)
      {
        return null;
      }

      return OBJYCDOIDUtil.getooId((CDOID)target);
    }
    if (target instanceof ooId)
    {
      return (ooId)target;
    }
    else if (target instanceof ObjyObject)
    {
      return ((ObjyObject)target).ooId();
    }
    else if (target instanceof ooObj)
    {
      return ((ooObj)target).getOid();
    }

    throw new IllegalArgumentException(target.toString());
  }

  static public ooObj toOoObj(Object target)
  {
    if (target instanceof ObjyObject)
    {
      target = ((ObjyObject)target).ooId();
    }
    if (target instanceof ooId)
    {
      return ooObj.create_ooObj((ooId)target);
    }
    throw new IllegalArgumentException(target.toString());
  }

  static public Class_Object toClassObject(Object target)
  {
    if (target == null)
    {
      return null;
    }
    if (target instanceof Class_Object)
    {
      return (Class_Object)target;
    }
    else if (target instanceof ooObj)
    {
      return new Class_Object(target);
    }
    else if (target instanceof ooId)
    {
      return Class_Object.class_object_from_oid((ooId)target);
    }

    throw new IllegalArgumentException("Not supported " + target);

  }

  static public ObjyObject toObjyObject(Object target)
  {
    if (target == null)
    {
      return null;
    }

    if (target instanceof ObjyObject)
    {
      return (ObjyObject)target;
    }
    else if (target instanceof Class_Object)
    {
      throw new IllegalArgumentException("Not supported " + target);
    }
    else if (target instanceof ooId)
    {
      throw new IllegalArgumentException("Not supported " + target);
    }
    return null;
  }

}

Back to the top