Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 5046e7f243394153ebaf5a2d7093677110dd32a5 (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
/*
 * 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:
 *    Ibrahim Sallam - initial API and implementation
 */
package org.eclipse.emf.cdo.server.internal.objectivity.db;

import com.objy.as.app.Class_Position;
import com.objy.as.app.d_Attribute;
import com.objy.as.app.d_Class;

import java.util.HashMap;

/**
 * Wrapper around the AS class to be able to cache attributes.
 * 
 * @author ibrahim
 */
public class ObjyClass
{

  protected d_Class asClass;

  protected String asClassName;

  protected HashMap<String, d_Attribute> attributeMap = new HashMap<String, d_Attribute>();

  protected HashMap<String, Class_Position> classPositionMap = new HashMap<String, Class_Position>();

  public ObjyClass(d_Class asClass/* , EClass eClass */)
  {
    this.asClass = asClass;
    if (asClass.namespace_name() != null)
    {
      asClassName = asClass.namespace_name() + ":" + asClass.name();
    }
    else
    {
      asClassName = asClass.name();
    }
  }

  public d_Attribute resolve_attribute(String attribute_name)
  {
    d_Attribute attr = attributeMap.get(attribute_name);
    if (attr == null)
    {
      attr = asClass.resolve_attribute(attribute_name);
      // we might get (attr == null) if the attribute is from a base class.
      // so we'll try to get the attribute through the position.
      if (attr == null)
      {
        Class_Position position = resolve_position(attribute_name);
        if (position != null)
        {
          attr = asClass.attribute_at_position(position);
        }
      }
      attributeMap.put(attribute_name, attr);
    }
    return attr;
  }

  public Class_Position resolve_position(String attribute_name)
  {
    Class_Position attr = classPositionMap.get(attribute_name);
    if (attr == null)
    {
      attr = asClass.position_in_class(attribute_name);
      classPositionMap.put(attribute_name, attr);
    }
    return attr;
  }

  public d_Class getASClass()
  {
    return asClass;
  }

  public String getASClassName()
  {
    return asClassName;
  }

  // public List<Class_Position> getListOfRefAttributes()
  // {
  // List<Class_Position> positions = new ArrayList<Class_Position>();
  //
  // System.out.println(">>> Class: " + asClassName);
  //
  // //
  // @SuppressWarnings("rawtypes")
  // Iterator itr = asClass.attributes_plus_inherited();
  // while (itr.hasNext())
  // {
  // d_Attribute attribute = (d_Attribute)itr.next();
  // if (attribute.is_type() && attribute.type_of() instanceof d_Ref_Type)
  // {
  // d_Class dClass = attribute.class_type_of();
  // if (dClass.name().equals(ObjyFeatureMapArrayList.ClassName))
  // {
  // // we'll need to copy this one.
  // positions.add(resolve_position(attribute.name()));
  // System.out.println("\t attr: " + attribute.name());
  // }
  // else if (dClass.name().equals(ObjyArrayListString.ClassName))
  // {
  // // we'll need to copy this one.
  // positions.add(resolve_position(attribute.name()));
  // System.out.println("\t attr: " + attribute.name());
  // }
  // else if (dClass.name().equals(ObjyArrayListId.className))
  // {
  // // we'll need to copy this one.
  // positions.add(resolve_position(attribute.name()));
  // System.out.println("\t attr: " + attribute.name());
  // }
  // else if (dClass.name().equals(ObjyProxy.className))
  // {
  // // we'll need to copy this one.
  // positions.add(resolve_position(attribute.name()));
  // System.out.println("\t attr: " + attribute.name());
  // }
  // }
  // }
  //
  // return positions;
  // }

}

Back to the top