Methods Summary |
---|
public final void | addDescriptor(MetadataDescriptor toAdd)Adds a metadata descriptor.
// check with throwing exceptions
this.containerType.assertConstraints(toAdd.getName(), toAdd
.getRawData(), toAdd.getType(), toAdd.getStreamNumber(), toAdd
.getLanguageIndex());
// validate containers capabilities
if (!isAddSupported(toAdd)) {
throw new IllegalArgumentException(
"Descriptor cannot be added, see isAddSupported(...)");
}
/*
* Check for containers types capabilities.
*/
// Search for descriptor list by name, language and stream.
List<MetadataDescriptor> list;
synchronized (this.perfPoint) {
list = this.descriptors.get(this.perfPoint.setDescriptor(toAdd));
}
if (list == null) {
list = new ArrayList<MetadataDescriptor>();
this.descriptors.put(new DescriptorPointer(toAdd), list);
} else {
if (!list.isEmpty() && !this.containerType.isMultiValued()) {
throw new IllegalArgumentException(
"Container does not allow multiple values of descriptors with same name, language index and stream number");
}
}
list.add(toAdd);
|
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.
return assertDescriptor(key, MetadataDescriptor.TYPE_STRING);
|
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.
MetadataDescriptor desc;
final List<MetadataDescriptor> descriptorsByName = getDescriptorsByName(key);
if (descriptorsByName == null || descriptorsByName.isEmpty()) {
desc = new MetadataDescriptor(getContainerType(), key, type);
addDescriptor(desc);
} else {
desc = descriptorsByName.get(0);
}
return desc;
|
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.
assert lookup != null;
return this.descriptors.containsKey(this.perfPoint
.setDescriptor(lookup));
|
private static ContainerType | determineType(GUID guid)Looks up all {@linkplain ContainerType#getContainerGUID() guids} and
returns the matching type.
assert guid != null;
ContainerType result = null;
for (final ContainerType curr : ContainerType.values()) {
if (curr.getContainerGUID().equals(guid)) {
result = curr;
break;
}
}
if (result == null) {
throw new IllegalArgumentException(
"Unknown metadata container specified by GUID ("
+ guid.toString() + ")");
}
return result;
|
public final ContainerType | getContainerType()Returns the type of container this instance represents.
return this.containerType;
|
public long | getCurrentAsfChunkSize(){@inheritDoc}
/*
* 16 bytes GUID, 8 bytes chunk size, 2 bytes descriptor count
*/
long result = 26;
for (final MetadataDescriptor curr : getDescriptors()) {
result += curr.getCurrentAsfSize(this.containerType);
}
return result;
|
public final int | getDescriptorCount()Returns the number of contained descriptors.
return this.getDescriptors().size();
|
public final java.util.List | getDescriptors()Returns all stored descriptors.
final List<MetadataDescriptor> result = new ArrayList<MetadataDescriptor>();
for (final List<MetadataDescriptor> curr : this.descriptors.values()) {
result.addAll(curr);
}
return result;
|
public final java.util.List | getDescriptorsByName(java.lang.String name)Returns a list of descriptors with the given
{@linkplain MetadataDescriptor#getName() name}.
assert name != null;
final List<MetadataDescriptor> result = new ArrayList<MetadataDescriptor>();
final Collection<List<MetadataDescriptor>> values = this.descriptors
.values();
for (final List<MetadataDescriptor> currList : values) {
if (!currList.isEmpty() && currList.get(0).getName().equals(name)) {
result.addAll(currList);
}
}
return result;
|
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.
String result = "";
final List<MetadataDescriptor> descs = getDescriptorsByName(name);
if (descs != null) {
assert descs.size() <= 1;
if (!descs.isEmpty()) {
result = descs.get(0).getString();
}
}
return result;
|
public final boolean | hasDescriptor(java.lang.String name)Determines if this container contains a descriptor with given
{@linkplain MetadataDescriptor#getName() name}.
return !getDescriptorsByName(name).isEmpty();
|
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 {@linkplain #getContainerType() container type}.
boolean result = getContainerType().checkConstraints(
descriptor.getName(), descriptor.getRawData(),
descriptor.getType(), descriptor.getStreamNumber(),
descriptor.getLanguageIndex()) == null;
// Now check if there is already a value contained.
if (result && !getContainerType().isMultiValued()) {
synchronized (this.perfPoint) {
final List<MetadataDescriptor> list = this.descriptors
.get(this.perfPoint.setDescriptor(descriptor));
if (list != null) {
result = list.isEmpty();
}
}
}
return result;
|
public final boolean | isEmpty(){@inheritDoc}
boolean result = true;
if (getDescriptorCount() != 0) {
final Iterator<MetadataDescriptor> iterator = getDescriptors()
.iterator();
while (result && iterator.hasNext()) {
result &= iterator.next().isEmpty();
}
}
return result;
|
public java.lang.String | prettyPrint(java.lang.String prefix){@inheritDoc}
final StringBuilder result = new StringBuilder(super.prettyPrint(prefix));
for (final MetadataDescriptor curr : getDescriptors()) {
result.append(prefix).append(" |-> ");
result.append(curr);
result.append(Utils.LINE_SEPARATOR);
}
return result.toString();
|
public final void | removeDescriptorsByName(java.lang.String name)Removes all stored descriptors with the given
{@linkplain MetadataDescriptor#getName() name}.
assert name != null;
final Iterator<List<MetadataDescriptor>> iterator = this.descriptors
.values().iterator();
while (iterator.hasNext()) {
final List<MetadataDescriptor> curr = iterator.next();
if (!curr.isEmpty() && curr.get(0).getName().equals(name)) {
iterator.remove();
}
}
|
protected final void | setStringValue(java.lang.String name, java.lang.String value){@linkplain #assertDescriptor(String) asserts} the existence of a
descriptor with given name and
{@linkplain MetadataDescriptor#setStringValue(String) assings} the string
value.
assertDescriptor(name).setStringValue(value);
|
public long | writeInto(java.io.OutputStream out){@inheritDoc}
final long chunkSize = getCurrentAsfChunkSize();
final List<MetadataDescriptor> descriptorList = getDescriptors();
out.write(getGuid().getBytes());
Utils.writeUINT64(chunkSize, out);
Utils.writeUINT16(descriptorList.size(), out);
for (final MetadataDescriptor curr : descriptorList) {
curr.writeInto(out, this.containerType);
}
return chunkSize;
|