Search in sources :

Example 26 with DomainPath

use of org.cristalise.kernel.lookup.DomainPath in project kernel by cristal-ise.

the class DescriptionObjectCache method findItem.

public ItemPath findItem(String name) throws ObjectNotFoundException, InvalidDataException {
    if (Gateway.getLookup() == null)
        throw new ObjectNotFoundException("Cannot find Items without a Lookup");
    // first check for a UUID name
    try {
        ItemPath resItem = new ItemPath(name);
        if (resItem.exists())
            return resItem;
    } catch (InvalidItemPathException ex) {
    }
    // then check for a direct path
    DomainPath directPath = new DomainPath(name);
    if (directPath.exists() && directPath.getItemPath() != null) {
        return directPath.getItemPath();
    }
    // else search for it in the whole tree using property description
    Property[] searchProps = new Property[classIdProps.length + 1];
    searchProps[0] = new Property(NAME, name);
    System.arraycopy(classIdProps, 0, searchProps, 1, classIdProps.length);
    Iterator<Path> e = Gateway.getLookup().search(new DomainPath(), searchProps);
    if (e.hasNext()) {
        Path defPath = e.next();
        if (e.hasNext())
            throw new ObjectNotFoundException("Too many matches for " + getTypeCode() + " " + name);
        if (defPath.getItemPath() == null)
            throw new InvalidDataException(getTypeCode() + " " + name + " was found, but was not an Item");
        return defPath.getItemPath();
    } else {
        throw new ObjectNotFoundException("No match for " + getTypeCode() + " " + name);
    }
}
Also used : DomainPath(org.cristalise.kernel.lookup.DomainPath) ItemPath(org.cristalise.kernel.lookup.ItemPath) Path(org.cristalise.kernel.lookup.Path) InvalidItemPathException(org.cristalise.kernel.lookup.InvalidItemPathException) DomainPath(org.cristalise.kernel.lookup.DomainPath) ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) Property(org.cristalise.kernel.property.Property) ItemPath(org.cristalise.kernel.lookup.ItemPath)

Aggregations

DomainPath (org.cristalise.kernel.lookup.DomainPath)26 ItemPath (org.cristalise.kernel.lookup.ItemPath)15 ObjectNotFoundException (org.cristalise.kernel.common.ObjectNotFoundException)12 InvalidDataException (org.cristalise.kernel.common.InvalidDataException)11 InvalidItemPathException (org.cristalise.kernel.lookup.InvalidItemPathException)8 ObjectAlreadyExistsException (org.cristalise.kernel.common.ObjectAlreadyExistsException)5 PersistencyException (org.cristalise.kernel.common.PersistencyException)5 C2KLocalObject (org.cristalise.kernel.entity.C2KLocalObject)4 Property (org.cristalise.kernel.property.Property)4 PropertyArrayList (org.cristalise.kernel.property.PropertyArrayList)4 PropertyDescription (org.cristalise.kernel.property.PropertyDescription)4 PropertyDescriptionList (org.cristalise.kernel.property.PropertyDescriptionList)4 Aggregation (org.cristalise.kernel.collection.Aggregation)3 TraceableEntity (org.cristalise.kernel.entity.TraceableEntity)3 ItemProxy (org.cristalise.kernel.entity.proxy.ItemProxy)3 AgentPath (org.cristalise.kernel.lookup.AgentPath)3 Path (org.cristalise.kernel.lookup.Path)3 Outcome (org.cristalise.kernel.persistency.outcome.Outcome)3 Viewpoint (org.cristalise.kernel.persistency.outcome.Viewpoint)3 Test (org.junit.Test)3