Package org.jdom

Examples of org.jdom.Element


    return getElementByName_internal(e, name);
  }
  private Element getElementByName_internal(Element e, String name) {
    java.util.List eChildren1 = e.getChildren();
    for (int i=0; i<eChildren1.size(); i++) {
      Element e1 = (Element)eChildren1.get(i);

      if (e1.getName().equals(name)) {
        return e1;
      }

      Element e2 = getElementByName_internal(e1, name);
      if (e2 != null) {
        return e2;
      }
    }
View Full Code Here


    }

    // Should be none, for now as everything is specified as attributes.
    java.util.List props = configElement.getChildren();
    for (int i=0; i<props.size(); i++) {
      Element aProp = (Element)props.get(i);
      String key = aProp.getName();
      String value = aProp.getText();
      logger.debug("Adding " + key + " - " + value);
      addProperty(key, value);
    }
  }
View Full Code Here

    return getElementByNameValue_internal(e, name, value);
  }
  private Element getElementByNameValue_internal(Element e, String name, String value) {
    java.util.List eChildren1 = e.getChildren();
    for (int i=0; i<eChildren1.size(); i++) {
      Element e1 = (Element)eChildren1.get(i);

      if (e1.getName().equals(name)) {
        if (e1.getText() != null && e1.getText().trim().equals(value)) {
          return e1;
        }
      }

      Element e2 = getElementByNameValue_internal(e1, name, value);
      if (e2 != null) {
        return e2;
      }
    }
View Full Code Here

   * then it calls the init(Element) method which actually initializes the DbConnectionPoolConfig
   * 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 DbConnectionPoolConfig named: " + getName());
    // Find the element specified by threadPoolName in the document
    Element configElement = getConfigElementByAttributeValue(getName(), "name");
    init(configElement);
  }
View Full Code Here

    return getElementByValue_internal(e, value);
  }
  private Element getElementByValue_internal(Element e, String value) {
    java.util.List eChildren1 = e.getChildren();
    for (int i=0; i<eChildren1.size(); i++) {
      Element e1 = (Element)eChildren1.get(i);

      if (e1.getText() != null && e1.getText().trim().equals(value)) {
        return e1;
      }

      Element e2 = getElementByValue_internal(e1, value);
      if (e2 != null) {
        return e2;
      }
    }
View Full Code Here

      }
    }

    logger.debug("[xmllayout buildOutputFromObject] ObjectName is " + objectName);

    Element eOutput = new Element(objectName);
    Element eLayout = getLayout(getLayoutRoot(), objectName);
    String layoutName = eLayout.getAttribute("name").getValue();
    logger.debug("eLayout is " + layoutName);

    java.util.List lFields = eLayout.getChildren("Field");
    logger.debug("There are " + lFields.size() + " Fields in the " + layoutName + " Layout.");

    XMLOutputter xmlOut = new XMLOutputter();
    for (int i=0; i<lFields.size(); i++) {
      Element eField = (Element)lFields.get(i);
      buildElement(xeo, eOutput, eField, true);
      logger.debug("eOutput is now " + xmlOut.outputString(eOutput));
    }

    logger.debug("XmlLayout - Build Output From Object - Ended Processing.");
View Full Code Here

  public void buildObjectFromInput(Object input, XmlEnterpriseObject xeo)
  throws EnterpriseLayoutException {

    logger.debug("XmlLayout - Build Object From Input - Started Processing.");

    Element eInput = (Element)input;   // Element from an XML document passed in.
    String className = xeo.getClass().getName();
    String objectName = className.substring(className.lastIndexOf('.') + 1)// Our based element in the XML passed in
    logger.debug("ObjectName is " + objectName);

    Element eLayout = getLayout(getLayoutRoot(), objectName);
    String layoutName = eLayout.getAttribute("name").getValue();
    logger.debug("eLayout is " + layoutName);

    java.util.List lFields = eLayout.getChildren("Field");
    logger.debug("There are " + lFields.size() + " Fields in the " + layoutName + " Layout.");

    for (int i=0; i<lFields.size(); i++) {
      Element eField = (Element)lFields.get(i);
      buildObject(xeo, eInput, eField, true);
    }

    logger.debug("XmlLayout - Build Object From Input - Ended Processing.");
  }
