blob: 3bd2060e6ac4a8d80a6301d6c1999353016c2ade (
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
|
/*******************************************************************************
* Copyright (c) 2000, 2005 IBM Corporation 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:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.wst.ws.internal.datamodel;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Vector;
public class BasicModel implements Model
{
// Copyright
public static final String copyright = "(c) Copyright IBM Corporation 2000, 2002.";
private String fName;
private Hashtable fElements;
private Element fRoot;
//This is used by the MUID
private int fUniqueNumberCounter;
public BasicModel ( String name )
{
fName = name;
fElements = new Hashtable();
fRoot = null;
fUniqueNumberCounter = 0;
}
public void setName ( String name )
{
fName = name;
}
public String getName ()
{
return fName;
}
/*
* simple counter that increments each call
*/
public int getUniqueNumber()
{
fUniqueNumberCounter++;
return fUniqueNumberCounter;
}
/*
* This will use a unique number and append it to the end of the name
* @param String name of the element
* @return String MUID
*/
public String makeMUID(String name)
{
String num = String.valueOf(getUniqueNumber());
String muid = name + num;
return muid;
}
public boolean setRootElement ( Element root )
{
if (root.getModel() == null)
addElement(root);
else if (root.getModel() != this)
return false;
fRoot = root;
return true;
}
public Element getRootElement ()
{
if (fRoot == null) fRoot = getFirstElement();
return fRoot;
}
/**
* Get the elements that have this name
* @param String name the name of the element
* @return Vector a vector of elements that have this name
* These elements may be of different types
**/
public Vector getElementsByName(String name)
{
Vector vector = new Vector();
Enumeration e = fElements.keys();
while (e.hasMoreElements()){
Element element = (Element)e.nextElement();
if (element.getName().equals(name)) vector.addElement(element);
}
return vector;
}
public boolean addElement ( Element element )
{
if (element.getModel() != null) return false;
fElements.put(element,element);
return true;
}
public boolean removeElement ( Element element )
{
if (element.getModel() != this) return false;
element.disconnectAll();
if (fRoot == element) fRoot = null;
return (fElements.remove(element) == element);
}
public Enumeration getElements ()
{
return fElements.elements();
}
public int getNumberOfElements ()
{
return fElements.size();
}
public boolean containsElement ( Element element )
{
return fElements.contains(element);
}
private Element getFirstElement ()
{
Enumeration e = getElements();
return (e.hasMoreElements() ? (Element)e.nextElement() : null);
}
public String toString ()
{
return getName();
}
}
|