Package org.sbml.jsbml.xml

Examples of org.sbml.jsbml.xml.XMLNode


   
    logger.debug("processAttribute: attribute name = " + attributeName + ", value = " + value);
   
    if (contextObject instanceof XMLNode) {
     
      XMLNode xmlNode = (XMLNode) contextObject;
      xmlNode.addAttr(attributeName, value, null, prefix);
     
     
    } else {
      logger.debug("processAttribute: context Object is not an XMLNode !!! " + contextObject);
    }
View Full Code Here


   
    logger.debug("processCharactersOf called: characters = @" + characters + "@");
   
    // characters = StringTools.encodeForHTML(characters); // TODO: use an apache util for that.

    XMLNode textNode = new XMLNode(characters);

    if (contextObject instanceof XMLNode) {
     
      XMLNode xmlNode = (XMLNode) contextObject;

      xmlNode.addChild(textNode);
     
    } else if (contextObject instanceof SBase) {
      SBase parentSBMLElement = (SBase) contextObject;
     
      XMLNode xmlNode = null;

      if (parentSBMLElement.isSetNotes() && typeOfNotes.equals("notes"))
      {
        xmlNode = parentSBMLElement.getNotes();
      }
      else if (typeOfNotes.equals("message") && parentSBMLElement instanceof Constraint
          && ((Constraint) parentSBMLElement).isSetMessage())
      {
        xmlNode = ((Constraint) parentSBMLElement).getMessage();
      }
      else
      {
        logger.warn("The type of String " + typeOfNotes + " on the element " +
            parentSBMLElement.getElementName() + " is unknown !! Some data might be lost");
        return;
      }

      xmlNode.addChild(textNode);
     
    } else
      logger.debug("processCharactersOf: context Object is not an XMLNode or SBase !!! " + contextObject);
    }
View Full Code Here

   */
  public boolean processEndElement(String elementName, String prefix,
      boolean isNested, Object contextObject)
  {
    if (contextObject instanceof XMLNode) {
      XMLNode xmlNode = (XMLNode) contextObject;
     
      if (xmlNode.getChildCount() == 0) {
        xmlNode.setEnd();
      }
    }
   
    return true;
  }
View Full Code Here

      String localName, boolean hasAttributes, boolean isLastNamespace,
      Object contextObject)
  {
    if (contextObject instanceof XMLNode) {
     
      XMLNode xmlNode = (XMLNode) contextObject;
      if (!xmlNode.isStart()) {
        logger.debug("processNamespace: context Object is not a start node !!! " + contextObject);
      }
     
      xmlNode.addNamespace(URI, prefix);
     
    } else {
      logger.debug("processNamespace: context Object is not an XMLNode !!! " + contextObject);
      logger.debug("processNamespace: element name = " + elementName + ", namespace = " + prefix + ":" + URI);
    }
View Full Code Here

    logger.debug("processStartElement: element name = " + elementName);
   
    if (elementName.equals("notes")
        && (contextObject instanceof SBase)) {
      SBase sbase = (SBase) contextObject;
      sbase.setNotes(new XMLNode(new XMLTriple("notes", null, null), new XMLAttributes()));
      return contextObject;
    }
   
    // Creating a StartElement XMLNode !! 
    XMLNode xmlNode = new XMLNode(new XMLTriple(elementName, null, prefix), new XMLAttributes(), new XMLNamespaces());
   
    if (contextObject instanceof SBase) {
      SBase parentSBMLElement = (SBase) contextObject;
     
      if (typeOfNotes.equals("notes")) {
        parentSBMLElement.getNotes().addChild(xmlNode);
      } else if (typeOfNotes.equals("message") && parentSBMLElement instanceof Constraint) {
        ((Constraint) parentSBMLElement).getMessage().addChild(xmlNode);
      } else {
        logger.warn("The type of String " + typeOfNotes + " on the element " +
            parentSBMLElement.getElementName() + " is unknown !! Some data might be lost");
      }
     
    } else if (contextObject instanceof XMLNode) {
      XMLNode parentNode = (XMLNode) contextObject;
     
      parentNode.addChild(xmlNode);
    }
   
    return xmlNode;
  }
