com.esri.adf.web.data
Class GISResource

java.lang.Object
  extended by com.esri.adf.web.data.GISResource
All Implemented Interfaces:
WebContextInitialize, WebLifecycle, Serializable
Direct Known Subclasses:
AGSGeocodeResource, AGSGeometryResource, AGSGPResource, AGSImageResource, AGSMapResource, AIMSMapResource, GraphicsResource, VEResource, WMSMapResource

public class GISResource
extends Object
implements WebLifecycle, WebContextInitialize, Serializable

The GISResource is the base class that all resources supported by the ADF must extend. Out of the box resources such as AGSMapResource, AGSGeocodeResource, AIMSMapResource, etc. all extend this class.

The GISResource also maintains a java.util.Map of named GISFunctionalitys supported by this instance of the resource. Users can add a functionality programmatically as such:

 AGSMapResource ags1 = ...;
 <b>ags1.addFunctionality("map", new AGSMapFunctionality());</b>
 

It can also be added declaratively in JSF managed bean configuration files as such:

 <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>ags1</managed-bean-name>
   <managed-bean-class>com.esri.adf.web.ags.data.AGSMapResource</managed-bean-class>
   <managed-bean-scope>none</managed-bean-scope>
   ...
   <managed-property>
     <property-name>functionalities</property-name>
     ...
     <map-entries>
       <map-entry>
         <key>map</key>
         <value>#{agsMap}</value>
       </map-entry>
     </map-entries>
   </managed-property>
 </managed-bean>
 

This class implements callback methods declared in the WebContextInitialize and WebLifecycle interfaces which get called at different phases of the ADF lifeycle. Please refer to the documentation for these two interfaces for more detail. Sub-classes that want to do custom work in addition to the work done by this class must do so by overriding the callbacks and making the super calls appropriately. Here's a typical way to override the callback methods:

 public class MyGISResource extends GISResource {
   ..
   public void init(WebContext context) {
     myInit();
     super.init(context);
   }
 
   public void destroy() {
     myDestroy();
     super.destroy();
   }
 
   public void activate() {
     super.activate();
     myActivate();
   }
 
   public void passivate() {
     myPassivate();
     super.passivate();
   }
   ..
 }
 

The basic premise is that you want the super-class to initialize and activate itself first before you do your custom initialization and activation. And you want to do your custom cleanup (destroy) and passivation before letting the super-class cleanup and passivate itself.

See Also:
Serialized Form

Field Summary
protected  String alias
          A reader friendly name for this resource
protected  WebContext context
           The WebContext that maintains a reference to this resource
protected  WebSpatialReference defaultSpatialReference
           The spatial reference associated with this resource.
protected  Map<String,GISFunctionality> functionalities
          A named java.util.Map of GISFunctionalitys supported by this instance of the resource.
protected  boolean hasFailedFunctionalities
           
protected  boolean init
          true if this resource has already been initialized
 
Constructor Summary
GISResource()
           
 
Method Summary
 void activate()
           This method is called by the associated WebContext when the context itself is being activated.
 void addFunctionality(String name, GISFunctionality functionality)
           Adds the given functionality to the existing Map of functionalities.
 void destroy()
           The cleanup (final) chores of the resource like releasing held resources must be performed in this method.
 String getAlias()
           Returns a reader friendly name for this resource.
 WebSpatialReference getDefaultSpatialReference()
           Returns the spatial reference associated with this resource.
 Map<String,GISFunctionality> getFunctionalities()
           Returns the java.util.Map of named GISFunctionalitys maintained by this resource.
 GISFunctionality getFunctionality(String name)
           Returns the GISFunctionality maintained by this resource and referenced by the given name.
 WebContext getWebContext()
           Returns the WebContext that maintains a reference to this resource.
 void init(WebContext webContext)
           This method is called by the WebContext to initialize the resource.
 void passivate()
           This method is called by the associated WebContext when the context itself is being passivated.
 void setAlias(String alias)
           Sets a reader friendly name for this resource.
 void setFunctionalities(Map<String,? extends GISFunctionality> functionalities)
           Sets the java.util.Map of named GISFunctionalitys maintained by this resource.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

context

protected WebContext context

The WebContext that maintains a reference to this resource


functionalities

protected Map<String,GISFunctionality> functionalities
A named java.util.Map of GISFunctionalitys supported by this instance of the resource.


hasFailedFunctionalities

protected boolean hasFailedFunctionalities

init

protected boolean init
true if this resource has already been initialized


alias

protected String alias
A reader friendly name for this resource


defaultSpatialReference

protected WebSpatialReference defaultSpatialReference

The spatial reference associated with this resource.

Resources should set this property in their respective init(WebContext) methods.

Typically when geometries are passed to the GISFunctionalitys, they should be in the default spatial reference of their resource. However, the functionalities themselves should also ensure that they are working with geometries in the correct spatial reference. Or else they should use the project() method on the WebGeometry to project it to the correct spatial reference before working on it.

Also, MapFunctionalitys should ensure that they export the map in the spatial reference of the WebMap if set.

Constructor Detail

GISResource

public GISResource()
Method Detail

getAlias

public String getAlias()

Returns a reader friendly name for this resource.

It is a good practice for users to explicitly set an alias when the resource is created programmatically or declaratively. Resource providers should provide an auto-generated alias anyway in case users don't explicitly set an alias themselves.

Returns:
a reader friendly name for this resource

setAlias

public void setAlias(String alias)

Sets a reader friendly name for this resource.

It is a good practice for users to explicitly set an alias when the resource is created programmatically or declaratively. Resource providers should provide an auto-generated alias anyway in case users don't explicitly set an alias themselves.

Parameters:
alias - a reader friendly name for this resource

init

public void init(WebContext webContext)

This method is called by the WebContext to initialize the resource. This is typically called when the context itself is initialized or when users add a new resource to the context by using the WebContext.addResource(String, GISResource) method. A GISResource is usable only after this method has been called.

This method iterates through all its supported GISFunctionalitys and calls the GISFunctionality.initFunctionality(GISResource) on them all.

Sub-classes that want to do custom initialization should override this method and make the super call first before doing the custom stuff:

 public void init(WebContext context) {
   super.init(context);
   myInit();
 }
 

Specified by:
init in interface WebContextInitialize
Parameters:
webContext - the WebContext that maintains a reference to this resource
See Also:
WebContextInitialize.init(com.esri.adf.web.data.WebContext), GISFunctionality.initFunctionality(GISResource), WebContext.init(WebContext), WebContext.addResource(String, GISResource)

destroy

public void destroy()

The cleanup (final) chores of the resource like releasing held resources must be performed in this method. This is typically called when the context itself is being destroyed or when users remove this resource from the context by using the WebContext.removeResource(GISResource) method. A GISResource is unusable after this method has been called.

This method iterates through all its supported GISFunctionalitys and calls the GISFunctionality.destroyFunctionality() on them all.

Sub-classes that want to do custom cleanup chores should override this method and do the custom cleanup first before making the super call:

 public void destroy() {
   myDestroy();
   super.destroy();
 }
 

Specified by:
destroy in interface WebContextInitialize
See Also:
WebContextInitialize.destroy(), GISFunctionality.destroyFunctionality(), WebContext.destroy(), WebContext.removeResource(GISResource)

activate

public void activate()

This method is called by the associated WebContext when the context itself is being activated. This typically happens when a new user request is received to perform a set of operations. A GISResource is available for the execution of these operations only after this method has been called.

This method iterates through all its supported GISFunctionalitys and calls the activate() method on those functionalities that implement WebLifecycle.

Sub-classes that want to do custom activation should override this method and make the super call first before doing the custom stuff:

 public void activate() {
   super.activate();
   myActivate();
 }
 

Specified by:
activate in interface WebLifecycle
See Also:
WebLifecycle.activate(), WebContext.activate()

passivate

public void passivate()

This method is called by the associated WebContext when the context itself is being passivated. This typically happens after a user request to perform a set of operations has been serviced. A GISResource is unavailable for the execution of more operations after this method has been called.

This method iterates through all its supported GISFunctionalitys and calls the passivate() method on those functionalities that implement WebLifecycle.

Sub-classes that want to do custom passivation should override this method and do the custom passivation first before making the super call:

 public void passivate() {
   myPassivate();
   super.passivate();
 }
 

Specified by:
passivate in interface WebLifecycle
See Also:
WebLifecycle.passivate(), WebContext.passivate()

getFunctionality

public GISFunctionality getFunctionality(String name)

Returns the GISFunctionality maintained by this resource and referenced by the given name.

Parameters:
name - the name of the GISFunctionality to return
Returns:
the GISFunctionality maintained by this resource and referenced by the given name

getFunctionalities

public Map<String,GISFunctionality> getFunctionalities()

Returns the java.util.Map of named GISFunctionalitys maintained by this resource.

Returns:
the java.util.Map of named GISFunctionalitys maintained by this resource

setFunctionalities

public void setFunctionalities(Map<String,? extends GISFunctionality> functionalities)

Sets the java.util.Map of named GISFunctionalitys maintained by this resource.

Typically this java.util.Map is set either declaratively in a JSF managed bean configuration file or programmatically before this resource is initialized. Once the resource has been initialized, you should use the addFunctionality(String, GISFunctionality) method instead.

Parameters:
functionalities - the java.util.Map of named GISFunctionalitys maintained by this resource
See Also:
addFunctionality(String, GISFunctionality)

addFunctionality

public void addFunctionality(String name,
                             GISFunctionality functionality)

Adds the given functionality to the existing Map of functionalities.

If the resource is already initialized, it also calls the initFunctionality(this) method on this functionality and passes it a reference to itself. If a functionality with the same name already exists, it logs a warning message and replaces the existing functionality with this new functionality.

Parameters:
name - the name of the GISFunctionality
functionality - the GISFunctionality to add to this resource

getWebContext

public WebContext getWebContext()

Returns the WebContext that maintains a reference to this resource.

Returns:
the WebContext that maintains a reference to this resource

getDefaultSpatialReference

public WebSpatialReference getDefaultSpatialReference()

Returns the spatial reference associated with this resource.

Resources should set this property in their respective init(WebContext) methods.

Typically when geometries are passed to the GISFunctionalitys, they should be in the default spatial reference of their resource. However, the functionalities themselves should also ensure that they are working with geometries in the correct spatial reference. Or else they should use the project() method on the WebGeometry to project it to the correct spatial reference before working on it.

Also, MapFunctionalitys should ensure that they export the map in the spatial reference of the WebMap if set.

Returns:
the spatial reference associated with this resource