de.folt.models.datamodel
Class GeneralLinguisticObject

java.lang.Object
  extended by java.util.Observable
      extended by de.folt.models.datamodel.GeneralLinguisticObject
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
MonoLingualObject, MultiLingualObject

public class GeneralLinguisticObject
extends java.util.Observable
implements java.io.Serializable

This class forms the basis of all OpenTMS language related classes. OpenTMS Software Architecture
Its main components are:

 stUniqueID - the unique id of the object, a string generated normally by UUID.randomUUID().toString()
 lastAccessTime - the time when the Object was accessed the last time
 lingType - the linguistic type associated with the class; derived from LinguisticTypes
 linguisticProperties - a set of properties associated with the object
 stOwner - the owner of the object (e.g. user)
 

Author:
klemens
See Also:
Serialized Form

Nested Class Summary
static class GeneralLinguisticObject.LinguisticTypes
          Currently supported LinguisticTypes (TMX, TERM, XLIFF)
 class GeneralLinguisticObject.TestObserver
           
 
Constructor Summary
GeneralLinguisticObject()
           
GeneralLinguisticObject(java.lang.Integer id, GeneralLinguisticObject.LinguisticTypes lingType, LinguisticProperties linguisticProperties, java.lang.String stUniqueID)
           
GeneralLinguisticObject(LinguisticProperties linguisticProperties, GeneralLinguisticObject.LinguisticTypes lingType)
           
GeneralLinguisticObject(java.lang.String uniqueID, LinguisticProperties linguisticProperties, GeneralLinguisticObject.LinguisticTypes lingType)
           
 
Method Summary
 void addLinguisticProperty(LinguisticProperty linguisticProperty)
          addLinguisticPropertiy
 void addObjectLinguisticProperty(java.lang.Object key, java.lang.Object value)
          addObjectLinguisticPropertiy
 void addStringLinguisticProperty(java.lang.String key, java.lang.String value)
          addStringLinguisticPropertiy
 boolean bCompare(GeneralLinguisticObject genObj)
          bCompare compare two GeneralLinguisticObject; if all the values and LinguisticProperties are identical return true; id/stUniqueID/lastAccessTime are never compared
 boolean bCompare(GeneralLinguisticObject genObj, boolean bCompareCoreAttributes)
          bCompare compare two GeneralLinguisticObject; if all the values and LinguisticProperties are identical return true; id/stUniqueID/lastAccessTime are never compared
 boolean checkDataSourceCriteria(DataSourceCriteria dataSourceCriteria, java.lang.String comparisionOperator)
          checkDataSourceCriteria checks a GLO against a dataSourceCriteria
 boolean checkDataSourceCriteria(java.util.Vector<DataSourceCriteria> dataSourceCriterias, java.lang.String comparisionOperator)
          checkDataSourceCriteria checks a GLO against a vector of dataSourceCriteria
 boolean checkDataSourceCriteria(java.util.Vector<DataSourceCriteria> dataSourceCriterias, java.lang.String comparisionOperator, boolean bOr)
          checkDataSourceCriteria checks a GLO against a vector of dataSourceCriteria
 void clearObject()
          clearObject sets all values to null or zero
 java.lang.String format()
          format
 java.lang.String formatAsXml()
          formatAsXml
static GeneralLinguisticObject fromJson(java.lang.String jsonMono)
          fromJson convert into a GeneralLinguisticObject from JSON String
 java.lang.Long getCreationTime()
           
 java.lang.Exception getException()
           
 java.lang.Integer getId()
           
 java.lang.Long getLastAccessTime()
           
 GeneralLinguisticObject.LinguisticTypes getLingType()
           
 LinguisticProperties getLinguisticProperties()
           
 java.lang.Long getModificationTime()
           
 LinguisticProperty getObjectLinguisticProperty(java.lang.Object key)
          getObjectLinguisticPropertiy
 java.lang.String getStOwner()
           
 java.lang.String getStUniqueID()
           
 java.lang.String getUniqueID()
           
 java.lang.Long getUsageNumber()
           
static boolean isbLogExceptions()
           
static void main(java.lang.String[] args)
          main
 java.lang.String mapToJson()
          mapToJson
 boolean matchLinguisticProperties(java.lang.String comparisionString)
          matchLinguisticProperties the method compares the LinguisticProperties of a GeneralLinguisticObject against a logical expression.
 void removeLinguisticProperty(LinguisticProperty linguisticProperty)
          removeLinguisticProperty
static void setbLogExceptions(boolean bLogExceptions)
           
 void setCreationTime(java.lang.Long creationTime)
           
 void setException(java.lang.Exception exception)
           
 void setId(java.lang.Integer id)
           
 void setLastAccessTime(long lastAccessTime)
           
 void setLingType(GeneralLinguisticObject.LinguisticTypes lingType)
           
 void setLinguisticProperties(LinguisticProperties linguisticProperties)
           
 void setModificationTime(java.lang.Long modificationTime)
           
 void setStOwner(java.lang.String stOwner)
           
 void setStUniqueID(java.lang.String stUniqueID)
           
 void setUniqueID(java.lang.String uniqueID)
           
 void setUsageNumber(java.lang.Long usageNumber)
           