View Full Code Here


    boolean isNested = false;
    long nbChildren = xmlNode.getChildCount();
    for (int i = 0; i < nbChildren; i++) {
      XMLNode child = xmlNode.getChildAt(i);
      if (!child.isText() && !(isRoot || isTopElement)) {
        isNested = true;
        writer.writeCharacters(StringTools.fill((depth - indentCount),
          indentChar));
      }
      write(child, depth + indentCount);
View Full Code Here

    Object object = readXMLFromString(notesXHTML, listener);
    if ((object != null) && (object instanceof Constraint)) {
      Constraint constraint = ((Constraint) object);
     
      if (constraint.isSetNotes()) {
        XMLNode notes = constraint.getNotes();
        if (notes != null) {
          return notes;
        }
      } else if (constraint.isSetMessage()) {
        XMLNode message = constraint.getMessage();
        if (message != null) {
          return message;
        }
      }
    }
View Full Code Here

   *
   * @param message
   *           the message to set
   */
  public void setMessage(XMLNode message) {
    XMLNode oldMessage = this.message;
    this.message = message;
    firePropertyChange(TreeNodeChangeEvent.message, oldMessage, message);
    this.message.setParent(this);
  }
View Full Code Here

        }

        if (elementName.equals("notes")
            && (contextObject instanceof SBase)) {
          SBase sbase = (SBase) contextObject;
          sbase.setNotes(new XMLNode(new XMLTriple("notes", null, null), new XMLAttributes()));
        } else if (elementName.equals("annotation")
            && (contextObject instanceof SBase)) {
          SBase sbase = (SBase) contextObject;
          Annotation annotation = (Annotation) newContextObject;
          sbase.setAnnotation(annotation);

          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");
            }
          } 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.addLocalParameter(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.addLocalParameter(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;

          if (elementName.equals("listOfEventAssignments")) {
            ListOf<EventAssignment> listOfEventAssignments = (ListOf<EventAssignment>) newContextObject;
            event.setListOfEventAssignments(listOfEventAssignments);

            return listOfEventAssignments;
          } else if (elementName.equals("trigger")) {
            Trigger trigger = (Trigger) newContextObject;
            event.setTrigger(trigger);

            return trigger;
          } else if (elementName.equals("delay")) {
            Delay delay = (Delay) newContextObject;
            event.setDelay(delay);

            return delay;
          } else if (elementName.equals("priority")) {
            Priority priority = (Priority) newContextObject;
            event.setPriority(priority);

            return priority;
          } else {
            log4jLogger.warn("The element " + elementName + " is not recognized");
          }
        } else if (contextObject instanceof Reaction) {
          Reaction reaction = (Reaction) contextObject;
          if (elementName.equals("listOfReactants")) {
            ListOf<SpeciesReference> listOfReactants = (ListOf<SpeciesReference>) newContextObject;
            reaction.setListOfReactants(listOfReactants);

            return listOfReactants;
          } else if (elementName.equals("listOfProducts")) {
            ListOf<SpeciesReference> listOfProducts = (ListOf<SpeciesReference>) newContextObject;
            reaction.setListOfProducts(listOfProducts);

            return listOfProducts;
          } else if (elementName.equals("listOfModifiers")
              && reaction.getLevel() > 1) {
            ListOf<ModifierSpeciesReference> listOfModifiers = (ListOf<ModifierSpeciesReference>) newContextObject;
            reaction.setListOfModifiers(listOfModifiers);

            return listOfModifiers;
          } else if (elementName.equals("kineticLaw")) {
            KineticLaw kineticLaw = (KineticLaw) newContextObject;
            reaction.setKineticLaw(kineticLaw);

            return kineticLaw;
          } else {
            log4jLogger.warn("The element " + elementName + " is not recognized");
          }
        } else if (contextObject instanceof SpeciesReference) {
          SpeciesReference speciesReference = (SpeciesReference) contextObject;

          if (elementName.equals("stoichiometryMath")) {
            StoichiometryMath stoichiometryMath = (StoichiometryMath) newContextObject;
            speciesReference.setStoichiometryMath(stoichiometryMath);

            return stoichiometryMath;
          } else {
            log4jLogger.warn("The element " + elementName + " is not recognized");
          }
        } else if (contextObject instanceof KineticLaw) {
          KineticLaw kineticLaw = (KineticLaw) contextObject;

          if (elementName.equals("listOfLocalParameters")
              && kineticLaw.getLevel() >= 3) {
            ListOf<LocalParameter> listOfLocalParameters = (ListOf<LocalParameter>) newContextObject;
            kineticLaw.setListOfLocalParameters(listOfLocalParameters);
            listOfLocalParameters.setSBaseListType(ListOf.Type.listOfLocalParameters);

            return listOfLocalParameters;
          } else if (elementName.equals("listOfParameters")
              && kineticLaw.isSetLevel() && kineticLaw.getLevel() < 3) {
            ListOf<LocalParameter> listOfLocalParameters = (ListOf<LocalParameter>) newContextObject;
            kineticLaw.setListOfLocalParameters(listOfLocalParameters);
            listOfLocalParameters.setSBaseListType(ListOf.Type.listOfLocalParameters);

            return listOfLocalParameters;
          } else {
            log4jLogger.warn("The element " + elementName + " is not recognized");
          }
        } else if (contextObject instanceof Constraint) {
          Constraint constraint = (Constraint) contextObject;

          if (elementName.equals("message")
              && ((constraint.getLevel() == 2 && constraint
                  .getVersion() > 1) || constraint.getLevel() >= 3))
          {
            constraint.setMessage(new XMLNode(new XMLTriple("message", null, null), new XMLAttributes()));

            return constraint;
          } else {
            log4jLogger.warn("The element " + elementName + " is not recognized");
          }
View Full Code Here

  /* (non-Javadoc)
   * @see org.sbml.jlibsbml.SBase#appendNotes(java.lang.String)
   */
  public void appendNotes(String notes) {
    XMLNode addedNotes = XMLNode.convertStringToXMLNode(StringTools
        .toXMLNotesString(notes));
    if (isSetNotes()) {
      XMLNode oldNotes = notesXMLNode.clone();
      appendNotes(addedNotes);
      firePropertyChange(TreeNodeChangeEvent.notes, oldNotes, notesXMLNode);
    } else {
      setNotes(addedNotes);
    }
View Full Code Here

TOP

Related Classes of org.sbml.jsbml.xml.XMLNode

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.