Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 1d2150bf6478302d6be5e78c846ae83f6cc58a97 (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
/***************************************************************************
 * Copyright (c) 2004, 2005, 2006 Eike Stepper, Fuggerstr. 39, 10777 Berlin, Germany.
 * 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
 **************************************************************************/
package org.eclipse.emf.cdo.server.impl;


import org.eclipse.emf.cdo.server.AttributeInfo;
import org.eclipse.emf.cdo.server.ClassInfo;
import org.eclipse.emf.cdo.server.PackageInfo;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;


public class ClassInfoImpl implements ClassInfo
{
  protected int cid;

  protected String name;

  protected String parentName;

  protected String tableName;

  protected PackageInfo packageInfo;

  protected List attributeInfos = new ArrayList();

  private ClassInfo cachedParent;

  private String cachedColumnNames;

  public ClassInfoImpl(int cid, String name, String parentName, String tableName,
      PackageInfo packageInfo)
  {
    this.cid = cid;
    this.cid = cid;
    this.name = name;
    this.parentName = parentName;
    this.tableName = tableName;
    this.packageInfo = packageInfo;
  }

  public int getCID()
  {
    return cid;
  }

  public String getName()
  {
    return name;
  }

  public String getParentName()
  {
    return parentName;
  }

  public String getTableName()
  {
    return tableName;
  }

  public PackageInfo getPackageInfo()
  {
    return packageInfo;
  }

  public AttributeInfo addAttribute(String name, int featureID, int dataType, String columnName,
      int columnType)
  {
    AttributeInfo attributeInfo = new AttributeInfoImpl(name, featureID, dataType, columnName,
        columnType);
    attributeInfos.add(attributeInfo);
    return attributeInfo;
  }

  public AttributeInfo getAttributeInfo(int feature)
  {
    for (Iterator iter = attributeInfos.iterator(); iter.hasNext();)
    {
      AttributeInfo attributeInfo = (AttributeInfo) iter.next();

      if (attributeInfo.getFeatureID() == feature)
      {
        return attributeInfo;
      }
    }

    ClassInfo parentInfo = getParent();
    if (parentInfo != null)
    {
      return parentInfo.getAttributeInfo(feature);
    }

    return null;
  }

  public AttributeInfo[] getAttributeInfos()
  {
    return (AttributeInfo[]) attributeInfos.toArray(new AttributeInfo[attributeInfos.size()]);
  }

  public ClassInfo getParent()
  {
    if (cachedParent == null && parentName != null)
    {
      cachedParent = packageInfo.getPackageManager().getClassInfo(parentName);
    }

    return cachedParent;
  }

  public String getColumnNames()
  {
    if (cachedColumnNames == null)
    {
      StringBuffer buffer = new StringBuffer();
      boolean first = true;

      for (Iterator iter = attributeInfos.iterator(); iter.hasNext();)
      {
        AttributeInfo attributeInfo = (AttributeInfo) iter.next();

        if (first)
        {
          first = false;
        }
        else
        {
          buffer.append(", ");
        }

        buffer.append(attributeInfo.getColumnName());
      }

      cachedColumnNames = buffer.toString();
    }

    return cachedColumnNames;
  }
}

Back to the top