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.keySet());
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.containsKey("*")) {
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 = (AbstractPropertyData<?>) prop.getValue(); // a
// bit
// dirty
ad.setQueryName(queryName);
ad.setLocalName(localName);
ad.setDisplayName(displayName);
mappedProperties.put(queryName, prop.getValue());
}
} else {
// replace all ids with query names or alias:
for (Map.Entry<String, PropertyData<?>> prop : properties.entrySet()) {
String queryNameOrAlias = requestedIds.get(prop.getKey());
String localName = td.getPropertyDefinitions().get(prop.getKey()).getLocalName();
String displayName = td.getPropertyDefinitions().get(prop.getKey()).getDisplayName();
AbstractPropertyData<?> ad = (AbstractPropertyData<?>) prop.getValue(); // a
// bit
// dirty
ad.setQueryName(queryNameOrAlias);
ad.setLocalName(localName);
ad.setDisplayName(displayName);
mappedProperties.put(queryNameOrAlias, prop.getValue());
}
}
// add functions:
BindingsObjectFactory objFactory = new BindingsObjectFactoryImpl();
for (Entry<String, String> funcEntry : requestedFuncs.entrySet()) {
PropertyInteger pi = objFactory.createPropertyIntegerData(funcEntry.getKey(), BigInteger.valueOf(100));
// fixed dummy value
mappedProperties.put(funcEntry.getValue(), pi);
}
Properties props = new PropertiesImpl(mappedProperties.values());