org.ow2.weblab.core.extended.factory
Class SegmentFactory

java.lang.Object
  extended by org.ow2.weblab.core.extended.factory.SegmentFactory

public class SegmentFactory
extends java.lang.Object

To create Segments we strongly encourage to use this class. It will enable the creation of a Segment having an URI compliant with the WebLabRI recommendations.
Since an Segment hasn't any sense without being attached to a MediaUnit, we only provide a method for creating Segment s that takes a MediaUnit in parameter. As a result, the created Segment (an instance of the Segment class in parameter) is added to the Segment List of the MediaUnit.

Author:
Cassidian WebLab Team
Date:
2008-01-18

Field Summary
protected static java.util.Map<java.lang.String,java.util.Set<java.lang.String>> innerMap
          This data structure is not well adapted to manage WebLab Resource
 
Method Summary
protected static void addAnnotation(Annotation annotation, Resource resource, Resource root)
           
protected static void addChild(MediaUnit mu, Document parent)
           
protected static void addChild(MediaUnit mu, Resource parent, Resource root)
          Deprecated. since model 1.2, no need to separates root and parent. replaced by addChild(final MediaUnit mu, final Document parent)
protected static void addDescriptor(LowLevelDescriptor descriptor, Resource parent, Resource root)
           
protected static void addSegment(Segment segment, MediaUnit parent, Resource root)
           
protected static void cleanMapping(java.lang.String uri)
           
static LinearSegment createAndLinkLinearSegment(Text text, int start, int end)
          Looks in text if a LinearSegment already exists at start and end.
static LinearSegment createAndLinkLinearSegment(Text text, int start, int end, boolean enableCollocatedSegment)
          Creates a LinearSegment at start and end, or returns an existing one.
static LinearSegment createAndLinkLinearSegment(TrackSegment track, int start, int end)
           
static
<T extends Segment>
T
createAndLinkSegment(MediaUnit mediaUnit, java.lang.Class<T> segClass)
          Automatically set a valid WebLabRI to the created Segment using the MediaUnit to generate an unique id.
static
<T extends Segment>
T
createAndLinkSegment(TrackSegment track, java.lang.Class<T> segClass)
          Automatically set a valid WebLabRI to the created Segment using the TrackSegment to generate an unique id.
static SpatialSegment createAndLinkSpatialSegment(MediaUnit mu, int... shape)
          Creates a SpatioTemporalSegment at timestamp.
static SpatialSegment createAndLinkSpatialSegment(TrackSegment track, int... shape)
           
static SpatioTemporalSegment createAndLinkSpatioTemporalSegment(MediaUnit mu, int timestamp, int... shape)
          Creates a SpatioTemporalSegment at timestamp.
static SpatioTemporalSegment createAndLinkSpatioTemporalSegment(TrackSegment track, int timestamp, int... shape)
           
static TemporalSegment createAndLinkTemporalSegment(MediaUnit mu, int start, int end)
          Look in MediaUnit if a TemporalSegment already exists at start and end.
static TemporalSegment createAndLinkTemporalSegment(MediaUnit mu, int start, int end, boolean enableCollocatedSegment)
          Creates a TemporalSegment at start and end, or returns an existing one.
static TemporalSegment createAndLinkTemporalSegment(TrackSegment track, int start, int end)
           
protected static java.lang.String createSegmentURIFor(java.lang.Object segmentContainer)
           
protected static java.lang.String createUniqueURIFrom(Resource resource, boolean isChild, boolean isAnnotation)
          Create a URI checking it does not already exist in the resource.
protected static java.lang.String createUniqueURIin(java.util.Set<java.lang.String> uris, boolean isChild, boolean isAnnotation, java.lang.String parentUri)
           
protected static Resource findParent(MediaUnit mu, Resource resource)
           
protected static java.lang.String getUniqueWebLabRIFrom(Resource res, boolean isChild, boolean isAnnotation)
           
protected static java.util.Set<java.lang.String> getUris(java.lang.String key)
           
protected static java.util.Set<java.lang.String> listUri(Resource resource)
          List uris in the resource
protected static java.util.Set<java.lang.String> listUri(Resource resource, boolean force)
          Lists all URI in a resource and its subresources.
protected static java.util.Set<java.lang.String> listUri(Segment segment)
          Lists all URI in a segment and its subsegments.
protected static void removeChild(MediaUnit mu, Resource parent, Resource root)
           
protected static void setUris(java.lang.String key, java.util.Set<java.lang.String> uris)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

innerMap

protected static final java.util.Map<java.lang.String,java.util.Set<java.lang.String>> innerMap
This data structure is not well adapted to manage WebLab Resource

Method Detail

createAndLinkLinearSegment

public static final LinearSegment createAndLinkLinearSegment(Text text,
                                                             int start,
                                                             int end)
Looks in text if a LinearSegment already exists at start and end. If it's the case, returns it. Otherwise, it creates a LinearSegment using createAndLinkSegment(MediaUnit, Class) method, and setting the start and end.

