Package org.jdom

Examples of org.jdom.Element


  protected boolean isRequired(Element eField) throws EnterpriseLayoutException {
    boolean isRequired = false;    // default
//    if (eField != null && eField.isRootElement() == false && eField.getParent().isRootElement() == false) {
    if (eField != null && eField.isRootElement() == false) {
      String fieldName = eField.getAttribute("name").getValue();
      Element eFormat = eField.getChild("Format");
      if (eFormat == null) {
        throw new EnterpriseLayoutException("The EnterpriseObjects document is invalid." +
                                            "  A Format element is required.  " + fieldName + " doesn't have one!");
      }
      else {
        isRequired = new Boolean(eFormat.getAttribute("required").getValue()).booleanValue();
      }
    }
    return isRequired;
  }
View Full Code Here


      throw new EnterpriseConfigurationObjectException(msg, e);
    }
    try {
      String appName = this.getAppName();
      logger.debug("looking for application named: " + appName);
      Element mainConfigElement =
        getElementByAttributeValue(getConfigDoc().getRootElement(), appName);
      XmlElementLocator locator = new XmlElementLocator();
      Element configElement =
        locator.getElementByAttributeNameValueRecursive(mainConfigElement,
                                                        "name", objectName);
      String className =
        getObjects().get(objectName.toLowerCase()).getClass().getName();
      setObjects(addObject(getObjects(), objectName, className, null,
View Full Code Here

    java.util.List configChildren = eConfig.getChildren();
    logger.debug(getName() + " has " + configChildren.size() +
                 " Configuration children.");
    // Now we'll get a list of all config lists (MessageObjectConfigs, ProducerConfigs, etc.).
    for (int i = 0; i < configChildren.size(); i++) {
      Element eConfig2 = (Element)configChildren.get(i);
      java.util.List configList = eConfig2.getChildren();
      java.util.List defaultAttrs = eConfig2.getAttributes();
      // Now, we need to go through all the Configuration elements and instantiate
      // the appropriate Java Config object for that Config element.  This will be based on
      // the configClassName attribute in the config elements.
      // MessageObjectConfigs/MessageObjectConfig, ProducerConfigs/ProducerConfig, etc.)
      // This is what we'll perform utilizing the thread pool.
      try {
        if (m_useThreads) {
          if (m_threadPool == null) {
            initializeThreadPool("10", "0", "1", false);
          }
          m_threadPool.addJob(new InitConfigsThread(eConfig2.getName(),
                                                    defaultAttrs, configList));
        }
        else {
          new InitConfigsThread(eConfig2.getName(), defaultAttrs,
                                configList).run();
        }
      }
      catch (ThreadPoolException e) {
      }
View Full Code Here

      initializing the ones that need initialized (Logger).
    - After they've been successfully initialized, started etc. add the names
      of the objects to the m_configObjectNames Vector and add the configurable object
      to the m_objects Vector.
    */
    Element rootElement = getConfigDoc().getRootElement();
    Element appElement = getElementByAttributeValue(rootElement, getName());
    Element eConfig = null;
    if (appElement != null) {
      logger.debug("Found app " + getName() + " in " + appElement.getName());
      eConfig = appElement.getChild("Configuration");
      if (eConfig == null) {
        String errMsg =
          "Could not find Configuration information for application '" +
          getName() +
          "' check that the 'messageComponentName' property matches " +
          "what's in the Deployment document.";
        logger.fatal(errMsg);
        throw new EnterpriseConfigurationObjectException(errMsg);
      }

      // determine if we should initialize this AppConfig object using threads or not.
      // default is 'true' (we should use threads).
      Attribute aInitializeUsingThreads =
        eConfig.getAttribute("initializeUsingThreads");
      if (aInitializeUsingThreads != null) {
        String initUsingThreads = aInitializeUsingThreads.getValue();
        logger.debug("initUsingThreads String value: '" + initUsingThreads +
                     "'");
        if (initUsingThreads.equalsIgnoreCase("true") == false &&
View Full Code Here

      m_listName = configListName;
    }

    public void run() {
      ArrayList aConfigObjects = new ArrayList();
      Element eDefaultParms = new Element("DefaultParms");

      if (m_defaultAttrs.size() == 0) {
        logger.debug("No default attributes for this config object.");
      }
      for (int i = 0; i < m_defaultAttrs.size(); i++) {
        org.jdom.Attribute anAttr = (org.jdom.Attribute)m_defaultAttrs.get(i);
        eDefaultParms.setAttribute((org.jdom.Attribute)anAttr.clone());
      }

      for (int j = 0; j < m_configList.size(); j++) {
        Element eConfigObject = (Element)m_configList.get(j);

        // If the name of eConfigObject is the same as m_configList (i.e. - ProducerConfigs/ProducerConfig
        // that will be the configuration element used for the specific object we're configuring
        // Otherwise, we'll add all the "default" configuration information for all configuration objects
        // i.e. - parms that all ProducerConfig objects withing the ProducerConfigs container will use
        // to a separate element that will be used for default values.
        // Then, we'll go through all of those and configure them with default values or
        // config specific values if they over-ride the default values.

        if (eConfigObject.getName().equals(m_listName.substring(0,
                                                                m_listName.length() -
                                                                1))) {
          aConfigObjects.add(eConfigObject);
        }
        else {
          logger.debug("Found a default config element for the '" +
                       eConfigObject.getName() +
                       "' element.  m_listName is: " + m_listName);
          eDefaultParms.addContent((Element)eConfigObject.clone());
        }
      }

      // Now, we're going to instantiate and initialize the object we're configuring (ie a ProducerConfig etc.)
      for (int i = 0; i < aConfigObjects.size(); i++) {
        Element eConfigObject = (Element)aConfigObjects.get(i);
        try {
          if (m_useThreads) {
            if (m_threadPool == null) {
              initializeThreadPool("10", "0", "1", false);
            }
View Full Code Here

      //      m_configElement.setAttribute((org.jdom.Attribute)nameAttr.clone());

      // Now the elements
      java.util.List defaultElementList = m_defaultParms.getChildren();
      for (int i = 0; i < defaultElementList.size(); i++) {
        Element eDefaultParm = (Element)defaultElementList.get(i);
        if (m_configElement.getChild(eDefaultParm.getName()) == null) {
          m_configElement.addContent((Element)eDefaultParm.clone());
        }
      }

      // Instantiate and save the config object
      // LoggerConfig, ProducerConfig, ConsumerConfig, MessageObjectConfig
View Full Code Here

    int propsSize = props.size();
    if (propsSize == 0) {
      keepTrying = false;
    }
    for (int i=0; i<propsSize; i++) {
      Element aProp = (Element)props.get(0);
      props.remove(0);
      if (aProp.getName().equals("Authentication")) {
        // UserId, Signature
        java.util.List auths = aProp.getChildren();
        for (int j=0; j<auths.size(); j++) {
          Element anAuthChild = (Element)auths.get(j);
          String key = anAuthChild.getName();
          String value = anAuthChild.getText();
          logger.debug("Adding " + key + " - " + value);
          addProperty(key, value);
        }
      }
      else if (aProp.getName().equals("PrimedXmlDocuments")) {
        java.util.List docs = aProp.getChildren();
        for (int k=0; k<docs.size(); k++) {
          Element aDoc = (Element)docs.get(k);
          String key, value;
          key = aDoc.getAttribute("type").getValue() + "-" + aDoc.getName();
          value = aDoc.getText();
          logger.debug("Adding " + key + " - " + value);
          addProperty(key, value);
        }
      }
      // NEW ENTERPRISEFIELDS CONFIGURATION START - 8/8
      else if (aProp.getName().equals("EnterpriseObjectDocument")) {
        eoDocUri = aProp.getAttribute("docUri").getValue();

        // new 7/30/2002, changed config document to allow multiple EnterpriseObject.xml
        // documents.  This way, we can break them apart and make each "chunk" smaller
        // this should decrease the time necessary to build an object and make AppConfig
        // initilialization quicker.
        if (enterpriseObjectsDoc == null) {
          if (eoDocUri != null) {
            try {

              //TODO: check for deferInitialization flag.  If True, don't parse the document yet.
              if (deferInitialization == false) {
                logger.debug("EF initialization is NOT deferred, parsing EO docs...");
                XmlDocumentReader xmlReader = new XmlDocumentReader();
                enterpriseObjectsDoc =
                  xmlReader.initializeDocument(eoDocUri,getValidation());
                logger.debug("DONE parsing EO docs.");
              }
              else {
                logger.debug("EnterpriseFields initialization has been deferred (not parsing EO doc).");
              }
               
            }
            catch (XmlDocumentReaderException e) {
              logger.fatal(e.getMessage(), e);
              String msg = "Exception occurred initializing EnterpriseFields object.  Exception: " + e.getMessage();
              logger.fatal(msg);
              throw new EnterpriseConfigurationObjectException(msg, e);
            }
          }
        }
        if (getEnterpriseFields() == null) {
          EnterpriseFields fields = new EnterpriseFields();
          fields.setEnterpriseObjectsUri(eoDocUri);
          fields.setIgnoreMissingFields(new Boolean(aProp.getAttribute("ignoreMissingFields").getValue()).booleanValue());
          fields.setIgnoreValidation(new Boolean(aProp.getAttribute("ignoreValidation").getValue()).booleanValue());
          logger.debug("[MessageObjectConfig] ignoreValidation is " + fields.ignoreValidation());
          fields.setTranslationType(getTranslationType());
          fields.setAppName(getAppName());
//          ObjectDefinitions.APP_NAME = getAppName();
          try {

            //TODO:  check for deferInitialization flag.  If true, don't do this yet.
            if (deferInitialization == false) {
              logger.debug("EnterpriseFields initialization is NOT deferred, initializing EF...");
              fields.init(enterpriseObjectsDoc);
              logger.debug("DONE with EnterpriseFields initialization.");
            }
            else {
              logger.debug("EnterpriseFields initialization has been deferred (not initializing EnterpriseFields).");
            }
           
          }
          catch (EnterpriseFieldException e) {
            String msg = "Exception occurred initializing EnterpriseFields object.  Exception: " + e.getMessage();
            logger.fatal(msg);
            throw new EnterpriseConfigurationObjectException(msg, e);
          }
          setEnterpriseFields(fields);
        }
      }
      // NEW ENTERPRISEFIELDS CONFIGURATION END - 8/8

      // NEW LAYOUT MANAGER CONFIGURATION START - 8/8
      else if (aProp.getName().equals("LayoutManager")) {
        // Build all of the layout manager objects...
        logger.debug("MessageObjectName is " + messageObjectName);

        //TODO:  may have to check deferInitialization flag here also...
//        if (enterpriseObjectsDoc == null && deferInitialization == false) {
        if (eoDocUri == null) {
          String msg = "[MessageObjectConfig] Cannot initialize LayoutManagers until the EnterpriseObjectDocument has been initialized, putting it back on the list";
          logger.warn(msg);
          props.add(aProp);
          continue;
        }
       
        logger.debug("Initializing layout managers...");
        java.util.List lInputLayouts = aProp.getChildren("InputLayout");
        boolean hasXmlLayoutManager = false;
        for (int im=0; im<lInputLayouts.size(); im++) {
          Element eInLayout = (Element)lInputLayouts.get(im);
          String inputLayoutType = eInLayout.getAttribute("type").getValue();
          String inputLayoutName = "";
          if (inputLayoutType.equals("xml")) {
            hasXmlLayoutManager = true;
            Attribute aInLayoutName = eInLayout.getAttribute("name");
            if (aInLayoutName != null) {
              inputLayoutName = aInLayoutName.getValue();
            }
            else {
              String className = getClass().getName();
              inputLayoutName = className.substring(className.lastIndexOf('.') + 1)// Our based element in the XML passed in
            }
          }
          else {
            Attribute aInLayoutName = eInLayout.getAttribute("name");
            if (aInLayoutName != null) {
              inputLayoutName = aInLayoutName.getValue();
            }
            else {
              String msg = "[MessageObjectConfig] Non-XML input layouts must have a name associated with them.";
              logger.fatal(msg);
              throw new EnterpriseConfigurationObjectException(msg);
            }
          }
          String inLayoutClass = eInLayout.getChild("ObjectClass").getText();
          try {
            logger.debug("Instantiating input layout manager: " + inLayoutClass + " for " + inputLayoutName);
            java.lang.Class inLayoutObj = java.lang.Class.forName(inLayoutClass);

            EnterpriseLayoutManager ainElm = (EnterpriseLayoutManager)inLayoutObj.newInstance();

            //TODO: check deferInitialization flag.
//            ainElm.init(messageObjectName, inputLayoutName, enterpriseObjectsDoc);
            if (deferInitialization == false) {
              logger.debug("Layout manager initialization is NOT deferred, initializing input layout manager...");
              ainElm.init(inputLayoutName, enterpriseObjectsDoc);
              logger.debug("DONE initializing input layout manager...");
            }
            else {
              logger.debug("Layout manager initialization has been deferred (input)");
              ainElm.setLayoutManagerName(inputLayoutName);
              ainElm.setEnterpriseObjectsUri(eoDocUri);
            }
           
            addInputLayoutManager(inputLayoutType, ainElm);
            // Set the default input layout manager to the first one in the list.
            if (im == 0) {
              setInputLayoutManager(ainElm);
            }
          }
          catch (Exception e) {
            String msg = "Error initializing Input Layout Manager.  Exception: " + e.getMessage();
            logger.fatal(msg, e);
            throw new EnterpriseConfigurationObjectException(msg, e);
          }
        }
        if (hasXmlLayoutManager == false) {
          // throw an exception
          String msg = "[MessageObjectConfig] Missing XML Input Layout manager.";
          logger.fatal(msg);
          throw new EnterpriseConfigurationObjectException(msg);
        }

        logger.debug("MessageObjectName is " + messageObjectName);
        java.util.List lOutputLayouts = aProp.getChildren("OutputLayout");
        hasXmlLayoutManager = false;
        for (int om=0; om<lOutputLayouts.size(); om++) {
          Element eOutLayout = (Element)lOutputLayouts.get(om);
          String outputLayoutType = eOutLayout.getAttribute("type").getValue();
          String outputLayoutName = "";
          if (outputLayoutType.equals("xml")) {
            hasXmlLayoutManager = true;
            Attribute aOutLayoutName = eOutLayout.getAttribute("name");
            if (aOutLayoutName != null) {
              outputLayoutName = aOutLayoutName.getValue();
            }
            else {
              String className = getClass().getName();
              outputLayoutName =className.substring(className.lastIndexOf('.') + 1)// Our based element in the XML passed in
            }
          }
          else {
            Attribute aOutLayoutName = eOutLayout.getAttribute("name");
            if (aOutLayoutName != null) {
              outputLayoutName = aOutLayoutName.getValue();
            }
            else {
              String msg = "[MessageObjectConfig] Non-XML output layouts must have a name associated with them.";
              logger.fatal(msg);
              throw new EnterpriseConfigurationObjectException(msg);
            }
          }

          String outLayoutClass = eOutLayout.getChild("ObjectClass").getText();
          try {
            logger.debug("Instantiating output layout manager: " + outLayoutClass + " for " + outputLayoutName);
            java.lang.Class outLayoutObj = java.lang.Class.forName(outLayoutClass);

            EnterpriseLayoutManager aoutElm = (EnterpriseLayoutManager)outLayoutObj.newInstance();           
View Full Code Here

      logger.fatal("[PublishSyncError] Error initializing Sync-Error-Sync primed document, could not publish the sync error sync message.");
      logger.fatal(e.getMessage(), e);
      return;
    }

    Element eControlArea = getControlArea(syncErrorDoc.getRootElement());

    Result aResult = new Result();
    ProcessedMessageId processedMsgId = new ProcessedMessageId();

    // Build the dynamic portion of the sync document's control area
    // Our sender information will go in the "Sender" element of the primed
    // document and in the ProcessedMessageId of the Result that gets built
    // Set the sender element

    // Build the ProcessedMessageId Object out of the contents of the
    // application that had the error.
    String messageSequence = Integer.toString(getSyncErrorPublisher().incrementMessageSequence());
    try {
      // processedMsgId is going to be the same as MessageId (built below)
      processedMsgId.setProducerId(getSyncErrorPublisher().getProducerId(null).getId());
      processedMsgId.setSenderAppId(getAppName());
      processedMsgId.setMessageSeq(messageSequence);
    }
    catch (Exception e) {
      logger.fatal("Error building ProcessedMessageId Element in Sync-Error-Sync message!");
      logger.fatal(e.getMessage(), e);
    }

    // This is the control area information relevant to this Gateway
    eControlArea.removeChild("Result");
    eControlArea.removeChild("Datetime");
    eControlArea.removeChild("Sender");

    Sender sender = new Sender();
    MessageId msgId = new MessageId();
    msgId.setProducerId(getSyncErrorPublisher().getProducerId(null).getId());
    msgId.setSenderAppId(getAppName());
    msgId.setMessageSeq(messageSequence);

    sender.setMessageId(msgId);
    Authentication auth = new Authentication();
    auth.setAuthUserId(getAppName());
    sender.setAuthentication(auth);
    Element eSender = null;
    try {
      eSender = (Element)sender.buildOutputFromObject();
    }
    catch (Exception e) {
      logger.fatal("[publishSyncError1] Exception occurred building an Element from the Sender object.  Can't publish Sync error.  Exception: " + e.getMessage());
      logger.fatal(e.getMessage(), e);
      return;
    }

    // Set the datetime element
    Datetime dt = new Datetime();
    Element eDatetime = null;
    try {
      eDatetime = (Element)dt.buildOutputFromObject();
    }
    catch (Exception e) {
      logger.fatal("[publishSyncError1] Exception occurred building an Element from the Datetime object.  Can't publish Sync error.  Exception: " + e.getMessage());
      logger.fatal(e.getMessage(), e);
      return;
    }

    eControlArea.addContent(eSender);
    eControlArea.addContent(eDatetime);

    if (action == null) {
      action = "Unknown";
    }
    aResult.setAction(action);
    aResult.setStatus("failure");
    aResult.setProcessedMessageId(processedMsgId);

    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);
    }

    try {
      Element eResult = (Element)aResult.buildOutputFromObject();
      eControlArea.addContent(eResult);
      syncErrorDoc.getRootElement().removeContent(eControlArea);
      syncErrorDoc.getRootElement().addContent(eControlArea);
      TextMessage syncErrorMessage = getSyncErrorPublisher().createTextMessage();
      XMLOutputter xmlOut = new XMLOutputter();
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

   * then it calls the init(Element) method which actually initializes the MessageObjectConfig
   * with the information found in the configuration element.
   *
   */
  private void init() throws EnterpriseConfigurationObjectException {
    Element rootElement = getConfigDoc().getRootElement();
    logger.debug("RootElement is: " + rootElement.getName());
    logger.debug("Looking for MessageObjectConfig named: " + getName());

    // Find the element specified by objectName 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.