/** * @see org.apache.felix.scrplugin.annotations.AnnotationProcessor#process(org.apache.felix.scrplugin.annotations.ScannedClass, org.apache.felix.scrplugin.description.ClassDescription) */ @Override public void process(final ScannedClass scannedClass, final ClassDescription describedClass) throws SCRDescriptorFailureException, SCRDescriptorException { final List<ClassAnnotation> servlets = scannedClass.getClassAnnotations(SlingServlet.class.getName()); scannedClass.processed(servlets); for(final ClassAnnotation cad : servlets) { processSlingServlet(cad, describedClass); } final List<ClassAnnotation> filters = scannedClass.getClassAnnotations(SlingFilter.class.getName()); scannedClass.processed(filters); for(final ClassAnnotation cad : filters) { processSlingFilter(cad, describedClass); } }
if (d.getBooleanValue("serviceFactory", false)) { service.setServiceFactory(true); if (d.getValue("value") != null) { final String[] interfaces = (String[]) d.getValue("value"); for (String t : interfaces) { listedInterfaces.add(t); addInterfaces(service, scannedClass.getScannedClass());
final boolean classIsAbstract = Modifier.isAbstract(scannedClass.getScannedClass().getModifiers()); component.setAbstract(cad.getBooleanValue("componentAbstract", classIsAbstract)); component.setName(cad.getStringValue("name", scannedClass.getScannedClass().getName())); component.setLabel(cad.getStringValue("label", null)); component.setDescription(cad.getStringValue("description", null)); component.setCreateDs(cad.getBooleanValue("ds", true)); component.setCreateMetatype(cad.getBooleanValue("metatype", false)); if (cad.getValue("enabled") != null) { component.setEnabled(cad.getBooleanValue("enabled", true)); if (cad.getValue("specVersion") != null) { component.setSpecVersion(SpecVersion.fromName(cad.getValue("specVersion").toString())); component.setFactory(cad.getStringValue("factory", null)); if (cad.getValue("immediate") != null) { component.setImmediate(cad.getBooleanValue("immediate", false)); component.setInherit(cad.getBooleanValue("inherit", true)); component.setConfigurationPolicy(ComponentConfigurationPolicy.valueOf(cad.getEnumValue("policy", ComponentConfigurationPolicy.OPTIONAL.name()))); component.setSetMetatypeFactoryPid(cad.getBooleanValue("configurationFactory", false)); component.setConfigurationPid(cad.getStringValue("configurationPid", null));
final List<ClassAnnotation> componentTags = scannedClass.getClassAnnotations(Component.class.getName()); scannedClass.processed(componentTags); final List<MethodAnnotation> methodTags = scannedClass.getMethodAnnotations(null); for (final MethodAnnotation m : methodTags) { if (m.getName().equals(Activate.class.getName())) { cd.setActivate(m.getAnnotatedMethod().getName()); scannedClass.processed(m); } else if (m.getName().equals(Deactivate.class.getName())) { cd.setDeactivate(m.getAnnotatedMethod().getName()); scannedClass.processed(m); } else if (m.getName().equals(Modified.class.getName())) { cd.setModified(m.getAnnotatedMethod().getName()); scannedClass.processed(m); final List<ClassAnnotation> serviceTags = scannedClass.getClassAnnotations(Service.class.getName()); if (serviceTags.size() > 0) { scannedClass.processed(serviceTags); allServiceTags.addAll(serviceTags); final List<ClassAnnotation> servicesTags = scannedClass.getClassAnnotations(Services.class.getName()); if (servicesTags.size() > 0) { scannedClass.processed(servicesTags); for (final ClassAnnotation cad : servicesTags) { final ClassAnnotation[] values = (ClassAnnotation[]) cad.getValue("value"); if (values != null) { allServiceTags.addAll(Arrays.asList(values)); final List<ClassAnnotation> referencesClassTags = scannedClass.getClassAnnotations(References.class.getName());
final boolean generateComponent = cad.getBooleanValue("generateComponent", true); final boolean metatype = cad.getBooleanValue("metatype", !generateComponent); cd.setName(cad.getStringValue("name", classDescription.getDescribedClass().getName())); cd.setConfigurationPolicy(ComponentConfigurationPolicy.OPTIONAL); cd.setLabel(cad.getStringValue("label", null)); cd.setDescription(cad.getStringValue("description", null)); final boolean generateService = cad.getBooleanValue("generateService", true); if (generateService) { final ServiceDescription sd = new ServiceDescription(cad); final int order = cad.getIntegerValue("order", 0); final PropertyDescription pd = new PropertyDescription(cad); pd.setName("service.ranking"); final String pattern = cad.getStringValue("pattern", ""); if(!StringUtils.isEmpty(pattern)) { final PropertyDescription pdPattern = new PropertyDescription(cad); final Object val = cad.getValue("scope"); if ( val != null ) { if ( val instanceof String[] ) {
final String propType = PROPERTY_VALUE_PROCESSING[index]; final String propName = PROPERTY_VALUE_PROCESSING[index + 1]; final Object propValue = ad.getValue(propName); if (propValue != null && propValue.getClass().isArray()) { type = propType; String name = ad.getStringValue("name", null); final Object value = fieldAnnotation.getAnnotatedFieldValue(); if (value != null) { name = value.toString(); final Object value = fieldAnnotation.getAnnotatedFieldValue(); if (value != null) { if (value.getClass().isArray()) { prop.setType(PropertyType.from(fieldAnnotation.getAnnotatedField().getType().getComponentType())); } else { prop.setType(PropertyType.from(value.getClass())); if ( Modifier.isStatic(fieldAnnotation.getAnnotatedField().getModifiers()) ) { final Object value = fieldAnnotation.getAnnotatedFieldValue(); if (value != null) { name = value.toString(); name = fieldAnnotation.getAnnotatedField().getName(); final Object value = fieldAnnotation.getAnnotatedFieldValue(); if (value != null) { if (value.getClass().isArray()) {
final boolean generateComponent = cad.getBooleanValue("generateComponent", true); final boolean metatype = cad.getBooleanValue("metatype", !generateComponent); cd.setName(cad.getStringValue("name", classDescription.getDescribedClass().getName())); cd.setConfigurationPolicy(ComponentConfigurationPolicy.OPTIONAL); cd.setLabel(cad.getStringValue("label", null)); cd.setDescription(cad.getStringValue("description", null)); final boolean generateService = cad.getBooleanValue("generateService", true); if (generateService) { final ServiceDescription sd = new ServiceDescription(cad);
/** * Get a boolean value of the annotation * @param name The property name * @param defaultValue A default value if the property is not set * @return The property value or the default value. */ public boolean getBooleanValue(final String name, final boolean defaultValue) { final Object val = this.getValue(name); if ( val != null ) { return ((Boolean) val).booleanValue(); } return defaultValue; }
/** * Generates a property descriptor of type {@link PropertyType#String} */ private void generateStringPropertyDescriptor(final ClassAnnotation cad, final ClassDescription classDescription, final boolean metatype, String annotationName, String propertyDescriptorName) { final String[] values = (String[]) cad.getValue(annotationName); if (values == null) { return; } final PropertyDescription pd = new PropertyDescription(cad); pd.setName(propertyDescriptorName); pd.setMultiValue(values); pd.setType(PropertyType.String); if (metatype) { pd.setPrivate(true); } classDescription.add(pd); }
if (ad instanceof FieldAnnotation) { fieldAnnotation = (FieldAnnotation) ad; ref.setField(fieldAnnotation.getAnnotatedField()); } else { fieldAnnotation = null; ref.setName(ad.getStringValue("name", (fieldAnnotation != null ? fieldAnnotation.getAnnotatedField().getName() : null))); String defaultInterfaceName = null; if ( fieldAnnotation != null ) { if ( fieldAnnotation.getAnnotatedField().getType().isArray() ) { defaultInterfaceName = fieldAnnotation.getAnnotatedField().getType().getComponentType().getName(); } else { defaultInterfaceName = fieldAnnotation.getAnnotatedField().getType().getName(); ref.setInterfaceName(ad.getStringValue("referenceInterface", defaultInterfaceName)); ref.setTarget(ad.getStringValue("target", null)); ref.setCardinality(ReferenceCardinality.valueOf(ad.getEnumValue("cardinality", ReferenceCardinality.MANDATORY_UNARY.name()))); ref.setPolicy(ReferencePolicy.valueOf(ad.getEnumValue("policy", ReferencePolicy.STATIC.name()))); ref.setPolicyOption(ReferencePolicyOption.valueOf(ad.getEnumValue("policyOption", ReferencePolicyOption.RELUCTANT.name()))); ref.setStrategy(ReferenceStrategy.valueOf(ad.getEnumValue("strategy", ReferenceStrategy.EVENT.name()))); ref.setBind(ad.getStringValue("bind", null)); ref.setUnbind(ad.getStringValue("unbind", null)); ref.setUpdated(ad.getStringValue("updated", null));
/** * @see org.apache.felix.scrplugin.annotations.AnnotationProcessor#process(org.apache.felix.scrplugin.annotations.ScannedClass, org.apache.felix.scrplugin.description.ClassDescription) */ public void process(final ScannedClass scannedClass, final ClassDescription describedClass) throws SCRDescriptorException, SCRDescriptorFailureException { // forward do all processors for(final AnnotationProcessor ap : this.processors) { ap.process(scannedClass, describedClass); } }
/** * Create a new abstract description * @param annotation The corresponding annotation. */ public AbstractDescription(final ScannedAnnotation annotation) { this.annotation = annotation; if ( annotation == null ) { this.annotationPrefix = ""; } else { this.annotationPrefix = "@" + annotation.getSimpleName(); } this.sourceLocation = "<unknown>"; }
public int compare(AnnotationProcessor o1, AnnotationProcessor o2) { return Integer.valueOf(o1.getRanking()).compareTo(Integer.valueOf(o2.getRanking())); } });
/** * Get all class annotations * @param name The name of the class annotation or <code>null</code> * for all class annotations. * @return A list of matching annotations or an empty list. */ public List<ClassAnnotation> getClassAnnotations(final String name) { final List<ClassAnnotation> list = new ArrayList<ClassAnnotation>(); for(final ScannedAnnotation desc : descriptions ) { if ( desc instanceof ClassAnnotation ) { if ( name == null || desc.getName().equals(name) ) { list.add( (ClassAnnotation)desc); } } } return list; }
@Override public void process(final ScannedClass scannedClass, final ClassDescription classDescription) throws SCRDescriptorException, SCRDescriptorFailureException { final List<ClassAnnotation> healthChecks = scannedClass.getClassAnnotations(SlingHealthCheck.class.getName()); scannedClass.processed(healthChecks); for (final ClassAnnotation cad : healthChecks) { processHealthCheck(cad, classDescription); } }
/** * Get an integer value of the annotation * @param name The property name * @param defaultValue A default value if the property is not set * @return The property value or the default value. */ public int getIntegerValue(final String name, final int defaultValue) { final Object val = this.getValue(name); if ( val != null ) { return ((Integer) val).intValue(); } return defaultValue; }
private boolean isLongDefaultValue(final ClassAnnotation cad, String propName) { Object value = cad.getValue(propName); return value == null || ((Long) value) == -1; }
/** * Get a long value of the annotation * @param name The property name * @param defaultValue A default value if the property is not set * @return The property value or the default value. */ public long getLongValue(final String name, final long defaultValue) { final Object val = this.getValue(name); if ( val != null ) { return ((Long) val).intValue(); } return defaultValue; }
/** * Get an enumeration value of the annotation * @param name The property name * @param defaultValue A default value if the property is not set * @return The property value or the default value. */ public String getEnumValue(final String name, final String defaultValue) { final Object val = this.getValue(name); if ( val != null ) { if ( val instanceof String[] ) { return ((String[])val)[1]; } if ( val instanceof String[][] ) { return ((String[][])val)[0][1]; } return val.toString(); } return defaultValue; }
/** * Get a string value of the annotation * @param name The property name * @param defaultValue A default value if the property is not set * @return The property value or the default value. */ public String getStringValue(final String name, final String defaultValue) { final Object val = this.getValue(name); if ( val != null && val.toString().trim().length() > 0 ) { return val.toString().trim(); } return defaultValue; }