You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@onami.apache.org by da...@apache.org on 2012/12/07 01:11:37 UTC
svn commit: r1418140 [2/8] - in /incubator/onami/trunk/autobind:
aop/src/main/java/org/apache/ aop/src/main/java/org/nnsoft/
aop/src/test/java/org/apache/ aop/src/test/java/org/apache/onami/
aop/src/test/java/org/nnsoft/ configuration/src/main/java/org...
Added: incubator/onami/trunk/autobind/core/src/main/java/org/apache/onami/autobind/annotations/Bind.java
URL: http://svn.apache.org/viewvc/incubator/onami/trunk/autobind/core/src/main/java/org/apache/onami/autobind/annotations/Bind.java?rev=1418140&view=auto
==============================================================================
--- incubator/onami/trunk/autobind/core/src/main/java/org/apache/onami/autobind/annotations/Bind.java (added)
+++ incubator/onami/trunk/autobind/core/src/main/java/org/apache/onami/autobind/annotations/Bind.java Fri Dec 7 00:11:06 2012
@@ -0,0 +1,57 @@
+package org.apache.onami.autobind.annotations;
+
+/*
+ * 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.
+ */
+
+import static java.lang.annotation.ElementType.TYPE;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import javax.inject.Named;
+import javax.inject.Qualifier;
+
+/**
+ * Annotate a Class which should be bound automatically. The Classpath Scanner,
+ * will check for these classes. If the name()-Attribute is set (default is ""),
+ * the class will be bound to the implemented interfaces and a named annotation.
+ *
+ * You can overwrite the interfaces, which should be used for binding the class.
+ * If bind()-Attribute is not set, the implemented interfaces will be used. If
+ * set they will be ignored and overwritten.
+ *
+ * If you annotate your class with {@link com.google.inject.Singleton} or
+ * {@link javax.inject.Singleton} they will be also bound to the
+ * Singleton-Scope.
+ */
+@Qualifier
+@GuiceAnnotation
+@Retention( RUNTIME )
+@Target( { TYPE } )
+public @interface Bind
+{
+
+ Named value() default @Named( "" );
+
+ boolean multiple() default false;
+
+ AnnotatedWith annotatedWith() default @AnnotatedWith();
+
+ To to() default @To( );
+
+}
Added: incubator/onami/trunk/autobind/core/src/main/java/org/apache/onami/autobind/annotations/GuiceAnnotation.java
URL: http://svn.apache.org/viewvc/incubator/onami/trunk/autobind/core/src/main/java/org/apache/onami/autobind/annotations/GuiceAnnotation.java?rev=1418140&view=auto
==============================================================================
--- incubator/onami/trunk/autobind/core/src/main/java/org/apache/onami/autobind/annotations/GuiceAnnotation.java (added)
+++ incubator/onami/trunk/autobind/core/src/main/java/org/apache/onami/autobind/annotations/GuiceAnnotation.java Fri Dec 7 00:11:06 2012
@@ -0,0 +1,33 @@
+package org.apache.onami.autobind.annotations;
+
+/*
+ * 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.
+ */
+
+import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+@Documented
+@Target( value = { ANNOTATION_TYPE } )
+@Retention( value = RUNTIME )
+public @interface GuiceAnnotation
+{
+
+}
Added: incubator/onami/trunk/autobind/core/src/main/java/org/apache/onami/autobind/annotations/GuiceModule.java
URL: http://svn.apache.org/viewvc/incubator/onami/trunk/autobind/core/src/main/java/org/apache/onami/autobind/annotations/GuiceModule.java?rev=1418140&view=auto
==============================================================================
--- incubator/onami/trunk/autobind/core/src/main/java/org/apache/onami/autobind/annotations/GuiceModule.java (added)
+++ incubator/onami/trunk/autobind/core/src/main/java/org/apache/onami/autobind/annotations/GuiceModule.java Fri Dec 7 00:11:06 2012
@@ -0,0 +1,44 @@
+package org.apache.onami.autobind.annotations;
+
+/*
+ * 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.
+ */
+
+import static java.lang.annotation.ElementType.TYPE;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+import static org.apache.onami.autobind.install.BindingStage.BUILD;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import javax.inject.Qualifier;
+
+import org.apache.onami.autobind.install.BindingStage;
+
+/**
+ * Annotate a Module with the GuiceModule-Annotation and it will be installed
+ * automatically.
+ */
+@Qualifier
+@GuiceAnnotation
+@Target( { TYPE })
+@Retention(RUNTIME)
+public @interface GuiceModule
+{
+
+ BindingStage stage() default BUILD;
+
+}
Added: incubator/onami/trunk/autobind/core/src/main/java/org/apache/onami/autobind/annotations/To.java
URL: http://svn.apache.org/viewvc/incubator/onami/trunk/autobind/core/src/main/java/org/apache/onami/autobind/annotations/To.java?rev=1418140&view=auto
==============================================================================
--- incubator/onami/trunk/autobind/core/src/main/java/org/apache/onami/autobind/annotations/To.java (added)
+++ incubator/onami/trunk/autobind/core/src/main/java/org/apache/onami/autobind/annotations/To.java Fri Dec 7 00:11:06 2012
@@ -0,0 +1,65 @@
+package org.apache.onami.autobind.annotations;
+
+/*
+ * 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.
+ */
+
+import static org.apache.onami.autobind.annotations.To.Type.INTERFACES;
+
+/**
+ * Can be used to tell autobind where the class should be bound to.
+ */
+public @interface To
+{
+
+ Type value() default INTERFACES;
+
+ Class<? extends Object>[] customs() default {};
+
+ public static enum Type
+ {
+
+ /**
+ * Binds the Implementation to itself. Equals
+ * binder.bind(Implementation.class);
+ */
+ IMPLEMENTATION,
+
+ /**
+ * Binds the Implementation to all implemented Interfaces.
+ *
+ * Equals: for(Interface interface: implementedInterfaces)
+ * binder.bind(interface).to(implementation);
+ */
+ INTERFACES,
+
+ /**
+ * Binds the Implementation to the extended Super-Class. Equals:
+ * binder.bind(superclass).to(implementation);
+ */
+ SUPER,
+
+ /**
+ * Binds the Implementation to the Classes specifed by @To(to={})
+ *
+ * Equals: for(Class<?> class: toClasses)
+ * binder.bind(class).to(implementation);
+ */
+ CUSTOM
+
+ }
+
+}
Propchange: incubator/onami/trunk/autobind/core/src/main/java/org/apache/onami/autobind/annotations/features/
------------------------------------------------------------------------------
bugtraq:number = true
Added: incubator/onami/trunk/autobind/core/src/main/java/org/apache/onami/autobind/annotations/features/AutoBindingFeature.java
URL: http://svn.apache.org/viewvc/incubator/onami/trunk/autobind/core/src/main/java/org/apache/onami/autobind/annotations/features/AutoBindingFeature.java?rev=1418140&view=auto
==============================================================================
--- incubator/onami/trunk/autobind/core/src/main/java/org/apache/onami/autobind/annotations/features/AutoBindingFeature.java (added)
+++ incubator/onami/trunk/autobind/core/src/main/java/org/apache/onami/autobind/annotations/features/AutoBindingFeature.java Fri Dec 7 00:11:06 2012
@@ -0,0 +1,197 @@
+package org.apache.onami.autobind.annotations.features;
+
+/*
+ * 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.
+ */
+
+import static java.lang.String.format;
+import static java.util.Collections.addAll;
+import static java.util.logging.Logger.getLogger;
+import static org.apache.onami.autobind.annotations.To.Type.IMPLEMENTATION;
+import static org.apache.onami.autobind.install.BindingStage.BINDING;
+import static org.apache.onami.autobind.install.BindingStage.IGNORE;
+import static org.apache.onami.autobind.jsr330.Names.named;
+
+import java.lang.annotation.Annotation;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import javax.inject.Named;
+import javax.inject.Qualifier;
+import javax.inject.Singleton;
+
+import org.apache.onami.autobind.annotations.Bind;
+import org.apache.onami.autobind.annotations.GuiceAnnotation;
+import org.apache.onami.autobind.install.BindingStage;
+import org.apache.onami.autobind.scanner.features.BindingScannerFeature;
+
+import com.google.inject.BindingAnnotation;
+
+@Singleton
+public class AutoBindingFeature
+ extends BindingScannerFeature
+{
+
+ protected final Logger _logger = getLogger( getClass().getName() );
+
+ @Override
+ public BindingStage accept( Class<Object> annotatedClass, Map<String, Annotation> annotations )
+ {
+ if ( annotations.containsKey( Bind.class.getName() ) )
+ {
+ Bind annotation = (Bind) annotations.get( Bind.class.getName() );
+ if ( !annotation.multiple() && !( IMPLEMENTATION == annotation.to().value() ) )
+ {
+ return BINDING;
+ }
+ }
+ return IGNORE;
+ }
+
+ @SuppressWarnings( "unchecked" )
+ @Override
+ public void process( final Class<Object> annotatedClass, final Map<String, Annotation> annotations )
+ {
+ Bind annotation = (Bind) annotations.get( Bind.class.getName() );
+ Map<String, Annotation> filtered = filter( annotations );
+
+ final boolean asSingleton =
+ ( annotations.containsKey( com.google.inject.Singleton.class.getName() ) || annotations.containsKey( javax.inject.Singleton.class.getName() ) );
+
+ if ( annotation.value().value().length() > 0 )
+ {
+ filtered.put( Named.class.getName(), named( resolver.resolve( annotation.value().value() ) ) );
+ }
+
+ Class<Object>[] interfaces;
+
+ switch ( annotation.to().value() )
+ {
+ case CUSTOM:
+ interfaces = (Class<Object>[]) annotation.to().customs();
+ break;
+
+ case SUPER:
+ Class<? super Object> superclass = annotatedClass.getSuperclass();
+ if ( Object.class.equals( superclass ) )
+ {
+ interfaces = new Class[] { annotatedClass };
+ }
+ else
+ {
+ interfaces = new Class[] { superclass };
+ }
+
+ break;
+
+ case INTERFACES:
+ default:
+ interfaces = (Class<Object>[]) annotatedClass.getInterfaces();
+ if ( interfaces.length == 0 )
+ {
+ List<Class<?>> interfaceCollection = new ArrayList<Class<?>>();
+ Class<? super Object> parent = annotatedClass.getSuperclass();
+ while ( parent != null && !parent.equals( Object.class ) )
+ {
+ addAll( interfaceCollection, parent.getInterfaces() );
+ parent = parent.getSuperclass();
+ }
+ interfaces = interfaceCollection.toArray( new Class[interfaceCollection.size()] );
+ if ( interfaces.length == 0 )
+ {
+ interfaces = new Class[] { annotatedClass };
+ // FIXME Guice doesn't allow a binding to itself
+ }
+ }
+ }
+
+ for ( Class<Object> interf : interfaces )
+ {
+ if ( _logger.isLoggable( Level.FINE ) )
+ {
+ _logger.fine( format( "Binding Class %s to Interface %s. Singleton? %s ",
+ annotatedClass, interf, asSingleton ) );
+ }
+
+ if ( filtered.size() > 0 )
+ {
+ for ( Annotation anno : filtered.values() )
+ {
+ bind( annotatedClass, interf, anno, ( asSingleton ? Singleton.class : null ) );
+ }
+ }
+ else
+ {
+ bind( annotatedClass, interf, null, ( asSingleton ? Singleton.class : null ) );
+ }
+ }
+ }
+
+ @SuppressWarnings( "unchecked" )
+ protected Map<String, Annotation> filter( final Map<String, Annotation> annotations )
+ {
+ Map<String, Annotation> filtered = new HashMap<String, Annotation>( annotations );
+
+ for ( Entry<String, Annotation> entry : annotations.entrySet() )
+ {
+ String key = entry.getKey();
+ if ( qualifiers.contains( key ) )
+ {
+ continue;
+ }
+ if ( others.contains( key ) )
+ {
+ filtered.remove( key );
+ continue;
+ }
+ Class<? extends Annotation> annotation;
+ try
+ {
+ annotation = (Class<? extends Annotation>) Class.forName( key );
+ if ( annotation.isAnnotationPresent( GuiceAnnotation.class ) )
+ {
+ filtered.remove( key );
+ others.add( key );
+ continue;
+ }
+ if ( annotation.isAnnotationPresent( Qualifier.class ) )
+ {
+ qualifiers.add( key );
+ continue;
+ }
+ if ( annotation.isAnnotationPresent( BindingAnnotation.class ) )
+ {
+ qualifiers.add( key );
+ continue;
+ }
+ filtered.remove( key );
+ others.add( key );
+ }
+ catch ( ClassNotFoundException e )
+ {
+ // TODO ignore
+ }
+ }
+
+ return filtered;
+ }
+
+}
Added: incubator/onami/trunk/autobind/core/src/main/java/org/apache/onami/autobind/annotations/features/ImplementationBindingFeature.java
URL: http://svn.apache.org/viewvc/incubator/onami/trunk/autobind/core/src/main/java/org/apache/onami/autobind/annotations/features/ImplementationBindingFeature.java?rev=1418140&view=auto
==============================================================================
--- incubator/onami/trunk/autobind/core/src/main/java/org/apache/onami/autobind/annotations/features/ImplementationBindingFeature.java (added)
+++ incubator/onami/trunk/autobind/core/src/main/java/org/apache/onami/autobind/annotations/features/ImplementationBindingFeature.java Fri Dec 7 00:11:06 2012
@@ -0,0 +1,67 @@
+package org.apache.onami.autobind.annotations.features;
+
+/*
+ * 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.
+ */
+
+import static java.lang.String.format;
+import static java.util.logging.Level.FINE;
+import static org.apache.onami.autobind.annotations.To.Type.IMPLEMENTATION;
+import static org.apache.onami.autobind.install.BindingStage.BINDING;
+import static org.apache.onami.autobind.install.BindingStage.IGNORE;
+
+import java.lang.annotation.Annotation;
+import java.util.Map;
+
+import javax.inject.Singleton;
+
+import org.apache.onami.autobind.annotations.Bind;
+import org.apache.onami.autobind.install.BindingStage;
+
+@Singleton
+public class ImplementationBindingFeature
+ extends AutoBindingFeature
+{
+
+ @Override
+ public BindingStage accept( Class<Object> annotatedClass, Map<String, Annotation> annotations )
+ {
+ if ( annotations.containsKey( Bind.class.getName() ) )
+ {
+ Bind annotation = (Bind) annotations.get( Bind.class.getName() );
+ if ( !annotation.multiple() && ( IMPLEMENTATION == annotation.to().value() ) )
+ {
+ return BINDING;
+ }
+ }
+ return IGNORE;
+ }
+
+ @Override
+ public void process( final Class<Object> annotatedClass, final Map<String, Annotation> annotations )
+ {
+ final boolean asSingleton =
+ ( annotations.containsKey( com.google.inject.Singleton.class.getName() ) || annotations.containsKey( javax.inject.Singleton.class.getName() ) );
+
+ if ( _logger.isLoggable( FINE ) )
+ {
+ _logger.fine( format( "Binding Class %s. Singleton? %s ", annotatedClass, asSingleton ) );
+ }
+
+ bind( annotatedClass, null, ( asSingleton ? Singleton.class : null ) );
+ }
+
+}
Added: incubator/onami/trunk/autobind/core/src/main/java/org/apache/onami/autobind/annotations/features/ModuleBindingFeature.java
URL: http://svn.apache.org/viewvc/incubator/onami/trunk/autobind/core/src/main/java/org/apache/onami/autobind/annotations/features/ModuleBindingFeature.java?rev=1418140&view=auto
==============================================================================
--- incubator/onami/trunk/autobind/core/src/main/java/org/apache/onami/autobind/annotations/features/ModuleBindingFeature.java (added)
+++ incubator/onami/trunk/autobind/core/src/main/java/org/apache/onami/autobind/annotations/features/ModuleBindingFeature.java Fri Dec 7 00:11:06 2012
@@ -0,0 +1,88 @@
+package org.apache.onami.autobind.annotations.features;
+
+/*
+ * 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.
+ */
+
+import static java.lang.String.format;
+import static java.util.logging.Level.FINE;
+import static java.util.logging.Level.INFO;
+import static java.util.logging.Logger.getLogger;
+import static org.apache.onami.autobind.install.BindingStage.IGNORE;
+
+import java.lang.annotation.Annotation;
+import java.util.Map;
+import java.util.logging.Logger;
+
+import javax.inject.Singleton;
+
+import org.apache.onami.autobind.annotations.GuiceModule;
+import org.apache.onami.autobind.install.BindingStage;
+import org.apache.onami.autobind.install.bindjob.BindingJob;
+import org.apache.onami.autobind.install.bindjob.ModuleBindingJob;
+import org.apache.onami.autobind.scanner.features.BindingScannerFeature;
+
+import com.google.inject.Module;
+
+@Singleton
+public class ModuleBindingFeature
+ extends BindingScannerFeature
+{
+
+ private final Logger _logger = getLogger( getClass().getName() );
+
+ @Override
+ public BindingStage accept( Class<Object> annotatedClass, Map<String, Annotation> annotations )
+ {
+ if ( annotations.containsKey( GuiceModule.class.getName() ) )
+ {
+ GuiceModule module = (GuiceModule) annotations.get( GuiceModule.class.getName() );
+ return module.stage();
+ }
+ return IGNORE;
+ }
+
+ @Override
+ public void process( final Class<Object> annotatedClass, Map<String, Annotation> annotations )
+ {
+ BindingJob job = new ModuleBindingJob( annotatedClass.getName() );
+ if ( !tracer.contains( job ) )
+ {
+ if ( _logger.isLoggable( INFO ) )
+ {
+ _logger.info( "Installing Module: " + annotatedClass.getName() );
+ }
+ synchronized ( _binder )
+ {
+ _binder.install( (Module) injector.getInstance( annotatedClass ) );
+ }
+ }
+ else
+ {
+ String message = format( "Ignoring BindingJob \"%s\", because it was already bound.", job );
+
+ if ( _logger.isLoggable( FINE ) )
+ {
+ _logger.log( FINE, message, new Exception( message ) );
+ }
+ else if ( _logger.isLoggable( INFO ) )
+ {
+ _logger.log( INFO, message );
+ }
+ }
+ }
+
+}
Added: incubator/onami/trunk/autobind/core/src/main/java/org/apache/onami/autobind/annotations/features/MultiBindingFeature.java
URL: http://svn.apache.org/viewvc/incubator/onami/trunk/autobind/core/src/main/java/org/apache/onami/autobind/annotations/features/MultiBindingFeature.java?rev=1418140&view=auto
==============================================================================
--- incubator/onami/trunk/autobind/core/src/main/java/org/apache/onami/autobind/annotations/features/MultiBindingFeature.java (added)
+++ incubator/onami/trunk/autobind/core/src/main/java/org/apache/onami/autobind/annotations/features/MultiBindingFeature.java Fri Dec 7 00:11:06 2012
@@ -0,0 +1,102 @@
+package org.apache.onami.autobind.annotations.features;
+
+/*
+ * 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.
+ */
+
+import static java.lang.String.format;
+import static com.google.inject.multibindings.Multibinder.newSetBinder;
+import static java.util.logging.Level.FINE;
+import static java.util.logging.Level.INFO;
+import static org.apache.onami.autobind.install.BindingStage.BINDING;
+import static org.apache.onami.autobind.install.BindingStage.IGNORE;
+
+import java.lang.annotation.Annotation;
+import java.util.Map;
+
+import javax.inject.Singleton;
+
+import org.apache.onami.autobind.annotations.Bind;
+import org.apache.onami.autobind.install.BindingStage;
+import org.apache.onami.autobind.install.bindjob.BindingJob;
+import org.apache.onami.autobind.install.bindjob.MultiBindingJob;
+
+import com.google.inject.binder.ScopedBindingBuilder;
+import com.google.inject.multibindings.Multibinder;
+
+@Singleton
+public class MultiBindingFeature
+ extends AutoBindingFeature
+{
+
+ @Override
+ public BindingStage accept( Class<Object> annotatedClass, Map<String, Annotation> annotations )
+ {
+ if ( annotations.containsKey( Bind.class.getName() ) )
+ {
+ Bind annotation = (Bind) annotations.get( Bind.class.getName() );
+ if ( annotation.multiple() )
+ {
+ return BINDING;
+ }
+ }
+ return IGNORE;
+ }
+
+ @Override
+ protected <T, V extends T> void bind( Class<V> implementationClass, Class<T> interf, Annotation annotation,
+ Class<? extends Annotation> scope )
+ {
+ BindingJob job = new MultiBindingJob( scope, annotation, implementationClass.getName(), interf.getName() );
+
+ if ( !tracer.contains( job ) )
+ {
+ Multibinder<T> builder;
+ synchronized ( _binder )
+ {
+ if ( annotation != null )
+ {
+ builder = newSetBinder( _binder, interf, annotation );
+ }
+ else
+ {
+ builder = newSetBinder( _binder, interf );
+ }
+
+ ScopedBindingBuilder scopedBindingBuilder = builder.addBinding().to( implementationClass );
+ if ( scope != null )
+ {
+ scopedBindingBuilder.in( scope );
+ }
+ }
+ tracer.add( job );
+ }
+ else
+ {
+ String message = format( "Ignoring Multi-BindingJob \"%s\", because it was already bound.", job );
+
+ if ( _logger.isLoggable( FINE ) )
+ {
+ _logger.log( FINE, message, new Exception( message ) );
+ }
+ else if ( _logger.isLoggable( INFO ) )
+ {
+ _logger.log( INFO, message );
+ }
+ }
+ }
+
+}
Added: incubator/onami/trunk/autobind/core/src/main/java/org/apache/onami/autobind/annotations/features/package-info.java
URL: http://svn.apache.org/viewvc/incubator/onami/trunk/autobind/core/src/main/java/org/apache/onami/autobind/annotations/features/package-info.java?rev=1418140&view=auto
==============================================================================
--- incubator/onami/trunk/autobind/core/src/main/java/org/apache/onami/autobind/annotations/features/package-info.java (added)
+++ incubator/onami/trunk/autobind/core/src/main/java/org/apache/onami/autobind/annotations/features/package-info.java Fri Dec 7 00:11:06 2012
@@ -0,0 +1,21 @@
+/**
+ * TODO fill me.
+ */
+package org.apache.onami.autobind.annotations.features;
+
+/*
+ * 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.
+ */
Added: incubator/onami/trunk/autobind/core/src/main/java/org/apache/onami/autobind/annotations/package-info.java
URL: http://svn.apache.org/viewvc/incubator/onami/trunk/autobind/core/src/main/java/org/apache/onami/autobind/annotations/package-info.java?rev=1418140&view=auto
==============================================================================
--- incubator/onami/trunk/autobind/core/src/main/java/org/apache/onami/autobind/annotations/package-info.java (added)
+++ incubator/onami/trunk/autobind/core/src/main/java/org/apache/onami/autobind/annotations/package-info.java Fri Dec 7 00:11:06 2012
@@ -0,0 +1,22 @@
+/**
+ * This package includes all annotations which are used to
+ * annotating class like it would be written with the Guice ESL.
+ */
+package org.apache.onami.autobind.annotations;
+
+/*
+ * 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.
+ */
Propchange: incubator/onami/trunk/autobind/core/src/main/java/org/apache/onami/autobind/install/
------------------------------------------------------------------------------
bugtraq:number = true
Added: incubator/onami/trunk/autobind/core/src/main/java/org/apache/onami/autobind/install/BindingStage.java
URL: http://svn.apache.org/viewvc/incubator/onami/trunk/autobind/core/src/main/java/org/apache/onami/autobind/install/BindingStage.java?rev=1418140&view=auto
==============================================================================
--- incubator/onami/trunk/autobind/core/src/main/java/org/apache/onami/autobind/install/BindingStage.java (added)
+++ incubator/onami/trunk/autobind/core/src/main/java/org/apache/onami/autobind/install/BindingStage.java Fri Dec 7 00:11:06 2012
@@ -0,0 +1,60 @@
+package org.apache.onami.autobind.install;
+
+/*
+ * 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.
+ */
+
+import java.util.LinkedList;
+import java.util.List;
+
+public enum BindingStage
+{
+
+ INTERNAL,
+ BOOT_BEFORE,
+ BOOT,
+ BOOT_POST,
+ BINDING_BEFORE,
+ BINDING,
+ BINDING_POST,
+ INSTALL_BEFORE,
+ INSTALL,
+ INSTALL_POST,
+ BUILD_BEFORE,
+ BUILD,
+ BUILD_POST,
+ IGNORE;
+
+ public static final List<BindingStage> ORDERED = new LinkedList<BindingStage>();
+
+ static
+ {
+ ORDERED.add( INTERNAL );
+ ORDERED.add( BOOT_BEFORE );
+ ORDERED.add( BOOT );
+ ORDERED.add( BOOT_POST );
+ ORDERED.add( BINDING_BEFORE );
+ ORDERED.add( BINDING );
+ ORDERED.add( BINDING_POST );
+ ORDERED.add( INSTALL_BEFORE );
+ ORDERED.add( INSTALL );
+ ORDERED.add( INSTALL_POST );
+ ORDERED.add( BUILD_BEFORE );
+ ORDERED.add( BUILD );
+ ORDERED.add( BUILD_POST );
+ }
+
+}
Added: incubator/onami/trunk/autobind/core/src/main/java/org/apache/onami/autobind/install/BindingTracer.java
URL: http://svn.apache.org/viewvc/incubator/onami/trunk/autobind/core/src/main/java/org/apache/onami/autobind/install/BindingTracer.java?rev=1418140&view=auto
==============================================================================
--- incubator/onami/trunk/autobind/core/src/main/java/org/apache/onami/autobind/install/BindingTracer.java (added)
+++ incubator/onami/trunk/autobind/core/src/main/java/org/apache/onami/autobind/install/BindingTracer.java Fri Dec 7 00:11:06 2012
@@ -0,0 +1,50 @@
+package org.apache.onami.autobind.install;
+
+/*
+ * 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.
+ */
+
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+
+import javax.inject.Singleton;
+
+import org.apache.onami.autobind.install.bindjob.BindingJob;
+
+@Singleton
+public class BindingTracer
+ implements Iterable<BindingJob>
+{
+
+ private Set<BindingJob> jobs = new HashSet<BindingJob>();
+
+ public synchronized boolean add( BindingJob e )
+ {
+ return jobs.add( e );
+ }
+
+ public synchronized boolean contains( Object o )
+ {
+ return jobs.contains( o );
+ }
+
+ public Iterator<BindingJob> iterator()
+ {
+ return jobs.iterator();
+ }
+
+}
Added: incubator/onami/trunk/autobind/core/src/main/java/org/apache/onami/autobind/install/InstallationContext.java
URL: http://svn.apache.org/viewvc/incubator/onami/trunk/autobind/core/src/main/java/org/apache/onami/autobind/install/InstallationContext.java?rev=1418140&view=auto
==============================================================================
--- incubator/onami/trunk/autobind/core/src/main/java/org/apache/onami/autobind/install/InstallationContext.java (added)
+++ incubator/onami/trunk/autobind/core/src/main/java/org/apache/onami/autobind/install/InstallationContext.java Fri Dec 7 00:11:06 2012
@@ -0,0 +1,86 @@
+package org.apache.onami.autobind.install;
+
+/*
+ * 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.
+ */
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.Callable;
+
+/**
+ * This class is internally used, to bind Installation Requests and process them
+ * sequentially in a predefined order.
+ */
+public class InstallationContext {
+
+ private final Map<BindingStage, List<Callable<?>>> context = new HashMap<BindingStage, List<Callable<?>>>();
+
+ public void process()
+ throws Exception
+ {
+ for ( BindingStage stage : BindingStage.ORDERED )
+ {
+ List<Callable<?>> requests = context.get( stage );
+ if ( requests != null )
+ {
+ for ( Callable<?> request : requests )
+ {
+ request.call();
+ }
+ }
+ }
+ }
+
+ public void add( BindingStage stage, Callable<?> request )
+ {
+ synchronized ( context )
+ {
+ List<Callable<?>> requests = context.get( stage );
+ if ( requests == null )
+ {
+ requests = new ArrayList<Callable<?>>();
+ context.put( stage, requests );
+ }
+ requests.add( request );
+ }
+ }
+
+ public void add( StageableRequest request )
+ {
+ synchronized ( context )
+ {
+ List<Callable<?>> requests = context.get( request.getExecutionStage() );
+ if ( requests == null )
+ {
+ requests = new ArrayList<Callable<?>>();
+ context.put( request.getExecutionStage(), requests );
+ }
+ requests.add( request );
+ }
+ }
+
+ public static interface StageableRequest
+ extends Callable<Void>
+ {
+
+ BindingStage getExecutionStage();
+
+ }
+
+}
Propchange: incubator/onami/trunk/autobind/core/src/main/java/org/apache/onami/autobind/install/bindjob/
------------------------------------------------------------------------------
bugtraq:number = true
Added: incubator/onami/trunk/autobind/core/src/main/java/org/apache/onami/autobind/install/bindjob/BindingJob.java
URL: http://svn.apache.org/viewvc/incubator/onami/trunk/autobind/core/src/main/java/org/apache/onami/autobind/install/bindjob/BindingJob.java?rev=1418140&view=auto
==============================================================================
--- incubator/onami/trunk/autobind/core/src/main/java/org/apache/onami/autobind/install/bindjob/BindingJob.java (added)
+++ incubator/onami/trunk/autobind/core/src/main/java/org/apache/onami/autobind/install/bindjob/BindingJob.java Fri Dec 7 00:11:06 2012
@@ -0,0 +1,102 @@
+package org.apache.onami.autobind.install.bindjob;
+
+/*
+ * 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.
+ */
+
+import static com.google.common.base.Objects.equal;
+import static com.google.common.base.Objects.toStringHelper;
+
+import java.lang.annotation.Annotation;
+
+import javax.inject.Provider;
+
+@SuppressWarnings( "rawtypes" )
+public class BindingJob
+{
+
+ public final Class<? extends Annotation> scoped;
+
+ public final Class<? extends Provider> provided;
+
+ public final Annotation annotated;
+
+ public final String className;
+
+ public final String interfaceName;
+
+ public BindingJob( Class<? extends Annotation> scoped, Class<? extends Provider> provided, Annotation annotated,
+ String className, String interfaceName )
+ {
+ this.scoped = scoped;
+ this.provided = provided;
+ this.annotated = annotated;
+ this.className = className;
+ this.interfaceName = interfaceName;
+ }
+
+ @Override
+ public int hashCode()
+ {
+ return hashCode( annotated, className, interfaceName, provided, scoped );
+ }
+
+ @Override
+ public boolean equals( Object obj )
+ {
+ if ( this == obj )
+ {
+ return true;
+ }
+ if ( obj == null || getClass() != obj.getClass() )
+ {
+ return false;
+ }
+ BindingJob other = (BindingJob) obj;
+
+ return equal( annotated, other.annotated )
+ && equal( interfaceName, other.interfaceName )
+ && equal( className, other.className )
+ && equal( provided, other.provided )
+ && equal( scoped, other.scoped );
+ }
+
+ protected static int hashCode( Object...args )
+ {
+ final int prime = 31;
+ int result = 1;
+
+ for ( Object arg : args )
+ {
+ result = prime * result + ( ( arg == null ) ? 0 : arg.hashCode() );
+ }
+
+ return result;
+ }
+
+ @Override
+ public String toString()
+ {
+ return toStringHelper( getClass() )
+ .add( "annotated", annotated )
+ .add( "className", className )
+ .add( "interfaceName", interfaceName )
+ .add( "provided", provided )
+ .add( "scoped", scoped )
+ .toString();
+ }
+
+}
Added: incubator/onami/trunk/autobind/core/src/main/java/org/apache/onami/autobind/install/bindjob/ConstantBindingJob.java
URL: http://svn.apache.org/viewvc/incubator/onami/trunk/autobind/core/src/main/java/org/apache/onami/autobind/install/bindjob/ConstantBindingJob.java?rev=1418140&view=auto
==============================================================================
--- incubator/onami/trunk/autobind/core/src/main/java/org/apache/onami/autobind/install/bindjob/ConstantBindingJob.java (added)
+++ incubator/onami/trunk/autobind/core/src/main/java/org/apache/onami/autobind/install/bindjob/ConstantBindingJob.java Fri Dec 7 00:11:06 2012
@@ -0,0 +1,31 @@
+package org.apache.onami.autobind.install.bindjob;
+
+/*
+ * 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.
+ */
+
+import java.lang.annotation.Annotation;
+
+public class ConstantBindingJob
+ extends BindingJob
+{
+
+ public ConstantBindingJob( Annotation annotated, String className )
+ {
+ super( null, null, annotated, className, "constant" );
+ }
+
+}
Added: incubator/onami/trunk/autobind/core/src/main/java/org/apache/onami/autobind/install/bindjob/ImplementationBindingJob.java
URL: http://svn.apache.org/viewvc/incubator/onami/trunk/autobind/core/src/main/java/org/apache/onami/autobind/install/bindjob/ImplementationBindingJob.java?rev=1418140&view=auto
==============================================================================
--- incubator/onami/trunk/autobind/core/src/main/java/org/apache/onami/autobind/install/bindjob/ImplementationBindingJob.java (added)
+++ incubator/onami/trunk/autobind/core/src/main/java/org/apache/onami/autobind/install/bindjob/ImplementationBindingJob.java Fri Dec 7 00:11:06 2012
@@ -0,0 +1,31 @@
+package org.apache.onami.autobind.install.bindjob;
+
+/*
+ * 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.
+ */
+
+import java.lang.annotation.Annotation;
+
+public class ImplementationBindingJob
+ extends BindingJob
+{
+
+ public ImplementationBindingJob( Class<? extends Annotation> scoped, Annotation annotated, String className )
+ {
+ super( scoped, null, annotated, className, null );
+ }
+
+}
Added: incubator/onami/trunk/autobind/core/src/main/java/org/apache/onami/autobind/install/bindjob/InstanceBindingJob.java
URL: http://svn.apache.org/viewvc/incubator/onami/trunk/autobind/core/src/main/java/org/apache/onami/autobind/install/bindjob/InstanceBindingJob.java?rev=1418140&view=auto
==============================================================================
--- incubator/onami/trunk/autobind/core/src/main/java/org/apache/onami/autobind/install/bindjob/InstanceBindingJob.java (added)
+++ incubator/onami/trunk/autobind/core/src/main/java/org/apache/onami/autobind/install/bindjob/InstanceBindingJob.java Fri Dec 7 00:11:06 2012
@@ -0,0 +1,38 @@
+package org.apache.onami.autobind.install.bindjob;
+
+/*
+ * 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.
+ */
+
+import java.lang.annotation.Annotation;
+
+public class InstanceBindingJob
+ extends BindingJob
+{
+
+ public InstanceBindingJob( Class<? extends Annotation> scoped, Annotation annotated, String className,
+ String interfaceName )
+ {
+ super( scoped, null, annotated, className, interfaceName );
+ }
+
+ @Override
+ public int hashCode()
+ {
+ return hashCode( annotated, interfaceName, provided, scoped );
+ }
+
+}
Added: incubator/onami/trunk/autobind/core/src/main/java/org/apache/onami/autobind/install/bindjob/InterfaceBindingJob.java
URL: http://svn.apache.org/viewvc/incubator/onami/trunk/autobind/core/src/main/java/org/apache/onami/autobind/install/bindjob/InterfaceBindingJob.java?rev=1418140&view=auto
==============================================================================
--- incubator/onami/trunk/autobind/core/src/main/java/org/apache/onami/autobind/install/bindjob/InterfaceBindingJob.java (added)
+++ incubator/onami/trunk/autobind/core/src/main/java/org/apache/onami/autobind/install/bindjob/InterfaceBindingJob.java Fri Dec 7 00:11:06 2012
@@ -0,0 +1,38 @@
+package org.apache.onami.autobind.install.bindjob;
+
+/*
+ * 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.
+ */
+
+import java.lang.annotation.Annotation;
+
+public class InterfaceBindingJob
+ extends BindingJob
+{
+
+ public InterfaceBindingJob( Class<? extends Annotation> scoped, Annotation annotated, String className,
+ String interfaceName )
+ {
+ super( scoped, null, annotated, className, interfaceName );
+ }
+
+ @Override
+ public int hashCode()
+ {
+ return hashCode( annotated, interfaceName, provided, scoped );
+ }
+
+}
Added: incubator/onami/trunk/autobind/core/src/main/java/org/apache/onami/autobind/install/bindjob/ModuleBindingJob.java
URL: http://svn.apache.org/viewvc/incubator/onami/trunk/autobind/core/src/main/java/org/apache/onami/autobind/install/bindjob/ModuleBindingJob.java?rev=1418140&view=auto
==============================================================================
--- incubator/onami/trunk/autobind/core/src/main/java/org/apache/onami/autobind/install/bindjob/ModuleBindingJob.java (added)
+++ incubator/onami/trunk/autobind/core/src/main/java/org/apache/onami/autobind/install/bindjob/ModuleBindingJob.java Fri Dec 7 00:11:06 2012
@@ -0,0 +1,29 @@
+package org.apache.onami.autobind.install.bindjob;
+
+/*
+ * 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.
+ */
+
+public class ModuleBindingJob
+ extends BindingJob
+{
+
+ public ModuleBindingJob( String moduleName )
+ {
+ super( null, null, null, moduleName, null );
+ }
+
+}
Added: incubator/onami/trunk/autobind/core/src/main/java/org/apache/onami/autobind/install/bindjob/MultiBindingJob.java
URL: http://svn.apache.org/viewvc/incubator/onami/trunk/autobind/core/src/main/java/org/apache/onami/autobind/install/bindjob/MultiBindingJob.java?rev=1418140&view=auto
==============================================================================
--- incubator/onami/trunk/autobind/core/src/main/java/org/apache/onami/autobind/install/bindjob/MultiBindingJob.java (added)
+++ incubator/onami/trunk/autobind/core/src/main/java/org/apache/onami/autobind/install/bindjob/MultiBindingJob.java Fri Dec 7 00:11:06 2012
@@ -0,0 +1,38 @@
+package org.apache.onami.autobind.install.bindjob;
+
+/*
+ * 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.
+ */
+
+import java.lang.annotation.Annotation;
+
+public class MultiBindingJob
+ extends BindingJob
+{
+
+ public MultiBindingJob( Class<? extends Annotation> scoped, Annotation annotated, String className,
+ String interfaceName )
+ {
+ super( scoped, null, annotated, className, interfaceName );
+ }
+
+ @Override
+ public int hashCode()
+ {
+ return hashCode( annotated, className, interfaceName, provided, scoped );
+ }
+
+}
Added: incubator/onami/trunk/autobind/core/src/main/java/org/apache/onami/autobind/install/bindjob/ProviderBindingJob.java
URL: http://svn.apache.org/viewvc/incubator/onami/trunk/autobind/core/src/main/java/org/apache/onami/autobind/install/bindjob/ProviderBindingJob.java?rev=1418140&view=auto
==============================================================================
--- incubator/onami/trunk/autobind/core/src/main/java/org/apache/onami/autobind/install/bindjob/ProviderBindingJob.java (added)
+++ incubator/onami/trunk/autobind/core/src/main/java/org/apache/onami/autobind/install/bindjob/ProviderBindingJob.java Fri Dec 7 00:11:06 2012
@@ -0,0 +1,35 @@
+package org.apache.onami.autobind.install.bindjob;
+
+/*
+ * 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.
+ */
+
+import java.lang.annotation.Annotation;
+
+import javax.inject.Provider;
+
+public class ProviderBindingJob
+ extends BindingJob
+{
+
+ @SuppressWarnings( "rawtypes" )
+ public ProviderBindingJob( Class<? extends Annotation> scoped, Class<? extends Provider> provided,
+ Annotation annotated, String interfaceName )
+ {
+ super( scoped, provided, annotated, null, interfaceName );
+ }
+
+}
Added: incubator/onami/trunk/autobind/core/src/main/java/org/apache/onami/autobind/install/bindjob/package-info.java
URL: http://svn.apache.org/viewvc/incubator/onami/trunk/autobind/core/src/main/java/org/apache/onami/autobind/install/bindjob/package-info.java?rev=1418140&view=auto
==============================================================================
--- incubator/onami/trunk/autobind/core/src/main/java/org/apache/onami/autobind/install/bindjob/package-info.java (added)
+++ incubator/onami/trunk/autobind/core/src/main/java/org/apache/onami/autobind/install/bindjob/package-info.java Fri Dec 7 00:11:06 2012
@@ -0,0 +1,21 @@
+/**
+ * TODO fillme.
+ */
+package org.apache.onami.autobind.install.bindjob;
+
+/*
+ * 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.
+ */
Added: incubator/onami/trunk/autobind/core/src/main/java/org/apache/onami/autobind/install/package-info.java
URL: http://svn.apache.org/viewvc/incubator/onami/trunk/autobind/core/src/main/java/org/apache/onami/autobind/install/package-info.java?rev=1418140&view=auto
==============================================================================
--- incubator/onami/trunk/autobind/core/src/main/java/org/apache/onami/autobind/install/package-info.java (added)
+++ incubator/onami/trunk/autobind/core/src/main/java/org/apache/onami/autobind/install/package-info.java Fri Dec 7 00:11:06 2012
@@ -0,0 +1,21 @@
+/**
+ * TODO fillme.
+ */
+package org.apache.onami.autobind.install;
+
+/*
+ * 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.
+ */
Propchange: incubator/onami/trunk/autobind/core/src/main/java/org/apache/onami/autobind/jsr330/
------------------------------------------------------------------------------
bugtraq:number = true
Added: incubator/onami/trunk/autobind/core/src/main/java/org/apache/onami/autobind/jsr330/NamedImpl.java
URL: http://svn.apache.org/viewvc/incubator/onami/trunk/autobind/core/src/main/java/org/apache/onami/autobind/jsr330/NamedImpl.java?rev=1418140&view=auto
==============================================================================
--- incubator/onami/trunk/autobind/core/src/main/java/org/apache/onami/autobind/jsr330/NamedImpl.java (added)
+++ incubator/onami/trunk/autobind/core/src/main/java/org/apache/onami/autobind/jsr330/NamedImpl.java Fri Dec 7 00:11:06 2012
@@ -0,0 +1,73 @@
+package org.apache.onami.autobind.jsr330;
+
+/*
+ * 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.
+ */
+
+import static java.lang.String.format;
+
+import java.io.Serializable;
+import java.lang.annotation.Annotation;
+
+import javax.inject.Named;
+
+@SuppressWarnings( "all" ) // TODO didn't fine the right value to suppress the specific warning
+class NamedImpl
+ implements Named, Serializable
+{
+
+ private static final long serialVersionUID = 0;
+
+ private final String value;
+
+ public NamedImpl( String value )
+ {
+ this.value = value;
+ }
+
+ public String value()
+ {
+ return this.value;
+ }
+
+ public int hashCode()
+ {
+ // This is specified in java.lang.Annotation.
+ return ( 127 * "value".hashCode() ) ^ value.hashCode();
+ }
+
+ public boolean equals( Object o )
+ {
+ if ( !( o instanceof Named ) )
+ {
+ return false;
+ }
+
+ Named other = (Named) o;
+ return value.equals( other.value() );
+ }
+
+ public String toString()
+ {
+ return format( "@%s(value=%s)", Named.class.getName(), value );
+ }
+
+ public Class<? extends Annotation> annotationType()
+ {
+ return Named.class;
+ }
+
+}
Added: incubator/onami/trunk/autobind/core/src/main/java/org/apache/onami/autobind/jsr330/Names.java
URL: http://svn.apache.org/viewvc/incubator/onami/trunk/autobind/core/src/main/java/org/apache/onami/autobind/jsr330/Names.java?rev=1418140&view=auto
==============================================================================
--- incubator/onami/trunk/autobind/core/src/main/java/org/apache/onami/autobind/jsr330/Names.java (added)
+++ incubator/onami/trunk/autobind/core/src/main/java/org/apache/onami/autobind/jsr330/Names.java Fri Dec 7 00:11:06 2012
@@ -0,0 +1,41 @@
+package org.apache.onami.autobind.jsr330;
+
+/*
+ * 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.
+ */
+
+import javax.inject.Named;
+
+public final class Names
+{
+
+ /**
+ * Private constructor, this class must not be instantiated.
+ */
+ private Names()
+ {
+ // does nothing
+ }
+
+ /**
+ * Creates a {@link Named} annotation with {@code name} as the value.
+ */
+ public static Named named( String name )
+ {
+ return new NamedImpl( name );
+ }
+
+}
Added: incubator/onami/trunk/autobind/core/src/main/java/org/apache/onami/autobind/jsr330/package-info.java
URL: http://svn.apache.org/viewvc/incubator/onami/trunk/autobind/core/src/main/java/org/apache/onami/autobind/jsr330/package-info.java?rev=1418140&view=auto
==============================================================================
--- incubator/onami/trunk/autobind/core/src/main/java/org/apache/onami/autobind/jsr330/package-info.java (added)
+++ incubator/onami/trunk/autobind/core/src/main/java/org/apache/onami/autobind/jsr330/package-info.java Fri Dec 7 00:11:06 2012
@@ -0,0 +1,21 @@
+/**
+ * TODO fillme.
+ */
+package org.apache.onami.autobind.jsr330;
+
+/*
+ * 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.
+ */
Propchange: incubator/onami/trunk/autobind/core/src/main/java/org/apache/onami/autobind/scanner/
------------------------------------------------------------------------------
bugtraq:number = true
Added: incubator/onami/trunk/autobind/core/src/main/java/org/apache/onami/autobind/scanner/ClasspathScanner.java
URL: http://svn.apache.org/viewvc/incubator/onami/trunk/autobind/core/src/main/java/org/apache/onami/autobind/scanner/ClasspathScanner.java?rev=1418140&view=auto
==============================================================================
--- incubator/onami/trunk/autobind/core/src/main/java/org/apache/onami/autobind/scanner/ClasspathScanner.java (added)
+++ incubator/onami/trunk/autobind/core/src/main/java/org/apache/onami/autobind/scanner/ClasspathScanner.java Fri Dec 7 00:11:06 2012
@@ -0,0 +1,69 @@
+package org.apache.onami.autobind.scanner;
+
+/*
+ * 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.
+ */
+
+import java.io.IOException;
+import java.util.List;
+
+import org.apache.onami.autobind.scanner.features.ScannerFeature;
+
+/**
+ * Interface which is used to create ClasspathScanner implementations. Our
+ * StartupModule will bind your chosen Implementation to this interface. You
+ * choose which ClasspathScanner should be used, by passing the Class to the
+ * StartupModule constructor.
+ */
+public interface ClasspathScanner
+{
+
+ /**
+ * Starts the Classpath Scanning and the Registration of Requests for Bindings. Called through the StartupModule.
+ *
+ * @throws IOException
+ */
+ void scan()
+ throws IOException;
+
+ /**
+ * Adds a ScannerFeature to the Scanner like Automatic Binding of Classes or Guice Modules, Interceptors, ... or
+ * your own one.
+ *
+ * @param feature
+ */
+ void addFeature( ScannerFeature feature );
+
+ void removeFeature( ScannerFeature feature );
+
+ List<ScannerFeature> getFeatures();
+
+ /**
+ * Adds a Package which should be included to scan. Only Classes found in the included Packages will be read and
+ * passed to the ScannerFeatures.
+ *
+ * @param filter
+ */
+ void includePackage( PackageFilter filter );
+
+ void excludePackage( PackageFilter filter );
+
+ /**
+ * Destroys a ClasspathScanner so it can do some kind of Cleanup.
+ */
+ void destroy();
+
+}
Added: incubator/onami/trunk/autobind/core/src/main/java/org/apache/onami/autobind/scanner/PackageFilter.java
URL: http://svn.apache.org/viewvc/incubator/onami/trunk/autobind/core/src/main/java/org/apache/onami/autobind/scanner/PackageFilter.java?rev=1418140&view=auto
==============================================================================
--- incubator/onami/trunk/autobind/core/src/main/java/org/apache/onami/autobind/scanner/PackageFilter.java (added)
+++ incubator/onami/trunk/autobind/core/src/main/java/org/apache/onami/autobind/scanner/PackageFilter.java Fri Dec 7 00:11:06 2012
@@ -0,0 +1,73 @@
+package org.apache.onami.autobind.scanner;
+
+/*
+ * 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.
+ */
+
+public class PackageFilter
+{
+
+ private String _package;
+
+ private boolean deep;
+
+ public PackageFilter( String p, boolean deeper )
+ {
+ _package = p;
+ deep = deeper;
+ }
+
+ public String getPackage()
+ {
+ return _package;
+ }
+
+ public boolean deep()
+ {
+ return deep;
+ }
+
+ public static PackageFilter create( Class<?> clazz )
+ {
+ return new PackageFilter( clazz.getPackage().getName(), true );
+ }
+
+ public static PackageFilter create( Class<?> clazz, boolean deeper )
+ {
+ return new PackageFilter( clazz.getPackage().getName(), deeper );
+ }
+
+ public static PackageFilter create( Package p )
+ {
+ return new PackageFilter( p.getName(), true );
+ }
+
+ public static PackageFilter create( Package p, boolean deeper )
+ {
+ return new PackageFilter( p.getName(), deeper );
+ }
+
+ public static PackageFilter create( String p )
+ {
+ return new PackageFilter( p, true );
+ }
+
+ public static PackageFilter create( String p, boolean deeper )
+ {
+ return new PackageFilter( p, deeper );
+ }
+
+}
Added: incubator/onami/trunk/autobind/core/src/main/java/org/apache/onami/autobind/scanner/ScannerModule.java
URL: http://svn.apache.org/viewvc/incubator/onami/trunk/autobind/core/src/main/java/org/apache/onami/autobind/scanner/ScannerModule.java?rev=1418140&view=auto
==============================================================================
--- incubator/onami/trunk/autobind/core/src/main/java/org/apache/onami/autobind/scanner/ScannerModule.java (added)
+++ incubator/onami/trunk/autobind/core/src/main/java/org/apache/onami/autobind/scanner/ScannerModule.java Fri Dec 7 00:11:06 2012
@@ -0,0 +1,107 @@
+package org.apache.onami.autobind.scanner;
+
+/*
+ * 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.
+ */
+
+import static java.lang.System.getProperty;
+import static java.util.logging.Level.FINE;
+import static java.util.logging.Level.INFO;
+import static java.util.logging.Level.SEVERE;
+import static java.util.logging.Logger.getLogger;
+
+import java.io.IOException;
+import java.util.Set;
+import java.util.logging.Logger;
+
+import javax.inject.Inject;
+
+import org.apache.onami.autobind.annotations.Bind;
+import org.apache.onami.autobind.annotations.GuiceModule;
+import org.apache.onami.autobind.install.InstallationContext;
+import org.apache.onami.autobind.scanner.features.BindingScannerFeature;
+import org.apache.onami.autobind.scanner.features.ScannerFeature;
+
+import com.google.inject.Binder;
+import com.google.inject.Module;
+
+/**
+ * The ScannerModule will be injected with a ClasspathScanner and the needed
+ * Annotation Listeners will be added. The attached Listeners will install all
+ * Modules annotated with {@link GuiceModule} and bind all Beans annotated with
+ * {@link Bind}.
+ */
+public class ScannerModule
+ implements Module
+{
+
+ private static String LINE_SEPARATOR = getProperty( "line.separator" );
+
+ private final Logger _logger = getLogger( getClass().getName() );
+
+ @Inject
+ private ClasspathScanner _scanner;
+
+ @Inject
+ private Set<ScannerFeature> _listeners;
+
+ @Inject
+ private InstallationContext _context;
+
+ @Override
+ public void configure( Binder binder )
+ {
+ if ( _logger.isLoggable( INFO ) )
+ {
+ StringBuilder builder = new StringBuilder( _scanner.getClass().getName() )
+ .append( " is using following Scanner Features: " )
+ .append( LINE_SEPARATOR );
+ for ( ScannerFeature listener : _listeners )
+ {
+ builder.append( listener.getClass().getName() ).append( LINE_SEPARATOR );
+ }
+ _logger.log( INFO, builder.toString() );
+ }
+ for ( ScannerFeature listener : _listeners )
+ {
+ if ( listener instanceof BindingScannerFeature )
+ {
+ ( (BindingScannerFeature) listener ).setBinder( binder );
+ if ( _logger.isLoggable( FINE ) )
+ {
+ _logger.fine( "Binding AnnotationListeners " + listener.getClass().getName() );
+ }
+ }
+ }
+ try
+ {
+ _scanner.scan();
+ }
+ catch ( IOException e )
+ {
+ _logger.log( SEVERE, "Failure while Scanning the Classpath for Classes with Annotations.", e );
+ }
+ try
+ {
+ _context.process();
+ }
+ catch ( Exception e )
+ {
+ _logger.log( SEVERE, "Failure while executing the collected Tasks.", e );
+ }
+ }
+
+}
Propchange: incubator/onami/trunk/autobind/core/src/main/java/org/apache/onami/autobind/scanner/features/
------------------------------------------------------------------------------
bugtraq:number = true