rdfreactor.generator.5.0.0.source-code.dynamicclass.vm Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of rdfreactor.generator Show documentation
Show all versions of rdfreactor.generator Show documentation
RDFReactor creates domain-specific, type-safe Java classes which
act as a view over domain-free, loosely typed RDF instances.
This package generates the Java classes form an RDF vocabulary.
#macro( mixedcase $name )$name.substring(0,1).toUpperCase()$name.substring(1)#end
#macro( lowercase $name )$name.toLowerCase()#end
#macro( uppercase $name )$name.toUpperCase()#end
/**
* generated by http://RDFReactor.semweb4j.org ($generatorVersion) on ${now}
*/
package $package.name;
import org.ontoware.rdf2go.model.Model;
import org.ontoware.rdf2go.model.node.BlankNode;
import org.ontoware.rdf2go.model.node.Node;
import org.ontoware.rdf2go.model.node.Resource;
import org.ontoware.rdf2go.model.node.URI;
import org.ontoware.rdf2go.model.node.impl.URIImpl;
import org.ontoware.rdf2go.exception.ModelRuntimeException;
#if ($class.throwsRDFDataException() )
import org.ontoware.rdfreactor.runtime.RDFDataException;
#end
#if ($class.throwsCardinalityException() )
import org.ontoware.rdfreactor.runtime.CardinalityException;
#end
#if($class.superclass.toString().equals("ReactorBaseNamed"))
import org.ontoware.rdfreactor.runtime.ReactorBaseNamed;
#end
/**
#if($class.getComment())
* ${class.getComment()}
*
#end
#if ($class.properties.size() > 0)
* This class manages access to these properties:
*
#foreach( $prop in $class.properties )
* - #mixedcase($prop.name)
#end
*
*
#end
* This class was generated by RDFReactor on ${now}
*/
public class ${class.name} extends $class.superclass {
/** ${class.mappedTo} */
public static final URI RDFS_CLASS = new URIImpl("${class.mappedTo}", false);
#foreach( $prop in $class.properties )
/** $prop.mappedTo */
public static final URI #uppercase($prop.name) = new URIImpl("${prop.mappedTo}",false);
#end
/** all property-URIs with this class as domain */
public static final URI[] MANAGED_URIS = {
#foreach( $prop in $class.properties )
new URIImpl("${prop.mappedTo}",false)#if (${velocityCount} < $class.properties.size()),
#end
#end
};
// protected constructors needed for inheritance
/**
* Returns a Java wrapper over an RDF object, identified by URI.
* Creating two wrappers for the same instanceURI is legal.
* @param model RDF2GO Model implementation, see http://rdf2go.semweb4j.org
* @param classURI URI of RDFS class
* @param instanceIdentifier Resource that identifies this instance
* @param write if true, the statement (this, rdf:type, TYPE) is written to the model
*/
protected ${class.name} ( Model model, URI classURI, Resource instanceIdentifier, boolean write ) {
super(model, classURI, instanceIdentifier, write);
}
// public constructors
/**
* Returns a Java wrapper over an RDF object, identified by URI.
* Creating two wrappers for the same instanceURI is legal.
* @param model RDF2GO Model implementation, see http://rdf2go.ontoware.org
* @param instanceIdentifier an RDF2Go Resource identifying this instance
* @param write if true, the statement (this, rdf:type, TYPE) is written to the model
*/
public ${class.name} (Model model, Resource instanceIdentifier, boolean write) {
super(model, RDFS_CLASS, instanceIdentifier, write);
}
#if( $writetostore )
/**
* Returns a Java wrapper over an RDF object, identified by URI.
* Creating two wrappers for the same instanceURI is legal.
* The statement (this, rdf:type, TYPE) is written to the model
* @param model RDF2GO Model implementation, see http://rdf2go.ontoware.org
* @param uri URI of this instance
*/
public ${class.name} ( Model model, URI uri ) {
this(model, uri, true);
}
/**
* Returns a Java wrapper over an RDF object, identified by URI.
* Creating two wrappers for the same instanceURI is legal.
* The statement (this, rdf:type, TYPE) is written to the model
* @param model RDF2GO Model implementation, see http://rdf2go.ontoware.org
* @param uriString A URI of this instance, represented as a String
* @throws ModelRuntimeException if URI syntax is wrong
*/
public ${class.name} ( Model model, String uriString ) throws ModelRuntimeException {
this(model, new URIImpl(uriString), true);
}
/**
* Returns a Java wrapper over an RDF object, identified by a blank node.
* Creating two wrappers for the same blank node is legal.
* The statement (this, rdf:type, TYPE) is written to the model
* @param model RDF2GO Model implementation, see http://rdf2go.ontoware.org
* @param bnode BlankNode of this instance
*/
public ${class.name} ( Model model, BlankNode bnode ) {
this(model, bnode, true);
}
/**
* Returns a Java wrapper over an RDF object, identified by
* a randomly generated URI.
* Creating two wrappers results in different URIs.
* The statement (this, rdf:type, TYPE) is written to the model
* @param model RDF2GO Model implementation, see http://rdf2go.ontoware.org
*/
public ${class.name} ( Model model ) {
this(model, model.newRandomUniqueURI(), true);
}
#else
/**
* Returns a Java wrapper over an RDF object, identified by a URI, given as a String.
* Creating two wrappers for the same URI is legal.
* @param model RDF2GO Model implementation, see http://rdf2go.ontoware.org
* @param uriString a URI given as a String
* @param write if true, the statement (this, rdf:type, TYPE) is written to the model
*/
public ${class.name} ( Model model, String uriString, boolean write) {
super(model, RDFS_CLASS, new URIImpl(uriString,false), write);
}
/**
* Returns a Java wrapper over an RDF object, identified by a blank node.
* Creating two wrappers for the same blank node is legal.
* @param model RDF2GO Model implementation, see http://rdf2go.ontoware.org
* @param bnode BlankNode of this instance
* @param write if true, the statement (this, rdf:type, TYPE) is written to the model
*/
public ${class.name} ( Model model, BlankNode bnode, boolean write ) {
super(model, RDFS_CLASS, bnode, write);
}
/**
* Returns a Java wrapper over an RDF object, identified by
* a randomly generated URI.
* Creating two wrappers results in different URIs.
* @param model RDF2GO Model implementation, see http://rdf2go.ontoware.org
* @param write if true, the statement (this, rdf:type, TYPE) is written to the model
*/
public ${class.name} ( Model model, boolean write ) {
super(model, RDFS_CLASS, model.newRandomUniqueURI(), write);
}
#end
///////////////////////////////////////////////////////////////////
// getters, setters, ...
/**
* @param model RDF2Go model
* @param uri instance identifier
* @return an instance of ${class.name} or null if none existst
* @throws Exception if Model causes problems
*/
public static ${class.name} getInstance(Model model, URI uri) throws Exception {
return ($class.name) getInstance(model, uri, ${class.name}.class);
}
/**
* @param model
* @param uri
* @return true if uri is an instance of this class in the model
*/
public static boolean hasInstance(Model model, URI uri) {
return hasInstance(model, uri, RDFS_CLASS);
}
/**
* @return all instances of this class
*/
public ${class.name}[] getAllInstances() {
return (${class.name}[]) getAllInstances(super.model, ${class.name}.class);
}
/**
* @return all instances of this class in the given Model
* @param model an RDF2Go model
*/
public static ${class.name}[] getAllInstances(Model model) {
return (${class.name}[]) getAllInstances(model, ${class.name}.class);
}
#foreach( $inverse in $class.inverseProperties )
/**
* @return all A's that have a relation '#mixedcase( $inverse.getInverse().getName() )' to this ${class.name} instance
*/
public ${inverse.getFirstType()}[] getAll${methodnameprefix}#mixedcase($inverse.name)_Inverse() {
return (${inverse.getFirstType()}[]) getAll_Inverse(${inverse.getFirstType()}.#uppercase($inverse.name), this.getResource(), ${inverse.getFirstType()}.class);
}
/**
* add '#mixedcase( $inverse.getInverse().getName() )'-Inverse
* @param value
*/
public void add${methodnameprefix}#mixedcase( $inverse.getInverse().getName() )_Inverse(${inverse.getFirstType()} value) {
value.add( ${inverse.getFirstType()}.#uppercase($inverse.name) ,this);
}
#end
#foreach( $prop in $class.properties )
#if ($prop.types.size() == 1)
#set( $classname = $prop.getFirstType() )
##
## generate get & set only if no cardinality is set (== -1) or
## max cardinality is exactly == 1
##
#if($prop.maxCardinality == -1 || $prop.maxCardinality == 1)
/**
#if($prop.getComment())
* Schema Comment: ${prop.getComment()}
#end
* @return the only value. null if none is found
* @throws RDFDataException, if the property has multiple values
*/
public ${classname} get${methodnameprefix}#mixedcase($prop.name)() {
return ($classname) get(#uppercase($prop.name), ${classname}.class);
}
/**
* removes all values and sets this one
* @param value the value to be set
#if($prop.getComment())
* Schema Comment: ${prop.getComment()}
#end
*/
public void set${methodnameprefix}#mixedcase($prop.name)( ${classname} value ) {
set(#uppercase($prop.name), value);
}
/**
* removes current value(s)
#if($prop.getComment())
* Schema Comment: ${prop.getComment()}
#end
*/
public void remove${methodnameprefix}#mixedcase($prop.name)() {
removeAll(#uppercase($prop.name));
}
#end ####if($prop.maxCardinality == -1 || $prop.maxCardinality == 1)
#if($prop.minCardinality != -1)
/**
* removes a value
* @param value the value to be removed
#if($prop.getComment())
* Schema Comment: ${prop.getComment()}
#end
* @throws CardinalityException if removing would change the number of
* values below the minimal cardinality $prop.minCardinality
*/
public void remove${methodnameprefix}#mixedcase($prop.name)( ${classname} value )
throws CardinalityException {
remove(#uppercase($prop.name), value, $prop.minCardinality);
}
#else
/**
* removes a value
* @param value the value to be removed
#if($prop.getComment())
* Schema Comment: ${prop.getComment()}
#end
*/
public void remove${methodnameprefix}#mixedcase($prop.name)( ${classname} value ) {
remove(#uppercase($prop.name), value);
}
/**
* removes all values
#if($prop.getComment())
* Schema Comment: ${prop.getComment()}
#end
*/
public void removeAll${methodnameprefix}#mixedcase($prop.name)() {
removeAll(#uppercase($prop.name));
}
#end ## if
/**
* @param value
* @return true if the model contains a statement (this, #uppercase($prop.name), value)
*/
public boolean has${methodnameprefix}#mixedcase($prop.name)( ${classname} value) {
return hasValue(#uppercase($prop.name), value);
}
/**
* @return true if the model contains a statement (this, #uppercase($prop.name), *)
*/
public boolean has${methodnameprefix}#mixedcase($prop.name)() {
return hasValue(#uppercase($prop.name));
}
#if($prop.maxCardinality > 1)
/**
* adds a value
* @param value the value to be added
#if($prop.getComment())
* Schema Comment: ${prop.getComment()}
#end
* @throws CardinalityException if adding would change the number of
* values above the maximal cardinality $prop.maxCardinality
*/
public void add${methodnameprefix}#mixedcase($prop.name)( ${classname} value )
throws CardinalityException {
add(#uppercase($prop.name), value, $prop.maxCardinality );
}
#end ## if
#if($prop.maxCardinality == -1)
/**
* adds a value
* @param value the value to be added
#if($prop.getComment())
* Schema Comment: ${prop.getComment()}
#end
*/
public void add${methodnameprefix}#mixedcase($prop.name)( ${classname} value ) {
add(#uppercase($prop.name), value );
}
/**
* @return all values
#if($prop.getComment())
* Schema Comment: ${prop.getComment()}
#end
*/
public ${classname}[] getAll${methodnameprefix}#mixedcase($prop.name)() {
return (${classname}[]) getAll(#uppercase($prop.name), ${classname}.class);
}
#end ## if
#else ## ------------------------------- start multi-range handling --------------------------------------
#foreach($classname in $prop.types)
##
## generate get & set only if no cardinality is set (== -1) or
## max cardinality is exactly == 1
##
#if($prop.maxCardinality == -1 || $prop.maxCardinality == 1)
/**
#if($prop.getComment())
* Schema Comment: ${prop.getComment()}
#end
* Technical detail: This is modeling a property with multiple ranges.
* @return the only value. null if none is found
* @throws RDFDataException, if the property has multiple values
*/
public ${classname} get#mixedcase($prop.name)_as_${classname.plainName}() {
return ($classname) get(#uppercase($prop.name), ${classname}.class);
}
/**
* removes all values and sets this one
* @param value the value to be set
#if($prop.getComment())
* Schema Comment: ${prop.getComment()}
#end
* Technical detail: This is modeling a property with multiple ranges.
*/
public void set${methodnameprefix}#mixedcase($prop.name)( ${classname} value ) {
set(#uppercase($prop.name), value);
}
#end ###if($prop.maxCardinality == -1 || $prop.maxCardinality == 1)
#if($prop.minCardinality != -1)
/**
* removes a value
* @param value the value to be removed
#if($prop.getComment())
* Schema Comment: ${prop.getComment()}
#end
* @throws CardinalityException if removing would change the number of
* values below the minimal cardinality $prop.minCardinality
* Technical detail: This is modeling a property with multiple ranges.
*/
public void remove${methodnameprefix}#mixedcase($prop.name)( ${classname} value )
throws CardinalityException {
remove(#uppercase($prop.name), value, $prop.minCardinality);
}
#else
/**
* removes a value
* @param value the value to be removed
#if($prop.getComment())
* Schema Comment: ${prop.getComment()}
#end
* Technical detail: This is modeling a property with multiple ranges.
*/
public void remove${methodnameprefix}#mixedcase($prop.name)( ${classname} value ) {
remove(#uppercase($prop.name), value);
}
#end ## if
#if($prop.maxCardinality > 1)
/**
* adds a value
* @param value the value to be added
#if($prop.getComment())
* Schema Comment: ${prop.getComment()}
#end
* @throws CardinalityException if adding would change the number of
* values above the maximal cardinality $prop.maxCardinality
* Technical detail: This is modeling a property with multiple ranges.
*/
public void add${methodnameprefix}#mixedcase($prop.name)( ${classname} value )
throws CardinalityException {
add(#uppercase($prop.name), value, $prop.maxCardinality );
}
#end ## if
#if($prop.maxCardinality == -1)
/**
* adds a value
* @param value the value to be added
#if($prop.getComment())
* Schema Comment: ${prop.getComment()}
#end
* Technical detail: This is modeling a property with multiple ranges.
*/
public void add${methodnameprefix}#mixedcase($prop.name)( ${classname} value ) {
add(#uppercase($prop.name), value );
}
#end ## if
/**
* @return all values
#if($prop.getComment())
* Schema Comment: ${prop.getComment()}
#end
* Technical detail: This is modeling a property with multiple ranges.
*/
public ${classname}[] getAll${methodnameprefix}#mixedcase($prop.name)_as_${classname.plainName}() {
return (${classname}[]) getAll(#uppercase($prop.name), ${classname}.class);
}
#end ## foreach
/**
* @return all values, generic version
#if($prop.getComment())
* Schema Comment: ${prop.getComment()}
#end
* Technical detail: This is modeling a property with multiple ranges.
*/
public ${root}[] getAll${methodnameprefix}#mixedcase($prop.name)() {
return (${root}[]) getAll(#uppercase($prop.name), ${root}.class);
}
#end ## multi range handling
#end ## for-each
}