jena
Klasse schemagen

public class schemagen

A vocabulary generator, that will consume an ontology or other vocabulary file, and generate a Java file with the constants from the vocabulary compiled in. Designed to be highly flexible and customisable.

Version:
CVS $Id: schemagen.java,v 1.40 2005/04/05 18:44:04 ian_dickinson Exp $
Author:
Ian Dickinson, HP Labs (email)
Feld-Detail

NS

public static final String NS
The namespace for the configuration model is "http://jena.hpl.hp.com/2003/04/schemagen#"

DEFAULT_CONFIG_URI

public static final String DEFAULT_CONFIG_URI
The default location of the configuration model is "file:schemagen.rdf"

DEFAULT_MARKER

public static final String DEFAULT_MARKER
The default marker string for denoting substitutions is "%"

DEFAULT_TEMPLATE

public static final String DEFAULT_TEMPLATE
Default template for writing out value declarations

DEFAULT_INDIVIDUAL_TEMPLATE

public static final String DEFAULT_INDIVIDUAL_TEMPLATE
Default template for writing out individual declarations

DEFAULT_HEADER_TEMPLATE

public static final String DEFAULT_HEADER_TEMPLATE
Default template for the file header

COMMENT_LENGTH_LIMIT

public static final int COMMENT_LENGTH_LIMIT
Default line length for comments before wrap

OPT_CONFIG_FILE

protected static final Object OPT_CONFIG_FILE
Select an alternative config file; use -c <filename> on command line

OPT_NO_COMMENTS

protected static final Object OPT_NO_COMMENTS
Turn off all comment output; use --nocomments on command line; use sgen:noComments in config file

OPT_INPUT

protected static final Object OPT_INPUT
Nominate the URL of the input document; use -i <URL> on command line; use sgen:input in config file

OPT_LANG_DAML

protected static final Object OPT_LANG_DAML
Specify that the language of the source is DAML+OIL; use --daml on command line; use sgen:daml in config file

OPT_LANG_OWL

protected static final Object OPT_LANG_OWL
Specify that the language of the source is OWL (the default); use --owl on command line; use sgen:owl in config file

OPT_LANG_RDFS

protected static final Object OPT_LANG_RDFS
Specify that the language of the source is RDFS; use --rdfs on command line; use sgen:rdfs in config file

OPT_OUTPUT

protected static final Object OPT_OUTPUT
Specify that destination file; use -o <fileName> on command line; use sgen:output in config file

OPT_HEADER

protected static final Object OPT_HEADER
Specify the file header; use --header "..." on command line; use sgen:header in config file

OPT_FOOTER

protected static final Object OPT_FOOTER
Specify the file footer; use --footer "..." on command line; use sgen:footer in config file

OPT_ROOT

protected static final Object OPT_ROOT
Specify the uri of the configuration root node; use --root <URL> on command line

OPT_MARKER

protected static final Object OPT_MARKER
Specify the marker string for substitutions, default is '%'; use -m "..." on command line; use sgen:marker in config file

OPT_PACKAGENAME

protected static final Object OPT_PACKAGENAME
Specify the packagename; use --package <packagename> on command line; use sgen:package in config file

OPT_ONTOLOGY

protected static final Object OPT_ONTOLOGY
Use ontology terms in preference to vanilla RDF; use --ontology on command line; use sgen:ontology in config file

OPT_CLASSNAME

protected static final Object OPT_CLASSNAME
The name of the generated class; use -n <classname> on command line; use sgen:classname in config file

OPT_CLASSDEC

protected static final Object OPT_CLASSDEC
Additional decoration for class header (such as implements); use --classdec <classname> on command line; use sgen:classdec in config file

OPT_NAMESPACE

protected static final Object OPT_NAMESPACE
The namespace URI for the vocabulary; use - <uri> on command line; use sgen:namespace in config file

OPT_DECLARATIONS

protected static final Object OPT_DECLARATIONS
Additional declarations to add at the top of the class; use --declarations <...> on command line; use sgen:declarations in config file

OPT_PROPERTY_SECTION

protected static final Object OPT_PROPERTY_SECTION
Section declaration for properties section; use --propSection <...> on command line; use sgen:propSection in config file

OPT_CLASS_SECTION

protected static final Object OPT_CLASS_SECTION
Section declaration for class section; use --classSection <...> on command line; use sgen:classSection in config file

