View Javadoc

1   package org.apache.onami.autobind.annotations;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one or more
5    * contributor license agreements.  See the NOTICE file distributed with
6    * this work for additional information regarding copyright ownership.
7    * The ASF licenses this file to You under the Apache License, Version 2.0
8    * (the "License"); you may not use this file except in compliance with
9    * the License.  You may obtain a copy of the License at
10   *
11   *  http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing, software
14   * distributed under the License is distributed on an "AS IS" BASIS,
15   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   * See the License for the specific language governing permissions and
17   * limitations under the License.
18   */
19  
20  import static org.apache.onami.autobind.annotations.To.Type.INTERFACES;
21  import static org.apache.onami.autobind.jsr330.Names.named;
22  
23  import java.lang.annotation.Annotation;
24  import java.lang.reflect.Array;
25  
26  import javax.inject.Named;
27  
28  import org.apache.onami.autobind.annotations.To.Type;
29  
30  public class Annotations
31  {
32  
33      /**
34       * Hidden constructor, this class cannot be instantiated.
35       */
36      protected Annotations()
37      {
38          // do nothing
39      }
40  
41      public static Bind createBind()
42      {
43          return createBind( INTERFACES );
44      }
45  
46      public static Bind createBind( final Type type )
47      {
48          return new Bind()
49          {
50  
51              @Override
52              public Class<? extends Annotation> annotationType()
53              {
54                  return Bind.class;
55              }
56  
57              @Override
58              public Named value()
59              {
60                  return named( "" );
61              }
62  
63              @Override
64              public AnnotatedWith annotatedWith() {
65                  return null;
66              }
67  
68              @Override
69              public To to()
70              {
71                  return createTo( type );
72              }
73  
74              @Override
75              public boolean multiple()
76              {
77                  return false;
78              }
79  
80          };
81      }
82  
83      @SuppressWarnings("unchecked")
84      public static AnnotatedWith createAnnotatedWith( )
85      {
86          return createAnnotatedWith( (Class<? super Annotation>[]) Array.newInstance(Annotation.class, 0) );
87      }
88  
89      public static AnnotatedWith createAnnotatedWith( final Class<? super Annotation>... annotations )
90      {
91          return new AnnotatedWith()
92          {
93  
94              @Override
95              public Class<? extends Annotation> annotationType()
96              {
97                  return AnnotatedWith.class;
98              }
99  
100             @Override
101             public Class<? super Annotation>[] value()
102             {
103                 return annotations;
104             }
105 
106         };
107     }
108 
109     public static To createTo()
110     {
111         return createTo( INTERFACES );
112     }
113 
114     public static To createTo( final Type type )
115     {
116         return new To()
117         {
118 
119             @Override
120             public Class<? extends Annotation> annotationType()
121             {
122                 return To.class;
123             }
124 
125             @Override
126             public Type value()
127             {
128                 return type;
129             }
130 
131             @Override
132             public Class<? extends Object>[] customs()
133             {
134                 return new Class<?>[0];
135             }
136 
137         };
138     }
139 
140 }