protected Document generateAntTask() {
    try {
      DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
      Document doc = factory.newDocumentBuilder().newDocument();
      Element root = doc.createElement("project"); // $NON-NLS-1$
      root.setAttribute("name", "build"); // $NON-NLS-1$ //$NON-NLS-2$
      root.setAttribute("default", "feature_export"); // $NON-NLS-1$ //$NON-NLS-2$
      doc.appendChild(root);

      Element target = doc.createElement("target"); // $NON-NLS-1$
      target.setAttribute("name", "feature_export"); // $NON-NLS-1$ //$NON-NLS-2$
      root.appendChild(target);

      Element export = doc.createElement("pde.exportFeatures"); // $NON-NLS-1$
      export.setAttribute("features", getFeatureIDs()); // $NON-NLS-1$
      export.setAttribute("destination", fPage.getDestination()); // $NON-NLS-1$
      String filename = fPage.getFileName();
      if (filename != null) export.setAttribute("filename", filename); // $NON-NLS-1$
      export.setAttribute("exportType", getExportOperation()); // $NON-NLS-1$
      export.setAttribute("useJARFormat", Boolean.toString(fPage.useJARFormat())); // $NON-NLS-1$
      export.setAttribute("exportSource", Boolean.toString(fPage.doExportSource())); // $NON-NLS-1$
      if (fPage.doExportSource()) {
        export.setAttribute(
            "exportSourceBundle", Boolean.toString(fPage.doExportSourceBundles())); // $NON-NLS-1$
      }
      String qualifier = fPage.getQualifier();
      if (qualifier != null) export.setAttribute("qualifier", qualifier); // $NON-NLS-1$
      target.appendChild(export);
      return doc;
    } catch (DOMException e) {
    } catch (FactoryConfigurationError e) {
    } catch (ParserConfigurationException e) {
    }
    return null;
  }
Ejemplo n.º 2
0
  public void marshall(
      Class parentType,
      QName elementType,
      ExtensibilityElement extension,
      PrintWriter pw,
      Definition def,
      ExtensionRegistry extReg)
      throws WSDLException {
    MIMEContent mimeContent = (MIMEContent) extension;

    if (mimeContent != null) {
      String tagName = DOMUtils.getQualifiedValue(MIMEConstants.NS_URI_MIME, "content", def);

      if (parentType != null && MIMEPart.class.isAssignableFrom(parentType)) {
        pw.print("    ");
      }

      pw.print("        <" + tagName);

      DOMUtils.printAttribute(MIMEConstants.ATTR_PART, mimeContent.getPart(), pw);
      DOMUtils.printAttribute(Constants.ATTR_TYPE, mimeContent.getType(), pw);

      Boolean required = mimeContent.getRequired();

      if (required != null) {
        DOMUtils.printQualifiedAttribute(Constants.Q_ATTR_REQUIRED, required.toString(), def, pw);
      }

      pw.println("/>");
    }
  }
Ejemplo n.º 3
0
 public void writeToLog(String preamble) throws IOException {
   String dirText = " (top down):";
   if (mSearchMethod == JOAConstants.SEARCH_BOTTOM_UP) dirText = " (bottom up):";
   try {
     JOAConstants.LogFileStream.writeBytes(preamble);
     JOAConstants.LogFileStream.writeBytes(
         "\t"
             + "Interpolation "
             + dirText
             + " "
             + mIntVar
             + " WRT "
             + mWRTVar
             + " Int. at Value = "
             + JOAFormulas.formatDouble(mIntAtValue, 3, false)
             + " Use deepest = "
             + Boolean.toString(mUseDeepest)
             + " At Surface = "
             + Boolean.toString(mAtSurface)
             + " Surface Depth Limit = "
             + JOAFormulas.formatDouble(mSurfaceDepthLimit, 3, false)
             + " At Bottom = "
             + Boolean.toString(mAtBottom)
             + " Interpolate Missing = "
             + Boolean.toString(mInterpolateMissing)
             + "\n");
     JOAConstants.LogFileStream.flush();
   } catch (IOException ex) {
     throw ex;
   }
 }
Ejemplo n.º 4
0
  private Element generatePortNode(Document doc, Port port) {
    Element portEl = doc.createElement(EL_PORT);

    portEl.setAttribute(ATR_NAME, port.getName());
    portEl.setAttribute(ATR_TYPE, port.getType());
    portEl.setAttribute(ATR_X, Integer.toString(port.getX()));
    portEl.setAttribute(ATR_Y, Integer.toString(port.getY()));
    portEl.setAttribute(ATR_PORT_CONNECTION, port.isArea() ? "area" : "");
    portEl.setAttribute(ATR_STRICT, Boolean.toString(port.isStrict()));
    portEl.setAttribute(ATR_MULTI, Boolean.toString(port.isMulti()));

    return portEl;
  }
