OFBIz之旅[结构]
注意:
1,持久层,在OFBIZ中的定义,就是Model。DAO被划分到业务层中。
OFBIz已经改名为OpenTaps项目发展了。其自身的工作流引擎也已经停止发展。现在改用内嵌式的shark工作流引擎作为自己的工作流引擎。而且,实际上并没有使用shark制作任何工作流。
Opentaps的宗旨,还是使用一系列自创的开源技术,开发大规模的企业级应用程序。它的目标,不是工作流,也不是appfuse这样一个整合其他开源技术的演示性的网站,而是一个综合的、企业级的电子商务网站。
First, go into your OFBiz directory and take a look inside:
首先,进入Ofbiz目录:
[sichen@localhost ofbiz_5010]$ ls -l
total 88
drwxrwxr-x 15 sichen sichen 4096 May 20 07:54 applications
drwxrwxr-x 8 sichen sichen 4096 May 20 07:59 base
-rw-rw-r-- 1 sichen sichen 10173 May 20 07:58 build.xml
drwxrwxr-x 4 sichen sichen 4096 May 20 07:59 data
drwxrwxr-x 24 sichen sichen 4096 May 20 07:58 framework
drwxrwxr-x 3 sichen sichen 4096 May 20 07:52 hot-deploy
-rwxrwxr-x 1 sichen sichen 309 May 20 07:58 ij.ofbiz
drwxrwxr-x 2 sichen sichen 4096 May 20 08:08 logs
-rw-rw-r-- 1 sichen sichen 21167 May 20 08:07 ofbiz.jar
-rw-rw-r-- 1 sichen sichen 2869 May 20 07:58 rc.ofbiz
drwxrwxr-x 6 sichen sichen 4096 May 20 07:55 specialized
-rw-rw-r-- 1 sichen sichen 265 May 20 07:58 startofbiz.bat
-rwxrw-r-- 1 sichen sichen 790 May 20 07:58 startofbiz.sh
-rwxrw-r-- 1 sichen sichen 325 May 20 07:58 stopofbiz.sh
drwxrwxr-x 12 sichen sichen 4096 May 20 07:52 website
Things to note here:
1,ofbiz-component.xml 每个组件都有这样一个文件。它们用于定位该组件的jar包和entity 实体等配置文件。
OFBiz is built around a components-based architecture, which means each application is inside a component. This allows outside or custom applications to be added easily.
OFBIZ采用了基于组件的架构。这就是说,每一个应用程序在一个组件内。这允许外部的和定制化的应用程序能够很容易的被包含近来。
The applications/ directory holds the applications components, such as order manager and ecommerce store.
Applications目录,包含了OFBIz核心的应用程序组件,如订单管理,电子商务存储等。
component-load.xml文件配置需要载入哪几个应用程序组件。
这里的每一个组件,都是一个基于OFBIZ构建的Web应用程序。
The framework/ directory holds the components for the OFBiz framework, such as the entity engine, and service engine.
Framework框架目录,包含OFBIZ框架的组件,例如实体引擎和服务引擎。
这是OFBIZ框架的核心,其他应用程序都是基于它来构建的。
component-load.xml文件配置需要载入哪几个框架组件。
specialized/ contains some other applications which are not part of the OFBiz core.
Specialized专门目录,包含一些其他的应用程序,不是OFBIZ核心的一部分。
hot-deploy/ is another directory where components can be dropped in and automatically loaded.
hot-deploy热部署目录,是另一个目录。它的组件能够被删除和自动载入。
金融和CRM2个项目在这里。
这里没有component-load.xml这个文件。
本目录中所有的组件,都会在framework和application目录下的组件被导入之后导入。
base/ contains code for starting up and configuring ofbiz.
base目录,包含启动和配置ofbiz的代码。
logs/ contains log files. On Unix/Linux, ofbiz runs as a background process, and all console output is in logs/console.log
logs日志目录,包含日志文件。
website/ is the contents of ofbiz.org.
website 网站目录,是ofbiz.org网站的内容。
另外,data目录下是几个内嵌式的数据库。
Now let's go inside framework/ and take a look:
现在,让我们进入framework目录看一看:
[sichen@localhost ofbiz_5010]$ cd framework/
[sichen@localhost framework]$ ls -l
total 88
drwxrwxr-x 7 sichen sichen 4096 May 20 08:00 appserver
drwxrwxr-x 8 sichen sichen 4096 May 20 07:59 catalina
drwxrwxr-x 12 sichen sichen 4096 May 20 08:00 common
-rw-rw-r-- 1 sichen sichen 2988 May 20 07:58 component-load.xml
drwxrwxr-x 6 sichen sichen 4096 May 20 07:59 datafile
drwxrwxr-x 10 sichen sichen 4096 May 20 07:59 entity
drwxrwxr-x 9 sichen sichen 4096 May 20 07:59 entityext
drwxrwxr-x 12 sichen sichen 4096 May 20 07:55 example
drwxrwxr-x 6 sichen sichen 4096 May 20 08:00 guiapp
drwxrwxr-x 4 sichen sichen 4096 May 20 07:56 images
drwxrwxr-x 6 sichen sichen 4096 May 20 07:59 jetty
drwxrwxr-x 7 sichen sichen 4096 May 20 07:59 jotm
drwxrwxr-x 6 sichen sichen 4096 May 20 07:59 minerva
drwxrwxr-x 7 sichen sichen 4096 May 20 08:00 minilang
drwxrwxr-x 9 sichen sichen 4096 May 20 07:59 security
drwxrwxr-x 11 sichen sichen 4096 May 20 07:59 service
drwxrwxr-x 12 sichen sichen 4096 May 20 08:00 shark
drwxrwxr-x 10 sichen sichen 4096 May 20 08:00 tests
drwxrwxr-x 9 sichen sichen 4096 May 20 08:00 webapp
drwxrwxr-x 9 sichen sichen 4096 May 20 08:00 webtools
drwxrwxr-x 6 sichen sichen 4096 May 20 08:00 widget
drwxrwxr-x 9 sichen sichen 4096 May 20 08:00 workflow
These are the components of the OFBiz framework, which is used to develop the OFBiz applications.
这些是用来开发OFBIZ应用程序的OFBIZ框架组件。
component-load.xml controls which of the components in the current directory are loaded.
component-load.xml文件控制现在哪些组件被使用。
Now go back and take a look at the applications themselves:
[sichen@localhost framework]$ cd ..
[sichen@localhost ofbiz_5010]$ cd applications/
[sichen@localhost applications]$ ls -l
total 52
drwxrwxr-x 13 sichen sichen 4096 May 20 08:00 accounting
-rw-rw-r-- 1 sichen sichen 2425 May 20 07:54 component-load.xml
drwxrwxr-x 15 sichen sichen 4096 May 20 08:00 content
drwxrwxr-x 11 sichen sichen 4096 May 20 08:00 ecommerce
drwxrwxr-x 5 sichen sichen 4096 May 20 07:53 humanres
drwxrwxr-x 12 sichen sichen 4096 May 20 08:00 manufacturing
drwxrwxr-x 12 sichen sichen 4096 May 20 08:00 marketing
drwxrwxr-x 13 sichen sichen 4096 May 20 08:00 order
drwxrwxr-x 12 sichen sichen 4096 May 20 08:00 party
drwxrwxr-x 12 sichen sichen 4096 May 20 08:00 pos
drwxrwxr-x 12 sichen sichen 4096 May 20 08:00 product
drwxrwxr-x 10 sichen sichen 4096 May 20 08:00 securityext
drwxrwxr-x 12 sichen sichen 4096 May 20 08:00 workeffort
These are the OFBiz applications themselves. Each application is self-contained with its own data model definitions, business logic, and presentation (web or Swing) tier, although applications may reuse each others' business logic and thus depend on each other.
这些是OFBIz应用程序本身。每一个应用程序是自包含的。它们自己有自己的数据定义,业务层和表现层(Web或Swing)。虽然应用程序之间可以重用业务逻辑(其数据层、数据库是一样的),因而是互相依赖的。
Now let's go inside an application and see what it looks like:
现在,让我们进入一个应用程序,看看里面有什么:
[sichen@localhost applications]$ cd product/
[sichen@localhost product]$ ls -l
total 52
drwxrwxr-x 4 sichen sichen 4096 May 20 08:08 build
-rw-rw-r-- 1 sichen sichen 6413 May 20 07:53 build.xml
drwxrwxr-x 3 sichen sichen 4096 May 20 07:53 config
drwxrwxr-x 3 sichen sichen 4096 May 20 07:53 data
drwxrwxr-x 3 sichen sichen 4096 May 20 07:53 entitydef
-rw-rw-r-- 1 sichen sichen 4202 May 20 07:53 ofbiz-component.xml
drwxrwxr-x 4 sichen sichen 4096 May 20 07:53 script
drwxrwxr-x 3 sichen sichen 4096 May 20 07:53 servicedef
drwxrwxr-x 4 sichen sichen 4096 May 20 07:53 src
drwxrwxr-x 5 sichen sichen 4096 May 20 07:53 webapp
drwxrwxr-x 5 sichen sichen 4096 May 20 07:53 widget
Here is what you are seeing:
build/ is where the compiled Java code and any libraries for this application go.
Build目录是已编译的java代码和任何Java库。它们能够使这个应用程序运行。(但是不能够仅仅靠它们运行。可以仅靠webapp目录下的一个或者多个web应用程序运行)
build.xml tells ant how to build this application. It is like a Makefile.
build.xml文件是ant文件,用于测试和构建这个应用程序。
config/ is for configuration data, such as internationalization (i18n) UI labels in various languages.
Config目录包含配置文件,例如多语言下的国际化UI标签的配置文件。
data/ is where the seed and demo data, in XML format, are located.
Data目录包含种籽和演示数据,xml格式。
entitydef/ is where the data model definitions of this application are.
Entitydef目录,包含这个应用程序的数据模型定义。
script/ is where scripts for business logic are. Scripts can be written in beanshell, OFBiz minilang, Jython, etc.
script脚本目录,包含业务逻辑的脚本文件。
servicedef/ is where the services, which are small, granular pieces of business logic (similar to functions or methods), are defined.
Servicedef目录,包含services服务,它们是细粒度的业务逻辑(类似于方法或函数,它们就是DAO方法)。
src/ is where Java classes for implementing business logic are.
Src源文件目录,包含实现业务逻辑的Java类文件(粗粒度的业务逻辑)。
webapp/ is where the web interface, or front end, applications are. An OFBiz application can have more than one webapp.
Webapp目录,是web接口,是应用程序的前端。一个OFBIZ应用程序能有多个webapp应用程序。
ofbiz-component.xml defines this application by specifying where its data model, business logic, seed data, and web applications are located.
ofbiz-component.xml文件定义这个应用程序指定的数据模型,业务逻辑,种籽数据和web应用程序的定位。包括部署web应用在哪里等等。
A look inside the entitydef/ and servicedef/ directories will show the XML files used to define the data model and business logic, respectively:
看一下entitydef目录和servicedef目录,它将显示被用来定义数据模型文件和业务逻辑(DAO)的xml文件。
[si@localhost product]$ ls -l entitydef/
total 264
-rw-rw-r-- 1 si si 3094 May 27 08:00 eecas.xml
-rw-rw-r-- 1 si si 16862 May 27 08:00 entitygroup.xml
-rw-rw-r-- 1 si si 62923 May 27 08:00 entitymodel_shipment.xml
-rw-rw-r-- 1 si si 171582 May 27 08:00 entitymodel.xml
[si@localhost product]$ ls -l servicedef/
total 252
-rw-rw-r-- 1 si si 1836 May 27 08:00 groups_shipment.xml
-rw-rw-r-- 1 si si 5217 May 27 08:00 secas_shipment.xml
-rw-rw-r-- 1 si si 3897 May 27 08:00 secas.xml
-rw-rw-r-- 1 si si 42967 May 27 08:00 services_facility.xml
-rw-rw-r-- 1 si si 15516 May 27 08:00 services_feature.xml
-rw-rw-r-- 1 si si 9261 May 27 08:00 services_maint.xml
-rw-rw-r-- 1 si si 9411 May 27 08:00 services_picklist.xml
-rw-rw-r-- 1 si si 19216 May 27 08:00 services_pricepromo.xml
-rw-rw-r-- 1 si si 3374 May 27 08:00 services_shipment_ups.xml
-rw-rw-r-- 1 si si 5844 May 27 08:00 services_shipment_usps.xml
-rw-rw-r-- 1 si si 29717 May 27 08:00 services_shipment.xml
-rw-rw-r-- 1 si si 16205 May 27 08:00 services_store.xml
-rw-rw-r-- 1 si si 9817 May 27 08:00 services_view.xml
-rw-rw-r-- 1 si si 56540 May 27 08:00 services.xml
The webapp/ directory holds the web front end applications. A look inside shows that this application actually has two web applications, catalog and facility:
[si@localhost product]$ ls -l webapp/
total 8
drwxrwxr-x 18 si si 4096 May 27 08:00 catalog
drwxrwxr-x 13 si si 4096 May 27 08:00 facility
catalog/ is the OFBiz Catalog Manager, used to manage product information. facility/ is the OFBiz Facility Manager, used to manage warehouses and inventory.
Catelog目录是OFBIZ的目录管理器,用来管理产品信息。
Facility设施目录,是OFBIZ设施管理器,用来管理仓库和存货。
In most dynamic web pages, there are some page elements, such as page headers, navigation bars, or shopping cart contents, that are repeated on many pages. When a visitor requests the page, the page will usually do some preprocessing, such as retrieving data from a database, and then present it to the user on a display page. In PHP, this is usually done by a SQL query first and then HTML code which presents the results of the query.
在大多数动态Web页面中,
With OFBiz, pages are divided into smaller pieces which are re-combined to create the final product. Thus, many pages can share common elements such as page headers, sidebars, and navigation bars. This is called the "decorator pattern." There is a further separation of the activities of a page into "actions," such as getting data from a database, and "presentation," the display of that data to the visitor.
装饰者模式----页面被分成很多小片,然后重新组合成最终的产品。
有一个更进一步动态页面的分离技术,“action”:例如,从数据库得到数据,并且在表现层把数据显示给参观者。
The "actions" in OFBiz are written in beanshell scripts, while the "presentation" is written in Freemarker template pages. Beanshell (.bsh) is a scripted version of Java, while Freemarker (.ftl) is a templating language that is used in OFBiz to create HTML or XSL:FO pages.
So here are the contents immediately inside a web application. The sub-directories hold the pieces of Freemarker pages:
[si@localhost product]$ ls -l webapp/catalog/
total 80
drwxrwxr-x 3 si si 4096 May 27 08:00 catalog
drwxrwxr-x 3 si si 4096 May 27 08:00 category
-rw-rw-r-- 1 si si 1866 May 27 08:00 ChooseTopCategory.ftl
drwxrwxr-x 3 si si 4096 May 27 08:00 config
drwxrwxr-x 3 si si 4096 May 27 08:00 error
-rw-rw-r-- 1 si si 1552 May 27 08:00 FastLoadCache.ftl
drwxrwxr-x 3 si si 4096 May 27 08:00 feature
drwxrwxr-x 3 si si 4096 May 27 08:00 find
drwxrwxr-x 3 si si 4096 May 27 08:00 includes
-rw-rw-r-- 1 si si 44 May 27 08:00 index.jsp
drwxrwxr-x 3 si si 4096 May 27 08:00 lookup
-rw-rw-r-- 1 si si 4575 May 27 08:00 main.ftl
drwxrwxr-x 3 si si 4096 May 27 08:00 price
drwxrwxr-x 3 si si 4096 May 27 08:00 product
drwxrwxr-x 3 si si 4096 May 27 08:00 promo
drwxrwxr-x 3 si si 4096 May 27 08:00 reviews
drwxrwxr-x 3 si si 4096 May 27 08:00 store
drwxrwxr-x 3 si si 4096 May 27 08:00 thesaurus
drwxrwxr-x 4 si si 4096 May 27 12:21 WEB-INF
Most of the web application's page sections are put into different directories depending on their function. The includes/ directory holds many of the pieces of a web application.
Includes目录是包含一个应用程序的很多页面片。
The WEB-INF directory is a "private" directory for files which should not be viewed directly by visitors. It holds files for controlling the flow logic and actions of this web application:
[si@localhost product]$ ls -l webapp/catalog/WEB-INF/
total 132
drwxrwxr-x 13 si si 4096 May 27 08:00 actions
-rw-rw-r-- 1 si si 117202 May 27 08:00 controller.xml
-rw-rw-r-- 1 si si 4442 May 27 08:00 web.xml
controller.xml is a very important file that directs the flow of the web application. It maps URI requests from the visitor's browser to events, services, and pages.
web.xml contains supplemental information for the web application.
actions/ directory has beanshell scripts that are used to process and gather data for the pages.
The beanshell scripts in the WEB-INF/actions/ directory often mirror the Freemarker pages in the other directories. For example:
[si@localhost product]$ ls -l webapp/catalog/product/
total 240
-rw-rw-r-- 1 si si 6886 May 27 08:00 ApplyFeaturesFromCategory.ftl
-rw-rw-r-- 1 si si 2099 May 27 08:00 CreateVirtualWithVariantsForm.ftl
-rw-rw-r-- 1 si si 16552 May 27 08:00 EditProductAssoc.ftl
-rw-rw-r-- 1 si si 3813 May 27 08:00 EditProductAttributes.ftl
-rw-rw-r-- 1 si si 1407 May 27 08:00 EditProductContentContent.ftl
-rw-rw-r-- 1 si si 14132 May 27 08:00 EditProductContent.ftl
-rw-rw-r-- 1 si si 6126 May 27 08:00 EditProductDupForm.ftl
-rw-rw-r-- 1 si si 4519 May 27 08:00 EditProductFacilities.ftl
-rw-rw-r-- 1 si si 5273 May 27 08:00 EditProductFacilityLocations.ftl
-rw-rw-r-- 1 si si 13625 May 27 08:00 EditProductFeatures.ftl
-rw-rw-r-- 1 si si 5008 May 27 08:00 EditProductGlAccounts.ftl
-rw-rw-r-- 1 si si 4200 May 27 08:00 EditProductGoodIdentifications.ftl
-rw-rw-r-- 1 si si 13207 May 27 08:00 EditProductInventoryItems.ftl
-rw-rw-r-- 1 si si 6358 May 27 08:00 EditProductKeyword.ftl
-rw-rw-r-- 1 si si 23480 May 27 08:00 EditProductQuickAdmin.ftl
-rw-rw-r-- 1 si si 60917 May 27 08:00 ProductForms.xml
-rw-rw-r-- 1 si si 5721 May 27 08:00 ProductTabBar.ftl
-rw-rw-r-- 1 si si 6380 May 27 08:00 QuickAddVariants.ftl
[si@localhost product]$ ls -l webapp/catalog/WEB-INF/actions/product/
total 72
-rw-rw-r-- 1 si si 5862 May 27 08:00 ApplyFeaturesFromCategory.bsh
-rw-rw-r-- 1 si si 2489 May 27 08:00 ApplyFeaturesFromGroup.bsh
-rw-rw-r-- 1 si si 3548 May 27 08:00 EditProductAssoc.bsh
-rw-rw-r-- 1 si si 7490 May 27 08:00 EditProductContent.bsh
-rw-rw-r-- 1 si si 6920 May 27 08:00 EditProductContentContent.bsh
-rw-rw-r-- 1 si si 2574 May 27 08:00 EditProductFeatures.bsh
-rw-rw-r-- 1 si si 11386 May 27 12:27 EditProductInventoryItems.bsh
-rw-rw-r-- 1 si si 17166 May 27 08:00 EditProductQuickAdmin.bsh
-rw-rw-r-- 1 si si 1890 May 27 08:00 QuickAddVariants.bsh
There is not a one-to-one correspondence because the same beanshell script in actions/ can be reused for multiple pages, and also because some pages are pieced together from multiple Freemarker templates but require only one beanshell script.
Finally, there is one more component of an OFBiz application: the widgets/ directory:
[si@localhost product]$ ls -l widget/
total 8
drwxrwxr-x 3 si si 4096 May 27 08:00 catalog
drwxrwxr-x 3 si si 4096 May 27 08:00 facility
As you can see, this mirrors the contents of webapp/ from above. This is not an accident. The widgets/ directory holds "widgets" for rendering user interface screens. OFBiz allows user interface designs to be created as "generic screens" rather than just web pages, so they could be reused eventually for some other platform. The widgets/ directory's contents mirror those of the webapp/, so there are widgets for the catalog/ webapp and the facility/ webapp.
Now let's take a look at what's in a widgets directory:
[si@localhost product]$ ls -l widget/catalog/
total 176
-rwxrwxr-x 1 si si 11824 May 27 08:00 CatalogScreens.xml
-rwxrwxr-x 1 si si 19862 May 27 08:00 CategoryScreens.xml
-rw-rw-r-- 1 si si 9986 May 27 08:00 CommonScreens.xml
-rwxrwxr-x 1 si si 11122 May 27 08:00 ConfigScreens.xml
-rw-rw-r-- 1 si si 10961 May 27 08:00 FeatureScreens.xml
-rwxrwxr-x 1 si si 5937 May 27 08:00 FindScreens.xml
-rw-rw-r-- 1 si si 6695 May 27 08:00 LookupScreens.xml
-rwxrwxr-x 1 si si 4440 May 27 08:00 PriceScreens.xml
-rw-rw-r-- 1 si si 39740 May 27 08:00 ProductScreens.xml
-rwxrwxr-x 1 si si 14900 May 27 08:00 PromoScreens.xml
-rwxrwxr-x 1 si si 3682 May 27 08:00 ReviewScreens.xml
-rwxrwxr-x 1 si si 19802 May 27 08:00 StoreScreens.xml
-rwxrwxr-x 1 si si 3588 May 27 08:00 ThesaurusScreens.xml
What you see are XML definitions for various screens here. The screens tell OFBiz how to create a screen: what pieces of common navigation elements, Freemarker page sections, and actions are required to create a particular page.
Now you've seen how an OFBiz application is put together. Future tutorials will show you how to develop one from scratch and customize an existing one.