use of org.apache.sling.models.annotations.Exporter in project sling by apache.
the class ModelPackageBundleListener method analyzeClass.
private void analyzeClass(Bundle bundle, String className, List<ServiceRegistration> regs) {
try {
Class<?> implType = bundle.loadClass(className);
Model annotation = implType.getAnnotation(Model.class);
if (annotation != null) {
// get list of adapters from annotation - if not given use annotated class itself
Class<?>[] adapterTypes = annotation.adapters();
if (adapterTypes.length == 0) {
adapterTypes = new Class<?>[] { implType };
} else if (!ArrayUtils.contains(adapterTypes, implType)) {
adapterTypes = (Class<?>[]) ArrayUtils.add(adapterTypes, implType);
}
// register adapter only if given adapters are valid
if (validateAdapterClasses(implType, adapterTypes)) {
if (adapterImplementations.addAll(implType, adapterTypes)) {
ServiceRegistration reg = registerAdapterFactory(adapterTypes, annotation.adaptables(), implType, annotation.condition());
regs.add(reg);
String[] resourceTypes = annotation.resourceType();
for (String resourceType : resourceTypes) {
if (StringUtils.isNotEmpty(resourceType)) {
for (Class<?> adaptable : annotation.adaptables()) {
adapterImplementations.registerModelToResourceType(bundle, resourceType, adaptable, implType);
ExportServlet.ExportedObjectAccessor accessor = null;
if (adaptable == Resource.class) {
accessor = new ExportServlet.ResourceAccessor(implType);
} else if (adaptable == SlingHttpServletRequest.class) {
accessor = new ExportServlet.RequestAccessor(implType);
}
Exporter exporterAnnotation = implType.getAnnotation(Exporter.class);
if (exporterAnnotation != null) {
registerExporter(bundle, implType, resourceType, exporterAnnotation, regs, accessor);
}
Exporters exportersAnnotation = implType.getAnnotation(Exporters.class);
if (exportersAnnotation != null) {
for (Exporter ann : exportersAnnotation.value()) {
registerExporter(bundle, implType, resourceType, ann, regs, accessor);
}
}
}
}
}
}
}
}
} catch (ClassNotFoundException e) {
log.warn("Unable to load class", e);
}
}
Aggregations