聊斋志异小故事名字:[中英对照]Liferay架构及所集成的各项技术

来源:百度文库 编辑:中财网 时间:2024/05/09 05:37:37
基本架构
  1. Overview
  2. Portlet API (JSR 168)
  3. Struts and Tiles
  4. Session EJBs, Spring, and Hibernate
  5. SOAP, RMI, and Tunneling
  6. Application Service Provider
  1. Overview

    Users can access the portal from traditional and wireless devices. Developers can access the portal from the exposed APIs via SOAP, RMI, and our custom tunneling classes.
    客户程序可以通过传统的或者无线设备来访问Liferay门户。而开发者能够通过开放的SOAP、RMI以及Liferay提供客户隧道(tunnel)类来实现对门户的访问。


  2. Portlet API (JSR 168)

    Liferay is designed to deploy portlets that adhere to the Portlet API (JSR 168). Many useful portlets are bundled with the portal (Mail, Document Library, Calendar, Message Boards, to name a few) and can be used as examples for adding your own custom portlets.Liferay是专门为符合Portlet API(JSR168)的门户单元设计开发的。而且有许多不错的门户单元附加在Lliferay中,包括邮件、文档库、日历、公告板等,它们也可以作为开发学习时的例子使用。
  3. Struts and Tiles

    All HTTP and WAP requests go through MainServlet which extends the basic Struts ActionServlet. MainServlet processes all requests and ensures that each request is routed to the proper PortletAction. Refer to Struts for a better understanding of how the portal‘s web framework functions.
    Liferay门户通过扩展struts的基本类ActionServlet生成自己的MainServlet类,而所有的HTTP或WAP请求都要提交给这个类来处理,以保证能传递给合适的PortletAction来处理。可能参阅Struts,进一步学习理解WEB架构的实现原理。
    All layout information for the portal is centralized in two files: portal_layout.jsp and portlet_layout.jsp. They can be found in /portal-web/docroot/WEB-INF/html/tiles. Refer to articles about Tiles to get a better understanding of how Tiles works as a layout manager.有关门户所有的页面表现信息都集中在两个文件:portal_layout.jsp和portlet_layout.jsp,他们存放在目录/portal-web/docroot/WEB-INF/html/tiles。要学习Tiles的工作原理,请参阅Tiles相关文档。
  4. Session EJBs, Spring, and Hibernate

    Liferay is no longer dependent on EJBs and can be deployed on a standalone servlet container. All business logic is concentrated inside POJO implementations that are looked up and instantiated by Spring. These implementations can be modified or enhanced via Spring‘s AOP and IOC capabilities.
    Liferay不再依赖于EJB,它完全可以单独装配到一个servlet容器(如:Tomcat,JBoss等)中。而所有的业务逻辑都通过Spring管理的POJO来实现。这样的实现利益于Spring的AOP各IOC特性。
    The enterprise release of the portal wraps the POJO implementations with Session EJBs to provide heavy scaling and transaction support required by large sites. The professional release of the portal calls the POJO implementations directly to provide a light weight facade.
    但在POJO的实现方法上Liferay的两个版本有所不同,企业版(enterprise)中通过EJB从而为大站点提供了高扩展性各良好的事务支持能力(如集群),而专业版(professiona)直接通过轻量级的接口完成。
    All data is persisted using Hibernate and is called through the POJO implementations. Liferay used to rely on CMP technology to achieve persistence, but switched over to Hibernate because of its raw speed and flexibility. Liferay is database agnostic and can run on a variety of popular databases.
    所有的业务数据都通过Hibernate来实现并通过POJO来调用。Liferay曾经使用CMP技术.来实现持久层,但后来因速度及灵活性等原因改用Hibernate。在数据库方面,Liferay也完全兼容大多数主流类型DB。
    Liferay uses JAAS Web security so that when a user logs in, their principal is propogated to the Servlet and EJB tiers. Remote Session EJBs can take advantage of this by checking security and permissions at the EJB level so it does not have be duplicated else where. Local Session EJBs exposes business logic to other Session EJBs and does not specifically check for security since they cannot be called remotely. Principals are also propagated to POJO implementations that are the base classes for Remote Session EJBs.
    Liferay使用JAAS来完成用户认证安全管理,好处是当一个用户登录后,它的安全属性可以在Servlet和EJB层中沿用,真正作到系统级的SSO。具体讲,远程EJB可以沿用安全检查及权限属性,本地的EJB是为其它EJB提供业务逻辑服务的,不能被远程调用所以也不必做此类检查;安全原则也派生到POJO实现中,而这此实现其实是远程EJB的基础类。
    The enterprise release uses Session EJBs which allows the deployer to separate the Web server, EJB server, and database server to achieve clustering at three levels. This is true n-tier deploying because no one is forced to cluster at any single layer and allows the most flexibility for large companies.
    企业版式使用EJB,所以系统分别可以在WEB服务器、EJB服务器、数据库服务器三层中实现集群。当然在n层的系统中,集群也保持优势,而且在每一层都并不强迫使用集群,这些都为大企业应用提供了极好的弹性选择权。
    Most of our EJBs, HBMs, and Models are generated through the ant task build-ejb which reads the file ejb.xml in /portal-ejb. Each portlet that persist data has its own ejb.xml (do a search in /portal-ejb and you will get a list back). We copy this file to /portal-ejb when we want to generate the persistence classes for that portlet. This is an internal tool that is built on top of the XDoclet engine.
    系统中的EJB、HBM、以及模式Model者是ant执行build-ejb任务时,通过读取目录/portal-ejb下的ejb.xml文件,然后自动生成的。每个有持久层对象的门户单元(portlet)都有自己的ejb.xml文件(可以在/portal-ejb下搜索得到清单)。当需要生成持久层的类时,就把文件复制到/portal-ejb下,这生成工具是建立在XDoclet之上的。
    For example, upon reading ejb.xml found in the Bookmarks portlet, the following model classes are generated. Each model class reflects a table in the database. Never edit BookmarksEntryModel. Do edit BookmarksEntry to add hand massaged code. BookmarksEntry is generated once and extends BookmarksEntryModel. This allows us the ease of generated code and flexibility of hand massaged code.
    例如:通过读取Bookmarks门户单元的ejb.xml文件配置后,自动生成下列的模式类。每个类对应数据库中的一个表。永远不要手工修改BookmarksEntryModel类,而要通过修改BookmarksEntry,然后再更新BookmarksEntryModel内容。这样做的好处是减少了直接写代码的工作,而只做相应的标记工作。
    com.liferay.portlet.bookmarks.model.BookmarksEntry
    com.liferay.portlet.bookmarks.model.BookmarksEntryModel
    com.liferay.portlet.bookmarks.model.BookmarksFolder
    com.liferay.portlet.bookmarks.model.BookmarksFolderModel

    Hibernate classes are generated that map to the model classes. This allows for an n-tier architecture for cases where your model classes are marshalled across the wire and your Hibernate classes are not.
    Hibernate类是根据模式(model)类对应生成的。这样就可以在多层系统中允许模式类是可作序列化处理的,而Hibernate类则不必。
    com.liferay.portlet.bookmarks.ejb.BookmarksEntryHBM
    com.liferay.portlet.bookmarks.ejb.BookmarksFolderHBM

    Persistence methods to add, update, delete, find, remove, and count the Hibernate entries are generated as the default persistence mechaninsm.
    持久层的方法如:add, update, delete, find, remove, 以及count,系统都默认自动生成。
    com.liferay.portlet.bookmarks.ejb.BookmarksEntryPersistence
    com.liferay.portlet.bookmarks.ejb.BookmarksFolderPersistence

    Helper classes are generated that call the persistence methods. By default, the helper classes call the Hibernate persistence methods to update the database. You can override this in portal.properties and set your own persistence class as long as it extends the default persistence class. This means you can customize where you store your data. It can be a traditional database, a LDAP server, or even something else.
    也生成了专门的协助类(Helper classes),可以用来调用持久层方法。默认时,协助类调用Hibernate的方法来对数据库进行更新操作,但是也可以改写portal.properties中的配置,使用自己专用的类来完成,但这种类要求要继承默认的持久层类。换言之,用户完全可以定制自己的持久层数据,可以是一个正统的数据库,或者是LDAP服务器,其它什么的。
    com.liferay.portlet.bookmarks.ejb.BookmarksEntryUtil
    com.liferay.portlet.bookmarks.ejb.BookmarksFolderUtil

    Pooling classes are also created to minimize object creation. Behavior can be modified in portal.properties.
    为了减少对象生成的成本,引入了对象池,可以通过修改portal.properties文件来控制池的基本动作。
    com.liferay.portlet.bookmarks.ejb.BookmarksEntryPool
    com.liferay.portlet.bookmarks.ejb.BookmarksFolderPool

    POJO implementations that extend PrincipalBean are generated to hold business logic that check the caller principal and can be called remotely. Calling getUserId() returns the user id of the current user. Calling getUser() returns the User model that represents the current user. The Session EJB that extends the POJO implementation implements PrincipalSessionBean.
    用来实现业务逻辑的POJO类,通过继承PrincipalBean类,来实现有关调用者的方法,所以可以远程调用。如:调用getUserId()可以得到当前用户的ID;调用getUser()则返回当前用户的对象。EJB再继承这类POJO,实现远程调用。
    For example, these classes allow you to delete a bookmark entry or folder if and only if you are the creator of that entry or folder.
    例如:下面的类实现了,允许当且公当bookmark项目或目录的生成者可以删除它。这些对象只有在不存在时才可能被创建。
    These classes are only generated once if they do not already exist.

    com.liferay.portlet.bookmarks.ejb.BookmarksEntryManagerImpl
    com.liferay.portlet.bookmarks.ejb.BookmarksFolderManagerImpl

    Helper classes are generated based on the POJO implementations. They help save developer time and prevent polluted code. Instead of writing many lines of code just to look up the appropriate Session EJB wrapper or POJO implementation, you simply call BookmarksEntryManagerUtil.addEntry to call the equivalent method in BookmarksEntryManagerImpl.addEntry.
    协助类(Helper classes)是在POJO的实现基础上生成的。它可以节约开发者的工作,不必书写很多行的代码,而只要简单的找到合适的EJB wrapper或POJO实现,通过调用BookmarksEntryManagerUtil.addEntry来间接调用相应的BookmarksEntryManagerImpl.addEntry方法就可以了。
    BookmarksEntryManagerUtil calls BookmarksFolderManagerFactory to look up the class that implements BookmarksEntryManager. BookmarksFolderManagerFactory defers to Spring and settings in portal.properties on whether to load the Session EJB wrapper or the plain POJO implementation. The Session EJB extends the POJO implementation.
    BookmarksEntryManagerUtil通过调用BookmarksFolderManagerFactory来查找实现BookmarksEntryManager的类。也正是通过BookmarksFolderManagerFactory来识别Spring和portal.properties中的配置来决定要是载入EJB wrapper还是POJO实现。
    com.liferay.portlet.bookmarks.ejb.BookmarksEntryManager
    com.liferay.portlet.bookmarks.ejb.BookmarksEntryManagerEJB
    com.liferay.portlet.bookmarks.ejb.BookmarksEntryManagerEJBImpl
    com.liferay.portlet.bookmarks.ejb.BookmarksEntryManagerFactory
    com.liferay.portlet.bookmarks.ejb.BookmarksEntryManagerHome
    com.liferay.portlet.bookmarks.ejb.BookmarksEntryManagerUtil
    com.liferay.portlet.bookmarks.ejb.BookmarksFolderManager
    com.liferay.portlet.bookmarks.ejb.BookmarksFolderManagerEJB
    com.liferay.portlet.bookmarks.ejb.BookmarksFolderManagerEJBImpl
    com.liferay.portlet.bookmarks.ejb.BookmarksFolderManagerFactory
    com.liferay.portlet.bookmarks.ejb.BookmarksFolderManagerHome
    com.liferay.portlet.bookmarks.ejb.BookmarksFolderManagerUtil

    Tunneling classes are generated so that developers can call the POJO implementations over port 80. An example of this given in the section V of this document.
    隧道类(Tunneling classes)是用来实现通过80端口来调用POJO的。在本文档的第V部分有一个例子。
    com.liferay.portlet.bookmarks.ejb.BookmarksEntryManagerHttp
    com.liferay.portlet.bookmarks.ejb.BookmarksFolderManagerHttp

    Soap classes are generated so that developers can call the POJO implementations over port 80. Soap is slower than tunneling because tunneling streams requests in binary format. Soap is more flexible than tunneling because the client classes are not limited to Java.
    Soap类也是用来实现通过80端口来调用POJO的。虽然与隧道类相比Soap类在速度上要差一点,原因是隧道类使用二进制数据流。但Soap类用灵活,可以适用各种客户端(不局限于Java)。
    com.liferay.portlet.bookmarks.ejb.BookmarksEntryManagerSoap
    com.liferay.portlet.bookmarks.ejb.BookmarksFolderManagerSoap

    POJO implementations classes that do not extend PrincipalBean are generated to hold business logic that do not check the caller principal and can be called locally. These classes exist so that business logic can be easily integrated with other projects.
    当地的POJO为类实现,并不继承PrincipalBean类,实现业务逻辑时也不检验调用者的身份。这种类使得可以更容易地与其它的项目集成。
    These classes are only generated once if they do not already exist.
    这些类只有在检验到不存在时才会被创建。
    com.liferay.portlet.bookmarks.ejb.BookmarksEntryLocalManagerImpl
    com.liferay.portlet.bookmarks.ejb.BookmarksFolderLocalManagerImpl

    Helper classes are also generated.
    同时协助类也生成了。
    com.liferay.portlet.bookmarks.ejb.BookmarksEntryLocalManager
    com.liferay.portlet.bookmarks.ejb.BookmarksEntryLocalManagerEJB
    com.liferay.portlet.bookmarks.ejb.BookmarksEntryLocalManagerEJBImpl
    com.liferay.portlet.bookmarks.ejb.BookmarksEntryLocalManagerFactory
    com.liferay.portlet.bookmarks.ejb.BookmarksEntryLocalManagerHome
    com.liferay.portlet.bookmarks.ejb.BookmarksEntryLocalManagerUtil
    com.liferay.portlet.bookmarks.ejb.BookmarksFolderLocalManager
    com.liferay.portlet.bookmarks.ejb.BookmarksFolderLocalManagerEJB
    com.liferay.portlet.bookmarks.ejb.BookmarksFolderLocalManagerEJBImpl
    com.liferay.portlet.bookmarks.ejb.BookmarksFolderLocalManagerFactory
    com.liferay.portlet.bookmarks.ejb.BookmarksFolderLocalManagerHome
    com.liferay.portlet.bookmarks.ejb.BookmarksFolderLocalManagerUtil

    Some of our users needed to call the Local Manager classes remotely, so Remote Manager classes that parallel their Local counterparts are also generated.
    但总有一些用户需要调用引种当地类,于是完全相对应的远程类也应用而生了。
    com.liferay.portlet.bookmarks.ejb.BookmarksEntryRemoteManager
    com.liferay.portlet.bookmarks.ejb.BookmarksEntryRemoteManagerEJB
    com.liferay.portlet.bookmarks.ejb.BookmarksEntryRemoteManagerEJBImpl
    com.liferay.portlet.bookmarks.ejb.BookmarksEntryRemoteManagerFactory
    com.liferay.portlet.bookmarks.ejb.BookmarksEntryRemoteManagerHome
    com.liferay.portlet.bookmarks.ejb.BookmarksEntryRemoteManagerUtil
    com.liferay.portlet.bookmarks.ejb.BookmarksFolderRemoteManager
    com.liferay.portlet.bookmarks.ejb.BookmarksFolderRemoteManagerEJB
    com.liferay.portlet.bookmarks.ejb.BookmarksFolderRemoteManagerEJBImpl
    com.liferay.portlet.bookmarks.ejb.BookmarksFolderRemoteManagerFactory
    com.liferay.portlet.bookmarks.ejb.BookmarksFolderRemoteManagerHome
    com.liferay.portlet.bookmarks.ejb.BookmarksFolderRemoteManagerUtil

    A lot of people stay away from Session EJBs because they are heavy and require a lot of coding. Our build scripts show that you can leverage the advantages of Session EJBs while minimizing repetitive labor so that you can strike a good balance between effort and results.
    许多人避免使用EJB,因为它的重量级,需要大量的代码工作。Liferay的自动生成脚本可以使得,既不损失EJB的优点,而且还最小化重复的代码等工作,从而你可以在努力与结果之间找到一个良好的平衡点。
    Spring gives Liferay additional flexibility. Developers can test their POJO implementations with Liferay Portal Professional in a servlet container and deploy to production with Liferay Portal Enterprise in an application server.Spring也给Liferay带来了更多的好处。开发者既可以利用专业版在一个servlet容器中测试POJO的实现,也可以通过企业版在应用服务器上装载要上线的产品。
  5. SOAP, RMI, and Tunneling

    All of our remote POJO implementations are exposed to the external world via SOAP, RMI, and our custom tunneling classes.
    通过SOAP, RMI, 以及我们客户化的隧道类等途径,所有的远程POJO实现都向外开放。
    We do not do this simply because Web services is a buzz word, but because we find it extremely useful for integration. The following is an example of a company that leveraged these resources.
    之所以这么做,并不仅仅是因为网络服务要应用于商务,而是根本上我们发现这样做对集成来说简直是太有用了。以下就有一个得益于此的企业集成案例。
    3sixteen is a t-shirt company that needed to get up and running fast. They saw Liferay and wanted to use the integrated Shopping portlet. However, they thought that Liferay was too ugly for a t-shirt company that prided itself on being at the cutting edge of fashion. To solve this problem, they decided to separate their web presence into two sites: a brochure site and shopping site.
    3sixteen是一个做服装T恤的公司,需要扩大发展。他们注意到了Liferay有意用之来集成一个商业门户。但是,他们又感觉在一个超前时尚的服务行业Liferay似乎显得有点太丑了,或者说不入格。为了解决这个矛盾,他们不得以把WEB表现层分成了两个站点:一个产品展示站点和一个在线购买站点。
    www.3sixteen.com became the pretty site built in Flash and my.3sixteen.com became the shopping site using the vanilla Liferay distribution. These two sites are hosted on two different Linux machines and for all intents and purposes could have resided on different continents.
    结果,www.3sixteen.com成了一个基于Flash技术的漂亮站点,而my.3sixteen.com则是一个基于Liferay的vanilla版本的在线购物站点。这两个站点分别安装在不同的两个Linux主机上,基于目标及用途的考虑可以布署在不同的国家。
    They also needed to build a mailing list to collect email addresses for all their interested customers. To accomplish this, they added a JSP pop up box on their Flash site that would tell the portal server to add the email address to a contact in the Address Book portlet.
    项目的一个重要需求是要建立一个邮件地址管理系统,用来收集目标客户的邮件地址。于是,在Flash作的站点中我们加入了弹出工窗口,用来通过门户服务器要增加记录某客户的这个邮件地址到系统中。
    The following is a JSP snippet that shows how the guys at 3sixteen leveraged ABContactManagerHttp to add a contact.
    以下是相应的JSP片段,它利用ABContactManagerHttp的功能来增加新的联系人。
    String URL = "http://my.3sixteen.com";

    HttpPrincipal httpPrincipal = new HttpPrincipal(URL, "joe_bloggs", "password");

    ABContactManagerHttp.addContact(httpPrincipal, firstName, lastName, emailAddress);
    ABContactManagerHttp invoked addContact in ABContactManagerUtil. The invokation was sent over port 80 and received by http://my.3sixteen.com/tunnel/servlet/AuthTunnelServlet. The application server made sure the authentication matched and then processed ABContactManagerUtil as if the user with the id joe_bloggs was calling addContact. ABContactManagerUtil then called ABContactManagerImpl to do the actual work. You can trace the logic of this by viewing the source included in the generated JavaDocs.
    ABContactManagerHttp调用了ABContactManagerUtil中的addContact方法,而重要的是这个调用是通过80端口,直接由门户站点的http://my.3sixteen.com/tunnel/servlet/AuthTunnelServlet接收,应用服务器只要判定认证合法之后,就以ID是joe_bloggs的用户的身份调用addContact方法,然后由ABContactManagerUtil调用实现类ABContactManagerImpl来完成真正的添加联系人的工作。这一过程可能通过查自动生成的JavaDocs文档中的源代码来证实。
    Now Joe Bloggs can log into the portal and look in his Address Book portlet to see that he has a new contact. All of the included portlets have this capability because these helper classses are generated. This means you can write applets or any other Java application to access the Session EJBs that contain your business logic. This can be a security hazard if someone had your password, so you can configure to limit the Tunnel Servlet to only listen on certain ports by editing portal.properties.
    之后呢,那个Joe Bloggs就可以登录门户,通过查看它的地址本发现多了一个新的联系人了。而且在系统的其它门户单元也可以通过协助类(helper classses)达到同样的目的。而另外一方面这也可能是一个安全隐患,因为随便一个人就可以通过一个小JAVA(applets)或其它程序,从而直接调用有业务逻辑功能的EJB,只要他拥有认证的密码。一个应对的方法是通过修改portal.properties来只指定特定的端口侦听这类服务请求。
    You can also access the Session EJBs over SOAP and RMI. We will post more examples of that shortly.当然也可以通过SOAT或RMI等来调用EJB,案例将在后续的工作中加入。
  6. Application Service Provider

    Liferay was built from the ground up to be used by application service providers. The following is a sample list of portals running off of one portal instance hitting one database and shows the capabilities of Liferay.
    Liferay是一个自下而上完整的应用系统提供者。以下是案例清单,它们都是单一门户单一数据库系统。
    http://demo.liferay.net
    http://my.ccuc.net
    http://my.3sixteen.com
    http://portal.liferay.com
    http://www.gatewayfriends.org
    http://www.jasonandiris.com

    Users in each of these portals have no information about the other portals. They are separated by domain and each portal exists in its own space based on the company‘s id.
    其中每个门户的用户都与其它门户完全隔离,门户间是依据各自的公司ID通过域来分割不同的空间。
    See Multiple Portals for detailed informaton on how to set up multiple instances of Liferay on one machine.
    如果对在同一机器集成多个Liferay有兴趣,请参阅Multiple Portals。