org.openptk.connection
Class Connection

java.lang.Object
  extended by org.openptk.api.Element
      extended by org.openptk.connection.Connection
All Implemented Interfaces:
ElementIF, ConnectionIF
Direct Known Subclasses:
JerseyConnection

public abstract class Connection
extends Element
implements ConnectionIF

Author:
Scott Fehrman, Sun Microsystems, Inc.

Nested Class Summary
 
Nested classes/interfaces inherited from interface org.openptk.connection.ConnectionIF
ConnectionIF.Session
 
Field Summary
protected  ConverterIF _converter
           
protected  java.lang.String _uriClients
           
protected  java.lang.String _uriContexts
           
protected  java.lang.String _uriLogin
           
protected  java.lang.String _uriLogout
           
protected  java.lang.String _uriSessionInfo
           
protected  java.lang.String _uriSubjects
           
 
Fields inherited from interface org.openptk.connection.ConnectionIF
PARAM_CLIENTCRED, PARAM_CLIENTID, PARAM_PASSWORD, PARAM_TOKEN, PARAM_USER, PROP_COOKIE_NAME, PROP_URI_CLIENTS, PROP_URI_CONTEXTS, PROP_URI_LOGIN, PROP_URI_LOGOUT, RESOURCE_SESSION
 
Constructor Summary
Connection(java.util.Properties props)
          Create a new instance.
 
Method Summary
 void close()
          Close the open connection.
protected  void debug(java.lang.String str)
           
protected  StructureIF decode(java.lang.String str)
          Convert the "encoded" string to a StructureIF object.
protected  Output doCreate(Input input)
          Execute CREATE operation.
protected  Output doDelete(Input input)
          Execute DELETE operation.
protected  Output doPwdChange(Input input)
          Execute PWDCHANGE operation.
protected  Output doPwdForgot(Input input)
          Execute PWDFORGOT operation.
protected  Output doPwdReset(Input input)
          Execute PWDRESET operation.
protected  Output doRead(Input input)
          Execute READ operation.
protected  Output doSearch(Input input)
          Execute SEARCH operation.
protected  Output doUpdate(Input input)
          Execute UPDATE operation.
protected  java.lang.String encode(StructureIF struct)
          Convert the StructureIF object to an "encoded" string.
protected  java.lang.String encrypt(java.lang.String value)
          Encrypt the provided String.
 Output execute(Opcode opcode, Input input)
          Execute the operation (Opcode) on the Server.
 java.lang.String getContextId()
          Gets the id of the current Context.
 java.lang.String[] getContextIds()
          Get all of the available Context Ids.
abstract  java.lang.String getSessionData(ConnectionIF.Session session)
          Get the String representing a Session data item.
protected  java.lang.String getSessionId()
          Get the Session Id.
protected  StructureIF getStructureFromAttribute(AttributeIF attr)
          Create a StructureIF object from the AttributeIF object.
protected  StructureIF getStructureFromInput(Opcode opcode, Input input)
          Create a StructureIF object from the Input object.
protected  void handleError(java.lang.String msg)
          Handle an error condition.
 boolean hasSessionChanged()
          Has the Session changed from the initial connection.
 boolean isDebug()
          Get the debug flag.
protected  void logError(java.lang.String str)
           
protected  void logInfo(java.lang.String str)
           
protected  void logWarning(java.lang.String str)
           
protected  void processClientStructure(StructureIF structClient)
          Process the Client Structure that comes from the server.
 void setContextId(java.lang.String contextId)
          Set the "current" Context Id.
 void setDebug(boolean debug)
          Set the debug flag.
protected  void setSessionChanged(boolean bool)
           
protected  void setSessionId(java.lang.String str)
           
protected  void updateOutputFromReadStructure(Output output, StructureIF structResponse)
          Update the StructureIF from the Read response (Structure).
protected  void updateOutputFromSearchStructure(Output output, StructureIF structResponse)
          Update Output from the Search response (Structure).
protected  java.lang.String urlDecode(java.lang.String str)
          URL Decode a string.
protected  java.lang.String urlEncode(java.lang.String str)
          URL Encode a string.
 
