Visit Map

Saturday, June 30, 2007

Adapter Variations

//: adapter:AdapterVariations.java
// Variations on the Adapter pattern.
package adapter;
import junit.framework.*;

class WhatIHave {
public void g() {}
public void h() {}
}

interface WhatIWant {
void f();
}

class SurrogateAdapter implements WhatIWant {
WhatIHave whatIHave;
public SurrogateAdapter(WhatIHave wih) {
whatIHave = wih;
}
public void f() {
// Implement behavior using
// methods in WhatIHave:
whatIHave.g();
whatIHave.h();
}
}

class WhatIUse {
public void op(WhatIWant wiw) {
wiw.f();
}
}

// Approach 2: build adapter use into op():
class WhatIUse2 extends WhatIUse {
public void op(WhatIHave wih) {
new SurrogateAdapter(wih).f();
}
}

// Approach 3: build adapter into WhatIHave:
class WhatIHave2 extends WhatIHave
implements WhatIWant {
public void f() {
g();
h();
}
}

// Approach 4: use an inner class:
class WhatIHave3 extends WhatIHave {
private class InnerAdapter implements WhatIWant{
public void f() {
g();
h();
}
}
public WhatIWant whatIWant() {
return new InnerAdapter();
}
}

public class AdapterVariations extends TestCase {
WhatIUse whatIUse = new WhatIUse();
WhatIHave whatIHave = new WhatIHave();
WhatIWant adapt= new SurrogateAdapter(whatIHave);
WhatIUse2 whatIUse2 = new WhatIUse2();
WhatIHave2 whatIHave2 = new WhatIHave2();
WhatIHave3 whatIHave3 = new WhatIHave3();
public void test() {
whatIUse.op(adapt);
// Approach 2:
whatIUse2.op(whatIHave);
// Approach 3:
whatIUse.op(whatIHave2);
// Approach 4:
whatIUse.op(whatIHave3.whatIWant());
}
public static void main(String args[]) {
junit.textui.TestRunner.run(AdapterVariations.class);
}
} ///:~

Saturday, May 19, 2007

Design Pattern -Builder Pattern


The builder Pattren intent is to Seperate the construction of a complex object from its representation so that the same construction process can create different objects.The builder pattren is useful when several kinds of complex objects.The Builder parttern is useful when several kinds of complex objects with similar rules for assembly need to joined at runtime but results in different object types.It achives this seperating the process of building the object from itsellf.t

The builder pattern creates complex objects in multiple steps instead of in single step as in other patterns.

Benefits

It permits you to vary an objects internal's internal representation.

It insolates the code for construction and representation

It provides finer control over the construction process.

GOF Creational pattern - Abstract Factory

More than Factory – allows creation of class families
Go to Sears and order a kitchen make-over. Same order request process can yield very different kitchen drawers, doors and hardware
Provide an interface for creating families of related or dependent objects without specifying their concrete classes

The abstract factory's intent is to provide an interface to use for creating families of related or dependent or dependent objects without actually specifying their concrete classes. For a given set of related abstract classes, this pattern supplies a technique for creating instances of those abstract classes from an equivalent set of concrete subclasses. On some occasions, you may need to create an object without having to know which concrete subclass of object to create.

The abstract factory pattern is also know as Kit.

Benefits

It isolates client from concrete classes.

It eases the exchanging of object families

It promotes consistency among objects

The base GOF patterns are divided into 3 types

Creational

Structural

Behavioral

The Abstract factory pattren come under the creational patterns
J2EE Applicability of Abstract Factory
DAO
Value Object Assembler

Thursday, April 26, 2007

To find Number of pages in word document Programatically

To compute no of pages in a word document you can use the following
ActiveDocument.ComputeStatistics(wdStatisticPages,1)
This gives you the number of pages in the word document
Hope this helps

Sunday, January 21, 2007

Java Bean Generator from Database table

Hi again,
I have written a small utility to generate the java bean classes from exiting tables whihc are present in the database.
You can gerenarate your bean class/Model classes with a click of button.
Hope this helps you

