WebLogic Integration


com.bea.wlai.client
Class ApplicationView

java.lang.Object
  |
  +--com.bea.wlai.client.ApplicationView

public class ApplicationView
extends java.lang.Object

An ApplicationView represents a subset of business functionality available within a Enterprise Information System (EIS). It accepts requests for service invocation from its client, and invokes the proper system functions within the target EIS. An ApplicationView makes use of connections provided by a resource adapter to communicate with the EIS.

A service is a named business function and is NOT the same as a system function within an EIS. The ApplicationView manages the mapping from service name to system function. Services expose a simple XML-based request/response interface. Services are self-describing in that they can return an IDocumentDefinition object for request and response document types that describe the structure and content required for the document type.

An ApplicationView uses an instance of ApplicationViewRemote which is the remote interface to a stateful session EJB. The session EJB is deployed at WebLogic Server startup, just as any other EJB is. Following this, a second round of deployment occurs which deploys Application Views that have been configured by the user for a particular business purpose. The deployment of an Application View places metadata about the services and events for the Application View into a runtime metadata repository. This repository is currently implemented using JNDI.

The mapping from service to interaction is made possible by this metadata. It includes information about the service's name, and the system function associated with the service. It also stores some (or all) of the data needed to successfully invoke the system function. As a result, the service can require less request data from the invoker of the service, because the ApplicationView can augment the data passed by the invoker with the stored metadata. This is a convenient way to hide the complexity of the underlying system function invocation from the invoker of a service, and comprises much of the power and added value of the ApplicationView.

The following is an example of the use of an ApplicationView...

  // Connect to WebLogic

  Hashtable env = new Hashtable();
  env.put(Context.INITIAL_CONTEXT_FACTORY,
          "weblogic.jndi.WLInitialContextFactory");
  env.put(Context.PROVIDER_URL, "t3://localhost:7001");
  env.put(Context.SECURITY_PRINCIPAL, "bob");
  env.put(Context.SECURITY_CREDENTIALS, "bobspassword");
  
  InitialContext ctx = new InitialContext(env);

  // Create an ApplicationView using a name that has already been
  // deployed into the server we just connected to
 
  ApplicationView appView = new ApplicationView(ctx, "DBMSAppView1");
 
  // Create a request document using the definition stored for this
  // Application View at deployment time.

  IDocumentDefinition rd = appView.getRequestDocumentDefinition();
  IDocument request = rd.createDefaultDocument();

  // Fill in the request with some data.  What you fill in depends on
  // the definition of the request document (i.e. its schema)

  request.setStringInFirst("SomeElement", "SomeData");
  
  // Invoke the service and retrieve the response document

  IDocument response = appView.invokeService("GetSomeData", request);

  // Dump the response document out as XML

  System.out.println("GetSomeData: " + response.toXML());
 
In the example above, it would require that an Application View named 'DBMSAppView1' had been deployed into the server at 'localhost:7001' and that this Application View contained the service named 'GetSomeData'. In addition, the document types for request/response must have been created and stored into the schema repository prior to invoking the service.

It is possible to 'hot deploy' an Application View into a server using the DeploymentManager. Below is an example of the Application View's deployment descriptor for the above example.

The SchemaManager session EJB or the SchemaServlet may be used to add the necessary schemas to the schema repository.

 <?xml version="1.0"?>
 <!DOCTYPE applicationView>
 <applicationView asyncEnabled="true"
                  connectionFactory="com.bea.adapter.dbms.DBMSConnectionFactory1"
                  name="DBMSAppView1">
   <service interactionSpecClass="com.bea.adapter.dbms.cci.InteractionSpecImpl"
            name="GetSomeData"
            requestDocumentType="GetSomeDataRequest"
            responseDocumentType="GetSomeDataResponse">
     <interactionSpecProperty name="sql">select * from DATA</interactionSpecProperty>
     <interactionSpecProperty name="functionName">executeQuery</interactionSpecProperty>
   </service>
 </applicationView>
 
Notice that the Application View deployment descriptor contains information about both the service name (name attribute of applicationView element) and the system function name to invoke for the service (interactionSpecProperty with name attribute equal to 'functionName'). Note also that the deployment descriptor contains the 'missing' metadata needed to invoke the system function that was not specified by the invoker of the service (the sql contained in the interactionSpecProperty element with name equal to 'sql').

This deployment descriptor also requires that a connection factory has been deployed to the JNDI name 'com.bea.adapter.dbms.DBMSConnectionFactory1'. The connection factory is deployed similarly to the Application View and contains the information about the physical instance of the EIS to which connections are to be made.

Author:
Copyright © 2000, 2001 BEA Systems, Inc. All Rights Reserved.
See Also:
SchemaManager

Field Summary
static java.lang.String APP_VIEW_ID_JMS_FIELD
           
 
Constructor Summary
ApplicationView(javax.naming.Context context, QualifiedName appViewName)
          Create a new ApplicationView with the given name, using the existing given InitialContext.
ApplicationView(javax.naming.Context context, java.lang.String appViewNameStr)
           
ApplicationView(java.util.Hashtable props, QualifiedName appViewName)
          Create a new ApplicationView with the given name, and using a new InitialContext obtained using the given Hashtable of properties.
 
Method Summary
 void addEventListener(java.lang.String eventTypeName, EventListener listener)
          Add a listener for events with type given by eventTypeName.
 void addEventListener(java.lang.String eventTypeName, EventListener listener, java.lang.String uniqueID)
          Add a listener for events with type given by eventTypeName.
protected  void checkClosed()
          Throw an exception if this app view instance is already closed.
 void close()
          Free any resources being held by this ApplicationView instance.
protected  void finalize()
          Cleans up this ApplicationView instance when the garbage collector determines this object is no longer needed.
protected  void freeAsync()
          Free any resources allocated for async service processing.
 javax.resource.cci.ConnectionSpec getConnectionSpec()
          Returns the ConnectionSpec being used by the ApplicationView to connect to the EIS.
 EventContext getEventContext()
          Get an EventContext for posting/listening for events on this ApplicationView.
 EventContext getEventContext(boolean release)
          Get an EventContext for posting/listening for events on this ApplicationView, possibly releasing ownership of the EventContext to the caller.
 IEventDefinition getEventDefinition(java.lang.String eventType)
          Get IEventDefinition for the given event type.
 javax.naming.Context getInitialContext()
          Return the InitialContext object representing the connection to the JNDI tree in WLS/WLAI.
 java.lang.String getName()
          Get this ApplicationView's name.
 QualifiedName getQualifiedName()
          Get this ApplicationView's qualified name
 IDocumentDefinition getRequestDocumentDefinition(java.lang.String serviceName)
          Get request DocumentDefinition for the given service.
 IDocumentDefinition getResponseDocumentDefinition(java.lang.String serviceName)
          Get response IDocumentDefinition for the given service.
protected  void initializeAsync()
          Initialize member variables required for performing asynchronous service invocation.
 IDocument invokeService(java.lang.String serviceName, IDocument request)
          Synchronously invoke the service with the given name, using the request document given.
 IDocument invokeService(java.lang.String serviceName, IDocument request, boolean autoCreateResponse)
          Synchronously invoke the service with the given name, using the request document given.
 void invokeService(java.lang.String serviceName, IDocument request, IDocument response)
          Synchronously invoke the service with the given name, using the request and response documents given.
 java.lang.String invokeServiceAsync(java.lang.String serviceName, IDocument request, AsyncServiceResponseListener listener)
          Asynchronously invoke the service with the given name, and notify the given listener when the response is available.
 java.lang.String invokeServiceAsync(java.lang.String serviceName, IDocument request, java.lang.String responseQueueJNDIName, java.util.Map jmsPropertyMap)
          Asynchronously invoke the service with the given name, and place the response on the indicated JMS queue when the response is available.
 boolean isAsyncEnabled()
          Determine if this application view has been set up to allow the user to use the invokeServiceAsync() method.
 java.lang.String[] listEventTypes()
          List the events this ApplicationView is capable of delivering, and thus the events which may be listened for using addEventListener().
 java.lang.String[] listServiceNames()
          List service names deployed for this ApplicationView.
 void postEvent(IEvent event)
          Post the given event to this ApplicationView, thus notifying any listeners listening on this ApplicationView for events with the type of the given event.
 void removeEventListener(java.lang.String eventType, EventListener listener)
          Remove the given listener from the subscription list for events with type given by eventTypeName.
 void setConnectionSpec(javax.resource.cci.ConnectionSpec connectionCriteria)
          Sets the connectionSpec for connections made to the EIS.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

APP_VIEW_ID_JMS_FIELD

public static final java.lang.String APP_VIEW_ID_JMS_FIELD
Constructor Detail

ApplicationView

public ApplicationView(java.util.Hashtable props,
                       QualifiedName appViewName)
                throws javax.naming.NamingException,
                       javax.ejb.CreateException,
                       java.rmi.RemoteException
Create a new ApplicationView with the given name, and using a new InitialContext obtained using the given Hashtable of properties.

Throws:
javax.naming.NamingException - If the attempt to create an InitialContext fails. or the ApplicationViewHome interface cannot be found in JNDI.
javax.ejb.CreateException - If the attempt to create an ApplicationViewRemote interface fails.
java.rmi.RemoteException - If an RMI communication failure occurs.

ApplicationView

public ApplicationView(javax.naming.Context context,
                       java.lang.String appViewNameStr)
                throws javax.naming.NamingException,
                       NamespaceException,
                       javax.ejb.CreateException,
                       java.rmi.RemoteException

ApplicationView

public ApplicationView(javax.naming.Context context,
                       QualifiedName appViewName)
                throws javax.naming.NamingException,
                       javax.ejb.CreateException,
                       java.rmi.RemoteException
Create a new ApplicationView with the given name, using the existing given InitialContext.

Throws:
javax.naming.NamingException - If the ApplicationViewHome interface cannot be found in JNDI.
javax.ejb.CreateException - If the attempt to create an ApplicationViewRemote interface fails.
java.rmi.RemoteException - If an RMI communication failure occurs.
Method Detail

finalize

protected void finalize()
                 throws java.lang.Throwable
Cleans up this ApplicationView instance when the garbage collector determines this object is no longer needed.

Overrides:
finalize in class java.lang.Object

getName

public java.lang.String getName()
Get this ApplicationView's name.

getQualifiedName

public QualifiedName getQualifiedName()
Get this ApplicationView's qualified name

listServiceNames

public java.lang.String[] listServiceNames()
                                    throws ApplicationViewException,
                                           java.rmi.RemoteException
List service names deployed for this ApplicationView.

Throws:
ApplicationViewException - If the appViewName or needed ApplicationView metadata cannot be found.
java.rmi.RemoteException - If an RMI communication failure occurs.

listEventTypes

public java.lang.String[] listEventTypes()
                                  throws ApplicationViewException,
                                         java.rmi.RemoteException
List the events this ApplicationView is capable of delivering, and thus the events which may be listened for using addEventListener().

Throws:
ApplicationViewException - If the appViewName or needed ApplicationView metadata cannot be found.
java.rmi.RemoteException - If an RMI communication failure occurs.
See Also:
addEventListener

getRequestDocumentDefinition

public IDocumentDefinition getRequestDocumentDefinition(java.lang.String serviceName)
                                                 throws ApplicationViewException,
                                                        java.rmi.RemoteException
Get request DocumentDefinition for the given service. If the schema for the document type cannot be found, null is returned.

Throws:
ApplicationViewException - If the schema repository cannot be found; the attempt to transport or manipulate the document type's schema fails; the document type's schema text, as stored in the schema repository, cannot be parsed; there is a read error while reading the document type's schema; the lookup of the document type fails; the creation of a SchemaManager remote interface fails; or the serviceName is not defined for this ApplicationView.
java.rmi.RemoteException - If an RMI communication failure occurs.

getResponseDocumentDefinition

public IDocumentDefinition getResponseDocumentDefinition(java.lang.String serviceName)
                                                  throws ApplicationViewException,
                                                         java.rmi.RemoteException
Get response IDocumentDefinition for the given service. If the schema for the document type cannot be found, null is returned.

Throws:
ApplicationViewException - If the schema repository cannot be found; the attempt to transport or manipulate the document type's schema fails; the document type's schema text, as stored in the schema repository, cannot be parsed; there is a read error while reading the document type's schema; the lookup of the document type fails; the creation of a SchemaManager remote interface fails; or the serviceName is not defined for this ApplicationView.
java.rmi.RemoteException - If an RMI communication failure occurs.

getEventDefinition

public IEventDefinition getEventDefinition(java.lang.String eventType)
                                    throws ApplicationViewException,
                                           java.rmi.RemoteException
Get IEventDefinition for the given event type. If the schema for the event type cannot be found, null is returned.

Throws:
ApplicationViewException - If the schema repository cannot be found; the attempt to transport or manipulate the event type's schema fails; the event type's schema text, as stored in the schema repository, cannot be parsed; or there is a read error while reading the event type's schema.
java.rmi.RemoteException - If an RMI communication failure occurs.

invokeService

public IDocument invokeService(java.lang.String serviceName,
                               IDocument request)
                        throws ApplicationViewException,
                               DocumentException,
                               javax.resource.ResourceException,
                               java.rmi.RemoteException
Synchronously invoke the service with the given name, using the request document given. This method is equivalent to calling invokeService(String, IDocument, boolean) with autoCreateResponse false.

The request document should conform to the document definition given by getRequestDocumentDefinition. The response document will conform to the document definition given by getResponseDocumentDefinition.

Throws:
ApplicationViewException - If the service or other resources needed by this method cannot be found in the metadata for this ApplicationView.
DocumentException - If there is an error processing the request or response document.
javax.resource.ResourceException - If there is an error obtaining a connection from the connection factory, or there is some other adapter related error.
java.rmi.RemoteException - If an RMI communication failure occurs.
See Also:
getRequestDocumentDefinition(String), getResponseDocumentDefinition(String)

invokeService

public IDocument invokeService(java.lang.String serviceName,
                               IDocument request,
                               boolean autoCreateResponse)
                        throws ApplicationViewException,
                               DocumentException,
                               javax.resource.ResourceException,
                               java.rmi.RemoteException
Synchronously invoke the service with the given name, using the request document given. If autoCreateResponse is true, this method will attempt to create a default document according to the response document definition, if possible, and pass this to the underlying Interaction. If auto creation fails, the Interaction is allowed to create the response on its own.

The request document should conform to the document definition given by getRequestDocumentDefinition. The response document will conform to the document definition given by getResponseDocumentDefinition.

Throws:
ApplicationViewException - If the service or other resources needed by this method cannot be found in the metadata for this ApplicationView.
DocumentException - If there is an error processing the request or response document.
javax.resource.ResourceException - If there is an error obtaining a connection from the connection factory, or there is some other adapter related error.
java.rmi.RemoteException - If an RMI communication failure occurs.
See Also:
getRequestDocumentDefinition(String), getResponseDocumentDefinition(String)

invokeService

public void invokeService(java.lang.String serviceName,
                          IDocument request,
                          IDocument response)
                   throws ApplicationViewException,
                          DocumentException,
                          javax.resource.ResourceException,
                          java.rmi.RemoteException
Synchronously invoke the service with the given name, using the request and response documents given. This method may be useful if the response document is expensive to create, and you wish to reuse it for subsequent calls to this method.

The request document should conform to the document definition given by getRequestDocumentDefinition. The response document should conform to the document definition given by getResponseDocumentDefinition.

Throws:
ApplicationViewException - If the service or other resources needed by this method cannot be found in the metadata for this ApplicationView.
DocumentException - If there is an error processing the request or response document.
javax.resource.ResourceException - If there is an error obtaining a connection from the connection factory, or there is some other adapter related error.
java.rmi.RemoteException - If an RMI communication failure occurs.
See Also:
getRequestDocumentDefinition(String), getResponseDocumentDefinition(String)

isAsyncEnabled

public boolean isAsyncEnabled()
                       throws ApplicationViewException,
                              java.rmi.RemoteException
Determine if this application view has been set up to allow the user to use the invokeServiceAsync() method. This value may be controlled by setting the value of the asycEnabled attribute in the application view deployment descriptor.

Throws:
ApplicationViewException - If any non-RMI error occurs.
java.rmi.RemoteException - If an RMI communication failure occurs.

invokeServiceAsync

public java.lang.String invokeServiceAsync(java.lang.String serviceName,
                                           IDocument request,
                                           AsyncServiceResponseListener listener)
                                    throws ApplicationViewException,
                                           java.rmi.RemoteException
Asynchronously invoke the service with the given name, and notify the given listener when the response is available. The return value is the ID assigned to this invocation request by the server. The given listener will be notified when the response is available, and will receive a AsyncServiceResponse object containing the request ID, response document, and other information.

If errors occur during the processing of an asyncronous service request, the error message is stored into the AsyncServiceResponse object. Users should check the hasError() method of the response to determine if an error has occurred before attempting to process the response document.

The request document should conform to the document definition given by getRequestDocumentDefinition. The response document will conform to the document definition given by getResponseDocumentDefinition.

Throws:
ApplicationViewException - if async messaging couldn't be initialized, or request/response async message queues couldn't be found.
java.rmi.RemoteException - If an RMI communication failure occurs.
See Also:
getRequestDocumentDefinition(String), getResponseDocumentDefinition(String), AsyncServiceResponse

invokeServiceAsync

public java.lang.String invokeServiceAsync(java.lang.String serviceName,
                                           IDocument request,
                                           java.lang.String responseQueueJNDIName,
                                           java.util.Map jmsPropertyMap)
                                    throws ApplicationViewException,
                                           java.rmi.RemoteException
Asynchronously invoke the service with the given name, and place the response on the indicated JMS queue when the response is available. The return value is the ID assigned to this invocation request by the server. The given JMS queue will be receive a message when the response is available, and will receive a AsyncServiceResponse object containing the request ID, response document, and other information.

Optionally, the caller can provide a map of JMS property name/value pairs. The name/value pairs must use a String for both name and value. This method will set the desired JMS properties into the async service response message that is posted to the response queue. If this feature is not required, pass jmsPropertyMap null.

If errors occur during the processing of an asyncronous service request, the error message is stored into the AsyncServiceResponse object. Users should check the hasError() method of the response to determine if an error has occurred before attempting to process the response document.

The request document should conform to the document definition given by getRequestDocumentDefinition. The response document will conform to the document definition given by getResponseDocumentDefinition.

Throws:
ApplicationViewException - if async messaging couldn't be initialized, or request/response async message queues couldn't be found.
java.rmi.RemoteException - If an RMI communication failure occurs.
See Also:
getRequestDocumentDefinition(String), getResponseDocumentDefinition(String), AsyncServiceResponse

getEventContext

public EventContext getEventContext()
                             throws ApplicationViewException,
                                    EventContextException
Get an EventContext for posting/listening for events on this ApplicationView. It is recommended that you use the convenience methods addEventListener, removeEventListener, and postEvent instead of this method and the EventContext.

Throws:
ApplicationViewException - If the event destination metadata needed by this method cannot be found.
EventContextException - If the underlying event transport layer cannot be initialized.

getEventContext

public EventContext getEventContext(boolean release)
                             throws ApplicationViewException,
                                    EventContextException
Get an EventContext for posting/listening for events on this ApplicationView, possibly releasing ownership of the EventContext to the caller. It is recommended that you use the convenience methods addEventListener, removeEventListener, and postEvent instead of this method and the EventContext.

Parameters:
release - If true, responsibility for closing the EventContext will be given to the caller. This app view instance will no longer hold a reference to the EventContext.
Throws:
ApplicationViewException - If the event destination metadata needed by this method cannot be found.
EventContextException - If the underlying event transport layer cannot be initialized.

getInitialContext

public javax.naming.Context getInitialContext()
Return the InitialContext object representing the connection to the JNDI tree in WLS/WLAI.

addEventListener

public void addEventListener(java.lang.String eventTypeName,
                             EventListener listener)
                      throws ApplicationViewException,
                             EventContextException
Add a listener for events with type given by eventTypeName. The event type that is being listened for must be present in the list returned by listEventTypes(). Otherwise, no event will ever be delivered to the listener, but no exception is thrown.

Throws:
ApplicationViewException - If the event destination metadata needed by this method cannot be found.
EventContextException - If the underlying event transport layer cannot be initialized.
See Also:
listEventTypes

addEventListener

public void addEventListener(java.lang.String eventTypeName,
                             EventListener listener,
                             java.lang.String uniqueID)
                      throws ApplicationViewException,
                             EventContextException
Add a listener for events with type given by eventTypeName. The event type that is being listened for must be present in the list returned by listEventTypes(). Otherwise, no event will ever be delivered to the listener, but no exception is thrown. Using a non-null uniqueID implies a Durable Listener.

Throws:
ApplicationViewException - If the event destination metadata needed by this method cannot be found.
EventContextException - If the underlying event transport layer cannot be initialized.
See Also:
listEventTypes

removeEventListener

public void removeEventListener(java.lang.String eventType,
                                EventListener listener)
                         throws ApplicationViewException,
                                EventContextException
Remove the given listener from the subscription list for events with type given by eventTypeName.

Throws:
ApplicationViewException - If the event destination metadata needed by this method cannot be found.
EventContextException - If the underlying event transport layer cannot be initialized.

postEvent

public void postEvent(IEvent event)
               throws ApplicationViewException,
                      EventContextException,
                      DocumentException
Post the given event to this ApplicationView, thus notifying any listeners listening on this ApplicationView for events with the type of the given event. Note that any listener that has been added to any ApplicationView object with the name given by getName() will be notified, not just those listeners that have been added to this ApplicationView object.

Throws:
ApplicationViewException - If the event destination metadata needed by this method cannot be found.
EventContextException - If the underlying event transport layer cannot be initialized.
DocumentException - If an error occurs while manipulating the event.

initializeAsync

protected void initializeAsync()
                        throws ApplicationViewException
Initialize member variables required for performing asynchronous service invocation. This initialization is deferred because it is expensive, and is not always needed.

Throws:
ApplicationViewException - If async messaging could not be initialized for any reason.

freeAsync

protected void freeAsync()
                  throws ApplicationViewException
Free any resources allocated for async service processing.

close

public void close()
           throws ApplicationViewException
Free any resources being held by this ApplicationView instance.

checkClosed

protected void checkClosed()
                    throws ApplicationViewException
Throw an exception if this app view instance is already closed.

setConnectionSpec

public void setConnectionSpec(javax.resource.cci.ConnectionSpec connectionCriteria)
Sets the connectionSpec for connections made to the EIS. After the ConnectionSpec is set it will be used to make connections to the EIS when invoking a service. To clear the connection spec, and use the default connection parameters, call this method using null.

getConnectionSpec

public javax.resource.cci.ConnectionSpec getConnectionSpec()
Returns the ConnectionSpec being used by the ApplicationView to connect to the EIS.

WebLogic Integration

WebLogic Integration (WLI)