Java Code Examples for org.apache.uima.util.InvalidXMLException#ELEMENT_NOT_FOUND

The following examples show how to use org.apache.uima.util.InvalidXMLException#ELEMENT_NOT_FOUND . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CasProcessorConfigurationJAXBImpl.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
/**
 * Copies deployment type associated with this Cas Processor
 * 
 * @param aJaxbCasProcessorConfig - -
 *          configuration object containing Cas Processor configuration
 * @throws ResourceConfigurationException -
 */
private void addDeploymentType(CpeCasProcessor aCasProcessorConfig)
        throws ResourceConfigurationException {
  if (aCasProcessorConfig == null) {
    throw new ResourceConfigurationException(InvalidXMLException.ELEMENT_NOT_FOUND, new Object[] {
        "<casProcessor>", "<casProcessors>" }, new Exception(CpmLocalizedMessage
            .getLocalizedMessage(CPMUtils.CPM_LOG_RESOURCE_BUNDLE,
                    "UIMA_CPM_EXP_bad_cpe_descriptor_no_cp__WARNING", new Object[] { Thread
                            .currentThread().getName() })));
  }
  String deployType = aCasProcessorConfig.getDeployment();
  if (deployType == null || deployType.trim().length() == 0) {
    throw new ResourceConfigurationException(InvalidXMLException.REQUIRED_ATTRIBUTE_MISSING,
            new Object[] { "deployment", "casProcessor" }, new Exception(CpmLocalizedMessage
                    .getLocalizedMessage(CPMUtils.CPM_LOG_RESOURCE_BUNDLE,
                            "UIMA_CPM_EXP_missing_attribute_from_xml_element__WARNING",
                            new Object[] { Thread.currentThread().getName(),
                                aCasProcessorConfig.getName(), "deployment", "<casProcessor>" })));
  }
  deploymentType = deployType;
}
 
Example 2
Source File: CasProcessorConfigurationJAXBImpl.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
/**
 * Copies path of the Cas Processor descriptor.
 * 
 * @param aJaxbCasProcessorConfig -
 *          configuration object holding path to the descriptor
 * 
 * @throws ResourceConfigurationException -
 */
private void addDescriptor(CpeCasProcessor aCasProcessorConfig)
        throws ResourceConfigurationException {
  if (aCasProcessorConfig == null) {
    throw new ResourceConfigurationException(InvalidXMLException.ELEMENT_NOT_FOUND, new Object[] {
        "<casProcessor>", "<casProcessors>" }, new Exception(CpmLocalizedMessage
            .getLocalizedMessage(CPMUtils.CPM_LOG_RESOURCE_BUNDLE,
                    "UIMA_CPM_EXP_bad_cpe_descriptor_no_cp__WARNING", new Object[] { Thread
                            .currentThread().getName() })));
  }
  descriptor = aCasProcessorConfig.getCpeComponentDescriptor();
  
  if (descriptor.getInclude() != null) {
    String descPath = descriptor.getInclude().get();
    if (descPath == null || descPath.trim().length() == 0) {
      throw new ResourceConfigurationException(InvalidXMLException.ELEMENT_NOT_FOUND, new Object[] {
          "href", "include" }, new Exception(CpmLocalizedMessage.getLocalizedMessage(
              CPMUtils.CPM_LOG_RESOURCE_BUNDLE,
              "UIMA_CPM_EXP_missing_attribute_from_xml_element__WARNING", new Object[] {
                  Thread.currentThread().getName(), aCasProcessorConfig.getName(), "href",
                  "<include>" })));
    }
  }

}
 
Example 3
Source File: CPEFactory.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a descriptor path associated with Cas Processor.
 *
 * @param aCasProcessorCfg -
 *          Cas Processor configuration
 * @return - Descriptor path
 * @throws ResourceConfigurationException -
 */
public URL getDescriptorURL(CpeCasProcessor aCasProcessorCfg)
        throws ResourceConfigurationException {
  if (aCasProcessorCfg.getCpeComponentDescriptor() == null) {
    throw new ResourceConfigurationException(InvalidXMLException.ELEMENT_NOT_FOUND, new Object[] {
        "descriptor", "casProcessor" }, new Exception(CpmLocalizedMessage.getLocalizedMessage(
            CPMUtils.CPM_LOG_RESOURCE_BUNDLE, "UIMA_CPM_EXP_missing_xml_element__WARNING",
            new Object[] { Thread.currentThread().getName(), aCasProcessorCfg.getName(),
                "descriptor" })));
  }
  return aCasProcessorCfg.getCpeComponentDescriptor().findAbsoluteUrl(getResourceManager());
}
 
