private void analyzeClass()

in src/main/java/org/apache/sling/models/impl/ModelPackageBundleListener.java [141:192]


    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 = 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|AnnotationFormatError e) {
            log.warn("Unable to load class '{}' from bundle '{}': {}", className, bundle.getSymbolicName(), e.getLocalizedMessage(), e);
        }
    }