public static Properties getPropertiesFromObject(StoredObject so, TypeDefinition td,
Map<String, String> requestedIds, Map<String, String> requestedFuncs) {
// build properties collection
List<String> idList = new ArrayList<String>(requestedIds.values());
BindingsObjectFactory objectFactory = new BindingsObjectFactoryImpl();
Map<String, PropertyData<?>> properties = new HashMap<String, PropertyData<?>>();
so.fillProperties(properties, objectFactory, idList);
String typeId = so.getTypeId();
if (FilterParser.isContainedInFilter(PropertyIds.BASE_TYPE_ID, idList)) {
if (td == null) {
log.warn("getPropertiesFromObject(), cannot get type definition, a type with id " + typeId
+ " is unknown");
} else {
String baseTypeId = td.getBaseTypeId().value();
properties.put(PropertyIds.BASE_TYPE_ID,
objectFactory.createPropertyIdData(PropertyIds.BASE_TYPE_ID, baseTypeId));
}
}
Map<String, PropertyData<?>> mappedProperties = new HashMap<String, PropertyData<?>>();
if (requestedIds.containsValue("*")) {
for (Map.Entry<String, PropertyData<?>> prop : properties.entrySet()) {
// map property id to property query name
String queryName = td.getPropertyDefinitions().get(prop.getKey()).getQueryName();
String localName = td.getPropertyDefinitions().get(prop.getKey()).getLocalName();
String displayName = td.getPropertyDefinitions().get(prop.getKey()).getDisplayName();
AbstractPropertyData<?> ad = clonePropertyData(prop.getValue());
ad.setQueryName(queryName);
ad.setLocalName(localName);
ad.setDisplayName(displayName);
mappedProperties.put(queryName, ad);
}
} else {
// replace all ids with query names or alias:
for (Entry<String, String> propAlias : requestedIds.entrySet()) {
String queryNameOrAlias = propAlias.getKey();
PropertyData<?> prop = properties.get(propAlias.getValue());
String localName = td.getPropertyDefinitions().get(prop.getId()).getLocalName();
String displayName = td.getPropertyDefinitions().get(prop.getId()).getDisplayName();
AbstractPropertyData<?> ad = clonePropertyData(prop);
ad.setQueryName(queryNameOrAlias);
ad.setLocalName(localName);
ad.setDisplayName(displayName);
mappedProperties.put(queryNameOrAlias, ad);
}
}
// add functions:
BindingsObjectFactory objFactory = new BindingsObjectFactoryImpl();
for (Entry<String, String> funcEntry : requestedFuncs.entrySet()) {
PropertyInteger pi = objFactory.createPropertyIntegerData(funcEntry.getValue(), BigInteger.valueOf(100));
// fixed dummy value
mappedProperties.put(funcEntry.getKey(), pi);
}
Properties props = new PropertiesImpl(mappedProperties.values());