Change the behavior of AVMService.getAVMStore() and AVMService.lookup()

methods to return null for not found instead of throwing an exception.


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/WCM-DEV2/root@3781 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Britt Park
2006-09-13 14:54:25 +00:00
parent a06fc74aef
commit 194d96082c
8 changed files with 91 additions and 76 deletions

View File

@@ -148,6 +148,10 @@ public class AVMInterpreter
}
AVMNodeDescriptor desc = fService.lookup(Integer.parseInt(command[2]),
command[1]);
if (desc == null)
{
return "Not Found.";
}
Map<String, AVMNodeDescriptor> listing =
fService.getDirectoryListing(desc);
for (String name : listing.keySet())
@@ -424,6 +428,10 @@ public class AVMInterpreter
return "Syntax Error.";
}
AVMStoreDescriptor desc = fService.getAVMStore(command[1]);
if (desc == null)
{
return "Not Found.";
}
out.println(desc);
Map<QName, PropertyValue> props =
fService.getStoreProperties(command[1]);

View File

@@ -142,15 +142,7 @@ public class AVMNodeService extends AbstractNodeServiceImpl implements NodeServi
*/
public boolean exists(StoreRef storeRef)
{
try
{
fAVMService.getAVMStore(storeRef.getIdentifier());
return true;
}
catch (AVMNotFoundException e)
{
return false;
}
return fAVMService.getAVMStore(storeRef.getIdentifier()) != null;
}
/**
@@ -162,15 +154,7 @@ public class AVMNodeService extends AbstractNodeServiceImpl implements NodeServi
Object [] avmInfo = AVMNodeConverter.ToAVMVersionPath(nodeRef);
int version = (Integer)avmInfo[0];
String avmPath = (String)avmInfo[1];
try
{
fAVMService.lookup(version, avmPath);
return true;
}
catch (AVMException e)
{
return false;
}
return fAVMService.lookup(version, avmPath) != null;
}
/**
@@ -195,15 +179,14 @@ public class AVMNodeService extends AbstractNodeServiceImpl implements NodeServi
*/
public NodeRef getRootNode(StoreRef storeRef) throws InvalidStoreRefException
{
try
String storeName = storeRef.getIdentifier();
if (fAVMService.getAVMStore(storeName) != null)
{
String storeName = storeRef.getIdentifier();
fAVMService.getAVMStore(storeName);
return AVMNodeConverter.ToNodeRef(-1, storeName + ":/");
}
catch (AVMNotFoundException e)
else
{
throw new InvalidStoreRefException(storeRef);
throw new InvalidStoreRefException("Not Found.", storeRef);
}
}
@@ -466,32 +449,28 @@ public class AVMNodeService extends AbstractNodeServiceImpl implements NodeServi
public QName getType(NodeRef nodeRef) throws InvalidNodeRefException
{
Object [] avmVersionPath = AVMNodeConverter.ToAVMVersionPath(nodeRef);
try
{
AVMNodeDescriptor desc = fAVMService.lookup((Integer)avmVersionPath[0],
(String)avmVersionPath[1]);
if (desc.isPlainDirectory())
{
return ContentModel.TYPE_AVM_PLAIN_FOLDER;
}
else if (desc.isPlainFile())
{
return ContentModel.TYPE_AVM_PLAIN_CONTENT;
}
else if (desc.isLayeredDirectory())
{
return ContentModel.TYPE_AVM_LAYERED_FOLDER;
}
else
{
return ContentModel.TYPE_AVM_LAYERED_CONTENT;
}
}
catch (AVMNotFoundException e)
AVMNodeDescriptor desc = fAVMService.lookup((Integer)avmVersionPath[0],
(String)avmVersionPath[1]);
if (desc == null)
{
throw new InvalidNodeRefException("Not Found.", nodeRef);
}
if (desc.isPlainDirectory())
{
return ContentModel.TYPE_AVM_PLAIN_FOLDER;
}
else if (desc.isPlainFile())
{
return ContentModel.TYPE_AVM_PLAIN_CONTENT;
}
else if (desc.isLayeredDirectory())
{
return ContentModel.TYPE_AVM_LAYERED_FOLDER;
}
else
{
return ContentModel.TYPE_AVM_LAYERED_CONTENT;
}
}
/**
@@ -844,13 +823,12 @@ public class AVMNodeService extends AbstractNodeServiceImpl implements NodeServi
{
Object [] avmVersionPath = AVMNodeConverter.ToAVMVersionPath(nodeRef);
Map<QName, PropertyValue> props = null;
AVMNodeDescriptor desc = null;
AVMNodeDescriptor desc = fAVMService.lookup((Integer)avmVersionPath[0],
(String)avmVersionPath[1]);
try
{
props = fAVMService.getNodeProperties((Integer)avmVersionPath[0],
(String)avmVersionPath[1]);
desc = fAVMService.lookup((Integer)avmVersionPath[0],
(String)avmVersionPath[1]);
}
catch (AVMNotFoundException e)
{
@@ -958,13 +936,9 @@ public class AVMNodeService extends AbstractNodeServiceImpl implements NodeServi
return null;
}
}
AVMNodeDescriptor desc = null;
try
{
desc = fAVMService.lookup((Integer)avmVersionPath[0],
AVMNodeDescriptor desc = fAVMService.lookup((Integer)avmVersionPath[0],
(String)avmVersionPath[1]);
}
catch (AVMNotFoundException e)
if (desc == null)
{
throw new InvalidNodeRefException("Not Found.", nodeRef);
}
@@ -1049,6 +1023,7 @@ public class AVMNodeService extends AbstractNodeServiceImpl implements NodeServi
{
throw new InvalidNodeRefException("Read only store.", nodeRef);
}
// TODO Not sure this try block is necessary.
try
{
// Invoke policy behaviors.
@@ -1063,6 +1038,10 @@ public class AVMNodeService extends AbstractNodeServiceImpl implements NodeServi
if (qName.equals(ContentModel.PROP_CONTENT))
{
AVMNodeDescriptor desc = fAVMService.lookup(-1, (String)avmVersionPath[1]);
if (desc == null)
{
throw new InvalidNodeRefException("Not Found.", nodeRef);
}
if (desc.isPlainFile())
{
fAVMService.setContentData((String)avmVersionPath[1],
@@ -1338,6 +1317,10 @@ public class AVMNodeService extends AbstractNodeServiceImpl implements NodeServi
{
AVMNodeDescriptor child = fAVMService.lookup((Integer)avmVersionPath[0],
(String)avmVersionPath[1]);
if (child == null)
{
return null;
}
return AVMNodeConverter.ToNodeRef((Integer)avmVersionPath[0],
child.getPath());
}

View File

@@ -450,6 +450,10 @@ public class AVMServiceImpl implements AVMService
*/
public AVMNodeDescriptor lookup(int version, String path)
{
if (path == null)
{
throw new AVMBadArgumentException("Illegal null path.");
}
return lookup(version, path, false);
}
@@ -471,8 +475,15 @@ public class AVMServiceImpl implements AVMService
{
throw new AVMBadArgumentException("Path is null.");
}
Lookup lookup = fAVMRepository.lookup(version, path, includeDeleted);
return lookup.getCurrentNode().getDescriptor(lookup);
try
{
Lookup lookup = fAVMRepository.lookup(version, path, includeDeleted);
return lookup.getCurrentNode().getDescriptor(lookup);
}
catch (AVMNotFoundException e)
{
return null;
}
}
/**
@@ -483,6 +494,10 @@ public class AVMServiceImpl implements AVMService
*/
public AVMNodeDescriptor lookup(AVMNodeDescriptor dir, String name)
{
if (dir == null || name == null)
{
throw new AVMBadArgumentException("Illegal null argument.");
}
return lookup(dir, name, false);
}
@@ -503,7 +518,14 @@ public class AVMServiceImpl implements AVMService
{
throw new AVMBadArgumentException("Illegal null argument.");
}
return fAVMRepository.lookup(dir, name, includeDeleted);
try
{
return fAVMRepository.lookup(dir, name, includeDeleted);
}
catch (AVMNotFoundException e)
{
return null;
}
}
/**
@@ -626,7 +648,14 @@ public class AVMServiceImpl implements AVMService
{
throw new AVMBadArgumentException("Null Store Name.");
}
return fAVMRepository.getAVMStore(name);
try
{
return fAVMRepository.getAVMStore(name);
}
catch (AVMNotFoundException e)
{
return null;
}
}
/**

View File

@@ -582,7 +582,7 @@ public class AVMStoreImpl implements AVMStore, Serializable
if (child.getType() != AVMNodeType.PLAIN_DIRECTORY &&
child.getType() != AVMNodeType.LAYERED_DIRECTORY)
{
throw new AVMWrongTypeException("Not a directory: " + pathElements[i]);
throw new AVMNotFoundException("Not a directory: " + pathElements[i]);
}
result.add(child, pathElements[i], write);
dir = (DirectoryNode)result.getCurrentNode();

View File

@@ -20,6 +20,7 @@ package org.alfresco.repo.avm;
import java.util.List;
import org.alfresco.service.cmr.avm.AVMNodeDescriptor;
import org.alfresco.service.cmr.avm.AVMNotFoundException;
import org.alfresco.service.cmr.avm.AVMService;
import org.alfresco.service.cmr.avmsync.AVMDifference;
import org.alfresco.service.cmr.avmsync.AVMSyncService;
@@ -114,6 +115,10 @@ public class AVMSyncServiceImpl implements AVMSyncService
public void resetLayer(String layerPath)
{
AVMNodeDescriptor desc = fAVMService.lookup(-1, layerPath);
if (desc == null)
{
throw new AVMNotFoundException("Not Found: " + layerPath);
}
String [] parts = AVMNodeConverter.SplitBase(layerPath);
fAVMService.removeNode(parts[0], parts[1]);
fAVMService.createLayeredDirectory(desc.getIndirection(), parts[0], parts[1]);

View File

@@ -134,21 +134,13 @@ public class AVMTestRemote extends TestCase
}
/**
* Test a call that should throw an exception.
* Test a call that should return null;
*/
public void testErrorState()
{
try
{
try
{
fAVMRemote.lookup(-1, "main:/fizz/fazz");
fail();
}
catch (AVMException e)
{
e.printStackTrace(System.out);
}
assertNull(fAVMRemote.lookup(-1, "main:/fizz/fazz"));
}
catch (Exception e)
{

View File

@@ -292,6 +292,10 @@ class AVMTester implements Runnable
String name = fNames[fgRandom.nextInt(26 * 26)];
String path = randomPath();
AVMNodeDescriptor desc = fService.lookup(-1, path);
if (desc == null)
{
return;
}
if (path.equals("main:/"))
{
return;