1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.oodt.xmlps.mapping;
19
20
21 import java.util.Arrays;
22 import java.util.List;
23 import java.util.Map;
24 import java.util.TreeMap;
25
26
27
28
29
30
31
32
33
34
35 public class Mapping {
36
37 private final Map<String, MappingField> fields;
38
39 private final DatabaseTableGroup tables;
40
41 private String id;
42
43 private String name;
44
45
46
47
48 public Mapping() {
49 this.fields = new TreeMap<String, MappingField>();
50 this.tables = new DatabaseTableGroup();
51 }
52
53 public Mapping(Map<String, MappingField> fields, DatabaseTableGroup tables,
54 String id, String name) {
55 super();
56 this.fields = fields;
57 this.id = id;
58 this.name = name;
59 this.tables = tables;
60 }
61
62 public void addField(String fldName, MappingField field) {
63 this.fields.put(fldName, field);
64 }
65
66 public MappingField getFieldByLocalName(String localName) {
67 if (this.fields == null
68 || (this.fields != null && this.fields.keySet() == null)
69 || (this.fields != null && this.fields.keySet() != null && this.fields
70 .keySet().size() == 0)) {
71 return null;
72 }
73
74 for (MappingField fld : this.fields.values()) {
75 if (fld.getLocalName().equals(localName)) {
76 return fld;
77 }
78 }
79
80 return null;
81 }
82
83 public MappingField getFieldByName(String name) {
84 return this.fields.get(name);
85 }
86
87 public boolean constantField(String localName) {
88 MappingField fld = getFieldByLocalName(localName);
89
90 if (fld == null) {
91 return true;
92 }
93
94 if (fld.getType() == FieldType.CONSTANT) {
95 return true;
96 } else
97 return false;
98 }
99
100 public int getNumFields() {
101 return this.fields.keySet().size();
102 }
103
104 public void addTable(String tblName, DatabaseTable tbl) {
105 this.tables.addTable(tblName, tbl);
106 }
107
108 public DatabaseTable getTableByName(String name) {
109 return this.tables.getTableByName(name);
110 }
111
112 public int getNumTables() {
113 return this.tables.getNumTables();
114 }
115
116 public List<String> getTableNames() {
117 return this.tables.getTableNames();
118 }
119
120 public List<String> getFieldNames() {
121 return Arrays.asList(this.fields.keySet().toArray(new String[] { "" }));
122 }
123
124
125
126
127 public String getId() {
128 return id;
129 }
130
131
132
133
134
135 public void setId(String id) {
136 this.id = id;
137 }
138
139
140
141
142 public String getName() {
143 return name;
144 }
145
146
147
148
149
150 public void setName(String name) {
151 this.name = name;
152 }
153
154
155
156
157 public String getDefaultTable() {
158 return this.tables.getDefaultTable();
159 }
160
161
162
163
164
165 public void setDefaultTable(String defaultTable) {
166 this.tables.setDefaultTable(defaultTable);
167 }
168
169 }