Wednesday, October 24, 2012

G-Old Days

 

 










 Today I was looking for decent GAZHAL I found link which was pointing to one of my favorites Gazhal. Suddenly it took me 12 yrs back when I was in Mumbai staying with friends in Vasai Tribhuvan Apartments. Those were old golden days ,we had a broken cassette player and everyday while sleeping we used to put this GAZHAL cassette and sleep. Best part is it used to run whole night and morning who ever wakes first used to switch of that player.Those are the most beautiful days and phase of life.I still remember those sleepless nights , those sleeping on news paper , sharing of lunch box , sleepless nights and whole day hunting for job.In spite of all these problems I miss those days.Few line from that beautiful GAHZAL which touch my heart even today specially bold lines.

    

    haath chooTen bhi tho rishthe nahin choDa karthe
    waqt ki shaak se lamhein nahin toDa karthe

    jiski aawaaz meiN silwat ho nigahoN meiN shikan
    aisi tasvir ke tukDe nahiN joda karthe

    shahad jeene ka mila karta hai thoDa thoDa
    jaane waaloN ke liye dil nahin thoDa karthe

    lagke saahil se jo beHta hai use beHne do
    aisi dariya ka kabhi rukh nahiN moDa karthe


:) Hemant

Thursday, February 11, 2010

R U A HAPPY PERSON? ........

Are you caught up in the ‘SHOULD BE’ trap? I was. I always felt that things SHOULD happen the way I expected.

My clients SHOULD be reasonable.

My family SHOULD be more understanding.

My boss SHOULD be more sensitive.

My colleagues SHOULD be less jealous.

The traffic SHOULD follow lane discipline.

The neighbor’s dog SHOULD bark less at night.
The government SHOULD be more effective.

The weather SHOULD be ..



Tell you what.. The government owes you nothing. Your family owes you nothing. People NEED NOT change their behavior to suit you. You need to tell yourself. “It’ll be great if things happen the way I want them to, but if they don’t, DOESN’T MATTER! My happiness is not dependant on some nutty driver changing his driving habits. My happiness is a CHOICE, not a RESULT of someone else’s action.”



When you get too attached to how the world SHOULD function, you lose focus of your own self. And worse still, the more you expect of the world around you, the more it seems to get out of alignment with your expectations! At one level, there’s nothing wrong with expectation. It’s okay to be NOT SATISFIED with something. That is in fact what propels us into improvement in ourselves and the world around us. But there is surely a distinction between SATISFACTION and HAPPINESS. You can be NOT SATISFIED and yet be HAPPY. Both are choices you make. And they CAN coexist.



So next time you don’t like the food (or service) at a restaurant, tell yourself. “I’m not satisfied, but I don’t’ need this to be happy. I have DECIDED to be happy anyway.” You’ll realize that when you relax the boundaries of your expectations, the world becomes a lot easier to sort out. Your stress levels drop dramatically. And SURPRISE, SURPRISE, you might just find that the restaurant food has become tastier, the traffic’s not a nightmare anymore, your family doesn’t crib about your late working and your BOSS just sent you on a paid holiday!


Wednesday, January 27, 2010

Friendship



Ever wondered how many friends we make in life?how many do we retain till life? well, well, that’s a difficult question to answer. but the most beautiful gift God has given to mankind is Friendship! the power to make friendship itself is so very good. i think God found a way out for us never to get lonely in life. i’m sure while people read by blog..they’d be guessing that the most beautiful gift is “FRIEND”…well, friend is a great gift..but how about the thought that the power to make friends is better?i make friends a lot…not all of them walk with me together in life…but still they are remembered and treasured. and on this new year’s eve i want to remember and thank all my friends for being my friends. this is the time to cheer our golden days, the times spent together and the times we missed each other.this is the occasion to pray for all the people who like me have been unable to stay in touch with the people they really wanted to be with.Long Live Friendship!

Wednesday, January 21, 2009

Portlet an advanced web component

What is Portlet?
Portlets are pluggable user interface software components that are managed and displayed in a web portal. Portlets produce fragments of markup code that are aggregated into a portal page.
Portlets are web components--like servlets--specifically designed to be aggregated in the context of a composite page. Usually, many portlets are invoked to in the single request of a portal page. Each portlet produces a fragment of markup that is combined with the markup of other portlets, all within the portal page markup.

