edu.nrao.sss.model.resource
Class Resource

java.lang.Object
  extended by edu.nrao.sss.model.resource.Resource
All Implemented Interfaces:
CatalogItem<Resource>, NameableCatalogItem<Resource>, Identifiable, Nameable, Cloneable

public class Resource
extends Object
implements NameableCatalogItem<Resource>, Identifiable

A container of scientific and hardware specifications for an observation of of an astronomical source.

Version Info:

$Revision: 2234 $
$Date: 2009-04-23 14:16:36 -0600 (Thu, 23 Apr 2009) $
$Author: dharland $ (last person to modify)

Since:
2006-02-24
Author:
David M. Harland

Field Summary
 
Fields inherited from interface edu.nrao.sss.util.Identifiable
UNIDENTIFIED
 
Constructor Summary
Resource()
          Creates a new instance.
Resource(String name)
          Creates a new instance with the given name.
 
Method Summary
 void clearId()
          Resets the identifier of this resource to a value that represents the unidentified state.
 Resource clone()
          Returns a resource that is a copy of this one.
 boolean equals(Object o)
          Returns true if o is equal to this resource.
static Resource fromXml(Reader reader)
          Creates a new resource based on the XML data read from reader.
static Resource fromXml(String xmlFile)
          Creates a new resource from the XML data in the given file.
 AntennaElectronics getAntennaElectronics()
          Returns antenna electronics that are configured to match this resource.
 TelescopeBackend getBackend(CorrelatorName backendType)
          Returns the backend of the given type held by this resource.
 List<TelescopeBackend> getBackends()
          Returns a list of the backends currently held by this resource.
 Long getCreatedBy()
           
 Date getCreatedOn()
           
 Long getId()
           
 Long getLastUpdatedBy()
           
 Date getLastUpdatedOn()
           
 String getName()
          Returns the name of this resource.
 List<String> getNotes()
          Returns a list of notes about this resource.
 ResourceSpecification getScienceSpecification()
          Returns the scientific specification for this resource.
 TelescopeType getTelescope()
          Returns the telescope whose setup is described by this specification.
 int hashCode()
          Returns a hash code value for this resource.
 boolean hasScienceSpecification()
          Returns true if this resource has a non-empty scientific specification.
 TelescopeBackend removeBackend(CorrelatorName backendType)
          Removes from this resource the backend of the given type.
 List<TelescopeBackend> removeBackends()
          Removes all backends from this resource.
 void reset()
          Resets this resource to its initial state.
 void setCreatedBy(Long userId)
           
 void setCreatedOn(Date d)
           
 void setLastUpdatedBy(Long userId)
           
 void setLastUpdatedOn(Date d)
           
 void setName(String newName)
          Sets the name of this resource.
 void setScienceSpecification(ResourceSpecification newSpec)
          Sets the scientific specification for this resource.
 void setTelescope(TelescopeType newTelescope)
          Sets the telescope whose setup is described by this specification.
 String toXml()
          Returns an XML representation of this resource.
 void writeAsXmlTo(Writer writer)
          Writes an XML representation of this resource to writer.
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Resource

public Resource()
Creates a new instance.


Resource

public Resource(String name)
Creates a new instance with the given name.

Method Detail

reset

public void reset()
Resets this resource to its initial state. A reset resource has the same state as a new resource.


getId

public Long getId()
Specified by:
getId in interface Identifiable

clearId

public void clearId()
Resets the identifier of this resource to a value that represents the unidentified state.

This method is useful for preparing a resource 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 object for the first time, you may need to call this method before performing a save. This is especially true if you have created this object from XML, as the XML unmarshalling brings along the ID property.


setName

public void setName(String newName)
Sets the name of this resource.

If newName is null or the empty string (""), the request to change the name will be denied and the current name will remain in place.

Specified by:
setName in interface Nameable
Parameters:
newName - the new name of this resource.

getName

public String getName()
Returns the name of this resource.

Specified by:
getName in interface Nameable
Returns:
the name of this resource.

setCreatedBy

public void setCreatedBy(Long userId)

setCreatedOn

public void setCreatedOn(Date d)

setLastUpdatedBy

public void setLastUpdatedBy(Long userId)

setLastUpdatedOn