Ejemplo n.º 5
0
  /** @see com.levelonelabs.aim.XMLizable#writeState(Element) */
  public void writeState(Element emptyStateElement) {
    Document doc = emptyStateElement.getOwnerDocument();
    emptyStateElement.setAttribute("name", this.getName());
    emptyStateElement.setAttribute("group", this.getGroup());
    emptyStateElement.setAttribute("isBanned", Boolean.toString(this.isBanned()));

    Iterator roleit = roles.keySet().iterator();
    while (roleit.hasNext()) {
      String role = (String) roleit.next();
      Element roleElem = doc.createElement("role");
      roleElem.setAttribute("name", role);
      emptyStateElement.appendChild(roleElem);
    }

    Iterator prefs = preferences.keySet().iterator();
    while (prefs.hasNext()) {
      String pref = (String) prefs.next();
      Element prefElem = doc.createElement("preference");
      prefElem.setAttribute("name", pref);
      prefElem.setAttribute("value", (String) preferences.get(pref));
      emptyStateElement.appendChild(prefElem);
    }

    for (int i = 0; i < messages.size(); i++) {
      String message = (String) messages.get(i);
      Element messElem = doc.createElement("message");
      CDATASection data = doc.createCDATASection(message);
      messElem.appendChild(data);
      emptyStateElement.appendChild(messElem);
    }
  }
Ejemplo n.º 6
0
 public Boolean getBooleanBody(Boolean def) {
   if (body == null) {
     return def;
   } else {
     return Boolean.valueOf(body);
   }
 }
Ejemplo n.º 7
0
 public Boolean getBooleanAttribute(String name, Boolean def) {
   String value = attributes.getProperty(name);
   if (value == null) {
     return def;
   } else {
     return Boolean.valueOf(value);
   }
 }
Ejemplo n.º 8
0
  private Element generateGraphicsNode(Document doc, ClassGraphics gr) {

    Element graphicsEl = doc.createElement(EL_GRAPHICS);

    Element bounds = doc.createElement(EL_BOUNDS);
    graphicsEl.appendChild(bounds);
    bounds.setAttribute(ATR_X, Integer.toString(gr.getBoundX()));
    bounds.setAttribute(ATR_Y, Integer.toString(gr.getBoundY()));
    bounds.setAttribute(ATR_WIDTH, Integer.toString(gr.getBoundWidth()));
    bounds.setAttribute(ATR_HEIGHT, Integer.toString(gr.getBoundHeight()));

    for (Shape shape : gr.getShapes()) {

      if (shape instanceof Rect) {
        Rect rect = (Rect) shape;
        Element rectEl = doc.createElement(EL_RECT);
        graphicsEl.appendChild(rectEl);
        rectEl.setAttribute(ATR_X, Integer.toString(rect.getX()));
        rectEl.setAttribute(ATR_Y, Integer.toString(rect.getY()));
        rectEl.setAttribute(ATR_WIDTH, Integer.toString(rect.getWidth()));
        rectEl.setAttribute(ATR_HEIGHT, Integer.toString(rect.getHeight()));
        rectEl.setAttribute(ATR_COLOUR, Integer.toString(rect.getColor().getRGB()));
        rectEl.setAttribute(ATR_FILLED, Boolean.toString(rect.isFilled()));
        rectEl.setAttribute(ATR_FIXED, Boolean.toString(rect.isFixed()));
        rectEl.setAttribute(ATR_STROKE, Float.toString(rect.getStroke().getLineWidth()));
        rectEl.setAttribute(ATR_LINETYPE, Float.toString(rect.getLineType()));
        rectEl.setAttribute(ATR_TRANSPARENCY, Integer.toString(rect.getTransparency()));
      } else if (shape instanceof Text) {
        Text text = (Text) shape;
        Element textEl = doc.createElement(EL_TEXT);
        textEl.setAttribute(ATR_STRING, text.getText());
        textEl.setAttribute(ATR_X, Integer.toString(text.getX()));
        textEl.setAttribute(ATR_Y, Integer.toString(text.getY()));
        textEl.setAttribute(ATR_FONTNAME, text.getFont().getName());
        textEl.setAttribute(ATR_FONTSIZE, Integer.toString(text.getFont().getSize()));
        textEl.setAttribute(ATR_FONTSTYLE, Integer.toString(text.getFont().getStyle()));
        textEl.setAttribute(ATR_TRANSPARENCY, Integer.toString(text.getTransparency()));
        textEl.setAttribute(ATR_COLOUR, Integer.toString(text.getColor().getRGB()));
        graphicsEl.appendChild(textEl);
      } // TODO handle the rest of shapes
    }

    return graphicsEl;
  }
