Guest User

Untitled

a guest
May 26th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.97 KB | None | 0 0
  1. package bordcomputer;
  2.  
  3. import org.osgi.framework.BundleActivator;
  4. import org.osgi.framework.BundleContext;
  5. import org.osgi.framework.ServiceReference;
  6.  
  7. import es.us.isa.FAMA.Reasoner.QuestionTrader;
  8. import es.us.isa.FAMA.Reasoner.questions.NumberOfProductsQuestion;
  9. import es.us.isa.FAMA.Reasoner.questions.ValidQuestion;
  10. import es.us.isa.FAMA.models.variabilityModel.VariabilityModel;
  11.  
  12. public class Activator implements BundleActivator {
  13.  
  14.     private static BundleContext context;
  15.     private ServiceReference sr;
  16.  
  17.     static BundleContext getContext() {
  18.         return context;
  19.     }
  20.  
  21.     /*
  22.      * (non-Javadoc)
  23.      * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
  24.      */
  25.     public void start(BundleContext bundleContext) throws Exception {
  26.         String className = QuestionTrader.class.getCanonicalName();
  27.         //attribute sr (ServiceReference) defined on the Activator
  28.         sr = context.getServiceReference(className);
  29.         QuestionTrader qt = (QuestionTrader) context.getService(sr);
  30.         if (qt != null){
  31.         System.out.println("FaMa load successful");
  32.         //here you use FaMa as on Standalone version
  33.         consumeFaMa(qt);
  34.         }
  35.     }
  36.  
  37.     private void consumeFaMa(QuestionTrader qt) {
  38.         //A feature model is loaded
  39.         VariabilityModel fm = qt.openFile("fm-samples/HIS.fm");
  40.         qt.setVariabilityModel(fm);
  41.         //////// VALID QUESTION + NUMBER PRODUCTS QUESTION /////////
  42.         ValidQuestion vq = (ValidQuestion) qt.createQuestion("Valid");
  43.         qt.ask(vq);
  44.         if (vq.isValid()) {
  45.         NumberOfProductsQuestion npq = (NumberOfProductsQuestion)
  46.         qt.createQuestion("#Products");
  47.         qt.ask(npq);
  48.         System.out.println("The number of products is: "+
  49.         npq.getNumberOfProducts());
  50.         } else {
  51.         System.out.println("Your feature model is not valid");
  52.         }
  53.     }
  54.  
  55.     /*
  56.      * (non-Javadoc)
  57.      * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
  58.      */
  59.     public void stop(BundleContext bundleContext) throws Exception {
  60.         if (sr != null){
  61.             context.ungetService(sr);
  62.             }
  63.     }
  64.  
  65. }
Add Comment
Please, Sign In to add comment