OPT_INDIVIDUALS_SECTION

protected static final Object OPT_INDIVIDUALS_SECTION
Section declaration for individuals section; use --individualsSection <...> on command line; use sgen:individualsSection in config file

OPT_NOPROPERTIES

protected static final Object OPT_NOPROPERTIES
Option to suppress properties in vocab file; use --noproperties <...> on command line; use sgen:noproperties in config file

OPT_NOCLASSES

protected static final Object OPT_NOCLASSES
Option to suppress classes in vocab file; use --noclasses <...> on command line; use sgen:noclasses in config file

OPT_NOINDIVIDUALS

protected static final Object OPT_NOINDIVIDUALS
Option to suppress individuals in vocab file; use --noindividuals <...> on command line; use sgen:noindividuals in config file

OPT_NOHEADER

protected static final Object OPT_NOHEADER
Option for no file header; use --noheader <...> on command line; use sgen:noheader in config file

OPT_PROP_TEMPLATE

protected static final Object OPT_PROP_TEMPLATE
Template for writing out property declarations; use --propTemplate <...> on command line; use sgen:propTemplate in config file

OPT_CLASS_TEMPLATE

protected static final Object OPT_CLASS_TEMPLATE
Template for writing out class declarations; use --classTemplate <...> on command line; use sgen:classTemplate in config file

OPT_INDIVIDUAL_TEMPLATE

protected static final Object OPT_INDIVIDUAL_TEMPLATE
Template for writing out individual declarations; use --individualTemplate <...> on command line; use sgen:individualTemplate in config file

OPT_UC_NAMES

protected static final Object OPT_UC_NAMES
Option for mapping constant names to uppercase; use --uppercase <...> on command line; use sgen:uppercase in config file

OPT_INCLUDE

protected static final Object OPT_INCLUDE
Option for including non-local URI's in vocabulary; use --include <uri> on command line; use sgen:include in config file

OPT_CLASSNAME_SUFFIX

protected static final Object OPT_CLASSNAME_SUFFIX
Option for adding a suffix to the generated class name; use --classnamesuffix <uri> on command line; use sgen:classnamesuffix in config file

OPT_ENCODING

protected static final Object OPT_ENCODING
Option for the presentation syntax (encoding) of the file; use -e encoding on command line; use sgen:encoding in config file

OPT_HELP

protected static final Object OPT_HELP
Option to show the usage message; use --help on command line

OPT_DOS

protected static final Object OPT_DOS
Option to generate an output file with DOS (\r\n) line endings. Default is Unix line endings.

OPT_USE_INF

protected static final Object OPT_USE_INF
Option to generate to force the model to perform inference, off by default.

m_cmdLineArgs

protected List m_cmdLineArgs
The list of command line arguments

m_root

protected Resource m_root
The root of the options in the config file

m_config

protected Model m_config
The model that contains the configuration information

m_source

protected OntModel m_source
The model that contains the input source

m_output

protected PrintStream m_output
The output stream we write to

m_optionDefinitions

protected Object[][] m_optionDefinitions
Option definitions

m_replacements

protected List m_replacements
Stack of replacements to apply

m_perlCompiler

protected Perl5Compiler m_perlCompiler
Perl5 pattern compiler

m_matcher

protected PatternMatcher m_matcher
Perl5 pattern matcher

m_nl

protected String m_nl
Output file newline char - default is Unix, override with --dos

m_indentStep

protected int m_indentStep
Size of indent step

m_usedNames

protected Set m_usedNames
Set of names used so far

m_resourcesToNames

protected Map m_resourcesToNames
Map from resources to java names

m_includeURI

protected List m_includeURI
List of allowed namespace URI strings for admissible values

Methoden-Detail

go

protected void go(String[] args)
Read the configuration parameters and do setup

processInput

protected void processInput()
The sequence of steps to process an entire file

determineConfigRoot

protected void determineConfigRoot()
Determine the root resource in the configuration file

determineLanguage

protected void determineLanguage()
Create the source model after determining which input language

selectInput

protected void selectInput()
Identify the URL that is to be read in and translated to a vocab file, and load the source into the source model

selectOutput

protected void selectOutput()
Identify the file we are to write the output to

processHeader

protected void processHeader()
Process the header at the start of the file, if defined

processFooter

protected void processFooter()
Process the footer at the end of the file, if defined

setGlobalReplacements

protected void setGlobalReplacements()
The list of replacements that are always available

