Turbine's profiles and control flows, see "Turbine Brief," this article mainly describes the development steps of Turbine 2.2 applications.
According to our different needs, there can be three ways to use Turbine. We can choose from one or three, depending on our own:
l as a servlet frameworks, turbine as the Controller
l as a Framework code Library
l as an Object-RELATIONAL TOOL
No matter how you want to use Turbine, you only need to use the turbine.jar file. In other words, if you want to use Turbine's connection pool, just add turbine.jar to your classpath, then tell Turbine with the appropriate code in your application, where to get it, you can get it.
Turbine has now developed into a huge, easy to make people a smoking code library (CodeBase). Even so, Turbine has a clear organic form to make it easy to identify the function of each part of the code.
1.1 Code Organization
Turbine's code is divided into the following sections:
l org.apache.turbine.modules - this is the module system in Turbine. See "Turbine Brief" for a detailed introduction of each module.
l org.apache.turbine.com - om means Object Model. This part of the code is how to deal with how Turbine's Object Model is, which is full of Turbine to process J.
l org.apache.turbine.services - This part is Turbine's service framework. Service Framework is a very important aspect in Turbine. These services have processed a variety of transactions, such as database connection pools, such as log services, and more.
l org.apache.turbine.torque - this is the data persistence of Turbine. It can generate. SQL, such a defined XML file, so we can easily build an Object Relational system.
l org.apache.turbine.util - As the name suggests, this is Turbine toolkit. Here is a lot of tools that are often used in Web Application.
2 drill
2.1 TDK
In order to make more convenient exercises, we need to use TDK.
Turbine Development Kit (TDK) is Turbine, Tomcat, and a collection of jars, documents. With it, we can easier learning and develop Turbine Application.
2.1.1 TDK installation
TDK detailed installation instructions See Referring 3, this article is not described later. However, in the narrative of this article, only the connection method of the mysql database is given, given that the use of Oracle is very wide, and the Oracle connection method is given here:
Okay, everyone has installed TDK and Turbine Data Manager examples. So, we will start now.
2.2 Turbine Data Manager
Top Turbine Data Manager (TDM) Home, what we saw:
View the login.vm file under WebApp-Name / Templates / App / Layouts, the contents are as follows:
$ navigation.setTemplate ("/ defaulttop.vm")
td>
TR>
$ SCREEN_PLACEHOLDER
td>
TR>
$ navigation.setTemplate ("/ defaultbottom.vm")
td>
TR>
TABLE>
Try to add a line in its most in front: "Welcome Turbine Data Manager!", Refresh the Turbine Data Manager's home page, we found that its homepage changes to:
At its top, there are many lines we just join. What exactly is this matter about?
Note that in "Turbine Brief", Turbine uses Velocity as its expression layer, and the text files for VelociMacro, HTML format is the configuration file used to control the page display. Velocity joined Turbine in the form of Service, which is the Velocity Service in Turbine Service Framework. Velocity Turbine constitutes the Template Service.
Login.vm is used to control the VelociMacro displayed by the TDM login page.
Look at the following lines in login.vm:
...
$ navigation.setTemplate ("/ defaulttop.vm")
td>
...
It defines that you need to call DEFAULTTOP Navigation in Login Layout, and this Navigation should be placed in a table. DEFAULTTOP.VM defines that you need to display a picture, this picture is "Turbine Data Manager".
Similar to Layout and Navigation control, the Screen, UI in Turbine is also controlled by the same method. In addition to using the .vm file, Turbine can also be controlled by the Java class, content display, etc.
So, how does Turbine know to find these files to these places?
Turbine's configuration file lookup mode is:
1. Define the storage path of the turbineresources.properties file in web.xml;
2, in the Turbineresources.properties file, define the storage path of the Template File [I].
2.2.1 SCREEN in TDM
Now let's take a look at the Screen in TDM in detail:
Transfer to the "WebApps / AppName / Templates / App / Screens" directory. Everyone may still remember that there is a "$ screen_PlaceHolder" variable in the login.vm file. In fact, this variable in each layout is replaced with the files in this directory. [Ii].
Open the "index.vm" file, where there is a variable called "$ headings", which saves the Head information in the Index page; another variable called "$ entries" saves all in the Index page. Dynamically displayed. The value of these variables comes from the Java class associated with it. Also, there are also some functions of "#" in Index.VM, such as "#ntrycell (...), which are replaced with a variety of HTML code when running [III] [IV] .
Looking at the "WebApps / Appname / Web-INF / SRC / JAVA / PACKAGE / MODULES / SCREENS" directory, the dynamic content in each page in TDM is closely related to the Java file here. Open the "index.java" file, just as we see, the DobuildTemplate method creates a variable called "Entries" and puts the data taken out in the GetEntries method. You can modify this Java file yourself, you can change the method and data of the data acquisition data. If you want to know more detailed information, please refer to Turbine's Velocity Site Howto documentation.
2.2.2 Action in TDM
Insert a data in TDM, it can be seen that the last paragraph in the URL shown in the browser is: "/ Action / SQL". The actual call of insertion data is the "WebAPPS / AppName / Web-INF / SRC / JAVA / PACKAGE / MODULES / ACTIONS / SQL.JAVA" Java class corresponding to this action.
In the sample program TDM, we can see a large number of URLs. Through these URLs, we can know which Action is called for each operation, which allows us to learn Turbine more easily.
[i] will explain how to configure this item.
[II] Well, strictly speaking, this sentence is not correct, but it is easy to understand, and so.
[III] These code is saved in the "WebApps / Appname / Templates / App / GlobalMacros.vm" file, through these code, you can understand what these functions are used to complete.
[IV] As for these. Various HTML, the specific meaning of the HTML, the specific meaning of the function, see Resources 4.