1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.springframework.osgi.service.exporter.support;
18
19 import org.springframework.core.enums.StaticLabeledEnum;
20 import org.springframework.osgi.util.internal.ClassUtils;
21
22 /**
23 * Enum-like class indicatin class exporters available to
24 * {@link OsgiServiceFactoryBean} for registering object as OSGi services.
25 *
26 * @author Costin Leau
27 */
28 public abstract class AutoExport extends StaticLabeledEnum {
29
30 /** Do not export anything */
31 public static final AutoExport DISABLED = new AutoExport(0, "DISABLED") {
32
33 private static final long serialVersionUID = -8297270116184239840L;
34
35 private final Class[] clazz = new Class[0];
36
37
38 Class[] getExportedClasses(Class targetClass) {
39 return clazz;
40 }
41 };
42
43 /**
44 * Export all interfaces (and their hierarchy) implemented by the given
45 * class
46 */
47 public static final AutoExport INTERFACES = new AutoExport(1, "INTERFACES") {
48
49 private static final long serialVersionUID = -8336152449611885031L;
50
51
52 public Class[] getExportedClasses(Class targetClass) {
53 return ClassUtils.getClassHierarchy(targetClass, ClassUtils.INCLUDE_INTERFACES);
54 }
55 };
56
57 /**
58 * Export the class hierarchy (all classes inherited by the given target
59 * excluding Object.class)
60 */
61 public static final AutoExport CLASS_HIERARCHY = new AutoExport(2, "CLASS_HIERARCHY") {
62
63 private static final long serialVersionUID = 6464782616822538297L;
64
65
66 public Class[] getExportedClasses(Class targetClass) {
67 return ClassUtils.getClassHierarchy(targetClass, ClassUtils.INCLUDE_CLASS_HIERARCHY);
68
69 }
70 };
71
72 /**
73 * Export every class, inherited or implemented by the given target. Similar
74 * to {@link #CLASS_HIERARCHY} + {@link #INTERFACES}
75 */
76 public static final AutoExport ALL_CLASSES = new AutoExport(3, "ALL_CLASSES") {
77
78 private static final long serialVersionUID = -6628398711158262852L;
79
80
81 public Class[] getExportedClasses(Class targetClass) {
82 return ClassUtils.getClassHierarchy(targetClass, ClassUtils.INCLUDE_ALL_CLASSES);
83 }
84 };
85
86
87 /**
88 * Determines the exported classes given a certain target class.
89 *
90 * @param targetClass class to be exported into OSGi
91 * @return array of classes that will be published for the OSGi service.
92 */
93 abstract Class[] getExportedClasses(Class targetClass);
94
95 /**
96 * Constructs a new <code>AutoExport</code> instance.
97 *
98 * @param code
99 * @param label
100 */
101 private AutoExport(int code, String label) {
102 super(code, label);
103 }
104 }