Mercurial > hg > blitz_condensed
view src/org/dancres/blitz/BootContext.java @ 33:0b9265358617
Added tag 2.1.1 for changeset a77f0a9ed93c
author | Dan Creswell <dan.creswell@gmail.com> |
---|---|
date | Sat, 12 Jun 2010 10:52:10 +0100 |
parents | 3dc0c5604566 |
children |
line wrap: on
line source
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"); } }