Methods inherited from class org.openptk.api.Element
addAttribute, addAttribute, addAttribute, addAttribute, addAttribute, addAttribute, addAttribute, addAttribute, addAttribute, addAttribute, addAttribute, addAttribute, addAttribute, addAttribute, addAttributes, copy, getAttribute, getAttributeNames, getAttributes, getAttributesSize, getDescription, getKey, getProperties, getPropertiesSize, getProperty, getState, getStateAsString, getStatus, getUniqueId, getUniqueIdType, isError, removeAttribute, removeProperty, setAttributes, setDescription, setError, setKey, setProperties, setProperty, setState, setStatus, setUniqueId, setUniqueId, setUniqueId, setUniqueId, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.openptk.api.ElementIF
addAttribute, addAttribute, addAttribute, addAttribute, addAttribute, addAttribute, addAttribute, addAttribute, addAttribute, addAttribute, addAttribute, addAttribute, addAttribute, addAttribute, addAttributes, copy, getAttribute, getAttributeNames, getAttributes, getAttributesSize, getDescription, getKey, getProperties, getPropertiesSize, getProperty, getState, getStateAsString, getStatus, getUniqueId, getUniqueIdType, isError, removeAttribute, removeProperty, setAttributes, setDescription, setError, setKey, setProperties, setProperty, setState, setStatus, setUniqueId, setUniqueId, setUniqueId, setUniqueId
 

Field Detail

_converter

protected ConverterIF _converter

_uriClients

protected java.lang.String _uriClients

_uriContexts

protected java.lang.String _uriContexts

_uriLogin

protected java.lang.String _uriLogin

_uriLogout

protected java.lang.String _uriLogout

_uriSessionInfo

protected java.lang.String _uriSessionInfo

_uriSubjects

protected java.lang.String _uriSubjects
Constructor Detail

Connection

public Connection(java.util.Properties props)
           throws ConnectionException
Create a new instance.

Throws:
java.lang.Exception
ConnectionException
Method Detail

close

public void close()
           throws ConnectionException
Close the open connection. The Session will be removed.

Specified by:
close in interface ConnectionIF
Throws:
java.lang.Exception
ConnectionException

debug

protected void debug(java.lang.String str)

decode

protected final StructureIF decode(java.lang.String str)
                            throws ConnectionException
Convert the "encoded" string to a StructureIF object.

Parameters:
str -
Returns:
StructureIF object
Throws:
java.lang.Exception
ConnectionException

doCreate

protected Output doCreate(Input input)
                   throws ConnectionException,
                          StructureException
Execute CREATE operation.

Parameters:
input -
Returns:
Output
Throws:
java.lang.Exception
ConnectionException
StructureException

doDelete

protected Output doDelete(Input input)
                   throws ConnectionException,
                          StructureException
Execute DELETE operation.

Parameters:
input -
Returns:
Output
Throws:
java.lang.Exception
ConnectionException
StructureException

doPwdChange

protected Output doPwdChange(Input input)
                      throws ConnectionException,
                             StructureException
Execute PWDCHANGE operation.

Parameters:
input -
Returns:
Output
Throws:
java.lang.Exception
ConnectionException
StructureException

doPwdForgot

protected Output doPwdForgot(Input input)
                      throws ConnectionException,
                             StructureException
Execute PWDFORGOT operation.

Parameters:
input -
Returns:
Output
Throws:
java.lang.Exception
ConnectionException
StructureException

doPwdReset

protected Output doPwdReset(Input input)
                     throws ConnectionException,
                            StructureException
Execute PWDRESET operation.

Parameters:
input -
Returns:
Output
Throws:
java.lang.Exception
ConnectionException
StructureException

doRead

protected Output doRead(Input input)
                 throws ConnectionException,
                        StructureException
Execute READ operation.

Parameters:
input -
Returns:
Output
Throws:
java.lang.Exception
ConnectionException
StructureException

doSearch

protected Output doSearch(Input input)
                   throws ConnectionException,
                          StructureException
Execute SEARCH operation.

Parameters:
input -
Returns:
Output
Throws:
java.lang.Exception
ConnectionException
StructureException

doUpdate

protected Output doUpdate(Input input)
                   throws ConnectionException,
                          StructureException
Execute UPDATE operation.

Parameters:
input -
Returns:
Output
Throws:
java.lang.Exception
ConnectionException
StructureException

encode

protected final java.lang.String encode(StructureIF struct)
                                 throws ConnectionException
Convert the StructureIF object to an "encoded" string.

Parameters:
struct -
Returns:
String encoded data that represents the StructureIF
Throws:
java.lang.Exception
ConnectionException

encrypt

protected final java.lang.String encrypt(java.lang.String value)
                                  throws ConnectionException
Encrypt the provided String.

Parameters:
value - clear text value.
Returns:
String encrypted value.
Throws:
java.lang.Exception
ConnectionException

execute

public final Output execute(Opcode opcode,
                            Input input)
                     throws ConnectionException
Execute the operation (Opcode) on the Server.

Specified by:
execute in interface ConnectionIF
Parameters:
opcode - Opcode what operation to execute
input - Input data used by the operation
Returns:
Output results of the operation
Throws:
java.lang.Exception
ConnectionException

getContextId

public final java.lang.String getContextId()
Gets the id of the current Context.

