Mercurial > hg > blitz_condensed
comparison src/org/dancres/blitz/BootContext.java @ 0:3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
author | Dan Creswell <dan.creswell@gmail.com> |
---|---|
date | Sat, 21 Mar 2009 11:00:06 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:3dc0c5604566 |
---|---|
1 package org.dancres.blitz; | |
2 | |
3 import java.util.List; | |
4 import java.util.LinkedList; | |
5 import java.util.Iterator; | |
6 | |
7 /** | |
8 Various components within Blitz require access to certain specific bits | |
9 of information concerning Boot state. BootContext is responsible for | |
10 holding all these bits of information and making them available to the | |
11 components. | |
12 */ | |
13 public class BootContext { | |
14 private static List theContext = new LinkedList(); | |
15 | |
16 public static void add(BootInfo anInfo) { | |
17 synchronized(theContext) { | |
18 theContext.add(anInfo); | |
19 } | |
20 } | |
21 | |
22 public static BootInfo get(Class aClass) { | |
23 validate(aClass); | |
24 | |
25 synchronized(theContext) { | |
26 Iterator myInfos = theContext.iterator(); | |
27 | |
28 while (myInfos.hasNext()) { | |
29 BootInfo myInfo = (BootInfo) myInfos.next(); | |
30 | |
31 if (aClass.isInstance(myInfo)) | |
32 return myInfo; | |
33 } | |
34 } | |
35 | |
36 return null; | |
37 } | |
38 | |
39 private static void validate(Class aClass) { | |
40 Class[] myInterfaces = aClass.getInterfaces(); | |
41 | |
42 for (int i = 0 ; i < myInterfaces.length; i++) { | |
43 if (myInterfaces[i].equals(BootInfo.class)) | |
44 return; | |
45 } | |
46 | |
47 throw new RuntimeException("Attempt to store object which is not a BootInfo"); | |
48 } | |
49 } |