Create a from in VB and keep one text boxes and list box places two command buttons
Here is code

Dim conn As ADODB.Connection
Private Sub CommandButton1_Click()Set conn = New ADODB.Connectionconn.Open "xxxx", "xxxx", "xxxx"Dim arr As ADODB.Recordsetconn.CursorLocation = adUseClientSet arr = New ADODB.Recordsetarr.Open "select TNAME from tab", conn, adOpenDynamic, adLockOptimisticDo While Not arr.EOF ListBox1.AddItem (arr.Fields(0)) arr.MoveNextLooparr.Close
End Sub
Private Sub CommandButton2_Click()Dim arr As ADODB.RecordsetDim strValue As StringDim strClassName As StringIf (conn Is Nothing) Then MsgBox "get the tables first", vbCritical Exit SubEnd IfSet arr = New ADODB.RecordsetstrClassName = Replace(ListBox1.Text, "_", "")strValue = "public class " & StrConv(strClassName, vbProperCase) & "{" & vbCrLf
arr.Open "select * " & "from " & ListBox1.Text, conn, adOpenDynamic, adLockOptimisticFor i = 0 To arr.Fields.Count - 1 Select Case arr.Fields(i).Type Case adNumeric, adInteger, adSingle, 139 strValue = strValue + "private int " & Replace(StrConv(arr.Fields(i).Name, vbLowerCase), "_", "") & ";" + Chr(13) Case adVarChar strValue = strValue + "private String " & StrConv(Replace(arr.Fields(i).Name, "_", ""), vbLowerCase) + ";" + Chr(13) End SelectNextstrValue = strValue & "}"TextBox1.Text = strValuearr.Close
End Sub
Private Sub UserForm_Click()
End Sub
Private Sub UserForm_Terminate()If Not (conn Is Nothing) Thenconn.CloseEnd IfEnd Sub
Raj

Sunday, December 31, 2006

My blog migrated to New Blogger

Hi all,
Hope you like my upgrade to new blogger. It has lots of features which you make use of.

Friday, October 27, 2006

Business Process Execution Language (BPEL)


Before we jump right into a discussion on Business Process Execution Language (BPEL) we need to set a framework for its use. It is important for managers, developers and DBAs to have an understanding of how BPEL can benefit them. Business process management (BPM) technology is a framework for applications that can effectively track and orchestrate business processes. BPM solutions will automatically manage processes and process flow, but allow for manual intervention when necessary. BPM might coordinate the extraction of customer information from a database or manage a new customer information transaction. BPM could generate transactions in multiple related systems or support straight-though processing without human intervention. BPM allows you to automate tasks involving information from multiple systems with rules to define the sequence in which the tasks are performed as well as responsibilities, conditions and other aspects of the process. BPM not only allows a business process to be executed more efficiently, it also provides the tools to allow you to measure performance and identify opportunities for improvement. A benefit of BPM is that changes can be easily made in processes or flow by adding, removing or updating a process.To take the advantage of the whole process the systems should follow Service Oriented architecture.

Business Process excecution language

Business process excecution language defines a notation for specifying the business process behavior.

The following are BPEL servers aviaible they are

ActiveBPEL Engine
IBM BPEL4WS Editor and Java Run-Time
Oracle BPEL Process Manager
Microsoft BizTalk Server 2004(Biz talk server orchestration)
Other BPEL Servers
Here iam giving a brief overview of Oracle BPEL server.

Oracle's BPEL server allows you to connect to data sources via its adaptors

1) File adapters
2) FTP adapters
3) Oracle advanced querying
4) Database server querying
5) JMS adapter
6) Oracle application adaptors
Oracle's BPM has a buit-in support for the following

XSLT Mapper
XPATH
XSD
XSL.

This BPM is completely built on XML.
This is an abstract from Search Oracle's article on BPEL
Hope this gives an idea about BPEL.

To summaries, if you want to implement BPEL in a project, the following are the steps

