Remove a few uses of ServiceRegistry where dependencies on the relevant services are cleaner, and note where the ServiceRegistry really is required

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@18781 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Nick Burch
2010-02-23 12:16:49 +00:00
parent 6241c8906e
commit a4d8f92c70
3 changed files with 58 additions and 32 deletions

View File

@@ -429,6 +429,7 @@
<property name="authorityService"> <property name="authorityService">
<ref bean="authorityService"></ref> <ref bean="authorityService"></ref>
</property> </property>
<!-- The service registry is needed as TemplateNodes are used -->
<property name="serviceRegistry"> <property name="serviceRegistry">
<ref bean="ServiceRegistry"></ref> <ref bean="ServiceRegistry"></ref>
</property> </property>
@@ -521,6 +522,7 @@
</bean> </bean>
<bean id="script" class="org.alfresco.repo.action.executer.ScriptActionExecuter" parent="action-executer"> <bean id="script" class="org.alfresco.repo.action.executer.ScriptActionExecuter" parent="action-executer">
<!-- The service registry is needed as ScriptAction needs it -->
<property name="serviceRegistry"> <property name="serviceRegistry">
<ref bean="ServiceRegistry" /> <ref bean="ServiceRegistry" />
</property> </property>

View File

@@ -27,9 +27,10 @@ import org.alfresco.repo.cache.SimpleCache;
import org.alfresco.repo.security.authentication.AuthenticationUtil; import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork; import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork;
import org.alfresco.repo.tenant.TenantService; import org.alfresco.repo.tenant.TenantService;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.repository.ContentReader; import org.alfresco.service.cmr.repository.ContentReader;
import org.alfresco.service.cmr.repository.ContentService;
import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.repository.StoreRef; import org.alfresco.service.cmr.repository.StoreRef;
import org.alfresco.service.cmr.search.SearchService; import org.alfresco.service.cmr.search.SearchService;
import org.alfresco.service.namespace.NamespaceService; import org.alfresco.service.namespace.NamespaceService;
@@ -56,8 +57,11 @@ public class MessageServiceImpl implements MessageService
private Lock writeLock = lock.writeLock(); private Lock writeLock = lock.writeLock();
// dependencies // dependencies
private ServiceRegistry serviceRegistry;
private TenantService tenantService; private TenantService tenantService;
private SearchService searchService;
private ContentService contentService;
private NamespaceService namespaceService;
private NodeService nodeService;
/** /**
* List of registered bundles * List of registered bundles
@@ -77,10 +81,18 @@ public class MessageServiceImpl implements MessageService
private List<MessageDeployer> messageDeployers = new ArrayList<MessageDeployer>(); private List<MessageDeployer> messageDeployers = new ArrayList<MessageDeployer>();
public void setNamespaceService(NamespaceService namespaceService)
public void setServiceRegistry(ServiceRegistry serviceRegistry)
{ {
this.serviceRegistry = serviceRegistry; this.namespaceService = namespaceService;
}
public void setSearchService(SearchService searchService) {
this.searchService = searchService;
}
public void setNodeService(NodeService nodeService)
{
this.nodeService = nodeService;
} }
public void setTenantService(TenantService tenantService) public void setTenantService(TenantService tenantService)
@@ -88,6 +100,11 @@ public class MessageServiceImpl implements MessageService
this.tenantService = tenantService; this.tenantService = tenantService;
} }
public void setContentService(ContentService contentService)
{
this.contentService = contentService;
}
public void setResourceBundleBaseNamesCache(SimpleCache<String, Set<String>> resourceBundleBaseNamesCache) public void setResourceBundleBaseNamesCache(SimpleCache<String, Set<String>> resourceBundleBaseNamesCache)
{ {
this.resourceBundleBaseNamesCache = resourceBundleBaseNamesCache; this.resourceBundleBaseNamesCache = resourceBundleBaseNamesCache;
@@ -538,18 +555,15 @@ public class MessageServiceImpl implements MessageService
// search & instantiation strategy similar to ResourceBundle.getBundle() // search & instantiation strategy similar to ResourceBundle.getBundle()
// Consider search query with basename* and then apply strategy ... // Consider search query with basename* and then apply strategy ...
SearchService searchService = serviceRegistry.getSearchService(); NodeRef rootNode = nodeService.getRootNode(storeRef);
NamespaceService resolver = serviceRegistry.getNamespaceService();
NodeRef rootNode = serviceRegistry.getNodeService().getRootNode(storeRef);
// first attempt - with locale // first attempt - with locale
List<NodeRef> nodeRefs = searchService.selectNodes(rootNode, path+"_"+locale+PROPERTIES_FILE_SUFFIX, null, resolver, false); List<NodeRef> nodeRefs = searchService.selectNodes(rootNode, path+"_"+locale+PROPERTIES_FILE_SUFFIX, null, namespaceService, false);
if ((nodeRefs == null) || (nodeRefs.size() == 0)) if ((nodeRefs == null) || (nodeRefs.size() == 0))
{ {
// second attempt - basename // second attempt - basename
nodeRefs = searchService.selectNodes(rootNode, path+PROPERTIES_FILE_SUFFIX, null, resolver, false); nodeRefs = searchService.selectNodes(rootNode, path+PROPERTIES_FILE_SUFFIX, null, namespaceService, false);
if ((nodeRefs == null) || (nodeRefs.size() == 0)) if ((nodeRefs == null) || (nodeRefs.size() == 0))
{ {
@@ -566,7 +580,7 @@ public class MessageServiceImpl implements MessageService
{ {
NodeRef messageResourceNodeRef = nodeRefs.get(0); NodeRef messageResourceNodeRef = nodeRefs.get(0);
ContentReader cr = serviceRegistry.getContentService().getReader(messageResourceNodeRef, ContentModel.PROP_CONTENT); ContentReader cr = contentService.getReader(messageResourceNodeRef, ContentModel.PROP_CONTENT);
resBundle = new MessagePropertyResourceBundle(new InputStreamReader(cr.getContentInputStream(), cr.getEncoding())); resBundle = new MessagePropertyResourceBundle(new InputStreamReader(cr.getContentInputStream(), cr.getEncoding()));
} }

View File

@@ -32,10 +32,13 @@ import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransacti
import org.alfresco.service.ServiceRegistry; import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.action.Action; import org.alfresco.service.cmr.action.Action;
import org.alfresco.service.cmr.action.ActionDefinition; import org.alfresco.service.cmr.action.ActionDefinition;
import org.alfresco.service.cmr.action.ActionService;
import org.alfresco.service.cmr.action.ParameterDefinition; import org.alfresco.service.cmr.action.ParameterDefinition;
import org.alfresco.service.cmr.dictionary.DataTypeDefinition; import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName; import org.alfresco.service.namespace.QName;
import org.alfresco.service.transaction.TransactionService;
import org.mozilla.javascript.Scriptable; import org.mozilla.javascript.Scriptable;
import org.mozilla.javascript.Wrapper; import org.mozilla.javascript.Wrapper;
@@ -54,13 +57,16 @@ public final class ScriptAction implements Serializable, Scopeable
/** Converter with knowledge of action parameter values */ /** Converter with knowledge of action parameter values */
private ActionValueConverter converter; private ActionValueConverter converter;
private ServiceRegistry services;
/** Action state */ /** Action state */
private Action action; private Action action;
private ActionDefinition actionDef; private ActionDefinition actionDef;
private ServiceRegistry services;
private ActionService actionService;
private NamespaceService namespaceService;
private TransactionService transactionService;
private ScriptableParameterMap<String, Serializable> parameters = null; private ScriptableParameterMap<String, Serializable> parameters = null;
/** /**
@@ -72,6 +78,10 @@ public final class ScriptAction implements Serializable, Scopeable
public ScriptAction(ServiceRegistry services, Action action, ActionDefinition actionDef) public ScriptAction(ServiceRegistry services, Action action, ActionDefinition actionDef)
{ {
this.services = services; this.services = services;
this.actionService = services.getActionService();
this.namespaceService = services.getNamespaceService();
this.transactionService = services.getTransactionService();
this.action = action; this.action = action;
this.actionDef = actionDef; this.actionDef = actionDef;
this.converter = new ActionValueConverter(); this.converter = new ActionValueConverter();
@@ -141,7 +151,7 @@ public final class ScriptAction implements Serializable, Scopeable
actionParams.put(name, value); actionParams.put(name, value);
} }
} }
services.getActionService().executeAction(action, node.getNodeRef()); actionService.executeAction(action, node.getNodeRef());
// Parameters may have been updated by action execution, so reset cache // Parameters may have been updated by action execution, so reset cache
this.parameters = null; this.parameters = null;
@@ -180,11 +190,11 @@ public final class ScriptAction implements Serializable, Scopeable
{ {
public Object execute() throws Throwable public Object execute() throws Throwable
{ {
services.getActionService().executeAction(action, node.getNodeRef()); actionService.executeAction(action, node.getNodeRef());
return null; return null;
} }
}; };
services.getTransactionService().getRetryingTransactionHelper().doInTransaction( transactionService.getRetryingTransactionHelper().doInTransaction(
executionActionCallback, executionActionCallback,
readOnly, readOnly,
newTxn); newTxn);
@@ -218,7 +228,7 @@ public final class ScriptAction implements Serializable, Scopeable
actionParams.put(name, value); actionParams.put(name, value);
} }
} }
services.getActionService().executeAction(action, nodeRef); actionService.executeAction(action, nodeRef);
// Parameters may have been updated by action execution, so reset cache // Parameters may have been updated by action execution, so reset cache
this.parameters = null; this.parameters = null;
@@ -254,11 +264,11 @@ public final class ScriptAction implements Serializable, Scopeable
{ {
public Object execute() throws Throwable public Object execute() throws Throwable
{ {
services.getActionService().executeAction(action, nodeRef); actionService.executeAction(action, nodeRef);
return null; return null;
} }
}; };
services.getTransactionService().getRetryingTransactionHelper().doInTransaction( transactionService.getRetryingTransactionHelper().doInTransaction(
executionActionCallback, executionActionCallback,
readOnly, readOnly,
newTxn); newTxn);
@@ -289,7 +299,7 @@ public final class ScriptAction implements Serializable, Scopeable
ParameterDefinition paramDef = actionDef.getParameterDefintion(paramName); ParameterDefinition paramDef = actionDef.getParameterDefintion(paramName);
if (paramDef != null && paramDef.getType().equals(DataTypeDefinition.QNAME)) if (paramDef != null && paramDef.getType().equals(DataTypeDefinition.QNAME))
{ {
return ((QName) value).toPrefixString(services.getNamespaceService()); return ((QName) value).toPrefixString(namespaceService);
} }
else else
{ {
@@ -331,7 +341,7 @@ public final class ScriptAction implements Serializable, Scopeable
} }
else else
{ {
return QName.createQName(stringQName, services.getNamespaceService()); return QName.createQName(stringQName, namespaceService);
} }
} }
else else