Skip to main content
summaryrefslogtreecommitdiffstats
blob: 7764255db44c9287cbf42f50a66cd09506ae87ea (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
/*******************************************************************************
 * Copyright (c) 2004, 2005, 2006 Eike Stepper, Sympedia Methods and Tools.
 * 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.protocol;


import org.eclipse.net4j.core.impl.AbstractIndicationWithResponse;

import org.eclipse.emf.cdo.core.CdoProtocol;
import org.eclipse.emf.cdo.server.AttributeInfo;
import org.eclipse.emf.cdo.server.CdoServerProtocol;
import org.eclipse.emf.cdo.server.ClassInfo;
import org.eclipse.emf.cdo.server.Mapper;
import org.eclipse.emf.cdo.server.PackageInfo;

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


public class DescribePackageIndication extends AbstractIndicationWithResponse
{
  private List infos;

  public short getSignalId()
  {
    return CdoProtocol.DESCRIBE_PACKAGE;
  }

  public void indicate()
  {
    int pid = getMapper().getNextPid();
    String packageName = receiveString();
    if (isDebugEnabled()) debug("Described package " + packageName);

    PackageInfo packageInfo = getMapper().getPackageManager().addPackage(pid, packageName);
    getMapper().insertPackage(packageInfo);

    infos = receiveClasses(packageInfo);
    getMapper().createAttributeTables(packageInfo);
  }

  public void respond()
  {
    transmitInt(infos.size());

    for (Iterator iter = infos.iterator(); iter.hasNext();)
    {
      ClassInfo classInfo = (ClassInfo) iter.next();
      if (isDebugEnabled())
        debug("Responding class " + classInfo.getName() + " = " + classInfo.getCid());

      transmitInt(classInfo.getCid());
      transmitString(classInfo.getName());
    }
  }

  private List receiveClasses(PackageInfo packageInfo)
  {
    List result = new ArrayList();
    int count = receiveInt();

    for (int i = 0; i < count; i++)
    {
      int cid = getMapper().getNextCid();
      String name = receiveString();
      String parentName = receiveString();
      String tableName = receiveString();
      if (isDebugEnabled()) debug("Described class " + name);

      ClassInfo classInfo = packageInfo.addClass(cid, name, parentName, tableName);
      getMapper().insertClass(classInfo);
      receiveAttributes(classInfo);

      result.add(classInfo);
    }

    return result;
  }

  private void receiveAttributes(ClassInfo classInfo)
  {
    int count = receiveInt();
    for (int i = 0; i < count; i++)
    {
      String name = receiveString();
      int featureId = receiveInt();
      int dataType = receiveInt();
      String columnName = receiveString();
      int columnType = receiveInt();
      if (isDebugEnabled()) debug("Described attribute " + name);

      AttributeInfo attributeInfo = classInfo.addAttribute(name, featureId, dataType, columnName,
          columnType);
      getMapper().insertAttribute(attributeInfo, classInfo.getCid());
    }
  }

  private Mapper getMapper()
  {
    return ((CdoServerProtocol) getProtocol()).getMapper();
  }
}

Back to the top