ch.dieseite.colladaloader.coreproc

## Class ObjectLinker

- java.lang.Object
- - ch.dieseite.colladaloader.coreproc.ObjectLinker

-     public class ObjectLinker
      extends java.lang.Object

  ObjectLinker creates and holds an object oriented database. So we get an abstraction to collada XML structure. ObjectLinker get its instructions via <loading> section in linking schema.

  In natural order and for each <entities> tag a new scan via SaxParser starts again committing search patterns. Each returned "SaxParser.Record" objects is added into DB tables and linked/backlinked to other Records (see also linking schema specifications <target>).

  Following fields into "SaxParser.Record" is added by ObjectLinker:

- a unique ID (auto generated or collada defined)
- a next link to a foreign Record (optional, collada defined)
- a back link to a foreign or parent Record (optional, collada defined)
- a set of fetched child Records (optional, search pattern dependent)

The database has the format:

HashMap<poolname,TreeMap<uniqueID,recordObject>>
resp.
HashMap<String,TreeMap<String,SaxParser.Record>>

Note: If the natural order of Records matters let ObjectLinker generate an uniqueID and limit to 2'147'483'647 entities per pool name

this class has a main() method to test a sketchup Version 8 dae file with colors and texture. It depends on xmlfiles SaxParser SimpleDomParser and Log

This source is free; you can redistribute it and/or modify it under the terms of the GNU General Public License and by nameing of the originally author

Version:
  3.1
