project35.mda.model
Class RecordModelFactory

java.lang.Object
  extended by project35.mda.model.RecordModelFactory

public class RecordModelFactory
extends java.lang.Object

Factory responsible for creating instances of record structures that are derived from XML schema structures.


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)

Constructor Summary
RecordModelFactory()
           
 
Method Summary
 void addFactory(java.lang.String recordClassTag, RecordModel recordObject)
          add a factory that produces a record model that is described by the tag recordClassTag found in the XML Schema
 void addListFieldFactory(java.lang.String listFieldFactoryName, ListFieldModel listFieldModelObject)
          add a list field factory to the list of factories
 RecordModel createRecordModel(java.lang.String recordClassTag)
          instantiate a copy of a record model with the given name
 RecordModel createTopLevelRecordModel()
          creates an instance of the top level record model.
 java.lang.String[] getIdentifierFieldNames(java.lang.String recordClassName)
           
 ListFieldModel getListFieldModelForProxy(ProxyListFieldModel proxyListFieldModel)
          returns a list field for a proxy list.
 java.lang.String getModelStamp()
          creates the model stamp used to mark experiment files made with the current model
 java.lang.String[] getRecordClassNames()
           
 java.util.ArrayList getRecordFactories()
           
 java.util.ArrayList getRecordTypesSupportingReferencing()
           
 java.lang.String getSchemaInstance()
           
 java.lang.String getSchemaName()
           
 java.lang.String getStyleSheetStamp()
          public void reset() { if (recordFactory != null) { recordFactory.recordFactoryObjects = new Hashtable(); recordFactory.listFactoryObjects = new Hashtable(); recordFactory.topLevelRecordModelClass = null; }

configurationReader.setTopLevelElementName(null); }

 java.lang.String getTargetNamespace()
          Returns the target namespace of the current schema
 java.lang.String getTopLevelRecordModelClass()
           
 boolean isAmbiguous()
          Returns whether any RecordModel in the RecordModelFactory is ambiguous or not.
 boolean isIdentifierField(java.lang.String fieldName, java.lang.String recordClassName)
           
 boolean modelSupportsIDField(java.lang.String recordClassName)
           
 void print(java.io.File file)
           
 boolean recordClassRegistered(java.lang.String recordClassTag)
          determines whether a factory with the given tag name already exists
 void resolveProxyFields()
          substitute proxy list fields in each factory with an appropriate list field model instance
 boolean schemaMatchesCurrentDataModel(java.lang.String applicationSchema, java.lang.String dataFileSchema)
          compares the model stamp found in experiment files with the current model and determines if they are the same.
 void setSchemaInstance(java.lang.String schemaInstance)
           
 void setSchemaName(java.lang.String schemaName)
           
 void setTargetNamespace(java.lang.String targetNamespace)
          Sets the target namespace of the current schema
 void setTopLevelRecordModelClass(java.lang.String topLevelRecordModelClass)
          sets the top level record model class.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RecordModelFactory

public RecordModelFactory()
Method Detail

isIdentifierField

public boolean isIdentifierField(java.lang.String fieldName,
                                 java.lang.String recordClassName)

getIdentifierFieldNames

public java.lang.String[] getIdentifierFieldNames(java.lang.String recordClassName)

createRecordModel

public RecordModel createRecordModel(java.lang.String recordClassTag)
instantiate a copy of a record model with the given name

Parameters:
recordClassTag - the name of the record model
Returns:
a copy of the factory object

createTopLevelRecordModel

public RecordModel createTopLevelRecordModel()
creates an instance of the top level record model. The top level record model corresponds to the top level record defined in the XML Schema

Returns:
a copy of the top level record model

getRecordTypesSupportingReferencing

public java.util.ArrayList getRecordTypesSupportingReferencing()

modelSupportsIDField

public boolean modelSupportsIDField(java.lang.String recordClassName)

getModelStamp

public java.lang.String getModelStamp()
creates the model stamp used to mark experiment files made with the current model

Returns:
model stamp written into data files

getRecordFactories

