Search in sources :

Example 41 with PersistencyException

use of org.cristalise.kernel.common.PersistencyException in project kernel by cristal-ise.

the class XMLClusterStorage method get.

@Override
public C2KLocalObject get(ItemPath itemPath, String path) throws PersistencyException {
    try {
        ClusterType type = ClusterStorage.getClusterType(path);
        String filePath = getFilePath(itemPath, path) + fileExtension;
        String objString = FileStringUtility.file2String(filePath);
        if (objString.length() == 0)
            return null;
        Logger.debug(9, "XMLClusterStorage.get() - objString:" + objString);
        if (type == ClusterType.OUTCOME)
            return new Outcome(path, objString);
        else
            return (C2KLocalObject) Gateway.getMarshaller().unmarshall(objString);
    } catch (Exception e) {
        Logger.msg(3, "XMLClusterStorage.get() - The path " + path + " from " + itemPath + " does not exist: " + e.getMessage());
        Logger.error(e);
        throw new PersistencyException(e.getMessage());
    }
}
Also used : Outcome(org.cristalise.kernel.persistency.outcome.Outcome) PersistencyException(org.cristalise.kernel.common.PersistencyException) ClusterType(org.cristalise.kernel.persistency.ClusterType) IOException(java.io.IOException) PersistencyException(org.cristalise.kernel.common.PersistencyException)

Example 42 with PersistencyException

use of org.cristalise.kernel.common.PersistencyException in project kernel by cristal-ise.

the class XMLClusterStorage method put.

@Override
public void put(ItemPath itemPath, C2KLocalObject obj) throws PersistencyException {
    try {
        String filePath = getFilePath(itemPath, getPath(obj) + fileExtension);
        Logger.msg(7, "XMLClusterStorage.put() - Writing " + filePath);
        String data = Gateway.getMarshaller().marshall(obj);
        String dir = filePath.substring(0, filePath.lastIndexOf('/'));
        if (!FileStringUtility.checkDir(dir)) {
            boolean success = FileStringUtility.createNewDir(dir);
            if (!success)
                throw new PersistencyException("XMLClusterStorage.put() - Could not create dir " + dir + ". Cannot continue.");
        }
        FileStringUtility.string2File(filePath, data);
    } catch (Exception e) {
        Logger.error(e);
        throw new PersistencyException("XMLClusterStorage.put() - Could not write " + getPath(obj) + " to " + itemPath);
    }
}
Also used : PersistencyException(org.cristalise.kernel.common.PersistencyException) IOException(java.io.IOException) PersistencyException(org.cristalise.kernel.common.PersistencyException)

Example 43 with PersistencyException

use of org.cristalise.kernel.common.PersistencyException in project kernel by cristal-ise.

the class ProxyLoader method getIOR.

private Item getIOR(ItemPath thisPath) throws PersistencyException {
    // check the cache
    if (entities.containsKey(thisPath)) {
        Logger.msg(8, "ProxyLoader.getIOR() - " + thisPath + " cached.");
        return entities.get(thisPath);
    }
    try {
        Logger.msg(8, "ProxyLoader.getIOR() - Resolving " + thisPath + ".");
        org.omg.CORBA.Object ior = thisPath.getIOR();
        Item thisItem = null;
        try {
            thisItem = ItemHelper.narrow(ior);
        } catch (org.omg.CORBA.BAD_PARAM ex) {
            try {
                thisItem = AgentHelper.narrow(ior);
            } catch (org.omg.CORBA.BAD_PARAM ex2) {
                throw new PersistencyException("Could not narrow " + thisItem + " as a known Entity type");
            }
        }
        Logger.msg(8, "ProxyLoader.getIOR() - Found " + thisItem + ".");
        entities.put(thisPath, thisItem);
        return thisItem;
    } catch (Exception e) {
        throw new PersistencyException("Error narrowing " + thisPath + ": " + e.getMessage());
    }
}
Also used : Item(org.cristalise.kernel.entity.Item) PersistencyException(org.cristalise.kernel.common.PersistencyException) PersistencyException(org.cristalise.kernel.common.PersistencyException) ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException)

Aggregations

PersistencyException (org.cristalise.kernel.common.PersistencyException)43 InvalidDataException (org.cristalise.kernel.common.InvalidDataException)26 ObjectNotFoundException (org.cristalise.kernel.common.ObjectNotFoundException)26 ObjectAlreadyExistsException (org.cristalise.kernel.common.ObjectAlreadyExistsException)10 IOException (java.io.IOException)9 Viewpoint (org.cristalise.kernel.persistency.outcome.Viewpoint)9 C2KLocalObject (org.cristalise.kernel.entity.C2KLocalObject)8 InvalidItemPathException (org.cristalise.kernel.lookup.InvalidItemPathException)8 AccessRightsException (org.cristalise.kernel.common.AccessRightsException)6 CannotManageException (org.cristalise.kernel.common.CannotManageException)6 ItemPath (org.cristalise.kernel.lookup.ItemPath)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 ObjectCannotBeUpdated (org.cristalise.kernel.common.ObjectCannotBeUpdated)5 History (org.cristalise.kernel.events.History)5 AgentPath (org.cristalise.kernel.lookup.AgentPath)5 DomainPath (org.cristalise.kernel.lookup.DomainPath)5 ArrayList (java.util.ArrayList)4