Class MexicoHelper

java.lang.Object
fr.ifremer.isisfish.mexico.MexicoHelper

public class MexicoHelper extends Object
Mexico helper class.
Since:
3.2.0.4 Last update : $Date$ By : $Author$
Version:
$Revision$
Author:
chatellier
  • Constructor Details

    • MexicoHelper

      public MexicoHelper()
  • Method Details

    • getDesignPlanAsXML

      public static String getDesignPlanAsXML(DesignPlan designPlan, String... args)
      Get xml representation of a design plan.
      Parameters:
      designPlan - design plan
      args - some meta information to put into generated xml (author, date, id, license)
      Returns:
      xml design plan representation
    • writeDesignPlanToFile

      public static void writeDesignPlanToFile(File file, DesignPlan designPlan)
      Convert design plan to xml and write it to given file.
      Parameters:
      designPlan -
    • getDesignPlanFromXML

      public static DesignPlan getDesignPlanFromXML(File xmlFile, org.nuiton.topia.TopiaContext topiaContext) throws IOException
      Parse xmlFile with sax, and return a DesignPlan.
      Parameters:
      xmlFile - file path to parse
      topiaContext - database context
      Returns:
      DesignPlan
      Throws:
      IOException
    • formatXML

      public static String formatXML(String unformattedXml)
      Format xml string.
      Parameters:
      unformattedXml - non formatted xml string (must be valid xml)
      Returns:
      xml, formatted and indented Code from http://stackoverflow.com/questions/139076/how-to-pretty-print-xml-from-java
      Throws:
      IsisFishRuntimeException
      IllegalArgumentException - if input xml is not valid
    • getMatrixAsXML

      public static String getMatrixAsXML(org.nuiton.math.matrix.MatrixND matrix)
      Transform matrix into XML mexico format. Format is :
         <mx name="une matrice">
          <dimension name="classe" size="2">
            <label>jeune</label>
            <label>vieux</label>
          </dimension>
          <dimension name="x" size="3">
            <label>0</label>
            <label>1</label>
            <label>2</label>
          </dimension>
          <d>2.0</d>
          <d>3.1415</d>
          <d>2.0</d>
          <d>3.1415</d>
          <d>2.0</d>
          <d>3.1415</d>
        </mx>
       
      Parameters:
      matrix - matrix
      Returns:
      matrix as xml or null if matrix is null
      Since:
      3.3.0.0
    • appendString

      protected static StringBuffer appendString(StringBuffer buffer, Object o)
      Append object type and value in stringbuffer. Append it as :
      fqn(value)
      Parameters:
      buffer - buffer to append to
      o - value to append
      Returns:
      stringbuffer
    • getMatrixFromXml

      public static org.nuiton.math.matrix.MatrixND getMatrixFromXml(org.dom4j.Element mxElement, org.nuiton.topia.TopiaContext context)
      Parse a dom element (mx) as a MatrixND. Format is :
         <mx name="une matrice">
          <dimension name="classe" size="2">
            <label>jeune</label>
            <label>vieux</label>
          </dimension>
          <dimension name="x" size="3">
            <label>0</label>
            <label>1</label>
            <label>2</label>
          </dimension>
          <d>2.0</d>
          <d>3.1415</d>
          <d>2.0</d>
          <d>3.1415</d>
          <d>2.0</d>
          <d>3.1415</d>
        </mx>
       
      Parameters:
      mxElement - dom element
      context - topia context
      Returns:
      matrix nd
    • getQualifiedName

      protected static String getQualifiedName(Object o)
      Return object fully qualified name excepted for TopiaEntity.
      Parameters:
      o - object to get fqn
      Returns:
      fqn for mexico file format
    • getRulesAsXml

      public static String getRulesAsXml(List<Rule> rules)
      Transform rules list as xml. Format is :
        <rules>
          <rule name="RuleName1">
            <param key="rule.0.parameter.param1">param1</param>
            <param key="rule.0.parameter.pop">topiaId1</param>
          </rule>
          <rule name="RuleName2">
            <param key="rule.0.parameter.param1">param2</param>
            <param key="rule.0.parameter.pop">topiaId2</param>
          </rule>
        </rules>
       
      Parameters:
      rules - rules list
      Returns:
      rules as xml
    • getRulesFromXml

      public static List<Rule> getRulesFromXml(org.dom4j.Element rulesElement, org.nuiton.topia.TopiaContext topiaContext)
      Parse xml as rules list. Format is :
        <rules>
          <rule name="RuleName1">
            <param key="rule.0.parameter.param1">param1</param>
            <param key="rule.0.parameter.pop">topiaId1</param>
          </rule>
          <rule name="RuleName2">
            <param key="rule.0.parameter.param1">param2</param>
            <param key="rule.0.parameter.pop">topiaId2</param>
          </rule>
        </rules>
       
      Parameters:
      rulesElement - rules dom element
      topiaContext - topia context (for rules parameters)
      Returns:
      rules as xml
    • getObjectFromString

      public static Object getObjectFromString(String content, org.nuiton.topia.TopiaContext context)
      Parse string content (human readable) to get isis fish instance for this object. For example:
      • Species:Nephrops
      • Population:Anchois
      • TimeStep:21
      • ...
      Parameters:
      content - content to parse
      context - context to database
      Returns:
      object instance
    • getStringFromObject

      public static String getStringFromObject(Object object)
      Get string representation (human readable) for an object.
      Parameters:
      object -
      Returns:
      string representation