转: pentaho源码分析

转自: http://blog.csdn.net/wengyupeng/archive/2008/07/16/2659662.aspx

Pentaho 项目主要分三个部分:

ü         pentaho 引擎(这部分以后基本很少变动)

ü         pentaho-solution( 解决方案,也就是以后根据不同的需求重点建设的部分 )

ü         pentaho-style (这是一个独立的应用,专职负责显示的样式)

Pentaho 首页研究笔记( Home.jsp

 

首页的模板是 ${ solution-path }/system/custom/template-home.html

采取模板页面的好处使得显示的样式和显示的内容分开,在 pentaho 中专门负责显示样式是专门的

1.      首先初始化 PentahoSession, PentahoSession HttpSession 进行了一次封装。

2.         根据 PentahoSystem 的工具方法 getUITemplater(IPentahoSession session) 获得模板核心接口 IUITemplater IUITemplater 经常用到,配置在 pentaho.xml 文件中,在整个 global 域内缓存)

3.         模板核心类 UIUtil IUITemplater 的实现)借助 breakTemplate( "template-home.html" , "" , userSession ) 方法,获得 ${ solution-path }/system/custom/template-home.html 文件,并将该文件转化成字符串。并将模板按照 {content} 为分界线一分为二,分别为 intro footer

 

 

 

 


Pentaho 关键接口及其类研究

1.         IPentahoSession

封装 HttpSession PortletSession ,除了提供这些 Session 的常用方法之外,还提供了如下的方法:

u       getLocale() 获得 session Locale 对象

u       isAuthenticated() 判断当前 session 是否被认证

u       setAuthenticated(String name) 设置 session 的名字,并且表明该 session 是被认证的,如果是 HTTP 或者 Portlet session name 应该是登陆的用户名 (request.getRemoteUser())

u       setNotAuthenticated() 设置登陆的 session 为未授权

u       setBackgroundExecutionAlert()

u       getBackgroundExexutionAlert() 检验后台执行任务的状态,如果后台的执行触发了一个警告( alert )则返回 true

u       resetBackgroundExecutuionAlert()

 

 

2.         ISolutionEngine

一个 request 有一个 solution engine, 处理一个或多个 action sequences

u       setParameterProvider(String name,IParameterProvider parameterProvider)       设置输入参数的源

u       public IRuntimeContext execute()   IRuntimeContext 执行 action sequence (有三个 execute 方法)

u        public void setlistener(IActionCompleteListener listener) 设置 action 完成的监听器, action 完成后将被监听器监听

u        public void setSession(IPentahoSession session) 设置 solution engine session

u        public IRuntimeContext getExecutionContext() 返回执行的运行环境

u        int Status() 返回执行的当前状态

u        public void init(IPentahoSession session) 初始化 SolutionEngine ,对象被构造之后(或者 solution engines 以不同的方式重用的时候)立即执行该方法

u        public void setForcePrompt( boolean forcePrompt)  设置强制执行 promp page

u        public void setParameterXsl(String xsl) 为当前的 component 设置 xsl 文件用于生成 parameter page parameter 的路径必须是以“ / ”开始的,从 solution 根开始的完整路径,或者是当前的 action sequence 的相对路径

 

 

3.         IRuntimeContext

该接口定义了一些方法和常量,用于在 action execution 的过程中解析参数,输入,输出,资源和持久化运行时数据,

u       public int executeSequence(IActionCompleteListener listener, boolean async) 执行 action sequence

u       public static Map createComponentClassMap() 静态方法中维护了组件名和组件类的对应关系

 

4.         ISequenceDefinition

  SequenceDefinition 表示包含有一个 ActionSequence 对象的定义,是 action sequence 文档运行是对象。(对应 .xaction 配置文件),一个 SequenceDefinition 可以包含一个到多个 ActionDefinition ,流程会自动一个接着一个 ActionDefinition 执行。

result-type 包括“ none report rule process

public Map getInputDefinitions() 获得定义文件中定义的输入参数