Example 4
Source File: CPEFactory.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
/**
 * Instantiates a local (managed) Cas Processor.
 *
 * @param aCasProcessorCfg -
 *          Cas Processor configuration
 * @return - Local CasProcessor
 * @throws ResourceConfigurationException -
 */
private CasProcessor produceLocalCasProcessor(CpeCasProcessor aCasProcessorCfg)
        throws ResourceConfigurationException {
  if (aCasProcessorCfg == null) {
    throw new ResourceConfigurationException(InvalidXMLException.ELEMENT_NOT_FOUND, new Object[] {
        "casProcessor", "casProcessors" }, new Exception(CpmLocalizedMessage.getLocalizedMessage(
            CPMUtils.CPM_LOG_RESOURCE_BUNDLE, "UIMA_CPM_EXP_bad_cpe_descriptor_no_cp__WARNING",
            new Object[] { Thread.currentThread().getName() })));
  }
  CasProcessor casProcessor = new NetworkCasProcessorImpl(aCasProcessorCfg);
  return casProcessor;
}
 
Example 5
Source File: CasProcessorConfigurationJAXBImpl.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
/**
 * Copies filter expression used during processing.
 * 
 * @param aJaxbCasProcessorConfig -
 *          configuration object containing Cas Processor configuration
 */
private void addFiltering(CpeCasProcessor aCasProcessorConfig)
        throws ResourceConfigurationException {
  if (aCasProcessorConfig == null) {
    throw new ResourceConfigurationException(InvalidXMLException.ELEMENT_NOT_FOUND, new Object[] {
        "<casProcessor>", "<casProcessors>" }, new Exception(CpmLocalizedMessage
            .getLocalizedMessage(CPMUtils.CPM_LOG_RESOURCE_BUNDLE,
                    "UIMA_CPM_EXP_bad_cpe_descriptor_no_cp__WARNING", new Object[] { Thread
                            .currentThread().getName() })));
  }
  filterString = aCasProcessorConfig.getCasProcessorFilter();
}
 
Example 6
Source File: CasProcessorConfigurationJAXBImpl.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
/**
 * Copies batch size associated with this Cas Processor
 * 
 * @param aJaxbCasProcessorConfig -
 *          configuration object containing Cas Processor configuration
 */
private void addBatchSize(CpeCasProcessor aCasProcessorConfig)
        throws ResourceConfigurationException {
  if (aCasProcessorConfig == null) {
    throw new ResourceConfigurationException(InvalidXMLException.ELEMENT_NOT_FOUND, new Object[] {
        "<casProcessor>", "<casProcessors>" }, new Exception(CpmLocalizedMessage
            .getLocalizedMessage(CPMUtils.CPM_LOG_RESOURCE_BUNDLE,
                    "UIMA_CPM_EXP_bad_cpe_descriptor_no_cp__WARNING", new Object[] { Thread
                            .currentThread().getName() })));
  }
  CpeCheckpoint checkpoint = aCasProcessorConfig.getCheckpoint();
  if (checkpoint == null) {
    throw new ResourceConfigurationException(InvalidXMLException.ELEMENT_NOT_FOUND, new Object[] {
        "<checkpoint>", "<casProcessor>" }, new Exception(CpmLocalizedMessage
            .getLocalizedMessage(CPMUtils.CPM_LOG_RESOURCE_BUNDLE,
                    "UIMA_CPM_EXP_missing_xml_element__WARNING", new Object[] {
                        Thread.currentThread().getName(), aCasProcessorConfig.getName(),
                        "<checkpoint>" })));
  }

  try {
    if (checkpoint.getBatchSize() > 0) {
      batchSize = checkpoint.getBatchSize();
    }
  } catch (NumberFormatException e) {
    throw new ResourceConfigurationException(InvalidXMLException.REQUIRED_ATTRIBUTE_MISSING,
            new Object[] { "batch", "<checkpoint>" }, new Exception(CpmLocalizedMessage
                    .getLocalizedMessage(CPMUtils.CPM_LOG_RESOURCE_BUNDLE,
                            "UIMA_CPM_EXP_missing_attribute_from_xml_element__WARNING",
                            new Object[] { Thread.currentThread().getName(),
                                aCasProcessorConfig.getName(), "batch", "<checkpoint>" })));
  }

}
 
Example 7
Source File: ResourceMetaData_impl.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
/**
 * Validates configuration parameter settings within a group.
 * 
 * @param aNVPs
 *          the parameter settings
 * @param aGroupName
 *          the group
 * @param aParamDecls
 *          Configuration Parameter Declarations
 * 
 * @throws ResourceConfigurationException
 *           if the configuration parameter settings are invalid
 */
