org.openanzo.jastor
Class JastorContext

java.lang.Object
  extended by org.openanzo.jastor.JastorContext

public class JastorContext
extends java.lang.Object

This class holds context information for code generation: ontGraphs, options, names, etc...

Author:
Ben Szekely ( bhszekel@us.ibm.com )

Field Summary
static java.lang.String ONT_LANG_OWL
          OWL type extension
static java.lang.String ONT_LANG_RDFS
          RDFS type extension
 
Constructor Summary
JastorContext()
          Construct an empty context with initially nothing to generate
JastorContext(INamedGraph ontGraph, java.util.List<org.openrdf.model.Resource> classesToGenerate, java.lang.String ontologyURI, java.lang.String packageName)
          This constructor should be used when the ontGraph is fully assembled.
 
Method Summary
 void addOntologyClassTemplate(java.lang.String name, OntologyClassTemplate ontgen)
          Add a generation template to be run for each ontology class
 void addOntologyDependency(java.io.InputStream ontologyFile, java.lang.String ontologyURI, java.lang.String packagename)
          Specify an ontology needed by one of the generation ontologies.
 void addOntologyDependency(java.io.InputStream ontologyFile, java.lang.String rdflang, java.lang.String ontologyURI, java.lang.String packagename)
          Specify an ontology needed by one of the generation ontologies.
 void addOntologyDependency(java.io.InputStream ontologyFile, java.lang.String ontLang, java.lang.String rdflang, java.lang.String ontologyURI, java.lang.String packagename)
          Specify an ontology needed by one of the generation ontologies.
 void addOntologyTemplate(java.lang.String name, OntologyTemplate ontgen)
          Add a generation template to be run for each ontology
 void addOntologyToGenerate(INamedGraph ontGraph, java.lang.String ontologyURI, java.lang.String packagename)
          Specify an ontology to generate
 void addOntologyToGenerate(INamedGraph ontGraph, java.lang.String ontlang, java.lang.String ontologyURI, java.lang.String packagename)
          Specify an ontology to generate
 void addOntologyToGenerate(java.io.InputStream ontologyFile, java.lang.String ontologyURI, java.lang.String packagename)
          Specify an OWL ontology to generate
 void addOntologyToGenerate(java.io.InputStream ontologyFile, java.lang.String rdflang, java.lang.String ontologyURI, java.lang.String packagename)
          Specify an OWL ontology to generate
 void addOntologyToGenerate(java.io.InputStream ontologyFile, java.lang.String ontLang, java.lang.String rdflang, java.lang.String ontologyURI, java.lang.String packagename)
          Specify an ontology to generate
 void finalize()
          Should be called to finalize the context after all ontologies have been added but before generation
 java.lang.Class<?> getBaseLiteralClass()
          Get the base literal Class for this context
 java.lang.String getNamespacePrefix(java.lang.String ns)
          Get the prefix for a namespace
 java.lang.String getNamespaceRemapper(java.lang.String namespace)
          Get a replace namespace for the given namespace
 INamedGraph getOntGraph()
          Get the INamedGraph that contains the ontology data
 java.util.Map<java.lang.String,OntologyClassTemplate> getOntologyClassTemplates()
          Get the mapping of ontology class template names to their template class
 org.openrdf.model.URI getOntologyForClass(org.openrdf.model.Resource ontClassURI)
          Get the Ontology for the given class URI
 org.openrdf.model.URI getOntologyForPackage(java.lang.String pkg)
          Get the Ontology for the given Package
 java.util.Map<java.lang.String,OntologyTemplate> getOntologyTemplates()
          Get the mapping of ontology template names to their template class
 java.lang.String getPackageForClass(org.openrdf.model.Resource ontClassURI)
          Get the Package name for the given class URI
 java.lang.String getPackageForOntology(org.openrdf.model.Resource ontologyURI)
          Get the Package for the given ontology URI
 java.lang.Class<?> getThingFactory()
          Return the Class of the base Thing factory
 java.lang.Class<?> getThingImpl()
          Return the Class of the base Thing implementation
 java.lang.Class<?> getThingInterface()
          Return the Class of the base Thing interface
 java.util.List<OntologyClass> getUnionClassExtensions(org.openrdf.model.Resource classURI)
          Return a list of OntologyClass that the given class should extend because the returned classes are unions of classuri.
 java.util.List<OntologyProperty> getUnionDomainProperties(org.openrdf.model.Resource classuri)
          Return a list or OntologyProperty that are properies declared with a domain that is a union of classes.
 boolean isAddAllRDFTypesInHierarchy()
          Determine if all RDF types in the classes hierarchy should be added
 boolean isGenerateCacheInFactory()
          Determine if we generate a cache of objects within the ontology factory
 boolean isGenerateListeners()
          Determine if we generate listeners for the beans
 boolean isGeneratePropertyCache()
          Determine if we generate caches for property values in beans
 boolean isGenerateStandardCode()
          Determine if we generate standard code
 boolean isGenerateVocabularyOnly()
          Determine if we generate only vocabulary files for the ontology
 boolean isIncludeCopyright()
          Determine if generated code should include copyright statements
 boolean isPropetyAndClassDefinedInSameOntology(org.openrdf.model.Resource ontPropertyUri, org.openrdf.model.Resource ontClassUri)
          Check if ontology and class are part of same ontology
 boolean isReturnNullOnMissingTypes()
          Determine if code returns null on missing types
 boolean isUseEntireURIForIdentifiers()
          Determine if we use the entire URI for identifiers
 boolean isUsePackageNameForRestrictedRanges()
          Determine if we use package names for restricted ranges
 boolean isUseStrictTypeChecking()
          Determine if we use strict type checking
 boolean isUseTypedLiterals()
          Determine if we used typed literals
 java.util.List<Ontology> listOntologiesToGenerate()
          Return a list of Ontology objects representing all the ontologies to be generated
 java.util.List<OntologyClass> listOntologyClassesToGenerate()
          Return a List of OntologyClass objects representing all the classes to be generated.
 java.lang.String remapUri(java.lang.String uri)
          Determine if the namespace for a URI needs to be replace, and replace if necessary
 java.lang.String remapUri(org.openrdf.model.URI uri)
          Determine if the namespace for a URI needs to be replace, and replace if necessary
 void setAddAllRDFTypesInHierarchy(boolean addAllRDFTypesInHierarchy)
          Set if all RDF types in the classes hierarchy should be added
 void setBaseLiteralClass(java.lang.String baseLiteralClass)
          Set the base literal Class for this context
 void setCustomThing(java.lang.String thingInterface, java.lang.String thingImpl, java.lang.String thingFactory)
          Set a custom thing implementation.
 void setGenerateCacheInFactory(boolean generateCacheInFactory)
          Set if we generate a cache of objects within the ontology factory
 void setGenerateListeners(boolean generateListeners)
          Indicate whether or not to generate listeners, default true
 void setGeneratePropertyCache(boolean generatePropertyCache)
          Set if we generate caches for property values in beans
 void setGenerateStandardCode(boolean generateStandardCode)
          Set if we generate standard code
 void setGenerateVocabularyOnly(boolean generateVocabularyOnly)
          Set if we generate only vocabulary files for the ontology
 void setIncludeCopyright(boolean includeCopyright)
          Set if generated code should include copyright statements
 void setNamespacePrefix(java.lang.String ns, java.lang.String prefix)
          Add a new mapping between a prefix and a full namespace.
 void setNamespaceRemapper(java.lang.String namespace, java.lang.String remappedNamesapce)
          Set a remapped namespace for the given namespace
 void setReturnNullOnMissingTypes(boolean returnNullOnMissingTypes)
          Set if code returns null on missing types
 void setUseEntireURIForIdentifiers(boolean useEntireURIForIdentifiers)
          Set if we use the entire URI for identifiers
 void setUsePackageNameForRestrictedRanges(boolean usePackageNameForRestrictedRanges)
          Set if we use package names for restricted ranges
 void setUseStrictTypeChecking(boolean useStrictTypeChecking)
          Set if we use strict type checking
 void setUseTypedLiterals(boolean useTypedLiterals)
          Set if we used typed literals
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ONT_LANG_OWL