public Map getInputDefinitionsForParameterProvider(String parameterProviderName) 获得为特定 paramerer provider 定义的输入参数。如果输入参数名为 ”REGION” 可能来自 request 域的 regn 参数,则调用该方法,并将 request 作为 parameterProviderName 传递进去

  public Map getOutputDefinitions() 获得定义文件中的输出参数

  public Map getResourceDefinitions() 获得定义文件中的资源

public String getSequenceName() 获得 action sequence 文件的名称

public String getResultType() 返回执行 action sequence 文件中 action 的返回结果类型

 

 

 


Pentaho 解决方案运行的过程

1.         PentahoSystem.systemEntryPoint()

2.         获得 IPentahoSession

3.         如果不需要在后台运行 ( doBackgroundExecution(request, response, userSession) ) ,则执行下面的工作,否则直接跳转到最后一步

4.         初始化 OutPutStream

5.         pentaho.xml 配置的作用域中获得 ISolutionRepository ,并进行初始化

6.         request 的访问参数中获得 solution,path,action ISolutionRepository 根据 solution,path,action 获得 IActionSequence

7.         如果 actionSequence 存在 title 属性则走第 9 步,否则执行第 8

8.        

9.         初始化 HttpOutputHandler

10.     初始化 HttpMimeTypeListener

11.     HttpOutputHandler 中注册 HttpMimeTypeListener 监听器

12.     初始化 SimpleUrlFactory

13.     初始化 IParameterProvider

14.     setupOutputHandler(outputHandler, requestParameters);

15.     如果 handleSubscriptions 为假,则初始化 HttpServletRequestHandler handleActionRequest

16.     PentahoSystem.systemExitPoint ()

 

15 步的分解

初始化 IRuntimeContext

           获得 ISolutionEngine, 并进行初始化, ISolutionEngine 执行 execute 获得 IRuntimeContext


Pentho 运行过程

SolutionContextListener 监听 ServletContext 初始化(在 public void contextInitialized(ServletContextEvent event) 方法中 )后依次:

²        根据 web.xml 文件设置编码格式;

²        根据 web.xml 文件设置 text-direction

²        根据 web.xml 文件设置国际化信息

²        获得 solutionPath                                    

²        获得 base-url

²        根据 solutionPath base-url 等信息实例化 IApplicationContext 对象

²        servletContext 内的 initParameter 拷贝到 applicationContext 对象中。

