root / branches / v2_0_0_prep / libraries / libFMap_data / src / org / gvsig / fmap / data / feature / joinstore / JoinFeatureType.java @ 23754
History | View | Annotate | Download (4.22 KB)
1 |
/* gvSIG. Geographic Information System of the Valencian Government
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department
|
4 |
* of the Valencian Government (CIT)
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 2
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
*/
|
22 |
|
23 |
/*
|
24 |
* AUTHORS (In addition to CIT):
|
25 |
* 2008 IVER T.I. S.A. {{Task}}
|
26 |
*/
|
27 |
|
28 |
package org.gvsig.fmap.data.feature.joinstore; |
29 |
|
30 |
import java.util.Iterator; |
31 |
|
32 |
import org.gvsig.fmap.data.feature.AttributeDescriptor; |
33 |
import org.gvsig.fmap.data.feature.FeatureAttributeDescriptor; |
34 |
import org.gvsig.fmap.data.feature.FeatureType; |
35 |
import org.gvsig.fmap.data.feature.exceptions.IsNotAttributeSettingException; |
36 |
import org.gvsig.fmap.data.feature.impl.DefaultFeatureType; |
37 |
|
38 |
public class JoinFeatureType extends DefaultFeatureType { |
39 |
/**
|
40 |
*
|
41 |
*/
|
42 |
private static final long serialVersionUID = -6196506718137857274L; |
43 |
private FeatureType fTypePrimary;
|
44 |
private FeatureType fTypeSecondary;
|
45 |
private String prefix; |
46 |
private JoinAttributeDescriptor defGeomAttr = null; |
47 |
|
48 |
public FeatureAttributeDescriptor createAttributeDescriptor() {
|
49 |
return new JoinAttributeDescriptor(this, true); |
50 |
} |
51 |
|
52 |
public FeatureAttributeDescriptor createNewAttributeDescriptor() {
|
53 |
return new JoinAttributeDescriptor(this, true); |
54 |
} |
55 |
|
56 |
public JoinAttributeDescriptor getDefaultGeometryAttribute() {
|
57 |
return defGeomAttr;
|
58 |
} |
59 |
|
60 |
protected void setDefaultGeometryAttribute(JoinAttributeDescriptor attr) { |
61 |
this.defGeomAttr = attr;
|
62 |
} |
63 |
|
64 |
public Object getFromOriginalPosition(int index) { |
65 |
Iterator iter = this.iterator(); |
66 |
while (iter.hasNext()) {
|
67 |
JoinAttributeDescriptor attr = (JoinAttributeDescriptor) iter |
68 |
.next(); |
69 |
if (attr.originalPosition() == index) {
|
70 |
return attr;
|
71 |
} |
72 |
|
73 |
} |
74 |
return null; |
75 |
|
76 |
} |
77 |
|
78 |
protected void loadPrimaryStoreFeatureType(FeatureType fType) |
79 |
throws IsNotAttributeSettingException {
|
80 |
this.fTypePrimary = fType;
|
81 |
|
82 |
Iterator iter = fType.iterator();
|
83 |
|
84 |
while (iter.hasNext()) {
|
85 |
this.importAttribute((AttributeDescriptor) iter.next());
|
86 |
} |
87 |
} |
88 |
|
89 |
protected JoinAttributeDescriptor importAttribute(AttributeDescriptor attr) {
|
90 |
JoinAttributeDescriptor newAttr = (JoinAttributeDescriptor) this
|
91 |
.createNewAttributeDescriptor(); |
92 |
|
93 |
newAttr.loadFrom(attr); |
94 |
this.add(newAttr);
|
95 |
return newAttr;
|
96 |
} |
97 |
|
98 |
protected void loadSecondaryStoreFeatureType(FeatureType fType, |
99 |
String prefix) throws IsNotAttributeSettingException { |
100 |
this.fTypeSecondary = fType;
|
101 |
this.prefix = prefix;
|
102 |
Iterator iter = fType.iterator();
|
103 |
|
104 |
JoinAttributeDescriptor newAttr; |
105 |
while (iter.hasNext()) {
|
106 |
newAttr = this.importAttribute((AttributeDescriptor) iter.next());
|
107 |
newAttr.loading(); |
108 |
newAttr.setFromSecondarySource(true);
|
109 |
newAttr.setOriginalName(newAttr.getName()); |
110 |
newAttr.setName(prefix + newAttr.getName()); |
111 |
newAttr.stopLoading(); |
112 |
} |
113 |
} |
114 |
|
115 |
public FeatureType getPrimaryFeatureType() {
|
116 |
return this.fTypePrimary; |
117 |
} |
118 |
|
119 |
public FeatureType getSecondaryFeatureType() {
|
120 |
return this.fTypeSecondary; |
121 |
} |
122 |
|
123 |
protected FeatureType newFeatureType() {
|
124 |
return new JoinFeatureType(); |
125 |
|
126 |
} |
127 |
protected void fillFeatureType(DefaultFeatureType type) { |
128 |
super.fillFeatureType(type);
|
129 |
if (type instanceof JoinFeatureType) { |
130 |
JoinFeatureType joinType = (JoinFeatureType) type; |
131 |
joinType.fTypePrimary = this.fTypePrimary;
|
132 |
joinType.fTypeSecondary = this.fTypeSecondary;
|
133 |
joinType.prefix = this.prefix;
|
134 |
} |
135 |
} |
136 |
|
137 |
public String getPrefix() { |
138 |
return this.prefix; |
139 |
} |
140 |
|
141 |
public boolean isFromSecondary(String name) { |
142 |
return ((JoinAttributeDescriptor) this.get(name)) |
143 |
.isFromSecondarySource(); |
144 |
} |
145 |
|
146 |
public boolean isFromSecondary(int index) { |
147 |
return ((JoinAttributeDescriptor) this.get(index)) |
148 |
.isFromSecondarySource(); |
149 |
|
150 |
} |
151 |
|
152 |
} |