Specified by:
getContextId in interface ConnectionIF
Returns:
String context id

getContextIds

public final java.lang.String[] getContextIds()
Get all of the available Context Ids.

Specified by:
getContextIds in interface ConnectionIF
Returns:
String[] Array of available Context Ids

getSessionData

public abstract java.lang.String getSessionData(ConnectionIF.Session session)
                                         throws ConnectionException
Get the String representing a Session data item.

Specified by:
getSessionData in interface ConnectionIF
Returns:
String Session data
Throws:
ConnectionException

getSessionId

protected java.lang.String getSessionId()
Get the Session Id. Will be null if connection is closed.

Returns:
String the Session Id

getStructureFromAttribute

protected StructureIF getStructureFromAttribute(AttributeIF attr)
                                         throws ConnectionException,
                                                StructureException
Create a StructureIF object from the AttributeIF object.

Parameters:
attr -
Returns:
StructureIF
Throws:
java.lang.Exception
ConnectionException
StructureException

getStructureFromInput

protected StructureIF getStructureFromInput(Opcode opcode,
                                            Input input)
                                     throws ConnectionException,
                                            StructureException
Create a StructureIF object from the Input object.

Parameters:
opcode -
input -
Returns:
StructureIF
Throws:
java.lang.Exception
ConnectionException
StructureException

handleError

protected final void handleError(java.lang.String msg)
                          throws ConnectionException
Handle an error condition.

Parameters:
msg -
Throws:
java.lang.Exception
ConnectionException

hasSessionChanged

public final boolean hasSessionChanged()
Has the Session changed from the initial connection.

Specified by:
hasSessionChanged in interface ConnectionIF
Returns:
boolean True if the session has changed

isDebug

public final boolean isDebug()
Get the debug flag.

Specified by:
isDebug in interface ConnectionIF
Returns:
boolean will the debug data be displayed.

logError

protected void logError(java.lang.String str)

logInfo

protected void logInfo(java.lang.String str)

logWarning

protected void logWarning(java.lang.String str)

processClientStructure

protected void processClientStructure(StructureIF structClient)
                               throws ConnectionException
Process the Client Structure that comes from the server. In this case the types of items that are setup as ConnectionAttributes include: Example: UniqueID JerseyConnection Context Employees-MySQL-JDBC Contexts Employees-MySQL-JDBC, Employees-UnboundID-LDAP This method is generally called by the init method of a child Connection class.

Parameters:
structClient -
Throws:
java.lang.Exception
ConnectionException

setContextId

public final void setContextId(java.lang.String contextId)
                        throws ConnectionException
Set the "current" Context Id. When a connection is initially created, the default context as defined by the server is set as the the "current" context. The client application can make a change and change the "current" context at anytime. This is the method that will make that change.

Specified by:
setContextId in interface ConnectionIF
Parameters:
contextId - a valid Context Id
Throws:
java.lang.Exception
ConnectionException

setDebug

public final void setDebug(boolean debug)
Set the debug flag.

Specified by:
setDebug in interface ConnectionIF
Parameters:
debug - should debug data be displayed.

setSessionChanged

protected void setSessionChanged(boolean bool)

setSessionId

protected void setSessionId(java.lang.String str)

updateOutputFromReadStructure

protected void updateOutputFromReadStructure(Output output,
                                             StructureIF structResponse)
                                      throws ConnectionException
Update the StructureIF from the Read response (Structure).

Parameters:
output -
structResponse -
Throws:
java.lang.Exception
ConnectionException

updateOutputFromSearchStructure

protected void updateOutputFromSearchStructure(Output output,
                                               StructureIF structResponse)
                                        throws ConnectionException
Update Output from the Search response (Structure).

Parameters:
output -
structResponse -
Throws:
java.lang.Exception
ConnectionException

urlDecode

protected final java.lang.String urlDecode(java.lang.String str)
                                    throws ConnectionException
URL Decode a string. Typically this is used to decode strings that have come back in a URI/URL from the server.

Parameters:
str - String Data to be decoded
Returns:
String URL decoded data that represents the String
Throws:
java.lang.Exception
ConnectionException

urlEncode

protected final java.lang.String urlEncode(java.lang.String str)
                                    throws ConnectionException
URL Encode a string. Typically this is used to encode strings that will be embedded in a URI/URL bound for the server.

Parameters:
str - String Data to be encoded
Returns:
String URL encoded data that represents the String
Throws:
java.lang.Exception
ConnectionException


View/submit a bug or feature

For further API reference and developer documentation, see www.openptk.org. That documentation contains more detailed, developer-targeted descriptions, definitions of terms, workarounds, and working code examples.

Copyright (C) 2008-2012, Project OpenPTK. All Rights Reserved