Package org.sbml.jsbml

Examples of org.sbml.jsbml.UnitDefinition


          if (listOfElementsToWrite.isEmpty()) {
            listOfElementsToWrite = null;
          }
        }
      } else if (sbase instanceof UnitDefinition) {
        UnitDefinition unitDefinition = (UnitDefinition) sbase;

        if (unitDefinition.isSetListOfUnits()) {
          listOfElementsToWrite = new ArrayList<Object>();
          listOfElementsToWrite.add(unitDefinition.getListOfUnits());
        }
      } else if (sbase instanceof Reaction) {
        Reaction reaction = (Reaction) sbase;
        listOfElementsToWrite = new ArrayList<Object>();
View Full Code Here


            Model model = (Model) list.getParentSBMLObject();
            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;
              model.addCompartment(compartment);

              return compartment;
            } else if (elementName.equals("specie")
                && list.getSBaseListType().equals(
                    ListOf.Type.listOfSpecies)) {
              Species species = (Species) newContextObject;
              model.addSpecies(species);

              return species;
            } else if (elementName.equals("parameter")
                && list.getSBaseListType().equals(
                    ListOf.Type.listOfParameters)) {
              Parameter parameter = (Parameter) newContextObject;
              model.addParameter(parameter);

              return parameter;
            } 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") // TODO : wrong, there are no assignmentRule element, only more specialize rule
                && list.getSBaseListType().equals(
                    ListOf.Type.listOfRules)) {
              AssignmentRule rule = (AssignmentRule) newContextObject;
              model.addRule(rule);

              return rule;
            } else if (elementName.equals("reaction")
                && list.getSBaseListType().equals(
                    ListOf.Type.listOfReactions)) {
              Reaction reaction = (Reaction) newContextObject;
              model.addReaction(reaction);

              return reaction;
            } else {
              // TODO : SBML syntax error, throw an exception?
            }
          } else if (list.getParentSBMLObject() instanceof UnitDefinition) {
            UnitDefinition unitDefinition = (UnitDefinition) list
                .getParentSBMLObject();

            if (elementName.equals("unit")
                && list.getSBaseListType().equals(
                    ListOf.Type.listOfUnits)) {
              Unit unit = (Unit) newContextObject;
              unitDefinition.addUnit(unit);

              return unit;
            } else {
              // TODO : SBML syntax error, throw an exception?
            }
          } else if (list.getParentSBMLObject() instanceof Reaction) {
            Reaction reaction = (Reaction) list
                .getParentSBMLObject();

            if (elementName.equals("specieReference")) {
              SpeciesReference speciesReference = (SpeciesReference) newContextObject;

              if (list.getSBaseListType().equals(
                  ListOf.Type.listOfReactants)) {
                reaction.addReactant(speciesReference);

                return speciesReference;
              } else if (list.getSBaseListType().equals(
                  ListOf.Type.listOfProducts)) {
                reaction.addProduct(speciesReference);

                return speciesReference;
              } else {
                // TODO : SBML syntax error, throw an exception?
              }
            } else {
              // TODO : SBML syntax error, throw an exception?
            }
          } else if (list.getParentSBMLObject() instanceof KineticLaw) {
            KineticLaw kineticLaw = (KineticLaw) list
                .getParentSBMLObject();

            if (elementName.equals("parameter")
                && list.getSBaseListType().equals(
                    ListOf.Type.listOfParameters)) {
              LocalParameter localParameter = (LocalParameter) newContextObject;
              kineticLaw.addParameter(localParameter);

              return localParameter;
            } else {
              // TODO : SBML syntax error, throw an exception?
            }
          } else {
            // TODO : SBML syntax error, throw an exception?
          }
        } else if (contextObject instanceof UnitDefinition) {
          UnitDefinition unitDefinition = (UnitDefinition) contextObject;

          if (elementName.equals("listOfUnits")) {
            ListOf<Unit> listOfUnits = (ListOf<Unit>) newContextObject;
            unitDefinition.setListOfUnits(listOfUnits);

            return listOfUnits;
          }
        } else if (contextObject instanceof Reaction) {
          Reaction reaction = (Reaction) contextObject;
View Full Code Here

  private void setCompartmentUnits(Compartment compartment, Model model) {

    if (compartment.isSetUnits()) {
      String unitsID = compartment.getUnits();

      UnitDefinition unitDefinition = model.getUnitDefinition(unitsID);

      if (unitDefinition != null) {
        compartment.setUnits(unitDefinition);
      } else {
        // TODO : the unitDefinition ID doesn't match a unitDefinition,
View Full Code Here

  private void setEventTimeUnits(Event event, Model model) {

    if (event.isSetTimeUnits()) {
      String timeUnitsID = event.getTimeUnits();

      UnitDefinition unitDefinition = model
          .getUnitDefinition(timeUnitsID);

      if (unitDefinition != null) {
        event.setTimeUnits(unitDefinition);
      } else {
View Full Code Here

      Model model) {

    if (parameter.isSetUnits()) {
      String unitsID = parameter.getUnits();

      UnitDefinition unitDefinition = model.getUnitDefinition(unitsID);

      if (unitDefinition != null) {
        parameter.setUnits(unitDefinition);
      } else {
        // TODO : the unitDefinition ID doesn't match an unitDefinition,
View Full Code Here

  private void setSpeciesSubstanceUnits(Species species, Model model) {

    if (species.isSetSubstanceUnits()) {
      String substanceUnitsID = species.getSubstanceUnits();

      UnitDefinition unitDefinition = model
          .getUnitDefinition(substanceUnitsID);

      if (unitDefinition != null) {
        species.setSubstanceUnits(unitDefinition);
      }
View Full Code Here

  /**
   * Test method for {@link org.sbml.jsbml.AbstractNamedSBaseWithUnit#setUnits(org.sbml.jsbml.UnitDefinition)}.
   */
  @Test
  public void testSetUnitsUnitDefinition() {
    UnitDefinition ud = sbase.getModel().getPredefinedUnitDefinition(
      kind.toString().toLowerCase());
    sbase.setUnits(ud);
    assertTrue(sbase.isSetUnits());
    assertTrue(sbase.isSetUnitsInstance());
    assertTrue(sbase.getUnits().equals(kind.toString().toLowerCase() + "_base"));
View Full Code Here

    assertTrue(s1.getNumCVTerms() == 0);
   
    assertTrue(s1.getInitialAmount() == 1);
   
   
    UnitDefinition mls = model.getUnitDefinition(1);
   
    assertTrue(mls != null);
    assertTrue(mls.getNumUnits() == 3);
    assertTrue(mls.getName().equals("mls"));
    assertTrue(mls.getUnit(0).getScale() == -3);
    assertTrue(mls.getUnit(0).getKind().getName().equals("mole"));
   
    assertTrue(mls.getUnit(2).getExponent() == -1);
    assertTrue(mls.getUnit(2).getKind().getName().equals("second"));
    assertTrue(mls.getUnit(2).getKind().equals(Kind.SECOND));

    Parameter vm = model.getParameter(0);
   
    assertTrue(vm != null);
    assertTrue(vm.getUnits().equals("mls"));
View Full Code Here

            SBase element = listOf.get(i);

            if (element != null) {
              boolean add = true;
              if (element instanceof UnitDefinition) {
                UnitDefinition ud = (UnitDefinition) element;
                if (ud.isPredefined()) {
                  add = false;
                }
              }
              if (add) {
                listOfElementsToWrite.add(element);
              }
            }
          }
          if (listOfElementsToWrite.isEmpty()) {
            listOfElementsToWrite = null;
          }
        }
      } else if (sbase instanceof UnitDefinition) {
        UnitDefinition unitDefinition = (UnitDefinition) sbase;

        if (unitDefinition.isSetListOfUnits()) {
          listOfElementsToWrite = new ArrayList<Object>();
          listOfElementsToWrite.add(unitDefinition.getListOfUnits());
        }
      } else if (sbase instanceof Reaction) {
        Reaction reaction = (Reaction) sbase;
        listOfElementsToWrite = new ArrayList<Object>();
View Full Code Here

              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");
            }
          } else if (list.getParentSBMLObject() instanceof UnitDefinition) {
            UnitDefinition unitDefinition = (UnitDefinition) list
                .getParentSBMLObject();

            if (elementName.equals("unit")
                && list.getSBaseListType().equals(
                    ListOf.Type.listOfUnits)) {
              Unit unit = (Unit) newContextObject;
              unit.initDefaults();
              unitDefinition.addUnit(unit);

              return unit;
            } else {
              log4jLogger.warn("The element " + elementName + " is not recognized");
            }
          } else if (list.getParentSBMLObject() instanceof Reaction) {
            Reaction reaction = (Reaction) list
                .getParentSBMLObject();

            if (elementName.equals("speciesReference")
                && (reaction.getLevel() > 1 || (reaction
                    .getLevel() == 1 && reaction
                    .getVersion() == 2))) {
              SpeciesReference speciesReference = (SpeciesReference) newContextObject;
              speciesReference.initDefaults();

              if (list.getSBaseListType().equals(
                  ListOf.Type.listOfReactants)) {
                reaction.addReactant(speciesReference);

                return speciesReference;
              } else if (list.getSBaseListType().equals(
                  ListOf.Type.listOfProducts)) {
                reaction.addProduct(speciesReference);

                return speciesReference;
              } else {
                log4jLogger.warn("The element " + elementName + " is not recognized");
              }
            } else if (elementName.equals("specieReference")
                && reaction.getLevel() == 1) {
              SpeciesReference speciesReference = (SpeciesReference) newContextObject;
              speciesReference.initDefaults();

              if (list.getSBaseListType().equals(
                  ListOf.Type.listOfReactants)) {
                reaction.addReactant(speciesReference);

                return speciesReference;
              } else if (list.getSBaseListType().equals(
                  ListOf.Type.listOfProducts)) {
                reaction.addProduct(speciesReference);

                return speciesReference;
              } else {
                log4jLogger.warn("The element " + elementName + " is not recognized");
              }
            } else if (elementName
                .equals("modifierSpeciesReference")
                && list.getSBaseListType().equals(
                    ListOf.Type.listOfModifiers)
                && reaction.getLevel() > 1) {
              ModifierSpeciesReference modifierSpeciesReference = (ModifierSpeciesReference) newContextObject;
              reaction.addModifier(modifierSpeciesReference);

              return modifierSpeciesReference;
            } else {
              log4jLogger.warn("The element " + elementName + " is not recognized");
            }
          } else if (list.getParentSBMLObject() instanceof KineticLaw) {
            KineticLaw kineticLaw = (KineticLaw) list
                .getParentSBMLObject();
            // Level 3 : parameter and listOfParameters =>
            // localParameter and listOfLocalParameter
            if (elementName.equals("localParameter")
                && list.getSBaseListType().equals(
                    ListOf.Type.listOfLocalParameters)
                && kineticLaw.getLevel() >= 3) {
              LocalParameter localParameter = (LocalParameter) newContextObject;
              kineticLaw.addParameter(localParameter);

              return localParameter;
            } else if (elementName.equals("parameter")
                && list.getSBaseListType().equals(
                    ListOf.Type.listOfLocalParameters)
                && kineticLaw.isSetLevel()
                && kineticLaw.getLevel() < 3) {
              LocalParameter localParameter = new LocalParameter(
                  (Parameter) newContextObject);
              kineticLaw.addParameter(localParameter);

              return localParameter;
            } else {
              log4jLogger.warn("The element " + elementName + " is not recognized");
            }
          } else if (list.getParentSBMLObject() instanceof Event) {
            Event event = (Event) list.getParentSBMLObject();

            if (elementName.equals("eventAssignment")
                && list.getSBaseListType().equals(
                    ListOf.Type.listOfEventAssignments)
                && event.getLevel() > 1) {
              EventAssignment eventAssignment = (EventAssignment) newContextObject;
              event.addEventAssignment(eventAssignment);

              return eventAssignment;
            } else {
              log4jLogger.warn("The element " + elementName + " is not recognized");
            }
          } else {
            log4jLogger.warn("The element " + elementName + " is not recognized");
          }
        } else if (contextObject instanceof UnitDefinition) {
          UnitDefinition unitDefinition = (UnitDefinition) contextObject;

          if (elementName.equals("listOfUnits")) {
            ListOf<Unit> listOfUnits = (ListOf<Unit>) newContextObject;
            unitDefinition.setListOfUnits(listOfUnits);

            return listOfUnits;
          }
        } else if (contextObject instanceof Event) {
          Event event = (Event) contextObject;
View Full Code Here

TOP

Related Classes of org.sbml.jsbml.UnitDefinition

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.