Monday, 22 September 2014

Installing and Runnig Application Server For EJB(For Windows)

There are many free application servers like Sun’s J2EE Reference Application Server, which is available free at http://www.javasoft.com or JBoss, which may be downloaded JBoss from JBoss website: www.jboss.org download the application server from their web site. Once you have download it, unzip the JBoss zip file into some directory e.g. C:/JBoss. The directory structure should be something like the following:

c:\jboss
        admin
        bin
        client
        conf
        db
        deploy
        lib
        log
        tmp

Now, to start JBoss with default configuration go to JBoss/bin directory and run the following command at the DOS prompt:


C:\JBoss\bin > run

Run the .bat file which starts the JBoss server. Once JBoss server starts, you should see huge lines of text appearing on your cmd screen. These lines show that JBoss server is starting. Once JBoss startup is complete you should see a message like following one on your screen:


[Default] JBoss 2.4.3 Started in 0m:11s

Now, we have successfully installed and run JBoss on your system. To stop JBoss, simply press Ctrl + C on the cmd and JBoss will stop, after displaying huge lines of text.
The client for our EJB will be a JSP page/ Servlet running in a separate Tomcat server, we have already learnt in an earlier, how to create and install tomcat server for running JSP or servlet.

Configure and Running Tomcat:

Create a new folder under the main C:\ drive and name it “projects”.  now, create a new sub-folder in the C:\projects folder and name it “tomcatjboss”. The directory strcture look like the following:

C:\projects
        tomcatjboss

Now, open conf/server.xml file from within tomcat directory where you have installed it. By default this location will be:

C:\tomcat\conf\server.xml

Somewhere in the middle where you can see multiple <context> tags, add following lines between other <context> tag.

<!-- Tomcat JBoss Context -->
<context path="/jboss" docBase="C\projects\tomcatjboss\" debug="0" reloadable="true"/>

Now, Save server.xml file. Go to Start -> All Programs -> Tomcat -> Start Tomcat, to start tomcat server. If everything has been setup correctly, Tomcat will start without any problem:




Sunday, 21 September 2014

Bean Properties

Bean Properties can be categorized as follows....
  • Simple Property:  Simple properties are basic, independent, individual properties like width, height, and color.
  • Indexed Property: It is a property that can take on an array of values.
  • Bound Property:  It is a property that alerts other objects when its value changes.
  • Constrained Property: It differs from bound property in that it notifies other objects of an impending change. Constrained properties give the notified objects the power to veto a property change.

Accessor Methods

·                                Simple Property:
o   If, a bean has a property named foo of type fooType that can be read and written, it should have the following accessor methods:
Public fooType getFoo()
{
                        Return foo;
}
Public void setFoo(fooType fooValue)
{
            Foo=fooValue; …..
}

If a property is boolean, getter methods are written using is instead of get eg. isFoo().

·                                Indexed Property:
o   Public widgetType getWidget(int index)
o   Public widgetType[] getWidget()
o   Public void setWidget(int index, widgetType widgetValue)
o   Public void setWidget(widgetType[] widgetValues)

·                                  Bound Property:

Getter and setter methods for bound property are as described above based on whether it is simple or indexed. Bounded properties require certain objects to be notified when they change. The change notification is accomplished through the generation of a PropertyChangeEvent(defined in java.beans). objects that want to be notified of a property change to a bound property must register as listeners. Accordingly, the bean that’s implementing the bound property supplies methods of the form:
Public void addPropertyChangeListener(propertyChangeListener l)
Public void removePropertyChangeListener(propertyChangeListener l)

The preceding listener registration methods do not identify specific bound properties. To register listeners for the PropertyChangeEvent of a specific property, the following methods must be provided:

public void addPropertyNameListener(PropertyChangeListener l)
public void removePropertyNameListener(PropertyChangeListener l)

In the preceding methods, PropertyName is replaced by the name of the bound property.
Objects that implement the PropertyChangeListener interface must implement the PropertyChange() method. This method is invoked by the bean for all registered listeners to inform them of a property change.

Constrained Property:

The previously discussed methods used with simple and indexed properties also apply to the constrained properties. In addition, the following event registration methods provided: 

public void addVetoableChangeListener(VetoableChangeListener l)
public void removeVetoableChangeListener(VetoableChangeListener l)
public void addPropertyNameListener(VetoableChangeListener l)
public void removePropertyNameListener(VetoableChangeListener l)

Objects that implement the VetoableChangeListener interface must implement the vetoableChange(). This method is invoked by the bean for all of its registered listener to inform them of a property change. Any object that does not approve of a property change can throw a PropertyVetoException within its vetoableChange() to inform the bean whose constrained property was changed that the change was not approved.