protected void validateConfigurationParameterSettings(NameValuePair[] aNVPs, String aGroupName,
        ConfigurationParameterDeclarations aParamDecls) throws ResourceConfigurationException {
  for (int i = 0; i < aNVPs.length; i++) {
    // look up the parameter info
    String name = aNVPs[i].getName();
    if (name == null) {
      throw new ResourceConfigurationException(InvalidXMLException.ELEMENT_NOT_FOUND,
              new Object[] { "name", "nameValuePair" });
    }
    ConfigurationParameter param = aParamDecls.getConfigurationParameter(aGroupName, name);
    if (param == null) {
      if (aGroupName == null) {
        throw new ResourceConfigurationException(
                ResourceConfigurationException.NONEXISTENT_PARAMETER, new Object[] { name,
                    getName() });
      } else {
        throw new ResourceConfigurationException(
                ResourceConfigurationException.NONEXISTENT_PARAMETER_IN_GROUP, new Object[] {
                    name, aGroupName, getName() });
      }
    } else {
      // check datatype
      validateConfigurationParameterDataTypeMatch(param, aNVPs[i]);
    }
  }
}
 
Example 8
Source File: CPEFactory.java    From uima-uimaj with Apache License 2.0 4 votes vote down vote up
/**
 * Adds new Cas Processor with given name.
 *
 * @param aCasProcessorName -
 *          name of the CasProcessor to add
 * @return -
 * @throws ResourceConfigurationException the resource configuration exception
 */
private CpeCasProcessor addCasProcessor(String aCasProcessorName)
        throws ResourceConfigurationException {
  CpeCasProcessor newProcessor = null;
  try {
    if (!isUniqueName(aCasProcessorName)) {
      throw new ResourceConfigurationException(new Exception(CpmLocalizedMessage
              .getLocalizedMessage(CPMUtils.CPM_LOG_RESOURCE_BUNDLE,
                      "UIMA_CPM_EXP_duplicate_name__WARNING", new Object[] {
                          Thread.currentThread().getName(), aCasProcessorName })));
    }
    int index = getCpeDescriptor().getCpeCasProcessors().getAllCpeCasProcessors().length; // getcasProcessorCount();

    if (UIMAFramework.getLogger().isLoggable(Level.FINEST)) {
      UIMAFramework.getLogger(this.getClass()).logrb(
              Level.FINEST,
              this.getClass().getName(),
              "initialize",
              CPMUtils.CPM_LOG_RESOURCE_BUNDLE,
              "UIMA_CPM_add_cp_with_index__FINEST",
              new Object[] { Thread.currentThread().getName(), aCasProcessorName,
                  String.valueOf(index) });
    }
    CpeCasProcessor processor = getCpeDescriptor().getCpeCasProcessors().getCpeCasProcessor(
            index - 1);

    if (processor.getCheckpoint() == null) {
      throw new ResourceConfigurationException(InvalidXMLException.ELEMENT_NOT_FOUND,
              new Object[] { "checkpoint", "casProcessor" }, new Exception(CpmLocalizedMessage
                      .getLocalizedMessage(CPMUtils.CPM_LOG_RESOURCE_BUNDLE,
                              "UIMA_CPM_EXP_missing_xml_element__WARNING", new Object[] {
                                  Thread.currentThread().getName(), aCasProcessorName,
                                  "<checkpoint>" })));
    }

    // For remote Cas Processor make sure that the required parameters are defined.
    // Specifically, VNS host and port are required. Do validation now. If it fails, the
    // ResourceConfigurationException is thrown and we are out here.
    if (Constants.DEPLOYMENT_REMOTE.equals(processor.getDeployment())) {
      String protocol = DeployFactory.getProtocol(processor, getResourceManager());
      if (Constants.VINCI_PROTOCOL.equals(protocol)) {
        verifyDeploymentParams(aCasProcessorName, processor.getDeploymentParams());
      }
    }

    if (processorCount == 0) {
      newProcessor = processor;
      copyCasProcessor(newProcessor, aCasProcessorName);
    } else {
      // CpeCasProcessor cloneProcessor =
      // getCpeDescriptor().getCpeCasProcessors().getCpeCasProcessor(0);

      newProcessor = new CpeIntegratedCasProcessorImpl();
      newProcessor.setDescriptor("href");
      // // Clone casProcessor from an existing one
      // newProcessor = cpeDescGen.createcasProcessor(cloneProcessor);
      copyCasProcessor(newProcessor, aCasProcessorName);
      getCpeDescriptor().getCpeCasProcessors().addCpeCasProcessor(newProcessor, processorCount);// setCpeCasProcessor(processorCount,
      // newProcessor);
    }
    if (UIMAFramework.getLogger().isLoggable(Level.FINEST)) {
      UIMAFramework.getLogger(this.getClass()).log(
              Level.FINEST,
              "getCpeDescriptor().getCasProcessors().getCasProcessor.getAttributeValue(name) "
                      + " "
                      + getCpeDescriptor().getCpeCasProcessors().getCpeCasProcessor(
                              processorCount).getAttributeValue("name"));
      UIMAFramework
              .getLogger(this.getClass())
              .log(
                      Level.FINEST,
                      "getCpeDescriptor().getCasProcessors().getCasProcessor("
                              + "processorCount).getErrorHandling().getMaxConsecutiveRestarts().getAction() "
                              + " "
                              + getCpeDescriptor().getCpeCasProcessors().getCpeCasProcessor(
                                      processorCount).getErrorHandling()
                                      .getMaxConsecutiveRestarts().getAction());
    }
    if (!casProcessorConfigMap.containsKey(aCasProcessorName)) {
      casProcessorConfigMap.put(aCasProcessorName, getCpeDescriptor().getCpeCasProcessors()
              .getCpeCasProcessor(processorCount));
    }
  } catch (Exception e) {
    throw new ResourceConfigurationException(e);
  }
  processorCount++;
  return newProcessor;
}
 
