Package uk.nhs.interoperability.payloads.util.fieldtypehandlers

Examples of uk.nhs.interoperability.payloads.util.fieldtypehandlers.FieldHandler


    for (String fieldName : fieldDefinitions.keySet()) {
      Field field = fieldDefinitions.get(fieldName);
      FieldType fieldType = field.getTypeEnum();
      Logger.trace("===== Processing field: " + field.getName() + " - type specified as: " + fieldType.name() + " multiplicity = " + field.getMaxOccurs());

      FieldHandler handler = fieldType.getHandler();
     
      String xpath = field.getXpath();
      String strValue = null;
      Object fieldValue = p.getValue(field.getName());
     
      // First, see if the field should be included in the output
      boolean outputField = handler.outputField(field, p);
     
      if (outputField) {
        if (field.getMaxOccurs() > 1) {
          // We are expecting an ArrayList with one or more items
          ArrayList list = (ArrayList)fieldValue;
          if (list != null) {
            for (Object fieldListItem : list) {
             
              // Do some pre-processing on the field if required
              boolean continueProcessing =
                  handler.preProcessSerialise(namespaces, fieldListItem, xpath, parent, xmldoc, field, p);

              // Sometimes the pre-processing may handle the node creation itself (e.g. for coded items),
              // in which case we don't need to continue here
              if (continueProcessing) {
                // If the field is not blank, create a new node or nodes for it to go into
                if (!handler.isItemBlank(field, fieldListItem, true)) {
                  createNode(namespaces, xpath, parent, xmldoc, fieldListItem, handler, field, p);
                }
              }
            }
          }
        } else {
          // Do some pre-processing on the field if required
          boolean continueProcessing =
              handler.preProcessSerialise(namespaces, fieldValue, xpath, parent, xmldoc, field, p);
         
          // Sometimes the pre-processing may handle the node creation itself (e.g. for coded items),
          // in which case we don't need to continue here
          if (continueProcessing) {
            // If the field is not blank, create a new node or nodes for it to go into
            if (!handler.isItemBlank(field, fieldValue, false)) {
              createNode(namespaces, xpath, parent, xmldoc, fieldValue, handler, field, p);
            }
          }
        }
      }
View Full Code Here


  }

  private static void processField(XMLNamespaceContext namespaces, Payload p, Element parent, Document xmldoc, String name, Field field) {
    String strXpath = field.getXpath();
    FieldType fieldType = field.getTypeEnum();
    FieldHandler handler = fieldType.getHandler();
   
    Logger.trace("=== Attempting to find field: " + field.getName() +
        " which is of type " + field.getTypeName() +
        " and has xpath: " + strXpath +
        " with maxOccurs = " + field.getMaxOccurs() +
        " in parent element: " + parent.getLocalName());
   
    if (field.getName().equals("RecipientName")) {
      System.out.println();
    }
   
    boolean continueProcessing = handler.preProcessParse(namespaces, p, parent, xmldoc, name, field);
   
    if (continueProcessing) {
     
      if (strXpath != null) {
        // An xpath of . is used for unstructured names, addresses, etc, but should only be used when there are no structured fields
        if (strXpath.equals(".")) {
          if (p.hasData()) {
            Logger.trace("Skipping unstructured data field (with Xpath = .) within payload object: "+p.getClassName()+" as the class already contains structured fields");
            return;
          }
        }
       
        // If this is a list, return all the matching nodes and add each to the payload object field
        if (field.getMaxOccurs() > 1) {
          XPathExpression xpath = field.getCompiledXpath(namespaces);
          ArrayList<Element> list = XPaths.findListFromXPath(xpath, parent, strXpath);
          if (list != null) {
            for (Element item : list) {
             
              Object elementValueObject = handler.parse(field, item, namespaces, p, xmldoc, parent);
             
              if (elementValueObject != null) {
                  p.addMultivalue(field.getName(), elementValueObject, true);
              }
            }
          } else {
            Logger.trace("  ** NO MATCH FOUND!");
          }
        } else {
         
          XPathExpression xpath = field.getCompiledXpath(namespaces);
          Element e = handler.getElement(xpath, parent, strXpath);
         
          Object elementValueObject = handler.parse(field, e, namespaces, p, xmldoc, parent);
         
          if (elementValueObject != null) {
            p.setValue(field.getName(), elementValueObject);
          }
        }
View Full Code Here

TOP

Related Classes of uk.nhs.interoperability.payloads.util.fieldtypehandlers.FieldHandler

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.