public Record parseRecord(DocumentBuilder stringdb, Element elParent, String strTagName, String strDatabase, BaseTable table, BaseTable tableMain, boolean bIsMainHasReferenceField)
    {
    	Record record = null;
    	if (table != null)
    		record = table.getRecord();
        if (record == null)
        {
            record = this.getRecord(strTagName);
	        if (record == null)
	        {   // Not found, create it!
	            record = new XmlRecord();
	            ((XmlRecord)record).setTableName(strTagName);
	            if (strDatabase != null)
	                ((XmlRecord)record).setDatabaseName(strDatabase);
	            ((XmlRecord)record).setDatabaseType(DBConstants.REMOTE);
	            record.init(this);
	            Record recMain = null;
	            if (tableMain != null)
	            	recMain = tableMain.getRecord();
	            if (recMain != null)    // If this is a sub-record
	                if (!bIsMainHasReferenceField)  // And the main record doesn't have a reference to my key
	            {
	                ReferenceField fld = new ReferenceField(record, recMain.getTableNames(false) + "ID", DBConstants.DEFAULT_FIELD_LENGTH, null, null);
	                KeyArea keyArea = record.makeIndex(DBConstants.NOT_UNIQUE, recMain.getTableNames(false) + "ID");
	                keyArea.addKeyField(fld, DBConstants.ASCENDING);
	            }
	            RecordParser parser = new RecordParser(elParent);
	            while (parser.next(stringdb) != null)
	            {   // First, add the fields to the record
	                parser.findField(record, true);     // This will create if not found
	            }
	        }
	        table = record.getTable();
        }
        // Now its time to move the data to the fields and write the record.
        RecordParser parser = new RecordParser(elParent);
        boolean bFirstTime = true;
        while (parser.next(stringdb) != null)
        {
            Node elChild = parser.getChildNode();
            String strName = parser.getName();
            String strValue = parser.getValue();
            boolean bIsRecord = parser.isRecord();
            if (bFirstTime)
            {   // First time thru
                bFirstTime = false;
                try   {
                    table.addNew();
    	            Record recMain = null;
    	            if (tableMain != null)
    	            	recMain = tableMain.getRecord();
                    if (recMain != null)
                    {   // If this is a sub-file, be sure to update the reference field.
                        BaseField field = record.getField(recMain.getTableNames(false) + "ID");
                        if (field != null)
                            if (field instanceof ReferenceField)
                                if (!bIsMainHasReferenceField)
                        {   // If the main record has to get me, but doesn't have my key, save it's key
                            if (recMain.getEditMode() == DBConstants.EDIT_ADD)
                            {   // Main record not added yet, add it now
                                recMain = this.updateRecord(tableMain, true);   // And return the record written
                                tableMain.edit();
                            }
                            ((ReferenceField)field).setReference(recMain);  // Reference the main record.
                        }
                    }
                } catch (DBException ex)    {
                    ex.printStackTrace();
                }
            }
            BaseField field = parser.findField(record, true);
            if (bIsRecord)
            {   // If this field directly references a record, you have to write the sub-record first.
                boolean bIsReferenceField = (parser.getReferenceName() != null);
                Record recNew = this.parseRecord(stringdb, (Element)elChild, strName, strDatabase, null, table, bIsReferenceField);
                if (bIsReferenceField) if (recNew != null)
                {
                    ((ReferenceField)field).setReference(recNew);
                    field = null; // Don't set it twice
                }
            }
            if (field != null)
            {   // Set the data
                if (field instanceof ObjectField)
                {
                    try {
						XmlUtilities.decodeFieldData(field, strValue);
					} catch (Exception e) {
						Utility.getLogger().severe("Error - bad base64 input field: " + record.getRecordName());
						e.printStackTrace();
					}
                }
                else if (field instanceof DateTimeField)
                    XmlUtilities.decodeDateTime((DateTimeField)field, strValue);
                else
                    field.setString(strValue);
            }
        }

        record = this.updateRecord(table, bIsMainHasReferenceField);
        return record;
    }
