Statistics
| Revision:

root / branches / v2_0_0_prep / libraries / libFMap_data / src / org / gvsig / fmap / data / feature / joinstore / JoinFeatureType.java @ 22933

History | View | Annotate | Download (3.96 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.DefaultFeatureType;
34
import org.gvsig.fmap.data.feature.FeatureAttributeDescriptor;
35
import org.gvsig.fmap.data.feature.FeatureType;
36
import org.gvsig.fmap.data.feature.IsNotAttributeSettingException;
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

    
47
        public FeatureAttributeDescriptor createAttributeDescriptor() {
48
                return new JoinAttributeDescriptor(this, true);
49
        }
50

    
51
        public FeatureAttributeDescriptor createNewAttributeDescriptor() {
52
                return new JoinAttributeDescriptor(this, true);
53
        }
54

    
55
        public Object getFromOriginalPosition(int index) {
56
                Iterator iter = this.iterator();
57
                while (iter.hasNext()) {
58
                        JoinAttributeDescriptor attr = (JoinAttributeDescriptor) iter
59
                                        .next();
60
                        if (attr.originalPosition() == index) {
61
                                return attr;
62
                        }
63

    
64
                }
65
                return null;
66

    
67
        }
68

    
69
        protected void loadPrimaryStoreFeatureType(FeatureType fType)
70
                        throws IsNotAttributeSettingException {
71
                this.fTypePrimary = fType;
72

    
73
                Iterator iter = fType.iterator();
74

    
75
                while (iter.hasNext()) {
76
                        this.importAttribute((AttributeDescriptor) iter.next());
77
                }
78
        }
79

    
80
        protected JoinAttributeDescriptor importAttribute(AttributeDescriptor attr) {
81
                JoinAttributeDescriptor newAttr = (JoinAttributeDescriptor) this
82
                                .createNewAttributeDescriptor();
83

    
84
                newAttr.loadFrom(attr);
85
                this.add(newAttr);
86
                return newAttr;
87
        }
88

    
89
        protected void loadSecondaryStoreFeatureType(FeatureType fType,
90
                        String prefix) throws IsNotAttributeSettingException {
91
                this.fTypeSecondary = fType;
92
                this.prefix = prefix;
93
                Iterator iter = fType.iterator();
94

    
95
                JoinAttributeDescriptor newAttr;
96
                while (iter.hasNext()) {
97
                        newAttr = this.importAttribute((AttributeDescriptor) iter.next());
98
                        newAttr.loading();
99
                        newAttr.setFromSecondarySource(true);
100
                        newAttr.setOriginalName(newAttr.getName());
101
                        newAttr.setName(prefix + newAttr.getName());
102
                        newAttr.stopLoading();
103
                }
104
        }
105

    
106
        public FeatureType getPrimaryFeatureType() {
107
                return this.fTypePrimary;
108
        }
109

    
110
        public FeatureType getSecondaryFeatureType() {
111
                return this.fTypeSecondary;
112
        }
113

    
114
        protected FeatureType newFeatureType() {
115
                return new JoinFeatureType();
116

    
117
        }
118
        protected void fillFeatureType(DefaultFeatureType type) {
119
                super.fillFeatureType(type);
120
                if (type instanceof JoinFeatureType) {
121
                        JoinFeatureType joinType = (JoinFeatureType) type;
122
                        joinType.fTypePrimary = this.fTypePrimary;
123
                        joinType.fTypeSecondary = this.fTypeSecondary;
124
                        joinType.prefix = this.prefix;
125
                }
126
        }
127

    
128
        public String getPrefix() {
129
                return this.prefix;
130
        }
131

    
132
        public boolean isFromSecondary(String name) {
133
                return ((JoinAttributeDescriptor) this.get(name))
134
                                .isFromSecondarySource();
135
        }
136

    
137
        public boolean isFromSecondary(int index) {
138
                return ((JoinAttributeDescriptor) this.get(index))
139
                                .isFromSecondarySource();
140

    
141
        }
142

    
143
}