}
private void loadCustomMappings() {
exposedClasses.add(MetaClassFactory.get(Object.class));
final MetaDataScanner scanner = ScannerSingleton.getOrCreateInstance();
EnvUtil.clearCache();
final EnvironmentConfig environmentConfig = getEnvironmentConfig();
final Set<MetaClass> envExposedClasses = environmentConfig.getExposedClasses();
for (final Class<?> cls : scanner.getTypesAnnotatedWith(CustomMapping.class, true)) {
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);
if (!envExposedClasses.contains(definition.getMappingClass())) {
definition.setLazy(true);
}
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);
if (!envExposedClasses.contains(metaClass)) {
aliasMappingDef.setLazy(true);
}
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 : mappingDefinitions.values()) {
mergeDefinition(def);
}
final Collection<MetaClass> cliMarshallers = ClassScanner.getTypesAnnotatedWith(ClientMarshaller.class, true);
final MetaClass Marshaller_MC = MetaClassFactory.get(Marshaller.class);
for (final MetaClass marshallerMetaClass : cliMarshallers) {
if (Marshaller_MC.isAssignableFrom(marshallerMetaClass)) {
final Class<? extends Marshaller> marshallerCls = marshallerMetaClass.asClass().asSubclass(Marshaller.class);
try {
final Class<?> type = marshallerMetaClass.getAnnotation(ClientMarshaller.class).value();
final MappingDefinition marshallMappingDef = new MappingDefinition(type, true);
marshallMappingDef.setClientMarshallerClass(marshallerCls);
addDefinition(marshallMappingDef);
exposedClasses.add(MetaClassFactory.get(type).asBoxed());
typesWithBuiltInMarshallers.add(MetaClassFactory.get(type).asBoxed());
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).asBoxed());
typesWithBuiltInMarshallers.add(MetaClassFactory.get(type).asBoxed());
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, true);
for (final Class<?> marshallerCls : serverMarshallers) {
if (Marshaller.class.isAssignableFrom(marshallerCls)) {
try {
final Class<?> type = marshallerCls.getAnnotation(ServerMarshaller.class).value();