stone12345 发表于 2013-1-29 11:55:09

JAVA ADF 运行原理(5)

      Fuctionality全称为GISFunctionality,每个GISResource对应多个GISFunctionality,
由Fuctionality来提供实际功能,我们通过ADF模板生成一个完整的工程,在WEB-INF/functionalities目录下可以看到多个functionality,这些funtionalities将会被注册到web.xml配置文件中,如下:
      <context-param>
    <param-name>javax.faces.CONFIG_FILES</param-name>
    <param-value>
      /WEB-INF/functionalities/aims-functionalities.xml,
      /WEB-INF/functionalities/ags-functionalities.xml,
      /WEB-INF/functionalities/aws-functionalities.xml,
      /WEB-INF/functionalities/wms-functionalities.xml,
      /WEB-INF/functionalities/ejb-functionalities.xml,
      /WEB-INF/functionalities/graphics-functionalities.xml,
      /WEB-INF/ajax-renderers.xml,
      /WEB-INF/context-attributes.xml
    </param-value>
    </context-param>
    其中ags-functionalities.xml,定义了关于GISResource功能的配置信息,文件中定义了多个操作GISResource的基本Functionality,下面给出部分配置信息:
<?xml version="1.0"?>
<!DOCTYPE faces-config PUBLIC "-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.0//EN" "http://java.sun.com/dtd/web-facesconfig_1_0.dtd">
<faces-config>
  <managed-bean>
    <managed-bean-name>agsMap</managed-bean-name>
    <managed-bean-class>com.esri.adf.web.ags.data.AGSMapFunctionality</managed-bean-class>
    <managed-bean-scope>none</managed-bean-scope>
  </managed-bean>
 
  <managed-bean>
    <managed-bean-name>agsGeocode</managed-bean-name>
    <managed-bean-class>com.esri.adf.web.ags.data.AGSGeocodeFunctionality</managed-bean-class>
    <managed-bean-scope>none</managed-bean-scope>
  </managed-bean>