public void setLastUpdatedOn(Date d)

getCreatedBy

public Long getCreatedBy()

getCreatedOn

public Date getCreatedOn()

getLastUpdatedBy

public Long getLastUpdatedBy()

getLastUpdatedOn

public Date getLastUpdatedOn()

setScienceSpecification

public void setScienceSpecification(ResourceSpecification newSpec)
Sets the scientific specification for this resource.

Parameters:
newSpec - the scientific specification for this resource. If this value is null it will be replaced by a new empty specification.

getScienceSpecification

public ResourceSpecification getScienceSpecification()
Returns the scientific specification for this resource.

Returns:
the scientific specification for this resource.

hasScienceSpecification

public boolean hasScienceSpecification()
Returns true if this resource has a non-empty scientific specification. A "non-empty" specification is one that has at least one subspecification (pulsar, sky frequency, or spectral line).

Returns:
true if this resource has a non-empty scientific specification.

setTelescope

public void setTelescope(TelescopeType newTelescope)
Sets the telescope whose setup is described by this specification.

SIDE EFFECTS: changing the telescope type also changes the antenna electronics held by this resource, and may change the backend as well.

Parameters:
newTelescope - the telescope whose setup is described by this specification. If this value is null a default telescope will be used instead.

getTelescope

public TelescopeType getTelescope()
Returns the telescope whose setup is described by this specification.

Returns:
the telescope whose setup is described by this specification.

getAntennaElectronics

public AntennaElectronics getAntennaElectronics()
Returns antenna electronics that are configured to match this resource.

Returns:
the antenna electronics used by this resource.

getBackend

public TelescopeBackend getBackend(CorrelatorName backendType)
Returns the backend of the given type held by this resource. If this resource does not currently have a backend of this type, one is created -- so long at it is a valid backend for this resource's telescope -- and returned.

The returned backend is the one held directly by this resource, so changes made to it will be reflected herein.

Parameters:
backendType - the type of backend desired.
Returns:
the backend of the given type held by this resource.
Throws:
IllegalArgumentException - if backendType is not a valid backend for this resource's telescope.
See Also:
setTelescope(TelescopeType), TelescopeType.getBackendTypes()

getBackends

public List<TelescopeBackend> getBackends()
Returns a list of the backends currently held by this resource. The returned list is not held directly by this resource, so changes to it will not be reflected herein. The objects in the list, however, are the actual backends held by this resource, so changes to those will affect this resource.

Returns:
a list of the backends currently held by this resource.
See Also:
getBackend(CorrelatorName)

removeBackend

public TelescopeBackend removeBackend(CorrelatorName backendType)
Removes from this resource the backend of the given type.

Parameters:
backendType - the type of backend to remove from this resource.
Returns:
the backend of the given type formerly held by this resource, or null if this resource had no such backend at the time this method was called.

removeBackends

public List<TelescopeBackend> removeBackends()
Removes all backends from this resource.

Returns:
the list of backends formerly held by this resource. The returned list will never be null but could be empty.

getNotes

public List<String> getNotes()
Returns a list of notes about this resource. Each note is free-form text with no particular structure.

This method returns the list actually held by this Resource, so any list manipulations may be performed by first fetching the list and then operating on it.

Returns:
a list of notes about this resource.

toXml

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

Returns:
an XML representation of this resource.
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 resource to writer.

Parameters:
writer - the device to which XML is written.
Throws:
JAXBException - if anything goes wrong during the conversion to XML.

fromXml

public static Resource fromXml(String xmlFile)
                        throws JAXBException,
                               XMLStreamException,
                               FileNotFoundException
Creates a new resource 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 resource 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 Resource fromXml(Reader reader)
                        throws JAXBException,
                               XMLStreamException
Creates a new resource 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 resource 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.

clone

public Resource clone()
Returns a resource that is a copy of this one.

If anything goes wrong during the cloning procedure, a RuntimeException will be thrown.

Specified by:
clone in interface CatalogItem<Resource>
Overrides:
clone in class Object

equals

public boolean equals(Object o)
Returns true if o is equal to this resource.

Overrides:
equals in class Object

hashCode

public int hashCode()
Returns a hash code value for this resource.

Overrides:
hashCode in class Object


Copyright © 2009. All Rights Reserved.