Creo Elements/Direct Model Manager Customization Guide > code_examples > taskagent > SimpleModelGeometryCheckJobResultHandler.txt
SimpleModelGeometryCheckJobResultHandler.txt
/*
* SimpleModelGeometryCheckJobResultHandler.java
*
* Created on January 9, 2008
*/
package com.acme;

import java.io.File;
import java.io.IOException;

import java.util.Properties;

import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathFactory;

import org.w3c.dom.Document;

import com.osm.automation.EmailJobResultHandler;
import com.osm.automation.JobExecutionFailedException;
import com.osm.automation.JobResultOutOfDateException;
import com.osm.automation.XmlConfigurationSupport;
import com.osm.exception.WMException;



public class SimpleModelGeometryCheckJobResultHandler extends EmailJobResultHandler {
public void importJobResultData(String elementElid, Properties jobParams)
throws JobExecutionFailedException, WMException, IOException, JobResultOutOfDateException {
final SimpleModelGeometryCheckJobResultIndex index = (SimpleModelGeometryCheckJobResultIndex) getResultIndex();
if (!index.isModelOK()) {
// only send e-mail if model is not ok
super.importJobResultData(elementElid, jobParams);
}
}

@Override

protected SimpleModelGeometryCheckJobResultIndex createResultIndex(File indexXmlFile)
throws Exception {
return new SimpleModelGeometryCheckJobResultIndex(indexXmlFile);
}
// special JobResultIndex that evaluates the modelcheck attribute
private static class SimpleModelGeometryCheckJobResultIndex extends JobResultIndex {
private static String XPATH_MODEL_CHECK = "//results/@modelcheck";
private String modelcheck;

public SimpleModelGeometryCheckJobResultIndex(File xmlFile)
throws Exception {
super(xmlFile);
}

@Override
protected void parseXml(Document indexDoc) throws Exception {
super.parseXml(indexDoc);

final XPath xpath = XPathFactory.newInstance().newXPath();
this.modelcheck = xpath.evaluate(XPATH_MODEL_CHECK, indexDoc);
}

public boolean isModelOK() {
return !XmlConfigurationSupport.isEmptyString(modelcheck) && modelcheck.equals("model_ok");
}
}
}
Was this helpful?