SCA_Spring规范(全部翻译完)

 
1 Spring 客户程序与实现模型
1.1 、目标
SCA Spring的Java客户程序与实现模型指定了Spring框架是如何在SCA中使用的。目标如下:
粗粒度的集成:与Spring的集成将是在SCA 构件(composite)层的,在SCA构件层中,Spring application context提供了完整的构件,该构件通过SCA来暴露服务和使用引用。这意味着Spring application context定义了构件实现的内部结构。
启始于SCA Component Type:可以使用Spring来实现任意的使用WSDL或Java接口来定义服务的SCA构件。当然可能会用到某些SCA规范的扩展。
       启始于Spring context:可以从任意Spring context生成任意的SCA 构件,并可以在SCA装配集中使用该构件。
1.2 、将 Spring Application Context 作为构件的实现
Spring Application context能用于实现某个Spring构件组件。概念上来说,可能如下所描述:
       图1的上部阐述了由两个构件组成的简单的SCA域,这两个构件都是由Spring application context来实现的。
       在该图中,有由独立的Spring Application Context定义的两个构件,每个构件都有一个声明的服务。Composite A由两个Spring bean组成,bean X是通过一个SCA服务暴露给SCA。Bean Y拥有一个对外部SCA服务的引用。该服务引用被连线于另一个Spring context,Composite B。该构件有单个声明性服务入口,该服务入口被连线于Bean Z。
       使用Spring作为实现的组件不需要引入SCA元数据到Spring配置中就可以连线SCA的服务和引用。Spring context对SCA环境知晓得非常少。所有的策略强制性都发生于SCA运行时的实现中,并不会进入到Spring的空间中。
图2
       图2展示了SCA运行时与Spring context交互的两点:服务和引用。任意的策略强制性都是由SCA运行时在最终消息到达目标Spring bean之前,调用进入Spring application context的时候来完成的。在来自applicaction context的向外部的调用时,由SCA运行时提供的引用提供了策略强制性。
1.2.1 Spring configuration 中直接使用 SCA 引用
       寄宿于SCA运行时,并实现了构件的Spring application context创建一个parent application context。在该parent application context中,所有的SCA引用都作为bean来定义。注意,该bean使用SCA引用名作为bean的名字。这些bean在child context(也称为用户应用)中都自动可见。
       如下的spring configuration为上述图1中表达的Spring application context A提供了模型。在本例中,有两个Spring bean,X和Y。名为”X”的bean是从SCA进入Spring context的入口点,Spring bean Y包含了一个由SCA提供的服务的引用。
<beans>
<bean id="X" class="org.xyz.someapp.SomeClass">
<property name="foo" ref="Y"/>
</bean>
<bean id="Y" class"org.xyz.someapp.SomeOtherClass">
<property name="bar" ref="SCAReference"/>
</bean>
</beans>
定义了两个bean。名为”X”的bean包含了一个名为”foo”的属性域,引用到上下文中的第二个bean,名字为”Y”。bean “Y”也有一个名为”bar”的属性域,引用到SCA服务的引用,名为”SCAReference”。
       SCA SCDL包含了带有相应绑定信息的Spring构件的服务和引用的定义。
<composite name="BazComposite">
<component name="SpringComponent">
<implementation.spring location=".."/>
<service name="X"/>
<reference name="SCAReference" .../> <!-- binding info specified -->
</component>
</composite>
       这里唯一与Spring相关的就是<implementation.spring>元素。该元素的location属性指定了一个archive文件或包含了Spring application context文件的目录的目标URI地址。用于创建application context的Spring application context配置文件的资源路径按如下方式被标识:
       如果被location属性标识的资源是一个archive文件,那么将读取archive文件的META-INF/MANIFEST.MF文件。如果location URI所标识的是一个目录,那么在该目录下必须存在MET-INF/MANIFEST.MF文件。如果manifest文件包含以下形式的头部信息:
       Spring-Context ::=path(‘;’ path)*
这里的path是location URI的相对路径,那么在头部中指定的path集合就用来标识context configuration文件。如果没有MANIFEST.MF文件或在manifest文件中没有Spring-Context的头部信息,那么默认将使用在META-INF/spring目录下所有*.xml文件来构建application context。
       <implementation.spring>使用的每个<service>元素在其name属性中都应该包含被暴露为SCA服务的Spring bean的名字。所以,对于Spring,服务的name属性起来两个作用:它标识一个Spring bean,并且其命名组件的服务。SCDL也包含了名为”SCAReference”的<reference>元素。该引用名变成为一个可寻址Spring application context的名称。所以,这种情况下,”SCAReference”才能在上面的Spring configuration中被bean “Y”引用。
        SCA运行时负责设置引用并将以这些引用在spring context中的标识名作为bean暴露出来。这些工作一般都是通过创建一个parent context来完成的,而该parent context有相应被定义的bean,并且实现提供的上下文将变成该parent context的child context。所以引用—如”SCAReference” ,被bean “Y”用于其”bar”属性对上下文有效。
