Revision 46874 trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.impl/src/main/java/org/gvsig/fmap/dal/complements/relatedfeatures/RelatedFeaturesFactory.java
RelatedFeaturesFactory.java | ||
---|---|---|
1 | 1 |
package org.gvsig.fmap.dal.complements.relatedfeatures; |
2 | 2 |
|
3 |
import java.util.ArrayList; |
|
4 |
import java.util.Arrays; |
|
5 |
import java.util.Collections; |
|
6 |
import java.util.List; |
|
7 |
import org.apache.commons.lang3.ArrayUtils; |
|
8 |
import org.apache.commons.lang3.StringUtils; |
|
9 |
import org.gvsig.fmap.dal.DALLocator; |
|
10 |
import org.gvsig.fmap.dal.StoresRepository; |
|
3 | 11 |
import org.gvsig.fmap.dal.complements.RelatedFeatures; |
12 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
|
13 |
import org.gvsig.fmap.dal.feature.FeatureType; |
|
4 | 14 |
import org.gvsig.tools.ToolsLocator; |
5 | 15 |
import org.gvsig.tools.complement.AbstractComplementFactory; |
6 | 16 |
import org.gvsig.tools.complement.Complement; |
7 | 17 |
import org.gvsig.tools.complement.ComplementsManager; |
18 |
import org.gvsig.tools.dynobject.AbstractDynMethod; |
|
19 |
import org.gvsig.tools.dynobject.DynMethod; |
|
20 |
import org.gvsig.tools.dynobject.DynObject; |
|
8 | 21 |
import org.gvsig.tools.dynobject.DynObjectManager; |
22 |
import org.gvsig.tools.dynobject.DynObjectValueItem; |
|
9 | 23 |
import org.gvsig.tools.dynobject.Tagged; |
24 |
import org.gvsig.tools.dynobject.Tags; |
|
25 |
import org.gvsig.tools.dynobject.exception.DynMethodException; |
|
26 |
import org.gvsig.tools.dynobject.exception.DynMethodNotSupportedException; |
|
10 | 27 |
|
11 | 28 |
/** |
12 | 29 |
* |
... | ... | |
22 | 39 |
public Complement<Tagged> createComplement(Tagged object) { |
23 | 40 |
return new RelatedFeaturesImpl(this, object); |
24 | 41 |
} |
42 |
|
|
43 |
private static class RelatedTableTagValues extends AbstractDynMethod { |
|
44 |
|
|
45 |
public RelatedTableTagValues() { |
|
46 |
super("RelatedTableTagValues"); |
|
47 |
} |
|
48 |
|
|
49 |
@Override |
|
50 |
public Object invoke(DynObject self, Object[] args) throws DynMethodException { |
|
51 |
StoresRepository repository = DALLocator.getDataManager().getStoresRepository(); |
|
52 |
List<String> tableNames = new ArrayList<>(); |
|
53 |
for (String tableName : repository.keySet()) { |
|
54 |
tableNames.add(tableName); |
|
55 |
} |
|
56 |
Collections.sort(tableNames); |
|
57 |
DynObjectValueItem[] values = new DynObjectValueItem[tableNames.size()]; |
|
58 |
for (int i = 0; i < tableNames.size(); i++) { |
|
59 |
values[i] = new DynObjectValueItem(tableNames.get(i),tableNames.get(i)); |
|
60 |
} |
|
61 |
return values; |
|
62 |
} |
|
63 |
} |
|
64 |
|
|
65 |
|
|
66 |
private static class RelatedUniqueFieldNameTagValues extends AbstractDynMethod { |
|
67 |
|
|
68 |
public RelatedUniqueFieldNameTagValues() { |
|
69 |
super("RelatedUniqueFieldNameTagValues"); |
|
70 |
} |
|
71 |
|
|
72 |
@Override |
|
73 |
public Object invoke(DynObject self, Object[] args) throws DynMethodException { |
|
74 |
if( ArrayUtils.isEmpty(args) ) { |
|
75 |
return null; |
|
76 |
} |
|
77 |
if( !(args[0] instanceof Tags) ) { |
|
78 |
return null; |
|
79 |
} |
|
80 |
Tags tags = (Tags) args[0]; |
|
81 |
String tableName = tags.getString(RelatedFeatures.DAL_RELATED_TABLE, null); |
|
82 |
if( StringUtils.isBlank(tableName) ) { |
|
83 |
return null; |
|
84 |
} |
|
85 |
StoresRepository repository = DALLocator.getDataManager().getStoresRepository(); |
|
86 |
FeatureType ft = repository.getFeatureType(tableName); |
|
87 |
if( ft == null ) { |
|
88 |
return null; |
|
89 |
} |
|
90 |
List<String> attrNames = new ArrayList<>(); |
|
91 |
for (FeatureAttributeDescriptor attr : ft) { |
|
92 |
attrNames.add(attr.getName()); |
|
93 |
} |
|
94 |
Collections.sort(attrNames); |
|
95 |
DynObjectValueItem[] values = new DynObjectValueItem[attrNames.size()]; |
|
96 |
for (int i = 0; i < attrNames.size(); i++) { |
|
97 |
values[i] = new DynObjectValueItem(attrNames.get(i),attrNames.get(i)); |
|
98 |
} |
|
99 |
return values; |
|
100 |
} |
|
101 |
} |
|
102 |
|
|
25 | 103 |
|
26 |
|
|
27 | 104 |
public static void selfRegister() { |
28 | 105 |
ComplementsManager complementsManager = ToolsLocator.getComplementsManager(); |
29 | 106 |
complementsManager.registerComplement(new RelatedFeaturesFactory()); |
... | ... | |
35 | 112 |
); |
36 | 113 |
dynObjectManager.registerTag( |
37 | 114 |
RelatedFeatures.DAL_RELATED_TABLE, |
38 |
"Part of a table of related features definition, store the table name of features." |
|
115 |
"Part of a table of related features definition, store the table name of features.", |
|
116 |
new RelatedTableTagValues() |
|
39 | 117 |
); |
40 | 118 |
dynObjectManager.registerTag( |
41 | 119 |
RelatedFeatures.DAL_RELATED_UNIQUE_FIELD_NAME, |
42 |
"Part of a table of related features definition, store the name of the field that is a unique key in the features table." |
|
120 |
"Part of a table of related features definition, store the name of the field that is a unique key in the features table.", |
|
121 |
new RelatedUniqueFieldNameTagValues() |
|
43 | 122 |
); |
44 | 123 |
// dynObjectManager.registerTag( |
45 | 124 |
// RelatedFeatures.DAL_RELATED_FOREING_KEY_NAME, |
Also available in: Unified diff