info.sswap.http.util
Class EntityUtil

java.lang.Object
  extended by info.sswap.http.util.EntityUtil

public class EntityUtil
extends java.lang.Object

A utility class for extracting information from intermediate representation for Entities, while performing validation.

Author:
Blazej Bulka

Field Summary
private static com.hp.hpl.jena.rdf.model.Model model
           
 
Constructor Summary
EntityUtil()
           
 
Method Summary
private static
<T> T
convertValue(Value value, com.google.common.base.Function<Value,T> valueConverter)
          Invokes the conversion function for a Value, and generates an exception if the function is unable to perform the conversion.
static
<T> java.util.Collection<T>
getMultiValueProperty(Entity entity, java.lang.String propertyName, com.google.common.base.Function<Value,T> valueConverter)
          Converts values for a property that can potentially have multiple values (e.g., the value of the property is a JSON array).
static java.lang.String getOptionalPropertyAsString(Entity entity, java.lang.String propertyName)
           
static java.net.URI getOptionalPropertyAsURI(Entity entity, java.lang.String propertyName)
          Gets a URI value for an optional property.
static java.lang.String getRequiredPropertyAsString(Entity entity, java.lang.String propertyName)
          Gets a value for the first property with the specified name for an entity.
static java.net.URI getRequiredPropertyAsURI(Entity entity, java.lang.String propertyName)
          Gets a URI value for a required property
private static boolean isMarked(java.lang.String markedURI)
          Checks whether the string has markings at the beginning (<) and the end (>)
static boolean isMarkedEntityURI(java.lang.String uri)
          Checks whether the given value is a URI with entity markers (i.e., surrounded by < and >) This kind of marking is used to mark URIs of entities in contexts where it is not certain whether the value is a URI or a literal typed xsd:anyURI.
static boolean isReserved(java.lang.String uri)
           
static boolean isUnknownReserved(java.lang.String uri, info.sswap.api.model.SSWAPDocument doc)
           
static java.lang.String stripEntityMarkers(java.lang.String markedURI)
          Strips the markings from a string (if it has them).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

model

private static final com.hp.hpl.jena.rdf.model.Model model
Constructor Detail

EntityUtil

public EntityUtil()
Method Detail

getOptionalPropertyAsURI

public static java.net.URI getOptionalPropertyAsURI(Entity entity,
                                                    java.lang.String propertyName)
                                             throws java.lang.IllegalArgumentException
Gets a URI value for an optional property.

Parameters:
entity - the entity from which the value should be extracted
propertyName - the property name
Returns:
a URI or null
Throws:
InvalidParametersException - if the value for this property existed in the entity, but it was not a valid URI
java.lang.IllegalArgumentException

getOptionalPropertyAsString

public static java.lang.String getOptionalPropertyAsString(Entity entity,
                                                           java.lang.String propertyName)
                                                    throws java.lang.IllegalArgumentException
Throws:
java.lang.IllegalArgumentException

getRequiredPropertyAsURI

public static java.net.URI getRequiredPropertyAsURI(Entity entity,
                                                    java.lang.String propertyName)
                                             throws java.lang.IllegalArgumentException
Gets a URI value for a required property

Parameters:
entity - the entity from which the value should be extracted
propertyName - the propertyName
Returns:
a URI
Throws:
InvalidParametersException - if the value is not a valid URI or there is no such property defined for this entity
java.lang.IllegalArgumentException

getRequiredPropertyAsString

public static java.lang.String getRequiredPropertyAsString(Entity entity,
                                                           java.lang.String propertyName)
                                                    throws java.lang.IllegalArgumentException
Gets a value for the first property with the specified name for an entity.

Parameters:
entity - the entity from which the value should be extracted
propertyName - the property name
Returns:
a string containing the value for the property
Throws:
InvalidParametersException - if there are no defined properties with that name for this entity
java.lang.IllegalArgumentException

getMultiValueProperty

public static <T> java.util.Collection<T> getMultiValueProperty(Entity entity,
                                                                java.lang.String propertyName,
                                                                com.google.common.base.Function<Value,T> valueConverter)
                                                     throws java.lang.IllegalArgumentException
Converts values for a property that can potentially have multiple values (e.g., the value of the property is a JSON array).

Type Parameters:
T - the return type of the conversion
Parameters:
entity - the entity containing the property
propertyName - the name of the property
valueConverter - a function that can convert a Value to the desired format
Returns:
a collection of converted values
Throws:
java.lang.IllegalArgumentException - if the values within the array are not literals, the value of the property is not a literal or an array, or the converting function returns null (indicating a conversion failure).

convertValue

private static <T> T convertValue(Value value,
                                  com.google.common.base.Function<Value,T> valueConverter)
                       throws java.lang.IllegalArgumentException
Invokes the conversion function for a Value, and generates an exception if the function is unable to perform the conversion. (The Function interface does not specify an exception that will be thrown in such a case, therefore any null value returned by the Function or any exception thrown will be treated as conversion failure.)

Type Parameters:
T - the type of the converted objects
Parameters:
value - a single value to be converted
valueConverter - the function that performs the conversion
Returns:
a converted value
Throws:
java.lang.IllegalArgumentException

isMarkedEntityURI

public static boolean isMarkedEntityURI(java.lang.String uri)
Checks whether the given value is a URI with entity markers (i.e., surrounded by < and >) This kind of marking is used to mark URIs of entities in contexts where it is not certain whether the value is a URI or a literal typed xsd:anyURI.

Parameters:
uri - the URI to be checked for marking
Returns:
true if the string is marked and it contains a valid URI inside, false otherwise

isMarked

private static boolean isMarked(java.lang.String markedURI)
Checks whether the string has markings at the beginning (<) and the end (>)

Parameters:
markedURI - the uri to be checked for marking
Returns:
true if it has marks

stripEntityMarkers

public static java.lang.String stripEntityMarkers(java.lang.String markedURI)
Strips the markings from a string (if it has them).

Parameters:
markedURI - the string whose markings should be stripped
Returns:
the markedURI without markings (if there were any).

isReserved

public static boolean isReserved(java.lang.String uri)

isUnknownReserved

public static boolean isUnknownReserved(java.lang.String uri,
                                        info.sswap.api.model.SSWAPDocument doc)


Copyright (c) 2010, iPlant Collaborative, University of Arizona, Cold Spring Harbor Laboratories, University of Texas at Austin.