View Javadoc

1   package com.atlassian.plugin.osgi.loader;
2   
3   import com.atlassian.plugin.AutowireCapablePlugin;
4   
5   
6   /**
7    * How to autowire a component
8    */
9   public enum AutowireStrategy {
10      /**
11       * Performs no autowiring
12       */
13      AUTOWIRE_NO(AutowireCapablePlugin.AUTOWIRE_NO),
14      /**
15       * Performs setter-based injection by name
16       */
17      AUTOWIRE_BY_NAME(AutowireCapablePlugin.AUTOWIRE_BY_NAME),
18  
19      /**
20       * Performs setter-based injection by type
21       */
22      AUTOWIRE_BY_TYPE(AutowireCapablePlugin.AUTOWIRE_BY_TYPE),
23  
24      /**
25       * Performs construction-based injection by type
26       */
27      AUTOWIRE_BY_CONSTRUCTOR(AutowireCapablePlugin.AUTOWIRE_BY_CONSTRUCTOR),
28  
29      /**
30       * Autodetects appropriate injection by first seeing if any no-arg constructors exist.  If not, performs constructor
31       * injection, and if so, autowires by type then name
32       */
33      AUTOWIRE_AUTODETECT(AutowireCapablePlugin.AUTOWIRE_AUTODETECT);
34  
35      private final int index;
36  
37      AutowireStrategy(int index) {
38          this.index = index;
39      }
40  
41      public int getIndex() {
42          return index;
43      }
44  
45      public static AutowireStrategy fromIndex(int index) {
46          for (AutowireStrategy s : AutowireStrategy.values()) {
47              if (s.getIndex() == index) {
48                  return s;
49              }
50          }
51          throw new IllegalArgumentException("The index " + index + " does not match any value of " + AutowireStrategy.class);
52      }
53  }