public MappingDefinition getDefinition(Class<?> clazz) {
return getDefinition(clazz.getName());
}
private void loadCustomMappings() {
MetaDataScanner scanner = ScannerSingleton.getOrCreateInstance();
for (Class<?> cls : scanner.getTypesAnnotatedWith(CustomMapping.class)) {
if (!MappingDefinition.class.isAssignableFrom(cls)) {
throw new RuntimeException("@CustomMapping class: " + cls.getName() + " does not inherit " + MappingDefinition.class.getName());
}
try {
MappingDefinition definition = (MappingDefinition) cls.newInstance();
definition.setMarshallerInstance(new DefaultDefinitionMarshaller(definition));
addDefinition(definition);
exposedClasses.add(definition.getMappingClass().asClass());
if (log.isDebugEnabled())
log.debug("loaded custom mapping class: " + cls.getName() + " (for mapping: "
+ definition.getMappingClass().getFullyQualifiedName() + ")");
if (cls.isAnnotationPresent(InheritedMappings.class)) {
InheritedMappings inheritedMappings = cls.getAnnotation(InheritedMappings.class);
for (Class<?> c : inheritedMappings.value()) {
MappingDefinition aliasMappingDef = new MappingDefinition(c);
aliasMappingDef.setMarshallerInstance(new DefaultDefinitionMarshaller(aliasMappingDef));
addDefinition(aliasMappingDef);
exposedClasses.add(c);
if (log.isDebugEnabled())
log.debug("mapping inherited mapping " + c.getName() + " -> " + cls.getName());
}
}
}
catch (Throwable t) {
throw new RuntimeException("Failed to load definition", t);
}
}
for (MappingDefinition def : MAPPING_DEFINITIONS.values()) {
mergeDefinition(def);
}
Set<Class<?>> marshallers = scanner.getTypesAnnotatedWith(ClientMarshaller.class);
for (Class<?> marshallerCls : marshallers) {
if (Marshaller.class.isAssignableFrom(marshallerCls)) {
try {
Class<?> type = (Class<?>) Marshaller.class.getMethod("getTypeHandled").invoke(marshallerCls.newInstance());
MappingDefinition marshallMappingDef = new MappingDefinition(type);
marshallMappingDef.setClientMarshallerClass(marshallerCls.asSubclass(Marshaller.class));
addDefinition(marshallMappingDef);
exposedClasses.add(type);
if (marshallerCls.isAnnotationPresent(ImplementationAliases.class)) {
for (Class<?> aliasCls : marshallerCls.getAnnotation(ImplementationAliases.class).value()) {
MappingDefinition aliasMappingDef = new MappingDefinition(aliasCls);
aliasMappingDef.setClientMarshallerClass(marshallerCls.asSubclass(Marshaller.class));
addDefinition(aliasMappingDef);
exposedClasses.add(aliasCls);
mappingAliases.put(aliasCls.getName(), type.getName());
}
}
}
catch (Throwable t) {
throw new RuntimeException("could not instantiate marshaller class: " + marshallerCls.getName(), t);
}
}
else {
throw new RuntimeException("class annotated with " + ClientMarshaller.class.getCanonicalName()
+ " does not implement " + Marshaller.class.getName());
}
}
Set<Class<?>> exposedFromScanner = new HashSet<Class<?>>(scanner.getTypesAnnotatedWith(Portable.class));
for (Class<?> cls : exposedFromScanner) {
for (Class<?> decl : cls.getDeclaredClasses()) {
if (decl.isSynthetic()) {
continue;
}
exposedClasses.add(decl);
}
}
exposedClasses.addAll(exposedFromScanner);
exposedClasses.add(Object.class);
Properties props = scanner.getProperties("ErraiApp.properties");
if (props != null) {
log.info("Checking ErraiApp.properties for configured types ...");
for (Object o : props.keySet()) {
String key = (String) o;