You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by cz...@apache.org on 2012/05/14 15:21:05 UTC
svn commit: r1338189 [3/4] - in /felix/sandbox/cziegeler:
eventadmin-tests/src/test/java/org/apache/felix/eventadmin/tests/
scrplugin/annotations/
scrplugin/annotations/src/main/java/org/apache/felix/scr/annotations/
scrplugin/annotations/src/main/java...
Copied: felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/helper/AnnotationProcessorManager.java (from r1332203, felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/tags/annotation/AnnotationTagProviderManager.java)
URL: http://svn.apache.org/viewvc/felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/helper/AnnotationProcessorManager.java?p2=felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/helper/AnnotationProcessorManager.java&p1=felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/tags/annotation/AnnotationTagProviderManager.java&r1=1332203&r2=1338189&rev=1338189&view=diff
==============================================================================
--- felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/tags/annotation/AnnotationTagProviderManager.java (original)
+++ felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/helper/AnnotationProcessorManager.java Mon May 14 13:21:02 2012
@@ -16,168 +16,135 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.felix.scrplugin.tags.annotation;
+package org.apache.felix.scrplugin.helper;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
import javax.imageio.spi.ServiceRegistry;
+import org.apache.felix.scrplugin.AnnotationProcessor;
+import org.apache.felix.scrplugin.SCRDescriptorException;
import org.apache.felix.scrplugin.SCRDescriptorFailureException;
-import org.apache.felix.scrplugin.tags.JavaField;
-import org.apache.felix.scrplugin.tags.JavaTag;
-
-import com.thoughtworks.qdox.model.Annotation;
-import com.thoughtworks.qdox.model.JavaClass;
+import org.apache.felix.scrplugin.description.ClassDescription;
+import org.apache.felix.scrplugin.scanner.ScannedClass;
/**
- * Supports mapping of built-in and custom java anntoations to {@link JavaTag}
- * implementations.
+ * Supports mapping of built-in and custom java annotations to
+ * descriptions.
*/
-public class AnnotationTagProviderManager
-{
+public class AnnotationProcessorManager implements AnnotationProcessor {
/**
* Allows to define additional implementations of the interface
- * {@link org.apache.felix.scrplugin.tags.annotation.AnnotationTagProvider}
- * that provide mappings from custom annotations to
- * {@link org.apache.felix.scrplugin.tags.JavaTag} implementations.
+ * {@linkAnnotationProcessor}
+ * that provide mappings from custom annotations to descriptions.
*/
- private final Map<String, AnnotationTagProvider> annotationTagProviders = new LinkedHashMap<String, AnnotationTagProvider>();
+ private final Map<String, AnnotationProcessor> processors = new HashMap<String, AnnotationProcessor>();
/**
- * @param annotationTagProviderClasses List of classes that implements
- * {@link AnnotationTagProvider} interface.
+ * Ordered list of processors
+ */
+ private final List<AnnotationProcessor> cachedProcessors = new ArrayList<AnnotationProcessor>();
+
+ /**
+ * @param annotationProcessorClasses List of classes that implements
+ * {@link AnnotationProcessor} interface.
* @throws SCRDescriptorFailureException
*/
- public AnnotationTagProviderManager(
- final String[] annotationTagProviderClasses,
+ public AnnotationProcessorManager(
+ final String[] annotationProcessorClasses,
final ClassLoader classLoader )
- throws SCRDescriptorFailureException
- {
+ throws SCRDescriptorFailureException {
// search for providers
- final Iterator<AnnotationTagProvider> serviceIter = ServiceRegistry.lookupProviders(AnnotationTagProvider.class, classLoader);
- while ( serviceIter.hasNext() )
- {
- final AnnotationTagProvider provider = serviceIter.next();
+ final Iterator<AnnotationProcessor> serviceIter = ServiceRegistry.lookupProviders(AnnotationProcessor.class, classLoader);
+ while ( serviceIter.hasNext() ) {
+ final AnnotationProcessor provider = serviceIter.next();
this.addProvider(provider);
}
- // add custom providers defined in pom
- for ( int i = 0; i < annotationTagProviderClasses.length; i++ )
- {
- loadProvider( classLoader, annotationTagProviderClasses[i], false );
+ // add custom processors defined in the tool (maven, ant...)
+ for ( int i = 0; i < annotationProcessorClasses.length; i++ ) {
+ loadProcessor( classLoader, annotationProcessorClasses[i], false );
}
- // always add provider supporting built-in SCR default properties (for compatibility with older
+ // always add processors supporting built-in SCR default properties (for compatibility with older
// annotation versions)
- loadProvider( classLoader,
- "org.apache.felix.scrplugin.tags.annotation.defaulttag.DefaultAnnotationTagProvider", true );
- loadProvider( classLoader,
- "org.apache.felix.scrplugin.tags.annotation.sling.SlingAnnotationTagProvider", true );
+ loadProcessor( classLoader,
+ "org.apache.felix.scrplugin.SCRAnnotationProcessor", true );
+ loadProcessor( classLoader,
+ "org.apache.felix.scrplugin.SlingAnnotationProcessor", true );
+
+ // create ordered list
+ for(final AnnotationProcessor pro : this.processors.values() ) {
+ this.cachedProcessors.add(pro);
+ }
+ Collections.sort(this.cachedProcessors, new Comparator<AnnotationProcessor>() {
+
+ public int compare(AnnotationProcessor o1, AnnotationProcessor o2) {
+ return Integer.valueOf(o1.getRanking()).compareTo(Integer.valueOf(o2.getRanking()));
+ }
+ });
+ }
+
+ /**
+ * @see org.apache.felix.scrplugin.AnnotationProcessor#process(org.apache.felix.scrplugin.scanner.ScannedClass, org.apache.felix.scrplugin.description.ClassDescription)
+ */
+ public void process(final ScannedClass scannedClass,
+ final ClassDescription describedClass)
+ throws SCRDescriptorException, SCRDescriptorFailureException {
+ for(final AnnotationProcessor ap : this.cachedProcessors) {
+ ap.process(scannedClass, describedClass);
+ }
}
/**
- * Add a provider (if not already available)
+ * @see org.apache.felix.scrplugin.AnnotationProcessor#getRanking()
*/
- private void addProvider(final AnnotationTagProvider provider)
- {
- // check if this provider is already loaded
- final String key = provider.getClass().getName();
- if ( !this.annotationTagProviders.containsKey(key) )
- {
- this.annotationTagProviders.put(key, provider);
+ public int getRanking() {
+ return 0;
+ }
+
+ /**
+ * Add a processor (if not already available)
+ */
+ private void addProvider(final AnnotationProcessor processor) {
+ // check if this processor is already loaded
+ final String key = processor.getClass().getName();
+ if ( !this.processors.containsKey(key) ) {
+ this.processors.put(key, processor);
}
}
- private void loadProvider( final ClassLoader classLoader, final String className, final boolean silent )
- throws SCRDescriptorFailureException
- {
+ private void loadProcessor( final ClassLoader classLoader, final String className, final boolean silent )
+ throws SCRDescriptorFailureException {
String failureMessage = null;
- try
- {
+ try {
Class<?> clazz = classLoader.loadClass( className );
- try
- {
- addProvider( ( AnnotationTagProvider ) clazz.newInstance() );
- }
- catch ( ClassCastException e )
- {
+ try {
+ addProvider( ( AnnotationProcessor ) clazz.newInstance() );
+ } catch ( final ClassCastException e ) {
failureMessage = "Class '" + clazz.getName() + "' " + "does not implement interface '"
- + AnnotationTagProvider.class.getName() + "'.";
- }
- catch ( InstantiationException e )
- {
+ + AnnotationProcessor.class.getName() + "'.";
+ } catch ( final InstantiationException e ) {
failureMessage = "Unable to instantiate class '" + clazz.getName() + "': " + e.getMessage();
- }
- catch ( IllegalAccessException e )
- {
+ } catch ( final IllegalAccessException e ) {
failureMessage = "Illegal access to class '" + clazz.getName() + "': " + e.getMessage();
}
- }
- catch ( ClassNotFoundException e )
- {
+ } catch ( final ClassNotFoundException e ) {
failureMessage = "Annotation provider class '" + className + "' not found.";
}
// throw an optional exception if not required to remaing silent
- if ( failureMessage != null && !silent )
- {
+ if ( failureMessage != null && !silent ) {
throw new SCRDescriptorFailureException( failureMessage );
}
}
-
-
- /**
- * Converts a java annotation to {@link JavaTag} if a mapping can be found.
- *
- * @param annotation Java annotation
- * @param description Description
- * @return Tag declaration or null if no mapping found
- */
- public List<JavaTag> getTags( Annotation annotation, AnnotationJavaClassDescription description )
- {
- return getTags( annotation, description, null );
- }
-
-
- /**
- * Converts a java annotation to {@link JavaTag} if a mapping can be found.
- *
- * @param annotation Java annotation
- * @param description Description
- * @param field Field
- * @return Tag declaration or null if no mapping found
- */
- public List<JavaTag> getTags( Annotation annotation, AnnotationJavaClassDescription description, JavaField field )
- {
- List<JavaTag> tags = new ArrayList<JavaTag>();
-
- for ( AnnotationTagProvider provider : this.annotationTagProviders.values() )
- {
- tags.addAll( provider.getTags( annotation, description, field ) );
- }
-
- return tags;
- }
-
-
- /**
- * Checks if the given class has any SCR plugin java annotations defined.
- *
- * @param pClass Class
- * @return true if SCR plugin java annotation found
- */
- public boolean hasScrPluginAnnotation( final JavaClass pClass, final AnnotationJavaClassDescription description )
- {
- for ( com.thoughtworks.qdox.model.Annotation annotation : pClass.getAnnotations() )
- {
- if ( getTags( annotation, description ).size() > 0 )
- {
- return true;
- }
- }
- return false;
- }
}
Propchange: felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/helper/AnnotationProcessorManager.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/helper/AnnotationProcessorManager.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision Rev Url
Propchange: felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/helper/AnnotationProcessorManager.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/helper/ClassScanner.java
URL: http://svn.apache.org/viewvc/felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/helper/ClassScanner.java?rev=1338189&view=auto
==============================================================================
--- felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/helper/ClassScanner.java (added)
+++ felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/helper/ClassScanner.java Mon May 14 13:21:02 2012
@@ -0,0 +1,238 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.scrplugin.helper;
+
+import static org.objectweb.asm.ClassReader.SKIP_CODE;
+import static org.objectweb.asm.ClassReader.SKIP_DEBUG;
+import static org.objectweb.asm.ClassReader.SKIP_FRAMES;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.lang.reflect.Array;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.felix.scrplugin.AnnotationProcessor;
+import org.apache.felix.scrplugin.Log;
+import org.apache.felix.scrplugin.Project;
+import org.apache.felix.scrplugin.SCRDescriptorException;
+import org.apache.felix.scrplugin.SCRDescriptorFailureException;
+import org.apache.felix.scrplugin.description.ClassDescription;
+import org.apache.felix.scrplugin.description.ComponentDescription;
+import org.apache.felix.scrplugin.scanner.ClassAnnotation;
+import org.apache.felix.scrplugin.scanner.FieldAnnotation;
+import org.apache.felix.scrplugin.scanner.MethodAnnotation;
+import org.apache.felix.scrplugin.scanner.ScannedAnnotation;
+import org.apache.felix.scrplugin.scanner.ScannedClass;
+import org.apache.felix.scrplugin.scanner.Source;
+import org.objectweb.asm.ClassReader;
+import org.objectweb.asm.Type;
+import org.objectweb.asm.tree.AnnotationNode;
+import org.objectweb.asm.tree.ClassNode;
+import org.objectweb.asm.tree.FieldNode;
+import org.objectweb.asm.tree.MethodNode;
+
+public class ClassScanner {
+
+ /**
+ * Scan all class files for annotations and process them.
+ */
+ public void execute(final Log log,
+ final Project project,
+ final AnnotationProcessor aProcessor)
+ throws SCRDescriptorException, SCRDescriptorFailureException {
+
+ for(final Source src : project.getSources()) {
+ log.debug("Scanning class " + src.getClassName());
+
+ try {
+ // load the class
+ final Class<?> annotatedClass = project.getClassLoader().loadClass(src.getClassName());
+ // get the class file for ASM
+ final String pathToClassFile = src.getClassName().replace('.', '/') + ".class";
+ final InputStream input = project.getClassLoader().getResourceAsStream(pathToClassFile);
+ final ClassReader classReader;
+ try {
+ classReader = new ClassReader(input);
+ } finally {
+ input.close();
+ }
+ final ClassNode classNode = new ClassNode();
+ classReader.accept(classNode, SKIP_CODE | SKIP_DEBUG | SKIP_FRAMES);
+
+ // create descriptions
+ final List<ScannedAnnotation> descriptions = extractAnnotation(classNode, annotatedClass);
+ if ( descriptions.size() > 0 ) {
+ // process descriptions
+ final ClassDescription desc = new ClassDescription(annotatedClass, src.getFile().toString());
+ aProcessor.process(new ScannedClass(descriptions, annotatedClass), desc);
+ if ( desc.getDescriptions(ComponentDescription.class).size() > 0 ) {
+ log.info("Found " + desc);
+ }
+ }
+ } catch (final ClassNotFoundException cnfe) {
+ throw new SCRDescriptorFailureException("Unable to load compiled class: " + src.getClassName(), cnfe);
+ } catch (final IOException ioe) {
+ throw new SCRDescriptorFailureException("Unable to scan class files: " + src.getClassName(), ioe);
+ }
+ }
+ }
+
+ /**
+ * Extract annotations
+ */
+ private final List<ScannedAnnotation> extractAnnotation(final ClassNode classNode, final Class<?> annotatedClass) {
+ final List<ScannedAnnotation> descriptions = new ArrayList<ScannedAnnotation>();
+ // first parse class annotations
+ @SuppressWarnings("unchecked")
+ final List<AnnotationNode> annotations = classNode.invisibleAnnotations;
+ if ( annotations != null ) {
+ for (final AnnotationNode annotation : annotations) {
+ this.parseAnnotation(descriptions, annotation, annotatedClass);
+ }
+
+ // second parse method annotations
+ @SuppressWarnings("unchecked")
+ final List<MethodNode> methods = classNode.methods;
+ if ( methods != null ) {
+ for(final MethodNode method : methods) {
+ @SuppressWarnings("unchecked")
+ final List<AnnotationNode> annos = method.invisibleAnnotations;
+ if ( annos != null ) {
+ // TODO - check signature and throw if not found!
+ final String name = method.name;
+ final Method[] allMethods = annotatedClass.getDeclaredMethods();
+ Method found = null;
+ for(final Method m : allMethods) {
+ if ( m.getName().equals(name) ) {
+ found = m;
+ }
+ }
+ for (final AnnotationNode annotation : annos) {
+ parseAnnotation(descriptions, annotation, found);
+ }
+ }
+ }
+ }
+
+ // third parse field annotations
+ @SuppressWarnings("unchecked")
+ final List<FieldNode> fields = classNode.fields;
+ if ( fields != null ) {
+ for(final FieldNode field : fields) {
+ @SuppressWarnings("unchecked")
+ final List<AnnotationNode> annos = field.invisibleAnnotations;
+ if ( annos != null ) {
+ // TODO - throw if not found
+ final String name = field.name;
+ final Field[] allFields = annotatedClass.getDeclaredFields();
+ Field found = null;
+ for(final Field f : allFields) {
+ if ( f.getName().equals(name) ) {
+ found = f;
+ }
+ }
+ for (final AnnotationNode annotation : annos) {
+ parseAnnotation(descriptions, annotation, found);
+ }
+ }
+ }
+ }
+ }
+ return descriptions;
+ }
+
+ private <T> T[] convertToArray(final List<?> values, final Class<T> type) {
+ @SuppressWarnings("unchecked")
+ final T[] result = (T[]) Array.newInstance(type, values.size());
+ return values.toArray(result);
+ }
+
+ /**
+ * Parse annotation and create a description.
+ */
+ private void parseAnnotation(final List<ScannedAnnotation> descriptions,
+ final AnnotationNode annotation,
+ final Object annotatedObject) {
+ // desc has the format 'L' + className.replace('.', '/') + ';'
+ final String name = annotation.desc.substring(1, annotation.desc.length() - 1).replace('/', '.');
+ Map<String, Object> values = null;
+ if ( annotation.values != null ) {
+ values = new HashMap<String, Object>();
+ final Iterator<?> i = annotation.values.iterator();
+ while ( i.hasNext() ) {
+ final Object vName = i.next();
+ Object value = i.next();
+
+ // convert type to class name string
+ if ( value instanceof Type ) {
+ value = ((Type)value).getClassName();
+ } else if ( value instanceof List<?> ) {
+ final List<?> objects = (List<?>)value;
+ if ( objects.size() > 0 ) {
+ if ( objects.get(0) instanceof Type ) {
+ final String[] classNames = new String[objects.size()];
+ int index = 0;
+ for(final Object v : objects) {
+ classNames[index] = ((Type)v).getClassName();
+ index++;
+ }
+ value = classNames;
+ } else if ( objects.get(0) instanceof AnnotationNode ) {
+ final List<ScannedAnnotation> innerDesc = new ArrayList<ScannedAnnotation>();
+ for(final Object v : objects) {
+ parseAnnotation(innerDesc, (AnnotationNode)v, annotatedObject);
+ }
+ if ( annotatedObject instanceof Method ) {
+ value = innerDesc.toArray(new MethodAnnotation[innerDesc.size()]);
+ } else if ( annotatedObject instanceof Field ) {
+ value = innerDesc.toArray(new FieldAnnotation[innerDesc.size()]);
+ } else {
+ value = innerDesc.toArray(new ClassAnnotation[innerDesc.size()]);
+ }
+ } else {
+ value = convertToArray(objects, objects.get(0).getClass());
+ }
+ } else {
+ value = null;
+ }
+ }
+
+ values.put(vName.toString(), value);
+ }
+ }
+
+ final ScannedAnnotation a;
+ if ( annotatedObject instanceof Method ) {
+ a = new MethodAnnotation(name, values, (Method) annotatedObject);
+ ((Method) annotatedObject).setAccessible(true);
+ } else if ( annotatedObject instanceof Field ) {
+ a = new FieldAnnotation(name, values, (Field) annotatedObject);
+ ((Field) annotatedObject).setAccessible(true);
+ } else {
+ a = new ClassAnnotation(name, values);
+ }
+ descriptions.add(a);
+ }
+}
Propchange: felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/helper/ClassScanner.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/helper/ClassScanner.java
------------------------------------------------------------------------------
svn:keywords = author date id revision rev url
Propchange: felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/helper/ClassScanner.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/om/AbstractObject.java
URL: http://svn.apache.org/viewvc/felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/om/AbstractObject.java?rev=1338189&r1=1338188&r2=1338189&view=diff
==============================================================================
--- felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/om/AbstractObject.java (original)
+++ felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/om/AbstractObject.java Mon May 14 13:21:02 2012
@@ -19,7 +19,6 @@
package org.apache.felix.scrplugin.om;
import org.apache.felix.scrplugin.helper.IssueLog;
-import org.apache.felix.scrplugin.tags.JavaTag;
/**
* The <code>AbstractObject</code>
@@ -27,21 +26,23 @@ import org.apache.felix.scrplugin.tags.J
*/
public abstract class AbstractObject {
- protected final JavaTag tag;
+ private final String annotationName;
- protected AbstractObject(JavaTag tag) {
- this.tag = tag;
+ private final String sourceLocation;
+
+ private final int lineNumber;
+
+ protected AbstractObject(final String annotationName, final String sourceLocation, final int lineNumber) {
+ this.annotationName = annotationName;
+ this.sourceLocation = sourceLocation;
+ this.lineNumber = lineNumber;
}
protected void logWarn(IssueLog iLog, String message) {
- iLog.addWarning( "@" + this.tag.getSourceName() + ": " + message, tag.getSourceLocation(), tag.getLineNumber() );
+ iLog.addWarning( "@" + this.annotationName + ": " + message, sourceLocation, lineNumber );
}
protected void logError(IssueLog iLog, String message) {
- iLog.addError( "@" + this.tag.getSourceName() + ": " + message, tag.getSourceLocation(), tag.getLineNumber() );
- }
-
- public JavaTag getJavaTag() {
- return this.tag;
+ iLog.addError( "@" + this.annotationName + ": " + message, sourceLocation, lineNumber );
}
}
Modified: felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/om/Component.java
URL: http://svn.apache.org/viewvc/felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/om/Component.java?rev=1338189&r1=1338188&r2=1338189&view=diff
==============================================================================
--- felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/om/Component.java (original)
+++ felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/om/Component.java Mon May 14 13:21:02 2012
@@ -18,13 +18,13 @@
*/
package org.apache.felix.scrplugin.om;
+import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.List;
import org.apache.felix.scrplugin.Constants;
import org.apache.felix.scrplugin.SCRDescriptorException;
import org.apache.felix.scrplugin.helper.IssueLog;
-import org.apache.felix.scrplugin.tags.*;
/**
* <code>Component</code>
@@ -82,14 +82,14 @@ public class Component extends AbstractO
* Default constructor.
*/
public Component() {
- this(null);
+ this(null, null, -1);
}
/**
* Constructor from java source.
*/
- public Component(JavaTag t) {
- super(t);
+ public Component(final String annotationName, final String sourceLocation, final int lineNumber) {
+ super(annotationName, sourceLocation, lineNumber);
}
/**
@@ -110,16 +110,6 @@ public class Component extends AbstractO
}
/**
- * Return the associated java class description
- */
- public JavaClassDescription getJavaClassDescription() {
- if ( this.tag != null ) {
- return this.tag.getJavaClassDescription();
- }
- return null;
- }
-
- /**
* @return All properties of this component.
*/
public List<Property> getProperties() {
@@ -257,95 +247,90 @@ public class Component extends AbstractO
* If errors occur a message is added to the issues list,
* warnings can be added to the warnings list.
*/
- public void validate(final int specVersion, final IssueLog iLog)
+ public void validate(final Context context)
throws SCRDescriptorException {
- final int currentIssueCount = iLog.getNumberOfErrors();
-
// nothing to check if this is ignored
if (!isDs()) {
return;
}
- final JavaClassDescription javaClass = this.tag.getJavaClassDescription();
- if (javaClass == null) {
- this.logError( iLog, "Tag not declared in a Java Class" );
- } else {
-
- // if the service is abstract, we do not validate everything
- if ( !this.isAbstract ) {
- // ensure non-abstract, public class
- if (!javaClass.isPublic()) {
- this.logError( iLog, "Class must be public: " + javaClass.getName() );
- }
- if (javaClass.isAbstract() || javaClass.isInterface()) {
- this.logError( iLog, "Class must be concrete class (not abstract or interface) : " + javaClass.getName() );
- }
+ final int currentIssueCount = context.getIssueLog().getNumberOfErrors();
- // no errors so far, let's continue
- if ( iLog.getNumberOfErrors() == currentIssueCount ) {
- final String activateName = this.activate == null ? "activate" : this.activate;
- final String deactivateName = this.deactivate == null ? "deactivate" : this.deactivate;
-
- // check activate and deactivate methods
- this.checkLifecycleMethod(specVersion, javaClass, activateName, true, iLog);
- this.checkLifecycleMethod(specVersion, javaClass, deactivateName, false, iLog);
+ // if the service is abstract, we do not validate everything
+ if ( !this.isAbstract ) {
+ // ensure non-abstract, public class
+ if (!Modifier.isPublic(context.getClassDescription().getDescribedClass().getModifiers()) ) {
+ this.logError( context.getIssueLog(), "Class must be public: " + context.getClassDescription().getDescribedClass().getName() );
+ }
+ if (Modifier.isAbstract(context.getClassDescription().getDescribedClass().getModifiers()) || context.getClassDescription().getDescribedClass().isInterface()) {
+ this.logError( context.getIssueLog(), "Class must be concrete class (not abstract or interface) : " + context.getClassDescription().getDescribedClass().getName() );
+ }
- if ( this.modified != null && specVersion >= Constants.VERSION_1_1 ) {
- this.checkLifecycleMethod(specVersion, javaClass, this.modified, true, iLog);
- }
- // ensure public default constructor
- boolean constructorFound = true;
- JavaMethod[] methods = javaClass.getMethods();
- for (int i = 0; methods != null && i < methods.length; i++) {
- if (methods[i].isConstructor()) {
- // if public default, succeed
- if (methods[i].isPublic()
- && (methods[i].getParameters() == null || methods[i].getParameters().length == 0)) {
- constructorFound = true;
- break;
- }
+ // no errors so far, let's continue
+ if ( context.getIssueLog().getNumberOfErrors() == currentIssueCount ) {
+ final String activateName = this.activate == null ? "activate" : this.activate;
+ final String deactivateName = this.deactivate == null ? "deactivate" : this.deactivate;
+
+ // check activate and deactivate methods
+ this.checkLifecycleMethod(specVersion, javaClass, activateName, true, iLog);
+ this.checkLifecycleMethod(specVersion, javaClass, deactivateName, false, iLog);
- // non-public/non-default constructor found, must have explicit
- constructorFound = false;
+ if ( this.modified != null && specVersion >= Constants.VERSION_1_1 ) {
+ this.checkLifecycleMethod(specVersion, javaClass, this.modified, true, iLog);
+ }
+ // ensure public default constructor
+ boolean constructorFound = true;
+ JavaMethod[] methods = javaClass.getMethods();
+ for (int i = 0; methods != null && i < methods.length; i++) {
+ if (methods[i].isConstructor()) {
+ // if public default, succeed
+ if (methods[i].isPublic()
+ && (methods[i].getParameters() == null || methods[i].getParameters().length == 0)) {
+ constructorFound = true;
+ break;
}
- }
- if (!constructorFound) {
- this.logError( iLog, "Class must have public default constructor: " + javaClass.getName() );
- }
- // verify properties
- for(final Property prop : this.getProperties()) {
- prop.validate(specVersion, iLog);
+ // non-public/non-default constructor found, must have explicit
+ constructorFound = false;
}
+ }
+ if (!constructorFound) {
+ this.logError( context.getIssueLog(), "Class must have public default constructor: " + javaClass.getName() );
+ }
- // verify service
- boolean isServiceFactory = false;
- if (this.getService() != null) {
- if ( this.getService().getInterfaces().size() == 0 ) {
- this.logError( iLog, "Service interface information is missing!" );
- }
- this.getService().validate(specVersion, iLog);
- isServiceFactory = this.getService().isServicefactory();
- }
+ // verify properties
+ for(final Property prop : this.getProperties()) {
+ prop.validate(specVersion, context.getIssueLog());
+ }
- // serviceFactory must not be true for immediate of component factory
- if (isServiceFactory && this.isImmediate() != null && this.isImmediate().booleanValue() && this.getFactory() != null) {
- this.logError( iLog, "Component must not be a ServiceFactory, if immediate and/or component factory: " + javaClass.getName() );
+ // verify service
+ boolean isServiceFactory = false;
+ if (this.getService() != null) {
+ if ( this.getService().getInterfaces().size() == 0 ) {
+ this.logError( context.getIssueLog(), "Service interface information is missing!" );
}
+ this.getService().validate(context);
+ isServiceFactory = this.getService().isServicefactory();
+ }
- // immediate must not be true for component factory
- if (this.isImmediate() != null && this.isImmediate().booleanValue() && this.getFactory() != null) {
- this.logError( iLog, "Component must not be immediate if component factory: " + javaClass.getName() );
- }
+ // serviceFactory must not be true for immediate of component factory
+ if (isServiceFactory && this.isImmediate() != null && this.isImmediate().booleanValue() && this.getFactory() != null) {
+ this.logError( context.getIssueLog(), "Component must not be a ServiceFactory, if immediate and/or component factory: " + javaClass.getName() );
}
- }
- if ( iLog.getNumberOfErrors() == currentIssueCount ) {
- // verify references
- for(final Reference ref : this.getReferences()) {
- ref.validate(specVersion, this.isAbstract, iLog);
+
+ // immediate must not be true for component factory
+ if (this.isImmediate() != null && this.isImmediate().booleanValue() && this.getFactory() != null) {
+ this.logError( context.getIssueLog(), "Component must not be immediate if component factory: " + javaClass.getName() );
}
}
}
+ if ( context.getIssueLog().getNumberOfErrors() == currentIssueCount ) {
+ // verify references
+ for(final Reference ref : this.getReferences()) {
+ ref.validate(context, this.isAbstract);
+ }
+ }
+
// check additional stuff if version is 1.1
if ( specVersion >= Constants.VERSION_1_1 ) {
final String cp = this.getConfigurationPolicy();
Modified: felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/om/Components.java
URL: http://svn.apache.org/viewvc/felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/om/Components.java?rev=1338189&r1=1338188&r2=1338189&view=diff
==============================================================================
--- felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/om/Components.java (original)
+++ felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/om/Components.java Mon May 14 13:21:02 2012
@@ -21,6 +21,8 @@ package org.apache.felix.scrplugin.om;
import java.util.ArrayList;
import java.util.List;
+import org.apache.felix.scrplugin.description.SpecVersion;
+
/**
* <code>Components</code>...
*
@@ -29,10 +31,10 @@ import java.util.List;
public class Components {
/** The spec version. */
- private int specVersion;
+ private SpecVersion specVersion;
/** The list of {@link Component}s. */
- protected List<Component> components = new ArrayList<Component>();
+ private List<Component> components = new ArrayList<Component>();
/**
* Return the list of {@link Component}s.
@@ -58,14 +60,14 @@ public class Components {
/**
* Get the spec version.
*/
- public int getSpecVersion() {
+ public SpecVersion getSpecVersion() {
return this.specVersion;
}
/**
* Set the spec version.
*/
- public void setSpecVersion(int value) {
+ public void setSpecVersion(SpecVersion value) {
this.specVersion = value;
}
}
Added: felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/om/Context.java
URL: http://svn.apache.org/viewvc/felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/om/Context.java?rev=1338189&view=auto
==============================================================================
--- felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/om/Context.java (added)
+++ felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/om/Context.java Mon May 14 13:21:02 2012
@@ -0,0 +1,67 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.scrplugin.om;
+
+import org.apache.felix.scrplugin.Project;
+import org.apache.felix.scrplugin.description.ClassDescription;
+import org.apache.felix.scrplugin.description.SpecVersion;
+import org.apache.felix.scrplugin.helper.IssueLog;
+
+public class Context {
+
+ private Project project;
+
+ private IssueLog issueLog;
+
+ private SpecVersion specVersion;
+
+ private ClassDescription classDescription;
+
+ public Project getProject() {
+ return project;
+ }
+
+ public void setProject(Project project) {
+ this.project = project;
+ }
+
+ public IssueLog getIssueLog() {
+ return issueLog;
+ }
+
+ public void setIssueLog(IssueLog issueLog) {
+ this.issueLog = issueLog;
+ }
+
+ public SpecVersion getSpecVersion() {
+ return specVersion;
+ }
+
+ public void setSpecVersion(SpecVersion specVersion) {
+ this.specVersion = specVersion;
+ }
+
+ public ClassDescription getClassDescription() {
+ return classDescription;
+ }
+
+ public void setClassDescription(ClassDescription classDescription) {
+ this.classDescription = classDescription;
+ }
+}
Propchange: felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/om/Context.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/om/Context.java
------------------------------------------------------------------------------
svn:keywords = author date id revision rev url
Propchange: felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/om/Context.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/om/Implementation.java
URL: http://svn.apache.org/viewvc/felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/om/Implementation.java?rev=1338189&r1=1338188&r2=1338189&view=diff
==============================================================================
--- felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/om/Implementation.java (original)
+++ felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/om/Implementation.java Mon May 14 13:21:02 2012
@@ -19,30 +19,24 @@
package org.apache.felix.scrplugin.om;
/**
- * <code>Implementation</code>...
+ * <code>Implementation</code>
*
* contains the class name implementing the component.
*/
public class Implementation {
/** The class name. */
- protected String classname;
+ private String className;
- public Implementation() {
- // nothing to do
+ public Implementation(final String name) {
+ this.className = name;
}
- public Implementation(String name) {
- this.classname = name;
+ public String getClassName() {
+ return this.className;
}
- public String getClassame() {
- return this.classname;
+ public void setClassName(final String name) {
+ this.className = name;
}
-
- public void setClassname(String name) {
- this.classname = name;
- }
-
-
}
Modified: felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/om/Interface.java
URL: http://svn.apache.org/viewvc/felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/om/Interface.java?rev=1338189&r1=1338188&r2=1338189&view=diff
==============================================================================
--- felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/om/Interface.java (original)
+++ felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/om/Interface.java Mon May 14 13:21:02 2012
@@ -19,38 +19,44 @@
package org.apache.felix.scrplugin.om;
import org.apache.felix.scrplugin.SCRDescriptorException;
-import org.apache.felix.scrplugin.helper.IssueLog;
-import org.apache.felix.scrplugin.tags.JavaClassDescription;
-import org.apache.felix.scrplugin.tags.JavaTag;
/**
- * <code>Interface.java</code>...
+ * <code>Interface</code>
*
+ * contains an interface name the component is implementing
+ * (the interface name can also be a class name)
*/
public class Interface extends AbstractObject {
- protected String interfacename;
+ /** Name of the interface. */
+ private String interfaceName;
/**
* Default constructor.
*/
public Interface() {
- this(null);
+ this(null, null, -1);
}
/**
* Constructor from java source.
*/
- public Interface(JavaTag t) {
- super(t);
+ public Interface(final String annotationName, final String sourceLocation, final int lineNumber) {
+ super(annotationName, sourceLocation, lineNumber);
}
- public String getInterfacename() {
- return this.interfacename;
+ /**
+ * Get the interface name.
+ */
+ public String getInterfaceName() {
+ return this.interfaceName;
}
- public void setInterfacename(String name) {
- this.interfacename = name;
+ /**
+ * Set the interface name.
+ */
+ public void setInterfaceName(final String name) {
+ this.interfaceName = name;
}
/**
@@ -58,16 +64,19 @@ public class Interface extends AbstractO
* If errors occur a message is added to the issues list,
* warnings can be added to the warnings list.
*/
- public void validate(final int specVersion, final IssueLog iLog)
+ public void validate(final Context context)
throws SCRDescriptorException {
- final JavaClassDescription javaClass = this.tag.getJavaClassDescription();
- if (javaClass == null) {
- this.logError( iLog, "Must be declared in a Java class" );
+ if (context.getClassDescription().getDescribedClass().isInterface()) {
+ this.logError( context.getIssueLog(), "Must be declared in a Java class - not an interface" );
} else {
-
- if ( !javaClass.isA(this.getInterfacename()) ) {
- // interface not implemented
- this.logError( iLog, "Class must implement provided interface " + this.getInterfacename() );
+ try {
+ final Class<?> interfaceClass = context.getProject().getClassLoader().loadClass(this.interfaceName);
+ if ( !interfaceClass.isAssignableFrom(context.getClassDescription().getDescribedClass()) ) {
+ // interface not implemented
+ this.logError( context.getIssueLog(), "Class must implement provided interface " + this.interfaceName);
+ }
+ } catch (final ClassNotFoundException cnfe) {
+ throw new SCRDescriptorException("Unable to load interface class.", cnfe);
}
}
}
Modified: felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/om/Property.java
URL: http://svn.apache.org/viewvc/felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/om/Property.java?rev=1338189&r1=1338188&r2=1338189&view=diff
==============================================================================
--- felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/om/Property.java (original)
+++ felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/om/Property.java Mon May 14 13:21:02 2012
@@ -19,8 +19,8 @@
package org.apache.felix.scrplugin.om;
import org.apache.felix.scrplugin.Constants;
-import org.apache.felix.scrplugin.helper.IssueLog;
-import org.apache.felix.scrplugin.tags.JavaTag;
+import org.apache.felix.scrplugin.description.PropertyType;
+import org.apache.felix.scrplugin.description.SpecVersion;
/**
* <code>Property.java</code>...
@@ -42,14 +42,14 @@ public class Property extends AbstractOb
* Default constructor.
*/
public Property() {
- this(null);
+ this(null, null, -1);
}
/**
* Constructor from java source.
*/
- public Property(JavaTag t) {
- super(t);
+ public Property(final String annotationName, final String sourceLocation, final int lineNumber) {
+ super(annotationName, sourceLocation, lineNumber);
}
public String getName() {
@@ -91,28 +91,21 @@ public class Property extends AbstractOb
* If errors occur a message is added to the issues list,
* warnings can be added to the warnings list.
*/
- public void validate(final int specVersion, final IssueLog iLog) {
+ public void validate(final Context context) {
if ( name == null || name.trim().length() == 0 ) {
- this.logError( iLog, "Property name can not be empty." );
+ this.logError( context.getIssueLog(), "Property name can not be empty." );
}
if ( type != null ) {
- if ( !type.equals(Constants.PROPERTY_TYPE_BOOLEAN)
- && !type.equals(Constants.PROPERTY_TYPE_BYTE )
- && !type.equals(Constants.PROPERTY_TYPE_CHAR )
- && !type.equals(Constants.PROPERTY_TYPE_CHAR_1_1 )
- && !type.equals(Constants.PROPERTY_TYPE_DOUBLE )
- && !type.equals(Constants.PROPERTY_TYPE_FLOAT )
- && !type.equals(Constants.PROPERTY_TYPE_INTEGER )
- && !type.equals(Constants.PROPERTY_TYPE_LONG )
- && !type.equals(Constants.PROPERTY_TYPE_STRING )
- && !type.equals(Constants.PROPERTY_TYPE_SHORT ) ) {
- this.logError( iLog, "Property " + name + " has unknown type: " + type );
+ try {
+ PropertyType.valueOf(this.type);
+ } catch (final IllegalArgumentException iae) {
+ this.logError( context.getIssueLog(), "Property " + name + " has unknown type: " + type );
}
// now check for old and new char
- if ( specVersion == Constants.VERSION_1_0 && type.equals(Constants.PROPERTY_TYPE_CHAR_1_1) ) {
+ if ( context.getSpecVersion() == SpecVersion.VERSION_1_0 && type.equals(Constants.PROPERTY_TYPE_CHAR_1_1) ) {
type = Constants.PROPERTY_TYPE_CHAR;
}
- if ( specVersion >= Constants.VERSION_1_1 && type.equals(Constants.PROPERTY_TYPE_CHAR) ) {
+ if ( context.getSpecVersion().ordinal() >= SpecVersion.VERSION_1_1.ordinal() && type.equals(Constants.PROPERTY_TYPE_CHAR) ) {
type = Constants.PROPERTY_TYPE_CHAR_1_1;
}
}
Modified: felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/om/Reference.java
URL: http://svn.apache.org/viewvc/felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/om/Reference.java?rev=1338189&r1=1338188&r2=1338189&view=diff
==============================================================================
--- felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/om/Reference.java (original)
+++ felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/om/Reference.java Mon May 14 13:21:02 2012
@@ -22,7 +22,6 @@ import org.apache.felix.scrplugin.Consta
import org.apache.felix.scrplugin.SCRDescriptorException;
import org.apache.felix.scrplugin.helper.IssueLog;
import org.apache.felix.scrplugin.helper.StringUtils;
-import org.apache.felix.scrplugin.tags.*;
/**
* <code>Reference.java</code>...
@@ -42,25 +41,18 @@ public class Reference extends AbstractO
/** @since 1.0.9 */
protected String strategy;
- /** Is this reference already checked? */
- protected boolean checked = false;
-
- /** The class description containing this reference. */
- protected final JavaClassDescription javaClassDescription;
-
/**
* Default constructor.
*/
public Reference() {
- this(null, null);
+ this(null, null, -1);
}
/**
* Constructor from java source.
*/
- public Reference(JavaTag t, JavaClassDescription desc) {
- super(t);
- this.javaClassDescription = desc;
+ public Reference(final String annotationName, final String sourceLocation, final int lineNumber) {
+ super(annotationName, sourceLocation, lineNumber);
}
public String getName() {
@@ -155,14 +147,9 @@ public class Reference extends AbstractO
* If errors occur a message is added to the issues list,
* warnings can be added to the warnings list.
*/
- public void validate(final int specVersion,
- final boolean componentIsAbstract,
- final IssueLog iLog)
+ public void validate(final Context context,
+ final boolean componentIsAbstract)
throws SCRDescriptorException {
- // if this reference is already checked, return immediately
- if ( this.checked ) {
- return;
- }
final int currentIssueCount = iLog.getNumberOfErrors();
// validate name
@@ -182,14 +169,14 @@ public class Reference extends AbstractO
this.cardinality = "1..1";
} else if (!"0..1".equals(this.cardinality) && !"1..1".equals(this.cardinality)
&& !"0..n".equals(this.cardinality) && !"1..n".equals(this.cardinality)) {
- this.logError( iLog, "Invalid Cardinality specification " + this.cardinality );
+ this.logError( context.getIssueLog(), "Invalid Cardinality specification " + this.cardinality );
}
// validate policy
if (this.policy == null) {
this.policy = "static";
} else if (!"static".equals(this.policy) && !"dynamic".equals(this.policy)) {
- this.logError( iLog, "Invalid Policy specification " + this.policy );
+ this.logError( context.getIssueLog(), "Invalid Policy specification " + this.policy );
}
// validate strategy
@@ -213,7 +200,7 @@ public class Reference extends AbstractO
final String oldUnbind = this.unbind;
this.bind = this.validateMethod(specVersion, this.bind, componentIsAbstract, iLog);
this.unbind = this.validateMethod(specVersion, this.unbind, componentIsAbstract, iLog);
- if ( iLog.getNumberOfErrors() == currentIssueCount ) {
+ if ( context.getIssueLog().getNumberOfErrors() == currentIssueCount ) {
if ( this.bind != null && this.unbind != null ) {
// no errors, so we're checked
this.checked = true;
Modified: felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/om/Service.java
URL: http://svn.apache.org/viewvc/felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/om/Service.java?rev=1338189&r1=1338188&r2=1338189&view=diff
==============================================================================
--- felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/om/Service.java (original)
+++ felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/om/Service.java Mon May 14 13:21:02 2012
@@ -23,40 +23,37 @@ import java.util.Iterator;
import java.util.List;
import org.apache.felix.scrplugin.SCRDescriptorException;
-import org.apache.felix.scrplugin.helper.IssueLog;
/**
- * <code>Service</code>...
+ * <code>Service</code>
*
+ * contains all service information of a component.
*/
public class Service {
- protected boolean isServicefactory;
+ /** Flag for the service factory. */
+ private boolean isServiceFactory;
/** The list of implemented interfaces. */
- protected final List<Interface> interfaces = new ArrayList<Interface>();
+ private final List<Interface> interfaces = new ArrayList<Interface>();
/**
- * Default constructor.
+ * Is this a service factory?
*/
- public Service() {
- // nothing to do
+ public boolean isServiceFactory() {
+ return this.isServiceFactory;
}
- public boolean isServicefactory() {
- return this.isServicefactory;
- }
-
- public void setServicefactory(String servicefactory) {
- if ( servicefactory != null ) {
- this.isServicefactory = Boolean.valueOf(servicefactory).booleanValue();
- }
- }
-
- public void setServicefactory(boolean flag) {
- this.isServicefactory = flag;
+ /**
+ * Set the service factory flag.
+ */
+ public void setServicefactory(final boolean flag) {
+ this.isServiceFactory = flag;
}
+ /**
+ * Return the list of interfaces.
+ */
public List<Interface> getInterfaces() {
return this.interfaces;
}
@@ -66,11 +63,11 @@ public class Service {
* @param name The name of the interface.
* @return The interface if it is implemented by this service or null.
*/
- public Interface findInterface(String name) {
+ public Interface findInterface(final String name) {
final Iterator<Interface> i = this.getInterfaces().iterator();
while ( i.hasNext() ) {
final Interface current = i.next();
- if ( current.getInterfacename().equals(name) ) {
+ if ( current.getInterfaceName().equals(name) ) {
return current;
}
}
@@ -81,9 +78,9 @@ public class Service {
* Add an interface to the list of interfaces.
* @param interf The interface.
*/
- public void addInterface(Interface interf) {
+ public void addInterface(final Interface interf) {
// add interface only once
- if ( this.findInterface(interf.getInterfacename()) == null ) {
+ if ( this.findInterface(interf.getInterfaceName()) == null ) {
this.interfaces.add(interf);
}
}
@@ -93,11 +90,10 @@ public class Service {
* If errors occur a message is added to the issues list,
* warnings can be added to the warnings list.
*/
- public void validate(final int specVersion, final IssueLog iLog)
+ public void validate(final Context context)
throws SCRDescriptorException {
for(final Interface interf : this.getInterfaces()) {
- interf.validate(specVersion, iLog);
+ interf.validate(context);
}
}
-
}
Added: felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/scanner/ClassAnnotation.java
URL: http://svn.apache.org/viewvc/felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/scanner/ClassAnnotation.java?rev=1338189&view=auto
==============================================================================
--- felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/scanner/ClassAnnotation.java (added)
+++ felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/scanner/ClassAnnotation.java Mon May 14 13:21:02 2012
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.scrplugin.scanner;
+
+import java.util.Map;
+
+public class ClassAnnotation extends ScannedAnnotation {
+
+ public ClassAnnotation(final String name, final Map<String, Object> values) {
+ super(name, values);
+ }
+
+ @Override
+ public String toString() {
+ return "ClassAnnotationDescription [name=" + name + ", values="
+ + values + "]";
+ }
+}
Propchange: felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/scanner/ClassAnnotation.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/scanner/ClassAnnotation.java
------------------------------------------------------------------------------
svn:keywords = author date id revision rev url
Propchange: felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/scanner/ClassAnnotation.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/scanner/FieldAnnotation.java
URL: http://svn.apache.org/viewvc/felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/scanner/FieldAnnotation.java?rev=1338189&view=auto
==============================================================================
--- felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/scanner/FieldAnnotation.java (added)
+++ felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/scanner/FieldAnnotation.java Mon May 14 13:21:02 2012
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.scrplugin.scanner;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Modifier;
+import java.util.Map;
+
+import org.apache.felix.scrplugin.SCRDescriptorException;
+import org.apache.felix.scrplugin.SCRDescriptorFailureException;
+
+public class FieldAnnotation extends ScannedAnnotation {
+
+ private final Field annotatedField;
+
+ public FieldAnnotation(final String name, final Map<String, Object> values, final Field f) {
+ super(name, values);
+ this.annotatedField = f;
+ }
+
+ public Field getAnnotatedField() {
+ return this.annotatedField;
+ }
+
+ public Object getAnnotatedFieldValue()
+ throws SCRDescriptorFailureException, SCRDescriptorException {
+ if ( Modifier.isStatic(annotatedField.getModifiers()) ) {
+ try {
+ final Object value = annotatedField.get(null);
+ return value;
+ } catch (final IllegalArgumentException e) {
+ throw new SCRDescriptorFailureException("Unable to get initial field value from: " + annotatedField, e);
+ } catch (final IllegalAccessException e) {
+ throw new SCRDescriptorFailureException("Unable to get initial field value from: " + annotatedField, e);
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public String toString() {
+ return "FieldAnnotationDescription [name=" + name + ", values="
+ + values + ", annotatedField=" + annotatedField + "]";
+ }
+}
Propchange: felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/scanner/FieldAnnotation.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/scanner/FieldAnnotation.java
------------------------------------------------------------------------------
svn:keywords = author date id revision rev url
Propchange: felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/scanner/FieldAnnotation.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/scanner/MethodAnnotation.java
URL: http://svn.apache.org/viewvc/felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/scanner/MethodAnnotation.java?rev=1338189&view=auto
==============================================================================
--- felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/scanner/MethodAnnotation.java (added)
+++ felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/scanner/MethodAnnotation.java Mon May 14 13:21:02 2012
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.scrplugin.scanner;
+
+import java.lang.reflect.Method;
+import java.util.Map;
+
+public class MethodAnnotation extends ScannedAnnotation {
+
+ private final Method method;
+
+ public MethodAnnotation(final String name, final Map<String, Object> values, final Method m) {
+ super(name, values);
+ this.method = m;
+ }
+
+ public Method getAnnotatedMethod() {
+ return this.method;
+ }
+
+ @Override
+ public String toString() {
+ return "MethodAnnotationDescription [name=" + name + ", values="
+ + values + ", method=" + method + "]";
+ }
+}
Propchange: felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/scanner/MethodAnnotation.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/scanner/MethodAnnotation.java
------------------------------------------------------------------------------
svn:keywords = author date id revision rev url
Propchange: felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/scanner/MethodAnnotation.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/scanner/ScannedAnnotation.java
URL: http://svn.apache.org/viewvc/felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/scanner/ScannedAnnotation.java?rev=1338189&view=auto
==============================================================================
--- felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/scanner/ScannedAnnotation.java (added)
+++ felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/scanner/ScannedAnnotation.java Mon May 14 13:21:02 2012
@@ -0,0 +1,109 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.scrplugin.scanner;
+
+import java.util.Map;
+
+/**
+ * Base class for all annotation.
+ */
+public abstract class ScannedAnnotation {
+
+ /** The fully qualified class name */
+ protected final String name;
+
+ /** The annotation values. */
+ protected final Map<String, Object> values;
+
+ /**
+ * Create a new description
+ * @param name The fully qualified class name of the annotation
+ * @param values The properties of the annotation (optional)
+ */
+ public ScannedAnnotation(final String name, final Map<String, Object> values) {
+ this.name = name;
+ this.values = values;
+ }
+
+ /**
+ * Get the fully qualified class name of the annotation.
+ * @return The fully qualified class name of the annotation.
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * Get a property value of the annotation.
+ * @param paramName The property name.
+ * @return The value of the property or <code>null</code>
+ */
+ public Object getValue(final String paramName) {
+ if ( values != null ) {
+ return values.get(paramName);
+ }
+ return null;
+ }
+
+ public boolean getBooleanValue(final String name, final boolean defaultValue) {
+ final Object val = this.getValue(name);
+ if ( val != null ) {
+ return ((Boolean) val).booleanValue();
+ }
+ return defaultValue;
+ }
+
+ public int getIntegerValue(final String name, final int defaultValue) {
+ final Object val = this.getValue(name);
+ if ( val != null ) {
+ return ((Integer) val).intValue();
+ }
+ return defaultValue;
+ }
+
+ public long getLongValue(final String name, final long defaultValue) {
+ final Object val = this.getValue(name);
+ if ( val != null ) {
+ return ((Long) val).intValue();
+ }
+ return defaultValue;
+ }
+
+ 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;
+ }
+
+ public String getEnumValue(final String name, final String defaultValue) {
+ final Object val = this.getValue(name);
+ if ( val != null ) {
+ return ((String[])val)[1];
+ }
+ return defaultValue;
+ }
+
+ @Override
+ public String toString() {
+ return "AnnotationDescription [name=" + name + ", values=" + values
+ + "]";
+ }
+}
Propchange: felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/scanner/ScannedAnnotation.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/scanner/ScannedAnnotation.java
------------------------------------------------------------------------------
svn:keywords = author date id revision rev url
Propchange: felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/scanner/ScannedAnnotation.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/scanner/ScannedClass.java
URL: http://svn.apache.org/viewvc/felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/scanner/ScannedClass.java?rev=1338189&view=auto
==============================================================================
--- felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/scanner/ScannedClass.java (added)
+++ felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/scanner/ScannedClass.java Mon May 14 13:21:02 2012
@@ -0,0 +1,93 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.scrplugin.scanner;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+/**
+ * A scanned class contains all scanned information
+ * like the found annotations.
+ */
+public class ScannedClass {
+
+ /** All found annotations .*/
+ private final List<ScannedAnnotation> descriptions = new ArrayList<ScannedAnnotation>();
+
+ /** The scanned class. */
+ private final Class<?> scannedClass;
+
+ public ScannedClass(final List<ScannedAnnotation> desc, final Class<?> scannedClass) {
+ this.descriptions.addAll(desc);
+ this.scannedClass = scannedClass;
+ }
+
+ /**
+ * Get the scanned class.
+ * @return The scanned class.
+ */
+ public Class<?> getScannedClass() {
+ return this.scannedClass;
+ }
+
+ public void processed(final ScannedAnnotation desc) {
+ this.descriptions.remove(desc);
+ }
+
+ public void processed(final Collection<? extends ScannedAnnotation> desc) {
+ this.descriptions.removeAll(desc);
+ }
+
+ 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;
+ }
+
+ public List<FieldAnnotation> getFieldAnnotations(final String name) {
+ final List<FieldAnnotation> list = new ArrayList<FieldAnnotation>();
+ for(final ScannedAnnotation desc : descriptions ) {
+ if ( desc instanceof FieldAnnotation ) {
+ if ( name == null || desc.getName().equals(name) ) {
+ list.add( (FieldAnnotation)desc);
+ }
+ }
+ }
+ return list;
+ }
+
+ public List<MethodAnnotation> getMethodAnnotations(final String name) {
+ final List<MethodAnnotation> list = new ArrayList<MethodAnnotation>();
+ for(final ScannedAnnotation desc : descriptions ) {
+ if ( desc instanceof MethodAnnotation ) {
+ if ( name == null || desc.getName().equals(name) ) {
+ list.add( (MethodAnnotation)desc);
+ }
+ }
+ }
+ return list;
+ }
+}
Propchange: felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/scanner/ScannedClass.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/scanner/ScannedClass.java
------------------------------------------------------------------------------
svn:keywords = author date id revision rev url
Propchange: felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/scanner/ScannedClass.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/scanner/Source.java
URL: http://svn.apache.org/viewvc/felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/scanner/Source.java?rev=1338189&view=auto
==============================================================================
--- felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/scanner/Source.java (added)
+++ felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/scanner/Source.java Mon May 14 13:21:02 2012
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.scrplugin.scanner;
+
+import java.io.File;
+
+/**
+ * Description of a source to be parsed.
+ */
+public interface Source {
+
+ /**
+ * The main class name.
+ * @return The main class name.
+ */
+ String getClassName();
+
+ /**
+ * The file containing the class.
+ * @return The file containing the class.
+ */
+ File getFile();
+}
Propchange: felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/scanner/Source.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/scanner/Source.java
------------------------------------------------------------------------------
svn:keywords = author date id revision rev url
Propchange: felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/scanner/Source.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/xml/ComponentDescriptorIO.java
URL: http://svn.apache.org/viewvc/felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/xml/ComponentDescriptorIO.java?rev=1338189&r1=1338188&r2=1338189&view=diff
==============================================================================
--- felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/xml/ComponentDescriptorIO.java (original)
+++ felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/xml/ComponentDescriptorIO.java Mon May 14 13:21:02 2012
@@ -18,15 +18,25 @@
*/
package org.apache.felix.scrplugin.xml;
-import java.io.*;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
import java.util.StringTokenizer;
import javax.xml.transform.TransformerException;
-import org.apache.felix.scrplugin.Constants;
import org.apache.felix.scrplugin.SCRDescriptorException;
-import org.apache.felix.scrplugin.om.*;
-import org.xml.sax.*;
+import org.apache.felix.scrplugin.description.SpecVersion;
+import org.apache.felix.scrplugin.om.Component;
+import org.apache.felix.scrplugin.om.Components;
+import org.apache.felix.scrplugin.om.Implementation;
+import org.apache.felix.scrplugin.om.Interface;
+import org.apache.felix.scrplugin.om.Property;
+import org.apache.felix.scrplugin.om.Reference;
+import org.apache.felix.scrplugin.om.Service;
+import org.xml.sax.Attributes;
+import org.xml.sax.ContentHandler;
+import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl;
import org.xml.sax.helpers.DefaultHandler;
@@ -147,9 +157,9 @@ public class ComponentDescriptorIO {
throws SAXException {
// detect namespace to use
final String namespace;
- if ( components.getSpecVersion() == Constants.VERSION_1_0 ) {
+ if ( components.getSpecVersion() == SpecVersion.VERSION_1_0 ) {
namespace = NAMESPACE_URI_1_0;
- } else if ( components.getSpecVersion() == Constants.VERSION_1_1 ) {
+ } else if ( components.getSpecVersion() == SpecVersion.VERSION_1_1 ) {
namespace = NAMESPACE_URI_1_1;
} else {
namespace = NAMESPACE_URI_1_1_FELIX;
@@ -402,10 +412,12 @@ public class ComponentDescriptorIO {
if ( NAMESPACE_URI_1_0.equals( uri ) || NAMESPACE_URI_1_1.equals( uri )
|| NAMESPACE_URI_1_1_FELIX.equals( uri ) ) {
- if ( NAMESPACE_URI_1_1.equals(uri) ) {
- components.setSpecVersion(Constants.VERSION_1_1);
+ if ( NAMESPACE_URI_1_0.equals(uri) ) {
+ components.setSpecVersion(SpecVersion.VERSION_1_0);
+ } else if ( NAMESPACE_URI_1_1.equals(uri) ) {
+ components.setSpecVersion(SpecVersion.VERSION_1_1);
} else if ( NAMESPACE_URI_1_1_FELIX.equals(uri) ) {
- components.setSpecVersion(Constants.VERSION_1_1_FELIX);
+ components.setSpecVersion(SpecVersion.VERSION_1_1_FELIX);
}
if (localName.equals(COMPONENT)) {
@@ -427,7 +439,7 @@ public class ComponentDescriptorIO {
this.currentComponent.setFactory(attributes.getValue(COMPONENT_ATTR_FACTORY));
// check for version 1.1 attributes
- if ( components.getSpecVersion() == Constants.VERSION_1_1 ) {
+ if ( components.getSpecVersion() == SpecVersion.VERSION_1_1 || components.getSpecVersion() == SpecVersion.VERSION_1_1_FELIX ) {
this.currentComponent.setConfigurationPolicy(attributes.getValue(COMPONENT_ATTR_POLICY));
this.currentComponent.setActivate(attributes.getValue(COMPONENT_ATTR_ACTIVATE));
this.currentComponent.setDeactivate(attributes.getValue(COMPONENT_ATTR_DEACTIVATE));
Modified: felix/sandbox/cziegeler/scrplugin/maven-scr-plugin/NOTICE
URL: http://svn.apache.org/viewvc/felix/sandbox/cziegeler/scrplugin/maven-scr-plugin/NOTICE?rev=1338189&r1=1338188&r2=1338189&view=diff
==============================================================================
--- felix/sandbox/cziegeler/scrplugin/maven-scr-plugin/NOTICE (original)
+++ felix/sandbox/cziegeler/scrplugin/maven-scr-plugin/NOTICE Mon May 14 13:21:02 2012
@@ -1,5 +1,5 @@
Apache Felix SCR Maven Plugin
-Copyright 2007-2011 The Apache Software Foundation
+Copyright 2007-2012 The Apache Software Foundation
This product includes software developed at
The Apache Software Foundation (http://www.apache.org/).
Modified: felix/sandbox/cziegeler/scrplugin/maven-scr-plugin/pom.xml
URL: http://svn.apache.org/viewvc/felix/sandbox/cziegeler/scrplugin/maven-scr-plugin/pom.xml?rev=1338189&r1=1338188&r2=1338189&view=diff
==============================================================================
--- felix/sandbox/cziegeler/scrplugin/maven-scr-plugin/pom.xml (original)
+++ felix/sandbox/cziegeler/scrplugin/maven-scr-plugin/pom.xml Mon May 14 13:21:02 2012
@@ -60,6 +60,17 @@
<version>1.1.5-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
+ <dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.scr.annotations</artifactId>
+ <version>1.6.1-SNAPSHOT</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>asm</groupId>
+ <artifactId>asm-all</artifactId>
+ <version>3.3.1</version>
+ </dependency>
</dependencies>
<build>