View Javadoc
1   /*
2    * Copyright (C) 2008 the original author or authors.
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  
17  package org.codehaus.plexus.metadata.ann;
18  
19  import java.lang.reflect.Proxy;
20  import java.util.LinkedHashMap;
21  import java.util.Map;
22  
23  import org.objectweb.asm.Type;
24  
25  /**
26   * @author Eugene Kuleshov
27   */
28  public class Ann {
29  
30      private String desc;
31      private Map<String, Object> params = new LinkedHashMap<String, Object>();
32  
33      public Ann(String desc) {
34          this.desc = desc;
35      }
36  
37      public void addParam(String name, Object value) {
38          params.put(name, value);
39      }
40  
41      public String getDesc() {
42          return desc;
43      }
44  
45      public String getType() {
46          return Type.getType(desc).getClassName();
47      }
48  
49      public Map<String, Object> getParams() {
50          return params;
51      }
52  
53      @SuppressWarnings("unchecked")
54      public <T> T getAnnotation(Class<T> c, ClassLoader cl) {
55          return (T) Proxy.newProxyInstance(
56                  Ann.class.getClassLoader(),
57                  new Class[] {c}, //
58                  new AnnInvocationHandler(this, cl, c));
59      }
60  }