public static final java.lang.String ONT_LANG_OWL
OWL type extension

See Also:
Constant Field Values

ONT_LANG_RDFS

public static final java.lang.String ONT_LANG_RDFS
RDFS type extension

See Also:
Constant Field Values
Constructor Detail

JastorContext

public JastorContext(INamedGraph ontGraph,
                     java.util.List<org.openrdf.model.Resource> classesToGenerate,
                     java.lang.String ontologyURI,
                     java.lang.String packageName)
This constructor should be used when the ontGraph is fully assembled. A future version might allow packages to be specified per class

Parameters:
ontGraph - INamedGraph containing ontology data
classesToGenerate - List of classes to generate
ontologyURI - String representation of the ontology to generate
packageName - Name of the package for generated classes

JastorContext

public JastorContext()
Construct an empty context with initially nothing to generate

Method Detail

finalize

public void finalize()
Should be called to finalize the context after all ontologies have been added but before generation

Overrides:
finalize in class java.lang.Object

setCustomThing

public void setCustomThing(java.lang.String thingInterface,
                           java.lang.String thingImpl,
                           java.lang.String thingFactory)
                    throws JastorException
Set a custom thing implementation.

Parameters:
thingInterface - - the classname of an extension of Thing
thingImpl - - the classname of an extension of ThingImpl
thingFactory - the classname of an extension of ThingFactory
Throws:
JastorException

