org.springframework.content.commons.mappingcontext.MappingContext Maven / Gradle / Ivy
package org.springframework.content.commons.mappingcontext;
import java.util.HashMap;
import java.util.Map;
import org.springframework.content.commons.storeservice.StoreInfo;
import org.springframework.content.commons.storeservice.Stores;
public class MappingContext {
private Map, Map> context = new HashMap<>();
private CharSequence keySeparator = "/";
private CharSequence contentPropertySeparator = ".";
public MappingContext(CharSequence keySeparator, CharSequence contentPropertySeparator) {
this.keySeparator = keySeparator;
this.contentPropertySeparator = contentPropertySeparator;
}
public MappingContext(Stores stores) {
for (StoreInfo info : stores.getStores(Stores.MATCH_ALL)) {
if (info.getDomainObjectClass() != null) {
context.put(info.getDomainObjectClass(), resolveProperties(info.getDomainObjectClass()));
}
}
}
public boolean hasMapping(Class> domainClass, String path) {
Map properties = context.get(domainClass);
if (properties == null) {
properties = resolveProperties(domainClass);
}
return properties.get(path) != null;
}
public ContentProperty getContentProperty(Class> domainClass, String path) {
Map properties = context.get(domainClass);
if (properties == null) {
properties = resolveProperties(domainClass);
}
return properties.get(path);
}
private Map resolveProperties(Class> domainClass) {
ContentPropertyBuilderVisitor visitor = new ContentPropertyBuilderVisitor(this.keySeparator, this.contentPropertySeparator, new ContentPropertyBuilderVisitor.CanonicalName());
ClassWalker walker = new ClassWalker(domainClass);
walker.accept(visitor);
context.put(domainClass, visitor.getProperties());
return visitor.getProperties();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy