thinkmap.server
Class DataSourceContext

java.lang.Object
  extended by thinkmap.server.DataSourceContext
All Implemented Interfaces:
IThinkmapContext, JSONSerializable, IMonitoredResource

public class DataSourceContext
extends Object
implements IThinkmapContext, IMonitoredResource, JSONSerializable

This class wraps a DataSource and implements the server side of the RemoteDataSource. This class can instantiate the datasource that it uses by reading from an XML file that is located at the URI passed to the constructor.

The DataSource wrapper lazily constructs and configures the datasource (i.e. on the first request).

The stream format to use for parsing the incoming stream is normally determined dynamically by reading the "Stream-Format-Class" HTTP header which the remote datasource sends with every request. if no stream format header is sent, the DataSourceServlet will fall back to the default format, which can be specified using the "default-format" initialization parameter. Stream formats are normally negotiated between the client and the server, and the default is only used as a last resort if the server cannot negotiate a protocol. The default format is the BinaryStreamFormat.

This class will only serve Thinkmap clients via the HTTP POST method.

Version:
$Revision: 1.16.2.1 $

Nested Class Summary
protected  class DataSourceContext.ServletStreamFactory
           
 
Field Summary
static int INITIALIZING
           
static int OFFLINE
           
static int OFFLINE_ERROR
           
static int ONLINE
           
static int STOPPING
           
 
Fields inherited from interface thinkmap.context.IThinkmapContext
errorLevelNames, MSG_ERROR, MSG_FATAL, MSG_INFO, MSG_WARNING
 
Fields inherited from interface thinkmap.server.rmon.IMonitoredResource
RESOURCE_MODIFIED, RESOURCE_REMOVED, RESOURCE_UNMODIFIED
 
Constructor Summary
DataSourceContext(DataSourceServlet servlet, String uri)
          Constructs a DataSourceWrapper using the provided DataSourceServlet and reading from the configuration file located at the provided URI.
 
Method Summary
 void addContextListener(IContextListener l)
          Add a listener to this context.
 void clearMessages()
           
protected  void doBinary(HttpServletRequest request, HttpServletResponse response)
           
 Object evalExternal(String code)
          Evaluate the given code in the external envorinment.
 ThinkmapServerApplication getApplication()
          Get the underlying ThinkmapServerApplication.
 Object getAttribute(String s)
          Returns an object defined by the container in an application specific way.
 IDataSource getDataSource()
          Get the datasource that is served by this servlet.
 long getErrorCount()
           
 long getHits()
           
 DataSourceIndex getIndex()
           
 MessageLog getMessages()
           
 int getModificationStatus()
          This method is called by the DataSourceServlet to determine if the configuration file that created this wrapper has been modified.
 String getParameter(String name)
          Returns the value of an initialization parameter that was specified to the container.
 DataSourceServlet getServlet()
          Returns a reference to the DataSourceServlet that is serving this DataSourceWrapper.
 String getStatus()
           
 int getStatusCode()
           
 String getType()
           
 String getURI()
           
 boolean isStarted()
           
protected  boolean processRequest(HttpServletRequest request, InputStream is, IStreamReader sr, StreamWriter sw)
           
 void removeContextListener(IContextListener l)
          Remove a listener from this context.
 void reportError(int level, String message, Throwable e)
          Report an error for the application / applet to display to the user.
 void resetStatistics()
          Reset the statistics.
 void restart()
           
protected  void service(HttpServletRequest request, HttpServletResponse response)
           
 void showDocument(String url, String frame)
          Open the document at the given URL in the given frame.
 void start()
           
 void stop()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

OFFLINE

public static final int OFFLINE
See Also:
Constant Field Values

INITIALIZING

public static final int INITIALIZING
See Also:
Constant Field Values

ONLINE

public static final int ONLINE
See Also:
Constant Field Values

STOPPING

public static final int STOPPING
See Also:
Constant Field Values

OFFLINE_ERROR

public static final int OFFLINE_ERROR
See Also:
Constant Field Values
Constructor Detail

DataSourceContext

public DataSourceContext(DataSourceServlet servlet,
                         String uri)
                  throws MalformedURLException,
                         FileNotFoundException
Constructs a DataSourceWrapper using the provided DataSourceServlet and reading from the configuration file located at the provided URI.

Parameters:
servlet - a reference to the DataSourceServlet
uri - the uri of the configuration file
Throws:
MalformedURLException - if the uri is malformed
FileNotFoundException - if the uri does not exist
Method Detail

getType

public String getType()

getURI

public String getURI()

addContextListener

public void addContextListener(IContextListener l)
Description copied from interface: IThinkmapContext
Add a listener to this context.

Specified by:
addContextListener in interface IThinkmapContext
Parameters:
l - the listener to add

removeContextListener

public void removeContextListener(IContextListener l)
Description copied from interface: IThinkmapContext
Remove a listener from this context.

Specified by:
removeContextListener in interface IThinkmapContext
Parameters:
l - the listener to remove

getParameter

public String getParameter(String name)
Description copied from interface: IThinkmapContext
Returns the value of an initialization parameter that was specified to the container. For applets, this maps directly to the Applet.getParameter() method. For servlets, this maps to the ServletContext.getInitParameter() merthod. Applications may implement this method in a implementation specific way (for example they may provide access to command line options).

Specified by:
getParameter in interface IThinkmapContext
Parameters:
name - the name of the parameter to get
Returns:
the value of that parameter, or null if it does not exist.

getAttribute

public Object getAttribute(String s)
Description copied from interface: IThinkmapContext
Returns an object defined by the container in an application specific way. Components should preferably use the above methods to access resources in a container-independent way. This method is here as a last resort, so that custom plugins and datasources can get access to container data.

Specified by:
getAttribute in interface IThinkmapContext
Returns:
the value of that attribute, or null if it does not exist.

showDocument

public void showDocument(String url,
                         String frame)
                  throws IOException
Description copied from interface: IThinkmapContext
Open the document at the given URL in the given frame. If this context is not running inside a browser or is unable to display a document, this method will throw an IOException. The url passed can either be relative or absolute. Relative URLs will be resolved relative to the document base (if this is an applet).

Specified by:
showDocument in interface IThinkmapContext
Parameters:
url - the URL of the document to show
frame - the name of the frame to populate with the document
Throws:
IOException - if this context is not running inside a browser or is unable to display a document

evalExternal

public Object evalExternal(String code)
                    throws Exception
Description copied from interface: IThinkmapContext
Evaluate the given code in the external envorinment. Usually, this would be a piece of JavaScript code that would be passed to the browser for evaluation.

Specified by:
evalExternal in interface IThinkmapContext
Parameters:
code - the code to execute in the external environment
Throws:
Exception - if there was an error, or if this context does not support external evaluation.

getModificationStatus

@JSONTransient
public int getModificationStatus()
This method is called by the DataSourceServlet to determine if the configuration file that created this wrapper has been modified.

Specified by:
getModificationStatus in interface IMonitoredResource
Returns:
true if the configuration file that created this wrapper has been modified.

getServlet

@JSONTransient
public DataSourceServlet getServlet()
Returns a reference to the DataSourceServlet that is serving this DataSourceWrapper.

Returns:
a reference to the DataSourceServlet that is serving this DataSourceWrapper

getDataSource

@JSONTransient
public IDataSource getDataSource()
Get the datasource that is served by this servlet.

Returns:
underlying datasource

getApplication

@JSONTransient
public ThinkmapServerApplication getApplication()
Get the underlying ThinkmapServerApplication.

Returns:

getHits

public long getHits()

getErrorCount

public long getErrorCount()

getIndex

public DataSourceIndex getIndex()

resetStatistics

public void resetStatistics()
Reset the statistics. Has no effect if statistics are not being collected.


getMessages

public MessageLog getMessages()

clearMessages

public void clearMessages()

start

public void start()
           throws Exception
Throws:
Exception

stop

public void stop()

restart

public void restart()
             throws Exception
Throws:
Exception

isStarted

public boolean isStarted()

getStatus

public String getStatus()

getStatusCode

public int getStatusCode()

service

protected void service(HttpServletRequest request,
                       HttpServletResponse response)
                throws ServletException,
                       IOException
Throws:
ServletException
IOException

doBinary

protected void doBinary(HttpServletRequest request,
                        HttpServletResponse response)
                 throws ServletException,
                        IOException
Throws:
ServletException
IOException

processRequest

protected boolean processRequest(HttpServletRequest request,
                                 InputStream is,
                                 IStreamReader sr,
                                 StreamWriter sw)
                          throws IOException
Throws:
IOException

reportError

public void reportError(int level,
                        String message,
                        Throwable e)
Description copied from interface: IThinkmapContext
Report an error for the application / applet to display to the user.

Specified by:
reportError in interface IThinkmapContext
Parameters:
level - the warning level of the error being reported
message - a human readable message describing the error
e - the Throwable that caused the error (may be null)


Copyright © 2013 Thinkmap, Inc. All Rights Reserved.