Parameters:
text - The Text containing the Segment
start - char index of the Segment start
end - char index of the Segment end
Returns:
Either a newly created LinearSegment or the existing one at the same position in the Text.
Throws:
WebLabUncheckedException - if start >= end or if text is null
See Also:
createAndLinkLinearSegment(Text, int, int, boolean)

createAndLinkLinearSegment

public static final LinearSegment createAndLinkLinearSegment(Text text,
                                                             int start,
                                                             int end,
                                                             boolean enableCollocatedSegment)
Creates a LinearSegment at start and end, or returns an existing one.

Parameters:
text - The Text containing the Segment
start - char index of the Segment start
end - char index of the Segment end
enableCollocatedSegment - Whether or not to prevent two segment (with two URIs) tobe at the same position. If false, it looks in text if a LinearSegment already exists at start and end. If it's the case, returns it. Otherwise, it creates a LinearSegment using createAndLinkSegment(MediaUnit, Class) method, and setting the start and end.
Returns:
Either a newly created LinearSegment or an existing one at the same position in the Text if enableCollocatedSegment is false.
Throws:
WebLabUncheckedException - if start >= end or if text is null

createAndLinkLinearSegment

public static final LinearSegment createAndLinkLinearSegment(TrackSegment track,
                                                             int start,
                                                             int end)
Parameters:
track - The TrackSegment in which to add a Linear
start - The starting offset of the linear
end - The ending offset of the linear
Returns:
The created linear

createAndLinkTemporalSegment

public static final TemporalSegment createAndLinkTemporalSegment(MediaUnit mu,
                                                                 int start,
                                                                 int end)
Look in MediaUnit if a TemporalSegment already exists at start and end. If it's the case, returns it. Otherwise, it creates a TemporalSegment using createAndLinkSegment(MediaUnit, Class) method, and setting the start and end. A best practice is that indexes are expressed in millisecond.

Parameters:
mu - The MediaUnit containing the Segment
start - index of the Segment start
end - index of the Segment end
Returns:
Either a newly created TemporalSegment or the existing one at the same position in the MediaUnit.

createAndLinkTemporalSegment

public static final TemporalSegment createAndLinkTemporalSegment(MediaUnit mu,
                                                                 int start,
                                                                 int end,
                                                                 boolean enableCollocatedSegment)
Creates a TemporalSegment at start and end, or returns an existing one. A best practice is that indexes are expressed in millisecond.

Parameters:
mu - The MediaUnit containing the Segment
start - index of the Segment start
end - index of the Segment end
enableCollocatedSegment - Whether or not to prevent two segment (with two URIs) tobe at the same position. If false, it looks in mu if a TemporalSegment already exists at start and end. If it's the case, returns it. Otherwise, it creates a TemporalSegment using createAndLinkSegment(MediaUnit, Class) method, and setting the start and end.
Returns:
Either a newly created TemporalSegment or the existing one at the same position in the MediaUnit if enableCollocatedSegment is false.
Throws:
WebLabUncheckedException - if start > end or if text is null

createAndLinkTemporalSegment

public static final TemporalSegment createAndLinkTemporalSegment(TrackSegment track,
                                                                 int start,
                                                                 int end)
Parameters:
track - The TrackSegment in which to add a Linear
start - The starting offset of the linear
end - The ending offset of the linear
Returns:
The created temporal

createAndLinkSpatioTemporalSegment

public static final SpatioTemporalSegment createAndLinkSpatioTemporalSegment(MediaUnit mu,
                                                                             int timestamp,
                                                                             int... shape)
Creates a SpatioTemporalSegment at timestamp. A best practice is that timestamp is expressed in millisecond.

Parameters:
mu - The MediaUnit containing the Segment
timestamp - index of the Segment start
shape - An array of int containing coordinates to be affected to this segment. The smallest array is {x1, y1, x2, y2}. In this case coordinate 1 (x1;y1) is the center of a disk, where coodinate 2 (x2;y2) is a point of the border. When shape contains more than tree coordinates, it defines a closed polygon.
Returns:
The newly created SpatioTemporalSegment

createAndLinkSpatioTemporalSegment

public static final SpatioTemporalSegment createAndLinkSpatioTemporalSegment(TrackSegment track,
                                                                             int timestamp,
                                                                             int... shape)
Parameters:
track - The track segment in which to add a spatio temporal
timestamp - The index of the Segment start
shape - An array of int containing coordinates to be affected to this segment. The smallest array is {x1, y1, x2, y2}. In this case coordinate 1 (x1;y1) is the centre of a disk, where coordinate 2 (x2;y2) is a point of the border. When shape contains more than tree coordinates, it defines a closed polygon.
Returns:
The newly created SpatioTemporalSegment

createAndLinkSpatialSegment

public static final SpatialSegment createAndLinkSpatialSegment(MediaUnit mu,
                                                               int... shape)
Creates a SpatioTemporalSegment at timestamp. A best practice is that timestamp is expressed in millisecond.

