org.qriterium.dogma
Class DogmaResource

java.lang.Object
  extended by org.qriterium.dogma.DogmaResource
All Implemented Interfaces:
java.io.Serializable, iResource

public class DogmaResource
extends java.lang.Object
implements iResource, java.io.Serializable

DogmaResource is a class which represents resource in Dogma program's context (in this class's comments "resource" refer to "DogmaResource").

Version:
%I%, %G%
See Also:
Serialized Form

Nested Class Summary
static class DogmaResource.defaultType
           
 
Field Summary
static long serialVersionUID
           
static java.lang.String tagSeparator
           
 
Constructor Summary
DogmaResource()
          A minimal constructor which initializes empty collections for multi-valued attibutes.
DogmaResource(java.lang.String name, java.lang.String canoname, java.lang.String rawName, java.lang.String resourceClass, java.lang.String type, java.util.Date added, java.util.Date created, java.util.Date imported, java.util.Date viewed, java.util.Date found, java.util.Date loaded, java.lang.String source, int inSourceId, int value, int views, int recency, int loads, int rank, int activity)
          Another default constructor for creating the resource from metadata (which is imported by Updater).
DogmaResource(java.lang.String name, java.lang.String canoname, java.lang.String rawName, java.lang.String resourceClass, java.lang.String type, java.util.Date added, java.util.Date created, java.util.Date imported, java.util.Date viewed, java.util.Date found, java.util.Date loaded, java.lang.String source, int inSourceId, int value, int views, int recency, int loads, int rank, int activity, int toConnections, int fromConnections, int totalConnections)
          Another default constructor for creating the resource from metadata (which is imported by Updater).
DogmaResource(java.lang.String name, java.lang.String canoname, java.lang.String rawName, java.lang.String resourceClass, java.lang.String type, java.util.Date added, java.util.Date created, java.util.Date imported, java.lang.String source, int inSourceId)
          A default constructor for creating the resource from metadata (which is imported by Updater).
 
Method Summary
 void addConnection(boolean tothis, iConnection connection)
          Adds a new connection to resource's connections.
 void addConnection(iConnection connection)
          Adds connection from this resource, calls method addConnection(boolean, DogmaConnection).
 void addTag(java.lang.String tag)
          Adds a new tag to resource's @see #tags
 void addUri(DogmaURI uri)
           
 void addUri(java.lang.String uri)
          Adds a new uri to resource's uris.
 java.lang.String[] attributesToString(java.lang.String[] attrNames)
          Method returns all attributevalues corresponding to given names as String array, same order as name array.
 java.lang.String[] attributesToString(java.lang.String[] attrNames, java.lang.String[] returnval)
          Works same way than getValuesAsString(String[]), but attribute value Strings are put in the array given as parameter.
 java.lang.String attributeToString(java.lang.String name)
          Returns a String representation of attribute, never returns null ("" instead of it).
 void changeUris(int index)
           
 boolean containsAttribute(java.lang.String name)
           
 boolean containsTag(java.lang.String tag)
           
static java.lang.String dateString(java.util.Date date)
           
 int fromX(java.lang.String type)
           
 int getActivity()
           
 java.util.Date getAdded()
           
static java.lang.String[] getAttributeList()
          Returns the attribute-names used.
 java.lang.String[] getAttributeNames(boolean sorted)
          Returns names of attributes, that are set in this resource, as array.
 java.lang.Object getAttributeValue(java.lang.String name)
          Returns the value of attribute, which name is param-name
 java.util.Date getAttributeValueAsDate(java.lang.String name)
           
 double getAttributeValueAsDouble(java.lang.String name)
           
 int getAttributeValueAsInt(java.lang.String name)
           
 java.lang.String getAttributeValueAsString(java.lang.String name)
           
 java.lang.String getCanoname()
           
 java.util.Vector<DogmaConnection> getConnections()
           
 java.util.Date getCreated()
           
 java.util.Date getFound()
           
 int getFromAmount()
           
 java.util.Date getImported()
           
 int getInSourceId()
           
 java.util.Date getLoaded()
           
 int getLoads()
           
 java.lang.String getName()
           
 int getRank()
           
 java.lang.String getRawName()
           
 int getRecency()
           
 java.lang.String getResourceClass()
           
 java.lang.String getSource()
           
 java.util.HashSet<java.lang.String> getTags()
           
 int getToAmount()
           
 java.lang.String getType()
           
 java.util.Vector<DogmaURI> getUris()
           
 int getValue()
           
 java.util.Date getViewed()
           
 int getViews()
           
 boolean hasConnection(java.lang.String idString)
          Returns true if the connectionvector of the resource already has a connection identical to the given identificationstring.
 boolean hasUri(java.lang.String uriString)
          Returns true if the uri-vector of the resource already has an uri identical to the given uristring.
 void incrementAttribute(java.lang.String name)
          Method for incrementing some int-attributes, like loads.
 void merge(DogmaResource another)
          Merges two resources into one
