Presentation is loading. Please wait.

Presentation is loading. Please wait.

WEB TECHNOLOGIES – Unit IV

Similar presentations


Presentation on theme: "WEB TECHNOLOGIES – Unit IV"— Presentation transcript:

1 WEB TECHNOLOGIES – Unit IV
By B. Ravinder Reddy Assistant Professor Department of CSE UNIT-4 WT

2 Lecture No. Topic Name Slide No.
LECTURE PLAN UNIT-4 Lecture No. Topic Name Slide No. L1 Introduction to Java Beans 2-33 L2 Advantages of Java Beans 34-39 L3 BDK Introspection 40-49 L4 Using Bound properties 50-61 L5 Constrained properties Persistence 62-73 L6 Bean info Interface 74-79 L7 Customizes, Java Beans API 80-87 L8 Introduction to EJB’s 88-111 UNIT-4 WT

3 LECTURE-1 UNIT-4 WT

4 Java Beans UNIT-4 WT

5 JAVA BEANS JAVA BEANS: Java beans are the software components that has been designed to be reusable in a variety of different environments Java bean is basically a java class with the following rules: 1. All the instance variables must be private 2. Access to the instance variables should be provided by using setXXX() and getXXX() methods 3. There should be a zero parameter constructor in the class UNIT-4 WT

6 Java beans cont… Ex: class Mybean { private int htno; Mybean() }
void setHtno( int x ) { htno = x; int getHtno() { return htno; UNIT-4 WT

7 JAVABEANS USING BDK BDK stands for BEAN DEVELOPEMENT KIT
USAGE: 2 Types 1: Executing the Existing Beans 2: Executing the User-Defined Beans NOTE: For Executing the JavaBeans Using BDK Compulsory You Have To Install JDK. UNIT-4 WT

8 BDK COMPONENTS BDK Contains 3 types of Components: 1) Tool Box
2) Bean Box 3) Property Sheet UNIT-4 WT

9 BEAN DEVELOPEMENT KIT Property Sheet Tool Box Bean Box UNIT-4 WT

10 Executing the Existing Beans
Position the cursor on the tool box entry labeled juggler and click left mouse button. Move the cursor to the bean box area and click the left mouse button. labeled OurButton and click left mouse button. Go to the properties window and change the label UNIT-4 WT

11 Executing the Existing Beans
By selecting the button, go to the menu bar of the Bean Box and select Edit – Events – action- action Performed. You should see a line extending from the button to the cursor Move the cursor so that the line drop inside the display area of juggler, and click left mouse button. Now you should see the Event Target Dialog Box. The dialog box allows you to choose a method that should be invoked when the button is clicked UNIT-4 WT

12 Executintg Existing Bean(contd..)
UNIT-4 WT

13 Executintg Existing Bean(contd..)
UNIT-4 WT

14 Executintg Existing Bean(contd..)
UNIT-4 WT

15 How to execute User Defines Beans using BDK
For Executing the User Defined Beans with BDK we require 2 files 1. JAR File 2. Manifest File UNIT-4 WT

16 JAR FILES JAR File stands for JAVA ARCHIEVE FILE
JAR Files are Java’s Version of zip Files There are Two main uses for JAR files 1) The first use is to compress (make a smaller size) a number of files into one file (archiving) 2) It makes easy to download JAR files can be opened with WinZip or WinRar. In terms of Java applications, the ability to archive any number of source or class files into one single archive represents the biggest advantage - distributing one file containing hundreds of files is so much easier than distributing hundreds of files separately UNIT-4 WT

17 Here is how to create a compressed JAR file:
Creating a Jar file: The syntax of utility used to create jar file is Jar options (list of files) List of Options: c: Create a new archive (jar) f : The first element in the file list is the name of the jar that is to be created or accessed m: The second element in the file list is the name of the external manifest file t : Tabulate the contents of jar u: Update the jar file x: Extract the files from jar 0: Do not use compression v: Generate verbose output on standard output file UNIT-4 WT

18 JAR(Contd..) Multiple options can be used together. They all must appear after the "jar" command with no white space separating them. Examples: creating a jar file with name MT.jar that contains all the .class and .gif files of the current directory Jar cf MT.jar *.class *.gif And with the above if we have a manifest file that is to be added Then the above statement will become Jar cfm MT.jar Manf.mf *.class *.gif UNIT-4 WT

19 Create An Executable JAR
Manifest file: A developer must provide a manifest file to indicate What are the components of a jar file and Which of these components in a jar file are java beans Ex : name: sunw\demo\slides\fig1.gif name: sunw\demo\slides\fig2.gif name: sunw\demo\slides\slide.class Java-bean: true UNIT-4 WT

20 Example: Colors.java Program: import java.awt.*;
import java.awt.event.*; public class Colors extends Canvas { private Color color; private boolean rectangular; public Colors() addMouseListener(new MouseAdapter() public void mousePressed(MouseEvent me) change(); } }); UNIT-4 WT

21 Example(Contd..) rectangular=false; setSize(200, 100); change(); } public boolean getRectangular() { return rectangular; public void setRectangular(boolean flag) this. rectangular = flag; repaint(); UNIT-4 WT

22 Example(contd..) { color = randomColor(); repaint(); }
public void change() { color = randomColor(); repaint(); } private Color randomColor() int r = (int)(255*Math.random()); int g = (int)(255*Math.random()); int b = (int)(255*Math.random()); return new Color(r,g,b); UNIT-4 WT

23 Example(contd..) public void paint (Graphics g) {
Dimension d = getSize(); int h = d.height; int w = d.width; g.setColor(color); if(rectangular) g.fillRect(0, 0, w-1, h-1); } else g.fillOval(0, 0, w-1, h-1); UNIT-4 WT

24 Steps For Executing The Existing Bean:
Compile the Colors. java file using Command Prompt Create The Manifest file Create Jar File Load The Jar File into Bdk Steps For Creating The ManifestFile Name: Colors. class Java-Bean: True Save this file in the form of “manifest.mft” UNIT-4 WT

25 Steps For Creating the Jar file:
Start Command Prompt. Navigate to the folder that holds your class files: C:\>raju Compile your classes: C:\raju> javac *.java Then create Manifest file Create a jar file: C:\raju> jar cvfm bdk.jar manifest.mft *.class UNIT-4 WT

26 Executing the Existing Beans
UNIT-4 WT

27 M V C: MVC ( Model View Controller) The MVC design pattern is the basis for the most web-application frameworks today Ex: Struts, JSF, Spring are all implementations of MVC design concept The new programming environment called Ruby on rails is entirely based on MVC design pattern In MVC the Controller is implemented by using a servlet View is implemented by JSP and the Model by Java beans UNIT-4 WT

28 M V C Cont.. A servlet is a Java programming language class that is used to extend the capabilities of servers that host applications access via a request-response programming model Java Server Pages (JSP) is a technology based on the Java language and enables the development of dynamic web sites. JSP was developed by Sun Microsystems to allow server side development. JSP files are HTML files with special Tags, containing Java source code that provide the dynamic content UNIT-4 WT

29 JSP cont… There are four main tags:
1. Declaration tag ( <%! %> ) 2. Expression tag ( <%= %>) 3. Directive Tag ( directive … %>) 4. Scriptlet tag ( <% … %> ) 5. Action tag (<jsp : usebean ----%> ) UNIT-4 WT

30 M V C Model: Controller (servlet) Model (Bean) Client View (JSP)
browser View (JSP) Server UNIT-4 WT

31 Java Beans A java bean is a software component that
has been designed to be reusable in a variety of different environments. Java Bean architecture is based on component model which enables developers to create software units called “components”. Components are reusable units and can be combined to build complex systems. Java beans defines an architecture that specifies how these building blocks can operate together. A java bean is a simple java class. All bean components follows Java Beans specification which specifies how different components can communicate with each other and interact with a builder tool. UNIT-4 WT

32 The required conventions for java beans
1. All the instance variables must be private. 2. It should have a no-argument constructor in the class so that its object can be created without knowing any thing about the bean. 3. Its properties must be accessable using getter/setter and other methods. UNIT-4 WT

33 Following are standard naming conventions.
Every property defined in a java bean consists of setter and getter methods. If name is a property defined in the Bean class then 1. public void setPropertyName(PropertyType value) Ex: public void setName(String str) 2. public PropertyType getPropertyName( ) Ex: public String getName( ) UNIT-4 WT

34 Characteristics of a Java Bean
There is no restriction on the capability of a Bean .It may perform a simple function such as the spell check of a document or a complex function such a forecasting the performance of a stock exchange. A bean may be visible to the end user. One example of this is a button of a graphical user interface. A bean may not be visible. Example it may be used as a decoder for stream of multimedia information. A bean may also be designed to work autonomously on a user’s work station or to work in corporation with a set of other distributed components. Example software that generates a pie chart from a set of data points. UNIT-4 WT

35 LECTURE-2 UNIT-4 WT

36 Advantages of Java Beans
A software component architecture provides standard mechanisms to deal with software building blocks. The following list enumerates some of the specific benefits that Java technology provides for a component developer: A Bean obtains all the benefits of Java's "write-once, run-anywhere" paradigm. The properties, events, and methods of a Bean that are exposed to an application builder tool can be controlled. A Bean may be designed to operate correctly in different locales, which makes it useful in global markets. UNIT-4 WT

37 Auxiliary software can be provided to help a person configure a Bean
Auxiliary software can be provided to help a person configure a Bean. This software is only needed when the design-time parameters for that component are being set. It does not need to be included in the run-time environment. The configuration settings of a Bean can be saved in persistent storage and restored at a later time. A Bean may register to receive events from other objects and can generate events that are sent to other objects UNIT-4 WT

38 Application Builder Tools
When working with Java Beans, most developers use an application builder tool, a utility that enables you to configure a set of Beans, connect them together, and produce a working application. Builder Tools have the following capabilities: A palette is provided that lists all of the available Beans. As additional Beans are developed or purchased, they can be added to the palette. UNIT-4 WT

39 A worksheet is displayed that allows the designer to lay out Beans in a graphical user
interface. A designer may drag and drop a Bean from the palette to this worksheet. Special editors and customizers allow a Bean to be configured. This is the mechanism by which the behavior of a Bean may be adapted for a particular environment. UNIT-4 WT

40 Commands allow a designer to inquire about the state and behavior of a Bean. This information automatically becomes available when a Bean is added to the palette. Capabilities exist to interconnect Beans. This means that events generated by one component are mapped to method invocations on other components. When a collection of Beans has been configured and connected, it is possible to save all of this information in a persistent storage area. At a later time, this information can then be used to restore the state of the application. UNIT-4 WT

41 LECTURE-3 UNIT-4 WT

42 Introspection Introspection is the process of analyzing a Bean to determine its capabilities. This is an essential feature of the Java Beans API, because it allows an application builder tool to present information about a component to a software designer. Without introspection, the Java Beans technology could not operate. There are two ways in which the developer of a Bean can indicate which of its properties, events, and methods should be exposed by an application builder tool. With the first method, simple naming conventions like set/get property( ) and add/remove Listner( ) are used. These allow the introspection mechanisms to infer information about a Bean. In the second way, an additional class is provided that explicitly supplies this information. UNIT-4 WT

43 Purpose of Introspection
introspection is implemented to provide great advantages, including: Portability - Everything is done in the Java platform, so you can write components once, reuse them everywhere. There are no extra specification files that need to be maintained independently from your component code. There are no platform-specific issues to contend with. Your component is not tied to one component model or one proprietary platform. You get all the advantages of the evolving Java APIs, while maintaining the portability of your components. Reuse - By following the JavaBeans design conventions, implementing the appropriate interfaces, and extending the appropriate classes, you provide your component with reuse potential that possibly exceeds your expectations. UNIT-4 WT

44 Introspection Example
The following example represents code to perform introspection: import java.beans.BeanInfo; import java.beans.Introspector; import java.beans.IntrospectionException; import java.beans.PropertyDescriptor; public class SimpleBean { private final String name = "SimpleBean"; private int size; public String getName() return this.name; } UNIT-4 WT

45 public int getSize() { return this
public int getSize() { return this.size; } public void setSize( int size ) this.size = size; public static void main( String[] args ) throws IntrospectionException BeanInfo info = Introspector.getBeanInfo( SimpleBean.class ); for ( PropertyDescriptor pd : info.getPropertyDescriptors() ) System.out.println( pd.getName() ); UNIT-4 WT

46 Output UNIT-4 WT

47 Properties A bean property is a named attribute of a bean that can affect its behavior or appearance. Examples of bean properties include color, label, font, font size, and display size. The JavaBeans specification defines the following types of bean properties: Simple – A bean property with a single value whose changes are independent of changes in any other property. Indexed – A bean property that supports a range of values instead of a single value. Bound – A bean property for which a change to the property results in a notification being sent to some other bean. Constrained – A bean property for which a change to the property results in validation by another bean. The other bean may reject the change if it is not appropriate. UNIT-4 WT

48 Bean properties can also be classified as follows:
Writable – A bean property that can be changed Standard Expert Preferred Read Only – A bean property that cannot be changed. Hidden – A bean property that can be changed. However, these properties are not disclosed with the BeanInfo class BeanBuilder uses this schema to group and represent properties in the Properties window. UNIT-4 WT

49 Simple Properties To add simple properties to a bean, add appropriate getXXX and setXXX methods (or isXXX and setXXX methods for a boolean property). The names of these methods follow specific rules called design patterns. UNIT-4 WT

50 MyBean.java public class MyBean {
/** Creates a new instance of MyBean */ public MyBean() { } /** Holds value of property title. */ private String title; /** Getter for property Value of property title. */ public String getTitle() { return this.title; /** Setter for property title New value of property title. */ public void setTitle(String title) { this.title = title; UNIT-4 WT

51 LECTURE-4 UNIT-4 WT

52 Bound Properties Bound properties support the PropertyChangeListener class. Sometimes when a Bean property changes, another object might need to be notified of the change, and react to the change. Whenever a bound property changes, notification of the change is sent to interested listeners. The accessor methods for a bound property are defined in the same way as those for simple properties. However, you also need to provide the event listener registration methods forPropertyChangeListener classes and fire a PropertyChangeEvent event to the PropertyChangeListener objects by calling their propertyChange methods UNIT-4 WT

53 The convenience PropertyChangeSupport class enables your bean to implement these methods. Your bean can inherit changes from the PropertyChangeSupportclass, or use it as an inner class In order to listen for property changes, an object must be able to add and remove itself from the listener list on the bean containing the bound property. It must also be able to respond to the event notification method that signals a property change. The PropertyChangeEvent class encapsulates property change information, and is sent from the property change event source to each object in the property change listener list with the propertyChange method. UNIT-4 WT

54 Implementing Bound Property
To implement a bound property in your application, follow these steps: Import the java.beans package. This gives you access to the PropertyChangeSupport class. Instantiate a PropertyChangeSupport object. This object maintains the property change listener list and fires property change events. You can also make your class a PropertyChangeSupport subclass. Implement methods to maintain the property change listener list. Since a PropertyChangeSupport subclass implements these methods, you merely wrap calls to the property-change support object's methods. Modify a property's set method to fire a property change event when the property is changed. UNIT-4 WT

55 Boundprop_source.java import java.beans.*; import java.beans.PropertyChangeListener; import java.beans.PropertyChangeSupport; import java.awt.*; /** Bean with bound properties. */ public class Boundprop_source extends Canvas { PropertyChangeSupport pcs; Color mycolor=Color.blue; public DemoSource() pcs = new PropertyChangeSupport( this ); setSize(200,200); setVisible(true); } UNIT-4 WT

56 public void paint( Graphics g ) { setBackground(mycolor); g
public void paint( Graphics g ) { setBackground(mycolor); g.drawString("source",20,50); } public Color getBGColor() return mycolor; public void setBGColor(Color cc) Color temp= mycolor; mycolor=cc; pcs.firePropertyChange("BGColor",temp,cc); repaint(); UNIT-4 WT

57 this.pcs.addPropertyChangeListener( listener ); }
public void addPropertyChangeListener( PropertyChangeListener listener ) { this.pcs.addPropertyChangeListener( listener ); } public void removePropertyChangeListener( PropertyChangeListener listener ) this.pcs.removePropertyChangeListener( listener ); public static void main(String args[]) new DemoSource(); UNIT-4 WT

58 Boundprop_Target.java import java.beans.*; import java.beans.PropertyChangeListener; import java.beans.PropertyChangeSupport; import java.awt.*; /** Bean with bound properties. */ class Boundpro_Target extends Canvas implements PropertyChangeListener { PropertyChangeSupport pcs; Color listcolor=Color.gray; public DemoTarget() setSize(200,200); setVisible(true); } UNIT-4 WT

59 public void paint( Graphics g ) { g
public void paint( Graphics g ) { g.drawString("Target",20,50); setBackground(listcolor); } public Color getBGColor() return listcolor; public void setBGColor(Color cc) listcolor=cc; repaint(); UNIT-4 WT

60 public void propertyChange( PropertyChangeEvent pce ) {
setBGColor(listcolor); pce.getNewValue(); } public static void main(String args[]) new DemoTarget(); UNIT-4 WT

61 Indexed Properties An indexed property is an array of properties or objects that supports a range of values and enables the accessor to specify an element of a property to read or write. Indexed properties are specified by the following methods: //Methods to access individual values public PropertyElement getPropertyName(int index) public void setPropertyName(int index, PropertyElement element) //Methods to access the entire indexed property array public PropertyElement[] getPropertyName() public void setPropertyName(PropertyElement element[]) Note: The distinction between the get and set methods for indexed properties is subtle. The get method either has an argument that is the array index of the property, or returns an array. The set method either has two arguments, namely an integer array index and the property element object that is being set, or has the entire array as an argument. UNIT-4 WT

62 The following listing shows a class that has one read/write indexed property:
public class PieChart { private double data[ ]; public double getData(int index) { return data[index]; } public void setData(int index, double value) { data[index] = value; public double[ ] getData( ) { return data; public void setData(double[ ] values) { data = new double[values.length]; System.arraycopy(values, 0, data, 0, values.length); UNIT-4 WT

63 LECTURE-5 UNIT-4 WT

64 Constrained Properties
A bean property is constrained if the bean supports the VetoableChangeListener and PropertyChangeEvent classes. The set method for this property throws a PropertyVetoException . Constrained properties are more complicated than bound properties because they also support property change listeners which happen to be vetoers. The following operations in the setXXX method for the constrained property must be implemented in this order: Save the old value in case the change is vetoed. Notify listeners of the new proposed value, allowing them to veto the change. UNIT-4 WT

65 If no listener vetoes the change (no exception is thrown), set the property to the new value.
The accessor methods for a constrained property are defined in the same way as those for simple properties, with the addition that the setXXX method throws a PropertyVetoException exception. The syntax is as follows: public void setPropertyName(PropertyType pt) throws PropertyVetoException {code} UNIT-4 WT

66 Handling Vetoes If a registered listener vetoes a proposed property change by throwing a PropertyVetoException exception, the source bean with the constrained property is responsible for the following actions: Catching exceptions. Reverting to the old value for the property. Issuing a new VetoableChangeListener.vetoableChange call to all listeners to report the reversion. The VetoableChangeListener class throws a PropertyVetoException and handles the PropertyChangeEvent event fired by the bean with the constrained property. The VetoableChangeSupport provides the following operations: UNIT-4 WT

67 Keeping track of VetoableChangeListener objects.
Issuing the vetoableChange method on all registered listeners. Catching any vetoes (exceptions) thrown by listeners. Informing all listeners of a veto by calling vetoableChange again, but with the old property value as the proposed "new" value. UNIT-4 WT

68 Implementing Constrained Property
To implement a constrained property in your application, follow these steps: Import the java.beans package. This gives you access to the VetoableChangeListner Interface. Implement the VetoableChangeListner Interface to the Bean class , you are writing. Over ride abstract method votoableChange( ) Instantiate a VetoableChangeSupport object. VetoableChangeSupport vetos= new VetoableChangeSupport(this) This object manages a list of VetoableChangeListners and fires property change events at each object in the list when a change occur to a constrained property. UNIT-4 WT

69 Public void addVetoableChangeListner( VetoableChangeListner vcl) {
Implement methods to maintain the property change listener list. Since a PropertyChangeSupport subclass implements these methods, you merely wrap calls to the property-change support object's methods. Public void addVetoableChangeListner( VetoableChangeListner vcl) { Vetos.addVetoableChangeListner(vcl); } Public void removeVetoableChangeListner( Vetos.removeVetoableChangeListner(vcl); Modify a property's set method to fire a property change event when the property is changed. This includes adding throws clause to the setter method’s signature. UNIT-4 WT

70 constrined_source.java import java.beans.*; import java.awt.*; /** Bean with constrained properties. */ public class constrained_source extends Canvas { VetoableChangeSupport vcs; String str=“Hello”; public constrained_source() vcs = new VetoableChangeSupport( this ); setSize(200,200); setVisible(true); } UNIT-4 WT

71 public void paint( Graphics g ) { g
public void paint( Graphics g ) { g.drawString("str",30,40); } public String getMyText() return str; } public void setMyText(String s) String temp= str; str=s; try vcs.fireVetoableChange(“myText",temp,s); }catch(PropertyVetoException e) str=temp; repaint(); } } UNIT-4 WT

72 Public void addVetoableChangeListner( VetoableChangeListner vcl) {
vcs.addVetoableChangeListner(vcl); } Public void removeVetoableChangeListner( vcs.removeVetoableChangeListner(vcl); public static void main(String args[]) new constrained_source (); UNIT-4 WT

73 constrined_Listner.java import java.beans.*; import java.awt.*; /** Bean with constrained properties. */ public class constrained_Listner extends Canvas { public constrained_Listner() setSize(200,200); setVisible(true); } public void paint( Graphics g ) g.drawString(“Target",30,40); UNIT-4 WT

74 public void vetoableChange(PropertyChangeEvent pce) throws PropertyVetoException { throw new PropertyVetoException(“property is vetoed”); } public static void main(String args[]) new constrained_Listner(); UNIT-4 WT

75 LECTURE-6 UNIT-4 WT

76 Using the BeanInfo Interface
BeanInfo interface explicitly control design patterns used to determine the information that was provided to a Bean. This interface defines several methods, including these: PropertyDescriptor[ ] getPropertyDescriptors( ) EventSetDescriptor[ ] getEventSetDescriptors( ) MethodDescriptor[ ] getMethodDescriptors( ) They return arrays of objects that provide information about the properties, events, and methods of a Bean. By implementing these methods, a developer can designate exactly what is presented to a user. UNIT-4 WT

77 SimpleBeanInfo is a class that provides default implementations of the BeanInfo interface, including the three methods just shown. You may extend this class and override one or more of them. ColorsBeanInfo is a subclass of SimpleBeanInfo. It overrides getPropertyDescriptors( ) in order to designate which properties are presented to a Bean user. This method creates a PropertyDescriptor object for the rectangular property. The PropertyDescriptor constructor that is used is shown here: PropertyDescriptor(String property, Class beanCls) throws IntrospectionException UNIT-4 WT

78 Selective Serialization: writeObject and readObject
If your serializable class contains either of the following two methods (the signatures must be exact), then the default serialization will not take place. private void writeObject(java.io.ObjectOutputStream out) throws IOException; private void readObject(java.io.ObjectInputStream in) throws IOException, ClassNotFoundException; UNIT-4 WT

79 You can control how more complex objects are serialized, by writing your own implementations of the writeObject and readObject methods. Implement writeObject when you need to exercise greater control over what gets serialized when you need to serialize objects that default serialization cannot handle, or when you need to add data to the serialization stream that is not an object data member. Implement readObject to reconstruct the data stream you wrote with writeObject UNIT-4 WT

80 The Externalizable Interface
Use the Externalizable interface when you need complete control over your bean's serialization (for example, when writing and reading a specific file format). To use the Externalizable interface you need to implement two methods: readExternal and writeExternal. Classes that implement Externalizable must have a no-argument constructor. UNIT-4 WT

81 LECTURE-7 UNIT-4 WT

82 Customizers The Properties window of the BDK allows a developer to modify the properties of a Bean. However, this may not be the best user interface for a complex component with many interrelated properties. Therefore, a Bean developer can provide a customizer that helps another developer configure this software. A customizer can provide a step-by-step guidethrough the process that must be followed to use the component in a specific context. A Bean developer has great flexibility to develop a customizer that can differentiate his or her product in the marketplace UNIT-4 WT

83 The Java Beans API The Java Beans functionality is provided by a set of classes and interfaces in the java.beans package. UNIT-4 WT

84 The Interfaces Defined in java.beans
AppletInitializer: Methods in this interface are used to initialize Beans that are also applets. BeanInfo: This interface allows a designer to specify information about the properties, events, and methods of a Bean. Customizer: This interface allows a designer to provide a graphical user interface through which a Bean may be configured. DesignMode: Methods in this interface determine if a Bean is executing in design mode. UNIT-4 WT

85 PropertyChangeListener: A method in this interface is invoked when a bound property i s changed.
PropertyEditor: Objects that implement this interface allow designers to change and display property values. VetoableChangeListener: A method in this interface is invoked when a constrained property is changed. Visibility: Methods in this interface allow a Bean to execute in environments where a graphical user interface is not available. UNIT-4 WT

86 The Classes Defined in java.beans
BeanDescriptor: This class provides information about a Bean. It also allows you to associate a customizer with a Bean. Beans: This class is used to obtain information about a Bean. EventSetDescriptor: Instances of this class describe an event that can begenerated by a Bean. FeatureDescriptor: This is the superclass of the PropertyDescriptor,EventSetDescriptor, and MethodDescriptor classes. IndexedPropertyDescriptor: Instances of this class describe an indexed property of aBean. UNIT-4 WT

87 MethodDescriptor: Instances of this class describe a method of a Bean.
IntrospectionException: An exception of this type is generated if a problem occurs when analyzing a Bean. Introspector: This class analyzes a Bean and constructs a BeanInfo object that describes the component. MethodDescriptor: Instances of this class describe a method of a Bean. ParameterDescriptor: Instances of this class describe a method parameter. PropertyChangeEvent:This event is generated when bound or constrained properties are changed. It is sent to objects that registered an interest in these events and implement either the PropertyChangeListener or VetoableChangeListener interfaces. UNIT-4 WT

88 PropertyChangeSupport: Beans that support bound properties can use this class to notify PropertyChangeListener objects. PropertyDescriptor: Instances of this class describe a property of a Bean. PropertyEditorManager: This class locates a PropertyEditor object for a given type. PropertyEditorSupport:This class provides functionality that can be used when writing property editors. PropertyVetoException: An exception of this type is generated if a change to a constrained property is vetoed. SimpleBeanInfo: This class provides functionality that can be used when writing BeanInfo classes. VetoableChangeSupport: Beans that support constrained properties can use this class to notify VetoableChangeListener objects. UNIT-4 WT

89 LECTURE-8 UNIT-4 WT

90 INTRODUCTION TO EJB Enterprise Java Bean architecture is the component architecture for the development and deployment of robust, world class component-based distributed application using the java language. Enterprise JavaBeans (EJB) is a comprehensive technology that provides the infrastructure for building enterprise-level server-side distributed Java components. The EJB technology provides a distributed component architecture that integrates several enterprise-level requirements such as distribution, transactions, security, messaging, persistence, and connectivity to mainframes and Enterprise Resource Planning (ERP) systems. UNIT-4 WT

91 Compared with other distributed component technologies such as Java RMI and CORBA, the EJB architecture hides most the underlying system-level semantics that are typical of distributed component applications, such as instance management, object pooling, multiple threading, and connection pooling. Secondly, unlike other component models, EJB technology provides us with different types of components for business logic, persistence, and enterprise messages. Thus, an Enterprise Java Bean is a remote object with semantics specified for creation, invocation and deletion. The EJB container is assigned the system-level tasks mentioned above. What a web container does for Java servlets and JSPs in a web server, the EJB container is for EJBs. UNIT-4 WT

92 EJB Architecture EJB architecture specifies three types of beans - session beans, entity beans, and message-driven beans. A bean developer has to specify the home and remote interfaces and also he has to implement one of these bean interfaces depending upon the type of the bean. For instance, for session beans, he has to implement the javax.ejb.SessionBean interface. The EJB architecture expects him to implement the methods specified in the bean interface and the methods specified in the home and remote interfaces. During the deployment time, he should specify the home and remote interfaces and bean implementation class to define a bean. The EJB container relies on specific method names and uses delegation for invoking methods on bean instances. UNIT-4 WT

93 Types of EJBs Session Beans 􀂄 Stateful session Beans
􀂄 Stateless session Beans Entity Beans 􀂄 Container-managed persistence (CMP) 􀂄 Bean-managed persistence (BMP) Message-Driven UNIT-4 WT

94 Session Beans Encapsulates typical business processes
May contain a conversational state associated with a particular client Unlike entity beans, states are not stored in a permanent data source and will not survive a server failure Session beans implement business logic, business rules, and workflow. UNIT-4 WT

95 Stateful Session Beans
Maintains client-specific session information (called conversational state) across multiple method calls and transactions Aware of client history Each stateful session bean has a timeout value The bean instance is destroyed and the remote reference is invalidated after the timeout period is elapsed. UNIT-4 WT

96 Stateless Session Beans
Does not maintain any conversational state. Stateless session beans are pooled by their container to handle multiple requests from multiple clients. Entity Beans Represent permanent data Provide methods to manipulate data Usually, permanent data is stored in a data source, such as a relational or object database Each bean is identified by a primary key UNIT-4 WT

97 Container Managed persistence (CMP)
Delegate their persistence to their EJB container Do not have to know which source is used to provide the persistent state of the bean. You just have to specify which fields are persistent. All the required JDBC code for accessing the database is generated for you. Therefore, there is absolute portability and the EJB developer can focus on the business logic. UNIT-4 WT

98 Bean-managed persistence(BMP)
Entity beans manage their own persistence The EJB developer manages the persistent state of the bean by coding database calls Usually, the developer uses JDBC for coding the persistence logic UNIT-4 WT

99 Comparing CMP and BMP A BMP entity bean is inappropriate for large applications. CMP is more scalable BMPs may provide better portability than CMPs, because less container generated code is used. UNIT-4 WT

100 Understanding and Designing with EJB
UNIT-4 WT

101 When to use EJB For large scale applications: where resources and data are distributed. When the application is run on servers at many locations. Where scalability is critical. Where transactions are required to ensure data integrity When a variety of clients need to handled. UNIT-4 WT

102 Types of Enterprise Bean: Session
Session bean: represents a single client inside the J2EE server. Session represents an interactive session. When a client terminates the session bean terminates/is no longer associated with the client. Stateful session bean: maintains a conversational state for the duration of a session. Ex: items reviewed in a session at some sites Stateless session bean: does not maintain a conversational state. Ex: computing a formula for a given value UNIT-4 WT

103 Types of Enterprise Bean: Entity
An entity bean represents a business object in a persistent storage mechanism. Ex: customers, orders, and products. Each entity bean typically has an underlying table in a relational database (business data), and each instance of the bean corresponds to a row in that table. Transactional and recoverable on a server crash. UNIT-4 WT

104 Types of Enterprise Bean: Message-Driven
A message driven bean is an enterprise bean that allows J2EE applications to process messages asynchronously. It acts as a JMS listener, which is similar to an event listener except that it receives messages instead of events. The messages can be sent by any J2EE component: an application client, another enterprise bean, or a web component, or a non-J2EE system using JMS. Retain no data or conversational state. UNIT-4 WT

105 Contents of an Enterprise Bean
Interfaces: The remote and home interface for remote access. Local and local home accesses for local access. Enterprise bean class: Implements the methods defined in the above interfaces. Deployment descriptor: An XML file that specifies information about the bean such as its type, transaction attributes, etc. Helper classes: non-bean classes needed by the enterprise bean class such as utility and exception classes. UNIT-4 WT

106 The life cycles of enterprise beans
An enterprise bean goes through various stages during its lifetime. Each type has different life cycle. UNIT-4 WT

107 Session bean Does not Exist Ready create remove Does not Exist create
passivate Ready Passive activate UNIT-4 WT

108 Entity and Message-driven Bean Lifecycle
Does not Exist Does not Exist Ready create remove setContext unsetContext Pooled onMessage ejbPassivate ejbActivate create remove Ready UNIT-4 WT

109 Entity Bean Data is at the heart of most business applications.
In J2EE applications, entity beans represent the business objects that need persistence (need to be stored in a database.) You have choice of bean-managed persistence (BMP) and container-managed persistence (CMP). In BMP you write the code for database access calls. This may be additional responsibility but it gives control to the bean developer. UNIT-4 WT

110 Entity Bean class Implements EntityBean interface
Zero or more ejbCreate and ejbPostCreate methods Finder methods Business methods Home methods UNIT-4 WT

111 Entity Bean Methods ejbCreate inserts the entity state into the database; initializes the instance variables and returns the primary key. ejbRemove will delete the record corresponding to the bean from the database. ejbLoad and ejbStore methods synchronize instance variables of an entity bean with the corresponding values stored in a database. ejbLoad refreshes the instance variables from the db and ejbStore writes variables to the database. Container does this not the client. ejbFinder allows client to locate entity beans. Find the collection of records with “Smith” as author. Business methods and home methods. UNIT-4 WT

112 SQL statements in Entity Bean
Method SQL Statement ejbCreate INSERT ejbFindPrimaryKey SELECT ejbFindByLastName ejbFindInRange ejbLoad ejbRemove DELETE ejbStore UPDATE UNIT-4 WT


Download ppt "WEB TECHNOLOGIES – Unit IV"

Similar presentations


Ads by Google