Expose the service(s) (by registering)
Invoke a process flow
Perform data transformation
Manage exception processing
Include user tasks
Place sensors throughout the process flow
Monitor the process

Thursday, October 26, 2006

Open Source Content Management Systems - .NET

Recently, i came accross some links on Open source Content Management Systems.
I am exploring them
http://petesbloggerama.blogspot.com/2006/10/open-source-aspnet-20-cms-content.html
http://msdn.microsoft.com/newsgroups/default.aspx?&guid=&sloc=en-us&dg=microsoft.public.dotnet.framework.aspnet&p=1&tid=b86611bd-2b72-4ee6-a397-d6f0d8ee9181&mid=b86611bd-2b72-4ee6-a397-d6f0d8ee9181

In my next posts i will write articles on these.

Wednesday, September 27, 2006

Log4J log file not getting generated in Weblogic

If you get a problem of Log file of Log4J is not getting generated, you need to add a entry to the weblogic.xml,
<container-descriptor>
<prefer-web-inf-classes>true</prefer-web-inf-classes>
</container-descriptor>


This is because weblogic has it's own logger.

Tuesday, June 20, 2006

Debugging in Eclipse

Debugging is an important in any development environment. By using the debug we will be able to solve the problem quickly and easily. It also reduces the extra outputs that will be added to the coding, which generally result in the removal of those codes at the End Minute, which might some times results in the Bugging of the entire code.

Like any other IDE’ Eclipse is also provided with the Debug option, so that the java files can be debugged easily and quickly. With that Debug ption, we can debug even the servlets running on the server. The only requirement is that we must have the source code and the server must be running in the Debug Mode.

Here, I am going to use Weblogic 8.0 as the Server.

First we have to edit the Startup Script for StartWeblogic.cmd or StartDocumentum.cmd. At the last of the script, we will be finding the Statement as Below.---------------------------------------------------------------------------------------------------------
%JAVA_HOME%\bin\java %JAVA_VM% %MEM_ARGS% %JAVA_OPTIONS% -Dweblogic.Name=%SERVER_NAME% -Dweblogic.ProductionModeEnabled=%PRODUCTION_MODE% -Djava.security.policy="%WL_HOME%\server\lib\weblogic.policy" weblogic.Server---------------------------------------------------------------------------------------------------------

Replace the above line with the below line

%JAVA_HOME%\bin\java %JAVA_VM% %MEM_ARGS% %JAVA_OPTIONS% -Xdebug -Xrunjdwp:transport=dt_socket,server=y,address=7001 -Dweblogic.Name=%SERVER_NAME% -Dweblogic.ProductionModeEnabled=%PRODUCTION_MODE% -Djava.security.policy="%WL_HOME%\server\lib\weblogic.policy" weblogic.Server
After this modification, when we try to start the server, the Screen will be displayed as fallows.


The Sever will be immediately suspended and it will wait for the Client Program like Eclipse to connect to them.








In the Eclipse, we need to run the application in Debug mode. For this we need to select the RUN->Debug, from the menu. Then we have to select Remote Java Application. In that, we have to specify the port, where the server is running. Here we have to specify the Port No 7001. Then the Debug has to be pressed.

Saturday, April 01, 2006

A rudimentary page flow controller

I have started refreshing struts. I am reading a book called Sturts Survival guide.
Every action has to render the next view to the user after successful business logic invocation.This would mean that a standard mapping.findForward() in every method of yours.The rundimentory page flow controller eliminates this by providing this information in declarative manner in struts-config.xml utilizing MyAction mapping That information is used at runtime to automatically decide which page to forward to. The reason why the page flow controller is called rudimentory si becuase it has serious limitation. If the page trasistions are dyanamic then it cannot work. This controller serves as an example for customized action mapping usage.

Friday, January 27, 2006

After long time

I just wanted to update my blog. Since i have joined a new job. I did not find time to update my blog. People say that they don't have time. But if people can defragment the time. You can find lots of free time. Defragmented time can be used some thing else.

Sunday, July 17, 2005

Creating word to PDF

Hi,