Example 9
Source File: CasProcessorConfigurationJAXBImpl.java    From uima-uimaj with Apache License 2.0 4 votes vote down vote up
/**
 * Initializes instance and copies configuation from cpe descriptor.
 * 
 * @param aCasProcessorConfig -
 *          configuration object containing Cas Processor configuration
 * @param aResourceManager - 
 *          needed to resolve import by name
 * @throws ResourceConfigurationException if descriptor error
 */
public CasProcessorConfigurationJAXBImpl(CpeCasProcessor aCasProcessorConfig, ResourceManager aResourceManager)
        throws ResourceConfigurationException {
  this.resourceManager = aResourceManager;
  
  if (aCasProcessorConfig == null) {
    throw new ResourceConfigurationException(InvalidXMLException.ELEMENT_NOT_FOUND, new Object[] {
        "<casProcessor>", "<casProcessors>" }, new Exception(CpmLocalizedMessage
            .getLocalizedMessage(CPMUtils.CPM_LOG_RESOURCE_BUNDLE,
                    "UIMA_CPM_EXP_bad_cpe_descriptor__WARNING", new Object[] { Thread
                            .currentThread().getName() })));
  }
  name = aCasProcessorConfig.getName();// getAttributeValue("name");
  if (UIMAFramework.getLogger().isLoggable(Level.FINEST)) {
    UIMAFramework.getLogger(this.getClass()).logrb(
            Level.FINEST,
            this.getClass().getName(),
            "initialize",
            CPMUtils.CPM_LOG_RESOURCE_BUNDLE,
            "UIMA_CPM_max_restart_action__FINEST",
            new Object[] { Thread.currentThread().getName(), name,
                aCasProcessorConfig.getErrorHandling().getMaxConsecutiveRestarts().getAction() });
  }
  parallelizable = aCasProcessorConfig.getIsParallelizable();
  // readOnly = aCasProcessorConfig.getReadOnly();
  addErrorHandling(aCasProcessorConfig);
  addDeploymentParameters(aCasProcessorConfig);
  addDeploymentType(aCasProcessorConfig);
  addFiltering(aCasProcessorConfig);
  addBatchSize(aCasProcessorConfig);
  addDescriptor(aCasProcessorConfig);
  addRunInSeparateProcess(aCasProcessorConfig);
  addIsJavaProcess(aCasProcessorConfig);
  if (!isJavaProcess()) {
    if (UIMAFramework.getLogger().isLoggable(Level.FINEST)) {
      UIMAFramework.getLogger(this.getClass()).logrb(Level.FINEST, this.getClass().getName(),
              "initialize", CPMUtils.CPM_LOG_RESOURCE_BUNDLE,
              "UIMA_CPM_config_non_java_service__FINEST",
              new Object[] { Thread.currentThread().getName(), name });
    }
    nonJavaApp = new NonJavaApplication(this, aCasProcessorConfig); 
  } else {
    if (UIMAFramework.getLogger().isLoggable(Level.FINEST)) {
      UIMAFramework.getLogger(this.getClass()).logrb(Level.FINEST, this.getClass().getName(),
              "initialize", CPMUtils.CPM_LOG_RESOURCE_BUNDLE,
              "UIMA_CPM_config_java_service__FINEST",
              new Object[] { Thread.currentThread().getName(), name });
    }
    javaApp = new JavaApplication(this, aCasProcessorConfig);
  }
}
 
