edu.nrao.sss.model.resource
Class ResourceCatalog

java.lang.Object
  extended by edu.nrao.sss.catalog.Catalog<Resource,ResourceGroup,ResourceCatalog>
      extended by edu.nrao.sss.model.resource.ResourceCatalog
All Implemented Interfaces:
CatalogItemGroupListener<Resource,ResourceGroup,ResourceCatalog>, ResourceProvider, UserAccountable, Identifiable, Cloneable

public class ResourceCatalog
extends Catalog<Resource,ResourceGroup,ResourceCatalog>
implements Identifiable, UserAccountable, ResourceProvider

A catalog of Resources.

Each entry in a resource catalog is a Resource. This catalog also supports the notion of ResourceGroups, which serve to associate resources with similar traits with one another.

Version Info:

$Revision: 1709 $
$Date: 2008-11-14 11:22:37 -0700 (Fri, 14 Nov 2008) $
$Author: dharland $ (last person to modify)

Since:
2006-10-20
Author:
David M. Harland

Field Summary
 
Fields inherited from interface edu.nrao.sss.util.Identifiable
UNIDENTIFIED
 
Fields inherited from interface edu.nrao.sss.model.UserAccountable
NULL_USER_ID
 
Constructor Summary
ResourceCatalog()
          Creates a new catalog with a default name.
ResourceCatalog(String nameOfCatalog)
          Creates a new catalog with the given name.
 
Method Summary
 void clearId()
          Resets this catalog's ID, and the IDs of all its contents, to a value that represents the unidentified state.
 ResourceCatalog clone()
           
 ResourceGroup createGroup()
           
protected  ResourceGroup createMainGroup()
           
 Resource findResourceById(long id)
          Returns the Resource with the given id, if any.
 List<Resource> findResourceByName(String name)
          Returns the Resource(s) with the given name, if any.
static ResourceCatalog fromXml(Reader reader)
          Creates a new catalog based on the XML data read from reader.
static ResourceCatalog fromXml(String xmlFile)
          Creates a new catalog from the XML data in the given file.
 List<Resource> getAllResources()
          Returns a list of all resources held by this provider.
 Long getCreatedBy()
          Returns the ID of the user who created this object.
 Date getCreatedOn()
          Returns the date on which this object was created.
protected  long getIdOfUnidentified()
          Returns Identifiable.UNIDENTIFIED.
 Long getLastUpdatedBy()
          Returns the ID of the user who most recently updated this object.
 Date getLastUpdatedOn()
          Returns the most recent date on which this object was updated.
 Long getOwner()
          Returns the ID of the user who owns this catalog.
 void setCreatedBy(Long userId)
          Sets the ID of the user who created this object.
 void setCreatedOn(Date d)
          Sets the date on which this object was created.
 void setLastUpdatedBy(Long userId)
          Sets the ID of the user who most recently updated this object.
 void setLastUpdatedOn(Date d)
          Sets the date on which this object was most recently updated.
 void setOwner(Long userId)
          Sets the ID of the user who owns this catalog.
 String toXml()
          Returns an XML representation of this catalog.
 void writeAsXmlTo(Writer writer)
          Writes an XML representation of this catalog to writer.
 
Methods inherited from class edu.nrao.sss.catalog.Catalog
addGroup, addGroup, addGroups, addGroups, addItem, addItem, addItemEvenIfEqualToCurrentItem, addItemEvenIfEqualToCurrentItem, addItems, addItems, addListener, clear, contains, containsGroupNamed, decrementIndexOfGroup, decrementIndexOfGroupAt, decrementIndexOfItem, decrementIndexOfItemAt, equals, getGroup, getGroup, getGroups, getGroupsThatContain, getId, getInternalGroupList, getInternalItemList, getItem, getItems, getName, getNotes, getReservedGroupName, hashCode, incrementIndexOfGroup, incrementIndexOfGroupAt, incrementIndexOfItem, incrementIndexOfItemAt, indexOf, lastIndexOf, memberAdded, memberMoved, memberRemoved, memberReplaced, membersSorted, moveGroup, moveGroup, moveItem, moveItem, removeAllGroups, removeAllItems, removeAllListeners, removeGroup, removeGroup, removeItem, removeItem, removeListener, setId, setInternalGroupList, setInternalItemList, setName, setReservedGroupName, size, sort, sortGroups, swapGroups, swapItems, tellListenersAboutFormerGroup, tellListenersAboutMovedGroup, tellListenersAboutNewGroup, toGroup, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface edu.nrao.sss.util.Identifiable
getId
 