I had opportunity to convert the word document to PDF. The word document is passed to a procedure. The procedure parseS the word document to create a PDF. The code is given below
I have used ITextDotnet which is converted from Java to J#.
You can download the ITEXTDOTNET code from Sourceforge.net
http://sourceforge.net/projects/itextdotnet/

using System;
using Word;
//use the ITextDotnet
using ds=com.lowagie.text;
//include the pdf libary
using com.lowagie.text.pdf;
using System.IO;
using System.Windows.Forms;
using System.Drawing;
using System.Drawing.Imaging;
namespace WindowsApplication3
{
///
/// Summary description for WordDoc.
///

public class WordDoc
{
public WordDoc()
{
//
// TODO: Add constructor logic here
//
}
public void ProccessWordDoc(Word.Document doc)
{


// step 1: creation of a document-object
com.lowagie.text.Document document = new ds.Document(ds.PageSize.A5, 36, 72, 108, 180);

// step 2:
// we create a writer that listens to the document
// and directs a PDF-stream to a file

PdfWriter.getInstance(document, new FileStream(doc.Name.Replace(".doc",".pdf"), FileMode.Create));

// step 3: we open the document
document.open();

// step 4: we add a paragraph to the document


//com.lowagie.text.Image img=new com.lowagie.text.Image()

foreach(Word.Paragraph para in doc.Paragraphs)
{
com.lowagie.text.Paragraph paragraph = new ds.Paragraph();
switch(para.Alignment)
{
case WdParagraphAlignment.wdAlignParagraphCenter:
paragraph.setAlignment(ds.ElementConst.ALIGN_CENTER);
break;
case WdParagraphAlignment.wdAlignParagraphJustify:
paragraph.setAlignment(ds.ElementConst.ALIGN_JUSTIFIED);
break;
case WdParagraphAlignment.wdAlignParagraphLeft:
paragraph.setAlignment(ds.ElementConst.ALIGN_LEFT);
break;
case WdParagraphAlignment.wdAlignParagraphRight:
paragraph.setAlignment(ds.ElementConst.ALIGN_RIGHT);
break;
}
paragraph.add(para.Range.Text);

document.add(paragraph);

}


// step 5: we close the document
document.close();
}
}
}
Hope you like my Idea.
This is a basic prelimary version.

Friday, April 22, 2005

Using Microsoft Agent from .NET

Download the microsoft agent from http://www.microsoft.com/msagent/default.asp. If not present at /msagent\chars
Add a reference to Microsoft Agent server using tools - references - Microsoft Agent server 2.0
Here is the code

IAgentCtlCharacterEx Genie;
Keep a textbox on form and a button in the button click keep the following code

