1818 */
1919package org .apache .felix .framework ;
2020
21+ import java .io .File ;
22+ import java .io .IOException ;
23+ import java .io .InputStream ;
24+ import java .net .URL ;
25+ import java .security .AccessControlContext ;
26+ import java .security .ProtectionDomain ;
27+ import java .security .cert .X509Certificate ;
28+ import java .util .ArrayList ;
29+ import java .util .Collection ;
30+ import java .util .Dictionary ;
31+ import java .util .Enumeration ;
32+ import java .util .HashMap ;
33+ import java .util .Iterator ;
34+ import java .util .List ;
35+ import java .util .Locale ;
36+ import java .util .Map ;
37+ import java .util .Map .Entry ;
38+ import java .util .Properties ;
39+ import java .util .Set ;
40+ import java .util .StringTokenizer ;
41+
2142import org .apache .felix .framework .cache .BundleArchive ;
2243import org .apache .felix .framework .util .SecurityManagerEx ;
2344import org .apache .felix .framework .util .ShrinkableCollection ;
4162import org .osgi .framework .wiring .BundleWire ;
4263import org .osgi .framework .wiring .BundleWiring ;
4364
44- import java .io .File ;
45- import java .io .IOException ;
46- import java .io .InputStream ;
47- import java .net .URL ;
48- import java .security .AccessControlContext ;
49- import java .security .ProtectionDomain ;
50- import java .util .ArrayList ;
51- import java .util .Collection ;
52- import java .util .Dictionary ;
53- import java .util .Enumeration ;
54- import java .util .HashMap ;
55- import java .util .Iterator ;
56- import java .util .List ;
57- import java .util .Locale ;
58- import java .util .Map ;
59- import java .util .Properties ;
60- import java .util .Set ;
61- import java .util .StringTokenizer ;
62-
6365class BundleImpl implements Bundle , BundleRevisions
6466{
6567 // No one should use this field directly, use getFramework() instead.
@@ -72,8 +74,8 @@ class BundleImpl implements Bundle, BundleRevisions
7274 private boolean m_useDeclaredActivationPolicy ;
7375 private BundleActivator m_activator = null ;
7476 private volatile BundleContext m_context = null ;
75- private final Map m_cachedHeaders = new HashMap ();
76- private Map m_uninstalledHeaders = null ;
77+ private final Map < String , Map < String , String >> m_cachedHeaders = new HashMap <> ();
78+ private Map < String , String > m_uninstalledHeaders = null ;
7779 private long m_cachedHeadersTimestamp ;
7880 private final Bundle m_installingBundle ;
7981
@@ -300,7 +302,7 @@ public URL getEntry(String name)
300302 }
301303
302304 @ Override
303- public Enumeration getEntryPaths (String path )
305+ public Enumeration < String > getEntryPaths (String path )
304306 {
305307 Object sm = System .getSecurityManager ();
306308
@@ -321,7 +323,7 @@ public Enumeration getEntryPaths(String path)
321323 }
322324
323325 @ Override
324- public Enumeration findEntries (String path , String filePattern , boolean recurse )
326+ public Enumeration < URL > findEntries (String path , String filePattern , boolean recurse )
325327 {
326328 Object sm = System .getSecurityManager ();
327329
@@ -343,13 +345,13 @@ public Enumeration findEntries(String path, String filePattern, boolean recurse)
343345 }
344346
345347 @ Override
346- public Dictionary getHeaders ()
348+ public Dictionary < String , String > getHeaders ()
347349 {
348350 return getHeaders (Locale .getDefault ().toString ());
349351 }
350352
351353 @ Override
352- public Dictionary getHeaders (String locale )
354+ public Dictionary < String , String > getHeaders (String locale )
353355 {
354356 Object sm = System .getSecurityManager ();
355357
@@ -367,14 +369,14 @@ public Dictionary getHeaders(String locale)
367369 return getFramework ().getBundleHeaders (this , locale );
368370 }
369371
370- Map getCurrentLocalizedHeader (String locale )
372+ Map < String , String > getCurrentLocalizedHeader (String locale )
371373 {
372- Map result = null ;
374+ Map < String , String > result = null ;
373375
374376 // Spec says empty local returns raw headers.
375377 if (locale .length () == 0 )
376378 {
377- result = new StringMap (adapt (BundleRevisionImpl .class ).getHeaders ());
379+ result = new StringMap <> (adapt (BundleRevisionImpl .class ).getHeaders ());
378380 }
379381
380382 // If we have no result, try to get it from the cached headers.
@@ -400,7 +402,7 @@ else if (getLastModified() > m_cachedHeadersTimestamp)
400402 // Check if headers for this locale have already been resolved
401403 if (m_cachedHeaders .containsKey (locale ))
402404 {
403- result = (Map ) m_cachedHeaders .get (locale );
405+ result = (Map < String , String > ) m_cachedHeaders .get (locale );
404406 }
405407 }
406408 }
@@ -410,13 +412,13 @@ else if (getLastModified() > m_cachedHeadersTimestamp)
410412 if (result == null )
411413 {
412414 // Get a modifiable copy of the raw headers.
413- Map headers = new StringMap (adapt (BundleRevisionImpl .class ).getHeaders ());
415+ Map < String , String > headers = new StringMap <> (adapt (BundleRevisionImpl .class ).getHeaders ());
414416 // Assume for now that this will be the result.
415417 result = headers ;
416418
417419 // Check to see if we actually need to localize anything
418420 boolean localize = false ;
419- for (Iterator it = headers .values ().iterator (); !localize && it .hasNext (); )
421+ for (Iterator < String > it = headers .values ().iterator (); !localize && it .hasNext (); )
420422 {
421423 if (((String ) it .next ()).startsWith ("%" ))
422424 {
@@ -482,9 +484,9 @@ else if (getLastModified() > m_cachedHeadersTimestamp)
482484 else
483485 {
484486 // Resolve all localized header entries
485- for (Iterator it = headers .entrySet ().iterator (); it .hasNext (); )
487+ for (Iterator < Entry < String , String >> it = headers .entrySet ().iterator (); it .hasNext (); )
486488 {
487- Map .Entry entry = ( Map . Entry ) it .next ();
489+ Map .Entry < String , String > entry = it .next ();
488490 String value = (String ) entry .getValue ();
489491 if (value .startsWith ("%" ))
490492 {
@@ -507,7 +509,7 @@ else if (getLastModified() > m_cachedHeadersTimestamp)
507509 return result ;
508510 }
509511
510- private void updateHeaderCache (String locale , Map localizedHeaders )
512+ private void updateHeaderCache (String locale , Map < String , String > localizedHeaders )
511513 {
512514 synchronized (m_cachedHeaders )
513515 {
@@ -565,7 +567,7 @@ private static List<BundleRevision> createLocalizationRevisionList(BundleRevisio
565567
566568 private static List <String > createLocalizationResourceList (String basename , String locale )
567569 {
568- List <String > result = new ArrayList (4 );
570+ List <String > result = new ArrayList <> (4 );
569571
570572 StringTokenizer tokens ;
571573 StringBuilder tempLocale = new StringBuilder (basename );
@@ -675,7 +677,7 @@ public URL getResource(String name)
675677 }
676678
677679 @ Override
678- public Enumeration getResources (String name ) throws IOException
680+ public Enumeration < URL > getResources (String name ) throws IOException
679681 {
680682 Object sm = System .getSecurityManager ();
681683
@@ -694,7 +696,7 @@ public Enumeration getResources(String name) throws IOException
694696
695697 // Spec says we should return null when resources not found,
696698 // even though ClassLoader.getResources() returns empty enumeration.
697- Enumeration e = getFramework ().getBundleResources (this , name );
699+ Enumeration < URL > e = getFramework ().getBundleResources (this , name );
698700 return ((e == null ) || !e .hasMoreElements ()) ? null : e ;
699701 }
700702
@@ -705,22 +707,22 @@ public Enumeration getResources(String name) throws IOException
705707 * @return an array of service references or null.
706708 **/
707709 @ Override
708- public ServiceReference [] getRegisteredServices ()
710+ public ServiceReference <?> [] getRegisteredServices ()
709711 {
710712 Object sm = System .getSecurityManager ();
711713
712714 if (sm != null )
713715 {
714- ServiceReference [] refs = getFramework ().getBundleRegisteredServices (this );
716+ ServiceReference <?> [] refs = getFramework ().getBundleRegisteredServices (this );
715717
716718 if (refs == null )
717719 {
718720 return refs ;
719721 }
720722
721- List result = new ArrayList ();
723+ List < ServiceReference <?>> result = new ArrayList <> ();
722724
723- for (ServiceReference ref : refs ) {
725+ for (ServiceReference <?> ref : refs ) {
724726 try
725727 {
726728 ((SecurityManager ) sm ).checkPermission (new ServicePermission (
@@ -748,22 +750,22 @@ public ServiceReference[] getRegisteredServices()
748750 }
749751
750752 @ Override
751- public ServiceReference [] getServicesInUse ()
753+ public ServiceReference <?> [] getServicesInUse ()
752754 {
753755 Object sm = System .getSecurityManager ();
754756
755757 if (sm != null )
756758 {
757- ServiceReference [] refs = getFramework ().getBundleServicesInUse (this );
759+ ServiceReference <?> [] refs = getFramework ().getBundleServicesInUse (this );
758760
759761 if (refs == null )
760762 {
761763 return refs ;
762764 }
763765
764- List result = new ArrayList ();
766+ List < ServiceReference <?>> result = new ArrayList <> ();
765767
766- for (ServiceReference ref : refs ) {
768+ for (ServiceReference <?> ref : refs ) {
767769 try
768770 {
769771 ((SecurityManager ) sm ).checkPermission (
@@ -952,14 +954,14 @@ public boolean hasPermission(Object obj)
952954 }
953955
954956 @ Override
955- public Map getSignerCertificates (int signersType )
957+ public Map < X509Certificate , List < X509Certificate >> getSignerCertificates (int signersType )
956958 {
957959 // TODO: SECURITY - This needs to be adapted to our security mechanisms.
958- return ( Map ) getFramework ().getSignerMatcher (this , signersType );
960+ return getFramework ().getSignerMatcher (this , signersType );
959961 }
960962
961963 @ Override
962- public Class loadClass (String name ) throws ClassNotFoundException
964+ public Class <?> loadClass (String name ) throws ClassNotFoundException
963965 {
964966 if (isExtension ())
965967 {
@@ -1055,7 +1057,7 @@ public void uninstall() throws BundleException
10551057 AdminPermission .LIFECYCLE ));
10561058 }
10571059
1058- Map headers = getCurrentLocalizedHeader (Locale .getDefault ().toString ());
1060+ Map < String , String > headers = getCurrentLocalizedHeader (Locale .getDefault ().toString ());
10591061
10601062 // Uninstall the bundle.
10611063 getFramework ().uninstallBundle (this );
@@ -1086,7 +1088,7 @@ <A> void checkAdapt(Class<A> type)
10861088 Object sm = System .getSecurityManager ();
10871089 if ((sm != null ) && (getFramework ().getSecurityProvider () != null ))
10881090 {
1089- Class [] classes = m_smEx .getClassContext ();
1091+ Class <?> [] classes = m_smEx .getClassContext ();
10901092 if (classes .length < 3 || ((Felix .m_secureAction .getClassLoader (classes [3 ]) != m_classloader ) ||
10911093 !classes [3 ].getName ().startsWith ("org.apache.felix.framework." )))
10921094 {
@@ -1096,7 +1098,8 @@ <A> void checkAdapt(Class<A> type)
10961098 }
10971099 }
10981100
1099- @ Override
1101+ @ SuppressWarnings ("unchecked" )
1102+ @ Override
11001103 public <A > A adapt (Class <A > type )
11011104 {
11021105 checkAdapt (type );
@@ -1276,7 +1279,7 @@ private BundleRevisionImpl createRevision(boolean isUpdate) throws Exception
12761279 {
12771280 // Get and parse the manifest from the most recent revision and
12781281 // create an associated revision object for it.
1279- Map headerMap = Util .getMultiReleaseAwareManifestHeaders (
1282+ Map < String , String > headerMap = Util .getMultiReleaseAwareManifestHeaders (
12801283 getFramework ()._getProperty ("java.specification.version" ), m_archive .getCurrentRevision ());
12811284
12821285 // Create the bundle revision instance.
0 commit comments