static java.util.HashSet<java.lang.String> parseTags(java.lang.String tagText)
          Parses tags from String, where tags are separated by tagSeparator
 void removeConnection(DogmaConnection c)
          Removes connection from this resource, calls method removeConnection(DogmaConnection, boolean).
 void removeConnection(DogmaConnection c, boolean toThis)
          Removes connection from this resource, decrements toAmount/fromAmount depending of connection's direction.
 void removeConnectionFromBoth(DogmaConnection c)
          Removes connection from this resource, and from the resource that is at another side of connection, if connection contains reference to that resource.
 void removeTag(java.lang.String tag)
          Removes tag from resource's @see #tags, does nothing there isn't such a tag.
 void setActivity(int activity)
           
 void setAdded(java.util.Date added)
           
 void setAttribute(java.lang.String name, java.lang.Object value)
          Sets a value to this resource's attribute, only if that attribute-name is in the global mapping in Attribute class
 boolean setAttributeAsString(java.lang.String name, java.lang.String value)
          Sets the given attribute value as it's canonical String-conversion
 void setCanoname(java.lang.String canoname)
           
 void setConnections(java.util.Vector<DogmaConnection> connections)
          Set resource's connections to be the given set.
 void setCreated(java.util.Date created)
           
 boolean setDateAsString(java.lang.String name, java.lang.String value)
          Sets a new Date value to attribute, if parameter-String is in valid format (otherwise old value will remain).
 void setFound(java.util.Date found)
           
 void setFromAmount(int amount)
           
 void setImmutableDateAttribute(java.lang.String name, java.util.Date time)
          Sets a Date value to DATE-attribute if previous value is null, otherwise does nothing.
 void setImported(java.util.Date imported)
           
 void setInSourceId(int inSourceId)
           
 void setLoaded(java.util.Date loaded)
           
 void setLoads(int loads)
           
 void setName(java.lang.String name)
           
 void setRank(int rank)
           
 void setRawName(java.lang.String rawName)
           
 void setRecency(int recency)
           
 void setResourceClass(java.lang.String resourceClass)
           
 void setSource(java.lang.String source)
           
 void setTags(java.util.HashSet<java.lang.String> tags)
          Adds the given tag-set to the resource's @see #tags
 void setToAmount(int amount)
           
 void setType(java.lang.String type)
           
 void setUris(java.util.Vector<DogmaURI> uris)
          Set the given DogmaURI-set to be resource's Won't change anything is parameter has only invalid elements.
 void setValue(int value)
           
 void setViewed(java.util.Date viewed)
           
 void setViews(int views)
           
 DogmaResource[] split(java.util.Vector<DogmaConnection> moveToNew)
          Splits this resource in two resources.
 int toX(java.lang.String type)
           
 void updateConnection(DogmaConnection conn)
          This method is meant to be used for updating resources existing connections.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

tagSeparator

public static final java.lang.String tagSeparator
See Also:
Constant Field Values

serialVersionUID

public static final long serialVersionUID
See Also:
Constant Field Values
Constructor Detail

DogmaResource

public DogmaResource()
A minimal constructor which initializes empty collections for multi-valued attibutes. This constructor is always called from every other constructors (directly or indirectly).


DogmaResource

public DogmaResource(java.lang.String name,
                     java.lang.String canoname,
                     java.lang.String rawName,
                     java.lang.String resourceClass,
                     java.lang.String type,
                     java.util.Date added,
                     java.util.Date created,
                     java.util.Date imported,
                     java.lang.String source,
                     int inSourceId)
A default constructor for creating the resource from metadata (which is imported by Updater).

Parameters:
name - value to resource's @see #name
canoname - value to resource's @see #canoname
rawName - value to resource's @see #rawName
resourceClass - value to resource's @see #resourceClass
type - value to resource's @see #type
added - value to resource's @see #added
created - value to resource's @see #created
imported - value to resource's @see #imported
source - value to resource's @see #source
inSourceId - value to resource's @see #inSourceId

