Package org.jdom

Examples of org.jdom.Element


  private Element matchConfigByAttribute(Element e, String attributeName) {
    matchCall++;
    if (e.getContentSize()>0) {
      java.util.List ec = e.getChildren();
      for (int i=0; i<ec.size(); i++) {
        Element e1 = (Element)ec.get(i);
        if (e1.getName().equals(getType())) {
          if (e1.getAttribute(attributeName).getValue().equals(getName())) {
            return e1;
          }
          else {
            e1 = matchConfigByAttribute(e1,attributeName);
            if (e1 != null) {
              if (e1.getName().equals(getType())) {
                if (e1.getAttribute(attributeName).getValue().equals(getName())) {
                  return e1;
                }
              }
            }
          }
        }
        else {
          e1 = matchConfigByAttribute(e1, attributeName);
          if (e1 != null) {
            if (e1.getName().equals(getType())) {
              if (e1.getAttribute(attributeName).getValue().equals(getName())) {
                return e1;
              }
            }
          }
        }
View Full Code Here


    // Just to be safe, we'll remove the DataArea message object if one exists..
    // We're only going to want to re-add an empty DataArea if it had one to begin
    // with (Provides).  In the case of "Responses" there won't be one so we won't
    // want to add one.
    Element replyDataArea = replyDoc.getRootElement().getChild(DATA_AREA);
    boolean needsDataArea = false;
    if (replyDataArea != null) {
      needsDataArea = true;
      replyDoc.getRootElement().removeChild(DATA_AREA);
    }

    // Build the reply document as if there were no errors.
    String strReplyDoc = buildReplyDocument(senderControlArea, replyDoc);
    XMLOutputter xmlOut = new XMLOutputter();

    // Now add the errors into the control area
    Result aResult = new Result();

    Document localReplyDoc = null;
    try {
      XmlDocumentReader xmlReader = new XmlDocumentReader();
      localReplyDoc = xmlReader.initializeDocument(new ByteArrayInputStream(strReplyDoc.getBytes()), false);
      Element replyControlArea = getControlArea(localReplyDoc.getRootElement());
      localReplyDoc.getRootElement().removeContent(replyControlArea);
      Element eResult = replyControlArea.getChild("Result");
      aResult.buildObjectFromInput(eResult);
      aResult.setStatus("failure");

      for (int i=0; i<errors.size(); i++) {
        org.openeai.moa.objects.resources.Error anError =
          (org.openeai.moa.objects.resources.Error)errors.get(i);
        aResult.addError(anError);
      }

      replyControlArea.removeChild("Result");
      replyControlArea.addContent((Element)aResult.buildOutputFromObject());
      localReplyDoc.getRootElement().addContent(replyControlArea);
      if (needsDataArea) {
        localReplyDoc.getRootElement().addContent(new Element(DATA_AREA));
      }
      return xmlOut.outputString(localReplyDoc);
    }
    catch (Exception e) {
      // We'll just have to return the replyDoc after we've added our error
View Full Code Here

    XMLOutputter xmlOut = new XMLOutputter();
    Document localReplyDoc = (Document)replyDoc.clone();

    String msgAction = senderControlArea.getAttribute(MESSAGE_ACTION).getValue();

    Element replyControlArea = getControlArea(localReplyDoc.getRootElement());
    localReplyDoc.getRootElement().removeContent(replyControlArea);

    // A DataArea will only exist for some reply documents,
    // later when we rebuild the reply document, we'll check to see
    // if this element is null before we try to add it back into
    // the document.  We need to do this so when we re-build the document
    // we can add the ControlArea and DataAreas in the proper order...
    Element replyDataArea = localReplyDoc.getRootElement().getChild(DATA_AREA);
    if (replyDataArea != null) {
      localReplyDoc.getRootElement().removeChild(DATA_AREA);
    }

    replyControlArea.removeChild("Result");
    replyControlArea.removeChild("Datetime");
    replyControlArea.removeChild("Sender");

    Result aResult = new Result();

    ProcessedMessageId processedMsgId = new ProcessedMessageId();
    Element eRequestSender = senderControlArea.getChild("Sender");

    processedMsgId.setProducerId(eRequestSender.getChild("MessageId").
      getChild("ProducerId").getText());
    processedMsgId.setSenderAppId(eRequestSender.getChild("MessageId").
      getChild("SenderAppId").getText());
    processedMsgId.setMessageSeq(eRequestSender.getChild("MessageId").
      getChild("MessageSeq").getText());

    aResult.setAction(msgAction);
    aResult.setStatus("success");
    aResult.setProcessedMessageId(processedMsgId);

    // Set the sender element (the replier)
    Sender sender = new Sender();

    MessageId replierMsgId = new MessageId();
    replierMsgId.setProducerId(eRequestSender.getChild("MessageId").
      getChild("ProducerId").getText());
    replierMsgId.setSenderAppId(getAppName());
    replierMsgId.setMessageSeq(eRequestSender.getChild("MessageId").
      getChild("MessageSeq").getText());
    sender.setMessageId(replierMsgId);

    Authentication auth = new Authentication();
    auth.setAuthUserId(getAppName());
    auth.setAuthUserSignature(getAppName());
    sender.setAuthentication(auth);

    Element eSender = null;
    try {
      XmlLayout xmlLayout = (XmlLayout)sender.getOutputLayoutManager("xml");
      sender.setOutputLayoutManager(xmlLayout);
      eSender = (Element)sender.buildOutputFromObject();
    }
    catch (Exception e) {
      logger.fatal("[buildReplyDocument] Exception occurred building an Element from the Sender object.  Exception: " + e.getMessage());
      return xmlOut.outputString(replyDoc);
    }

    // Set the datetime element (for the replier)
    Datetime dt = new Datetime();
    Element eDatetime = null;
    try {
      eDatetime = (Element)dt.buildOutputFromObject();
    }
    catch (Exception e) {
      logger.fatal("[buildReplyDocument] Exception occurred building an Element from the Datetime object.  Exception: " + e.getMessage());
View Full Code Here

      return;
    }
    try {
      XmlDocumentReader xmlReader = new XmlDocumentReader();
      Document objectDoc = xmlReader.initializeDocument(new ByteArrayInputStream(theString.getBytes()), false);
      Element eObject = objectDoc.getRootElement();
      EnterpriseLayoutManager saveInputLManager = null;
      saveInputLManager = getInputLayoutManager();
      EnterpriseLayoutManager xmlInputLayoutManager = getInputLayoutManager("xml");
      if (xmlInputLayoutManager == null) {
        throw new XmlEnterpriseObjectException("Could not find an XML Input Layout Manager for object " + getClass().getName());
View Full Code Here

   * @return          Element the ControlArea element (may be ControlAreaRequest,
   *                  ControlAreaReply or ControlAreaSync depending on the doc)
   */
  protected Element getControlArea(Element root) {
    java.util.List cList = root.getChildren();
    Element retElem = null;
    for (int i=0; i<cList.size(); i++) {
      Element current = (Element)cList.get(i);
      if (current.getName().indexOf("ControlArea") != -1) {
        retElem = current;
      }
    }
    return retElem;
  }
View Full Code Here

      if (inElm == null) {
        throw new XmlEnterpriseObjectException("Couldn't find an XML " +
                                               "Input Layout Manager for " + getClass().getName());
      }
      setOutputLayoutManager(outElm);
      Element eOutput = (Element)buildOutputFromObject();
      setOutputLayoutManager(saveOutElm);

      XmlEnterpriseObject xeo = null;
      String className = this.getClass().getName();
      java.lang.Class obj = java.lang.Class.forName(className);
View Full Code Here

      }

      // Now the Elements.
      java.util.List props = configElement.getChildren();
      for (int i=0; i<props.size(); i++) {
        Element aProp = (Element)props.get(i);
        if (aProp.getName().equals("Commands")) {
          java.util.List defaultAttrs = aProp.getAttributes();
          java.util.List commandElements = aProp.getChildren();
          ArrayList commands = new ArrayList();
          Element eDefaultParms = new Element("DefaultParms");
          // Add default attributes
          for (int l=0; l<defaultAttrs.size(); l++) {
            org.jdom.Attribute anAttr = (org.jdom.Attribute)defaultAttrs.get(l);
            eDefaultParms.setAttribute((org.jdom.Attribute)anAttr.clone());
          }
          // Add default elements
          for (int k=0; k<commandElements.size(); k++) {
            Element eElem = (Element)commandElements.get(k);
            if (eElem.getName().equals("Command")) {
              commands.add(eElem);
            }
            else {
              eDefaultParms.addContent((Element)eElem.clone());
            }
          }
//          java.util.List commands = aProp.getChildren();
          // Instantiate and add a CommandConfig object for each Command element.
          // ...
          for (int j=0; j<commands.size(); j++) {
            Element eCommand = (Element)commands.get(j);
//            CommandConfig aCommandConfig = new CommandConfig(eCommand);
            CommandConfig aCommandConfig = new CommandConfig();
            aCommandConfig.setAppName(getAppName());
            aCommandConfig.setDefaultParms(eDefaultParms);
            aCommandConfig.init(eCommand);
View Full Code Here

   * then it calls the init(Element) method which actually initializes the ConsumerConfig
   * with the information found in the configuration element.
   *
   */
  private void init() throws EnterpriseConfigurationObjectException {
    Element rootElement = getConfigDoc().getRootElement();
    logger.debug("RootElement is: " + rootElement.getName());
    // Find the element specified by producerName in the document
    Element configElement = getConfigElementByAttributeValue(getName(), "name");
    init(configElement);
  }
View Full Code Here

      }

      // Now the Elements.
      java.util.List props = configElement.getChildren();
      for (int i=0; i<props.size(); i++) {
        Element aProp = (Element)props.get(i);
        if (aProp.getName().equals("Schedules")) {
          java.util.List defaultAttrs = aProp.getAttributes();
          java.util.List scheduleElements = aProp.getChildren();
          ArrayList schedules = new ArrayList();
          Element eDefaultParms = new Element("DefaultParms");
          // Add default attributes
          for (int l=0; l<defaultAttrs.size(); l++) {
            org.jdom.Attribute anAttr = (org.jdom.Attribute)defaultAttrs.get(l);
            eDefaultParms.setAttribute((org.jdom.Attribute)anAttr.clone());
          }
          // Add default elements
          for (int k=0; k<scheduleElements.size(); k++) {
            Element eElem = (Element)scheduleElements.get(k);
            if (eElem.getName().equals("Schedule")) {
              logger.debug("ScheduleAppConfig, found a Schedule element.");
              schedules.add(eElem);
            }
            else {
              eDefaultParms.addContent((Element)eElem.clone());
            }
          }
          // Instantiate and add a ScheduleConfig object for each Schedule element.
          // ...
          for (int j=0; j<schedules.size(); j++) {
            Element eSchedule = (Element)schedules.get(j);
            ScheduleConfig aScheduleConfig = new ScheduleConfig();
            aScheduleConfig.setAppName(outterAppName);
            aScheduleConfig.setDefaultParms(eDefaultParms);
            aScheduleConfig.init(eSchedule);
            String scheduleClass = aScheduleConfig.getClassName();
            String scheduleName = aScheduleConfig.getName();
            logger.info("ScheduledAppConfig, adding ScheduleConfig, " + scheduleName);
            addProperty(scheduleName, scheduleClass);
            addScheduleConfig(aScheduleConfig.getName(), aScheduleConfig);
          }
        }
        else if (aProp.getName().equals("ThreadPoolConfig")) {
          setThreadPoolConfig(new ThreadPoolConfig(aProp));
        }
        else if (aProp.getName().equals("ScheduleIdRepository")) {
          String className = aProp.getChild("ObjectClass").getText();
          Element eConfig = aProp.getChild("Configuration");
          AppConfig aConfig = new AppConfig();
          aConfig.setName(getAppName());
          aConfig.init(eConfig);
          java.lang.Class storeClass = java.lang.Class.forName(className);
          ScheduleIdStore store = (ScheduleIdStore)storeClass.newInstance();
View Full Code Here

   * then it calls the init(Element) method which actually initializes the ScheduledAppConfig
   * with the information found in the configuration element.
   *
   */
  private void init() throws EnterpriseConfigurationObjectException {
    Element rootElement = getConfigDoc().getRootElement();
    logger.debug("RootElement is: " + rootElement.getName());
    // Find the element specified by producerName in the document
    Element configElement = getConfigElementByAttributeValue(getName(), "name");
    init(configElement);
  }
View Full Code Here

TOP

Related Classes of org.jdom.Element

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.