What are the elements of a Portal Page ?
Every portlet page is made up of one or more than one portlet windows. Every portlet window is made up of two parts: one is the decoration, which will decide how the title bar, controls, and borders of portlet windows will appear. The second part is the portlet fragment, which is the part contributed by the portlet application.
Your portal server decides the overall look and feel of the portal page, such as the logo, the colors of the title bars, the images for the controls, etc. By changing a few standard JSPs and .css files, you can change the complete look and feel of your portal.

What Is a Portal?
In order to understand what a portlet is, it is very necessary to understand what a portal is. According to the Portlet Specification, "a portal is a web application that commonly provides personalization, single sign on, content aggregation from different sources, and hosts the presentation layer of information systems. Aggregation is the act of integrating content from different sources within a web page."
Portal functionality can be divided into three main parts:
Portlet container: A portlet container is very similar to a servlet container, in that every portlet is deployed inside a portlet container that controls the life cycle of the portlet and provides it with necessary resources and information about its environment. A portlet container is responsible for initializing and destroying portlets and also for passing user requests to it and collecting responses. Content aggregator: As defined in the Portlet Specification, one of the main jobs of a portal is to aggregate content generated by various portlet applications. We will talk more about this in the "How a Portal Page is Created" section. Common services: One of the main strengths of a portal server is the set of common services that it provides. Services are not part of the portlet specification, but commercial portal implementations provide a rich set of common services to distinguish themselves from their competitors. A few common services that you can hope to find in most implementations are: Single sign on: Allows you to get access to all other applications once you log into the portal server, meaning you don't have to log into every application separately. For example, once I log in to my intranet site, I should get access to my mail application, IM messaging application, and other intranet applications, without having to log into each of these applications separately.
A portal server will provide you with a secured credentials store. What you do is to go to the mail application and specify your user name and password once. This information will be stored in the credentials store in encrypted form. From the next time onwards, when you log into your intranet site, the portal server will read your credentials from the store and log into your mail server on your behalf. The same goes for other applications.
Personalization: The basic implementation of personalization service allows a user to customize her page in two ways. First, the user can decide what colors she wants for title bars and what icons she wants for controls. Second, the user can decide which portlets she wants on her page. For example, if I'm a big sports fan, I will probably replace the stock and news update portlets with a portlet that lets me track my favorite team.
There are also a few advanced commercial implementations of personalization services that allow you to decide which applications should be displayed to user based on criteria such as his income or interests. In this case, you can create some business rules like "Show the premium products portlet to any user with X amount of income" and "Show the discount deals portlet to users with Y amount of income."
There are a few more common services such as machine translation, in which case the portal server will take content generated by portlet in one language and machine translate it into a language requested by user. Most of the commercial portal servers provide access via handheld devices and are capable of generating different content for different browsers.

What Are Portlets?
Similar to servlets, portlets are web components that are deployed inside of a container and generate dynamic content. On the technical side, a portlet is a class that implements the javax.portlet.Portlet interface and is packaged and deployed as a .war file inside of a portlet container.
Portlets are similar to servlets, in that:
Portlets are managed by a specialized container. Portlets generate dynamic content. A portlet's life cycle is managed by the container. Portlets interact with web client via a request/response paradigm. Portlets are different from servlets, in that:
Portlets only generate markup fragments, not complete documents. Portlets are not directly URL addressable. You cant send somebody URL of a portlet. You can send him the URL of the page containing a portlet. Portlets cannot generate arbitrary content, since the content generated by a portlet is going to be part of portal page. If a portal server is asking for html/text, then all portlets should generate text/html content. On the other hand, if the portal server is asking for WML, then each portlet should generate WML content.
ortlets do provide some additional functionality.

