Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package bordcomputer;
- import org.osgi.framework.BundleActivator;
- import org.osgi.framework.BundleContext;
- import org.osgi.framework.ServiceReference;
- import es.us.isa.FAMA.Reasoner.QuestionTrader;
- import es.us.isa.FAMA.Reasoner.questions.NumberOfProductsQuestion;
- import es.us.isa.FAMA.Reasoner.questions.ValidQuestion;
- import es.us.isa.FAMA.models.variabilityModel.VariabilityModel;
- public class Activator implements BundleActivator {
- private static BundleContext context;
- private ServiceReference sr;
- static BundleContext getContext() {
- return context;
- }
- /*
- * (non-Javadoc)
- * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
- */
- public void start(BundleContext bundleContext) throws Exception {
- String className = QuestionTrader.class.getCanonicalName();
- //attribute sr (ServiceReference) defined on the Activator
- sr = context.getServiceReference(className);
- QuestionTrader qt = (QuestionTrader) context.getService(sr);
- if (qt != null){
- System.out.println("FaMa load successful");
- //here you use FaMa as on Standalone version
- consumeFaMa(qt);
- }
- }
- private void consumeFaMa(QuestionTrader qt) {
- //A feature model is loaded
- VariabilityModel fm = qt.openFile("fm-samples/HIS.fm");
- qt.setVariabilityModel(fm);
- //////// VALID QUESTION + NUMBER PRODUCTS QUESTION /////////
- ValidQuestion vq = (ValidQuestion) qt.createQuestion("Valid");
- qt.ask(vq);
- if (vq.isValid()) {
- NumberOfProductsQuestion npq = (NumberOfProductsQuestion)
- qt.createQuestion("#Products");
- qt.ask(npq);
- System.out.println("The number of products is: "+
- npq.getNumberOfProducts());
- } else {
- System.out.println("Your feature model is not valid");
- }
- }
- /*
- * (non-Javadoc)
- * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
- */
- public void stop(BundleContext bundleContext) throws Exception {
- if (sr != null){
- context.ungetService(sr);
- }
- }
- }
Add Comment
Please, Sign In to add comment