Ejemplo n.º 9
0
  public void doCompare(
      Object value1,
      Object value2,
      List<Object> messages,
      Locale locale,
      ClassLoader loader,
      boolean value2InlineConstant) {
    Boolean success =
        BaseCompare.doRealCompare(
            value1,
            value2,
            this.operator,
            this.type,
            this.format,
            messages,
            locale,
            loader,
            value2InlineConstant);

    if (success != null && success.booleanValue() == false) {
      addMessage(messages, loader, locale);
    }
  }
  public void marshall(
      Class parentType,
      QName elementType,
      ExtensibilityElement extension,
      PrintWriter pw,
      Definition def,
      ExtensionRegistry extReg)
      throws WSDLException {
    SOAPBody soapBody = (SOAPBody) extension;

    if (soapBody != null) {
      String tagName = DOMUtils.getQualifiedValue(SOAPConstants.NS_URI_SOAP, "body", def);

      if (parentType != null && MIMEPart.class.isAssignableFrom(parentType)) {
        pw.print("    ");
      }

      pw.print("        <" + tagName);

      DOMUtils.printAttribute(
          SOAPConstants.ATTR_PARTS, StringUtils.getNMTokens(soapBody.getParts()), pw);
      DOMUtils.printAttribute(SOAPConstants.ATTR_USE, soapBody.getUse(), pw);
      DOMUtils.printAttribute(
          SOAPConstants.ATTR_ENCODING_STYLE,
          StringUtils.getNMTokens(soapBody.getEncodingStyles()),
          pw);
      DOMUtils.printAttribute(Constants.ATTR_NAMESPACE, soapBody.getNamespaceURI(), pw);

      Boolean required = soapBody.getRequired();

      if (required != null) {
        DOMUtils.printQualifiedAttribute(Constants.Q_ATTR_REQUIRED, required.toString(), def, pw);
      }

      pw.println("/>");
    }
  }
Ejemplo n.º 11
0
  static Object getValue(String pname, String pvalue, State state) {
    TYPE_NAME tname = state._hmPVariables.get(new PVAR_NAME(pname))._sRange;

    // TYPE_NAMES are interned so that equality can be tested directly
    // (also helps enforce better type safety)
    if (TYPE_NAME.INT_TYPE.equals(tname)) {
      return Integer.valueOf(pvalue);
    }

    if (TYPE_NAME.BOOL_TYPE.equals(tname)) {
      return Boolean.valueOf(pvalue);
    }

    if (TYPE_NAME.REAL_TYPE.equals(tname)) {
      return Double.valueOf(pvalue);
    }

    if (state._hmObject2Consts.containsKey(tname)) {
      return new OBJECT_VAL(pvalue);
      // for( LCONST lc : state._hmObject2Consts.get(tname)) {
      //	if ( lc.toString().equals(pvalue)) {
      //		return lc;
      //	}
      // }
    }

    if (state._hmTypes.containsKey(tname)) {
      return new ENUM_VAL(pvalue);
      // if ( state._hmTypes.get(tname) instanceof ENUM_TYPE_DEF ) {
      //	ENUM_TYPE_DEF etype = (ENUM_TYPE_DEF)state._hmTypes.get(tname);
      //	for ( ENUM_VAL ev : etype._alPossibleValues) {
      //		if ( ev.toString().equals(pvalue)) {
      //			return ev;
      //		}
      //	}
      // }
    }

    return null;
  }
Ejemplo n.º 12
0
  // read enemy launchers and their missiles form XML
  protected void readEnemyLaunchers() {
    NodeList launchers = root.getElementsByTagName("launcher");

    for (int i = 0; i < launchers.getLength(); i++) {
      Element tempLauncher = (Element) launchers.item(i);

      String idLauncher = tempLauncher.getAttribute("id");
      boolean isHidden = Boolean.parseBoolean(tempLauncher.getAttribute("isHidden"));

      // add to the war
      war.addEnemyLauncher(idLauncher, isHidden);
      IdGenerator.updateEnemyLauncherId(idLauncher);

      NodeList missiles = tempLauncher.getElementsByTagName("missile");

      // read all missiles
      readMissilesForGivenLauncher(missiles, idLauncher);
    }

    // update the id's in the war
    IdGenerator.updateFinalEnemyMissileId();
    IdGenerator.updateFinalEnemyLauncherId();
  }
Ejemplo n.º 13
0
  public void parseXML(Node rootNode) {
    try {
      NumberFormat nf = WLPNumberFormat.getInstance();
      NamedNodeMap attrs = rootNode.getAttributes();
      if (attrs != null) {
        Node nameNode = attrs.getNamedItem(nameTag);
        if (nameNode != null) {
          name = nameNode.getTextContent().trim();
        }
        Node guidNode = attrs.getNamedItem(guidTag);
        if (guidNode != null) {
          guid = guidNode.getTextContent().trim();
        }
      }

      Node mergedNode = XmlHelper.getChildNode(rootNode, mergedTag);
      if (mergedNode != null) {
        merged = Boolean.parseBoolean(mergedNode.getTextContent().trim());
      }

      Node durationNode = XmlHelper.getChildNode(rootNode, durationTag);
      if (durationNode != null) {
        duration = nf.parse(durationNode.getTextContent().trim()).doubleValue();
      }

      Node activeDurationNode = XmlHelper.getChildNode(rootNode, activeDurationTag);
      if (activeDurationNode != null) {
        activeDuration = nf.parse(activeDurationNode.getTextContent().trim()).doubleValue();
      }

      Node numMobsNode = XmlHelper.getChildNode(rootNode, numMobsTag);
      if (numMobsNode != null) {
        numMobs = Integer.parseInt(numMobsNode.getTextContent().trim());
      }

      Node totalDamageNode = XmlHelper.getChildNode(rootNode, totalDamageTag);
      if (totalDamageNode != null) {
        totalDamage = Long.parseLong(totalDamageNode.getTextContent().trim());
      }

      Node victimNode = XmlHelper.getChildNode(rootNode, victimTag);
      if (victimNode != null) {
        Node victimFightparticipantNode =
            XmlHelper.getChildNode(victimNode, XMLFightParticipant.fightParticipantTag);
        if (victimFightparticipantNode != null) {
          xmlVictim = new XMLFightParticipant();
          xmlVictim.parseXML(victimFightparticipantNode);
        }
      }
      List<Node> fightParticipantNodes =
          XmlHelper.getChildNodes(rootNode, XMLFightParticipant.fightParticipantTag);
      fightParticipants = new ArrayList<XMLFightParticipant>();
      for (Node partNode : fightParticipantNodes) {
        if (partNode != null) {
          XMLFightParticipant xmlPart = new XMLFightParticipant();
          xmlPart.parseXML(partNode);
          fightParticipants.add(xmlPart);
        }
      }
    } catch (ParseException ex) {
      throw new NumberFormatException();
    }
  }
