This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
Authored by: AmirSam Bahador Level: Advanced Contents: Introduction - The purpose of compilation this essay
Chapter 1: Basic concepts of J2EE - Servlet and JSP - MVC - MVC or JWMS? That is the problem? Perhaps both!
Chapter 2: Basic concepts of Shine Framework - What is "Shine Framework�? - The components of Shine Framework - Implimentation of an application by Shine Framework
Chapter 3: The objects of Shine Framework - The types of objects in Shine Framework
Chapter 4: Engineering & Communication items - The communication of Shine Framework with the other existing Frameworks - The major purpose of Shine Framework
Introduction The purpose of compilation of the this paper A few years ago, when I was the software architect of a big project with J2EE, I advised some of the modern tools of that time to the project manager. He acknowledged it. Therefore, we began deploying our Enterprise on Java platform. However, we encounterd with many problems, as we got ahead the project. Our tools were included Struts Framework, Spring Framework & Hibernate.
I convinced that MVC architecture is the best option to develop macro projects! However, I believe it now, as well. Couldn't it be more completed? In developed Enterprise projects, an advanced architecture is required to divide the project, technically. The project was successfully finished after one year, but my mind was busy with it for a long time!
Then, I began implementing an Application Framework and registered it in Sourceforge.net as an Open Source Framework. I developed some Enterprise projects & some other J2EE frameworks, as well. I achieved a good result! The velocity of implemention & developing projects increased up to 50%. Subsequently, by cooperation of my elected students who had worked with Application Framework, I established an organization, named J2SOS, to protect & develop this Application Framework. Fortunately, my students were so skilled that each took a chief task in big J2EE projects. Their experiences had a practical affect on development of Application Framework as well as the organization. Therefore, it is required to write down my & my yesterday students (my today co-workers) experiences. This was the outset to write the present paper!
Chapter 1 The basic concepts of J2EE Purposes In this chapter, we do our best to introduce J2EE basic concepts. Servlet & JSP If you ahve ever worked with JSP & Servlet, you know that Servlet is so proper for processing functions but there are particular problems with it in displaying functions.
JSP is applied reverse to Servlet. Thus, what is the solution? To apply both JSP and Servlet together!
What is MVC? MVC is an easy way to use JSP & Servlet together. In MVC architecture, the request will be processed by a Class (Servlet) and the appropriate response will be showen by JSP.
See Figure 1-1
In the above Servlet Class, the validation operation, etc will be done.
Nowadays, there are numerous Frameworks which will assist you to use MVC Framework architecture. Struts Framework is the most well-known one. MVC or JWMS ? That is the problem! Perhaps both!
MVC is a powerful architecture, but it is required an advanced architecture to implement developed projects. Today, web applications are well developed which complicatethe work for programmers & developers. To clarify it, see Google site! Google Web Application enjoys numerous services, each have a special service for the users. For Instance, Gmail service, E-Mail or by SearchEngine, the users can search for websites, pictures, etc.
These services have certaily close communication with each other. If the services do not use a particular architecture, the Google will encounter with various problems. In Service Oriented architecture, each part of the program is a service programme. For example, E-Mail service, SearchEngine service, etc.
Consider Electeronic-Goverment application. This application does numerous services; each can be regarded as a separate application.
However, there is a problem! These applications should have communication with each other, i.e., a communication which is not a simple messaging one! I propose JWMS architecture to solve this problem! Java Web Model Service (JWMS) transforms each part of E-Government application to a service. For instance, E-Bank service, E-Ministry service, etc.
See Figure 1-3
As you see, the request of user is transfered to Model via Web, it is processed by the Model t and the user is directed to the proper Service. Model means a Servlet which processes the Request of the user. It is likely that, in the first outlook, this architecture looks like MVC. Wait! You are not familiar with its internal components, yet! To understand it obviously, you should be familiar with a Framework.
J2EE Service Oriented Programming In
Chapter 2 Basic concepts of Shine Application Framework
The purpose of this chapter is to introduce you Shine Application Framework. What is Shine Application Framework? Shine Application Framework is a Service Oriented Framework which assists you to implement applications in accordance with MVC & JWMS architedtures. The components of Shine Framework In applications which impliment by Shine, the request is first processed by the Model and the user is directed to the proper Service.
The Class that acts as Model is called Mapping. Mapping Class is similar to a servlet.
Each Mapping Class should extend �j2sos.shine.controller.Mapping� Class & implement �public void rater()� method.
Each service includes a JSP or a JSF page or � in which there are a succession of Shine�s rules and its exclusive tags.
See Figure 2-1:
Let�s review exclusively the components of the application which have been implemented by Shine.
See Figure 2-2:
The request is processed when it inserts the Mapping Class which spacifies the appropriate service for the user�s request and directs the user toward the service by web.xml file. Implimentation of an application by Shine Framework Make a web application as below:
Then apply �shine.jar� file to your library. After adding the mentioned library, change �web.xml� file as follow:
Now, let�s analyze this file. - �Description� tag indicates the name of application. - �Servlet-name� & �servlet-class� tags show the name & address of �Mapping� class.
- �Init-param� tag and �ServerConsoleStatus� property & its �true� value notify Shine that the descriptions of the request should be displayed in Server side
This property will help you to get information about the requests via text environment of ApplicationServer. This property will certainly remind you of �showsql� in �Hibernate�.
- �Init-param� tag & its �Content-Type� property indicate the type of the contents of the response. - "Init-param" tag & "servicename1", "servicename2" properties identify two services to Shine as well as specify the address of each service on the same server or the other one in Shine. - "Servlet-mapping" tag indicates a name to attain "Mapping" class to the requests. - The address of the library of Shine is identified to the ApplicationServer by "Taglib" tag.
Getting to know setting of Shine's properties in "web.xml" file, you should put "shine.tld" file beside "web.xml" file.
At present, � properties� setting of �web.xml� file is finished & we should consider the �Mapping� classes.
All of �Mapping� classes should be extended �j2sos.shine.controller.Mapping� class and implement �public void rater()� method.
For instance, let�s impliment �view.MyMapping� class.
As you see, this class enjoyes a method named �rater�. When the request inserts the �MyMapping� class, It will automatically be called.
This method is responsible for the first processes on the requests.
It is obvious that another method has been called in this method.
�Forward� method lead the user to the proper service. In this example, the user will be directed to �servicename2� service.
The value of �tag1� will be further explained next.
It is noted that you can call �forward� method by the other methods.
As it is previously mentioned, �servicename1� & �servicename2� indicate the address of two JSP pages which perform as a service.
Let�s implement one of these services (JSP pages).
Since �servicename2� is utilized in the previous example, we implement �service2.jsp� now. First �web.xml� should be reviewed.
Iimplement a JSP page initially named �service2� with the following contents:
In the beginning of the above page, the library of ApplicationServer is identified.
This page (Service) includes four principal tags.
�header� & �footer� tags act as the same as header & footer of text pages.
The values of �tag1� & �tag2� perform as two pages. When you call �forward� method in �MyMapping� class as below:
The user will be directed to �service2.jsp� as well as �tag1� will be displayed alongwith header & footer.
This is Shine Application ! Hello , this is service 2 and tag 1 J2SOS Organization
Now, if you call �forward� method in �MyMapping� class as below:
The user will be directed to �service2.jsp� and �tag2� will be displayed alongwith header & footer.
This is Shine Application ! Hello , this is service 2 and tag 2 J2SOS Organization
This type of coding in these pages lead to data sorting. In these pages, you can get values once via JSP and use it in all tags.
In fact, in this architecture, JSP pages act as �Service� & tags are considered as your �pages�.
Now, let�s impliment �service1.jsp� page.
To direct user to this service, it is merely required to call �forward� method as below:
To get the address of JSP pages & setting them in �web.xml� file, each page is directly run directly, then its address is indicated in �web.xml� file.
In these pages, reverse to Struts, you can use objects of request, response, etc in JSP since URL values are sent to JSP pages (Services) by �Mapping� classes send to.
Being acquainted with �Mapping� classes & �Service� pages, you should be able to send the request of user to �Mapping� class.
Therefore, It is required to set the value of the Action of HTML forms on your Mapping classes.
It is observed that this form bears a text field called �name� and the value of its action has been set on �MyMapping� class. Now, let�s survey on sending request by Ajax! In this example, you should put �ajax.js� & �md5.js� files beside the request page.
As you can see, this form have a name. its information is sent to �MyMapping� class via �ajaxSubmit� method. The value of �flase� in �ajaxSubmit� method causes the user not to communication with the request page till receiving the response.
�AjaxLoad� method will automatically be called when the form is sent. While the response is received, �ajaxResponse� method will be called, as well.
The value of �content� value includes the response of �MyMapping� class.
You can use �ajaxMD5Submit� method instead of �ajaxSubmit� one to send the information of form in MD5 format to �MyMapping� class.
�ajaxEternalSend� method acts similar �ajaxSubmit� method but it sends an URL and receives response, constantly. For instance:
In this method, the number �4� indicates a time scale to send URL to the �MyMapping.exec� class again.
Some other methods are determined in �component.js� file to help you in communication with java.
The objects of Shine Framework
In this chapter, the objects of Shine framework will be discussed.
The types of objects of Shine framework As you know we have not achieved a parameter in mapping classes yet, therefore, 3 methods are used in these classes as follows; - getRequest() method acts similar to request object in JSP. To get parameter from URL, it is required perform as bellows;
getConfig() and getResponse() method are applied the same as getRequest() too.
j2sos.shine.script.Server class help you work with server operating system API. If you intend to install a web based operating system, you can use this class. The followings are the methods of this class:
To work with each method, you should make an object from this class. Herein, the above methods are described.
Write() and writln() methods create a text on textual consul of Application Server.
getFileValue() method receives a directory and afile name, then return the contents of textual file.
writeFile() method receives a directory, a file name as well as file contents and makes a file in server.
createFolder() method recieves a directory and a file name to create a folder in server.
deleteFolderAndFile() method deletes a file or folder in server.
getCurrentDate() method sends back server's local time .
shutDownApplication() method stops the executing application.
j2sos.shine.script.CompietionRequest class helps you to receive parameters from URL. The followings are the methods of this class:
getUserid() method sends back identify number of the user session.
getRequestCounter() method makes a general counter and recieves a value for indicating the step of counter. The other methods of this class perform similar to request.getParameter("ParamName") command, except they help you in casting and validation. For instance, getStrParam("name","it is null") method leads the value of name to be sent back from URL, if this value is not available in URL, "it is null" value is returned. j2sos.shine.monitor.ServerConsole class bears a method named showSeverConsole, which receives an object of request and displays the descriptions of request by application server console. j2sos.shine.socket.ResponseService class have a method named getTagText, which receives an URL and tag name, then returns the contents of tag.
Chapter 4 Engineering and communication items
In this chapter, you are acquainted with engineering and communication items.
The communication of Shine Framework with other existing Frameworks
As you now, the communication of a framework with other frameworks is extremely important. You can communicate with other frameworks in shine. These frameworks include as follows: Hibernate Spring Struts Or even Jsf, I am sure you have idea in this regard. I try my best to put some of frameworks beside shine. You can have several methods in mapping classes, for instance:
In this class, it is first received PageName value from URL. Next, regarding PageName value, the service which should respond the request, will be identified. If the insert value is p, p1Validation() method will be called. If the input value is p2, p2Validation() method will be called. If it is not input any P1 & P2 values, the user will be directed to errorservice and the value of notexisturl tag will be displayed. If it is not input any P1 & P2 values, the user will be directed to errorservice and the contents of URL tag will be displayed. If the developer makes an Exception, the user will be directed to errorservice and the contents of exp will be displayed. Suppose we made an aspect file and programming it as before running each of methods(P1Validation, P2Validation), the other method is called. Therefore, you will create a powerful management in mapping2 class. Now, let's combine struts and shine together. It is required to use struts tags in your own service tags. For instance:
As you see, you can easily communicate with other existing frameworks in shine. Ther have been published numerous papers about SHINE and JDBC , etc. See the following websites: www.j2sos.org or www.sourceforge.net .
The major purpose of Shine framework
The main purpose of shine framework is implementing service oriented applications. In this framework, the developer is focused on implementing services. This framework includes java web model service (JWMS) and MVC , which provides a particular system in implementing enormous applications.