getThingInterface

public java.lang.Class<?> getThingInterface()
Return the Class of the base Thing interface

Returns:
the Class of the base Thing interface

getThingImpl

public java.lang.Class<?> getThingImpl()
Return the Class of the base Thing implementation

Returns:
the Class of the base Thing implementation

getThingFactory

public java.lang.Class<?> getThingFactory()
Return the Class of the base Thing factory

Returns:
the Class of the base Thing factory

addOntologyToGenerate

public void addOntologyToGenerate(java.io.InputStream ontologyFile,
                                  java.lang.String ontologyURI,
                                  java.lang.String packagename)
Specify an OWL ontology to generate

Parameters:
ontologyFile - The InputStream containing the ontology document
ontologyURI - The URI of the ontology
packagename - The Java package that generate classes should be in.

addOntologyToGenerate

public void addOntologyToGenerate(java.io.InputStream ontologyFile,
                                  java.lang.String rdflang,
                                  java.lang.String ontologyURI,
                                  java.lang.String packagename)
Specify an OWL ontology to generate

Parameters:
ontologyFile - The InputStream containing the ontology document
rdflang - The seriazation format of the ontology file (N3,RDF/XM)
ontologyURI - The URI of the ontology
packagename - The Java package that generate classes should be in.

addOntologyToGenerate

public void addOntologyToGenerate(java.io.InputStream ontologyFile,
                                  java.lang.String ontLang,
                                  java.lang.String rdflang,
                                  java.lang.String ontologyURI,
                                  java.lang.String packagename)
Specify an ontology to generate

Parameters:
ontologyFile - The InputStream containing the ontology document
ontLang - The Ontology Language, owl or rdfs.
rdflang - The serialization format of the ontology file (N3,RDF/XM,)
ontologyURI - The URI of the ontology
packagename - The Java package that generate classes should be in.

addOntologyToGenerate

public void addOntologyToGenerate(INamedGraph ontGraph,
                                  java.lang.String ontologyURI,
                                  java.lang.String packagename)
Specify an ontology to generate

Parameters:
ontGraph - An INamedGraph containing the ontology
ontologyURI - The URI of the ontology
packagename - The Java package that generate classes should be in.

addOntologyToGenerate

public void addOntologyToGenerate(INamedGraph ontGraph,
                                  java.lang.String ontlang,
                                  java.lang.String ontologyURI,
                                  java.lang.String packagename)
Specify an ontology to generate

