svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.xml2db / org.gvsig.xml2db.lib / org.gvsig.xml2db.lib.impl / src / main / java / org / gvsig / xml2db / lib / impl / xmlinfo / XMLInfoImpl.java @ 47486
History | View | Annotate | Download (4.58 KB)
1 |
package org.gvsig.xml2db.lib.impl.xmlinfo; |
---|---|
2 |
|
3 |
import java.nio.charset.Charset; |
4 |
import java.util.ArrayList; |
5 |
import java.util.Collection; |
6 |
import java.util.Iterator; |
7 |
import java.util.LinkedHashMap; |
8 |
import java.util.List; |
9 |
import java.util.Locale; |
10 |
import java.util.Map; |
11 |
import org.apache.commons.lang3.StringUtils; |
12 |
import org.cresques.cts.IProjection; |
13 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
14 |
import org.gvsig.fmap.geom.DataTypes; |
15 |
import org.gvsig.tools.util.CompareUtils; |
16 |
import org.gvsig.xml2db.lib.api.xmlinfo.XMLInfo; |
17 |
import org.gvsig.xml2db.lib.api.xmlinfo.XMLTableInfo; |
18 |
|
19 |
/**
|
20 |
*
|
21 |
* @author jjdelcerro
|
22 |
*/
|
23 |
public class XMLInfoImpl implements XMLInfo { |
24 |
|
25 |
private final Map<String,XMLAttributeInfoImpl> tags; |
26 |
private final Map<String,XMLTableInfo> tables; |
27 |
private IProjection srid;
|
28 |
private long countLines; |
29 |
private String repositoryID; |
30 |
private Charset charset; |
31 |
private Locale locale; |
32 |
private String tablePrefix; |
33 |
|
34 |
public XMLInfoImpl() {
|
35 |
this.tags = new LinkedHashMap<>(); |
36 |
this.tables = new LinkedHashMap<>(); |
37 |
this.countLines = -1; |
38 |
} |
39 |
|
40 |
@Override
|
41 |
public IProjection getSrid() {
|
42 |
return this.srid; |
43 |
} |
44 |
|
45 |
@Override
|
46 |
public void setSrid(IProjection srid) { |
47 |
this.srid = srid;
|
48 |
} |
49 |
|
50 |
public XMLAttributeInfoImpl getTag(String path) { |
51 |
return this.tags.get(path); |
52 |
} |
53 |
|
54 |
public Collection<String> getTagsPaths() { |
55 |
return this.tags.keySet(); |
56 |
} |
57 |
|
58 |
public void addTag(XMLAttributeInfoImpl info) { |
59 |
tags.put(info.getPath(), info); |
60 |
} |
61 |
|
62 |
public XMLAttributeInfoImpl getTagInfo(String path) { |
63 |
return this.tags.get(path); |
64 |
} |
65 |
|
66 |
public void addTable(XMLTableInfoImpl tableInfo) { |
67 |
tables.put(tableInfo.getPath(), tableInfo); |
68 |
} |
69 |
|
70 |
public XMLTableInfoImpl getTableByPath(String path) { |
71 |
return (XMLTableInfoImpl) this.tables.get(path); |
72 |
|
73 |
} |
74 |
|
75 |
public boolean existsTableByPath(String path) { |
76 |
return this.tables.containsKey(path); |
77 |
} |
78 |
|
79 |
@Override
|
80 |
public int size() { |
81 |
return this.tables.size(); |
82 |
} |
83 |
|
84 |
@Override
|
85 |
public XMLTableInfo get(String name) { |
86 |
for (XMLTableInfo tableInfo : this) { |
87 |
if( StringUtils.equals(name, tableInfo.getName()) ) {
|
88 |
return tableInfo;
|
89 |
} |
90 |
} |
91 |
for (XMLTableInfo tableInfo : this) { |
92 |
if( StringUtils.equals(name, this.getNameWithPrefix(tableInfo.getName())) ) { |
93 |
return tableInfo;
|
94 |
} |
95 |
} |
96 |
return null; |
97 |
} |
98 |
|
99 |
// public XMLTableInfo getByOriginalName(String name) {
|
100 |
// for (XMLTableInfo tableInfo : this) {
|
101 |
// if( StringUtils.equals(name, ((XMLTableInfoImpl)tableInfo).getOriginalName()) ) {
|
102 |
// return tableInfo;
|
103 |
// }
|
104 |
// }
|
105 |
// return null;
|
106 |
// }
|
107 |
//
|
108 |
@Override
|
109 |
public List<String> getKeys() { |
110 |
List<String> names = new ArrayList<>(this.tables.keySet()); |
111 |
names.sort(CompareUtils.EQUALS_IGNORECASE_COMPARATOR); |
112 |
return names;
|
113 |
} |
114 |
|
115 |
@Override
|
116 |
public Iterator<XMLTableInfo> iterator() { |
117 |
return this.tables.values().iterator(); |
118 |
} |
119 |
|
120 |
@Override
|
121 |
public boolean isEmpty() { |
122 |
return this.tables.isEmpty(); |
123 |
} |
124 |
|
125 |
public void setCountLines(long countlines) { |
126 |
this.countLines = countlines;
|
127 |
} |
128 |
|
129 |
public long getCountLines() { |
130 |
return this.countLines; |
131 |
} |
132 |
|
133 |
@Override
|
134 |
public String getRepositoryID() { |
135 |
return this.repositoryID; |
136 |
} |
137 |
|
138 |
@Override
|
139 |
public void setRepositoryID(String id) { |
140 |
this.repositoryID = id;
|
141 |
} |
142 |
|
143 |
@Override
|
144 |
public Charset getCharset() { |
145 |
return this.charset; |
146 |
} |
147 |
|
148 |
public void setCharset(Charset charset) { |
149 |
this.charset = charset;
|
150 |
} |
151 |
|
152 |
@Override
|
153 |
public Locale getLocale() { |
154 |
return this.locale; |
155 |
} |
156 |
|
157 |
public void setLocale(Locale locale) { |
158 |
this.locale = locale;
|
159 |
} |
160 |
|
161 |
@Override
|
162 |
public boolean hasGeometries() { |
163 |
for (XMLTableInfo tableInfo : this) { |
164 |
for (FeatureAttributeDescriptor ft : tableInfo.getFeatureType()) {
|
165 |
if( ft.getType()==DataTypes.GEOMETRY ) {
|
166 |
return true; |
167 |
} |
168 |
} |
169 |
} |
170 |
return false; |
171 |
} |
172 |
|
173 |
@Override
|
174 |
public void setTablePrefix(String tablePrefix) { |
175 |
this.tablePrefix = tablePrefix;
|
176 |
} |
177 |
|
178 |
@Override
|
179 |
public String getTablePrefix() { |
180 |
return this.tablePrefix; |
181 |
} |
182 |
|
183 |
@Override
|
184 |
public String getNameWithPrefix(String name) { |
185 |
return StringUtils.join(this.tablePrefix,name); |
186 |
} |
187 |
|
188 |
} |