return annotation;
} else if (contextObject instanceof SBMLDocument) {
SBMLDocument sbmlDocument = (SBMLDocument) contextObject;
if (elementName.equals("model")) {
Model model = (Model) newContextObject;
model.setLevel(sbmlDocument.getLevel());
model.setVersion(sbmlDocument.getVersion());
model.initDefaults();
sbmlDocument.setModel(model);
return model;
}
} else if (contextObject instanceof Model) {
Model model = (Model) contextObject;
if (newContextObject instanceof ListOf<?>) {
if (elementName.equals("listOfFunctionDefinitions")
&& model.getLevel() > 1) {
ListOf<FunctionDefinition> listOfFunctionDefinitions = (ListOf<FunctionDefinition>) newContextObject;
model.setListOfFunctionDefinitions(listOfFunctionDefinitions);
return listOfFunctionDefinitions;
} else if (elementName.equals("listOfUnitDefinitions")) {
ListOf<UnitDefinition> listOfUnitDefinitions = (ListOf<UnitDefinition>) newContextObject;
model.setListOfUnitDefinitions(listOfUnitDefinitions);
return listOfUnitDefinitions;
} else if (elementName.equals("listOfCompartments")) {
ListOf<Compartment> listOfCompartments = (ListOf<Compartment>) newContextObject;
model.setListOfCompartments(listOfCompartments);
return listOfCompartments;
} else if (elementName.equals("listOfSpecies")) {
ListOf<Species> listOfSpecies = (ListOf<Species>) newContextObject;
model.setListOfSpecies(listOfSpecies);
return listOfSpecies;
} else if (elementName.equals("listOfParameters")) {
ListOf<Parameter> listOfParameters = (ListOf<Parameter>) newContextObject;
model.setListOfParameters(listOfParameters);
return listOfParameters;
} else if (elementName.equals("listOfInitialAssignments")
&& ((model.getLevel() == 2 && model.getVersion() > 1)
|| model.getLevel() >= 3)) {
ListOf<InitialAssignment> listOfInitialAssignments = (ListOf<InitialAssignment>) newContextObject;
model.setListOfInitialAssignments(listOfInitialAssignments);
return listOfInitialAssignments;
} else if (elementName.equals("listOfRules")) {
ListOf<Rule> listOfRules = (ListOf<Rule>) newContextObject;
model.setListOfRules(listOfRules);
return listOfRules;
} else if (elementName.equals("listOfConstraints")
&& ((model.getLevel() == 2 && model.getVersion() > 1)
|| model.getLevel() >= 3)) {
ListOf<Constraint> listOfConstraints = (ListOf<Constraint>) newContextObject;
model.setListOfConstraints(listOfConstraints);
return listOfConstraints;
} else if (elementName.equals("listOfReactions")) {
ListOf<Reaction> listOfReactions = (ListOf<Reaction>) newContextObject;
model.setListOfReactions(listOfReactions);
return listOfReactions;
} else if (elementName.equals("listOfEvents")
&& model.getLevel() > 1) {
ListOf<Event> listOfEvents = (ListOf<Event>) newContextObject;
model.setListOfEvents(listOfEvents);
return listOfEvents;
} else if (elementName.equals("listOfCompartmentTypes")
&& (model.getLevel() == 2 && model.getVersion() > 1)) {
ListOf<CompartmentType> listOfCompartmentTypes = (ListOf<CompartmentType>) newContextObject;
model.setListOfCompartmentTypes(listOfCompartmentTypes);
return listOfCompartmentTypes;
} else if (elementName.equals("listOfSpeciesTypes")
&& (model.getLevel() == 2 && model.getVersion() > 1)) {
ListOf<SpeciesType> listOfSpeciesTypes = (ListOf<SpeciesType>) newContextObject;
model.setListOfSpeciesTypes(listOfSpeciesTypes);
return listOfSpeciesTypes;
} else {
log4jLogger.warn("The element " + elementName + " is not recognized");
}
} else {
log4jLogger.warn("The element " + elementName + " is not recognized");
}
} else if (contextObject instanceof ListOf<?>) {
ListOf<?> list = (ListOf<?>) contextObject;
if (list.getParentSBMLObject() instanceof Model) {
Model model = (Model) list.getParentSBMLObject();
if (elementName.equals("functionDefinition")
&& list.getSBaseListType().equals(
ListOf.Type.listOfFunctionDefinitions)
&& model.getLevel() > 1) {
FunctionDefinition functionDefinition = (FunctionDefinition) newContextObject;
model.addFunctionDefinition(functionDefinition);
return functionDefinition;
} else if (elementName.equals("unitDefinition")
&& list.getSBaseListType().equals(
ListOf.Type.listOfUnitDefinitions)) {
UnitDefinition unitDefinition = (UnitDefinition) newContextObject;
model.addUnitDefinition(unitDefinition);
return unitDefinition;
} else if (elementName.equals("compartment")
&& list.getSBaseListType().equals(
ListOf.Type.listOfCompartments)) {
Compartment compartment = (Compartment) newContextObject;
compartment.initDefaults();
model.addCompartment(compartment);
return compartment;
} else if (elementName.equals("species")
&& list.getSBaseListType().equals(
ListOf.Type.listOfSpecies)
&& ((model.getLevel() == 1 && model
.getVersion() > 1) || model.getLevel() > 1)) {
Species species = (Species) newContextObject;
species.initDefaults();
model.addSpecies(species);
return species;
}
// level 1: species => specie
else if (elementName.equals("specie")
&& list.getSBaseListType().equals(
ListOf.Type.listOfSpecies)
&& model.getLevel() == 1
&& model.getVersion() == 1) {
Species species = (Species) newContextObject;
species.initDefaults();
model.addSpecies(species);
return species;
} else if (elementName.equals("parameter")
&& list.getSBaseListType().equals(
ListOf.Type.listOfParameters)) {
Parameter parameter = (Parameter) newContextObject;
parameter.initDefaults();
model.addParameter(parameter);
return parameter;
} else if (elementName.equals("initialAssignment")
&& list.getSBaseListType().equals(
ListOf.Type.listOfInitialAssignments)
&& ((model.getLevel() == 2 && model
.getVersion() > 1) || model.getLevel() >= 3)) {
InitialAssignment initialAssignment = (InitialAssignment) newContextObject;
model.addInitialAssignment(initialAssignment);
return initialAssignment;
} else if (elementName.equals("algebraicRule")
&& list.getSBaseListType().equals(
ListOf.Type.listOfRules)) {
AlgebraicRule rule = (AlgebraicRule) newContextObject;
model.addRule(rule);
return rule;
} else if (elementName.equals("assignmentRule")
&& list.getSBaseListType().equals(
ListOf.Type.listOfRules)
&& model.getLevel() > 1) {
AssignmentRule rule = (AssignmentRule) newContextObject;
model.addRule(rule);
return rule;
} else if (elementName.equals("parameterRule")
&& list.getSBaseListType().equals(ListOf.Type.listOfRules)
&& model.getLevel() == 1)
{
ExplicitRule rule = (ExplicitRule) newContextObject;
model.addRule(rule);
return rule;
} else if (elementName.equals("specieConcentrationRule")
&& list.getSBaseListType().equals(ListOf.Type.listOfRules)
&& model.getLevel() == 1
&& model.getVersion() == 1)
{
ExplicitRule rule = (ExplicitRule) newContextObject;
model.addRule(rule);
return rule;
} else if (elementName.equals("speciesConcentrationRule")
&& list.getSBaseListType().equals(ListOf.Type.listOfRules)
&& model.getLevel() == 1
&& model.getVersion() == 2)
{
ExplicitRule rule = (ExplicitRule) newContextObject;
model.addRule(rule);
return rule;
} else if (elementName.equals("compartmentVolumeRule")
&& list.getSBaseListType().equals(ListOf.Type.listOfRules)
&& model.getLevel() == 1)
{
ExplicitRule rule = (ExplicitRule) newContextObject;
model.addRule(rule);
return rule;
} else if (elementName.equals("rateRule")
&& list.getSBaseListType().equals(
ListOf.Type.listOfRules)) {
RateRule rule = (RateRule) newContextObject;
model.addRule(rule);
return rule;
} else if (elementName.equals("constraint")
&& list.getSBaseListType().equals(
ListOf.Type.listOfConstraints)
&& ((model.getLevel() == 2 && model
.getVersion() > 1) || model.getLevel() >= 3)) {
Constraint constraint = (Constraint) newContextObject;
model.addConstraint(constraint);
return constraint;
} else if (elementName.equals("reaction")
&& list.getSBaseListType().equals(
ListOf.Type.listOfReactions)) {
Reaction reaction = (Reaction) newContextObject;
model.addReaction(reaction);
reaction.initDefaults();
return reaction;
} else if (elementName.equals("event")
&& list.getSBaseListType().equals(
ListOf.Type.listOfEvents)
&& model.getLevel() > 1) {
Event event = (Event) newContextObject;
model.addEvent(event);
event.initDefaults();
return event;
} else if (elementName.equals("compartmentType")
&& list.getSBaseListType().equals(
ListOf.Type.listOfCompartmentTypes)
&& (model.getLevel() == 2 && model.getVersion() > 1)) {
CompartmentType compartmentType = (CompartmentType) newContextObject;
model.addCompartmentType(compartmentType);
return compartmentType;
} else if (elementName.equals("speciesType")
&& list.getSBaseListType().equals(
ListOf.Type.listOfSpeciesTypes)
&& (model.getLevel() == 2 && model.getVersion() > 1)) {
SpeciesType speciesType = (SpeciesType) newContextObject;
model.addSpeciesType(speciesType);
return speciesType;
} else {
log4jLogger.warn("The element " + elementName + " is not recognized");
}