Ejemplo n.º 14
0
 /**
  * Gets the XRI authority isEscrow flag. If the flag was never set, this method would return the
  * default (false) value.
  */
 public boolean getIsEscrow() {
   if (isEscrow == null) return false;
   return isEscrow.booleanValue();
 }
Ejemplo n.º 15
0
 /** Sets the XRI authority isEscrow flag */
 public void setIsEscrow(boolean isEscrow) {
   this.isEscrow = Boolean.valueOf(isEscrow);
 }
Ejemplo n.º 16
0
 /**
  * Gets the XRI authority isContact flag. If the flag was never set, this method returns the
  * default value (false).
  */
 public boolean getIsContact() {
   if (isContact == null) return false;
   return isContact.booleanValue();
 }
Ejemplo n.º 17
0
 /** Sets the XRI authority isContact flag */
 public void setIsContact(boolean isContact) {
   this.isContact = Boolean.valueOf(isContact);
 }
Ejemplo n.º 18
0
 /**
  * Returns whether an XMLA request should return invisible members.
  *
  * <p>According to the XMLA spec, it should not. But we allow the client to specify different
  * behavior. In particular, the olap4j driver for XMLA may need to access invisible members.
  *
  * <p>Returns true if the EmitInvisibleMembers property is specified and equal to "true".
  *
  * @param request XMLA request
  * @return Whether to return invisible members
  */
 public static boolean shouldEmitInvisibleMembers(XmlaRequest request) {
   final String value =
       request.getProperties().get(PropertyDefinition.EmitInvisibleMembers.name());
   return Boolean.parseBoolean(value);
 }
Ejemplo n.º 19
0
  /**
   * Converts the <code>EppXriAuthority</code> object into an XML element
   *
   * @param doc the XML <code>Document</code> object
   * @param tag the tag/element name for the <code>EppXriAuthority</code> object
   * @return an <code>Element</code> object
   */
  public Element toXML(Document doc, String tag) {
    Element elm;
    Element body = EppUtil.createElementNS(doc, "xriAU", tag);
    boolean isCreate = tag.equals("create");

    // the order of the tags for create is:
    //
    // authId/isEscrow/isContact/escrowAgent/contactAgent/socialData/authInfo
    //
    // the order of the tags for info is
    //
    // authId/isEscrow/isContact/escrowAgent/contactAgent/
    // roid/status/socialData/trustee/ref/redirect/equivID/canonicalEquivID/
    // sep/iname/inumber/iservice/extension/
    // clID/crID/crDate/upDate/trDate/authInfo
    //

    if (authId != null) {
      elm = doc.createElement("authId");
      elm.appendChild(doc.createTextNode(authId));
      body.appendChild(elm);
    }

    if (isEscrow != null) {
      elm = doc.createElement("isEscrow");
      elm.appendChild(doc.createTextNode(isEscrow.toString()));
      body.appendChild(elm);
    }

    if (isContact != null) {
      elm = doc.createElement("isContact");
      elm.appendChild(doc.createTextNode(isContact.toString()));
      body.appendChild(elm);
    }

    if (escrowAgent != null) {
      body.appendChild(escrowAgent.toXML(doc, "escrowAgent"));
    }

    if (contactAgent != null) {
      body.appendChild(contactAgent.toXML(doc, "contactAgent"));
    }
    if (contactHands != null) {
      for (int i = 0; i < contactHands.size(); i++) {
        EppXriContactData t = (EppXriContactData) contactHands.elementAt(i);
        body.appendChild(t.toXML(doc, "contactId"));
      }
    }
    if (isCreate) {
      if (socialData != null) {
        body.appendChild(socialData.toXML(doc, "socialData"));
      }
      if (authInfo != null) {
        body.appendChild(authInfo.toXML(doc, "authInfo"));
      }

      return body;
    }
    if (roid != null) {
      elm = doc.createElement("roid");
      elm.appendChild(doc.createTextNode(roid));
      body.appendChild(elm);
    }
    if (status != null) {
      for (int i = 0; i < status.size(); i++) {
        EppStatus s = (EppStatus) status.elementAt(i);
        body.appendChild(s.toXML(doc, "status"));
      }
    }
    if (socialData != null) {
      body.appendChild(socialData.toXML(doc, "socialData"));
    }
    if (trustee != null) {
      for (int i = 0; i < trustee.size(); i++) {
        EppXriTrustee t = (EppXriTrustee) trustee.elementAt(i);
        body.appendChild(t.toXML(doc, "trustee"));
      }
    }
    if (ref != null) {
      for (int i = 0; i < ref.size(); i++) {
        EppXriRef t = (EppXriRef) ref.elementAt(i);
        body.appendChild(t.toXML(doc, "ref"));
      }
    }
    if (redirect != null) {
      for (int i = 0; i < redirect.size(); i++) {
        EppXriURI t = (EppXriURI) redirect.elementAt(i);
        body.appendChild(t.toXML(doc, "redirect"));
      }
    }
    if (equivIDs != null) {
      for (int i = 0; i < equivIDs.size(); i++) {
        EppXriSynonym id = (EppXriSynonym) equivIDs.elementAt(i);
        body.appendChild(id.toXML(doc, "equivID"));
      }
    }
    if (canonicalEquivID != null) {
      elm = doc.createElement("canonicalEquivID");
      elm.appendChild(doc.createTextNode(canonicalEquivID));
      body.appendChild(elm);
    }
    if (sep != null) {
      for (int i = 0; i < sep.size(); i++) {
        EppXriServiceEndpoint t = (EppXriServiceEndpoint) sep.elementAt(i);
        body.appendChild(t.toXML(doc, "sep"));
      }
    }
    if (iname != null) {
      for (int i = 0; i < iname.size(); i++) {
        String s = (String) iname.elementAt(i);
        elm = doc.createElement("iname");
        elm.appendChild(doc.createTextNode(s));
        body.appendChild(elm);
      }
    }
    if (inumber != null) {
      for (int i = 0; i < inumber.size(); i++) {
        EppXriNumberAttribute xin = (EppXriNumberAttribute) inumber.elementAt(i);
        body.appendChild(xin.toXML(doc, "inumber"));
      }
    }
    if (iservice != null) {
      for (int i = 0; i < iservice.size(); i++) {
        String s = (String) iservice.elementAt(i);
        elm = doc.createElement("iservice");
        elm.appendChild(doc.createTextNode(s));
        body.appendChild(elm);
      }
    }
    if (extension != null) {
      elm = doc.createElement("extension");
      elm.appendChild(doc.createTextNode(extension));
      body.appendChild(elm);
    }

    toXMLCommon(doc, body);

    return body;
  }