1.2.2 Spring cofiguration 中与 SCA 相关 bean 的显式声明
       也可以在Spring configuration中显式声明与SCA相关bean来代理SCA引用。当继承在parent context中由SCA运行时创建的bean定义时,在child context中以相同的名字定义的bean将覆盖它。这么做的主要原因是这样可以让Spring容器来修饰bean(比如,使用Spring AOP)。
       通过使用Spring SCA命名空间支持来声明某个到SCA服务的引用。
       比如,要声明描述了引用到SCA reference(名为”SCAReference”,在2.2.1中讨论了)的bean,你应该声明如下:
       <sca:reference name="SCAReference" type="com.xyz.SomeType/>
       Spring SCA命名空间支持提供一共三个元素。它们是:
       <sca:reference> 该元素定义了描述了某个SCA service的Spring bean。注意:此处的SCA service是在Spring application context的外部。
       <sca:property> 该元素定义了描述了某个SCA component的property。该property配置了Spring composite。
       <sca:service> 该元素定义了Spring composite暴露为service的bean。它的功能就是为Spring composite提供组件类型信息。特别地,SCA运行时负责创建相应的绑定(binding),并应用必须的策略到那些基于SCDL配置的服务上。如果<sca:service>入口没有在parent SCDL中配置,那么SCA运行时必须抛出configuration error。如果在Spring application context中没有<sca:service>元素指定,那么任意的bean都可以暴露为service。
       以下案例展示了一个application context。该应用上下文暴露出一个服务,SCAService,并显式地为SCA reference定义了一个bean,SCAReference。bean Y 的”goo”属性配置为名为”sca-property-name”的SCA Property。
<beans>
<!-- this definition is not required, and the bean SCAReference could also
have been inherited from the parent context -->
<sca:reference name=”SCAReference” type="com.xyz.SomeType"/>
<bean name="X">
<property name="foo" ref="Y"/>
</bean>
<bean name="Y">
<property name="bar" ref="SCAReference"/>
<property name="goo" ref="sca-property-name"/>
</bean>
<!-- expose an SCA property named “sca-property-name” -->
<sca:property name="sca-property-name" type="java.lang.String"/>
<!-- expose the bean "X" as an sca service named "SCAService" -->
<sca:service name="SCAService" type="org.xyz.someapp.SomeInterface" target="X"/>
</beans>
2. 附录
2.1. Spring SCA Namespace schema
<? xml version = "1.0" encoding = "UTF-8" ?>
< xsd:schema xmlns = "http://www.springframework.org/schema/sca"
    xmlns:xsd = "http://www.w3.org/2001/XMLSchema"
    attributeFormDefault = "unqualified" elementFormDefault = "qualified"
    targetNamespace = "http://www.springframework.org/schema/sca" >
 
    < xsd:element name = "composite" >
       < xsd:complexType >
           < xsd:attribute name = "component" use = "required" >
              < xsd:simpleType >
                  < xsd:restriction base = "xsd:string" />
              </ xsd:simpleType >
           </ xsd:attribute >
           < xsd:attribute name = "sca-adapter-class" use = "optional" >
              < xsd:simpleType >
                  < xsd:restriction base = "xsd:string" />
              </ xsd:simpleType >
           </ xsd:attribute >
       </ xsd:complexType >
    </ xsd:element >
    < xsd:element name = "reference" >
       < xsd:complexType >
           < xsd:attribute name = "name" use = "required" >
              < xsd:simpleType >
                  < xsd:restriction base = "xsd:string" />
              </ xsd:simpleType >
           </ xsd:attribute >
           < xsd:attribute name = "type" use = "required" >
              < xsd:simpleType >
                  < xsd:restriction base = "xsd:string" />
              </ xsd:simpleType >
           </ xsd:attribute >
           < xsd:attribute name = "default" use = "optional" >
              < xsd:simpleType >
                  < xsd:restriction base = "xsd:string" />
              </ xsd:simpleType >
           </ xsd:attribute >
       </ xsd:complexType >
    </ xsd:element >
    < xsd:element name = "property" >
       < xsd:complexType >
           < xsd:attribute name = "id" use = "optional" >
              < xsd:simpleType >
                  < xsd:restriction base = "xsd:string" />
              </ xsd:simpleType >
           </ xsd:attribute >
           < xsd:attribute name = "name" use = "required" >
              < xsd:simpleType >
                  < xsd:restriction base = "xsd:string" />
              </ xsd:simpleType >
           </ xsd:attribute >
           < xsd:attribute name = "type" use = "required" >
              < xsd:simpleType >
                  < xsd:restriction base = "xsd:string" />
              </ xsd:simpleType >
           </ xsd:attribute >
       </ xsd:complexType >
    </ xsd:element >
    < xsd:element name = "service" >
       < xsd:complexType >
           < xsd:attribute name = "name" use = "required" >
              < xsd:simpleType >
                  < xsd:restriction base = "xsd:string" />
              </ xsd:simpleType >
           </ xsd:attribute >
           < xsd:attribute name = "type" use = "required" >
              < xsd:simpleType >
                  < xsd:restriction base = "xsd:string" />
              </ xsd:simpleType >
           </ xsd:attribute >
           < xsd:attribute name = "target" use = "required" >
              < xsd:simpleType >
                  < xsd:restriction base = "xsd:string" />
              </ xsd:simpleType >
           </ xsd:attribute >
       </ xsd:complexType >
    </ xsd:element >
</ xsd:schema >
2.2. 参考资料
[1] Spring Framework
http://static.springframework.org/spring/docs/2.0.x/reference/index.html
 
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值