</faces-config>
     我们一直再说,每个GISResource对应多个GISFunctionality,但是到目前为止,还没看到他们之间有任何关联的痕迹,那么GISResource是如何使用GISFunctionality的呢?
     在faces-config.xml文件中,可以看到如下的配置信息:
      <managed-bean>
   <managed-bean-name>ags1</managed-bean-name>
   <managed-bean-class>com.esri.adf.web.ags.data.AGSLocalMapResource</managed-bean-class>
   <managed-bean-scope>none</managed-bean-scope>
   <managed-property>
    <property-name>user</property-name>
    <value>#{agsUser1}</value>
   </managed-property>
   <managed-property>
    <property-name>alias</property-name>
    <value>shanghai</value>
   </managed-property>
   <managed-property>
    <property-name>serverObjectName</property-name>
    <value>shanghai</value>
   </managed-property>
   <managed-property>
    <property-name>hosts</property-name>
    <list-entries>
     <value>localhost</value>
    </list-entries>
   </managed-property>
   <managed-property>
    <property-name>functionalities</property-name>
    <map-entries>
     <map-entry>
      <key>map</key>
      <value>#{agsMap}</value>
     </map-entry>
     <map-entry>
      <key>query</key>
      <value>#{agsQuery}</value>
     </map-entry>
     <map-entry>
      <key>tile</key>
      <value>#{agsTile}</value>
     </map-entry>
     <map-entry>
      <key>overview</key>
      <value>#{agsOverview}</value>
     </map-entry>
     <map-entry>
      <key>toc</key>
      <value>#{agsToc}</value>
     </map-entry>
    </map-entries>
   </managed-property>
  </managed-bean>
  <managed-bean>
   <managed-bean-name>renderer_symbol1</managed-bean-name>
   <managed-bean-class>com.esri.adf.web.data.symbol.WebPictureMarkerSymbol</managed-bean-class>
   <managed-bean-scope>none</managed-bean-scope>
   <managed-property>
    <property-name>fileName</property-name>
    <value>images/maptips/pin-bl-green-20x20.png</value>
   </managed-property>
  </managed-bean>
  <managed-bean>
   <managed-bean-name>renderer1</managed-bean-name>
   <managed-bean-class>com.esri.adf.web.data.renderer.WebSimpleRenderer</managed-bean-class>
   <managed-bean-scope>none</managed-bean-scope>
   <managed-property>
    <property-name>symbol</property-name>
    <value>#{renderer_symbol1}</value>
   </managed-property>
  </managed-bean>
  <managed-bean>
   <managed-bean-name>renderer_symbol2</managed-bean-name>
   <managed-bean-class>com.esri.adf.web.data.symbol.WebPictureMarkerSymbol</managed-bean-class>
   <managed-bean-scope>none</managed-bean-scope>
   <managed-property>
    <property-name>fileName</property-name>
    <value>images/maptips/pin-bl-red-20x20.png</value>
   </managed-property>
  </managed-bean>
  <managed-bean>
   <managed-bean-name>renderer2</managed-bean-name>
   <managed-bean-class>com.esri.adf.web.data.renderer.WebSimpleRenderer</managed-bean-class>
   <managed-bean-scope>none</managed-bean-scope>
   <managed-property>
    <property-name>symbol</property-name>
    <value>#{renderer_symbol2}</value>
   </managed-property>
  </managed-bean>
  <managed-bean>
   <managed-bean-name>layer1</managed-bean-name>
   <managed-bean-class>com.esri.adf.web.data.query.LayerDefinition</managed-bean-class>
   <managed-bean-scope>none</managed-bean-scope>
   <managed-property>
    <property-name>resourceId</property-name>
    <value>ags1</value>
   </managed-property>
   <managed-property>
    <property-name>layerId</property-name>
    <value>0</value>
   </managed-property>
   <managed-property>
    <property-name>calloutTemplate</property-name>
    <value>default</value>
   </managed-property>
   <managed-property>
    <property-name>resultTemplate</property-name>
    <value>default</value>
   </managed-property>
   <managed-property>
    <property-name>renderer</property-name>
    <value>#{renderer1}</value>
   </managed-property>
   <managed-property>
    <property-name>highlightRenderer</property-name>
    <value>#{renderer2}</value>
   </managed-property>
  </managed-bean>
  <managed-bean>
   <managed-bean-name>webappQuery</managed-bean-name>
   <managed-bean-class>com.esri.adf.web.data.query.WebQuery</managed-bean-class>
   <managed-bean-scope>none</managed-bean-scope>
   <managed-property>
    <property-name>layerDefinitions</property-name>
    <list-entries>
     <value>#{layer1}</value>
     <value>#{layer2}</value>
     <value>#{layer3}</value>
     <value>#{layer4}</value>
     <value>#{layer5}</value>
    </list-entries>
   </managed-property>
  </managed-bean>
    看了上面的信息有何感受?
    ------------他妈妈*真长!
    呵呵,没关系,eclipse会帮助我们完成。上面就是关于一个GISResource的配置信息,如果你只对Funtionality感兴趣,那么只需看黑体信息即可,可以看到黑体部分正是在ags-functionalities.xml中定义的 managed-bean-name,我们只需将Bean的name注册到GISResource,该GISResource即具备了该Funtionality的使用权。
     通过GISFunctionality这个接口,我们可以看的更清楚.
     public abstract interface GISFunctionality{
     public abstract void initFunctionality(GISResource paramGISResource);
     public abstract void destroyFunctionality();
     public abstract GISResource getResource();
     }
    在GISResource被初始化的时候,ADF会遍历其所有的GISFunctionality对象并调用其initFunctionality方法,这样返回Functionality就可以被使用了。从这以后,你不但可以从GISResource获得GISFunctionality,也可以从GISFuctionality获得其GISResource。这些都是ADF在后台自动完成的工作。
     当我们自定义Functionality来拓展GISResource的功能时,即采用上面的配置方式,这样我们就可以集中经历去编写自定义的Fuctionality类。下面是一个自定义放大地图5倍的Functionality,摘自arcgis server java adf,如下:
      public class Zoom5Functionality implements GISFunctionality{
          private GISResource resource;
          public void zoomIn5(){
          WebContext webContext = resource.getWebContext();
          webContext.getWebMap().getCurrentExtent().expand(0.2);
          webContext.refresh();
       }
     public void zoomOut5() {
        WebContext webContext = resource.getWebContext();
        webContext.getWebMap().getCurrentExtent().expand(5);
        webContext.refresh();
      }
    public void initFunctionality(GISResource resource){
        this.resource = resource;
     }
    public void destroyFunctionality() {}
       public GISResource getResource() {
       return this.resource;
      }
    }
    public class ZoomInListener implements ActionListener{
       public void processAction(ActionEvent event) throws AbortProcessingException {
       WebContext webContext = WebUtil.getWebContext(event.getComponent());
       GISResource resource = webContext.getResourceById("ags1");
       Zoom5Functionality functionality = (Zoom5Functionality)resource.getFunctionality("zoom5Functionality");
       functionality.zoomIn5();
    }
    }
    前台调用:
 <a:command id="zoomIn"
      defaultImage="images/tasks/maptools/zoomin.png"
      hoverImage="images/tasks/maptools/zoominU.png"
      selectedImage="images/tasks/maptools/zoominD.png"
      clientPostBack="true" >
      <f:actionListener type="wuyf.ZoomInListener"/>
</a:command>
    zoom5Functionality即为注册的Fuctionality,ZoomInListener中黑体部分实现了获取资源并调用其zoom5Functionality方法放大地图5倍的功能。
   
页: [1]
查看完整版本: JAVA ADF 运行原理(5)