All Downloads are FREE. Search and download functionalities are using the official Maven repository.

rdfreactor.generator.5.0.0.source-code.class.vm Maven / Gradle / Ivy

Go to download

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.

There is a newer version: 5.0.1
Show newest version
##     ----------------------------------------------------------------------
##    |  string manipulation utilities
##
#macro( mixedcase $name )$name.substring(0,1).toUpperCase()$name.substring(1)#end
#macro( lowercase $name )$name.toLowerCase()#end
#macro( uppercase $name )$name.toUpperCase()#end
#macro( comment   $indent $name )#if($name.getComment().length() > 0)
${indent}* Comment from schema: ${name.getComment()}
${indent}*
#end
#end
##  production
##macro( debug $text )$!{nix}#end
## debug
#macro( debug $text )	 *
	 * [Generated from RDFReactor template rule #${text}]
#end
#set( $UNDEFINED = -1 )
##     -----------------------------------------------------------------------
##    |  package declaration and comment
##
/*
 * generated by http://RDFReactor.semweb4j.org ($generatorVersion) on ${now}
 */
package $package.name;

##     -----------------------------------------------------------------------
##    |  imports
##
import org.ontoware.aifbcommons.collection.ClosableIterator;
import org.ontoware.rdf2go.exception.ModelRuntimeException;
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.rdfreactor.runtime.Base;
import org.ontoware.rdfreactor.runtime.ReactorResult;
#if ($class.cardinalityexception)
import org.ontoware.rdfreactor.runtime.CardinalityException;
#end## conditional import

##     -----------------------------------------------------------------------
##    |  class comment
##
/**
#comment(" " $class)
#if ($class.properties.size() > 0)
 * This class manages access to these properties:
 * 
    #foreach( $prop in $class.properties ) *
  • #mixedcase($prop.name)
  • #end##foreach *
#end## if ($class.properties.size() > 0) * * This class was generated by RDFReactor on ${now} */ ## ----------------------------------------------------------------------- ## | class declaration ## public class ${class.name} extends $class.superclass { ## ----------------------------------------------------------------------- ## | URI constants for properties ## private static final long serialVersionUID = ${serialVersionUID}L; /** ${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## foreach( $prop in $class.properties ) /** * All property-URIs with this class as domain. * All properties of all super-classes are also available. */ public static final URI[] MANAGED_URIS = { #foreach( $prop in $class.properties ) new URIImpl("${prop.mappedTo}", false)#if (${velocityCount} < $class.properties.size()), #end## #foreach( $prop in $class.properties ) #end }; ## ----------------------------------------------------------------------- ## | constructors ## // 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 #debug("c1") */ 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 #debug("c2") */ 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 #debug("c3") */ 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 #debug("c4") */ 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 #debug("c5") */ 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 #debug("c6") */ public ${class.name} (Model model) { this(model, model.newRandomUniqueURI(), true); } #else###if( $writetostore ) /** * 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 * @throws ModelRuntimeException if URI syntax is wrong #debug("c7") */ public ${class.name} (Model model, String uriString, boolean write) throws ModelRuntimeException { 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 #debug("c8") */ 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 #debug("c9") */ public ${class.name} (Model model, boolean write) { super(model, RDFS_CLASS, model.newRandomUniqueURI(), write); } #end###if( $writetostore ) ## ----------------------------------------------------------------------- ## | static methods ## /////////////////////////////////////////////////////////////////// // typing /** * Return an existing instance of this class in the model. No statements are written. * @param model an RDF2Go model * @param instanceResource an RDF2Go resource * @return an instance of ${class.name} or null if none existst #debug("class0") */ public static ${class.name} getInstance(Model model, Resource instanceResource) { return Base.getInstance(model, instanceResource, ${class.name}.class); } /** * Create a new instance of this class in the model. * That is, create the statement (instanceResource, RDF.type, $class.mappedTo). * @param model an RDF2Go model * @param instanceResource an RDF2Go resource #debug("class1") */ public static void createInstance(Model model, Resource instanceResource) { Base.createInstance(model, RDFS_CLASS, instanceResource); } /** * @param model an RDF2Go model * @param instanceResource an RDF2Go resource * @return true if instanceResource is an instance of this class in the model #debug("class2") */ public static boolean hasInstance(Model model, Resource instanceResource) { return Base.hasInstance(model, RDFS_CLASS, instanceResource); } /** * @param model an RDF2Go model * @return all instances of this class in Model 'model' as RDF resources #debug("class3") */ public static ClosableIterator getAllInstances(Model model) { return Base.getAllInstances(model, RDFS_CLASS, Resource.class); } /** * @param model an RDF2Go model * @return all instances of this class in Model 'model' as a ReactorResult, * which can conveniently be converted to iterator, list or array. #debug("class3-as") */ public static ReactorResult getAllInstances_as(Model model) { return Base.getAllInstances_as(model, RDFS_CLASS, ${class.name}.class ); } /** * Remove triple {@code (this, rdf:type, ${class.name})} from this instance. Other triples are not affected. * To delete more, use deleteAllProperties * @param model an RDF2Go model * @param instanceResource an RDF2Go resource #debug("class4") */ public static void deleteInstance(Model model, Resource instanceResource) { Base.deleteInstance(model, RDFS_CLASS, instanceResource); } /** * Delete all triples {@code (this, *, *)}, i.e. including {@code rdf:type}. * @param model an RDF2Go model * @param instanceResource an RDF2Go resource #debug("class5") */ public static void deleteAllProperties(Model model, Resource instanceResource) { Base.deleteAllProperties(model, instanceResource); } /////////////////////////////////////////////////////////////////// // property access methods ## ----------------------------------------------------------------------- ## | inverse properties ## #foreach( $inverse in $class.inverseProperties ) /** #comment(" " $inverse) * @param model an RDF2Go model * @param objectValue * @return all A's as RDF resources, that have a relation '#mixedcase( $inverse.getInverse().getName() )' to this ${class.name} instance #debug("getallinverse1static") */ public static ClosableIterator getAll${methodnameprefix}#mixedcase($inverse.name)_Inverse(Model model, Object objectValue) { return Base.getAll_Inverse(model, ${inverse.getFirstType()}.#uppercase($inverse.name), objectValue); } /** #comment(" " $inverse) * @return all A's as RDF resources, that have a relation '#mixedcase( $inverse.getInverse().getName() )' to this ${class.name} instance #debug("getallinverse1dynamic") */ public ClosableIterator getAll${methodnameprefix}#mixedcase($inverse.name)_Inverse() { return Base.getAll_Inverse(this.model, ${inverse.getFirstType()}.#uppercase($inverse.name), this.getResource() ); } /** #comment(" " $inverse) * @param model an RDF2Go model * @param objectValue * @return all A's as a ReactorResult, that have a relation '#mixedcase( $inverse.getInverse().getName() )' to this ${class.name} instance #debug("getallinverse-as1static") */ public static ReactorResult getAll${methodnameprefix}#mixedcase($inverse.name)_Inverse_as(Model model, Object objectValue) { return Base.getAll_Inverse_as(model, ${inverse.getFirstType()}.#uppercase($inverse.name), objectValue, Resource.class); } #end## #foreach( $inverse in $class.inverseProperties ) ## ----------------------------------------------------------------------- ## | regular properties ## ## minCard == 1 => set to UNDEFINED (?) ## maxCard == 0 => remove property from model ## ## then we are left with the cases: ## * minCard = ? | 1 | n ## * maxCard = ? | 1 | n ## ## ## Generate method? ## X = yes ## - = no ## C = yes, with cardinality check ## ## ## minCard=| ? | ? | ? | 1 | 1 | 1 | n | n | n | ## maxCard=| ? | 1 | n | ? | 1 | n | ? | 1 | n | method has solution ## | | | | | | | | | | issues with ## method | | | | | | | | | | multi-range? ## ----------+---+---+---+---+---+---+---+---+---+ ## get | - | X | - | - | X | - | - | X | - | yes, _asA _asB _asNode ## getAll | X | - | X | X | - | X | X | - | X | yes _asA _asB _asNode ## add | X | C | C | X | C | C | X | C | C | yes (A), (B), (Node) ## set | X | X | X | X | X | X | - | - | - | yes (A), (B), (Node) ## remove | X | X | X | C | C | C | C | C | C | yes (A), (B), (Node) ## removeAll | X | X | X | - | - | - | - | - | - | no ## ## #foreach( $prop in $class.properties ) #set( $multirange = ($prop.types.size() != 1) ) #set( $classname = $prop.getFirstType() ) #parse("get.vm") #parse("add.vm") #parse("set.vm") #parse("remove.vm") #parse("removeall.vm") #end## #foreach( $prop in $class.properties ) }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy