Tuesday, 25 January 2011

public enum POSEntryMode {

 SWIPE("01"),
 SWIPE_WO_PIN("01"),
 EMV_WO_PIN("05"),
 EMV_ONLINE_PIN("05"),
 EMV_OFFLINE_PIN("05"),
 MANUAL("02"),
 TOUCH("06"),
 FALLBACK("04"),
 CARD_NOT_PRESENT("03"),
 UNKNOWN("00"); 
 
 private String name;
 
 private POSEntryMode(String name){
  this.name = name;
 }
 
 public String getValue(){
  return this.name;
 }
 
 public static POSEntryMode parse(String POSEntryMode) throws OneICommonException{
  if(POSEntryMode == null || "".equalsIgnoreCase(POSEntryMode)){
   throw new OneICommonException(ErrorCodeConstant.INVALID_REQUEST_ERROR,
            CommonExceptionConstant.INVALID_POS_ENTRY_MODE_ERR_MSG,
            new IllegalArgumentException("POS ENTRY MODE IS BLANK OR NULL"));
  }
  /*
   * Matching starts here
   */
  if(POSEntryMode.equalsIgnoreCase("SWIPE") || POSEntryMode.equalsIgnoreCase("S") || POSEntryMode.equalsIgnoreCase("01")){
   return SWIPE;   
  }else if(POSEntryMode.equalsIgnoreCase("EMV") || POSEntryMode.equalsIgnoreCase("ICC")
      || POSEntryMode.equalsIgnoreCase("DIP") || POSEntryMode.equalsIgnoreCase("CHIP")
       || POSEntryMode.equalsIgnoreCase("PIN") || POSEntryMode.equalsIgnoreCase("D") || POSEntryMode.equalsIgnoreCase("05")){
   return EMV_ONLINE_PIN;   
  }else if(POSEntryMode.equalsIgnoreCase("MANUAL") || POSEntryMode.equalsIgnoreCase("KEYED")
     || POSEntryMode.equalsIgnoreCase("M") || POSEntryMode.equalsIgnoreCase("02")){
   return MANUAL;   
  }else if(POSEntryMode.equalsIgnoreCase("TOUCH") || POSEntryMode.equalsIgnoreCase("CONTANTLESS")
     || POSEntryMode.equalsIgnoreCase("T")|| POSEntryMode.equalsIgnoreCase("06")){
   return TOUCH;   
  }else if(POSEntryMode.equalsIgnoreCase("FALLBACK") || POSEntryMode.equalsIgnoreCase("04")){
   return FALLBACK;   
  }else if(POSEntryMode.equalsIgnoreCase("03") ){
   return CARD_NOT_PRESENT;   
  }else{
   throw new OneICommonException(ErrorCodeConstant.INVALID_REQUEST_ERROR,
       CommonExceptionConstant.INVALID_POS_ENTRY_MODE_ERR_MSG,
       new IllegalArgumentException("POS ENTRY MODE IS NOT RECOGNIZED ["+ POSEntryMode+"]"));
  }
 }
 
}

Monday, 7 December 2009

Day - 2 : Part 1 - Spring container

From Day 1, we know that -
SPRING = Plain JAVA( CORE JAVA) + DI + AOP

How does a POJO achieve the complex functionality of EJB ?

We have a Spring container - That helps to create a Bean, give it DI and AOP.
Spring container is the GOD of BEANS(POJO)- It maintains the life of BEAN

TWO type of Container:
1) BEAN FACTORY
2) APPLICATION CONTEXT

BEAN FACTORY: See the below image:



1)We need a file resource to read the XML file that contain all Bean definitions.
2) BeanFactory will not create an object of Beans until we call getBean method on BeanFactory object.
3) BeanFactory used Factory framework to create and dispense Beans.



Application context is the most commonly used Spring container. It can read the XML file, which contain bean definitions, from File system, class path, or Web application.

What is Spring and why spring?

Spring is a FRAMEWORK, which facilitates the java development in more flexible and configurable manner.

Why Spring?

In my opinion Spring was developed to reduce the overhead of irritating syntax and rules of EJB. EJB are not only irritating but also SLOW.

So Spring gave you all the functionality of EJB with POJO( plain old java object).
Spring use two things to achieve this : DI and AOP

DI:- Dependency Injection:- What is this?
In most simplest form, suppose you have one Java code in which you need a string called str. you will write following code:

String str = new String();

Basically, here the java file or java bean is taking pain to create a String object.
similarly If we need another Bean object for eg:

MyBean myBean = new MyBean();

Again java Bean is taking pain to create an object.

DI reduce this pain. Whatever we need in a JAVA file is given to it, So in the same java file we will automatically get a myBean object, we dont need to create it.

so the Object on which our java file or bean depend are given to it by Spring container.
OR
the dependency of a JAVA bean is given to it by Spring.
This is called as DEPENDENCY INJECTION.

AOP: Aspect oriented programming:
AOP is basically separation of concern. In simple terms, enhancing the modularity.
For ex- In an office, we try to assign different things to different ppl. Everyone do his/her own work but communicate with each other also.
similarly in a software, AOP helps to assign one work on one component. Separation of work in different component of Software.

That's all..about Spring Basics.