public MappingDefinition getDefinition(final Class<?> clazz) {
return getDefinition(clazz.getName());
}
private void loadCustomMappings() {
final MetaDataScanner scanner = ScannerSingleton.getOrCreateInstance();
for (final 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 {
final MappingDefinition definition = (MappingDefinition) cls.newInstance();
definition.setMarshallerInstance(new DefaultDefinitionMarshaller(definition));
addDefinition(definition);
exposedClasses.add(definition.getMappingClass());
if (log.isDebugEnabled())
log.debug("loaded custom mapping class: " + cls.getName() + " (for mapping: "
+ definition.getMappingClass().getFullyQualifiedName() + ")");
if (cls.isAnnotationPresent(InheritedMappings.class)) {
final InheritedMappings inheritedMappings = cls.getAnnotation(InheritedMappings.class);
for (final Class<?> c : inheritedMappings.value()) {
final MetaClass metaClass = MetaClassFactory.get(c);
final MappingDefinition aliasMappingDef = new MappingDefinition(metaClass, definition.alreadyGenerated());
aliasMappingDef.setMarshallerInstance(new DefaultDefinitionMarshaller(aliasMappingDef));
addDefinition(aliasMappingDef);
exposedClasses.add(metaClass);
if (log.isDebugEnabled())
log.debug("mapping inherited mapping " + c.getName() + " -> " + cls.getName());
}
}
}
catch (Throwable t) {
throw new RuntimeException("Failed to load definition", t);
}
}
for (final MappingDefinition def : MAPPING_DEFINITIONS.values()) {
mergeDefinition(def);
}
final Set<Class<?>> cliMarshallers = scanner.getTypesAnnotatedWith(ClientMarshaller.class);
for (final Class<?> marshallerCls : cliMarshallers) {
if (Marshaller.class.isAssignableFrom(marshallerCls)) {
try {
final Class<?> type =
(Class<?>) Marshaller.class.getMethod("getTypeHandled").invoke(marshallerCls.newInstance());
final MappingDefinition marshallMappingDef = new MappingDefinition(type, true);
marshallMappingDef.setClientMarshallerClass(marshallerCls.asSubclass(Marshaller.class));
addDefinition(marshallMappingDef);
exposedClasses.add(MetaClassFactory.get(type));
if (marshallerCls.isAnnotationPresent(ImplementationAliases.class)) {
for (final Class<?> aliasCls : marshallerCls.getAnnotation(ImplementationAliases.class).value()) {
final MappingDefinition aliasMappingDef = new MappingDefinition(aliasCls, true);
aliasMappingDef.setClientMarshallerClass(marshallerCls.asSubclass(Marshaller.class));
addDefinition(aliasMappingDef);
exposedClasses.add(MetaClassFactory.get(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());
}
}
final Set<Class<?>> serverMarshallers = scanner.getTypesAnnotatedWith(ServerMarshaller.class);
for (final Class<?> marshallerCls : serverMarshallers) {
if (Marshaller.class.isAssignableFrom(marshallerCls)) {
try {
final Class<?> type =