DogmaResource

public DogmaResource(java.lang.String name,
                     java.lang.String canoname,
                     java.lang.String rawName,
                     java.lang.String resourceClass,
                     java.lang.String type,
                     java.util.Date added,
                     java.util.Date created,
                     java.util.Date imported,
                     java.util.Date viewed,
                     java.util.Date found,
                     java.util.Date loaded,
                     java.lang.String source,
                     int inSourceId,
                     int value,
                     int views,
                     int recency,
                     int loads,
                     int rank,
                     int activity)
Another default constructor for creating the resource from metadata (which is imported by Updater). Enters all the attributes of the attribute-class to the resource.


DogmaResource

public DogmaResource(java.lang.String name,
                     java.lang.String canoname,
                     java.lang.String rawName,
                     java.lang.String resourceClass,
                     java.lang.String type,
                     java.util.Date added,
                     java.util.Date created,
                     java.util.Date imported,
                     java.util.Date viewed,
                     java.util.Date found,
                     java.util.Date loaded,
                     java.lang.String source,
                     int inSourceId,
                     int value,
                     int views,
                     int recency,
                     int loads,
                     int rank,
                     int activity,
                     int toConnections,
                     int fromConnections,
                     int totalConnections)
Another default constructor for creating the resource from metadata (which is imported by Updater). Enters all the attributes of the attribute-class to the resource.

Method Detail

attributeToString

public java.lang.String attributeToString(java.lang.String name)
Returns a String representation of attribute, never returns null ("" instead of it).


attributesToString

public java.lang.String[] attributesToString(java.lang.String[] attrNames)
Method returns all attributevalues corresponding to given names as String array, same order as name array. If resource doesn't have particular attribute set, it's value is then returned as "". Therefore null values won't be returned;

Parameters:
attrNames - Attribute names
Returns:
Attribute values

attributesToString

public java.lang.String[] attributesToString(java.lang.String[] attrNames,
                                             java.lang.String[] returnval)
Works same way than getValuesAsString(String[]), but attribute value Strings are put in the array given as parameter.

Parameters:
attrNames -
returnval - Array for return values, must be same length as another parameter attrNames.
Returns:
Atribute values

containsAttribute

public boolean containsAttribute(java.lang.String name)
Parameters:
name - attribute name
Returns:
true, if attribute exists in this resource

getAttributeValue

public java.lang.Object getAttributeValue(java.lang.String name)
Returns the value of attribute, which name is param-name

Parameters:
name - name of the attribute
Returns:
value of the attribute

setAttribute

public void setAttribute(java.lang.String name,
                         java.lang.Object value)
Sets a value to this resource's attribute, only if that attribute-name is in the global mapping in Attribute class

Parameters:
name - attribute name
value - attribute value

getAttributeNames

public java.lang.String[] getAttributeNames(boolean sorted)
Returns names of attributes, that are set in this resource, as array.

Parameters:
defines - is return array sorted (alphabetically)
Returns:
attribute names

addConnection

public void addConnection(iConnection connection)
Adds connection from this resource, calls method addConnection(boolean, DogmaConnection).

Parameters:
connection - DogmaConnection to be added

addConnection

public void addConnection(boolean tothis,
                          iConnection connection)
Adds a new connection to resource's connections.

Specified by:
addConnection in interface iResource
Parameters:
tothis - true, if connection is directed into this resource
connection - a connection to be added

addUri

public void addUri(java.lang.String uri)
Adds a new uri to resource's uris.

Parameters:
uri - uri - string to be added.

addUri

public void addUri(DogmaURI uri)

removeConnection

public void removeConnection(DogmaConnection c)
Removes connection from this resource, calls method removeConnection(DogmaConnection, boolean).

Parameters:
c - DogmaConnection to be removed

removeConnection

public void removeConnection(DogmaConnection c,
                             boolean toThis)
Removes connection from this resource, decrements toAmount/fromAmount depending of connection's direction.

Parameters:
c - DogmaConnection to be removed
toThis - true, if connection is directed into this resource

removeConnectionFromBoth

public void removeConnectionFromBoth(DogmaConnection c)
Removes connection from this resource, and from the resource that is at another side of connection, if connection contains reference to that resource. With both cases, calls the removeConnection(DogmaConnection, boolean) -method.