public java.util.ArrayList getRecordFactories()
Returns:
a list of factories used to instantiate record structures described in the XML Schema

getRecordClassNames

public java.lang.String[] getRecordClassNames()

getStyleSheetStamp

public java.lang.String getStyleSheetStamp()
public void reset() { if (recordFactory != null) { recordFactory.recordFactoryObjects = new Hashtable(); recordFactory.listFactoryObjects = new Hashtable(); recordFactory.topLevelRecordModelClass = null; }

configurationReader.setTopLevelElementName(null); }


getSchemaInstance

public java.lang.String getSchemaInstance()

getSchemaName

public java.lang.String getSchemaName()

getTopLevelRecordModelClass

public java.lang.String getTopLevelRecordModelClass()
Returns:
the top level record model class. The record model class corresponds to the top level data structure described in the XML Schema

recordClassRegistered

public boolean recordClassRegistered(java.lang.String recordClassTag)
determines whether a factory with the given tag name already exists

Parameters:
recordClassTag - the tag name of the record model structure
Returns:
true if a factory already exists; otherwise false

print

public void print(java.io.File file)

schemaMatchesCurrentDataModel

public boolean schemaMatchesCurrentDataModel(java.lang.String applicationSchema,
                                             java.lang.String dataFileSchema)
compares the model stamp found in experiment files with the current model and determines if they are the same. The only part of the two values that needs to be compared is the *.xsd file that appears at the end. Differences in paths don't matter.

Parameters:
applicationSchema - the schema currently being used by Project35
dataFileSchema - the model stamp that appears in an experiment file
Returns:
true if the data file schema matches the current schema. Otherwise false.

getListFieldModelForProxy

public ListFieldModel getListFieldModelForProxy(ProxyListFieldModel proxyListFieldModel)
returns a list field for a proxy list. You can specify a list structure once in Project35 and refer to it elsewhere in other documents. To help parsing, fields that appear as references are stored. In a second pass, the references are replaced with actual instances of the field.

Parameters:
proxyListFieldModel - the proxy list model
Returns:
a new instance of the appropriate ListFieldModel indicated in the proxyListFieldModel.

getTargetNamespace

public java.lang.String getTargetNamespace()
Returns the target namespace of the current schema

Returns:
the target namespace of the current schema

setTargetNamespace

public void setTargetNamespace(java.lang.String targetNamespace)
Sets the target namespace of the current schema

Parameters:
targetNamespace - the desired target namespace

setSchemaInstance

public void setSchemaInstance(java.lang.String schemaInstance)

setSchemaName

public void setSchemaName(java.lang.String schemaName)

resolveProxyFields

public void resolveProxyFields()
substitute proxy list fields in each factory with an appropriate list field model instance


setTopLevelRecordModelClass

public void setTopLevelRecordModelClass(java.lang.String topLevelRecordModelClass)
sets the top level record model class. The top level class corresponds to the top level record structure described in the XML Schema

Parameters:
topLevelRecordModelClass - the top level record model class

addFactory

public void addFactory(java.lang.String recordClassTag,
                       RecordModel recordObject)
add a factory that produces a record model that is described by the tag recordClassTag found in the XML Schema

Parameters:
recordClassTag - the tag name of the record model.
recordObject - the object that will be copied whenever a copy of "recordClassTag" is requested

addListFieldFactory

public void addListFieldFactory(java.lang.String listFieldFactoryName,
                                ListFieldModel listFieldModelObject)
add a list field factory to the list of factories

Parameters:
listFieldFactoryName - the tag name of the list field
listFieldModelObject - the list field factory object

isAmbiguous

public boolean isAmbiguous()
Returns whether any RecordModel in the RecordModelFactory is ambiguous or not. Example of an ambiguous XML schema construct:
 <xs:element name="test">
     <xs:complexType>
         <xs:sequence>
             <xs:element name="test1" type="xs:float" minOccurs="0"/>
             <xs:element name="test1" type="xs:float" maxOccurs="unbounded"/>
         </xs:sequence>
     </xs:complexType>
 </xs:element>
 

Returns:
true if it found at least one ambiguous RecordModel, false otherwise.