project35.mda.model
Class RecordModelUtility

java.lang.Object
  extended by project35.mda.model.RecordModelUtility
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable

public class RecordModelUtility
extends java.lang.Object
implements java.io.Serializable, java.lang.Cloneable

This class was designed to offload some of the functionality in RecordModel that didn't relate to holding data. Right now the methods are static. They're also mostly called within RecordModel but that should be changed.


Copyright (c) 2008 Kevin Garwood for Project35. The original code was developed by Kevin Garwood for the University of Manchester. Revisions have been made for Project35, a project that is independent of that institution. This code is licensed under the Academic Free License version 3.0. The code attribution for the original code is included here:

Copyright (c) Kevin Garwood and University of Manchester 2007. All rights reserved. Licensed under the Academic Free License version 3.0. For more information on the terms and conditions, please see the file "LICENSE" that is included in this distribution.


Version:
1.0
Author:
Kevin Garwood (kgarwood@users.sourceforge.net)
See Also:
Serialized Form

Constructor Summary
RecordModelUtility()
           
 
Method Summary
 boolean addedReferenceToListField(java.lang.String attributeName, java.lang.String attributeValue, RecordModel recordModel)
           
 void addIDREFSToField(ListFieldModel listFieldModel, java.lang.String idRefsValue)
          given the list field and an IDREFs value that could contain multiple IDs, add appropriate unresolved references to the list.
 void addRecordModelToListField(RecordModel parentRecordModel, RecordModel childRecordModel)
           
 void addRecordModelToListField(RecordModel parentRecordModel, java.lang.String listFieldName, RecordModel childRecordModel)
           
static RecordModel determineRecordModel(RecordNameProvider recordNameProvider)
           
 int determineReferenceNumber(RecordModel recordModel)
           
 java.lang.String[] getAllFieldNames(RecordModel recordModel)
           
 java.util.ArrayList getAllImmediateChildren(RecordModel recordModel)
           
 java.util.ArrayList getAllRecordModels(RecordModel recordModel)
           
 java.lang.String[] getAttributeFieldNames(RecordModel recordModel)
          gets a list of those edit fields that represent XML attributes
 java.util.ArrayList getAttributeFields(RecordModel recordModel)
          gets a list of those edit fields that represent XML attributes
 boolean getBooleanFieldValue(RecordModel parentRecordModel, java.lang.String fieldName)
          assumes that field exists and that it is a boolean field model
 java.util.ArrayList getChildren(RecordModel recordModel, java.lang.String listFieldName)
           
 java.lang.String[] getConstraints(EditFieldModel editFieldModel)
           
 java.lang.String[] getEditAndAttributeFieldNames(RecordModel recordModel)
           
 java.util.ArrayList getEditAndAttributeFields(RecordModel recordModel)
          in some cases you want to treat these field types separatly and in others you don't
 java.lang.String[] getEditFieldNames(RecordModel recordModel)
          provides the list of edit field names.
 java.util.ArrayList getEditFields(RecordModel recordModel)
          provides a list of edit fields
 java.util.ArrayList getElementFields(RecordModel recordModel)
           
 java.lang.String[] getExistingValues(java.lang.String recordClassName, java.lang.String fieldName, RecordModel dataLayerRootModel)
           
 IDFieldModel getIDField(RecordModel recordModel)
          returns the first available ID field
 java.util.ArrayList getIDFields(RecordModel recordModel)
          returns a list of all ID fields in a recordModel
 int getImmediateChildCount(RecordModel recordModel)
           
 int getIntegerFieldValue(RecordModel parentRecordModel, java.lang.String fieldName)
           
 java.util.ArrayList getListChildren(ListFieldModel listFieldModel, java.lang.String childType)
           
 java.lang.String[] getListFieldNames(RecordModel recordModel)
          provides the list of edit field names.
 java.util.ArrayList getListFields(RecordModel recordModel)
           
 java.lang.String[] getMissingRecordTypes(RecordModel recordModel)
          this is a convenience method for helping to determine which of its required list fields remains empty.
 java.util.ArrayList getNonReferenceListChildren(ListFieldModel listFieldModel)
           
 RecordModel getOnlyChild(RecordModel parentRecordModel, java.lang.String fieldName)
           
 java.lang.String getPath(RecordNameProvider recordNameProvider)
           
 java.util.ArrayList getProxyListFields(RecordModel recordModel)
           
 RecordModel getRecordModel(RecordNameProvider recordNameProvider)
           
 RecordModel[] getRecordModelChildren(RecordModel parentRecordModel, java.lang.String fieldName)
          convenience method for extracting record model instances from list fields which only have one type of children.
 java.util.ArrayList getReferenceListChildren(ListFieldModel listFieldModel)
           
 RecordModel getRootModel(RecordNameProvider recordNameProvider)
           
 FieldDataType getType(DataFieldModel dataFieldModel)
           
 boolean isIDField(java.lang.String fieldName, RecordModel recordModel)
          method determines whether a field name names an identifier field in the model
 boolean isNumeric(EditFieldModel editFieldModel)
           
 boolean recordClassNameFoundInPath(RecordNameProvider recordNameProvider, java.lang.String recordClassName)
           
 boolean saveChanges(java.util.ArrayList recordModels)
          only reports errors in the edit fields
 void setBooleanFieldValue(RecordModel parentRecordModel, java.lang.String fieldName, boolean fieldValue)
           
 void setChildrenInListField(RecordModel parentRecordModel, java.lang.String listFieldName, java.util.ArrayList revisedChildList)
           
 void setListFieldChildren(RecordModel parentRecordModel, java.lang.String listFieldName, java.lang.String childType, java.util.ArrayList children)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RecordModelUtility

