Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

step 11 #8

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion BakeryCookConsumer/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
@@ -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);
}
}

}
1 change: 1 addition & 0 deletions BakeryCookProducer/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -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
36 changes: 36 additions & 0 deletions BakeryCookProducer/src/bakerycook/CookRecipes.java
Original file line number Diff line number Diff line change
@@ -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;
}

}
Original file line number Diff line number Diff line change
@@ -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();
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

}
156 changes: 156 additions & 0 deletions BakeryCookProducer/src/bakerycookproducer/ProducerBakeryCook.java
Original file line number Diff line number Diff line change
@@ -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;
}



}