Persistent storage for preferences: Portlets provide a PortletPreferences object for storing user preferences. These preferences are stored in a persistent data store, so they will be available across server restarts. As a developer, you don't have to worry about the actual implementation of how it is stored.
Request processing: Portlets provide much more refined request handling. A portlet may get a request when user takes some action on it (a state called action phase), or because the user took action on some other portlet and the page needs to be refreshed. A portal server provides different callback methods for handling both situations.
Portlet modes: Portlets use a concept of mode to indicate what user is doing. When using a mail application, you may be using it for reading, composing, or checking mail messages--this is the expected functionality of a mail application. Portlets normally provide this in VIEW mode. But there are other activities, like specifying a refresh time or (re-)setting the username and password. These activities allow the user to configure the behavior of the application, so they come under EDIT mode. Help functionality of the mail application comes under HELP mode.
If you think about it, you will find none of these represents new functionality. Instead, most of these are common business requirements. The only thing the portlet specification is doing is providing you one layer of abstraction, so that it will be useful for all stake holders end users, developers and administrators.
As a developer, I put all my business logic related to VIEW mode in a method called doView(), and I put business logic related to the configuration of my application in a doEdit() method, with help-related logic in a doHelp() method.
This makes it simple for an administrator to control access in the portlet application, because all he has to do is change access rights of the portlet to dictate what things a user is allowed to do. For example, a user of a mail application is supposed to specify his username and password in EDIT mode, so it makes sense for him to have access to EDIT mode.
But consider the case where I am the administrator of an intranet site and my company bought a third-party portlet application that displays news updates. This application allows a user to specify the URL from where it can retrieve updates. I want to use this application for displaying internal company news to users. Another requirement is that I don't want users to use this application for tracking any other news source. So as the administrator, I can specify the URL of an internal news update site for all users, and take out their edit privileges by changing the deployment descriptor of this portlet application.
Using portlets makes my website much more appealing to the end user because she will get a similar UI for all her portlet applications. If she wants to read help information about any of the applications, she can click the help button. She will also know that clicking on an edit button will take her to a configure screen for that application. Standardizing the user interface will make your portlet application more appealing.
Window state: The window state determines how much space should be given to content generated by a portlet on a portal page. If you click on the maximize button, the portlet will take up the entire screen and it will become the only portlet that will be available to the user. In minimized state, the portlet will be displayed as only a title bar. As a developer, you should customize your content based on the space available to you.
User information: Commonly, portlets provide content personalized to the user making the request. To do this effectively, they may require access to user attributes such as name, email, phone, etc. The Portlet API provides the concept of user attributes for this. A developer can access these attributes in a standard way, and it is the responsibility of the administrator to map these attributes to an actual user information repository (usually an LDAP server).

Tuesday, November 07, 2006

Decorator Design Pattern

Benefits of Decorator Design Pattern:

1. Make a responsibility easily added and removed dynamically.
2. More flexibility than static inheritance.
3. Provide an alternative to sub classing.
4. Add new function to an object without affecting other objects.
5. Transparent to the object.

What is Decorator Pattern :

Attach additional responsibilities or functions to an object dynamically or statically. Also known as Wrapper. Suppose we have some 10 objects and 2 of them need a special behavior, we can do this with the help of a decorator. The decorator pattern can be use wherever there is a need to add some functionality to the object or group of objects.
Java Design Patterns suggest that Decorators should be abstract classes and the concrete implementation should be derived from them.

Example of Decorator Pattern:

Christmas tree branches need to be decorated with the different types of branches.

package test.structural.decorator;

public abstract class Decorator {

// This method is used to decorate the branch of the Christmas tree
public abstract void place(Branch branch);

} // End of class

Above class has method place which places different types of items on the branches of the tree.

package test.structural.decorator;

public class ChristmasTree {

private Branch branch;

//returns the branch
public Branch getBranch() {
return branch;

}

} // End of class

You decorate the branches in three different ways; one is by putting different color balls on them, by putting different color squares on them and also by putting stars on them.


Implementation of one of the above three decorator will as below

package test.structural.decorator;

// Decorates the branch of the tree with different color balls.

public class BallDecorator extends Decorator {

public BallDecorator(ChristmasTree tree) {
Branch branch = tree.getBranch();place(branch);
}
//The method places each decorative item on the tree.
public void place(Branch branch) {
branch.put("ball");
}

}// End of class

Same way you can write the SquareDecorator and StarDecorator.

Instantiation of the BallDecorator will be like

BallDecorator decorator = new BallDecorator(new ChristmasTree());

Ball decorator will be instantiated and a branch of the Christmas tree will be decorated with different color balls.

This pattern provides functionality to objects in a more flexible way rather than inheriting from them. Disadvantage of the decorator pattern will be maintenance of the code as lots of similar looking small object for each decorator.

Monday, November 06, 2006

Bridge Design Pattern

Benefits of Bridge Design Pattern:

1. Share the implementation among the multiple objects
2. Wants to improve extensibility.
3. Wants to share the abstraction and implementation permamantly.
4. Hide the implementation details from client.

What is Bridge Design Pattern :
Bridge pattern decouples the interface from its implementation. Doing this gives the flexibility so that both can vary independently.

Example of Bridge Design Pattern :

The switch is the interface and the actual implementation is the starting of the Television once it’s switched-on. Still, both the switch and the Refrigerator are independent of each other. Another switch can be plugged in for the Refrigerator and this switch can be connected to start Television

package structural.bridge.test;

public interface Switch {

public void switchOn(); //to switch on
public void switchOff(); //to switch off


}

