Advertisement
Guest User

Bundle Implementation

a guest
May 26th, 2015
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.08 KB | None | 0 0
  1.  
  2. public class VikingService implements IVikingService {
  3.  
  4.     ArrayList<IGameEntity> vikings;
  5.  
  6.     /**
  7.      * Default implementation loads 4 vikings of each type into list
  8.      */
  9.     public VikingService() {
  10.         vikings = new ArrayList<IGameEntity>();
  11.  
  12.         vikings.add(new Viking(100, 100, IGameEntity.Type.VIKING));
  13.         vikings.add(new Viking(100, 200, IGameEntity.Type.VIKING));
  14.         vikings.add(new Viking(100, 520, IGameEntity.Type.VIKING));
  15.         vikings.add(new Viking(100, 620, IGameEntity.Type.VIKING));
  16.  
  17.         vikings.add(new Viking(1000, 100, IGameEntity.Type.ENEMY_VIKING));
  18.         vikings.add(new Viking(1000, 200, IGameEntity.Type.ENEMY_VIKING));
  19.         vikings.add(new Viking(1000, 520, IGameEntity.Type.ENEMY_VIKING));
  20.         vikings.add(new Viking(1000, 620, IGameEntity.Type.ENEMY_VIKING));
  21.  
  22.     }
  23.  
  24.     //@todo implement selection based on enum type. make new array list and pluck out appropriate types to return in new list.
  25.     @Override
  26.     public ArrayList<IGameEntity> getVikings(IGameEntity.Type t) {
  27.         return vikings;
  28.     }
  29.  
  30.     @Override
  31.     public void disposeVikings() {
  32.         vikings.clear();
  33.         vikings = null;
  34.  
  35.     }
  36.  
  37.     @Override
  38.     public void addViking(double xPos, double yPos, IGameEntity.Type t) {
  39.         if (vikings == null)
  40.             vikings = new ArrayList<IGameEntity>();
  41.         vikings.add(new Viking(xPos, yPos, t));
  42.     }
  43.  
  44.  
  45. }
  46.  
  47.  
  48.  
  49.  
  50. //////////////////////ACTIVATOR BELOW HERE//////////////////////
  51. public class Activator implements BundleActivator {
  52.     private ServiceRegistration registration;
  53.  
  54.     @Override
  55.     public void start(BundleContext context) throws Exception {
  56.         registration = context.registerService(IVikingService.class, new VikingService(), null);
  57.     }
  58.  
  59.     @Override
  60.     public void stop(BundleContext context) throws Exception {
  61.         ServiceReference ref = context.getServiceReference(IVikingService.class);
  62.         IVikingService v = (IVikingService) context.getService(ref);
  63.         v.disposeVikings();
  64.         registration.unregister();
  65.  
  66.     }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement