Revision 44259 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/feature/impl/DefaultFeatureAttributeDescriptor.java
DefaultFeatureAttributeDescriptor.java | ||
---|---|---|
33 | 33 |
import org.apache.commons.lang3.ArrayUtils; |
34 | 34 |
import org.apache.commons.lang3.StringUtils; |
35 | 35 |
import org.cresques.cts.IProjection; |
36 |
import org.gvsig.expressionevaluator.Expression; |
|
37 |
import org.gvsig.expressionevaluator.ExpressionUtils; |
|
38 |
import org.gvsig.expressionevaluator.SymbolTable; |
|
39 |
import org.gvsig.fmap.dal.DALLocator; |
|
40 |
import org.gvsig.fmap.dal.DataManager; |
|
41 |
import static org.gvsig.fmap.dal.DataManager.DAL_FOREING_CODE; |
|
42 |
import static org.gvsig.fmap.dal.DataManager.DAL_FOREING_LABEL; |
|
43 |
import static org.gvsig.fmap.dal.DataManager.DAL_FOREING_TABLE; |
|
36 | 44 |
import org.gvsig.fmap.dal.DataStore; |
37 | 45 |
import org.gvsig.fmap.dal.DataTypes; |
46 |
import org.gvsig.fmap.dal.StoresRepository; |
|
47 |
import org.gvsig.fmap.dal.expressionevaluator.FeatureSymbolTable; |
|
48 |
import org.gvsig.fmap.dal.feature.Feature; |
|
38 | 49 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
39 | 50 |
import org.gvsig.fmap.dal.feature.FeatureAttributeEmulator; |
40 | 51 |
import org.gvsig.fmap.dal.feature.FeatureAttributeGetter; |
... | ... | |
74 | 85 |
import org.slf4j.Logger; |
75 | 86 |
import org.slf4j.LoggerFactory; |
76 | 87 |
|
88 |
@SuppressWarnings("UseSpecificCatch") |
|
77 | 89 |
public class DefaultFeatureAttributeDescriptor implements |
78 | 90 |
FeatureAttributeDescriptor, Persistent, DynField_v2, DynField_LabelAttribute { |
79 | 91 |
|
... | ... | |
128 | 140 |
} |
129 | 141 |
|
130 | 142 |
protected DefaultFeatureAttributeDescriptor(FeatureType type) { |
143 |
this(); |
|
144 |
// LOGGER.info(String.format("Created FeatureAttributeDescriptor [%08x].", this.hashCode())); |
|
131 | 145 |
setFeatureType(type); |
132 | 146 |
this.allowNull = true; |
133 | 147 |
this.dataType = null; |
... | ... | |
155 | 169 |
protected DefaultFeatureAttributeDescriptor( |
156 | 170 |
DefaultFeatureAttributeDescriptor other |
157 | 171 |
) { |
172 |
this(); |
|
158 | 173 |
copyFrom(other); |
174 |
// LOGGER.info(String.format("Created FeatureAttributeDescriptor [%08x] [%s] (copy).", this.hashCode(), this.name)); |
|
159 | 175 |
} |
160 | 176 |
|
161 | 177 |
@Override |
... | ... | |
230 | 246 |
this.typeRef = null; |
231 | 247 |
} else { |
232 | 248 |
this.typeRef = new WeakReference(type); |
249 |
// LOGGER.info(String.format("FeatureAttributeDescriptor[%08x] set FeatureType [%08x], ref [%08x].", this.hashCode(), type.hashCode(), typeRef.hashCode())); |
|
233 | 250 |
} |
234 | 251 |
} |
235 | 252 |
|
... | ... | |
346 | 363 |
} |
347 | 364 |
|
348 | 365 |
public FeatureAttributeDescriptor setName(String name) { |
366 |
// LOGGER.info(String.format("FeatureAttributeDescriptor[%08x] set name [%s].", this.hashCode(), name)); |
|
349 | 367 |
this.name = name; |
350 | 368 |
return this; |
351 | 369 |
} |
... | ... | |
735 | 753 |
|
736 | 754 |
@Override |
737 | 755 |
public DynObjectValueItem[] getAvailableValues() { |
756 |
if( this.availableValues == null ) { |
|
757 |
if( StringUtils.isBlank(this.getDataProfileName()) ) { |
|
758 |
return null; |
|
759 |
} |
|
760 |
if( !StringUtils.equalsIgnoreCase( |
|
761 |
this.getDataProfileName(), |
|
762 |
DataManager.DAL_SELECTABLE_FOREING_KEY) |
|
763 |
) { |
|
764 |
return null; |
|
765 |
} |
|
766 |
Tags theTags = this.getTags(); |
|
767 |
if( theTags==null ) { |
|
768 |
return null; |
|
769 |
} |
|
770 |
String foreingLabel = theTags.getString(DAL_FOREING_LABEL, null); |
|
771 |
if( StringUtils.isBlank(foreingLabel) ) { |
|
772 |
return null; |
|
773 |
} |
|
774 |
String foreingTableName = theTags.getString(DAL_FOREING_TABLE, null); |
|
775 |
if( StringUtils.isBlank(foreingTableName) ) { |
|
776 |
return null; |
|
777 |
} |
|
778 |
String foreingCodeName = theTags.getString(DAL_FOREING_CODE, null); |
|
779 |
if( StringUtils.isBlank(foreingCodeName) ) { |
|
780 |
return null; |
|
781 |
} |
|
782 |
try { |
|
783 |
DataManager dataManager = DALLocator.getDataManager(); |
|
784 |
StoresRepository repository = this.getStore().getStoresRepository(); |
|
785 |
FeatureStore store = (FeatureStore) repository.get(foreingTableName); |
|
786 |
if( store == null ) { |
|
787 |
LOGGER.warn("Can't locate store '"+foreingTableName+"' to get available values of field '"+this.getName()+"'."); |
|
788 |
return null; |
|
789 |
} |
|
790 |
|
|
791 |
Expression labelExpression = ExpressionUtils.createExpression(foreingLabel); |
|
792 |
FeatureSymbolTable featureSymbolTable = dataManager.createFeatureSymbolTable(); |
|
793 |
SymbolTable symbolTable = featureSymbolTable.createParent(); |
|
794 |
|
|
795 |
int count = (int) store.getFeatureCount(); |
|
796 |
DynObjectValueItem[] values = new DynObjectValueItem[count]; |
|
797 |
int n = 0; |
|
798 |
for (Feature feature : store.getFeatureSet()) { |
|
799 |
featureSymbolTable.setFeature(feature); |
|
800 |
Object code = feature.get(foreingCodeName); |
|
801 |
Object label = labelExpression.execute(symbolTable); |
|
802 |
values[n++] = new DynObjectValueItem(code, Objects.toString(label, Objects.toString(code, "##ERROR##"))); |
|
803 |
} |
|
804 |
this.availableValues = values; |
|
805 |
} catch (Exception ex) { |
|
806 |
LOGGER.warn("Can't get values from table '" + foreingTableName + "' for field '" + this.getName() + "'.", ex); |
|
807 |
return null; |
|
808 |
} |
|
809 |
} |
|
738 | 810 |
return this.availableValues; |
739 | 811 |
} |
740 | 812 |
|
... | ... | |
1225 | 1297 |
if( this.typeRef==null ) { |
1226 | 1298 |
return null; |
1227 | 1299 |
} |
1228 |
return (FeatureType) this.typeRef.get(); |
|
1300 |
FeatureType ftype = (FeatureType) this.typeRef.get(); |
|
1301 |
// LOGGER.info(String.format("FeatureAttributeDescriptor[%08x] get FeatureType [%08x], ref [%08x].", this.hashCode(), ftype.hashCode(), typeRef.hashCode())); |
|
1302 |
return ftype; |
|
1229 | 1303 |
} |
1230 | 1304 |
|
1231 | 1305 |
public FeatureAttributeDescriptor setInterval(Interval interval) { |
Also available in: Unified diff