Parameters:
c - DogmaConnection to be removed

updateConnection

public void updateConnection(DogmaConnection conn)
This method is meant to be used for updating resources existing connections. If given connection is not already in resource, it is added normally. Connection is classified as found in resource, if its neighbour canoname matches some connection neighbour canoname (first hit).

Parameters:
conn - Connection to updated

changeUris

public void changeUris(int index)
Specified by:
changeUris in interface iResource

getUris

public java.util.Vector<DogmaURI> getUris()
Returns:
resource's @see #uris

addTag

public void addTag(java.lang.String tag)
Adds a new tag to resource's @see #tags

Parameters:
tag - a tag-String to be added

containsTag

public boolean containsTag(java.lang.String tag)
Parameters:
tag - String
Returns:
true, if resource have this tag

removeTag

public void removeTag(java.lang.String tag)
Removes tag from resource's @see #tags, does nothing there isn't such a tag.

Parameters:
tag - a tag to be removed

merge

public void merge(DogmaResource another)
Merges two resources into one

Parameters:
another - DogmaResource to be merged with this resource

split

public DogmaResource[] split(java.util.Vector<DogmaConnection> moveToNew)
Splits this resource in two resources.

Parameters:
moveToNew - A set of Current resource's connections to be moved to new resource
Returns:
array of DogmaResources, where array[0] = current resource, and array[1] = new resource

getConnections

public java.util.Vector<DogmaConnection> getConnections()
Returns:
resource's @see #connections

setConnections

public void setConnections(java.util.Vector<DogmaConnection> connections)
Set resource's connections to be the given set. Adjusts also the fromAmount and toAmount values.

Parameters:
connections - The resource's new connections

getTags

public java.util.HashSet<java.lang.String> getTags()
Returns:
resource's @see #tags

setTags

public void setTags(java.util.HashSet<java.lang.String> tags)
Adds the given tag-set to the resource's @see #tags

Parameters:
tags - new set of tags to resource's tags

setUris

public void setUris(java.util.Vector<DogmaURI> uris)
Set the given DogmaURI-set to be resource's Won't change anything is parameter has only invalid elements.

Parameters:
uris - new DogmaURI set
See Also:
uris

hasUri

public boolean hasUri(java.lang.String uriString)
Returns true if the uri-vector of the resource already has an uri identical to the given uristring.

Parameters:
uriString -
Returns:

hasConnection

public boolean hasConnection(java.lang.String idString)
Returns true if the connectionvector of the resource already has a connection identical to the given identificationstring.

Parameters:
idString -
Returns:

getFromAmount

public int getFromAmount()
Returns:
resource's @see #fromAmount

setFromAmount

public void setFromAmount(int amount)
Parameters:
amount - fromAmount to set

getToAmount

public int getToAmount()
Returns:
resource's @see #toAmount

setToAmount

public void setToAmount(int amount)
Parameters:
amount - toAmount to set

fromX

public int fromX(java.lang.String type)

toX

public int toX(java.lang.String type)

setAttributeAsString

public boolean setAttributeAsString(java.lang.String name,
                                    java.lang.String value)
Sets the given attribute value as it's canonical String-conversion

Parameters:
name - attribute name
value - attribute value as String
Returns:
false, if conversion from String to attribute-type object failed

dateString

public static java.lang.String dateString(java.util.Date date)
Parameters:
date -
Returns:
a DogmaTime-format String representation of Date

setDateAsString

public boolean setDateAsString(java.lang.String name,
                               java.lang.String value)
Sets a new Date value to attribute, if parameter-String is in valid format (otherwise old value will remain).

Parameters:
name - attribute name
s - is assumed to be in format YYYY-MM-DD-hh-mm-ss, or format that is substring of previous starting from index 0. For example 1982-05-12 is valid, it will be converted to String 19820512000000. 1982-5-12 is not valid form.
Returns:
true, if parameter was in valid format and value setting succeeded.

getAttributeValueAsInt

public int getAttributeValueAsInt(java.lang.String name)
Parameters:
name - attribute name
Returns:
INT-typed attribute value as int

getAttributeValueAsString

public java.lang.String getAttributeValueAsString(java.lang.String name)
Parameters:
name - attribute name
Returns:
STRING-typed attribute value as String

getAttributeValueAsDate