View Full Code Here

            obj = getValueFromObject(xeo, getTargetAppName(), fieldName, new Object[] {iParm}, new Class[] {Integer.TYPE});
          }
          if (obj instanceof String) {
            fieldValue = (String)obj;

            Element eChildOutput = new Element(fieldName);
            // Have to do this to validate the data since the object we're dealing
            // with may not have had an EnterpriseFields object when it was populated.
            try {
              String tempValue = removeXmlEscapes(fieldValue);
              // 4/4/2002 fix
              // in this case, we really do want to set the value in the vector at the index
              // so we don't keep adding items to it
              setVariableValue(xeo, fieldName, tempValue , String.class, i);
            }
            catch (Exception e) {
               throw new EnterpriseLayoutException("Error setting " + objectName + "/" + fieldName +
                "  to the value " + fieldValue + "  Exception: " + e.getMessage(), e);
            }

            // Now, we have to get the value from the object again since it may have been
            // modified when the setter methods are called above.  Otherwise, we'll be
            // creating the XML using the "non enterprise" value.
            if (getTargetAppName() == null) {
              fieldValue = (String)getValueFromObject(xeo, fieldName, new Object[] {iParm}, new Class[] {Integer.TYPE});
            }
            else {
              fieldValue = (String)getValueFromObject(xeo, getTargetAppName(), fieldName, new Object[] {iParm}, new Class[] {Integer.TYPE});
            }

            eChildOutput.setText(fieldValue);
            eOutput.addContent(eChildOutput);
          }
          else {
            // should never get here.
          }
        }
        if (numObjects == 0) {
          // Have to check the parent field (if one exists) for situations
          // where the Parent field isn't required but children of that Parent
          // are.  Example is DeceasedDate in BasicPerson.  DeceasedDate is optional
          // but Month,Day,Year are required if DeceasedDate is present...
          if (isRequired && parentIsRequired && xeo.getEnterpriseFields().ignoreValidation() == false) {
            throw new EnterpriseLayoutException("The " + fieldType + " " +
              elementName + "/" + fieldName + " is required but it has no value.  NumObjects: " + numObjects);
          }
          else {
            logger.debug(fieldName + " on " + elementName + " is required but " + elementName + " isn't so we can ignore this missing field.");
          }
        }
      }
      else {
        Object obj = null;
        if (getTargetAppName() == null) {
          obj = getValueFromObject(xeo, fieldName);
        }
        else {
          obj = getValueFromObject(xeo, getTargetAppName(), fieldName);
        }
        if (obj instanceof String) {
          fieldValue = (String)obj;
        }
        else {
        }
        if (fieldValue == null || fieldValue.trim().length() == 0) {
          // Have to check the parent field (if one exists) for situations
          // where the Parent field isn't required but children of that Parent
          // are.  Example is DeceasedDate in BasicPerson.  DeceasedDate is optional
          // but Month,Day,Year are required if DeceasedDate is present...
          if (isRequired && parentIsRequired && xeo.getEnterpriseFields().ignoreValidation() == false) {
            throw new EnterpriseLayoutException("The " + fieldType + " " +
              elementName + "/" + fieldName + " is required but it has no value.");
          }
          else {
            logger.debug(fieldName + " on " + elementName + " is required but " + elementName + " isn't so we can ignore this missing field.");
            // Don't even add the Element since it's not required and there is no
            // data in the object's field.
            return;
          }
        }

        // Have to do this to validate the data since the object we're dealing
        // with may not have had an EnterpriseFields object when it was populated.
        try {
          String tempValue = removeXmlEscapes(fieldValue);
          setVariableValue(xeo, fieldName, tempValue , String.class);
         }
        catch (Exception e) {
           throw new EnterpriseLayoutException("Error setting " + objectName + "/" + fieldName +
            "  to the value " + fieldValue + "  Exception: " + e.getMessage(), e);
         }

        // Now, we have to get the value from the object again since it may have been
        // modified when the setter methods are called above.  Otherwise, we'll be
        // creating the XML using the "non enterprise" value.
        if (getTargetAppName() == null) {
          fieldValue = (String)getValueFromObject(xeo, fieldName);
        }
        else {
          fieldValue = (String)getValueFromObject(xeo, getTargetAppName(), fieldName);
        }

        logger.debug("[buildElement] Adding Element (" + fieldName + ") with a value of " +
                     fieldValue + " to Element " + elementName + " passed in.");
        eOutput.addContent(new Element(fieldName).setText(fieldValue));
      }
    }
    else if (fieldType.equals("Attribute")) {
      StringBuffer sBuf = new StringBuffer();
      sBuf.append(fieldName.substring(0,1).toLowerCase());
      sBuf.append(fieldName.substring(1));
      String attrName = new String(sBuf);

      Object obj = null;
      if (getTargetAppName() == null) {
        obj = getValueFromObject(xeo, fieldName);
      }
      else {
        obj = getValueFromObject(xeo, getTargetAppName(), fieldName);
      }
      if (obj instanceof String) {
        fieldValue = (String)obj;
      }
      else {
      }
      if (fieldValue == null || fieldValue.trim().length() == 0) {
        // Have to check the parent field (if one exists) for situations
        // where the Parent field isn't required but children of that Parent
        // are.  Example is DeceasedDate in BasicPerson.  DeceasedDate is optional
        // but Month,Day,Year are required if DeceasedDate is present...

        // 8/6/01 - this won't work for things like Address@type, type is required but Address isn't
        // need to figure out a better way to do this.....
        if (isRequired && parentIsRequired && xeo.getEnterpriseFields().ignoreValidation() == false) {
          throw new EnterpriseLayoutException("The " + fieldType + " " +
            elementName + "/" + fieldName + " is required but it has no value.");
        }
        else {
          logger.debug(fieldName + " on " + elementName + " is required but " + elementName + " isn't so we can ignore this missing field.");
          // Don't even add the Attribute since it's not required and there is no
          // data in the object's field.
          return;
        }
      }

      // Have to do this to validate the data since the object we're dealing
      // with may not have had an EnterpriseFields object when it was populated.
      try {
        String tempValue = removeXmlEscapes(fieldValue);
         setVariableValue(xeo, fieldName, tempValue , String.class);
      }
      catch (Exception e) {
         throw new EnterpriseLayoutException("Error setting " + objectName + "/" + fieldName +
          "  to the value " + fieldValue + "  Exception: " + e.getMessage(), e);
      }

      // Now, we have to get the value from the object again since it may have been
      // modified when the setter methods are called above.  Otherwise, we'll be
      // creating the XML using the "non enterprise" value.
      if (getTargetAppName() == null) {
        fieldValue = (String)getValueFromObject(xeo, fieldName);
      }
      else {
        fieldValue = (String)getValueFromObject(xeo, getTargetAppName(), fieldName);
      }

      logger.debug("[buildElement] Adding Attribute (" + attrName + ") with a value of " +
                   fieldValue + " to Element " + elementName + " passed in.");
      eOutput.setAttribute(attrName, fieldValue);
    }
    else if (fieldType.equals("Object")) {
      // If we can't find the ObjectDefinition as a child,
      // look for it at the root of the document.  If it's
      // not there, then we have an error situation.
      Element eObjDef = eField.getChild("ObjectDefinition");
      if (eObjDef == null) {
        eObjDef = getLayout(getLayoutRoot(), fieldName);
        if (eObjDef == null) {
          throw new EnterpriseLayoutException("Can't find an ObjectDefinition in the Layout Document for " +
            objectName + "/" + fieldName);
        }
      }
      java.util.List lFields = eObjDef.getChildren("Field");
      String layoutName = eObjDef.getAttribute("name").getValue();
      logger.debug("There are " + lFields.size() + " Fields in the " + layoutName + " Layout.");

      if (isRepeating(xeo, fieldName)) {
        int numObjects = getLength(xeo, fieldName);

        java.util.List sortedIndexes = getSortedIndexes(xeo, numObjects, fieldName);
        logger.debug("XmlLayout: sortedIndexes.size: " + sortedIndexes.size());
        for (int i=0; i<sortedIndexes.size(); i++) {
          String nextIndex = (String)sortedIndexes.get(i);
          logger.debug("Sorted Index [" + i + "] is " + nextIndex);
          Integer iParm = new Integer(nextIndex);

          // the rest is the same????
          Object obj = null;
          obj = getValueFromObject(xeo, fieldName, new Object[] {iParm}, new Class[] {Integer.TYPE});
          if (obj instanceof XmlEnterpriseObject) {
            XmlEnterpriseObject aNewXeo = (XmlEnterpriseObject)obj;
            try {
              aNewXeo.setEnterpriseFields((EnterpriseFields)xeo.getEnterpriseFields().clone());
            }
            catch (Exception e) {
              throw new EnterpriseLayoutException("Exception cloning EnterpriseFields object for object " + objectName + "." +
                "  Exception: " + e.getMessage(), e);
            }
            String newXeoClassName = aNewXeo.getClass().getName();
            String newXeoObjectName = newXeoClassName.substring(newXeoClassName.lastIndexOf('.') + 1);
            Element eChildOutput = new Element(fieldName);
            for (int j=0; j<lFields.size(); j++) {
              Element eChildField = (Element)lFields.get(j);
              buildElement(aNewXeo, eChildOutput, eChildField, isRequired);
            }
            logger.debug("[buildElement] Adding [" + i + "] Element " + fieldName + " to the " + elementName + " passed in.");
            eOutput.addContent(eChildOutput);
          }
          else {
            // should never get here.
          }
        }
      }
      else {
        Object obj = null;
        obj = getValueFromObject(xeo, fieldName);       
        if (obj instanceof XmlEnterpriseObject) {
          XmlEnterpriseObject aNewXeo = (XmlEnterpriseObject)obj;
          try {
            aNewXeo.setEnterpriseFields((EnterpriseFields)xeo.getEnterpriseFields().clone());
          }
          catch (Exception e) {
            throw new EnterpriseLayoutException("Exception cloning EnterpriseFields object for object " + objectName + "." +
              "  Exception: " + e.getMessage(), e);
          }

          try {
            if (aNewXeo.isEmpty()) {
              logger.debug("No need to try and add the " + fieldName + " to the element passed in.");
              if (isRequired == false || parentIsRequired == false) {
                return;
              }
            }
            else {
              logger.debug("Object " + fieldName + " isn't empty so we have to try and add it.");
            }
          }
          catch (XmlEnterpriseObjectException e) {
            throw new EnterpriseLayoutException("Error checking if object " + objectName + "/" +
              fieldName + " is empty.  Exception: " + e.getMessage(), e);
          }
          String newXeoClassName = aNewXeo.getClass().getName();
          String newXeoObjectName = newXeoClassName.substring(newXeoClassName.lastIndexOf('.') + 1);

          Element eChildOutput = new Element(fieldName);
          for (int i=0; i<lFields.size(); i++) {
            Element eChildField = (Element)lFields.get(i);
            buildElement(aNewXeo, eChildOutput, eChildField, isRequired);
          }
          logger.debug("[buildElement] Adding Element " + fieldName + " to the " + elementName + " passed in.");
          eOutput.addContent(eChildOutput);
        }
View Full Code Here

            objectName + " Element passed in.");
        }
      }

      for (int j=0; j<lValues.size(); j++) {
        Element eValue = (Element)lValues.get(j);
        fieldValue = eValue.getText();
        logger.debug("Setting " + fieldName + " to " + fieldValue + " on the " + objectName + " object passed in.");

        try {
          fieldValue = removeXmlEscapes(fieldValue);
          setVariableValue(xeo, fieldName, fieldValue, String.class);
        }
        catch (Exception e) {
          throw new EnterpriseLayoutException("Error setting " + objectName + "/" + fieldName +
            "  Exception: " + e.getMessage(), e);
        }
      }
    }
    else if (fieldType.equals("Attribute")) {
      StringBuffer sBuf = new StringBuffer();
      sBuf.append(fieldName.substring(0,1).toLowerCase());
      sBuf.append(fieldName.substring(1));
      String attrName = new String(sBuf);
      Attribute anAttr = eInput.getAttribute(attrName);
      if (anAttr == null) {
        if (isRequired && xeo.getEnterpriseFields().ignoreValidation() == false) {
          throw new EnterpriseLayoutException(fieldName +
             " is a required field but could not be found in the " +
            objectName + " Element passed in.");
        }
      }
      else {
        fieldValue = anAttr.getValue();
        if (fieldValue == null || fieldValue.trim().length() == 0) {
          if (isRequired && xeo.getEnterpriseFields().ignoreValidation() == false) {
            throw new EnterpriseLayoutException(fieldName +
                                                " is a required field but could not be found in the " +
                                                objectName + " Element passed in.");
          }
        }
        logger.debug("Setting " + fieldName + " to " + fieldValue + " on the " + objectName + " object passed in.");
        try {
          fieldValue = removeXmlEscapes(fieldValue);
          setVariableValue(xeo, fieldName, fieldValue, String.class);
        }
        catch (Exception e) {
          throw new EnterpriseLayoutException("Error setting " + objectName + "/" +
            fieldName + "  Exception:" + e.getMessage(), e);
        }
      }
    }
    else if (fieldType.equals("Object")) {
      Element eObjDef = eField.getChild("ObjectDefinition");
      if (eObjDef == null) {
        logger.debug("Getting ObjectDefinition for " + fieldName + " from root...");
        eObjDef = getLayout(getLayoutRoot(), fieldName);
        if (eObjDef == null) {
          throw new EnterpriseLayoutException("Can't find an ObjectDefinition in the Layout Document for " +
            objectName + "/" + fieldName);
        }
      }
      String objClassName = eObjDef.getChild("ClassName").getText();
      String objObjectName = objClassName.substring(objClassName.lastIndexOf('.') + 1);
      String layoutName = eObjDef.getAttribute("name").getValue();

      /*
      if (fieldName.equals("EffectiveDate")) {
        logger.debug("Date class name is: " + objClassName);
      }
      */

      java.util.List lObjs = eInput.getChildren(fieldName);
      logger.debug("[xmllayout] There are " + lObjs.size() + " " + fieldName + " elements in the " + objectName + " Element passed in.");
      if (lObjs.size() == 0) {
        if (isRequired && xeo.getEnterpriseFields().ignoreValidation() == false) {
          throw new EnterpriseLayoutException(fieldName +
                                              " is a required field but could not be found in the " +
                                              objectName + " Element passed in.");
        }
      }
      else {
        XmlEnterpriseObject aNewXeo = null;
        Element eObjInput = null;
        for (int j=0; j<lObjs.size(); j++) {
          eObjInput = (Element)lObjs.get(j);
          if (elementIsEmpty(eObjInput) && isRequired == false) {
            // If the element is empty and the object is not required,
            // then there's no reason to instantiate and attempt to build
            // the object.
            logger.debug("No need to instantiate the " + fieldName + " object!");
            return;
          }
          Class classType = null;
          if (isDate(objClassName)) {
            String oName = objClassName + "(" + layoutName + ")";
            logger.debug("instantiating a " + oName);
            aNewXeo = (XmlEnterpriseObject)instantiate(oName);

            try {
              aNewXeo.setEnterpriseFields((EnterpriseFields)xeo.getEnterpriseFields().clone());
            }
            catch (Exception e) {
              throw new EnterpriseLayoutException("Exception cloning EnterpriseFields object for object " + objectName + "." +
                "  Exception: " + e.getMessage(), e);
            }

            classType = aNewXeo.getClass();
            objectName = objectName + "(" + layoutName + ")";
          }
          else {
            logger.debug("instantiating a " + objClassName);
            aNewXeo = (XmlEnterpriseObject)instantiate(objClassName);

            try {
              aNewXeo.setEnterpriseFields((EnterpriseFields)xeo.getEnterpriseFields().clone());
            }
            catch (Exception e) {
              throw new EnterpriseLayoutException("Exception cloning EnterpriseFields object for object " + objectName + "." +
                "  Exception: " + e.getMessage(), e);
            }

            classType = aNewXeo.getClass();
          }

          java.util.List lFields = eObjDef.getChildren("Field");
          logger.debug("There are " + lFields.size() + " Fields in the " + layoutName + " Layout.");
          for (int i=0; i<lFields.size(); i++) {
            Element eObjField = (Element)lFields.get(i);
            buildObject(aNewXeo, eObjInput, eObjField, isRequired);
          }

          logger.debug("Setting the " + fieldName + " object on the " + xeo.getClass().getName());

View Full Code Here

      }
    }

    java.util.List children = e.getChildren();
    for (int i=0; i<children.size(); i++) {
      Element eChild = (Element)children.get(i);
      if (eChild.getContentSize()>0) {
        retVal = elementIsEmpty(eChild);
        if (retVal) {
          logger.debug(e.getName() + " has a child with values, must instantiate.");
          return false;
        }
      }
      else {
        if (eChild.getText().length() > 0) {
          logger.debug("Child element " + eChild.getName() + " of " + e.getName() +
            " has a data in it, must instantiate.");
          return false;
        }
      }
    }
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.