This switch can be implemented by various devices in house, as Television, Refrigerator etc. Here is the sample code for that.

Package structural.bridge.test;

public class Television implements Switch { // implements switch interface

// On position of switch.
public void switchOn() {
System.out.println("Television Switched ON");
}

// Off position of switch.
public void switchOff() {
System.out.println("Television Switched OFF");

}
}


Package structural.bridge.test;

public class Refrigerator implements Switch { // implements switch interface

// On position of switch.
public void switchOn() {
System.out.println("Refrigerator Switched ON");
}

// Off position of switch.
public void switchOff() {
System.out.println("Refrigerator Switched OFF");
}

}

The interface Switch can be implemented in different ways. Switch as an interface as it has only two functions, on and off. But, there may arise a case where some other function be added to it, like change () (change the switch).You need to make the decision earlier to implementation whether the interface should be interface or abstract class.

Friday, November 03, 2006

Transfer Object Design Pattern

Benefits of Transfer Object Pattern
1. Fetch multiple values in one trip.
2.Decrease network traffic.
3.Get related values from remote business method.
4. Minimize latency and server resource usage.

What is Transfer Object Pattern?
A transfer object is a serializable class that groups related attributes, forming a composite value. This class is used as the return type of a remote business method. Clients receive instances of this class by calling coarse-grained business methods, and then locally access the fine-grained values within the transfer object. Fetching multiple values in one server roundtrip decreases network traffic and minimizes latency and server resource usage.

Example of Transfer Object
The EmployeeDetails and EmployeeTO transfer objects.
Sample application class EmployeeAdminFacade has a method getEmployeeInfo that returns an immutable, serializable collection of EmployeeDetails objects, each of which is a transfer object that represents data from an employee. The collection returned by method getEmployeeInfo is also a transfer object, because the values it contains are always accessed together where they are used. This hierarchical transfer object is implemented by class EmployeeTO.




Above Figure shows the structure of the EmployeeTO transfer object. Class mutableEmployeeTO, which extends a serializable ArrayList, contains a collection of EmployeeDetails objects. But because MutableEmployeeTO extends ArrayList, it is mutable. Transfer objects should be immutable so that clients do not unintentionally change their contents. Interface EmployeeTO adapts the MutableEmployeeTO collection, allowing read-only access to the collection while preventing modifications.

The definition of the EmployeeTO interface follows.

public interface EmployeeTO extends Serializable {

public Iterator iterator();

public int size();

public boolean contains(Object o);

public boolean containsAll(Collection c);

public boolean equals(Object o);

public int hashCode();

public boolean isEmpty();

public Object[] toArray();

public Object[] toArray(Object[] a);

static class MutableEmployeeTO extends ArrayList implements EmployeeTO { }

} //end of the interface

The EmployeeTO interface is clearly a collection, since it defines the Java collection methods. The collection is immutable, because it has no methods that would allow the collection contents to be changed. An example of using EmployeeTO appears in method EmployeeAdminFacadeEJB. getEmployeeInfo, shown below. The method constructs a EmployeeTO.MutableEmployeeTO object and populates it with EmployeeDetails instances. Note that the return type of getEmployeeInfo is EmployeeTO, so callers can access only methods that read the collection contents, and not methods that would change them.

public EmployeeTO getEmployeeInfo(int employeeId) throws Exception {

EmployeeTO.MutableEmployeeTO retVal = new EmployeeTO.MutableEmployeeTO();

EmployeeManagerLocal mgr = getEmpMgr();

try {

EmployeeLocalHome pohome = getEmpInfo();

Collection employee = mgr.getEmpById(employeeId);

Iterator it = employee.iterator();

while((it!= null) && (it.hasNext())) {

....... // Access and format data

retVal.add(new EmployeeDetails(employeeId, joiningDate,salary,department));

}

} catch (FinderException fe) {

... // process exception

}

return(retVal);

} //end of method

The details for a single employee are contained in an immutable, serializable transfer object of type employeeDetails It is a typical transfer object for a single composite value, containing private fields and public, read-only property accessors, as shown in the following code sample.

public class EmployeeDetails implements java.io.Serializable {

private int employeeId;

private Date joiningDate;

private float salary;

private String department;

public EmployeeDetails(int employeeId, Date joiningDate, float salary, String department) {

this.employeeId = employeeId;

this.joiningDate = joiningDate;

this.salary = salary;

this.department = department;

}

public int getEmployeeId() { return employeeId; }

public Date getJoiningDate () { return joiningDate; }

public float getSalary () { return salary; }

public String getDepartment () { return department; }

}