Parameters:
ontGraph - An INamedGraph containing the ontology
ontlang - The Ontology Language, owl or rdfs.
ontologyURI - The URI of the ontology
packagename - The Java package that generate classes should be in.

addOntologyDependency

public void addOntologyDependency(java.io.InputStream ontologyFile,
                                  java.lang.String ontologyURI,
                                  java.lang.String packagename)
Specify an ontology needed by one of the generation ontologies. One of these entries should be added for every import in every ontology to generate.We have this call because imports aren't automatically loaded.

Parameters:
ontologyFile - The InputStream containing the ontology document
ontologyURI - The URI of the ontology
packagename - The Java package that generate classes should be in.

addOntologyDependency

public void addOntologyDependency(java.io.InputStream ontologyFile,
                                  java.lang.String rdflang,
                                  java.lang.String ontologyURI,
                                  java.lang.String packagename)
Specify an ontology needed by one of the generation ontologies. One of these entries should be added for every import in every ontology to generate. We have this call because imports aren't automatically loaded.

Parameters:
ontologyFile - The InputStream containing the ontology document
rdflang - The seriazation format of the ontology file (N3,RDF/XM,...all supported formats)
ontologyURI - The URI of the ontology
packagename - The Java package that generate classes should be in.

addOntologyDependency

public void addOntologyDependency(java.io.InputStream ontologyFile,
                                  java.lang.String ontLang,
                                  java.lang.String rdflang,
                                  java.lang.String ontologyURI,
                                  java.lang.String packagename)
Specify an ontology needed by one of the generation ontologies. One of these entries should be added for every import in every ontology to generate. We have this call because imports aren't automatically loaded.

Parameters:
ontologyFile - The InputStream containing the ontology document
ontLang - The Ontology Language, owl or rdfs.
rdflang - The serialization format of the ontology file (N3,RDF/XM)
ontologyURI - The URI of the ontology
packagename - The Java package that generate classes should be in.

listOntologyClassesToGenerate

public java.util.List<OntologyClass> listOntologyClassesToGenerate()
Return a List of OntologyClass objects representing all the classes to be generated.

Returns:
a List of OntologyClass objects representing all the classes to be generated.

listOntologiesToGenerate

public java.util.List<Ontology> listOntologiesToGenerate()
Return a list of Ontology objects representing all the ontologies to be generated

Returns:
a list of Ontology objects representing all the ontologies to be generated

isGenerateListeners

public boolean isGenerateListeners()
Determine if we generate listeners for the beans

Returns:
true if we generate listeners for the beans, default true

setGenerateListeners

public void setGenerateListeners(boolean generateListeners)
Indicate whether or not to generate listeners, default true

Parameters:
generateListeners - set whether or not to generate listeners

isGeneratePropertyCache

public boolean isGeneratePropertyCache()
Determine if we generate caches for property values in beans

Returns:
true if we generate caches for property values in beans

setGeneratePropertyCache

public void setGeneratePropertyCache(boolean generatePropertyCache)
Set if we generate caches for property values in beans

Parameters:
generatePropertyCache - sets if we generate caches for property values in beans

isGenerateVocabularyOnly

public boolean isGenerateVocabularyOnly()
Determine if we generate only vocabulary files for the ontology

Returns:
true if we generate only vocabulary files for the ontology

setGenerateVocabularyOnly

public void setGenerateVocabularyOnly(boolean generateVocabularyOnly)
Set if we generate only vocabulary files for the ontology

Parameters:
generateVocabularyOnly - sets if we generate only vocabulary files for the ontology

isUseEntireURIForIdentifiers

public boolean isUseEntireURIForIdentifiers()
Determine if we use the entire URI for identifiers

Returns:
true if we use the entire URI for identifiers

setUseEntireURIForIdentifiers

public void setUseEntireURIForIdentifiers(boolean useEntireURIForIdentifiers)
Set if we use the entire URI for identifiers

Parameters:
useEntireURIForIdentifiers - sets if we use the entire URI for identifiers

isGenerateCacheInFactory

public boolean isGenerateCacheInFactory()
Determine if we generate a cache of objects within the ontology factory

Returns:
true if we generate a cache of objects within the ontology factory

