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

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

public final class SegmentFactory
extends 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. For creating MediaUnit and other kind of Resource you shoud used WebLabResourceFactory.

Author:
Cassidian WebLab Team
See Also:
WebLabResourceFactory

Field Summary
protected static Map<String,Set<String>> INNER_MAP
          This data structure is not well adapted to manage WebLab Resource
protected static int MODULO
          The modulo used in the uris
 
Method Summary
protected static void addAnnotation(Annotation annotation, Resource resource, Resource root)
          Adds an annotation on the resource.
protected static void addChild(MediaUnit mediaUnit, Document parent)
          Add a sub-MediaUnit to a document
protected static void addChild(MediaUnit mediaUnit, Resource parent, Resource root)
          Deprecated. since model 1.2, no need to separates root and parent. replaced by addChild(final MediaUnit mediaUnit, final Document parent)
protected static void addDescriptor(LowLevelDescriptor descriptor, Resource parent, Resource root)
          Adds a LowLevelDescriptor to a resource.
protected static void addPokInResultSet(PieceOfKnowledge pok, ResultSet parentRoot)
          Adds a PieceOfKnowledge to a ResultSet
protected static void addSegment(Segment segment, MediaUnit parent, Resource root)
          Adds a Segment to a MediaUnit
protected static void cleanMapping(String uri)
          Cleans the internal mapping INNER_MAP for every occurrence of the 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, 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, Class<T> segClass)
          Automatically set a valid WebLabRI to the created Segment using the TrackSegment to generate an unique id.
static SpatialSegment createAndLinkSpatialSegment(MediaUnit mediaUnit, int... shape)
          Creates a SpatioTemporalSegment at timestamp.
static SpatialSegment createAndLinkSpatialSegment(TrackSegment track, int... shape)
           
static SpatioTemporalSegment createAndLinkSpatioTemporalSegment(MediaUnit mediaUnit, int timestamp, int... shape)
          Creates a SpatioTemporalSegment at timestamp.
static SpatioTemporalSegment createAndLinkSpatioTemporalSegment(TrackSegment track, int timestamp, int... shape)
           
static TemporalSegment createAndLinkTemporalSegment(MediaUnit mediaUnit, int start, int end)
          Look in MediaUnit if a TemporalSegment already exists at start and end.