public java.util.Date getAttributeValueAsDate(java.lang.String name)
Parameters:
name - attribute name
Returns:
DATE-typed attribute value as java.util.Date

getAttributeValueAsDouble

public double getAttributeValueAsDouble(java.lang.String name)
Parameters:
name - attribute name
Returns:
DOUBLE-typed attribute value as double

getActivity

public int getActivity()
Returns:
Returns the activity.

setActivity

public void setActivity(int activity)
Parameters:
activity - The activity to set.

getAdded

public java.util.Date getAdded()
Returns:
Returns the added.

setAdded

public void setAdded(java.util.Date added)
Specified by:
setAdded in interface iResource
Parameters:
added - The added to set.

getCanoname

public java.lang.String getCanoname()
Specified by:
getCanoname in interface iResource
Returns:
Returns the canoname.

setCanoname

public void setCanoname(java.lang.String canoname)
Parameters:
canoname - The canoname to set.

getCreated

public java.util.Date getCreated()
Returns:
Returns the created.

setCreated

public void setCreated(java.util.Date created)
Specified by:
setCreated in interface iResource
Parameters:
created - The created to set.

getFound

public java.util.Date getFound()
Returns:
Returns the found.

setFound

public void setFound(java.util.Date found)
Parameters:
found - The found to set.

getImported

public java.util.Date getImported()
Returns:
Returns the imported.

setImported

public void setImported(java.util.Date imported)
Parameters:
imported - The imported to set.

getInSourceId

public int getInSourceId()
Returns:
Returns the inSourceId.

setInSourceId

public void setInSourceId(int inSourceId)
Parameters:
inSourceId - The inSourceId to set.

getLoaded

public java.util.Date getLoaded()
Returns:
Returns the loaded.

setLoaded

public void setLoaded(java.util.Date loaded)
Parameters:
loaded - The loaded to set.

getLoads

public int getLoads()
Returns:
Returns the loads.

setLoads

public void setLoads(int loads)
Parameters:
loads - The loads to set.

getName

public java.lang.String getName()
Returns:
Returns the name.

setName

public void setName(java.lang.String name)
Specified by:
setName in interface iResource
Parameters:
name - The name to set.

getRank

public int getRank()
Returns:
Returns the rank.

setRank

public void setRank(int rank)
Parameters:
rank - The rank to set.

getRawName

public java.lang.String getRawName()
Returns:
Returns the rawName.

setRawName

public void setRawName(java.lang.String rawName)
Parameters:
rawName - The rawName to set.

getRecency

public int getRecency()
Returns:
Returns the recency.

setRecency

public void setRecency(int recency)
Parameters:
recency - The recency to set.

getResourceClass

public java.lang.String getResourceClass()
Returns:
Returns the resourceClass.

setResourceClass

public void setResourceClass(java.lang.String resourceClass)
Parameters:
resourceClass - The resourceClass to set.

getSource

public java.lang.String getSource()
Returns:
Returns the source.

setSource

public void setSource(java.lang.String source)
Specified by:
setSource in interface iResource
Parameters:
source - The source to set.

getType

public java.lang.String getType()
Specified by:
getType in interface iResource
Returns:
Returns the type.

setType

public void setType(java.lang.String type)
Parameters:
type - The type to set.

getValue

public int getValue()
Returns:
Returns the value.

setValue

public void setValue(int value)
Parameters:
value - The value to set.

getViewed

public java.util.Date getViewed()
Returns:
Returns the viewed.

setViewed

public void setViewed(java.util.Date viewed)
Parameters:
viewed - The viewed to set.

getViews

public int getViews()
Returns:
Returns the views.

setViews

public void setViews(int views)
Parameters:
views - The views to set.

getAttributeList

public static java.lang.String[] getAttributeList()
Returns the attribute-names used.


parseTags

public static java.util.HashSet<java.lang.String> parseTags(java.lang.String tagText)
Parses tags from String, where tags are separated by tagSeparator

Parameters:
tagText -
Returns:
set of tags

incrementAttribute

public void incrementAttribute(java.lang.String name)
Method for incrementing some int-attributes, like loads. Does nothing if there is no such name attribute, or it is not int-attribute, or it's value is null.

Parameters:
name - attribute name

setImmutableDateAttribute

public void setImmutableDateAttribute(java.lang.String name,
                                      java.util.Date time)
Sets a Date value to DATE-attribute if previous value is null, otherwise does nothing.

Parameters:
name - attribute name
time - The Date to set