Ejemplo n.º 20
0
  private void processRootNode(Session session, Node node, HashMap additionalInformation) {

    if ((node == null) || (session == null)) {
      MessageUtils.showMessage("Invalid session file: root node not found");
      return;
    }

    String nodeName = node.getNodeName();
    if (!(nodeName.equalsIgnoreCase(SessionElement.GLOBAL.getText())
        || nodeName.equalsIgnoreCase(SessionElement.SESSION.getText()))) {
      MessageUtils.showMessage(
          "Session files must begin with a \"Global\" or \"Session\" element.  Found: " + nodeName);
    }
    process(session, node, additionalInformation);

    Element element = (Element) node;

    // Load the genome, which can be an ID, or a path or URL to a .genome or indexed fasta file.
    String genomeId = getAttribute(element, SessionAttribute.GENOME.getText());
    if (genomeId != null && genomeId.length() > 0) {
      if (genomeId.equals(GenomeManager.getInstance().getGenomeId())) {
        // We don't have to reload the genome, but the gene track for the current genome should be
        // restored.
        Genome genome = GenomeManager.getInstance().getCurrentGenome();
        IGV.getInstance().setGenomeTracks(genome.getGeneTrack());
      } else {
        // Selecting a genome will actually "reset" the session so we have to
        // save the path and restore it.
        String sessionPath = session.getPath();
        if (IGV.getInstance().getGenomeIds().contains(genomeId)) {
          IGV.getInstance().selectGenomeFromList(genomeId);
        } else {
          String genomePath = genomeId;
          if (!ParsingUtils.pathExists(genomePath)) {
            genomePath = FileUtils.getAbsolutePath(genomeId, session.getPath());
          }
          if (ParsingUtils.pathExists(genomePath)) {
            try {
              IGV.getInstance().loadGenome(genomePath, null);
            } catch (IOException e) {
              throw new RuntimeException("Error loading genome: " + genomeId);
            }
          } else {
            MessageUtils.showMessage("Warning: Could not locate genome: " + genomeId);
          }
        }
        session.setPath(sessionPath);
      }
    }

    session.setLocus(getAttribute(element, SessionAttribute.LOCUS.getText()));
    session.setGroupTracksBy(getAttribute(element, SessionAttribute.GROUP_TRACKS_BY.getText()));

    String removeEmptyTracks = getAttribute(element, "removeEmptyTracks");
    if (removeEmptyTracks != null) {
      try {
        Boolean b = Boolean.parseBoolean(removeEmptyTracks);
        session.setRemoveEmptyPanels(b);
      } catch (Exception e) {
        log.error("Error parsing removeEmptyTracks string: " + removeEmptyTracks, e);
      }
    }

    String versionString = getAttribute(element, SessionAttribute.VERSION.getText());
    try {
      version = Integer.parseInt(versionString);
    } catch (NumberFormatException e) {
      log.error("Non integer version number in session file: " + versionString);
    }
    session.setVersion(version);

    NodeList elements = element.getChildNodes();
    process(session, elements, additionalInformation);

    // ReferenceFrame.getInstance().invalidateLocationScale();
  }
