Skip navigation links

Oracle Fusion Middleware Java API Reference for Oracle ADF Mobile
11g Release 2 (11.1.2.4.0)

E27204-03


oracle.adfmf.framework.api
Class AdfmfJavaUtilities

java.lang.Object
  extended by oracle.adfmf.framework.api.AdfmfJavaUtilities


public class AdfmfJavaUtilities
extends java.lang.Object

Field Summary
static java.lang.String AES128
          Database password prefix to denote AES128 database encryption should be used.
static java.lang.String AES256
          Database password prefix to denote AES256 database encryption should be used.
static int ApplicationDirectory
          Constant to be used to determine which directory path to obtain
static int DatabaseAES128Encryption
          Constant returned by encryptDatabase(..) to denote what encryption algorithm will be used for the database.
static int DatabaseAES256Encryption
          Constant returned by encryptDatabase(..) to denote what encryption algorithm will be used for the database.
static int DatabaseDefaultEncryption
          Default database encryption algorithm
static int DatabaseNoEncryption
          Constant returned by encryptDatabase(..) to denote what encryption algorithm will be used for the database.
static int DatabaseRC4Encryption
          Constant returned by encryptDatabase(..) to denote what encryption algorithm will be used for the database.
static int DeviceOnlyDirectory
          Constant to be used to determine which directory path to obtain
static int DownloadDirectory
          Constant to be used to determine which directory path to obtain
static java.lang.String RC4
          Database password prefix to denote RC4 database encryption should be used.
static int TemporaryDirectory
          Constant to be used to determine which directory path to obtain

 

Constructor Summary
AdfmfJavaUtilities()
           

 

Method Summary
static void clearPasswordCredential(java.lang.String adfCredentialStoreKey, java.lang.String username)
          Clear a password credential for the key from the credential store
static void decryptDatabase(java.sql.Connection db)
          Permanently decrypt a previously-encrypted database
static int encryptDatabase(java.sql.Connection db, java.lang.String newPassword)
          Encrypt the database with the specified password.
static java.lang.Object evaluateELExpression(java.lang.String elExpression)
          Evaluates the expression and returns the resulting value.
static void flushDataChangeEvent()
          Flush any pending data change events NOTE: Can only be called from a background thread.
static java.lang.String getActiveContextId()
          Get the active EL context name.
static AdfELContext getAdfELContext()
          Get the ADF EL context.
static java.lang.Object getDataControlProvider(java.lang.String dcName)
          Used to to get the root provider instance from a DataControl.
static java.lang.String getDirectoryPathRoot(int typeOfPath)
          Gets the path to certain writable directory on the device
static oracle.adfmf.framework.FeatureContext getFeatureContext()
          Get current FeatureContext instance.
static java.lang.String getFeatureName()
          Get current feature name.
static MethodExpression getMethodExpression(java.lang.String expression, java.lang.Class expectedReturnType, java.lang.Class[] expectedParamTypes)
          Use this method for expressions that refer to methods.
static ValueExpression getValueExpression(java.lang.String expression, java.lang.Class expectedType)
          Use this method for expressions that refer to values.
static java.lang.Object invokeDataControlMethod(java.lang.String dcName, java.lang.String instanceName, java.lang.String methodName, java.util.List parameterNames, java.util.List parameters, java.util.List parameterTypes)
          Invoke a DC operation.
static boolean isBackgroundThread()
          Use it to test if the current thread is a background thread or not.
static boolean isEvaluationExpression(java.lang.String elExpression)
          Checks if the passed in expression string is an evaluation expression.
static boolean isPrimaryRequestThread()
          Use it to test if the current thread is a primary thread or not.
static void loadXliffResourceBundle(java.lang.String baseName, java.lang.String varNameUsed)
          Used to load the recourse bundle and store it as a map in the request scope.
static void logout()
          Logout the current authentication server
static void setELValue(java.lang.String elExpression, java.lang.Object value)
          Sets a property resolved by an EL Expression to a value

 

Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

 

Field Detail

TemporaryDirectory

public static final int TemporaryDirectory
Constant to be used to determine which directory path to obtain
See Also:
getDirectoryPathRoot, Constant Field Values

