View Javadoc

1   /**
2    * Copyright (C) 2010 Daniel Manzke <daniel.manzke@googlemail.com>
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *         http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.apache.onami.autobind.aop.example.interceptor;
17  
18  import java.io.IOException;
19  
20  import org.apache.onami.autobind.annotations.Bind;
21  import org.apache.onami.autobind.annotations.GuiceModule;
22  import org.apache.onami.autobind.aop.feature.InterceptorFeature;
23  import org.apache.onami.autobind.configuration.StartupModule;
24  import org.apache.onami.autobind.example.starter.ExampleApplication;
25  import org.apache.onami.autobind.scanner.ClasspathScanner;
26  import org.apache.onami.autobind.scanner.PackageFilter;
27  import org.apache.onami.autobind.scanner.ScannerModule;
28  import org.apache.onami.autobind.scanner.asm.ASMClasspathScanner;
29  
30  import com.google.inject.Guice;
31  import com.google.inject.Injector;
32  
33  
34  /**
35   * Example Application, which creates a new Injector with the help of the
36   * provided {@link StartupModule}. It passes the {@link ASMClasspathScanner}
37   * class for the {@link ClasspathScanner} and the packages (de.devsurf) which
38   * should be scanned. The {@link StartupModule} binds these parameter, so we are
39   * able to create and inject our {@link ScannerModule}. This Module uses the
40   * {@link ClasspathScanner} to explore the Classpath and scans for Annotations.
41   * 
42   * All recognized Classes annotated with {@link GuiceModule} are installed in
43   * the child injector and with {@link Bind} are automatically bound.
44   * 
45   * @author Daniel Manzke
46   * 
47   */
48  @Bind(multiple = true)
49  public class ExampleApp implements ExampleApplication {
50  	@Override
51  	public void run() {
52  		StartupModule startup = StartupModule.create(ASMClasspathScanner.class, PackageFilter.create(ExampleApp.class), PackageFilter.create("de.devsurf.injection.guice.aop"));
53  		startup.addFeature(InterceptorFeature.class);
54  		Injector injector = Guice.createInjector(startup);
55  
56  		Example example = injector.getInstance(Example.class);
57  		System.out.println(example.sayHello());
58  		System.out.println(example.convert("good bye! ", true, 3));
59  	}
60  
61  	public static void main(String[] args) throws IOException {
62  		new ExampleApp().run();
63  	}
64  }