Example 10
Source File: CasProcessorConfigurationJAXBImpl.java    From uima-uimaj with Apache License 2.0 4 votes vote down vote up
/**
 * Copies Error handling settings
 * 
 * @param aJaxbCasProcessorConfig -
 *          configuration object containing Cas Processor configuration
 */
private void addErrorHandling(CpeCasProcessor aCasProcessorConfig)
        throws ResourceConfigurationException {
  CasProcessorErrorHandling casProcessorErrorHandling = aCasProcessorConfig.getErrorHandling();

  if (casProcessorErrorHandling == null) {
    throw new ResourceConfigurationException(InvalidXMLException.ELEMENT_NOT_FOUND, new Object[] {
        "errorHandling", "casProcessor" }, new Exception(CpmLocalizedMessage.getLocalizedMessage(
            CPMUtils.CPM_LOG_RESOURCE_BUNDLE, "UIMA_CPM_EXP_missing_xml_element__WARNING",
            new Object[] { Thread.currentThread().getName(), name, "<errorHandling>" })));
  }
  CasProcessorMaxRestarts maxRestarts = casProcessorErrorHandling.getMaxConsecutiveRestarts();
  if (maxRestarts == null) {
    throw new ResourceConfigurationException(
            ResourceConfigurationException.MANDATORY_VALUE_MISSING, new Object[] {
                "maxConsecutiveRestarts", "CPE" }, new Exception(CpmLocalizedMessage
                    .getLocalizedMessage(CPMUtils.CPM_LOG_RESOURCE_BUNDLE,
                            "UIMA_CPM_EXP_missing_xml_element__WARNING", new Object[] {
                                Thread.currentThread().getName(), name,
                                "<maxConsecutiveRestarts>" })));
  }
  maxRetryThreshold = maxRestarts.getRestartCount();
  waitTimeBetweenRestarts = maxRestarts.getWaitTimeBetweenRetries();

  maxRestartThreshold = maxRestarts.getRestartCount();

  if (!validActionOnError(maxRestarts.getAction())) {
    throw new ResourceConfigurationException(
            ResourceConfigurationException.MANDATORY_VALUE_MISSING, new Object[] { "action",
                "CPE" }, new Exception(CpmLocalizedMessage.getLocalizedMessage(
                    CPMUtils.CPM_LOG_RESOURCE_BUNDLE, "UIMA_CPM_EXP_bad_action_string__WARNING",
                    new Object[] { Thread.currentThread().getName(), name,
                        "<maxConsecutiveRestarts>", maxRestarts.getAction() })));
  }
  actionOnMaxRestarts = maxRestarts.getAction();

  // Setup Error rate Threshold in terms of (count)/(sample size) eg. 3/1000
  CasProcessorErrorRateThreshold errorRateThresholdType = casProcessorErrorHandling
          .getErrorRateThreshold();
  if (errorRateThresholdType == null) {
    throw new ResourceConfigurationException(
            ResourceConfigurationException.MANDATORY_VALUE_MISSING, new Object[] {
                "errorRateThreshold", "CPE" },
            new Exception(CpmLocalizedMessage.getLocalizedMessage(
                    CPMUtils.CPM_LOG_RESOURCE_BUNDLE,
                    "UIMA_CPM_EXP_missing_xml_element__WARNING", new Object[] {
                        Thread.currentThread().getName(), name, "<errorRateThreshold>" })));
  }

  errorRate = errorRateThresholdType.getMaxErrorCount();
  errorSampleSize = errorRateThresholdType.getMaxErrorSampleSize();

  if (!validActionOnError(errorRateThresholdType.getAction())) {
    throw new ResourceConfigurationException(
            ResourceConfigurationException.MANDATORY_VALUE_MISSING, new Object[] { "action",
                "CPE" }, new Exception(CpmLocalizedMessage.getLocalizedMessage(
                    CPMUtils.CPM_LOG_RESOURCE_BUNDLE, "UIMA_CPM_EXP_bad_action_string__WARNING",
                    new Object[] { Thread.currentThread().getName(), name,
                        "<errorRateThreshold>", maxRestarts.getAction() })));

  }
  actionOnMaxError = errorRateThresholdType.getAction();

  CasProcessorTimeout timeoutType = casProcessorErrorHandling.getTimeout();
  timeOut = timeoutType.get();

}