addReplacementPattern

protected void addReplacementPattern(String key,
                                     String replacement)
Add a pattern-value pair to the list of available patterns

pop

protected void pop(int n)
Pop n replacements off the stack

closeOutput

protected void closeOutput()
Close the output file

isTrue

protected boolean isTrue(Object option)
Answer true if the given option is set to true

hasValue

protected boolean hasValue(Object option)
Answer true if the given option has value

hasResourceValue

protected boolean hasResourceValue(Object option)
Answer true if the given option has a resource value

getValue

protected String getValue(Object option)
Answer the value of the option or null

getAllValues

protected List getAllValues(Object option)
Answer all values for the given options as Strings

getResource

protected Resource getResource(Object option)
Answer the value of the option or null

getOpt

protected OptionDefinition getOpt(Object option)
Answer the option object for the given option

abort

protected void abort(String msg,
                     Exception e)
Abort due to exception

usage

protected void usage()
Print usage message and abort

substitute

protected String substitute(String sIn)
Use the current replacements list to do the subs in the given string

indentTo

protected int indentTo(int i,
                       StringBuffer buf)
Add the appropriate indent to a buffer

writeln

protected void writeln(int indent)
Write a blank line, with indent and newline

writeln

protected void writeln(int indent,
                       String s)
Write out the given string with n spaces of indent, with newline

write

protected void write(int indentLevel,
                     String s)
Write out the given string with n spaces of indent

getImports

protected String getImports()
Determine the list of imports to include in the file

getClassName

protected String getClassName()
Determine the class name of the vocabulary from the uri

useOntology

protected boolean useOntology()
Answer true if we are using ontology terms in this vocabulary

noComments

protected boolean noComments()
Answer true if all comments are suppressed

asLegalJavaID

protected String asLegalJavaID(String s,
                               boolean cap)
Convert s to a legal Java identifier; capitalise first char if cap is true

writeClassDeclaration

protected void writeClassDeclaration()
The opening class declaration

writeClassClose

protected void writeClassClose()
The close of the class decoration

writeInitialDeclarations

protected void writeInitialDeclarations()
Write the declarations at the head of the class

writeModelDeclaration

protected void writeModelDeclaration()
Write the declaration of the model

writeNamespace

protected void writeNamespace()
Write the string and resource that represent the namespace

determineNamespaceURI

protected String determineNamespaceURI()
Determine what the namespace URI for this vocabulary is

writeProperties

protected void writeProperties()
Write the list of properties

writeObjectProperties

protected void writeObjectProperties()
Write any object properties in the vocabulary

writeDatatypeProperties

protected void writeDatatypeProperties()
Write any datatype properties in the vocabulary

writeAnnotationProperties

protected void writeAnnotationProperties()
Write any annotation properties in the vocabulary

writeRDFProperties

protected void writeRDFProperties()
Write any vanilla RDF properties in the vocabulary

writeClasses

protected void writeClasses()
Write any classes in the vocabulary

writeOntClasses

protected void writeOntClasses()
Write classes as ontology terms

writeRDFClasses

protected void writeRDFClasses()
Write classes as vanilla RDF terms

writeIndividuals

protected void writeIndividuals()
Write any instances (individuals) in the vocabulary

writeOntIndividuals

protected void writeOntIndividuals()
Write individuals as ontology terms

writeRDFIndividuals

protected void writeRDFIndividuals()
Write individuals as vanilla RDF terms

writeValue

protected void writeValue(Resource r,
                          String template,
                          String valueClass,
                          String creator,
                          String disambiguator)
Write the value declaration out using the given template, optionally creating comments

hasComment

protected boolean hasComment(Resource r)
Answer true if the given resource has an rdf:comment or daml:comment

getComment

protected String getComment(Resource r)
Answer all of the commentage on the given resource, as a string

formatComment

protected String formatComment(String comment)
Format the comment as Javadoc, and limit the line width

filter

protected boolean filter(Resource r)
Answer true if resource r does not show in output

getValueName

protected String getValueName(Resource r,
                              String disambiguator)
Answer the Java value name for the URI

getUCValueName

protected String getUCValueName(Resource r)
Answer the local name of resource r mapped to upper case

urlCheck

protected String urlCheck(String uriOrFile)
Return a URI formed from the given string, unchanged if it's already a URI or converted to a file URI otherwise. If not recognisable as a URL, abort.