public RecordModelUtility()
Method Detail

getExistingValues

public java.lang.String[] getExistingValues(java.lang.String recordClassName,
                                            java.lang.String fieldName,
                                            RecordModel dataLayerRootModel)

getBooleanFieldValue

public boolean getBooleanFieldValue(RecordModel parentRecordModel,
                                    java.lang.String fieldName)
assumes that field exists and that it is a boolean field model


getIntegerFieldValue

public int getIntegerFieldValue(RecordModel parentRecordModel,
                                java.lang.String fieldName)
                         throws java.lang.Exception
Throws:
java.lang.Exception

getRecordModelChildren

public RecordModel[] getRecordModelChildren(RecordModel parentRecordModel,
                                            java.lang.String fieldName)
convenience method for extracting record model instances from list fields which only have one type of children. Automatically dereferences RecordModelReferences and includes the items they refer to


getOnlyChild

public RecordModel getOnlyChild(RecordModel parentRecordModel,
                                java.lang.String fieldName)

getAllRecordModels

public java.util.ArrayList getAllRecordModels(RecordModel recordModel)

getImmediateChildCount

public int getImmediateChildCount(RecordModel recordModel)

getRecordModel

public RecordModel getRecordModel(RecordNameProvider recordNameProvider)

recordClassNameFoundInPath

public boolean recordClassNameFoundInPath(RecordNameProvider recordNameProvider,
                                          java.lang.String recordClassName)

getPath

public java.lang.String getPath(RecordNameProvider recordNameProvider)

getRootModel

public RecordModel getRootModel(RecordNameProvider recordNameProvider)

determineRecordModel

public static RecordModel determineRecordModel(RecordNameProvider recordNameProvider)

isNumeric

public boolean isNumeric(EditFieldModel editFieldModel)

getConstraints

public java.lang.String[] getConstraints(EditFieldModel editFieldModel)

getType

public FieldDataType getType(DataFieldModel dataFieldModel)

addedReferenceToListField

public boolean addedReferenceToListField(java.lang.String attributeName,
                                         java.lang.String attributeValue,
                                         RecordModel recordModel)
Returns:
true if the attribute was successfully interpretted as a reference that got added to some list. The attributes for a tag will be of two types: attributes that would appear as normal fields in a record form and attributes that simply reference a bunch of other records.

addIDREFSToField

public void addIDREFSToField(ListFieldModel listFieldModel,
                             java.lang.String idRefsValue)
