org.jaudiotagger.audio.asf.data
Class MetadataContainer

java.lang.Object
  extended by org.jaudiotagger.audio.asf.data.Chunk
      extended by org.jaudiotagger.audio.asf.data.MetadataContainer
All Implemented Interfaces:
WriteableChunk
Direct Known Subclasses:
ContentBranding, ContentDescription

public class MetadataContainer
extends Chunk
implements WriteableChunk

This structure represents the "Metadata Object","Metadata Library Object" and "Extended Content Description".

Author:
Christian Laireiter

Nested Class Summary
private static class MetadataContainer.DescriptorPointer
          This class is used to uniquely identify an enclosed descriptor by its name, language index and stream number.
The type of the descriptor is ignored, since it just specifies the data content.
 
Field Summary
private  ContainerType containerType
          stores the represented container type.
private  java.util.Map<MetadataContainer.DescriptorPointer,java.util.List<MetadataDescriptor>> descriptors
          Stores the descriptors.
private  MetadataContainer.DescriptorPointer perfPoint
          for performance reasons this instance is used to look up existing descriptors in descriptors.
 
Fields inherited from class org.jaudiotagger.audio.asf.data.Chunk
chunkLength, guid, position
 
Constructor Summary
MetadataContainer(ContainerType type)
          Creates an instance.
MetadataContainer(ContainerType type, long pos, java.math.BigInteger size)
          Creates an instance.
MetadataContainer(GUID containerGUID, long pos, java.math.BigInteger size)
          Creates an instance.
 
Method Summary
 void addDescriptor(MetadataDescriptor toAdd)
          Adds a metadata descriptor.
protected  MetadataDescriptor assertDescriptor(java.lang.String key)
          This method asserts that this container has a descriptor with the specified key, means returns an existing or creates a new descriptor.
protected  MetadataDescriptor assertDescriptor(java.lang.String key, int type)
          This method asserts that this container has a descriptor with the specified key, means returns an existing or creates a new descriptor.
 boolean containsDescriptor(MetadataDescriptor lookup)
          Checks whether a descriptor already exists.
Name, stream number and language index are compared.
private static ContainerType determineType(GUID guid)
          Looks up all guids and returns the matching type.
 ContainerType getContainerType()
          Returns the type of container this instance represents.
 long getCurrentAsfChunkSize()
          This method calculates the total amount of bytes, the chunk would consume in an ASF file.
 int getDescriptorCount()
          Returns the number of contained descriptors.
 java.util.List<MetadataDescriptor> getDescriptors()
          Returns all stored descriptors.
 java.util.List<MetadataDescriptor> getDescriptorsByName(java.lang.String name)
          Returns a list of descriptors with the given name.
protected  java.lang.String getValueFor(java.lang.String name)
          This method looks up a descriptor with given name and returns its value as string.
 boolean hasDescriptor(java.lang.String name)
          Determines if this container contains a descriptor with given name.
 boolean isAddSupported(MetadataDescriptor descriptor)
          Determines/checks if the given descriptor may be added to the container.
This implies a check for the capabilities of the container specified by its container type.
 boolean isEmpty()
          true if it is not necessary to write the chunk into an ASF file, since it contains no information.
 java.lang.String prettyPrint(java.lang.String prefix)
          This method creates a String containing useful information prepared to be printed on STD-OUT.
 void removeDescriptorsByName(java.lang.String name)
          Removes all stored descriptors with the given name.
protected  void setStringValue(java.lang.String name, java.lang.String value)
          asserts the existence of a descriptor with given name and assings the string value.
 long writeInto(java.io.OutputStream out)
          Writes the chunk into the specified output stream, as ASF stream chunk.
 
Methods inherited from class org.jaudiotagger.audio.asf.data.Chunk
getChunckEnd, getChunkEnd, getChunkLength, getGuid, getPosition, setPosition, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.jaudiotagger.audio.asf.io.WriteableChunk
getGuid
 

Field Detail

containerType

private final ContainerType containerType
stores the represented container type.


descriptors

private final java.util.Map<MetadataContainer.DescriptorPointer,java.util.List<MetadataDescriptor>> descriptors
Stores the descriptors.


perfPoint

private final MetadataContainer.DescriptorPointer perfPoint
for performance reasons this instance is used to look up existing descriptors in descriptors.

Constructor Detail

MetadataContainer

public MetadataContainer(ContainerType type)
Creates an instance.

Parameters:
type - determines the type of the container

MetadataContainer

public MetadataContainer(ContainerType type,
                         long pos,
                         java.math.BigInteger size)
Creates an instance.

Parameters:
type - determines the type of the container
pos - location in the ASF file
size - size of the chunk.

MetadataContainer

public MetadataContainer(GUID containerGUID,
                         long pos,
                         java.math.BigInteger size)