Parameters:
mu - The MediaUnit containing the Segment
shape - An array of int containing coordinates to be affected to this segment. The smallest array is {x1, y1, x2, y2}. In this case coordinate 1 (x1;y1) is the center of a disk, where coordinate 2 (x2;y2) is a point of the border. When shape contains more than tree coordinates, it defines a closed polygon.
Returns:
The newly created SpatialSegment

createAndLinkSpatialSegment

public static final SpatialSegment createAndLinkSpatialSegment(TrackSegment track,
                                                               int... shape)
Parameters:
track - The track segment in which to add a spatio temporal
shape - An array of int containing coordinates to be affected to this segment. The smallest array is {x1, y1, x2, y2}. In this case coordinate 1 (x1;y1) is the center of a disk, where coordinate 2 (x2;y2) is a point of the border. When shape contains more than tree coordinates, it defines a closed polygon.
Returns:
The newly created SpatialSegment

createAndLinkSegment

public static final <T extends Segment> T createAndLinkSegment(MediaUnit mediaUnit,
                                                               java.lang.Class<T> segClass)
Automatically set a valid WebLabRI to the created Segment using the MediaUnit to generate an unique id. Created Segment will be added to the MediaUnit.

Type Parameters:
T - The subclass of Segment to be created
Parameters:
mediaUnit - the MediaUnit that will contains the created Segment
segClass - The class of the Segment to be created
Returns:
a new instance of segClass with a valid WebLabRI and added to the MediaUnit

createAndLinkSegment

public static final <T extends Segment> T createAndLinkSegment(TrackSegment track,
                                                               java.lang.Class<T> segClass)
Automatically set a valid WebLabRI to the created Segment using the TrackSegment to generate an unique id. Created Segment will be added to the TrackSegment.

Type Parameters:
T - The subclass of Segment to be created
Parameters:
track - the TrackSegment that will contains the created Segment
segClass - The class of the Segment to be created
Returns:
a new instance of segClass with a valid WebLabRI and added to the TrackSegment

cleanMapping

protected static void cleanMapping(java.lang.String uri)

getUris

protected static java.util.Set<java.lang.String> getUris(java.lang.String key)

setUris

protected static void setUris(java.lang.String key,
                              java.util.Set<java.lang.String> uris)

listUri

protected static java.util.Set<java.lang.String> listUri(Resource resource)
List uris in the resource

Parameters:
resource - a resource
Returns:
a set of uri in this resource

listUri

protected static java.util.Set<java.lang.String> listUri(Segment segment)
Lists all URI in a segment and its subsegments.

Parameters:
segment - a segment

listUri

protected static java.util.Set<java.lang.String> listUri(Resource resource,
                                                         boolean force)
Lists all URI in a resource and its subresources.

Parameters:
resource - a resource
force - if false URI in this resource will not be listed if the resource have already been processed, else they will not matter what.
Returns:
a list of all URI in this resource the last time this resource was processed
WARNING:
this function does not support cyclic resources (a resource that contains itself) if force is true

createSegmentURIFor

protected static java.lang.String createSegmentURIFor(java.lang.Object segmentContainer)

createUniqueURIFrom

protected static java.lang.String createUniqueURIFrom(Resource resource,
                                                      boolean isChild,
                                                      boolean isAnnotation)
Create a URI checking it does not already exist in the resource.

Parameters:
resource - a top container resource
isChild - if true, the uri will describe a child or subchild of this resource
isAnnotation - if true, the uri will describe a annotation on this resource
Returns:
an URI unique among all URI in the resource and its sub resources

createUniqueURIin

protected static java.lang.String createUniqueURIin(java.util.Set<java.lang.String> uris,
                                                    boolean isChild,
                                                    boolean isAnnotation,
                                                    java.lang.String parentUri)

removeChild

protected static void removeChild(MediaUnit mu,
                                  Resource parent,
                                  Resource root)

addAnnotation

protected static void addAnnotation(Annotation annotation,
                                    Resource resource,
                                    Resource root)

addSegment

protected static void addSegment(Segment segment,
                                 MediaUnit parent,
                                 Resource root)

addDescriptor

protected static void addDescriptor(LowLevelDescriptor descriptor,
                                    Resource parent,
                                    Resource root)

addChild

@Deprecated
protected static void addChild(MediaUnit mu,
                                          Resource parent,
                                          Resource root)
Deprecated. since model 1.2, no need to separates root and parent. replaced by addChild(final MediaUnit mu, final Document parent)


addChild

protected static void addChild(MediaUnit mu,
                               Document parent)

findParent

protected static Resource findParent(MediaUnit mu,
                                     Resource resource)

getUniqueWebLabRIFrom

protected static final java.lang.String getUniqueWebLabRIFrom(Resource res,
                                                              boolean isChild,
                                                              boolean isAnnotation)
Parameters:
res - The Resource to be used to create WebLabRI
Returns:
The String to be used as URI by the MediaUnit created


Copyright © 2004-2011 WebLab Project. All Rights Reserved.