Search in sources :

Example 16 with InvalidDataException

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);
}
Also used : MalformedURLException(java.net.MalformedURLException) Resource(org.cristalise.kernel.process.resource.Resource) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) ObjectProperties(org.cristalise.kernel.utils.ObjectProperties) Properties(java.util.Properties) ModuleManager(org.cristalise.kernel.process.module.ModuleManager) CastorXMLUtility(org.cristalise.kernel.utils.CastorXMLUtility) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException) MalformedURLException(java.net.MalformedURLException) PersistencyException(org.cristalise.kernel.common.PersistencyException) CannotManageException(org.cristalise.kernel.common.CannotManageException)

Example 17 with InvalidDataException

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);
}
Also used : InvalidDataException(org.cristalise.kernel.common.InvalidDataException) InvalidDataException(org.cristalise.kernel.common.InvalidDataException)

Example 18 with InvalidDataException

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();
}
Also used : DOMSource(javax.xml.transform.dom.DOMSource) TransformerFactory(javax.xml.transform.TransformerFactory) Transformer(javax.xml.transform.Transformer) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) StringWriter(java.io.StringWriter) StreamResult(javax.xml.transform.stream.StreamResult) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) StringWriter(java.io.StringWriter) Writer(java.io.Writer) XPathExpressionException(javax.xml.xpath.XPathExpressionException) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) IOException(java.io.IOException) PersistencyException(org.cristalise.kernel.common.PersistencyException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException)

Example 19 with InvalidDataException

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);
}
Also used : Node(org.w3c.dom.Node) InvalidDataException(org.cristalise.kernel.common.InvalidDataException)

Example 20 with InvalidDataException

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;
}
Also used : InvalidDataException(org.cristalise.kernel.common.InvalidDataException)

Aggregations

InvalidDataException (org.cristalise.kernel.common.InvalidDataException)91 ObjectNotFoundException (org.cristalise.kernel.common.ObjectNotFoundException)40 PersistencyException (org.cristalise.kernel.common.PersistencyException)33 IOException (java.io.IOException)14 ObjectAlreadyExistsException (org.cristalise.kernel.common.ObjectAlreadyExistsException)11 InvalidItemPathException (org.cristalise.kernel.lookup.InvalidItemPathException)11 DomainPath (org.cristalise.kernel.lookup.DomainPath)10 Viewpoint (org.cristalise.kernel.persistency.outcome.Viewpoint)9 CannotManageException (org.cristalise.kernel.common.CannotManageException)8 AgentPath (org.cristalise.kernel.lookup.AgentPath)8 Schema (org.cristalise.kernel.persistency.outcome.Schema)8 AccessRightsException (org.cristalise.kernel.common.AccessRightsException)7 ItemPath (org.cristalise.kernel.lookup.ItemPath)7 C2KLocalObject (org.cristalise.kernel.entity.C2KLocalObject)6 Outcome (org.cristalise.kernel.persistency.outcome.Outcome)6 MappingException (org.exolab.castor.mapping.MappingException)6 MarshalException (org.exolab.castor.xml.MarshalException)6 ValidationException (org.exolab.castor.xml.ValidationException)6 ArrayList (java.util.ArrayList)5 XPathExpressionException (javax.xml.xpath.XPathExpressionException)5