Package org.apache.sling.models.annotations

Examples of org.apache.sling.models.annotations.Model


                while (classUrls.hasMoreElements()) {
                    URL url = classUrls.nextElement();
                    String className = toClassName(url);
                    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 };
                            }
                            // register adapter only if given adapters are valid
                            if (validateAdapterClasses(implType, adapterTypes)) {
                                for (Class<?> adapterType : adapterTypes) {
                                    if (adapterType != implType) {
                                        adapterImplementations.add(adapterType, implType);
                                    }
                                }
                                ServiceRegistration reg = registerAdapterFactory(adapterTypes, annotation.adaptables(), implType, annotation.condition());
                                regs.add(reg);
                            }
                        }
                    } catch (ClassNotFoundException e) {
                        log.warn("Unable to load class", e);
View Full Code Here


        return innerCanCreateFromAdaptable(adaptable, modelClass);
    }

    private boolean innerCanCreateFromAdaptable(Object adaptable, Class<?> modelClass) throws InvalidModelException {
        modelClass = getImplementationTypeForAdapterType(modelClass, adaptable);
        Model modelAnnotation = modelClass.getAnnotation(Model.class);
        if (modelAnnotation == null) {
            throw new InvalidModelException(String.format("Model class '%s' does not have a model annotation", modelClass));
        }

        Class<?>[] declaredAdaptable = modelAnnotation.adaptables();
        for (Class<?> clazz : declaredAdaptable) {
            if (clazz.isInstance(adaptable)) {
                return true;
            }
        }
View Full Code Here

        threadInvocationCounter.increase();
        try {
            // check if a different implementation class was registered for this adapter type
            type = (Class<ModelType>) getImplementationTypeForAdapterType(type, adaptable);

            Model modelAnnotation = type.getAnnotation(Model.class);
            if (modelAnnotation == null) {
                result.addFailure(FailureType.NO_MODEL_ANNOTATION, type);
                return result;
            }
            boolean isAdaptable = false;

            Class<?>[] declaredAdaptable = modelAnnotation.adaptables();
            for (Class<?> clazz : declaredAdaptable) {
                if (clazz.isInstance(adaptable)) {
                    isAdaptable = true;
                }
            }
View Full Code Here

TOP

Related Classes of org.apache.sling.models.annotations.Model

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.