Mercurial > hg > blitz_condensed
diff 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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/org/dancres/blitz/BootContext.java Sat Mar 21 11:00:06 2009 +0000 @@ -0,0 +1,49 @@ +package org.dancres.blitz; + +import java.util.List; +import java.util.LinkedList; +import java.util.Iterator; + +/** + Various components within Blitz require access to certain specific bits + of information concerning Boot state. BootContext is responsible for + holding all these bits of information and making them available to the + components. + */ +public class BootContext { + private static List theContext = new LinkedList(); + + public static void add(BootInfo anInfo) { + synchronized(theContext) { + theContext.add(anInfo); + } + } + + public static BootInfo get(Class aClass) { + validate(aClass); + + synchronized(theContext) { + Iterator myInfos = theContext.iterator(); + + while (myInfos.hasNext()) { + BootInfo myInfo = (BootInfo) myInfos.next(); + + if (aClass.isInstance(myInfo)) + return myInfo; + } + } + + return null; + } + + private static void validate(Class aClass) { + Class[] myInterfaces = aClass.getInterfaces(); + + for (int i = 0 ; i < myInterfaces.length; i++) { + if (myInterfaces[i].equals(BootInfo.class)) + return; + } + + throw new RuntimeException("Attempt to store object which is not a BootInfo"); + } +}