setGenerateCacheInFactory

public void setGenerateCacheInFactory(boolean generateCacheInFactory)
Set if we generate a cache of objects within the ontology factory

Parameters:
generateCacheInFactory - sets if we generate a cache of objects within the ontology factory

isUsePackageNameForRestrictedRanges

public boolean isUsePackageNameForRestrictedRanges()
Determine if we use package names for restricted ranges

Returns:
true if we use package names for restricted ranges

setUsePackageNameForRestrictedRanges

public void setUsePackageNameForRestrictedRanges(boolean usePackageNameForRestrictedRanges)
Set if we use package names for restricted ranges

Parameters:
usePackageNameForRestrictedRanges - sets if we use package names for restricted ranges

isUseStrictTypeChecking

public boolean isUseStrictTypeChecking()
Determine if we use strict type checking

Returns:
true if we use strict type checking

setUseStrictTypeChecking

public void setUseStrictTypeChecking(boolean useStrictTypeChecking)
Set if we use strict type checking

Parameters:
useStrictTypeChecking - sets if we use strict type checking

isGenerateStandardCode

public boolean isGenerateStandardCode()
Determine if we generate standard code

Returns:
true if we generate standard code

setGenerateStandardCode

public void setGenerateStandardCode(boolean generateStandardCode)
Set if we generate standard code

Parameters:
generateStandardCode - sets if we generate standard code

isUseTypedLiterals

public boolean isUseTypedLiterals()
Determine if we used typed literals

Returns:
true if we used typed literals

setUseTypedLiterals

public void setUseTypedLiterals(boolean useTypedLiterals)
Set if we used typed literals

Parameters:
useTypedLiterals - sets if we used typed literals

isAddAllRDFTypesInHierarchy

public boolean isAddAllRDFTypesInHierarchy()
Determine if all RDF types in the classes hierarchy should be added

Returns:
true if all RDF types in the classes hierarchy should be added

setAddAllRDFTypesInHierarchy

public void setAddAllRDFTypesInHierarchy(boolean addAllRDFTypesInHierarchy)
Set if all RDF types in the classes hierarchy should be added

Parameters:
addAllRDFTypesInHierarchy - sets if all RDF types in the classes hierarchy should be added

getOntGraph

public INamedGraph getOntGraph()
Get the INamedGraph that contains the ontology data

Returns:
the INamedGraph that contains the ontology data

getOntologyForClass

public org.openrdf.model.URI getOntologyForClass(org.openrdf.model.Resource ontClassURI)
Get the Ontology for the given class URI

Parameters:
ontClassURI - URI of class for which to get ontology
Returns:
URI of ontology for given class

getPackageForClass

public java.lang.String getPackageForClass(org.openrdf.model.Resource ontClassURI)
Get the Package name for the given class URI

Parameters:
ontClassURI - URI of class for which to get Package
Returns:
Package for given class

getPackageForOntology

public java.lang.String getPackageForOntology(org.openrdf.model.Resource ontologyURI)
Get the Package for the given ontology URI

Parameters:
ontologyURI - URI of ontology for which to get Package
Returns:
Package for given ontology

getOntologyForPackage

public org.openrdf.model.URI getOntologyForPackage(java.lang.String pkg)
Get the Ontology for the given Package

Parameters:
pkg - Package for which to get ontology
Returns:
URI of ontology for given Package

getUnionClassExtensions

public java.util.List<OntologyClass> getUnionClassExtensions(org.openrdf.model.Resource classURI)
Return a list of OntologyClass that the given class should extend because the returned classes are unions of classuri. Returns an empty list if no extensions exist. We pre-compute this table because the corresponding per-class query is messy and inefficient.

Parameters:
classURI - URI of class to get OntologyClasses for
Returns:
list of OntologyClass that the given class

getUnionDomainProperties

public java.util.List<OntologyProperty> getUnionDomainProperties(org.openrdf.model.Resource classuri)
Return a list or OntologyProperty that are properies declared with a domain that is a union of classes.

