210 likes | 297 Views
Java in the Box: Implementing the BoxScript Component Language. Yi Liu Electrical Engineering and Computer Science South Dakota State University H. Conrad Cunningham Computer and Information Science University of Mississippi. Software Components. provided. required. required.
E N D
Java in the Box: Implementing the BoxScript Component Language Yi Liu Electrical Engineering and Computer Science South Dakota State University H. Conrad Cunningham Computer and Information ScienceUniversity of Mississippi
provided required required provided interface inner component Component1 Component2 Components – A Closer Look
Storage Storage Pricing Discounting Discounting2 CalPrice Pricing Discounting2 Discounting A Simple Example Compositionality Flexibility
Key Concepts Interface • Interface (type) • Java interface gives operation signatures • Provided interface • describes operations the component implements that other components may use • Required interface • describes operations the component uses that must be implemented by another component Price.java public interface Price { double getPrice(int client, int item, int quantity); }
1…n P1 Pn … Box … R1 Rn 0…m Key Concepts Box • A box is a component • whose description includes provided and required interfaces • has 1..n provided interfaces • has 0..m required interfaces • Boxes may be • abstract • concrete • atomic • compound
Price Pr PricingAbs Dc PrRt PriceRetrieve Discount Key Concepts Abstract Box • Abstract box • does not implement provided interfaces • implemented by concrete boxes PricingAbs.box abstract box PricingAbs { provided interface Price Pr; required interface Discount Dc, PriceRetrieve PrRt; } Interface type Interface Handle
Price Pr Pricing Dc PrRt PriceRetrieve Discount Key Concepts Concrete Box • Atomic box • does not contain any other boxes • implements the provided interfaces Pricing.box box Pricing implements PricingAbs { provided interface Price Pr; required interface Discount Dc; } Interface type Interface handle
Price Pr Pricing Dc PrRt PriceRetrieve Discount Key Concepts Interface Implementation for Atomic Box PrImp.java public class PrImp implements Price { private BoxTop _box; Discount dc; // required interface PriceRetrieve prRt; //required interface public PrImp(BoxTop myBox) { _box = myBox; InterfaceName name = new InterfaceName("Dc"); dc = (Discount)_box.getRequiredItf(name); name = new InterfaceName(“PrRt"); prRt = (PriceRetrieve)_box.getRequiredItf(name); } public double getPrice(int client,int item,int quantity) { double price = prRt.itemPrice(item); double disc = dc.getDiscount(client, item, quantity); return price * (1 – disc * 0.01) * quantity; } }
Key Concepts Compound Box • Compound box • Composed from atomic boxes or other compound boxes • Follows composition rules • hide provided interfaces unless explicitly exposed • must expose required interface of constituent unless connected to provided interface of another constituent
box handle Price Pr PricingAbs boxP Price tPrice Discount Dis Dc PriceRetrieve Discount PrRt DiscountingAbs boxD PriceRetrieve PrRt StorageAbs boxS CalPrice Key ConceptsCompound Box Example box CalPrice implements CalPriceAbs { composed from PricingAbs boxP, DiscountingAbs boxD, StorageAbsboxS; provided interface Price tPricefromboxP.Pr; connectboxP.DctoboxD.Dis, boxP.PrRt to boxS.PrRt; }
Key ConceptsBox Variant • Box variants • Enable flexibility • Implement same (parent) abstract box • Can be substituted for each other • Conform to their (parent) abstract box • provide at least the provided interfaces of parent • require at most the required interfaces of parent
Key ConceptsBox Conformity Suppose • IP2’ extends IP2 • IR1’ extends IR1 IP1 IP2’ IP3 IP1 IP2 Provided interfaces P1 P3 P2 P1 P2 B BAbs Required interfaces R1 R2 R1 R2 R3 IR1 IR2 IR1’ IR2 IR3 B conforms to BAbs
Box code BoxCompiler Java code Java Compiler BoxScript ImplementationBox Source Code and Compilation • For all boxes • interfaces (.java) by user • box description (.box) by user • For atomic boxes only • interface implementation (.java) by user • For concrete boxes only • configuration information (.conf) by user • box manager code (.java) by compiler
BoxScript Implementation Box Manager Implementation • package declaration • define filesystem usage • import • interfacedeclarations • data type declarations • variable declarations • instance variables for class • class definition Box manager B.java Concrete Box B
<<interface >> Price references implements instantiates <<Java class >> Pricing <<Java class >> PrImp instantiates Pricing constructor Pricing <<interface >> Discount <<Java class >> CalPrice instantiates Discounting implements constructor CalPrice instantiates <<Java class >> Discounting <<Java class >> DisImp constructor Discounting references BoxScript ImplementationBox Runtime Structure Lazy instantiation
BoxScript ImplementationBox Manager Code • Generated by compiler • to instantiate box instances • to assign references to interface handles
BoxTop BoxTop() void setProvInterfacceDsc(InterfaceDsc pItfDsc) void setRequInterfaceDsc(InterfaceDsc rItfDsc) Object getProvidedItf(InterfaceName name) Object getRequiredItf(InterfaceName name) void setRequiredItf(InterfaceName iname, Object objRef) BoxScript Implementation Box Manager Implementation • Supports lazy instantiation • BoxTop
BoxScript Implementation Box Manager Implementation • Code generation generateCode (B’dscFile, mngFile) //mngFile : filename for box manager read in dscFile genPackage(); genImports(); genVars(); genConstructor(); genGetProvidedItf(); // generate overriding method getProvidedItf if B is compound genSetRequiredItf(); // generate overriding method setRequiredItf writeIntoFile(mngFile);
Conclusion • Component-oriented programming language BoxScript • Builds upon Java • Provides novel concepts of • box type structure • box variants • box conformity • interface satisfaction to support composition and flexibility