1
2
3
4
5
6
7
8
9
10
11
12
13 package org.eclipse.jetty.osgi.annotations;
14
15 import java.util.ArrayList;
16 import java.util.List;
17
18 import org.eclipse.jetty.annotations.ClassNameResolver;
19 import org.eclipse.jetty.osgi.boot.OSGiWebappConstants;
20 import org.eclipse.jetty.osgi.boot.utils.internal.PackageAdminServiceTracker;
21 import org.eclipse.jetty.util.resource.Resource;
22 import org.eclipse.jetty.webapp.DiscoveredAnnotation;
23 import org.eclipse.jetty.webapp.WebAppContext;
24 import org.osgi.framework.Bundle;
25 import org.osgi.framework.Constants;
26
27
28
29
30
31
32 public class AnnotationConfiguration extends org.eclipse.jetty.annotations.AnnotationConfiguration
33 {
34
35
36
37
38 @Override
39 protected org.eclipse.jetty.annotations.AnnotationParser createAnnotationParser()
40 {
41 return new AnnotationParser();
42 }
43
44
45
46
47
48
49
50
51
52
53
54 @Override
55 public void parseWebInfLib (WebAppContext context, org.eclipse.jetty.annotations.AnnotationParser parser)
56 throws Exception
57 {
58 AnnotationParser oparser = (AnnotationParser)parser;
59
60 Bundle webbundle = (Bundle) context.getAttribute(OSGiWebappConstants.JETTY_OSGI_BUNDLE);
61 Bundle[] fragAndRequiredBundles = PackageAdminServiceTracker.INSTANCE.getFragmentsAndRequiredBundles(webbundle);
62 if (fragAndRequiredBundles != null)
63 {
64
65 for (Bundle bundle : fragAndRequiredBundles)
66 {
67 Resource bundleRes = oparser.indexBundle(bundle);
68 if (!context.getMetaData().getWebInfJars().contains(bundleRes))
69 {
70 context.getMetaData().addWebInfJar(bundleRes);
71 }
72 }
73
74
75 for (Bundle fragmentBundle : fragAndRequiredBundles)
76 {
77 if (fragmentBundle.getHeaders().get(Constants.FRAGMENT_HOST) != null)
78 {
79
80 parseFragmentBundle(context,oparser,webbundle,fragmentBundle);
81 }
82 }
83 }
84
85 parseWebBundle(context,oparser,webbundle);
86
87
88 super.parseWebInfLib(context,parser);
89 if (fragAndRequiredBundles != null)
90 {
91
92 for (Bundle requiredBundle : fragAndRequiredBundles)
93 {
94 if (requiredBundle.getHeaders().get(Constants.FRAGMENT_HOST) == null)
95 {
96
97 parseRequiredBundle(context,oparser,webbundle,requiredBundle);
98 }
99 }
100 }
101 }
102
103
104
105
106
107
108
109
110
111 protected void parseFragmentBundle(WebAppContext context, AnnotationParser parser,
112 Bundle webbundle, Bundle fragmentBundle) throws Exception
113 {
114 parseBundle(context,parser,webbundle,fragmentBundle);
115 }
116
117
118
119
120
121
122
123
124
125 protected void parseWebBundle(WebAppContext context, AnnotationParser parser, Bundle webbundle)
126 throws Exception
127 {
128 parseBundle(context,parser,webbundle,webbundle);
129 }
130
131
132
133
134
135
136
137
138
139 protected void parseRequiredBundle(WebAppContext context, AnnotationParser parser,
140 Bundle webbundle, Bundle requiredBundle) throws Exception
141 {
142 parseBundle(context,parser,webbundle,requiredBundle);
143 }
144
145 protected void parseBundle(WebAppContext context, AnnotationParser parser,
146 Bundle webbundle, Bundle bundle) throws Exception
147 {
148 Resource bundleRes = parser.getResource(bundle);
149 parser.parse(bundle,createClassNameResolver(context));
150 List<DiscoveredAnnotation> annotations = new ArrayList<DiscoveredAnnotation>();
151 gatherAnnotations(annotations, parser.getAnnotationHandlers());
152 if (webbundle == bundle)
153 {
154
155
156 context.getMetaData().addDiscoveredAnnotations(annotations);
157 }
158 else
159 {
160 context.getMetaData().addDiscoveredAnnotations(bundleRes, annotations);
161 }
162 }
163
164
165
166
167
168
169 protected ClassNameResolver createClassNameResolver(final WebAppContext context)
170 {
171 return createClassNameResolver(context,true,false,false,false);
172 }
173
174 protected ClassNameResolver createClassNameResolver(final WebAppContext context,
175 final boolean excludeSysClass, final boolean excludeServerClass, final boolean excludeEverythingElse,
176 final boolean overrideIsParenLoaderIsPriority)
177 {
178 return new ClassNameResolver ()
179 {
180 public boolean isExcluded (String name)
181 {
182 if (context.isSystemClass(name)) return excludeSysClass;
183 if (context.isServerClass(name)) return excludeServerClass;
184 return excludeEverythingElse;
185 }
186
187 public boolean shouldOverride (String name)
188 {
189
190 if (context.isParentLoaderPriority())
191 return overrideIsParenLoaderIsPriority;
192 return !overrideIsParenLoaderIsPriority;
193 }
194 };
195 }
196
197 }