ApplicationDirectory

public static final int ApplicationDirectory
Constant to be used to determine which directory path to obtain
See Also:
getDirectoryPathRoot, Constant Field Values

DeviceOnlyDirectory

public static final int DeviceOnlyDirectory
Constant to be used to determine which directory path to obtain
See Also:
getDirectoryPathRoot, Constant Field Values

DownloadDirectory

public static final int DownloadDirectory
Constant to be used to determine which directory path to obtain
See Also:
getDirectoryPathRoot, Constant Field Values

DatabaseNoEncryption

public static final int DatabaseNoEncryption
Constant returned by encryptDatabase(..) to denote what encryption algorithm will be used for the database.
See Also:
encryptDatabase, Constant Field Values

DatabaseAES128Encryption

public static final int DatabaseAES128Encryption
Constant returned by encryptDatabase(..) to denote what encryption algorithm will be used for the database.
See Also:
encryptDatabase, Constant Field Values

DatabaseAES256Encryption

public static final int DatabaseAES256Encryption
Constant returned by encryptDatabase(..) to denote what encryption algorithm will be used for the database.
See Also:
encryptDatabase, Constant Field Values

DatabaseRC4Encryption

public static final int DatabaseRC4Encryption
Constant returned by encryptDatabase(..) to denote what encryption algorithm will be used for the database.
See Also:
encryptDatabase, Constant Field Values

DatabaseDefaultEncryption

public static final int DatabaseDefaultEncryption
Default database encryption algorithm
See Also:
DatabaseAES128Encryption, Constant Field Values

AES128

public static final java.lang.String AES128
Database password prefix to denote AES128 database encryption should be used.
See Also:
encryptDatabase, Constant Field Values

AES256

public static final java.lang.String AES256
Database password prefix to denote AES256 database encryption should be used.
See Also:
encryptDatabase, Constant Field Values

RC4

public static final java.lang.String RC4
Database password prefix to denote RC4 database encryption should be used.
See Also:
encryptDatabase, Constant Field Values

Constructor Detail

AdfmfJavaUtilities

public AdfmfJavaUtilities()

Method Detail

getDirectoryPathRoot

public static java.lang.String getDirectoryPathRoot(int typeOfPath)
Gets the path to certain writable directory on the device
Parameters:
typeOfPath - If the value is:
  • TemporaryDirectory, returns the directory for storing temporary files
  • ApplicationDirectory, returns the directory for storing Application files
  • DeviceOnlyDirectory, returns the directory for storing cache files
  • DownloadDirectory, returns the directory for storing downloaded files
Returns:
the path
See Also:
TemporaryDirectory, ApplicationDirectory, DeviceOnlyDirectory, DownloadDirectory

getFeatureContext

public static oracle.adfmf.framework.FeatureContext getFeatureContext()
Get current FeatureContext instance.
Returns:
the current FeatureContext instance.

getFeatureName

public static java.lang.String getFeatureName()
                                       throws AdfException
Get current feature name.
Returns:
the current feature's name
Throws:
AdfException

getAdfELContext

public static AdfELContext getAdfELContext()
Get the ADF EL context.
Returns:
the ADF EL Context

getActiveContextId

public static java.lang.String getActiveContextId()
Get the active EL context name.
Returns:
the name of the current feature's active EL context

getValueExpression

public static ValueExpression getValueExpression(java.lang.String expression,
                                                 java.lang.Class expectedType)
Use this method for expressions that refer to values. This method should perform syntactic validation of the expression. If in doing so it detects errors, it should raise an ELException.Evaluations performed through this object are not inherently thread safe. It is recommended that developers use the thread safe evaluateELExpression and setELValue methods to get and set values if expressions in the same feature are accessed in multiple threads. If this is not possible, the developer should surround any usages of the returned expression object in a synchronized block, using the object returned by getAdfELContext() as the monitor.
Parameters:
expression - The expression to parse
expectedType - The type the result of the expression will be coerced to after evaluation.
Returns:
The parsed expression
Throws:
ELException - Thrown if there are syntactical errors in the provided expression.
java.lang.NullPointerException - if paramTypes is null.
See Also:
getAdfELContext, evaluateELExpression, setELValue