Ejemplo n.º 21
0
  protected static XmlConfigurator parse(InputStream stream, Boolean validate)
      throws java.io.IOException {
    /**
     * CAUTION: crappy code ahead ! I (bela) am not an XML expert, so the code below is pretty
     * amateurish... But it seems to work, and it is executed only on startup, so no perf loss on
     * the critical path. If somebody wants to improve this, please be my guest.
     */
    try {
      DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
      boolean validation = false;
      String tmp = Util.getProperty(new String[] {Global.XML_VALIDATION}, null, null, false, null);
      if (tmp != null) {
        validation = Boolean.valueOf(tmp).booleanValue();
      } else if (validate != null) {
        validation = validate.booleanValue();
      }
      factory.setValidating(validation);
      factory.setNamespaceAware(validation);
      if (validation) {
        factory.setAttribute(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA);
      }

      DocumentBuilder builder = factory.newDocumentBuilder();
      builder.setEntityResolver(
          new EntityResolver() {

            public InputSource resolveEntity(String publicId, String systemId) throws IOException {
              if (systemId != null
                  && systemId.startsWith("http://www.jgroups.org/schema/JGroups-")) {
                String schemaName = systemId.substring("http://www.jgroups.org/".length());
                InputStream schemaIs = getAsInputStreamFromClassLoader(schemaName);
                if (schemaIs == null) {
                  throw new IOException("Schema not found from classloader: " + schemaName);
                }
                InputSource source = new InputSource(schemaIs);
                source.setPublicId(publicId);
                source.setSystemId(systemId);
                return source;
              }
              return null;
            }
          });
      // Use AtomicReference to allow make variable final, not for atomicity
      // We store only last exception
      final AtomicReference<SAXParseException> exceptionRef =
          new AtomicReference<SAXParseException>();
      builder.setErrorHandler(
          new ErrorHandler() {

            public void warning(SAXParseException exception) throws SAXException {
              log.warn("Warning during parse", exception);
            }

            public void fatalError(SAXParseException exception) throws SAXException {
              exceptionRef.set(exception);
            }

            public void error(SAXParseException exception) throws SAXException {
              exceptionRef.set(exception);
            }
          });
      Document document = builder.parse(stream);
      if (exceptionRef.get() != null) {
        throw exceptionRef.get();
      }

      // The root element of the document should be the "config" element,
      // but the parser(Element) method checks this so a check is not
      // needed here.
      Element configElement = document.getDocumentElement();
      return parse(configElement);
    } catch (Exception x) {
      throw new IOException(Util.getMessage("ParseError", x.getLocalizedMessage()));
    }
  }
Ejemplo n.º 22
0
  private PackageClass parseClass(Element classNode) {
    PackageClass newClass = new PackageClass();
    _package.getClasses().add(newClass);

    newClass.setComponentType(PackageClass.ComponentType.getType(classNode.getAttribute(ATR_TYPE)));
    newClass.setStatic(Boolean.parseBoolean(classNode.getAttribute(ATR_STATIC)));
    newClass.setName(getElementByName(classNode, EL_NAME).getTextContent());
    final String source = getElementStringByName(classNode, EL_FILE);
    if (source != null) {
      newClass.setSource(source);
    }
    newClass.setTarget(getElementStringByName(classNode, EL_EXTENDS));
    newClass.setDescription(getElementByName(classNode, EL_DESCRIPTION).getTextContent());
    newClass.setIcon(getElementByName(classNode, EL_ICON).getTextContent());

    // parse all variables declared in the corresponding specification
    if (newClass.getComponentType().hasSpec()) {
      final String newClassName = newClass.getName();
      try {
        switch (RuntimeProperties.getSpecParserKind()) {
          case REGEXP:
            {
              ClassList classList = new ClassList();
              SpecParser.parseSpecClass(newClassName, getWorkingDir(), classList);
              newClass.setSpecFields(classList.getType(newClassName).getFields());
              break;
            }
          case ANTLR:
            {
              if (specificationLoader == null) {
                specificationLoader =
                    new SpecificationLoader(new PackageSpecSourceProvider(_package), null);
              }
              final AnnotatedClass annotatedClass =
                  specificationLoader.getSpecification(newClassName);
              newClass.setSpecFields(annotatedClass.getFields());
              break;
            }
          default:
            throw new IllegalStateException("Undefined specification language parser");
        }
      } catch (SpecParseException e) {
        final String msg = "Unable to parse the specification of class " + newClassName;
        logger.error(msg, e);
        collector.collectDiagnostic(msg + "\nReason: " + e.getMessage() + "\nLine: " + e.getLine());
      }
    }

    // Graphics
    Element grNode = getElementByName(classNode, EL_GRAPHICS);
    newClass.addGraphics(
        getGraphicsParser().parse(grNode/*, newClass.getComponentType() == ComponentType.REL*/ ));

    Element painter;
    if ((painter = getElementByName(grNode, EL_PAINTER)) != null) {
      newClass.setPainterName(painter.getTextContent());
    }

    // Ports
    NodeList ports = classNode.getElementsByTagName(EL_PORT);
    for (int i = 0; i < ports.getLength(); i++) {
      parsePort(newClass, (Element) ports.item(i));
    }

    // Fields
    NodeList fields = classNode.getElementsByTagName(EL_FIELD);
    for (int i = 0; i < fields.getLength(); i++) {
      parseField(newClass, (Element) fields.item(i));
    }

    return newClass;
  }