Parameters:
classuri - URI of union domain
Returns:
list or OntProperty that are properies declared with a domain

addOntologyClassTemplate

public void addOntologyClassTemplate(java.lang.String name,
                                     OntologyClassTemplate ontgen)
Add a generation template to be run for each ontology class

Parameters:
name - template name
ontgen - template for code generation

addOntologyTemplate

public void addOntologyTemplate(java.lang.String name,
                                OntologyTemplate ontgen)
Add a generation template to be run for each ontology

Parameters:
name - template name
ontgen - template for code generation

getOntologyClassTemplates

public java.util.Map<java.lang.String,OntologyClassTemplate> getOntologyClassTemplates()
Get the mapping of ontology class template names to their template class

Returns:
the mapping of ontology class template names to their template class

getOntologyTemplates

public java.util.Map<java.lang.String,OntologyTemplate> getOntologyTemplates()
Get the mapping of ontology template names to their template class

Returns:
the mapping of ontology template names to their template class

setNamespacePrefix

public void setNamespacePrefix(java.lang.String ns,
                               java.lang.String prefix)
Add a new mapping between a prefix and a full namespace.

Parameters:
ns - full namespace
prefix - prefixed namespace

getNamespacePrefix

public java.lang.String getNamespacePrefix(java.lang.String ns)
Get the prefix for a namespace

Parameters:
ns - namespace to lookup
Returns:
prefix for the namespace, or if no prefix is found, ns[number] is used

isPropetyAndClassDefinedInSameOntology

public boolean isPropetyAndClassDefinedInSameOntology(org.openrdf.model.Resource ontPropertyUri,
                                                      org.openrdf.model.Resource ontClassUri)
Check if ontology and class are part of same ontology

Parameters:
ontPropertyUri - URI of property to check
ontClassUri - URI of class to check
Returns:
true if ontology and class are part of same ontology

getBaseLiteralClass

public java.lang.Class<?> getBaseLiteralClass()
Get the base literal Class for this context

Returns:
the base literal Class for this context

setBaseLiteralClass

public void setBaseLiteralClass(java.lang.String baseLiteralClass)
                         throws JastorException
Set the base literal Class for this context

Parameters:
baseLiteralClass - the name of the base literal Class for this context
Throws:
JastorException - if the Class does not exist

isReturnNullOnMissingTypes

public boolean isReturnNullOnMissingTypes()
Determine if code returns null on missing types

Returns:
true if code returns null on missing types

setReturnNullOnMissingTypes

public void setReturnNullOnMissingTypes(boolean returnNullOnMissingTypes)
Set if code returns null on missing types

Parameters:
returnNullOnMissingTypes - Set if code returns null on missing types

isIncludeCopyright

public boolean isIncludeCopyright()
Determine if generated code should include copyright statements

Returns:
true if generated code should include copyright statements

setIncludeCopyright

public void setIncludeCopyright(boolean includeCopyright)
Set if generated code should include copyright statements

Parameters:
includeCopyright - Set if generated code should include copyright statements

getNamespaceRemapper

public java.lang.String getNamespaceRemapper(java.lang.String namespace)
Get a replace namespace for the given namespace

Parameters:
namespace - namespace to replace
Returns:
a replacement namespace for the given namespace

setNamespaceRemapper

public void setNamespaceRemapper(java.lang.String namespace,
                                 java.lang.String remappedNamesapce)
Set a remapped namespace for the given namespace

Parameters:
namespace - namespace to replace
remappedNamesapce - remapped namespace to use in its place

remapUri

public java.lang.String remapUri(org.openrdf.model.URI uri)
Determine if the namespace for a URI needs to be replace, and replace if necessary

Parameters:
uri - URI to check
Returns:
a new URI with its namespace remapped, if there is a remapping for the namespace

remapUri

public java.lang.String remapUri(java.lang.String uri)
Determine if the namespace for a URI needs to be replace, and replace if necessary

Parameters:
uri - URI to check
Returns:
a new URI with its namespace remapped, if there is a remapping for the namespace


Copyright © 2007 Cambridge Semantics Inc.. All Rights Reserved.