static void test()
          test simple test method for generating some general linguistic objects
 void updateModificationTime()
          set the modification time to the current time stamp
 void updateUsageNumber()
          increment the usage counter
 
Methods inherited from class java.util.Observable
addObserver, countObservers, deleteObserver, deleteObservers, hasChanged, notifyObservers, notifyObservers
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GeneralLinguisticObject

public GeneralLinguisticObject()

GeneralLinguisticObject

public GeneralLinguisticObject(java.lang.Integer id,
                               GeneralLinguisticObject.LinguisticTypes lingType,
                               LinguisticProperties linguisticProperties,
                               java.lang.String stUniqueID)
Parameters:
id -
lingType -
linguisticProperties -
stUniqueID -

GeneralLinguisticObject

public GeneralLinguisticObject(LinguisticProperties linguisticProperties,
                               GeneralLinguisticObject.LinguisticTypes lingType)
Parameters:
linguisticProperties -
lingType -

GeneralLinguisticObject

public GeneralLinguisticObject(java.lang.String uniqueID,
                               LinguisticProperties linguisticProperties,
                               GeneralLinguisticObject.LinguisticTypes lingType)
Parameters:
uniqueID -
linguisticProperties -
lingType -
Method Detail

fromJson

public static GeneralLinguisticObject fromJson(java.lang.String jsonMono)
fromJson convert into a GeneralLinguisticObject from JSON String

Parameters:
jsonMono - the json formatted string
Returns:
the GeneralLinguisticObject

isbLogExceptions

public static boolean isbLogExceptions()
Returns:
the bLogExceptions

main

public static void main(java.lang.String[] args)
main

Parameters:
args -

setbLogExceptions

public static void setbLogExceptions(boolean bLogExceptions)
Parameters:
bLogExceptions - the bLogExceptions to set

test

public static void test()
test simple test method for generating some general linguistic objects


addLinguisticProperty

public void addLinguisticProperty(LinguisticProperty linguisticProperty)
addLinguisticPropertiy

Parameters:
linguisticProperty -

addObjectLinguisticProperty

public void addObjectLinguisticProperty(java.lang.Object key,
                                        java.lang.Object value)
addObjectLinguisticPropertiy

Parameters:
key - any object - must be possible to generate a String value from it
value - the value to associate with the property

addStringLinguisticProperty

public void addStringLinguisticProperty(java.lang.String key,
                                        java.lang.String value)
addStringLinguisticPropertiy

Parameters:
key - the key as a string to associate with the property
value - the string to associate with the property

bCompare

public boolean bCompare(GeneralLinguisticObject genObj)
bCompare compare two GeneralLinguisticObject; if all the values and LinguisticProperties are identical return true; id/stUniqueID/lastAccessTime are never compared

Parameters:
genObj - the object to compare against
Returns:
true if LinguisticProperties match

bCompare

public boolean bCompare(GeneralLinguisticObject genObj,
                        boolean bCompareCoreAttributes)
bCompare compare two GeneralLinguisticObject; if all the values and LinguisticProperties are identical return true; id/stUniqueID/lastAccessTime are never compared

Parameters:
genObj - the object to compare against
bCompareCoreAttributes - if true compare lingType and stOwner too
Returns:
true if lingType, stOwner attributes and LinguisticProperties match

checkDataSourceCriteria

public boolean checkDataSourceCriteria(DataSourceCriteria dataSourceCriteria,
                                       java.lang.String comparisionOperator)
checkDataSourceCriteria checks a GLO against a dataSourceCriteria

Parameters:
dataSourceCriteria - the DataSourceCriteria
comparisionOperator - the comparisionOperator to use
bOr - use OR (= true) or AND (= false)
Returns:
true or false if match

checkDataSourceCriteria

public boolean checkDataSourceCriteria(java.util.Vector<DataSourceCriteria> dataSourceCriterias,
                                       java.lang.String comparisionOperator)
checkDataSourceCriteria checks a GLO against a vector of dataSourceCriteria

Parameters:
dataSourceCriterias - a vector of DataSourceCriteria
comparisionOperator - the comparisionOperator to use
Returns:
true if any matches

checkDataSourceCriteria

public boolean checkDataSourceCriteria(java.util.Vector<DataSourceCriteria> dataSourceCriterias,
                                       java.lang.String comparisionOperator,
                                       boolean bOr)
checkDataSourceCriteria checks a GLO against a vector of dataSourceCriteria

Parameters:
dataSourceCriterias - a vector of DataSourceCriteria
comparisionOperator - the comparisionOperator to use
bOr - use OR (= true) or AND (= false) for individual comparisions
Returns:
true if any matches

clearObject

public void clearObject()
clearObject sets all values to null or zero


format

public java.lang.String format()
format