²        如果 web.xml 文件中配置了 pentaho-system-cfg ,则用该值设置 System SYSTEM_CFG_PATH_KEY 值( SYSTEM_CFG_PATH_KEY LiberatedSystemSettings 类用来决定系统的配置文件,一般为 pentaho.xml , 如果没有配置 pentaho-system-cfg 则用默认的。

²        初始化 PentahoSystem( PentahoSystem.init (applicationContext) )

²        提示 Pentaho 是否初始化成功

 

初始化 PentahoSystem 的过程

Ø         applicationContext 中获得 solutionPath 并设置到 System properties 中( System.setProperty ( "pentaho.solutionpath" , propertyPath)

Ø         初始化 SystemSettings (子类 PathBasedSystemSettings

Ø         通过 pentaho.xml 文件的 acl-files 标签设置 ACL 文件后缀

Ø         设置缓存管理器,并方到 PentahoSystem globalObjectsMap

Ø         根据 pentaho.xml 文件的 xml-factories 结点初始化 xmlFactory ,否则用默认的 XMLFactory

Ø         检验 pentaho.xml 文件中配置的 audit 类是否存在

Ø         初始化 StandaloneSession

Ø         to guarantee hostnames in SSL mode are not being spoofed

Ø         根据 pentaho.xml 文件中配置的 publishers 初始化 PentahoSystem publishers

Ø         根据 pentaho.xml 文件初始化 PentahoSystem listerers

Ø         根据 pentaho.xml 文件初始化 session 中需要创建的 action 列表,


Action Sequence

Action Sequence XML

1 、定义 input

Action Sequence 文档可以识别三种类型的参数: inputs,outputs,resources .inputs outputs 是一种特定类型( string,property-map 等)的变量, resources inputs 很像,但是有特定的 mimie type path 。而且 Resources 也没有默认值。 Resources 典型的表示数据量比较大的,比如报表定义( report definition )或图片。

参数可以从 runtime,request,session,global default 五种途径获得

Ø         Runtime 参数:存储在 RuntimeContext 内的参数

Ø         Request 参数:在 URL 中以 name-value 对的形式的参数

Ø         Session 参数:用户 Session 中的参数,每个用户的值不一样

Ø         Global  参数:和 session 中的参数类似,但是所有的用户是公用的

Ø         Default 参数:在 Action Sequence 文档中定义的,只有前四个地方获取不了的情况下,才用 Default 参数值

例如:

<inputs>

    <region type= "string" >

        <sources>

            <request> REGION </request>

            <runtime> aRegion </runtime>

        </sources>

        <default-value> Central </default-value>

    </region>

</inputs>

例子中显示在执行的过程中,Action Sequence 文档需要一个名为region ( 大小写敏感 ) 的参数,RuntimeContext 首先从request 域中查找时候有名为REGION 的参数(URL 中以REGION=xxx ),如果找到了则将xxx 赋给region 如果找不到,再从runtimeContext 域中找是否有名为aRegion 值,如果再 RuntimeContext 中还没有找到,则最后将默认值Central 赋给region

注意:

ü         RuntimeContext Action Sequence 文档 sources 的先后顺序赋值,最后是 default-value ,如果赋值不成功,则 Action Sequence 会抛出错误并且返回;

ü         有两个隐形参数 instance-id solution-id ,不用声明和配置,对 inputs 或者 outputs 都是可见的

2 、数据类型( Data Types

Pentaho BI 平台目前支持的类型

ü         content 组件内数据量大的数据 ,例如 reporting 组件生成的 PDF 文件, content 可以是任何类型,而且内部是字节流的形式,所以没有 default-value

ü         long  Java Long 对象

ü         property-map-list map 组成的 list ,而且 map 内是 Java String 类型的值

ü         property-map  Java String 类型组成的 map

ü         string 标准的 Java String

ü         string-list Java String 对象组成的 list

3 、资源类型( resources type

ü         file 系统内的绝对路径 ,

<file>

    <location> D:\samples\reporting\MyReport.rptdesign </location>

    <mime-type> text/xml </mime-type>

</file>

ü         solution-file  ${solution-path}/system 目录的相对路径

<solution-file>

    <location>MyReport.rptdesign</location>

    <mime-type>text/xml</mime-type>

</solution-file>

ü         url

<file>

    <location>http://www.myserver.com/logo.png</location>

    <mime-type>image/png</mime-type>

</file>

4 Actions

Action Sequence 文档是描述文件, RuntimeContext 提供运行环境, Component 是商业逻辑,一个 Component 执行一个独立的功能。 Component 有两个主要的职责:校验执行 ,校验是检验 inputs resources 是否有效,执行就是实际操作。

Action Sequence 文档中 action-definition 结点描述了组件应该有那些功能,并且存放组件执行是需要的 inputs,outputs 以及其他的配置信息。

4 1Action-inputs

action-inputs action-resoueces 定义组件执行时需要的参数,组件所必须的参数如果在运行时获取不了,则会出现运行时错误。有多种方法给运行时参数赋值, name 赋值, mapping 赋值,常量硬编码,有时可以靠提示输入

4 2 Action-outputs

action-outputs 定义被保存在 RuntimeContext 内的变量,当该组件执行完毕之后,该组件的 action-outputs 对于其他的组件是可见的,而且可以做为其他组件的 action-inputs.

5 XML Schema

·    < action-sequence> REQUIRED 根结点

o   <name> NOT REQUIRED – Action Sequence 文件名称,如 example.xaction

o   <version> NOT USED – 文档版本

o   <title> NOT REQUIRED – 文档比较好记的名字,用于显示

o   </span

猜你喜欢

转载自zhzhiqun2005.iteye.com/blog/935596