Constructor Detail

ResourceCatalog

public ResourceCatalog()
Creates a new catalog with a default name.


ResourceCatalog

public ResourceCatalog(String nameOfCatalog)
Creates a new catalog with the given name.

Parameters:
nameOfCatalog - the name of this catalog. If this value is null, this catalog will be given a default name.
Method Detail

getIdOfUnidentified

protected long getIdOfUnidentified()
Returns Identifiable.UNIDENTIFIED.

Overrides:
getIdOfUnidentified in class Catalog<Resource,ResourceGroup,ResourceCatalog>

createMainGroup

protected ResourceGroup createMainGroup()
Specified by:
createMainGroup in class Catalog<Resource,ResourceGroup,ResourceCatalog>

createGroup

public ResourceGroup createGroup()
Specified by:
createGroup in class Catalog<Resource,ResourceGroup,ResourceCatalog>

clearId

public void clearId()
Resets this catalog's ID, and the IDs of all its contents, to a value that represents the unidentified state.

This method is useful for preparing a catalog for storage in a database. The ID property (as of now, though this may change in the future) is used by our persistence mechanism to identify objects. If you are persisting this catalog for the first time, you may need to call this method before performing a save. This is especially true if you have created this source from XML, as the XML unmarshalling brings along the ID property.

Overrides:
clearId in class Catalog<Resource,ResourceGroup,ResourceCatalog>

setOwner

public void setOwner(Long userId)
Sets the ID of the user who owns this catalog.

Parameters:
userId - the ID of the user who owns this catalog. If this value is null it will be replaced with UserAccountable.NULL_USER_ID.

setCreatedBy

public void setCreatedBy(Long userId)
Description copied from interface: UserAccountable
Sets the ID of the user who created this object.

If userId is null, this object will be updated not with null but with UserAccountable.NULL_USER_ID instead.

Specified by:
setCreatedBy in interface UserAccountable
Parameters:
userId - the ID of the user who most recently updated this object.

setCreatedOn

public void setCreatedOn(Date d)
Description copied from interface: UserAccountable
Sets the date on which this object was created.

If d is null it will be ignored and this method will do nothing.

Specified by:
setCreatedOn in interface UserAccountable
Parameters:
d - the date on which this object was created.

setLastUpdatedBy

public void setLastUpdatedBy(Long userId)
Description copied from interface: UserAccountable
Sets the ID of the user who most recently updated this object.

If userId is null, this object will be updated not with null but with UserAccountable.NULL_USER_ID instead.

Specified by:
setLastUpdatedBy in interface UserAccountable
Parameters:
userId - the ID of the user who most recently updated this object.

setLastUpdatedOn

public void setLastUpdatedOn(Date d)
Description copied from interface: UserAccountable
Sets the date on which this object was most recently updated.

If d is null it will be ignored and this method will do nothing.

Specified by:
setLastUpdatedOn in interface UserAccountable
Parameters:
d - the date on which this object was most recently updated.

getOwner

public Long getOwner()
Returns the ID of the user who owns this catalog.

Returns:
the ID of the user who owns this catalog.

getCreatedBy

public Long getCreatedBy()
Description copied from interface: UserAccountable
Returns the ID of the user who created this object.

If this object does not know the identity of the user who created it, the returned ID will be UserAccountable.NULL_USER_ID.

Specified by:
getCreatedBy in interface UserAccountable
Returns:
the ID of the user who created this object.

getCreatedOn

public Date getCreatedOn()
Description copied from interface: UserAccountable
Returns the date on which this object was created.

Specified by:
getCreatedOn in interface UserAccountable
Returns:
the date on which this object was created.