getMethodExpression

public static MethodExpression getMethodExpression(java.lang.String expression,
                                                   java.lang.Class expectedReturnType,
                                                   java.lang.Class[] expectedParamTypes)
Use this method for expressions that refer to methods. If the expression is a String literal, a MethodExpression is created, which when invoked, returns the String literal, coerced to expectedReturnType. An ELException is thrown if expectedReturnType is void or if the coercion of the String literal to the expectedReturnType yields an error. This method should perform syntactic validation of the expression. If in doing so it detects errors, it should raise an ELException.EL Resolution of the method to invoke through this object is not inherently thread safe. If expressions in the same feature are expected to be used in multiple threads, the developer should surround any usages of the returned expression object in a synchronized block, using the object returned by getAdfELContext() as the monitor.
Parameters:
expression - The expression to parse
expectedReturnType - The expected return type for the method to be found. After evaluating the expression, the MethodExpression must check that the return type of the actual method matches this type. Passing in a value of null indicates the caller does not care what the return type is, and the check is disabled.
expectedParamTypes - The expected parameter types for the method to be found. Must be an array with no elements if there are no parameters expected. It is illegal to pass null, unless the method is specified with arguments in the EL expression.
Returns:
The parsed expression
Throws:
ELException - Thrown if there are syntactical errors in the provided expression.
java.lang.NullPointerException - if paramTypes is null.
See Also:
getAdfELContext

evaluateELExpression

public static java.lang.Object evaluateELExpression(java.lang.String elExpression)
                                             throws AdfException
Evaluates the expression and returns the resulting value.This method is thread safe, however generic underlying EL evaluation is not. It is recommended that developers use this method to evaluate EL expressions if expressions in the same feature are expected to be used in multiple threads.
Parameters:
elExpression - The expression to be evaluated.
Returns:
The result of the expression evaluation.
Throws:
java.lang.NullPointerException - if context is null.
PropertyNotFoundException - if one of the property resolutions failed because a specified variable or property does not exist or is not readable.
ELException - if an exception was thrown while performing property or variable resolution. The thrown exception must be included as the cause property of this exception, if available.
AdfException
See Also:
getAdfELContext, getValueExpression, setELValue

setELValue

public static void setELValue(java.lang.String elExpression,
                              java.lang.Object value)
Sets a property resolved by an EL Expression to a valueThis method is thread safe, however generic underlying EL resolution is not. It is recommended that developers use this method to set values through EL expressions if expressions in the same feature are expected to be used in multiple threads.
Parameters:
elExpression - The expression that resolves to the property on which to set the value.
value - The value to set the resolved expression to.
Throws:
java.lang.NullPointerException - if context is null.
PropertyNotFoundException - if one of the property resolutions failed because a specified variable or property does not exist or is not readable.
ELException - if an exception was thrown while performing property or variable resolution. The thrown exception must be included as the cause property of this exception, if available.
See Also:
getAdfELContext, evaluateELExpression, getValueExpression

isEvaluationExpression

public static boolean isEvaluationExpression(java.lang.String elExpression)
Checks if the passed in expression string is an evaluation expression.
Parameters:
elExpression -
Returns:
true if the el string is an evaluated expression, as opposed to literal text.

flushDataChangeEvent

public static void flushDataChangeEvent()
Flush any pending data change events NOTE: Can only be called from a background thread.

invokeDataControlMethod

public static java.lang.Object invokeDataControlMethod(java.lang.String dcName,
                                                       java.lang.String instanceName,
                                                       java.lang.String methodName,
                                                       java.util.List parameterNames,
                                                       java.util.List parameters,
                                                       java.util.List parameterTypes)
                                                throws AdfInvocationException
