Class XMLModel


  • public class XMLModel
    extends Object
    The most important model, the first access to the XML Schema information.

    Provides all XML attribute and XML element definitions from the schema. All further information can be accessed from those definitions (e.g. dependencies, constant values, data types, etc.).

    • Field Detail

      • mRootExpression

        public com.sun.msv.grammar.Expression mRootExpression
      • mLastSchemaFileName

        public String mLastSchemaFileName
    • Constructor Detail

      • XMLModel

        public XMLModel​(File schemaFile)
        Constructs new model by the grammar and a label
        Parameters:
        schemaFile - grammar to read into MSV
      • XMLModel

        public XMLModel​(File schemaFile,
                        String grammarVersion,
                        String grammarID)
        Constructs new model by the grammar and a label
        Parameters:
        schemaFile - grammar to read into MSV
        grammarVersion - numbered version used to establish timely order and create a label with the grammarID
        grammarID - identifier of the grammar (used in Velocity template and for output subdirectories - often concatenated with grammarVersion)
    • Method Detail

      • getElements

        public SortedSet<PuzzlePiece> getElements​(String qName)
        Returns:
        a set of one or more elements, which might exist in the grammar for this qName
      • getAttributes

        public SortedSet<PuzzlePiece> getAttributes​(String qName)
        Returns:
        a set of one or more elements, which might exist in the grammar for this qName
      • getGrammar

        public com.sun.msv.grammar.Grammar getGrammar()
        Returns:
        the MSV Grammar this model is based upon.
      • getGrammarVersion

        public String getGrammarVersion()
        Returns:
        the version label identifying this version of this schema (XML grammar)
      • getGrammarID

        public String getGrammarID()
        Returns:
        the grammar ID identifying this schema (XML grammar)
      • loadSchema

        public static com.sun.msv.grammar.Grammar loadSchema​(File rngFile)
        Load and parse a Schema from File.
        Parameters:
        rngFile - Schema file (RelaxNG or W3C schema)
        Returns:
        MSV Expression Tree (more specific: The tree's MSV root expression)
      • loadSchema

        public static com.sun.msv.grammar.Grammar loadSchema​(String rngFilePath)
        Load and parse a Schema from File.
        Parameters:
        rngFilePath - Schema file (RelaxNG or W3C schema)
        Returns:
        MSV Expression Tree (more specific: The tree's MSV root expression)
      • writeGrammar

        public static void writeGrammar​(com.sun.msv.grammar.Grammar g,
                                        OutputStream out)
                                 throws SAXException
        Writes a grammar to the specified output.
        Throws:
        SAXException
      • getElements

        public PuzzlePieceSet getElements()
        Get all elements, sorted by ns:local name.
        Returns:
        Unmodifiable SortedSet of elements
      • getAttributes

        public PuzzlePieceSet getAttributes()
        Get all attributes, sorted by ns:local name.
        Returns:
        Unmodifiable SortedSet of attributes
      • getElement

        public PuzzleComponent getElement​(String name)
        Get element(s) by tag name. If there are multiple elements sharing the same tag name, a PuzzlePieceSet is returned. If not, a single PuzzlePiece is returned.
        Parameters:
        name -
        Returns:
        Element PuzzlePiece(s)
      • getElement

        public PuzzlePiece getElement​(String name,
                                      int hashCode)
        Get element by tag name and hash code. The hash code distincts elements from sharing the same tag name.
        Parameters:
        name -
        hashCode -
        Returns:
        Element PuzzlePiece
      • getAttribute

        public PuzzleComponent getAttribute​(String name)
        Get attribute by tag name. If there are multiple attributes sharing the same tag name, a PuzzlePieceSet is returned. If not, a single PuzzlePiece is returned.
        Parameters:
        name -
        Returns:
        Attribute PuzzlePiece(s)
      • getAttribute

        public PuzzlePiece getAttribute​(String name,
                                        int hashCode)
        Get attribute by tag name and hash code. The hash code distincts Attributes sharing the same tag name.
        Parameters:
        name -
        hashCode -
        Returns:
        Attribute PuzzlePiece
      • camelCase

        public static String camelCase​(String raw)
        Convert a-few:words into AFewWords in CamelCase spelling
        Parameters:
        raw - input String
        Returns:
        filtered output String
      • camelCase

        public static String camelCase​(PuzzleComponent def)
        Convert a-few:words into AFewWords in CamelCase spelling
        Parameters:
        def - input
        Returns:
        filtered output String
      • javaCase

        public static String javaCase​(String raw)
        Convert a-few:words into aFewWords in spelling for java method names
        Parameters:
        raw - input String
        Returns:
        filtered output String
      • javaCase

        public static String javaCase​(PuzzleComponent def)
        Convert a-few:words into aFewWords in spelling for java method names
        Parameters:
        def - input
        Returns:
        filtered output String
      • constantCase

        public static String constantCase​(String raw)
        Convert a-few:words into A_FEW_WORDS in spelling used for Java constants
        Parameters:
        raw - input String
        Returns:
        filtered output String
      • constantCase

        public static String constantCase​(PuzzleComponent def)
        Convert a-few:words into A_FEW_WORDS in spelling used for Java constants
        Parameters:
        def - input
        Returns:
        filtered output String
      • firstWord

        public static String firstWord​(String raw)
        Assist method for camel-case adaptions or namespace extraction. Maybe not used anymore: Get first word out of a String containing delimiters like "-:/ _.,"
        Parameters:
        raw - input String
        Returns:
        filtered output String
      • firstWord

        public static String firstWord​(PuzzleComponent def)
        Maybe not used anymore: Get first word out of a PuzzleComponent object containing delimiters like "-:/ _.,"
        Parameters:
        def - input
        Returns:
        first word
      • lastWord

        public static String lastWord​(String raw)
        Maybe not used anymore: Get last word out of a String containing delimiters like "-:/ _.,"
        Parameters:
        raw - input
        Returns:
        last word
      • lastWord

        public static String lastWord​(PuzzleComponent def)
        Maybe not used anymore: Get last word out of a String containing delimiters like "-:/ _.,"
        Parameters:
        def - input
        Returns:
        last word
      • escapeKeyword

        public static String escapeKeyword​(PuzzleComponent in)
        (Java) member variable may not start with a number, so escape it
        Parameters:
        in - raw input
        Returns:
        filtered output, starting with a literal
      • escapeKeyword

        public static String escapeKeyword​(String in)
        (Java) Keyword may not start with a number, so escape it
        Parameters:
        in - raw input
        Returns:
        filtered output, starting with a literal
      • escapeLiteral

        public static String escapeLiteral​(PuzzleComponent in)
        Escape the quotation marks of String literals
        Parameters:
        in - raw input
        Returns:
        filtered output, with escaped quotation marks
      • escapeLiteral

        public static String escapeLiteral​(String in)
        Escape the quotation marks of String literals
        Parameters:
        in - raw input
        Returns:
        filtered output, with escaped quotation marks
      • extractNamespacePrefix

        public static String extractNamespacePrefix​(String name)
        Extract namespace ns from ns:local name
        Parameters:
        name - in form ns:local
        Returns:
        ns part from ns:local name
      • extractNamespacePrefix

        public static String extractNamespacePrefix​(PuzzleComponent def)
        Extract namespace ns from ns:local name
        Parameters:
        def - PuzzleComponent object
        Returns:
        ns part from ns:local name
      • extractLocalName

        public static String extractLocalName​(String name)
        Extract localname local from ns:local name
        Parameters:
        name - in form ns:local
        Returns:
        local part from ns:local name
      • extractLocalName

        public static String extractLocalName​(PuzzleComponent def)
        Extract localname local from ns:local name
        Parameters:
        def - PuzzleComponent object
        Returns:
        local part from ns:local name