use of org.cristalise.kernel.common.InvalidDataException in project kernel by cristal-ise.
the class Gateway method init.
/**
* Initialises the Gateway and all of the client objects it holds, with
* the exception of the Lookup, which is initialised during connect()
*
* @param props - java.util.Properties containing all application properties.
* If null, the java system properties are used
* @param res - ResourceLoader for the kernel to use to resolve all class resource requests
* such as for bootstrap descriptions and version information
* @throws InvalidDataException - invalid properties caused a failure in initialisation
*/
public static void init(Properties props, ResourceLoader res) throws InvalidDataException {
// Init properties & resources
mC2KProps.clear();
orbDestroyed = false;
mResource = res;
if (mResource == null)
mResource = new Resource();
// report version info
Logger.msg("Gateway.init() - Kernel version: " + getKernelVersion());
// the application to be able to configure castor
try {
mMarshaller = new CastorXMLUtility(mResource, props, mResource.getKernelResourceURL("mapFiles/"));
} catch (MalformedURLException e1) {
throw new InvalidDataException("Invalid Resource Location");
}
Properties allModuleProperties;
// init module manager
try {
mModules = new ModuleManager(AbstractMain.isServer);
allModuleProperties = mModules.loadModules(mResource.getModuleDefURLs());
} catch (Exception e) {
Logger.error(e);
throw new InvalidDataException("Could not load module definitions.");
}
// merge in module props
for (Enumeration<?> e = allModuleProperties.propertyNames(); e.hasMoreElements(); ) {
String propName = (String) e.nextElement();
mC2KProps.put(propName, allModuleProperties.get(propName));
}
// Overwrite with argument props
if (props != null)
mC2KProps.putAll(props);
// dump properties
Logger.msg("Gateway.init() - DONE");
dumpC2KProps(7);
}
use of org.cristalise.kernel.common.InvalidDataException in project kernel by cristal-ise.
the class StandardClient method login.
/**
* @param agentName
* @param agentPass
* @param resource
* @throws InvalidDataException
*/
protected void login(String agentName, String agentPass, String resource) throws InvalidDataException {
// login - try for a while in case server hasn't imported our agent yet
for (int i = 1; i < 6; i++) {
try {
Logger.msg("Login attempt " + i + " of 5");
agent = Gateway.connect(agentName, agentPass, resource);
break;
} catch (Exception ex) {
Logger.error("Could not log in.");
Logger.error(ex);
try {
Thread.sleep(5000);
} catch (InterruptedException ex2) {
}
}
}
if (agent == null)
throw new InvalidDataException("Could not login agent:" + agentName);
}
use of org.cristalise.kernel.common.InvalidDataException in project kernel by cristal-ise.
the class Outcome method serialize.
/**
* Serialize the Given Document
*
* @param doc document to be serialized
* @param prettyPrint if the xml is pretty printed or not
* @return the xml string
* @throws InvalidDataException Transformer Exception
*/
public static String serialize(Document doc, boolean prettyPrint) throws InvalidDataException {
TransformerFactory tf = TransformerFactory.newInstance();
Transformer transformer;
try {
transformer = tf.newTransformer();
} catch (TransformerConfigurationException ex) {
Logger.error(ex);
return "";
}
transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
transformer.setOutputProperty(OutputKeys.INDENT, prettyPrint ? "yes" : "no");
transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
Writer out = new StringWriter();
try {
transformer.transform(new DOMSource(doc), new StreamResult(out));
} catch (Exception e) {
Logger.error(e);
throw new InvalidDataException(e.getMessage());
}
return out.toString();
}
use of org.cristalise.kernel.common.InvalidDataException in project kernel by cristal-ise.
the class Outcome method setFieldByXPath.
/**
* Sets the text, CDATA or attribute value of the Node selected by the XPath. It only updates existing Nodes.
* If data is null and the node exists, the node is removed
*
* @param xpath the selected Node to be updated
* @param data string containing the data, it can be null
* @param remove flag to remove existing node when data is null
* @throws XPathExpressionException xpath is invalid
* @throws InvalidDataException xpath result is not text, CDATA or attribute
*/
public void setFieldByXPath(String xpath, String data, boolean remove) throws XPathExpressionException, InvalidDataException {
if (StringUtils.isBlank(xpath))
throw new InvalidDataException("Xpath is null or empty string");
if (data == null && remove) {
Logger.msg(7, "Outcome.setFieldByXPath() - removing field xpath");
removeNodeByXPath(xpath);
return;
}
// Setting nodeValue to null could corrupt document
if (data == null)
data = "";
Node field = getNodeByXPath(xpath);
if (field == null) {
Logger.error(getData());
throw new InvalidDataException("Xpath '" + xpath + "' is invalid");
} else
setNodeValue(field, data);
}
use of org.cristalise.kernel.common.InvalidDataException in project kernel by cristal-ise.
the class DataHelperUtility method evaluateValue.
/**
* If the
*
* @param itemPath the actual Item context
* @param value the value to be evaluated
* @param actContext activity path
* @param locker database transaction locker
* @return String value which was evaluated using {@link DataHelper} implementation
*
* @throws InvalidDataException data inconsistency
* @throws PersistencyException persistency issue
* @throws ObjectNotFoundException object was not found
*/
public static Object evaluateValue(ItemPath itemPath, Object value, String actContext, Object locker) throws InvalidDataException, PersistencyException, ObjectNotFoundException {
if (value == null || !(value instanceof String) || !((String) value).contains("//"))
return value;
if (itemPath == null)
throw new InvalidDataException("DataHelper must have ItemPath initialised");
// Finding the first occurrence of '//' because DataHelper uses XPath which can start with '//'
int i = ((String) value).indexOf("//");
if (i == -1)
throw new InvalidDataException("DataHelperUtility.evaluateValue() - Cannot locate '//' in value:" + value);
String pathType = ((String) value).substring(0, i);
String dataPath = ((String) value).substring(i + 2);
Logger.msg(5, "DataHelperUtility.evaluateValue() - pathType:" + pathType + " dataPath:" + dataPath);
DataHelper dataHelper = getDataHelper(pathType);
if (dataHelper != null)
return dataHelper.get(itemPath, actContext, dataPath, locker);
else
return value;
}
Aggregations