Invoke a DC operation. The operation does not have to be explicitly added as a methodAction in a pagedef.
Parameters:
dcName - The name of the DataControl on which the method (or the nested object that declares the method) is declared.
instanceName - The name of the nested object on the DataControl that declares the method (can be null if the method is on the root DC).
methodName - The name of the method to invoke.
parameterNames - The names of any named parameters. Required, elements must be of type java.lang.String.
parameters - The parameter values. Elements can be of any type.
parameterTypes - The parameter types. Elements must be of type java.lang.Class. Can be null if the data control implementation does not require parameter types for invocation.
Returns:
The Object returned by the invoked method. null if the method returns void. In addition to the direct return, the returned object is also cached in the DataControl and can be resolved via EL of the following form : #{data.dcName.methodResults.methodName_result}, where dcName and methodName are their respective parameter values.
Throws:
AdfInvocationException - on invocation errors
Examples of usage:
   public void changePlayerName(ActionEvent evt)
   {

     // call a method that takes an int as a parameter

     List pnames = new ArrayList();
     List params = new ArrayList();
     List ptypes = new ArrayList();

        pnames.add("name");
     ptypes.add(String.class);
        params.add("Bill");

        pnames.add("index");
     ptypes.add(int.class); // the class must be the primitive version for
                            // reflection to find the proper method
     params.add(new Integer(0)); // the value must be the object version here,
                                 // reflection will auto unbox the value when
                                 // passing

     try {
       AdfmfJavaUtilities.invokeDataControlMethod("TeamBean", null, "changePlayerName", pnames, params, ptypes);
     }catch(AdfInvocationException ex) {
       // If the web service is not available throw a nice exception
        if(AdfInvocationException.CATEGORY_WEBSERVICE.compareTo(ex.getErrorCategory()) == 0) {
           throw new RuntimeException("Error with the server.  Please try later.");
        }
     } 
   }

   public void addNewPlayerAsObject(ActionEvent evt)
   {
     // call a method that takes a bean instance

     PlayerBean player = new PlayerBean(); // Application Bean

     List pnames = new ArrayList();
     List params = new ArrayList();
     List ptypes = new ArrayList();

     player.setName("Morris");
     player.setNumber("53");
     player.setPosition("RD");

     pnames.add("player");
     ptypes.add(PlayerBean.class);
     params.add(player);

     try {
       AdfmfJavaUtilities.invokeDataControlMethod("TeamBean", null, "addPlayer", pnames, params, ptypes);
     }catch(AdfInvocationException ex) {
       // If the web service is not available throw a nice exception
        if(AdfInvocationException.CATEGORY_WEBSERVICE.compareTo(ex.getErrorCategory()) == 0) {
           throw new RuntimeException("Error with the server.  Please try later.");
        }
     } 
   }

   public void addNewPlayerAsGT(ActionEvent evt)
   {

     // call a method that takes a GenericType representation of a bean as a
     // parameter
     // use the GenericType serialization helper class to convert

     PlayerBean player = new PlayerBean(); // Application Bean

     GenericType gt = null;
     GenericType result = null;

     List pnames = new ArrayList();
     List params = new ArrayList();
     List ptypes = new ArrayList();

     player.setName("Morris");
     player.setNumber("53");
     player.setPosition("RD");

     gt = GenericTypeBeanSerializationHelper.toGenericType("test.mobile.PlayerBean", player);

     pnames.add("player");
     ptypes.add(gt.getClass());
     params.add(gt);

     try {
       result = (GenericType) AdfmfJavaUtilities.
                              invokeDataControlMethod("TeamBean", null, "addPlayerAsGT", pnames, params, ptypes);

       Object provider = AdfmfJavaUtilities.getDataControlprovider("TeamBean");

       GenericTypeBeanSerializationHelper.fromGenericType(provider, result);

     }catch(AdfInvocationException ex) {
       // If the web service is not available throw a nice exception
        if(AdfInvocationException.CATEGORY_WEBSERVICE.compareTo(ex.getErrorCategory()) == 0) {
           throw new RuntimeException("Error with the server.  Please try later.");
        }
     } 
   }
   

clearPasswordCredential

public static void clearPasswordCredential(java.lang.String adfCredentialStoreKey,
                                           java.lang.String username)
                                    throws AdfException
Clear a password credential for the key from the credential store
Parameters:
adfCredentialStoreKey - attribute associated with the login server reference that appears in the connections.xml file.
username - who's credentials will be removed.
Throws:
AdfException