Creates an instance.

Parameters:
containerGUID - the containers GUID
pos - location in the ASF file
size - size of the chunk.
Method Detail

determineType

private static ContainerType determineType(GUID guid)
                                    throws java.lang.IllegalArgumentException
Looks up all guids and returns the matching type.

Parameters:
guid - GUID to look up
Returns:
matching container type.
Throws:
java.lang.IllegalArgumentException - if no container type matches

addDescriptor

public final void addDescriptor(MetadataDescriptor toAdd)
                         throws java.lang.IllegalArgumentException
Adds a metadata descriptor.

Parameters:
toAdd - the descriptor to add.
Throws:
java.lang.IllegalArgumentException - if descriptor does not meet container requirements, or already exist.

assertDescriptor

protected final MetadataDescriptor assertDescriptor(java.lang.String key)
This method asserts that this container has a descriptor with the specified key, means returns an existing or creates a new descriptor.

Parameters:
key - the descriptor name to look up (or create)
Returns:
the/a descriptor with the specified name (and initial type of MetadataDescriptor.TYPE_STRING.

assertDescriptor

protected final MetadataDescriptor assertDescriptor(java.lang.String key,
                                                    int type)
This method asserts that this container has a descriptor with the specified key, means returns an existing or creates a new descriptor.

Parameters:
key - the descriptor name to look up (or create)
type - if the descriptor is created, this data type is applied.
Returns:
the/a descriptor with the specified name.

containsDescriptor

public final boolean containsDescriptor(MetadataDescriptor lookup)
Checks whether a descriptor already exists.
Name, stream number and language index are compared. Data and data type are ignored.

Parameters:
lookup - descriptor to look up.
Returns:
true if such a descriptor already exists.

getContainerType

public final ContainerType getContainerType()
Returns the type of container this instance represents.

Returns:
represented container type.

getCurrentAsfChunkSize

public long getCurrentAsfChunkSize()
This method calculates the total amount of bytes, the chunk would consume in an ASF file.

Specified by:
getCurrentAsfChunkSize in interface WriteableChunk
Returns:
amount of bytes the chunk would currently need in an ASF file.

getDescriptorCount

public final int getDescriptorCount()
Returns the number of contained descriptors.

Returns:
number of descriptors.

getDescriptors

public final java.util.List<MetadataDescriptor> getDescriptors()
Returns all stored descriptors.

Returns:
stored descriptors.

getDescriptorsByName

public final java.util.List<MetadataDescriptor> getDescriptorsByName(java.lang.String name)
Returns a list of descriptors with the given name.

Parameters:
name - name of the descriptors to return
Returns:
list of descriptors with given name.

getValueFor

protected final java.lang.String getValueFor(java.lang.String name)
This method looks up a descriptor with given name and returns its value as string.

Parameters:
name - the name of the descriptor to look up.
Returns:
the string representation of a found descriptors value. Even an empty string if no descriptor has been found.

hasDescriptor

public final boolean hasDescriptor(java.lang.String name)
Determines if this container contains a descriptor with given name.

Parameters:
name - Name of the descriptor to look for.
Returns:
true if descriptor has been found.

isAddSupported

public boolean isAddSupported(MetadataDescriptor descriptor)
Determines/checks if the given descriptor may be added to the container.
This implies a check for the capabilities of the container specified by its container type.

Parameters:
descriptor - the descriptor to test.
Returns:
true if addDescriptor(MetadataDescriptor) can be called with given descriptor.

isEmpty

public final boolean isEmpty()
true if it is not necessary to write the chunk into an ASF file, since it contains no information.

Specified by:
isEmpty in interface WriteableChunk
Returns:
true if no useful data will be preserved.

prettyPrint

public java.lang.String prettyPrint(java.lang.String prefix)
This method creates a String containing useful information prepared to be printed on STD-OUT.
This method is intended to be overwritten by inheriting classes.

Overrides:
prettyPrint in class Chunk
Parameters:
prefix - each line gets this string prepended.
Returns:
Information of current Chunk Object.

removeDescriptorsByName

public final void removeDescriptorsByName(java.lang.String name)
Removes all stored descriptors with the given name.

Parameters:
name - the name to remove.

setStringValue

protected final void setStringValue(java.lang.String name,
                                    java.lang.String value)
asserts the existence of a descriptor with given name and assings the string value.

Parameters:
name - the name of the descriptor to set the value for.
value - the string value.

writeInto

public long writeInto(java.io.OutputStream out)
               throws java.io.IOException
Writes the chunk into the specified output stream, as ASF stream chunk.

Specified by:
writeInto in interface WriteableChunk
Parameters:
out - stream to write into.
Returns:
amount of bytes written.
Throws:
java.io.IOException - on I/O errors