public void buildFromXMLElement()

in uimaj-ep-runtime-deployeditor/src/main/java/org/apache/uima/aae/deployment/impl/AEDeploymentMetaData_Impl.java [275:539]


  public void buildFromXMLElement(Element aElement, XMLParser aParser,
          XMLParser.ParsingOptions aOptions) throws InvalidXMLException {
    // Find out about the parent node (used to decide the type of error config
    boolean isTopAnalysisEngine = false;
    if (aElement.getParentNode() instanceof Element) {
      if ( ((Element) aElement.getParentNode()).getTagName().equalsIgnoreCase(TAG_SERVICE) ) {
        isTopAnalysisEngine = true;
        // Trace.err(" >>> Top AE ");
      } else {
        // Trace.err(" >>> Delegate AE ");
      }
    } else {
      Trace.bug("Not an Element class: " + aElement.getParentNode().getClass().getName());
    }

    // Check for "key" and "async" attributes
    NamedNodeMap map = aElement.getAttributes();
    if (map != null) {
      for (int i=0; i<map.getLength(); ++i) {
        Node item = map.item(i);
        String name = item.getNodeName();
        String val = item.getNodeValue();
        if (val == null) {
          val = "";
        } else {
          val = val.trim();
        }
        if (AEDeploymentConstants.TAG_ATTR_KEY.equalsIgnoreCase(name)) {
          // Set "key = ..." attribute
          setKey(val);
          
        } else if (AEDeploymentConstants.TAG_ATTR_ASYNC.equalsIgnoreCase(name)) {
          // Set "async =[yes|no]" attribute
          setAsync(Boolean.parseBoolean(val));
          
        } else if (AEDeploymentConstants.TAG_ATTR_INPUT_QUEUE_SCALEOUT.equalsIgnoreCase(name)) {
          // Set "inputQueueScaleout =nnn" attribute
          try {
            int n = Integer.parseInt(val);
            if (n > 0) {
              setInputQueueScaleout(n);
            } else {
              throw new InvalidXMLException(InvalidXMLException.INVALID_ELEMENT_TEXT,
                      new Object[] { n, TAG_ATTR_INPUT_QUEUE_SCALEOUT });
            }
          } catch (NumberFormatException e) {
            throw new InvalidXMLException(InvalidXMLException.UNKNOWN_ELEMENT,
                    new Object[] { TAG_ATTR_INPUT_QUEUE_SCALEOUT }, e);
          }
          
        } else if (AEDeploymentConstants.TAG_ATTR_INTERNAL_REPLYQUEUE_SCALEOUT.equalsIgnoreCase(name)) {
          // Set "inputQueueScaleout =nnn" attribute
          try {
            int n = Integer.parseInt(val);
            if (n > 0) {
              setInternalReplyQueueScaleout(n);
            } else {
              throw new InvalidXMLException(InvalidXMLException.INVALID_ELEMENT_TEXT,
                      new Object[] { n, TAG_ATTR_INTERNAL_REPLYQUEUE_SCALEOUT });
            }
          } catch (NumberFormatException e) {
            throw new InvalidXMLException(InvalidXMLException.UNKNOWN_ELEMENT,
                    new Object[] { TAG_ATTR_INTERNAL_REPLYQUEUE_SCALEOUT }, e);
          }
          
        } else {
          throw new InvalidXMLException(InvalidXMLException.UNKNOWN_ELEMENT,
                  new Object[]{name});
        }
      }
      
      // Check validity of queue listeners
      if (!isAsync()) {
        if (getInputQueueScaleout() > 1) {
          throw new InvalidXMLException(InvalidXMLException.INVALID_ELEMENT_TEXT,
                  new Object[] { getInputQueueScaleout(), TAG_ATTR_INPUT_QUEUE_SCALEOUT });
        }
        if (getInternalReplyQueueScaleout() > 1) {
          throw new InvalidXMLException(InvalidXMLException.INVALID_ELEMENT_TEXT,
                  new Object[] { getInternalReplyQueueScaleout(), TAG_ATTR_INTERNAL_REPLYQUEUE_SCALEOUT });
        }
      }      
    }

    // Has "key = ..." attribute ?
    if (!isTopAnalysisEngine && getKey() == null) {
      throw new InvalidXMLException(InvalidXMLException.ELEMENT_NOT_FOUND,
              new Object[]{AEDeploymentConstants.TAG_ATTR_KEY, AEDeploymentConstants.TAG_ANALYSIS_ENGINE});
    }

    NodeList childNodes = aElement.getChildNodes();
    String val;
    for (int i = 0; i < childNodes.getLength(); i++) {
      Node curNode = childNodes.item(i);
      if (!(curNode instanceof Element)) {
        continue;
      }
      Element elem = (Element) curNode;

      if (AEDeploymentConstants.TAG_SCALE_OUT.equalsIgnoreCase(elem.getTagName())) {
        int n;
        val = DDParserUtil.checkAndGetAttributeValue(TAG_SCALE_OUT, TAG_ATTR_NUMBER_OF_INSTANCES, elem, true);
        if (val == null || val.trim().length() == 0) {
          n = 0;
        } else {
          try {
            n = Integer.parseInt(val);
          } catch (NumberFormatException e) {
            e.printStackTrace();
            throw new InvalidXMLException(InvalidXMLException.UNKNOWN_ELEMENT,
                    new Object[] { TAG_ATTR_NUMBER_OF_INSTANCES }, e);
          }
        }
        setNumberOfInstances(n);

      } else if (TAG_CAS_MULTIPLIER.equalsIgnoreCase(elem.getTagName())) {
        // Get "poolSize" attribute
        int n;
        val = DDParserUtil.checkAndGetAttributeValue(TAG_CAS_MULTIPLIER, TAG_ATTR_POOL_SIZE, elem, true);
        if (val == null || val.trim().length() == 0) {
          n = 0;
        } else {
          try {
            n = Integer.parseInt(val);
          } catch (NumberFormatException e) {
            e.printStackTrace();
            throw new InvalidXMLException(InvalidXMLException.UNKNOWN_ELEMENT,
                    new Object[] { TAG_ATTR_POOL_SIZE }, e);
          }
        }
        setCasMultiplierPoolSize(n);
        
        // Check for Optional "initialFsHeapSize"
        val = DDParserUtil.checkAndGetAttributeValue(TAG_CAS_MULTIPLIER, TAG_ATTR_INIT_SIZE_OF_CAS_HEAP, elem, false);
        if (val != null && val.trim().length() > 0) {
          try {
            initialFsHeapSize = Integer.parseInt(val);
          } catch (NumberFormatException e) {
            e.printStackTrace();
            throw new InvalidXMLException(InvalidXMLException.UNKNOWN_ELEMENT,
                    new Object[] { TAG_ATTR_INIT_SIZE_OF_CAS_HEAP }, e);
          }
        }
        
        // Check for Optional "processParentLast =[false|true]"
        val = DDParserUtil.checkAndGetAttributeValue(TAG_CAS_MULTIPLIER, TAG_ATTR_PROCESS_PARENT_CAS_LAST, elem, false);
	    boolean b = false;      
	    if (val != null && val.trim().length() > 0) {
	    	try {
	    		b = Boolean.parseBoolean(val);
	    	} catch (NumberFormatException e) {
	    		e.printStackTrace();
	    		throw new InvalidXMLException(InvalidXMLException.UNKNOWN_ELEMENT,
	    				new Object[] { TAG_ATTR_PROCESS_PARENT_CAS_LAST }, e);
	    	}
	    }
	    setProcessParentCASLast(b);          

      } else if (AEDeploymentConstants.TAG_DELEGATES.equalsIgnoreCase(elem.getTagName())) {
        delegates = new AEDelegates_Impl(this);
        NodeList nodes = elem.getChildNodes();
        if (nodes.getLength() > 0) {
          // Look for "analysisEngine" or "remoteDelegate"
          for (int k = 0; k < nodes.getLength(); ++k) {
            Node n = nodes.item(k);
            if (!(n instanceof Element)) {
              continue;
            }

            Element e = (Element) n;
            if (AEDeploymentConstants.TAG_ANALYSIS_ENGINE.equalsIgnoreCase(e.getTagName())) {
              // Add "Analysis Engine" to the list
              delegates.addDelegate((DeploymentMetaData_Impl) aParser.buildObject(e, aOptions));

            } else if (AEDeploymentConstants.TAG_REMOTE_DELEGATE.equalsIgnoreCase(e.getTagName())) {
              delegates.addDelegate((DeploymentMetaData_Impl) aParser.buildObject(e, aOptions));

            }
          }
        }
      } else if (AEDeploymentConstants.TAG_ASYNC_PRIMITIVE_ERROR_CONFIGURATION.equalsIgnoreCase(elem
              .getTagName())) {
        asyncAEErrorConfiguration = (AsyncPrimitiveErrorConfiguration) aParser.buildObject(elem,
                aOptions);
        asyncAEErrorConfiguration.sParentObject(this);

      } else if (AEDeploymentConstants.TAG_ASYNC_AGGREGATE_ERROR_CONFIGURATION.equalsIgnoreCase(elem
              .getTagName())) {
        asyncAEErrorConfiguration = (AsyncAggregateErrorConfiguration) aParser.buildObject(elem,
                aOptions);
        asyncAEErrorConfiguration.sParentObject(this);

      } else {
        throw new InvalidXMLException(InvalidXMLException.UNKNOWN_ELEMENT,
                new Object[]{elem.getTagName()});
      }

    } // for

    // Check if async=false and "delegates" are defined
    if ( (!isAsync()) && delegates != null) {
      setAsync(true);
    }

    // Create Error Config if not specified
    if (asyncAEErrorConfiguration == null) {
      Class cls;
      if (isTopAnalysisEngine) {
        cls = AsyncPrimitiveErrorConfiguration.class;          
      } else {
        cls = AsyncAggregateErrorConfiguration.class;          
      }
      asyncAEErrorConfiguration = (AsyncAEErrorConfiguration) UIMAFramework
                        .getResourceSpecifierFactory().createObject(cls);
      setAsyncAEErrorConfiguration(asyncAEErrorConfiguration);
      asyncAEErrorConfiguration.sParentObject(this);
      if (cls == AsyncAggregateErrorConfiguration.class) {
        asyncAEErrorConfiguration.getGetMetadataErrors().setTimeout(0);
      }
    } else {      
      // Validate some values 
      if (!isTopAnalysisEngine) {
        int value;
        String s;
        boolean b;
        if (!isAsync()) {
          // For co-located delegates
          // Check for GetMetadataErrors
          if ( (value=asyncAEErrorConfiguration.getGetMetadataErrors().getMaxRetries()) != 0) {
            throw new InvalidXMLException(InvalidXMLException.INVALID_ELEMENT_TEXT,
                    new Object[]{value, TAG_ATTR_MAX_RETRIES});
//          } else if ( (value=asyncAEErrorConfiguration.getGetMetadataErrors().getTimeout()) != 0) {
//            throw new InvalidXMLException(InvalidXMLException.INVALID_ELEMENT_TEXT,
//                    new Object[]{value, TAG_ATTR_TIMEOUT});
//          } else if ( !(s=asyncAEErrorConfiguration.getGetMetadataErrors().getErrorAction()).equals("terminate")) {
//            throw new InvalidXMLException(InvalidXMLException.INVALID_ELEMENT_TEXT,
//                    new Object[]{s, TAG_ATTR_ERROR_ACTION});
          }
          
          // Check for ProcessCasErrors
          if ( (value=asyncAEErrorConfiguration.getProcessCasErrors().getMaxRetries()) != 0) {
            throw new InvalidXMLException(InvalidXMLException.INVALID_ELEMENT_TEXT,
                    new Object[]{value, TAG_ATTR_MAX_RETRIES});
//          } else if ( (b=asyncAEErrorConfiguration.getProcessCasErrors().isContinueOnRetryFailure()) ) {
//            throw new InvalidXMLException(InvalidXMLException.INVALID_ELEMENT_TEXT,
//                    new Object[]{b, TAG_ATTR_CONTINUE_ON_RETRY_FAILURE});
          }
        }
        
        // Check for Threshold Count = 0
//        if ( asyncAEErrorConfiguration.getProcessCasErrors().getThresholdCount() == 0) {
//          if ( (value=asyncAEErrorConfiguration.getProcessCasErrors().getThresholdWindow()) != 0 ) {
//            throw new InvalidXMLException(InvalidXMLException.INVALID_ELEMENT_TEXT,
//                    new Object[]{value, TAG_ATTR_THRESHOLD_WINDOW});            
//          }
//          if ( !(s=asyncAEErrorConfiguration.getProcessCasErrors().getThresholdAction()).equals("disable")) {
//            throw new InvalidXMLException(InvalidXMLException.INVALID_ELEMENT_TEXT,
//                  new Object[]{s, TAG_ATTR_THRESHOLD_ACTION});
//          }
//        }
      }

    }

  }