given the list field and an IDREFs value that could contain multiple IDs, add appropriate unresolved references to the list. Note that after the initial read, all of the XMLIdentifier values will have to be substituted with actual object references to records that are held in memory


determineReferenceNumber

public int determineReferenceNumber(RecordModel recordModel)

getReferenceListChildren

public java.util.ArrayList getReferenceListChildren(ListFieldModel listFieldModel)

getNonReferenceListChildren

public java.util.ArrayList getNonReferenceListChildren(ListFieldModel listFieldModel)

isIDField

public boolean isIDField(java.lang.String fieldName,
                         RecordModel recordModel)
method determines whether a field name names an identifier field in the model


getIDFields

public java.util.ArrayList getIDFields(RecordModel recordModel)
returns a list of all ID fields in a recordModel


getIDField

public IDFieldModel getIDField(RecordModel recordModel)
returns the first available ID field


getAttributeFields

public java.util.ArrayList getAttributeFields(RecordModel recordModel)
gets a list of those edit fields that represent XML attributes


getListFields

public java.util.ArrayList getListFields(RecordModel recordModel)
Returns:
list of list fields for the record

getListChildren

public java.util.ArrayList getListChildren(ListFieldModel listFieldModel,
                                           java.lang.String childType)

getEditFieldNames

public java.lang.String[] getEditFieldNames(RecordModel recordModel)
provides the list of edit field names. This is a convenience method used in Project35's default data import feature.

Returns:
list of edit field names

getListFieldNames

public java.lang.String[] getListFieldNames(RecordModel recordModel)
provides the list of edit field names. This is a convenience method used in Project35's default data import feature.

Returns:
list of edit field names

getAttributeFieldNames

public java.lang.String[] getAttributeFieldNames(RecordModel recordModel)
gets a list of those edit fields that represent XML attributes


getAllFieldNames

public java.lang.String[] getAllFieldNames(RecordModel recordModel)

getProxyListFields

public java.util.ArrayList getProxyListFields(RecordModel recordModel)
Returns:
list of proxy list fields. Proxy list fields are a result of parsing schema where the list is defined in one placed and merely referenced in other places

getEditAndAttributeFields

public java.util.ArrayList getEditAndAttributeFields(RecordModel recordModel)
in some cases you want to treat these field types separatly and in others you don't


getEditAndAttributeFieldNames

public java.lang.String[] getEditAndAttributeFieldNames(RecordModel recordModel)

getEditFields

public java.util.ArrayList getEditFields(RecordModel recordModel)
provides a list of edit fields

Returns:
list of edit fields

getMissingRecordTypes

public java.lang.String[] getMissingRecordTypes(RecordModel recordModel)
this is a convenience method for helping to determine which of its required list fields remains empty. Used in validation checks.

Returns:
list of missing record types.

getElementFields

public java.util.ArrayList getElementFields(RecordModel recordModel)

saveChanges

public boolean saveChanges(java.util.ArrayList recordModels)
only reports errors in the edit fields

Returns:
null if there are no errors with the record. otherwise returns an appropriate error message. The other validate

getChildren

public java.util.ArrayList getChildren(RecordModel recordModel,
                                       java.lang.String listFieldName)

getAllImmediateChildren

public java.util.ArrayList getAllImmediateChildren(RecordModel recordModel)

setBooleanFieldValue

public void setBooleanFieldValue(RecordModel parentRecordModel,
                                 java.lang.String fieldName,
                                 boolean fieldValue)

setListFieldChildren

public void setListFieldChildren(RecordModel parentRecordModel,
                                 java.lang.String listFieldName,
                                 java.lang.String childType,
                                 java.util.ArrayList children)

setChildrenInListField

public void setChildrenInListField(RecordModel parentRecordModel,
                                   java.lang.String listFieldName,
                                   java.util.ArrayList revisedChildList)

addRecordModelToListField

public void addRecordModelToListField(RecordModel parentRecordModel,
                                      java.lang.String listFieldName,
                                      RecordModel childRecordModel)

addRecordModelToListField

public void addRecordModelToListField(RecordModel parentRecordModel,
                                      RecordModel childRecordModel)