Author:
  Markus Zimmermann http://www.die-seite.ch

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `class` | `ObjectLinker.CTXInfo` Wrapps all infos needed to build the internal database This fields is set BEFORE object linker does his work
    `class` | `ObjectLinker.RecInfo` this class wrapps individual infos for each DB record this fields is set AFTER ObjectLinker is done

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `private java.util.HashMap<java.lang.String,java.util.TreeMap<java.lang.String,SaxParser.Record<ObjectLinker.CTXInfo,ObjectLinker.RecInfo>>>` | `database`
    `private int` | `IdCnt`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `ObjectLinker()`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `private void` | `execJobs(java.util.List<SimpleDomParser.Element> entities, java.lang.String daeFile, SaxParser<ObjectLinker.CTXInfo,ObjectLinker.RecInfo> sax)` Iterates all jobs in <entities> and rescans the whole .dae document each time
    `java.util.HashMap<java.lang.String,java.util.TreeMap<java.lang.String,SaxParser.Record<ObjectLinker.CTXInfo,ObjectLinker.RecInfo>>>` | `getDatabase()` See notes on the class description
    `private java.lang.String` | `getValue(java.lang.String expression, SaxParser.Record<ObjectLinker.CTXInfo,ObjectLinker.RecInfo> r)` Returns a Textcontent or an attribute value from record, depending on the expression.
    `private java.util.List<SimpleDomParser.Element>` | `initLoadingJobs(java.lang.String filename)` parses linking schema.
    `private SaxParser<ObjectLinker.CTXInfo,ObjectLinker.RecInfo>` | `initSaxParser()` creates a sax parser that scans a later defined collada file.
    `private java.util.List<SaxParser.Context<ObjectLinker.CTXInfo,ObjectLinker.RecInfo>>` | `initSearchPatterns(SimpleDomParser.Element aTarget, SaxParser.Context<ObjectLinker.CTXInfo,ObjectLinker.RecInfo> parent, java.lang.String poolname)` Digs recursively into <target> tag and its subtags in linking schema to get all search patterns for SaxParser class
    `private SaxParser.Record<ObjectLinker.CTXInfo,ObjectLinker.RecInfo>` | `linkRecord(SaxParser.Record<ObjectLinker.CTXInfo,ObjectLinker.RecInfo> aDaeRec, SaxParser.Record<ObjectLinker.CTXInfo,ObjectLinker.RecInfo> parentRec, SaxParser.Context<ObjectLinker.CTXInfo,ObjectLinker.RecInfo> ctx)` Adds a RecInfo(), gives a unique ID (or defined ID by collada) establish foreign key links/backlinks and does the same procedure with its children recursively
    `void` | `start(java.lang.String filename, java.lang.String daeFile)` The schemaFile says how to parse a .dae file into a valid internal database using searchpatterns to fetch collada xml tags, or linking instructions

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### database

          private java.util.HashMap<java.lang.String,java.util.TreeMap<java.lang.String,SaxParser.Record<ObjectLinker.CTXInfo,ObjectLinker.RecInfo>>> database

    - #### IdCnt

          private int IdCnt

  - ### Constructor Detail

    - #### ObjectLinker

          public ObjectLinker()

  - ### Method Detail

    - #### initLoadingJobs

          private java.util.List<SimpleDomParser.Element> initLoadingJobs(java.lang.String filename)
                                                                   throws javax.xml.parsers.ParserConfigurationException,
                                                                          org.xml.sax.SAXException,
                                                                          java.io.IOException

      parses linking schema. It returns all <entities> inside <loading> tags in natural order. it also creates a database skeleton based by Linking Schema
      Parameters:
        `linking` - schema
      Returns:
        all jobs to be done
      Throws:
        `java.io.IOException`
        `org.xml.sax.SAXException`
        `javax.xml.parsers.ParserConfigurationException`

    - #### initSaxParser

          private SaxParser<ObjectLinker.CTXInfo,ObjectLinker.RecInfo> initSaxParser()

      creates a sax parser that scans a later defined collada file. It embeds also a callback handler that edit the internal database by incoming callbacks from SaxParser
      Returns:

    - #### execJobs

          private void execJobs(java.util.List<SimpleDomParser.Element> entities,
                                java.lang.String daeFile,
                                SaxParser<ObjectLinker.CTXInfo,ObjectLinker.RecInfo> sax)
                         throws javax.xml.parsers.ParserConfigurationException,
                                org.xml.sax.SAXException,
                                java.io.IOException

      Iterates all jobs in <entities> and rescans the whole .dae document each time
      Parameters:
        `entities` -
        `daeFile` -
        `sax` -
      Throws:
        `javax.xml.parsers.ParserConfigurationException`
        `org.xml.sax.SAXException`
        `java.io.IOException`

    - #### start

          public void start(java.lang.String filename,
                            java.lang.String daeFile)
                     throws javax.xml.parsers.ParserConfigurationException,
                            org.xml.sax.SAXException,
                            java.io.IOException

      The schemaFile says how to parse a .dae file into a valid internal database using searchpatterns to fetch collada xml tags, or linking instructions
      Parameters:
        `schemaFile` - with focus to "entities" tags
        `collada` - file
      Throws:
        `java.io.IOException`
        `org.xml.sax.SAXException`
        `javax.xml.parsers.ParserConfigurationException`

    - #### initSearchPatterns

          private java.util.List<SaxParser.Context<ObjectLinker.CTXInfo,ObjectLinker.RecInfo>> initSearchPatterns(SimpleDomParser.Element aTarget,
                                                                                                                  SaxParser.Context<ObjectLinker.CTXInfo,ObjectLinker.RecInfo> parent,
                                                                                                                  java.lang.String poolname)

      Digs recursively into <target> tag and its subtags in linking schema to get all search patterns for SaxParser class
      Parameters:
        `aTarget` -
        `parent` - or null if root <target>
      Returns:

    - #### linkRecord

          private SaxParser.Record<ObjectLinker.CTXInfo,ObjectLinker.RecInfo> linkRecord(SaxParser.Record<ObjectLinker.CTXInfo,ObjectLinker.RecInfo> aDaeRec,
                                                                                         SaxParser.Record<ObjectLinker.CTXInfo,ObjectLinker.RecInfo> parentRec,
                                                                                         SaxParser.Context<ObjectLinker.CTXInfo,ObjectLinker.RecInfo> ctx)

      Adds a RecInfo(), gives a unique ID (or defined ID by collada) establish foreign key links/backlinks and does the same procedure with its children recursively
      Parameters:
        `aDaeRec` -
        `parentRec` -
        `ctx` -
      Returns:

    - #### getValue

          private java.lang.String getValue(java.lang.String expression,
                                            SaxParser.Record<ObjectLinker.CTXInfo,ObjectLinker.RecInfo> r)

      Returns a Textcontent or an attribute value from record, depending on the expression. Any tabstops or '#' characters will be removed from the result
      Parameters:
        `expression` - 'myValue' or '#myAttributeName' or '$TEXTCONTENT' or null
        `r` - current record (child or parent)
      Returns:
        value a String or null if expression is null

    - #### getDatabase

          public java.util.HashMap<java.lang.String,java.util.TreeMap<java.lang.String,SaxParser.Record<ObjectLinker.CTXInfo,ObjectLinker.RecInfo>>> getDatabase()

      See notes on the class description
      Returns:
        the Database