diff --git a/BakeryCookConsumer/META-INF/MANIFEST.MF b/BakeryCookConsumer/META-INF/MANIFEST.MF index 93a50da..afffa2c 100644 --- a/BakeryCookConsumer/META-INF/MANIFEST.MF +++ b/BakeryCookConsumer/META-INF/MANIFEST.MF @@ -6,5 +6,6 @@ Bundle-Version: 1.0.0.qualifier Bundle-Activator: bakerycookconsumer.BakeryCookConsumerActivator Bundle-RequiredExecutionEnvironment: JavaSE-15 Automatic-Module-Name: BakeryCookConsumer -Import-Package: org.osgi.framework;version="1.3.0" +Import-Package: bakerycookproducer, + org.osgi.framework;version="1.3.0" Bundle-ActivationPolicy: lazy diff --git a/BakeryCookConsumer/src/bakerycookconsumer/BakeryCookConsumerActivator.java b/BakeryCookConsumer/src/bakerycookconsumer/BakeryCookConsumerActivator.java index 5390980..c3c558c 100644 --- a/BakeryCookConsumer/src/bakerycookconsumer/BakeryCookConsumerActivator.java +++ b/BakeryCookConsumer/src/bakerycookconsumer/BakeryCookConsumerActivator.java @@ -1,22 +1,43 @@ package bakerycookconsumer; +import bakerycookproducer.BakeryCookProducer; +import java.util.Scanner; + import org.osgi.framework.BundleActivator; import org.osgi.framework.BundleContext; +import org.osgi.framework.ServiceReference; + + public class BakeryCookConsumerActivator implements BundleActivator { - private static BundleContext context; + ServiceReference serviceReference; + Scanner sc = new Scanner(System.in); - static BundleContext getContext() { - return context; - } + public void start(BundleContext context) throws Exception { + System.out.println("Start Cook Consumer Service"); + serviceReference = context.getServiceReference(BakeryCookProducer.class.getName()); + BakeryCookProducer bakeryadminproducer = (BakeryCookProducer) context.getService(serviceReference); + System.out.println(bakeryadminproducer.wellcomeCook()); + bakeryadminproducer.ViewAllRecord(); + +// System.out.println("_________________________________ Bakery Shop Add New Recipes _________________________________\n"); +// System.out.println("Item Categorys :Bars\tBreads\tBreakfast Products\tCookies\tDessertsEnter\n "); +// System.out.println("Enter food Item ?"); +// String bcfoodItem = sc.next(); +// System.out.println("Enter recipes Name ?"); +// String bcrecipesName = sc.next(); +// System.out.println("Enter Driscription ?"); +// String bcDriscription = sc.next(); +// bakeryadminproducer.insertnewRecipes(bcfoodItem , bcrecipesName ,bcDriscription); - public void start(BundleContext bundleContext) throws Exception { - BakeryCookConsumerActivator.context = bundleContext; } - public void stop(BundleContext bundleContext) throws Exception { - BakeryCookConsumerActivator.context = null; + public void stop(BundleContext context) throws Exception { + System.out.println("Cook Consumer Stop !!!"); + if(serviceReference != null) { + context.ungetService(serviceReference); + } } } diff --git a/BakeryCookProducer/META-INF/MANIFEST.MF b/BakeryCookProducer/META-INF/MANIFEST.MF index 29d5f67..be68247 100644 --- a/BakeryCookProducer/META-INF/MANIFEST.MF +++ b/BakeryCookProducer/META-INF/MANIFEST.MF @@ -8,3 +8,4 @@ Bundle-RequiredExecutionEnvironment: JavaSE-15 Automatic-Module-Name: BakeryCookProducer Import-Package: org.osgi.framework;version="1.3.0" Bundle-ActivationPolicy: lazy +Export-Package: bakerycookproducer diff --git a/BakeryCookProducer/src/bakerycook/CookRecipes.java b/BakeryCookProducer/src/bakerycook/CookRecipes.java new file mode 100644 index 0000000..3a885e2 --- /dev/null +++ b/BakeryCookProducer/src/bakerycook/CookRecipes.java @@ -0,0 +1,36 @@ +package bakerycook; + +public class CookRecipes { + private String foodItem; + private String recipesName; + private String driscription; + + public CookRecipes(){} + + + public CookRecipes(String foodItem, String recipesName, String driscription) { + super(); + this.foodItem = foodItem; + this.recipesName = recipesName; + this.driscription = driscription; + } + public String getFoodItem() { + return foodItem; + } + public void setFoodItem(String foodItem) { + this.foodItem = foodItem; + } + public String getRecipesName() { + return recipesName; + } + public void setRecipesName(String recipesName) { + this.recipesName = recipesName; + } + public String getDriscription() { + return driscription; + } + public void setDriscription(String driscription) { + this.driscription = driscription; + } + +} diff --git a/BakeryCookProducer/src/bakerycookproducer/BakeryCookProducer.java b/BakeryCookProducer/src/bakerycookproducer/BakeryCookProducer.java new file mode 100644 index 0000000..fef31b0 --- /dev/null +++ b/BakeryCookProducer/src/bakerycookproducer/BakeryCookProducer.java @@ -0,0 +1,8 @@ +package bakerycookproducer; + +public interface BakeryCookProducer { + public String wellcomeCook(); + public void insertnewRecipes(String foodItem , String recipesName , String Driscription); + public String display(); + public void ViewAllRecord(); +} diff --git a/BakeryCookProducer/src/bakerycookproducer/BakeryCookProducerActivator.java b/BakeryCookProducer/src/bakerycookproducer/BakeryCookProducerActivator.java index c2e7f66..9a8c918 100644 --- a/BakeryCookProducer/src/bakerycookproducer/BakeryCookProducerActivator.java +++ b/BakeryCookProducer/src/bakerycookproducer/BakeryCookProducerActivator.java @@ -2,21 +2,23 @@ import org.osgi.framework.BundleActivator; import org.osgi.framework.BundleContext; +import org.osgi.framework.ServiceRegistration; public class BakeryCookProducerActivator implements BundleActivator { - private static BundleContext context; + ServiceRegistration publishServiceRegistration; + - static BundleContext getContext() { - return context; - } - public void start(BundleContext bundleContext) throws Exception { - BakeryCookProducerActivator.context = bundleContext; + public void start(BundleContext context) throws Exception { + System.out.println("Bakery Cook Producer Start"); + BakeryCookProducer bakeryCookProducer = (BakeryCookProducer) new ProducerBakeryCook(); + publishServiceRegistration = context.registerService(BakeryCookProducer.class.getName(), bakeryCookProducer, null); } - public void stop(BundleContext bundleContext) throws Exception { - BakeryCookProducerActivator.context = null; + public void stop(BundleContext context) throws Exception { + System.out.println("Bakery Cook Producer Stop"); + publishServiceRegistration.unregister(); } } diff --git a/BakeryCookProducer/src/bakerycookproducer/ProducerBakeryCook.java b/BakeryCookProducer/src/bakerycookproducer/ProducerBakeryCook.java new file mode 100644 index 0000000..c0462fc --- /dev/null +++ b/BakeryCookProducer/src/bakerycookproducer/ProducerBakeryCook.java @@ -0,0 +1,156 @@ +package bakerycookproducer; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.RandomAccessFile; +import java.util.Scanner; + +import bakerycook.CookRecipes; + +public class ProducerBakeryCook implements BakeryCookProducer { + Scanner input = new Scanner(System.in); + CookRecipes recipes = new CookRecipes(); + + @Override + public String wellcomeCook() { + // TODO Auto-generated method stub + return "_________________________________ Bakery Cook DashBoard _________________________________\\n"; + } + + @Override + public void insertnewRecipes(String foodItem, String recipesName, String Driscription) { + // TODO Auto-generated method stub + recipes.setFoodItem(foodItem); + recipes.setRecipesName(recipesName); + recipes.setDriscription(Driscription); + this.AddRecord(); + + + } + private void AddRecord() { + // TODO Auto-generated method stub + boolean found = false; + /*try { + oos =new ObjectOutputStream(new FileOutputStream(file)); + oos.writeObject("Amila"+" "+"Panadura"); + oos.close(); + System.out.println("Added"); + } catch (FileNotFoundException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + }*/ + try { + File myObj = new File("C:\\Users\\sean udayantha\\Desktop\\New folder\\Recipes.txt"); + if (myObj.createNewFile()) { + System.out.println("File created: " + myObj.getName()); + System.out.println("File Opened: " + myObj.getAbsolutePath()); + } else { + System.out.println("File Opened: " + myObj.getAbsolutePath()); + } + try { + String nameNumberString; + int index; + String foodItem; + String recipesName; + String Driscription; + String newfoodItem= recipes.getFoodItem(); + String newrecipesName = recipes.getRecipesName(); + String newDriscription = recipes.getDriscription(); + + + /**FileWriter myWriter = new FileWriter("customer.txt"); + myWriter.write(customer.getcName()+" "+customer.getcEmail()); + myWriter.close(); + System.out.println("Successfully wrote to the file.");**/ + + RandomAccessFile raf= new RandomAccessFile(myObj, "rw"); + + + +// while (raf.getFilePointer() < raf.length()) { +// +// +// nameNumberString = raf.readLine(); +// +// +// String[] lineSplit +// = nameNumberString.split("!"); +// +// +// name = lineSplit[0]; +// number = lineSplit[1]; +// username= lineSplit[2]; +// password = lineSplit[3]; +// +// if (name.equals(newName) +// || number.equals(newNumber)) { +// found = true; +// System.out.println(" Delivery preson already Registered!!! "); +// +// break; +// } +// } + + if (found == false) { + + + nameNumberString= newfoodItem + "!"+ newrecipesName+"!"+newDriscription; + + + raf.writeBytes(nameNumberString); + + raf.writeBytes(System.lineSeparator()); + + System.out.println("New Recipes added Successfull !!! "); + System.out.println("Hi " + newfoodItem+", well be added to the shop "); + + raf.close(); + } + + + } catch (IOException e) { + System.out.println("An error occurred."); + e.printStackTrace(); + } + + + + + } catch (IOException e) { + System.out.println("An error occurred."); + e.printStackTrace(); + } + + } + + + + public void ViewAllRecord() { + try { + File myObj = new File("C:\\Users\\sean udayantha\\Desktop\\New folder\\oder.txt"); + Scanner myReader = new Scanner(myObj); + while (myReader.hasNextLine()) { + String data = myReader.nextLine(); + System.out.println("......................................Avilabal Oders in shop....................................\n"); + System.out.println(data); + } + myReader.close(); + } catch (FileNotFoundException e) { + System.out.println("An error occurred."); + e.printStackTrace(); + } + + } + @Override + public String display() { + // TODO Auto-generated method stub + return null; + } + + + +}