logout

public static void logout()
                   throws AdfException
Logout the current authentication server
Throws:
AdfException

isPrimaryRequestThread

public static boolean isPrimaryRequestThread()
Use it to test if the current thread is a primary thread or not.
Returns:
true if the current thread is the primary thread handling the request.

isBackgroundThread

public static boolean isBackgroundThread()
Use it to test if the current thread is a background thread or not.
Returns:
true if the current thread is a background thread (i.e. not the thread handling an incoming request)

encryptDatabase

public static int encryptDatabase(java.sql.Connection db,
                                  java.lang.String newPassword)
Encrypt the database with the specified password.
Parameters:
db - A previously-opened database connection. If the database is already encrypted, it must also have been opened with the correct password.
newPassword - New password to use when encrypting the database. A particular encryption algorithm may be selected by prefixing one of: 'aes128:', 'aes256:', or 'rc4:' to the password. Note that the entire password, including prefix, must subsequently be specified when opening this now-encrypted database. The default encryption mode AES128 is used when no prefix (or an invalid one) is specified. If no password is specified, the database is permanently decrypted, i.e. no password will be required to subsequently open the database.
Returns:
A constant indicating which encryption mode was used to encrypt the database. One of the Database*Encryption constants.

NOTE:
For customers who would like to enforce a specific database encryption algorithm, they should programmatically prepend the proper database encryption prefix to the database driver's encrypt and getConnection calls. i.e.

     public String getDatabaseEncryptedAlgorithmPassword(String userPassword) {
       return (AdfmfJavaUtilities.AES256 + ":" + userPassword);
     }

     ...

     public void setDatabasePassword(String userPassword) {
       AdfmfJavaUtilties.encrypteDatabase(getDatabaseEncryptedAlgorithmPassword(userPassword));
     }

     ...

     public Connection openApplicationDatabaseConnection(String dataSource, String userPassword) {
       return new SQLite.JDBCDataSource(dataSource).getConnection(null, getDatabaseEncryptedAlgorithmPassword(userPassword));
     }

 
See Also:
DatabaseNoEncryption, DatabaseAES128Encryption, DatabaseAES256Encryption, DatabaseRC4Encryption, DatabaseDefaultEncryption, decryptDatabase

decryptDatabase

public static void decryptDatabase(java.sql.Connection db)
Permanently decrypt a previously-encrypted database
Parameters:
db - A previously-opened database connection. If the database is already encrypted, it must also have been opened with the correct password.
See Also:
encryptDatabase

loadXliffResourceBundle

public static void loadXliffResourceBundle(java.lang.String baseName,
                                           java.lang.String varNameUsed)
                                    throws AdfException
Used to load the recourse bundle and store it as a map in the request scope. This allows you to access the message in AMX/HTML. This call is equivalent to amx declaration of: <amx:loadBundle> eg. <amx:loadBundle basename="mobile_ViewControllerBundle" var="viewcontrollerBundle"/>
Parameters:
baseName - Base name where the bundle is present (relative to the project) eg. If ViewControllerBundle.xlf is located in <Application>/ViewController/src/mobile then baseName will be: "mobile.ViewControllerBundle"
varNameUsed - Name by which the we will refer this bundle. eg. viewcontrollerBundle
Throws:
AdfException
See Also:
amx:loadBundle

getDataControlProvider

public static java.lang.Object getDataControlProvider(java.lang.String dcName)
                                               throws AdfException
Used to to get the root provider instance from a DataControl. From this, the developer can then navigate the actual datacontrol's provider hierarchy to get the instance (which is already hooked in) to populate.
Parameters:
dcName - The name of the DataControl
Returns:
The root provider instance from a DataControl
Throws:
AdfException - Thrown if cannot not find DataControl by name in the Binding Context.
See Also:
invokeDataControlMethod

Skip navigation links

Oracle Fusion Middleware Java API Reference for Oracle ADF Mobile
11g Release 2 (11.1.2.4.0)

E27204-03


Copyright © 2012, 2013 Oracle. All Rights Reserved.