IAgentCtlCharacterEx Genie;
if(textBox1.Text!="")
{
Agent1=new AgentClass();
try
{
Agent1.Connected = true;
string strPath=ConfigurationSettings.AppSettings.Get("path").ToString();
//strPath is /msagent\chars
Agent1.Characters.Load("Merlin",strPath);
Genie=Agent1.Characters.Character("Merlin");
Genie.Show(true);
Genie.Speak(textBox1.Text,"");
}
catch(Exception ex)
{
throw ex;
}


This is just an idea to share

Sunday, April 17, 2005

Checklist:ADO.NET Performance

While browsing the Net i came across one book
Improving .NET Application Performance and Scalability called ScaleNet.pdf
You can download the same from www.microsoft.com/practices
The book is very goood. I suggest you to read that book

In that they given a checklist
Here is checklist for ADO.NET Performance

Design your data access layer based on how the data is used.
Cache data to avoid unnecessary work.
Connect by using service accounts.
Acquire late, release early.
Close disposable resources.
Reduce round trips.
Return only the data you need.
Use Windows authentication.
Choose the appropriate transaction type.
Use stored procedures.
Prioritize performance, maintainability, and productivity when you choose how to pass data
across layers.
Consider how to handle exceptions.
Use appropriate normalization
If you follow the above checklist you can increase the performence of a .NET Application

Thursday, April 07, 2005

Session State

Recently i had doubt on a session is handled between Classic ASP and Classic ASP.NET.The session management between ASP and ASP.NET is sticky issues. An article from Egghead Café cleared by doubts.
http://www.eggheadcafe.com/articles/20021207.asp
I also went through the article in MSDN how a session is managed in ASP.NET
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconsessionstate.asp

Microsoft User Group Hyderabad is conducting a session on Existing and Emerging technologies the session in Cyber towers, Chip Auditorium Madhapur Hyderabad.
One can register at www.mugh.net/devcon.htm.

Saturday, March 12, 2005

Error Registering ComPlus Components

I have solved the problem of Com + Registration problem on Windows 2003. "Type Library cannot be loaded".
The problem is with the path.The path C:\WINNT\Microsoft.NET\Framework\v1.1.4322 is not specified in the path string, Environment Variables.
Before ten days it was working so to know this we have downloaded the FileMon from www.SysInternals.com monitored the dllhost.exe.
The dllhost.exe is shown in the FileMon saying "mscorlib.tlb" Path Not Found.
Then I searched for the path and found out that C:\WINNT\Microsoft.NET\Framework\v1.1.4322 is not there in the path string
I have kept it there, then components are registered

Wednesday, November 24, 2004

Showing a Excel report in a Web Page by using Response.Content Type

When showing Excel in a Webpage using a dataset and binding the dataset to a datagrid. Make sure that you keep EnableViewState=false.This is because State is getting lost when you bind the data to the datagrid.This is to maitain state accross the webpage.



Monday, October 11, 2004

Using XML Serialization

I have started my code for a bigger module. Which contains Lots a new stuff. I have lots of new things to explore. I need to learn a lot. Till now i have a learnt a Very little bit. It was said "Known is a drop and Unknown is a ocean." I have used XML Serialization for loading data into a dataset. This goes likes this I will get all the data in a array list The array list contains objects of a class (which is a model class which contains only properties) I will loop through the array list and get the xml strings. All the xml strings will be loaded to into string builder. After that i will load the xml to a dataset. But this approach has some issues. The xml is loaded into different tables i.e. all the elements in the xml file are loading into different tables. That’s why i looked for some other work around for this. I will make the model class as a data table. All the properties will become columns in the datatable. After getting the datatable i will attach this datatable to dataset. The dataset will be loaded into a data grid. I need to see how this goes.
I have known that the above approach is very useful.
But we can load the arraylist directly to the data grid.
The arraylist contains a bunch of Model class which contains property values.
We have to assign the data source of the data grid to the array list and we need to assign the specific property names to the data grid.


Monday, September 27, 2004

I have made a dession

Now I have made decision that I will concentrate more on design. I have to learn more about class design and use case design the things what i have learnt are not enough. Today i have learnt about association, abstraction, composition, aggregation and specialization.
Definitions
Association:- kind of relationship or link between classes. Associations are further documented by stereotypes + roles + multiplicities + constraints + descriptive names + aggregation indicators + navigability indicators. [ uml.coll0.gif ] [ uml.coll1.jpg ] [ uml.game.gif ] [ uml.association.gif ] [ uml.link.gif ]
Composition:- composition::= a strong form of the 'has_a' or APO relation so that deleting the whole automatically removes the parts as well. Composition fits when objects of one class are made up of parts that are objects of other classes, for example when they are implemented using fields in structures, items in records, columns in a data base, or pieces of a document. However, in some cases, the responsibility for keeping an object alive changes during that objects life, and so that objects class would be shown as being parts of several different compositions. [ clock2.gif ] [ uml.period.gif ] [ uml.link.gif ]
Aggregation: - aggregation::=a way that one class can refer to another class without having possession of it + a weak form of 'has-a' / APO link + if the whole object is an aggregation then deleting it does not effect the existence of the aggregated part. An open diamond at one end of a link shows this relationship. The other end may have an arrowhead indicating the link can be navigated in one direction only.
Specialization:- When we derive a class from an existing class and add some functionality to it becomes a specialization