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 @ 47472
History | View | Annotate | Download (4.39 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 |
return null; |
92 |
} |
93 |
|
94 |
// public XMLTableInfo getByOriginalName(String name) {
|
95 |
// for (XMLTableInfo tableInfo : this) {
|
96 |
// if( StringUtils.equals(name, ((XMLTableInfoImpl)tableInfo).getOriginalName()) ) {
|
97 |
// return tableInfo;
|
98 |
// }
|
99 |
// }
|
100 |
// return null;
|
101 |
// }
|
102 |
//
|
103 |
@Override
|
104 |
public List<String> getKeys() { |
105 |
List<String> names = new ArrayList<>(this.tables.keySet()); |
106 |
names.sort(CompareUtils.EQUALS_IGNORECASE_COMPARATOR); |
107 |
return names;
|
108 |
} |
109 |
|
110 |
@Override
|
111 |
public Iterator<XMLTableInfo> iterator() { |
112 |
return this.tables.values().iterator(); |
113 |
} |
114 |
|
115 |
@Override
|
116 |
public boolean isEmpty() { |
117 |
return this.tables.isEmpty(); |
118 |
} |
119 |
|
120 |
public void setCountLines(long countlines) { |
121 |
this.countLines = countlines;
|
122 |
} |
123 |
|
124 |
public long getCountLines() { |
125 |
return this.countLines; |
126 |
} |
127 |
|
128 |
@Override
|
129 |
public String getRepositoryID() { |
130 |
return this.repositoryID; |
131 |
} |
132 |
|
133 |
@Override
|
134 |
public void setRepositoryID(String id) { |
135 |
this.repositoryID = id;
|
136 |
} |
137 |
|
138 |
@Override
|
139 |
public Charset getCharset() { |
140 |
return this.charset; |
141 |
} |
142 |
|
143 |
public void setCharset(Charset charset) { |
144 |
this.charset = charset;
|
145 |
} |
146 |
|
147 |
@Override
|
148 |
public Locale getLocale() { |
149 |
return this.locale; |
150 |
} |
151 |
|
152 |
public void setLocale(Locale locale) { |
153 |
this.locale = locale;
|
154 |
} |
155 |
|
156 |
@Override
|
157 |
public boolean hasGeometries() { |
158 |
for (XMLTableInfo tableInfo : this) { |
159 |
for (FeatureAttributeDescriptor ft : tableInfo.getFeatureType()) {
|
160 |
if( ft.getType()==DataTypes.GEOMETRY ) {
|
161 |
return true; |
162 |
} |
163 |
} |
164 |
} |
165 |
return false; |
166 |
} |
167 |
|
168 |
@Override
|
169 |
public void setTablePrefix(String tablePrefix) { |
170 |
this.tablePrefix = tablePrefix;
|
171 |
} |
172 |
|
173 |
@Override
|
174 |
public String getTablePrefix() { |
175 |
return this.tablePrefix; |
176 |
} |
177 |
|
178 |
@Override
|
179 |
public String getNameWithPrefix(String name) { |
180 |
return StringUtils.join(this.tablePrefix,name); |
181 |
} |
182 |
|
183 |
} |