Ejemplo n.º 23
0
  private void parseField(PackageClass newClass, Element fieldNode) {
    String name = fieldNode.getAttribute(ATR_NAME);
    String type = fieldNode.getAttribute(ATR_TYPE);

    ClassField newField;

    if (newClass.getComponentType().hasSpec()) {
      if (name.indexOf(".") > -1) {
        // TODO - temporarily do not dig into hierarchy
        int idx = name.indexOf(".");
        String root = name.substring(0, idx);

        if (newClass.getSpecField(root) == null) {
          collector.collectDiagnostic(
              "Field "
                  + root
                  + " in class "
                  + newClass.getName()
                  + " is not declared in the specification, variable "
                  + type
                  + " "
                  + name
                  + " ignored ");
          return;
        }

        newField = new ClassField(name, type);
        newClass.addSpecField(newField);
      } else {
        newField = newClass.getSpecField(name);

        if (newField == null) {

          collector.collectDiagnostic(
              "Field "
                  + type
                  + " "
                  + name
                  + " in class "
                  + newClass.getName()
                  + " is not declared in the specification");
          return;
        } else if (!newField.getType().equals(type)) {

          collector.collectDiagnostic(
              "Field "
                  + type
                  + " "
                  + name
                  + " in class "
                  + newClass.getName()
                  + " does not match the field declared in the specification: "
                  + newField.getType()
                  + " "
                  + newField.getName());
          return;
        }
      }
    } else {
      newField = new ClassField(name, type);
      newClass.addSpecField(newField);
    }

    newField.setValue(fieldNode.hasAttribute(ATR_VALUE) ? fieldNode.getAttribute(ATR_VALUE) : null);
    newField.setDescription(fieldNode.getAttribute(ATR_DESCRIPTION));
    newField.setHidden(Boolean.parseBoolean(fieldNode.getAttribute(ATR_HIDDEN)));

    String nature = fieldNode.getAttribute(ATR_NATURE);
    if ("input".equals(nature)) newField.setInput(true);
    else if ("goal".equals(nature)) newField.setGoal(true);

    newClass.addField(newField);

    Element gr;
    // known
    if ((gr = getElementByName(fieldNode, EL_KNOWN)) != null
        && (gr = getElementByName(gr, EL_GRAPHICS)) != null) {
      newField.setKnownGraphics(getGraphicsParser().parse(gr));
    }
    // default
    if ((gr = getElementByName(fieldNode, EL_DEFAULT)) != null
        && (gr = getElementByName(gr, EL_GRAPHICS)) != null) {
      newField.setDefaultGraphics(getGraphicsParser().parse(gr));
    }
  }
Ejemplo n.º 24
0
  private void parsePort(PackageClass newClass, Element portNode) {
    String name = portNode.getAttribute(ATR_NAME);
    String type = portNode.getAttribute(ATR_TYPE);
    String x = portNode.getAttribute(ATR_X);
    String y = portNode.getAttribute(ATR_Y);
    String portConnection = portNode.getAttribute(ATR_PORT_CONNECTION);
    String strict = portNode.getAttribute(ATR_STRICT);
    String multi = portNode.getAttribute(ATR_MULTI);

    ClassField cf = newClass.getSpecField(name);

    if (newClass.getComponentType().hasSpec()) {

      if (name.indexOf(".") > -1) {
        // TODO - temporarily do not dig into hierarchy
        int idx = name.indexOf(".");
        String root = name.substring(0, idx);

        if (newClass.getSpecField(root) == null) {
          collector.collectDiagnostic(
              "Field "
                  + root
                  + " in class "
                  + newClass.getName()
                  + " is not declared in the specification, variable "
                  + type
                  + " "
                  + name
                  + " ignored ");
          return;
        }

        newClass.addSpecField(new ClassField(name, type));
      } else if (!TypeUtil.TYPE_THIS.equalsIgnoreCase(name)) {
        if (cf == null) {

          collector.collectDiagnostic(
              "Port "
                  + type
                  + " "
                  + name
                  + " in class "
                  + newClass.getName()
                  + " does not have the corresponding field in the specification");
        } else if (!cf.getType().equals(type)
            // type may be declared as "alias", however cf.getType() returns e.g. "double[]", ignore
            // it
            && !(cf.isAlias() && TypeUtil.TYPE_ALIAS.equals(type))) {

          collector.collectDiagnostic(
              "Port "
                  + type
                  + " "
                  + name
                  + " in class "
                  + newClass.getName()
                  + " does not match the field declared in the specification: "
                  + cf.getType()
                  + " "
                  + cf.getName());
        }
      }
    }

    Port newPort =
        new Port(
            name,
            type,
            Integer.parseInt(x),
            Integer.parseInt(y),
            portConnection,
            Boolean.parseBoolean(strict),
            Boolean.parseBoolean(multi));

    if (portNode.hasAttribute(ATR_ID)) newPort.setId(portNode.getAttribute(ATR_ID));

    Element gr;
    // open
    if ((gr = getElementByName(portNode, EL_OPEN)) != null
        && (gr = getElementByName(gr, EL_GRAPHICS)) != null) {
      newPort.setOpenGraphics(getGraphicsParser().parse(gr));
    }

    // closed
    if ((gr = getElementByName(portNode, EL_CLOSED)) != null
        && (gr = getElementByName(gr, EL_GRAPHICS)) != null) {
      newPort.setClosedGraphics(getGraphicsParser().parse(gr));
    }

    newClass.addPort(newPort);
  }