static TemporalSegment createAndLinkTemporalSegment(MediaUnit mediaUnit, 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 String createSegmentURIFor(Object segmentContainer)
          Create an URI for a segment
protected static String createUniqueURIFrom(Resource resource, boolean isChild, boolean isAnnotation)
          Create a URI checking it does not already exist in the resource.
protected static String createUniqueURIin(Set<String> uris, boolean isChild, boolean isAnnotation, String parentUri)
          Create an URI
protected static Resource findParent(MediaUnit mediaUnit, Resource resource)
          Searches for the parent of a MediaUnit inside a Resource.
protected static String getUniqueWebLabRIFrom(Resource res, boolean isChild, boolean isAnnotation)
           
protected static Set<String> getUris(String key)
          Returns the set of URI linked to this URI.
protected static Set<String> listUri(Resource resource)
          List uris in the resource
protected static Set<String> listUri(Resource resource, boolean force)
          Lists all URI in a resource and its subresources.
protected static Set<String> listUri(Segment segment)
          Lists all URI in a segment and its subsegments.
protected static Set<String> listUri(String uri)
          Returns linked URI set with this URI
protected static void removeChild(MediaUnit mediaUnit, Resource parent, Resource root)
          Removes a MediaUnit from a Resource
protected static void setUris(String key, Set<String> uris)
          Sets the linked set of URIs of a given URI.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

INNER_MAP

protected static final Map<String,Set<String>> INNER_MAP
This data structure is not well adapted to manage WebLab Resource


MODULO

protected static final int MODULO
The modulo used in the uris

See Also:
Constant Field Values
Method Detail

createAndLinkLinearSegment

public static 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.
See Also:
createAndLinkLinearSegment(Text, int, int, boolean)

createAndLinkLinearSegment

public static 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.

createAndLinkLinearSegment

public static 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

createAndLinkSegment

public static <T extends Segment> T createAndLinkSegment(MediaUnit mediaUnit,
                                                         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 <T extends Segment> T createAndLinkSegment(TrackSegment track,
                                                         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

createAndLinkSpatialSegment

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

Parameters:
mediaUnit - 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 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

createAndLinkSpatioTemporalSegment

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

Parameters:
mediaUnit - 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 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

createAndLinkTemporalSegment

public static TemporalSegment createAndLinkTemporalSegment(MediaUnit mediaUnit,
                                                           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:
mediaUnit - 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 TemporalSegment createAndLinkTemporalSegment(MediaUnit mediaUnit,
                                                           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:
mediaUnit - 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) to be 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.

createAndLinkTemporalSegment

public static 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

addAnnotation

protected static void addAnnotation(Annotation annotation,
                                    Resource resource,
                                    Resource root)
Adds an annotation on the resource.

Parameters:
annotation - the annotation to add
resource - the resource in which we want to add the annotation
root - the root resource containing the previous resource, or the resource itself

addChild

protected static void addChild(MediaUnit mediaUnit,
                               Document parent)
Add a sub-MediaUnit to a document

Parameters:
mediaUnit - the mediaunit to add to the document
parent - a document.

addChild

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

Parameters:
mediaUnit - The MediaUnit to be added into parent
parent - The Resource in which to add mediaUnit
root - The root Resource of parent

addDescriptor

protected static void addDescriptor(LowLevelDescriptor descriptor,
                                    Resource parent,
                                    Resource root)
Adds a LowLevelDescriptor to a resource.

Parameters:
descriptor - LowLevelDescriptor to add
parent - the resource in which we want to add the LowLevelDescriptor
root - the root resource containing the previous resource, or the resource itself

addPokInResultSet

protected static void addPokInResultSet(PieceOfKnowledge pok,
                                        ResultSet parentRoot)
Adds a PieceOfKnowledge to a ResultSet

Parameters:
pok - a PieceOfKnowledge
parentRoot - a ResultSet

addSegment

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

Parameters:
segment - the Segment to add to the mediaunit
parent - a mediaunit
root - the root resource containing the previous mediaunit

cleanMapping

protected static void cleanMapping(String uri)
Cleans the internal mapping INNER_MAP for every occurrence of the URI

Parameters:
uri - The URI to remove from the INNER_MAP

createSegmentURIFor

protected static String createSegmentURIFor(Object segmentContainer)
Create an URI for a segment

Parameters:
segmentContainer - the Segment object
Returns:
an URI coherent w.r.t. knowledge of this factory

createUniqueURIFrom

protected static 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 String createUniqueURIin(Set<String> uris,
                                          boolean isChild,
                                          boolean isAnnotation,
                                          String parentUri)
Create an URI

Parameters:
uris - list of existing URIs
isChild - if true, this URI will refer to a child of a resource
isAnnotation - if true, this URI will refer to an annotation
parentUri - the parent URI of this URI
Returns:
an URI coherent w.r.t. knowledge of this factory

findParent

protected static Resource findParent(MediaUnit mediaUnit,
                                     Resource resource)
Searches for the parent of a MediaUnit inside a Resource.

Parameters:
mediaUnit - the MediaUnit to search for its parent.
resource - the "root" resource containing all resources in which we perform the search
Returns:
the parent resource of the MediaUnit or null if this MediaUnitwas not in the root resource.

getUniqueWebLabRIFrom

protected static final String getUniqueWebLabRIFrom(Resource res,
                                                    boolean isChild,
                                                    boolean isAnnotation)
Parameters:
res - The Resource to be used to create WebLabRI
isChild - Whether res is a root or a sub-resource
isAnnotation - Whether res is an Annotation or Resource
Returns:
The String to be used as URI by the MediaUnit created

getUris

protected static Set<String> getUris(String key)
Returns the set of URI linked to this URI. Two URIs are linked if they they share the same root resource.

Parameters:
key - an URI
Returns:
the set of URIs linked to this URI.

listUri

protected static Set<String> listUri(Resource resource)
List uris in the resource

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

listUri

protected static Set<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

listUri

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

Parameters:
segment - a segment
Returns:
a list of all URI in this segment the last time this segment was processed

listUri

protected static Set<String> listUri(String uri)
Returns linked URI set with this URI

Parameters:
uri - an URI
Returns:
a set of linked URI.
See Also:
for more information

removeChild

protected static void removeChild(MediaUnit mediaUnit,
                                  Resource parent,
                                  Resource root)
Removes a MediaUnit from a Resource

Parameters:
mediaUnit - the MediaUnit to remove
parent - the parent of this MediaUnit
root - the root resource containing the MediaUnit and its parent or the parent itself.

setUris

protected static void setUris(String key,
                              Set<String> uris)
Sets the linked set of URIs of a given URI.

Parameters:
key - an URI.
uris - the linked set of URIs.


Copyright © 2012. All Rights Reserved.