public Record parseRecord ( DocumentBuilder stringdb , Element elParent , String strTagName , String strDatabase , BaseTable table , BaseTable tableMain , boolean bIsMainHasReferenceField ) { Record record = null ; if ( table != null ) record = table . getRecord ( ) ; if ( record == null ) { record = this . getRecord ( strTagName ) ; if ( record == null ) { record = new XmlRecord ( ) ; ( ( XmlRecord ) record ) . setTableName ( strTagName ) ; if ( strDatabase != null ) ( ( XmlRecord ) record ) . setDatabaseName ( strDatabase ) ; ( ( XmlRecord ) record ) . setDatabaseType ( DBConstants . REMOTE ) ; record . init ( this ) ; Record recMain = null ; if ( tableMain != null ) recMain = tableMain . getRecord ( ) ; if ( recMain != null ) if ( ! bIsMainHasReferenceField ) { ReferenceField fld = new ReferenceField ( record , recMain . getTableNames ( false ) + "ID" , DBConstants . DEFAULT_FIELD_LENGTH , null , null ) ; KeyArea keyArea = record . makeIndex ( DBConstants . NOT_UNIQUE , recMain . getTableNames ( false ) + "ID" ) ; keyArea . addKeyField ( fld , DBConstants . ASCENDING ) ; } RecordParser parser = new RecordParser ( elParent ) ; while ( parser . next ( stringdb ) != null ) { parser . findField ( record , true ) ; } } table = record . getTable ( ) ; } RecordParser parser = new RecordParser ( elParent ) ; boolean bFirstTime = true ; while ( parser . next ( stringdb ) != null ) { Node elChild = parser . getChildNode ( ) ; String strName = parser . getName ( ) ; String strValue = parser . getValue ( ) ; boolean bIsRecord = parser . isRecord ( ) ; if ( bFirstTime ) { bFirstTime = false ; try { table . addNew ( ) ; Record recMain = null ; if ( tableMain != null ) recMain = tableMain . getRecord ( ) ; if ( recMain != null ) { BaseField field = record . getField ( recMain . getTableNames ( false ) + "ID" ) ; if ( field != null ) if ( field instanceof ReferenceField ) if ( ! bIsMainHasReferenceField ) { if ( recMain . getEditMode ( ) == DBConstants . EDIT_ADD ) { recMain = this . updateRecord ( tableMain , true ) ; tableMain . edit ( ) ; } ( ( ReferenceField ) field ) . setReference ( recMain ) ; } } } catch ( DBException ex ) { ex . printStackTrace ( ) ; } } BaseField field = parser . findField ( record , true ) ; if ( bIsRecord ) { boolean bIsReferenceField = ( parser . getReferenceName ( ) != null ) ; Record recNew = this . parseRecord ( stringdb , ( Element ) elChild , strName , strDatabase , null , table , bIsReferenceField ) ; if ( bIsReferenceField ) if ( recNew != null ) { ( ( ReferenceField ) field ) . setReference ( recNew ) ; field = null ; } } if ( field != null ) { if ( field instanceof ObjectField ) { try { XmlUtilities . decodeFieldData ( field , strValue ) ; } catch ( Exception e ) { Utility . getLogger ( ) . severe ( "Error - bad base64 input field: " + record . getRecordName ( ) ) ; e . printStackTrace ( ) ; } } else if ( field instanceof DateTimeField ) XmlUtilities . decodeDateTime ( ( DateTimeField ) field , strValue ) ; else field . setString ( strValue ) ; } } record = this . updateRecord ( table , bIsMainHasReferenceField ) ; return record ; }
Find or create this record and then add these elements.
Note: If the MainHasReferenceField is true, you must return the bookmark of this new record.
@param stringdb The documentbuilder (so you have access to an XML string parser).
@param elParent The (file) parent element to read thru.
@param strTagName The tag name of this (file) element (ie., the file name).
@param strDatabase The name of the current database.
@param record The record to add these record elements to (if null, I will create this record).
@param recMain The main record if I am parsing a sub-file referencing another file's field element.
@param bIsMainHasReferenceField The main record doesn't have a reference to my main field.
@return This new record.