Returns:
the formatted string

formatAsXml

public java.lang.String formatAsXml()
formatAsXml

Returns:

getCreationTime

public java.lang.Long getCreationTime()

getException

public java.lang.Exception getException()
Returns:
the exception

getId

public java.lang.Integer getId()
Returns:
the id

getLastAccessTime

public java.lang.Long getLastAccessTime()
Returns:
the lastAccessTime

getLingType

public GeneralLinguisticObject.LinguisticTypes getLingType()
Returns:
the lingType - an enumeration currently either TMX oder TERM

getLinguisticProperties

public LinguisticProperties getLinguisticProperties()
Returns:
the linguisticProperties

getModificationTime

public java.lang.Long getModificationTime()

getObjectLinguisticProperty

public LinguisticProperty getObjectLinguisticProperty(java.lang.Object key)
getObjectLinguisticPropertiy

Parameters:
key -
Returns:
a LinguisticProperty for key

getStOwner

public java.lang.String getStOwner()
Returns:
the stOwner

getStUniqueID

public java.lang.String getStUniqueID()
Returns:
the stUniqueID

getUniqueID

public java.lang.String getUniqueID()
Returns:
the stUniqueID

getUsageNumber

public java.lang.Long getUsageNumber()

mapToJson

public java.lang.String mapToJson()
mapToJson

Returns:

matchLinguisticProperties

public boolean matchLinguisticProperties(java.lang.String comparisionString)
matchLinguisticProperties the method compares the LinguisticProperties of a GeneralLinguisticObject against a logical expression. It returns true if the expression matches, otherwise false.
The method loops thru all properties. Depending on the type of property the the property value is treated as string or as int or similar.
The comparison is done using the JavaScript ScriptEngine (see http://download .oracle.com/javase/6/docs/api/javax/script/ScriptEngineManager.html).
The names of the properties are represented as "%prop-name%"
The returning expression is constructed as:
evalcode = "res = " + comparisionString + "; res;";
If the evalcode should not be constructed in this way the logical expression start with: <JavaScript>.
In this case the comparison expression is responsible returning "true" or "false" as the last value; otherwise the method will always return false.
The following key - value pairs are supplied to the script:
Key Value
prop-name[1..n] value of property[1..n]
comparisionString comparisionString
finalComparisionString final comparisionString
evalCode evalcode
Examples of logical expressions:
MonoLingualObject mono1 = new MonoLingualObject("My small segment!", "en");
mono1.addStringLinguisticProperty("OpenTMS", "FoltNew");
mono1.addLinguisticProperty(new LinguisticProperty("Zahl", (Integer) 10));
System.out.println(mono1.matchLinguisticProperties( "%OpenTMS% == \"FoltNew\""));
System.out.println(mono1.matchLinguisticProperties("%Zahl% == 10"));
System.out.println(mono1.matchLinguisticProperties("%Zahl% == 12"));
System.out.println(mono1.matchLinguisticProperties("%Zahl% < 12"));
System.out.println("<JavaScript>b = true; b; " + mono1.matchLinguisticProperties("b = true; b;"));

Parameters:
comparisionString - the logical string against which the LinguisticProperties of the GeneralLinguisticObject is compared
Returns:
true if comparisionString matches based on the LinguisticProperties; otherwise false; false if an exception occurs; the exception can be checked with .getException(); null if successful

removeLinguisticProperty

public void removeLinguisticProperty(LinguisticProperty linguisticProperty)
removeLinguisticProperty

Parameters:
linguisticProperty -

setCreationTime

public void setCreationTime(java.lang.Long creationTime)

setException

public void setException(java.lang.Exception exception)
Parameters:
exception - the exception to set

setId

public void setId(java.lang.Integer id)
Parameters:
id - the id to set

setLastAccessTime

public void setLastAccessTime(long lastAccessTime)
Parameters:
lastAccessTime - the lastAccessTime to set

setLingType

public void setLingType(GeneralLinguisticObject.LinguisticTypes lingType)
Parameters:
lingType - the lingType to set

setLinguisticProperties

public void setLinguisticProperties(LinguisticProperties linguisticProperties)
Parameters:
linguisticProperties - the linguisticProperties to set

setModificationTime

public void setModificationTime(java.lang.Long modificationTime)

setStOwner

public void setStOwner(java.lang.String stOwner)
Parameters:
stOwner - the stOwner to set

setStUniqueID

public void setStUniqueID(java.lang.String stUniqueID)
Parameters:
stUniqueID - the stUniqueID to set

setUniqueID

public void setUniqueID(java.lang.String uniqueID)
Parameters:
uniqueID - the stUniqueID to set; this should be an unique id and no conflict with other (subclasses) of this class

setUsageNumber

public void setUsageNumber(java.lang.Long usageNumber)
Parameters:
usageNumber - the new usage number

updateModificationTime

public void updateModificationTime()
set the modification time to the current time stamp


updateUsageNumber

public void updateUsageNumber()
increment the usage counter