Ejemplo n.º 25
0
 private boolean isShapeFixed(Element shape) {
   return Boolean.parseBoolean(shape.getAttribute(ATR_FIXED));
 }
Ejemplo n.º 26
0
    private ClassGraphics parse(Element grNode /*, boolean isRelation*/) {
      ClassGraphics newGraphics = new ClassGraphics();
      newGraphics.setShowFields(Boolean.parseBoolean(grNode.getAttribute(ATR_SHOW_FIELDS)));
      // newGraphics.setRelation( isRelation );

      NodeList list = grNode.getChildNodes();
      for (int k = 0; k < list.getLength(); k++) {
        if (list.item(k).getNodeType() != Node.ELEMENT_NODE) continue;
        Element node = (Element) list.item(k);
        String nodeName = node.getNodeName();

        Shape shape = null;
        if (EL_BOUNDS.equals(nodeName)) {
          Dim dim = getDim(node);
          newGraphics.setBounds(dim.x, dim.y, dim.width, dim.height);
          continue;
        } else if (EL_LINE.equals(nodeName)) {

          shape = makeLine(node, newGraphics);

        } else if (EL_RECT.equals(nodeName)) {

          Dim dim = getDim(node);
          Lineprops lp = getLineProps(node);
          shape =
              new Rect(
                  dim.x,
                  dim.y,
                  dim.width,
                  dim.height,
                  getColor(node),
                  isShapeFilled(node),
                  lp.strokeWidth,
                  lp.lineType);

        } else if (EL_OVAL.equals(nodeName)) {

          Dim dim = getDim(node);
          Lineprops lp = getLineProps(node);
          shape =
              new Oval(
                  dim.x,
                  dim.y,
                  dim.width,
                  dim.height,
                  getColor(node),
                  isShapeFilled(node),
                  lp.strokeWidth,
                  lp.lineType);

        } else if (EL_ARC.equals(nodeName)) {

          Dim dim = getDim(node);
          Lineprops lp = getLineProps(node);
          int startAngle = Integer.parseInt(node.getAttribute(ATR_START_ANGLE));
          int arcAngle = Integer.parseInt(node.getAttribute(ATR_ARC_ANGLE));
          shape =
              new Arc(
                  dim.x,
                  dim.y,
                  dim.width,
                  dim.height,
                  startAngle,
                  arcAngle,
                  getColor(node),
                  isShapeFilled(node),
                  lp.strokeWidth,
                  lp.lineType);

        } else if (EL_POLYGON.equals(nodeName)) {
          Lineprops lp = getLineProps(node);

          Polygon polygon =
              new Polygon(getColor(node), isShapeFilled(node), lp.strokeWidth, lp.lineType);

          // points
          NodeList points = node.getElementsByTagName(EL_POINT);
          int pointCount = points.getLength();
          // arrays of polygon points
          int[] xs = new int[pointCount];
          int[] ys = new int[pointCount];
          // arrays of FIXED information about polygon points
          int[] fxs = new int[pointCount];
          int[] fys = new int[pointCount];
          int width = newGraphics.getBoundWidth();
          int height = newGraphics.getBoundHeight();

          for (int j = 0; j < pointCount; j++) {
            FixedCoords fc = getFixedCoords((Element) points.item(j), width, height, null);
            xs[j] = fc.x;
            fxs[j] = fc.fx;
            ys[j] = fc.y;
            fys[j] = fc.fy;
          }

          polygon.setPoints(xs, ys, fxs, fys);
          shape = polygon;

        } else if (EL_IMAGE.equals(nodeName)) {

          Dim dim = getDim(node);
          // image path should be relative to the package xml
          String imgPath = node.getAttribute(ATR_PATH);
          String fullPath = FileFuncs.preparePathOS(getWorkingDir() + imgPath);
          shape = new Image(dim.x, dim.y, fullPath, imgPath, isShapeFixed(node));

        } else if (EL_TEXT.equals(nodeName)) {
          shape = makeText(node, newGraphics);
          /*
           * if (str.equals("*self")) newText.name = "self"; else if
           * (str.equals("*selfWithName")) newText.name = "selfName";
           */
        }

        if (shape != null) newGraphics.addShape(shape);
      }

      return newGraphics;
    }