Sunday, 22 May 2016

JavaBeans in Hybris..

JavaBeans: 

 JavaBean  is a Java class that:
1.     Implements the Serializable interface
2.     Has a no-argument constructor
3.     JavaBean properties must have public setter and getter methods
 Java Bean makes it easy to reuse software components.

Example of JavaBean:

public class JavaBeanDemo  implements java.io.Serializable
{
          private int num;
          private String Fname;
                  
          public JavaBeanDemo()
          {
                   // default constructor
          }
          public void setNum(final int num)
          {
                   this.num = num;
          }              
          public int getNum()
          {
                   return num;
          }
          public void setFname(final String Fname)
          {
                   this.Fname = Fname;
          }
          public String getFname()
          {
                   return Fname;
          }   
}

 JavaBean in Hybris:

  • In hybris javabeans are automatically generated.
  • Each extension may provide a bean configuration file in this file class name, attributes or superclass are defined. 
  • Java Beans or Enums definitions are melded across extensions.
  • Java beans Contain an abstraction of models.  

Example for custom java bean Generating:

Configure the bean in extension-beans.xml
    <bean class="com.hybrisdemo.data.JavaBeanDemo">
             <property name="num" type="int"/>
               <property name="Fname" type="String"/>
        </bean>
The following JavaBean is Generated under platform/bootstrap/gensrc folder based on above configuration. it generated  when ever we call “ant all” ( or)  “ant clean all” target.
 public class JavaBeanDemo  implements java.io.Serializable
{
          private int num;
          private String Fname;
                  
          public JavaBeanDemo()
          {
                   // default constructor
          }
       //Setters and getters methods..
}
  • Java beans are useful as DataObjects used by Frontend layer.
  • Merge attributes into existing beans.

For example:- extenstion1 and extenstion2 have same bean class with different attributes that attributes merge into one javabean class Generated under platform/bootstrap/gensrc.

 extension1-beans.xml:- 

        <bean class="com.hybrisdemo.data.JavaBeanDemo">
             <property name="num" type="int"/>
                  <property name="Fname" type="String"/>
        </bean>

 extension2-beans.xml:-

        <bean class="com.hybrisdemo.data.JavaBeanDemo">
             <property name="num" type="int"/>
                  <property name="Fname" type="String"/>
                  <property name=”Lname” type=”String”/>
        </bean>

Generated JavaBean Class:- 

public class JavaBeanDemo  implements java.io.Serializable
{
       private int num;
       private String Fname;
       private String Lname;
             
       public JavaBeanDemo()
       {
              // default constructor
       }
       public void setNum(final int num)
       {
              this.num = num;
       }           
       public int getNum()
       {
              return num;
       }      
       public void setFname(final String Fname)
       {
              this.Fname = Fname;
       }      
       public String getFname()
       {
              return Fname;
       }              
       public void setLname(final String Lname)
       {
              this.Lname = Lname;
       }       
       public String getLname()
       {
              return Lname;
       }
}




1 comment:

  1. Very Good Blog if someone need any help in technological things please visit our blog page

    ReplyDelete