getLastUpdatedBy

public Long getLastUpdatedBy()
Description copied from interface: UserAccountable
Returns the ID of the user who most recently updated this object.

If this object does not know the identity of the user who lasted updated it, the returned ID will be UserAccountable.NULL_USER_ID.

Specified by:
getLastUpdatedBy in interface UserAccountable
Returns:
the ID of the user who most recently updated this object.

getLastUpdatedOn

public Date getLastUpdatedOn()
Description copied from interface: UserAccountable
Returns the most recent date on which this object was updated.

Specified by:
getLastUpdatedOn in interface UserAccountable
Returns:
the most recent date on which this object was updated.

findResourceById

public Resource findResourceById(long id)
                          throws RepositoryException
Returns the Resource with the given id, if any.

If this provider holds no Resource with an ID of id, null is returned.

Specified by:
findResourceById in interface ResourceProvider
Parameters:
id - the identifier (primary key) for a Resource in this repository.
Returns:
The Resource with the given id, or null, if this provider holds no such Resource.
Throws:
RepositoryException - if anything goes wrong while trying to fetch resources from this provider.

findResourceByName

public List<Resource> findResourceByName(String name)
                                  throws RepositoryException
Returns the Resource(s) with the given name, if any.

Ideally, the returned list will contain only one resource. However, since the name is not usually used as a primary key to a resource, it is possible that the returned list may contain more than one resource. If this provider holds no Resource with a name of name, the returned list will be empty.

Specified by:
findResourceByName in interface ResourceProvider
Parameters:
name - the name of a Resource requested from this provider.
Returns:
The Resources with the given name, or null, if this provider holds no such Resource.
Throws:
RepositoryException - if anything goes wrong while trying to fetch resources from this provider.

getAllResources

public List<Resource> getAllResources()
                               throws RepositoryException
Returns a list of all resources held by this provider.

Specified by:
getAllResources in interface ResourceProvider
Returns:
a list of all resources held by this provider. If the provider has no resources the returned list will be empty.
Throws:
RepositoryException - if anything goes wrong while trying to fetch resources from this provider.

fromXml

public static ResourceCatalog fromXml(String xmlFile)
                               throws JAXBException,
                                      XMLStreamException,
                                      FileNotFoundException
Creates a new catalog from the XML data in the given file.

Parameters:
xmlFile - the name of an XML file. This method will attempt to locate the file by using Class.getResource(String).
Returns:
a new catalog from the XML data in the given file.
Throws:
FileNotFoundException - if the XML file cannot be found.
JAXBException - if the schema file used (if any) is malformed, if the XML file cannot be read, or if the XML file is not schema-valid.
XMLStreamException - if there is a problem opening the XML file, if the XML is not well-formed, or for some other "unexpected processing conditions".

fromXml

public static ResourceCatalog fromXml(Reader reader)
                               throws JAXBException,
                                      XMLStreamException
Creates a new catalog based on the XML data read from reader.

Parameters:
reader - the source of the XML data. If this value is null, null is returned.
Returns:
a new catalog based on the XML data read from reader.
Throws:
XMLStreamException - if the XML is not well-formed, or for some other "unexpected processing conditions".
JAXBException - if anything else goes wrong during the transformation.

toXml

public String toXml()
             throws JAXBException
Returns an XML representation of this catalog.

Overrides:
toXml in class Catalog<Resource,ResourceGroup,ResourceCatalog>
Returns:
an XML representation of this catalog.
Throws:
JAXBException - if anything goes wrong during the conversion to XML.

writeAsXmlTo

public void writeAsXmlTo(Writer writer)
                  throws JAXBException
Writes an XML representation of this catalog to writer.

Overrides:
writeAsXmlTo in class Catalog<Resource,ResourceGroup,ResourceCatalog>
Parameters:
writer - the device to which XML is written.
Throws:
JAXBException - if anything goes wrong during the conversion to XML.

clone

public ResourceCatalog clone()
Overrides:
clone in class Catalog<Resource,ResourceGroup,ResourceCatalog>


Copyright © 2009. All Rights Reserved.