diff --git a/source/java/org/alfresco/jcr/dictionary/JCRNamespacePrefixResolver.java b/source/java/org/alfresco/jcr/dictionary/JCRNamespacePrefixResolver.java index 8c0d5cc772..e53d450621 100644 --- a/source/java/org/alfresco/jcr/dictionary/JCRNamespacePrefixResolver.java +++ b/source/java/org/alfresco/jcr/dictionary/JCRNamespacePrefixResolver.java @@ -42,6 +42,8 @@ import org.alfresco.service.namespace.NamespaceService; */ public class JCRNamespacePrefixResolver implements NamespaceService { + private static final long serialVersionUID = -2451839324143403283L; + // delegate private NamespacePrefixResolver delegate; diff --git a/source/java/org/alfresco/repo/avm/Issuer.java b/source/java/org/alfresco/repo/avm/Issuer.java index 07219d56d2..3693b14661 100644 --- a/source/java/org/alfresco/repo/avm/Issuer.java +++ b/source/java/org/alfresco/repo/avm/Issuer.java @@ -72,6 +72,21 @@ public class Issuer * After the database is up, get our value. */ public void initialize() + { + getNextId(); + } + + /** + * Issue the next number. + * @return A serial number. + */ + public synchronized long issue() + { + + return getNextId(); + } + + private long getNextId() { class TxnWork implements RetryingTransactionCallback { @@ -89,14 +104,6 @@ public class Issuer { fNext = result + 1L; } - } - - /** - * Issue the next number. - * @return A serial number. - */ - public synchronized long issue() - { - return fNext++; + return fNext; } } diff --git a/source/java/org/alfresco/repo/dictionary/DictionaryNamespaceComponent.java b/source/java/org/alfresco/repo/dictionary/DictionaryNamespaceComponent.java index 703264e123..f929e9705f 100644 --- a/source/java/org/alfresco/repo/dictionary/DictionaryNamespaceComponent.java +++ b/source/java/org/alfresco/repo/dictionary/DictionaryNamespaceComponent.java @@ -37,6 +37,7 @@ import org.alfresco.service.namespace.NamespaceService; public class DictionaryNamespaceComponent implements NamespaceService { + private static final long serialVersionUID = -3774701459465102431L; /** * Namespace DAO */ diff --git a/source/java/org/alfresco/repo/dictionary/NamespaceDAOImpl.java b/source/java/org/alfresco/repo/dictionary/NamespaceDAOImpl.java index 39ffef74c6..44bceeb3a0 100644 --- a/source/java/org/alfresco/repo/dictionary/NamespaceDAOImpl.java +++ b/source/java/org/alfresco/repo/dictionary/NamespaceDAOImpl.java @@ -1,543 +1,545 @@ -/* - * Copyright (C) 2005-2007 Alfresco Software Limited. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - - * As a special exception to the terms and conditions of version 2.0 of - * the GPL, you may redistribute this Program in connection with Free/Libre - * and Open Source Software ("FLOSS") applications as described in Alfresco's - * FLOSS exception. You should have recieved a copy of the text describing - * the FLOSS exception, and it is also available here: - * http://www.alfresco.com/legal/licensing" - */ -package org.alfresco.repo.dictionary; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.concurrent.locks.Lock; -import java.util.concurrent.locks.ReadWriteLock; -import java.util.concurrent.locks.ReentrantReadWriteLock; - -import org.alfresco.error.AlfrescoRuntimeException; -import org.alfresco.repo.cache.SimpleCache; -import org.alfresco.repo.tenant.TenantService; -import org.alfresco.service.namespace.NamespaceException; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -/** - * Simple in-memory namespace DAO - */ -public class NamespaceDAOImpl implements NamespaceDAO -{ - private static final Log logger = LogFactory.getLog(NamespaceDAOImpl.class); - - /** - * Lock objects - */ - private ReadWriteLock lock = new ReentrantReadWriteLock(); - private Lock readLock = lock.readLock(); - private Lock writeLock = lock.writeLock(); - - // internal caches that are clusterable - private SimpleCache> urisCache; - private SimpleCache> prefixesCache; - - // Dependencies - private TenantService tenantService; - - - public void setTenantService(TenantService tenantService) - { - this.tenantService = tenantService; - } - - public void setUrisCache(SimpleCache> urisCache) - { - this.urisCache = urisCache; - } - - public void setPrefixesCache(SimpleCache> prefixesCache) - { - this.prefixesCache = prefixesCache; - } - - - private DictionaryDAO dictionaryDAO; - - public void registerDictionary(DictionaryDAO dictionaryDAO) - { - this.dictionaryDAO = dictionaryDAO; - } - - - /** - * Initialise empty namespaces - */ - public void init() - { - String tenantDomain = getTenantDomain(); - - putUrisCtx(tenantDomain, new ArrayList()); - putPrefixesCtx(tenantDomain, new HashMap()); - - if (logger.isDebugEnabled()) - { - logger.debug("Empty namespaces initialised"); - } - } - - /** - * Destroy the namespaces - */ - public void destroy() - { - String tenantDomain = getTenantDomain(); - - removeUrisCtx(tenantDomain); - removePrefixesCtx(tenantDomain); - - if (logger.isDebugEnabled()) - { - logger.debug("Namespaces destroyed"); - } - } - - /** - * Resets the namespaces (by resetting the dictionary) - */ - private void reset() - { - if (logger.isDebugEnabled()) - { - logger.debug("Resetting namespaces ..."); - } - - if (dictionaryDAO == null) - { - // Unexpected - throw new AlfrescoRuntimeException("Dictionary should be registered in order to perform reset"); - } - else - { - dictionaryDAO.reset(); - } - - if (logger.isDebugEnabled()) - { - logger.debug("... resetting namespaces completed"); - } - } - - /* (non-Javadoc) - * @see org.alfresco.repo.ref.NamespacePrefixResolver#getURIs() - */ - public Collection getURIs() - { - if (! tenantService.isTenantUser()) - { - return Collections.unmodifiableCollection(getUrisCtx()); - } - else - { - // Get tenant-specific URIs - List domainUris = getUrisCtx(); - - // Get non-tenant-specific URIs (and filter out, if overridden) - List urisFiltered = new ArrayList(); - for(String uri : getUrisCtx("")) - { - if (domainUris.contains(uri)) - { - // overridden, hence skip this default prefix - continue; - } - urisFiltered.add(uri); - } - - // default (non-overridden) + tenant-specific - urisFiltered.addAll(domainUris); - - return Collections.unmodifiableCollection(urisFiltered); - } - } - - - /* (non-Javadoc) - * @see org.alfresco.repo.ref.NamespacePrefixResolver#getPrefixes() - */ - public Collection getPrefixes() - { - if (! tenantService.isTenantUser()) - { - return Collections.unmodifiableCollection(getPrefixesCtx().keySet()); - } - else - { - // Get tenant-specific prefixes - Collection domainPrefixes = getPrefixesCtx().keySet(); - - // Get non-tenant-specific URIs (and filter out, if overridden) - List prefixesFiltered = new ArrayList(); - for(String prefix : getPrefixesCtx("").keySet()) - { - if (domainPrefixes.contains(prefix)) - { - // overridden, hence skip this default prefix - continue; - } - prefixesFiltered.add(prefix); - } - - // default (non-overridden) + tenant-specific - prefixesFiltered.addAll(domainPrefixes); - - return Collections.unmodifiableCollection(prefixesFiltered); - } - } - - - /* (non-Javadoc) - * @see org.alfresco.repo.dictionary.impl.NamespaceDAO#addURI(java.lang.String) - */ - public void addURI(String uri) - { - if (getUrisCtx().contains(uri)) - { - throw new NamespaceException("URI " + uri + " has already been defined"); - } - getUrisCtx().add(uri); - } - - - /* (non-Javadoc) - * @see org.alfresco.repo.dictionary.impl.NamespaceDAO#addPrefix(java.lang.String, java.lang.String) - */ - public void addPrefix(String prefix, String uri) - { - if (!getUrisCtx().contains(uri)) - { - throw new NamespaceException("Namespace URI " + uri + " does not exist"); - } - getPrefixesCtx().put(prefix, uri); - } - - - /* (non-Javadoc) - * @see org.alfresco.repo.dictionary.impl.NamespaceDAO#removeURI(java.lang.String) - */ - public void removeURI(String uri) - { - getUrisCtx().remove(uri); - } - - - /* (non-Javadoc) - * @see org.alfresco.repo.dictionary.impl.NamespaceDAO#removePrefix(java.lang.String) - */ - public void removePrefix(String prefix) - { - getPrefixesCtx().remove(prefix); - } - - - /* (non-Javadoc) - * @see org.alfresco.repo.ref.NamespacePrefixResolver#getNamespaceURI(java.lang.String) - */ - public String getNamespaceURI(String prefix) - { - if (! tenantService.isTenantUser()) - { - return getPrefixesCtx().get(prefix); - } - else - { - // first look for tenant-specific prefix - String uri = getPrefixesCtx().get(prefix); - if (uri != null) - { - // found tenant specific uri - return uri; - } - else - { - // try with default (non-tenant-specific) prefix - return getPrefixesCtx("").get(prefix); - } - } - } - - - /* (non-Javadoc) - * @see org.alfresco.repo.ref.NamespacePrefixResolver#getPrefixes(java.lang.String) - */ - public Collection getPrefixes(String URI) - { - if (! tenantService.isTenantUser()) - { - Collection uriPrefixes = new ArrayList(); - for (String key : getPrefixesCtx().keySet()) - { - String uri = getPrefixesCtx().get(key); - if ((uri != null) && (uri.equals(URI))) - { - uriPrefixes.add(key); - } - } - return uriPrefixes; - } - else - { - // check domain prefixes - Collection domainUriPrefixes = new ArrayList(); - for (String key : getPrefixesCtx().keySet()) - { - String uri = getPrefixesCtx().get(key); - if ((uri != null) && (uri.equals(URI))) - { - domainUriPrefixes.add(key); - } - } - - // check non-domain prefixes - Collection uriPrefixes = new ArrayList(); - for (String key : getPrefixesCtx("").keySet()) - { - String uri = getPrefixesCtx("").get(key); - if ((uri != null) && (uri.equals(URI))) - { - if (domainUriPrefixes != null) - { - if (domainUriPrefixes.contains(key)) - { - // overridden, hence skip this default prefix - continue; - } - } - - uriPrefixes.add(key); - } - } - - if (domainUriPrefixes != null) - { - // default (non-overridden) + domain - uriPrefixes.addAll(domainUriPrefixes); - } - - return uriPrefixes; - } - } - - /** - * Get URIs from the cache (in the context of the current user's tenant domain) - * - * @return URIs - */ - private List getUrisCtx() - { - return getUrisCtx(getTenantDomain()); - } - - /** - * Get URIs from the cache - * - * @param tenantDomain - * @return URIs - */ - private List getUrisCtx(String tenantDomain) - { - List uris = null; - try - { - readLock.lock(); - uris = urisCache.get(tenantDomain); - } - finally - { - readLock.unlock(); - } - - - if (uris == null) - { - reset(); // reset caches - may have been invalidated (e.g. in a cluster) - - try - { - readLock.lock(); - uris = urisCache.get(tenantDomain); - } - finally - { - readLock.unlock(); - } - - if (uris == null) - { - // unexpected - throw new AlfrescoRuntimeException("Failed to re-initialise urisCache " + tenantDomain); - } - } - return uris; - } - - /** - * Put URIs into the cache - * - * @param tenantDomain - * @param uris - */ - private void putUrisCtx(String tenantDomain, List uris) - { - try - { - writeLock.lock(); - urisCache.put(tenantDomain, uris); - } - finally - { - writeLock.unlock(); - } - } - - /** - * Remove URIs from the cache - * - * @param tenantDomain - */ - private void removeUrisCtx(String tenantDomain) - { - try - { - writeLock.lock(); - if (urisCache.get(tenantDomain) != null) - { - urisCache.get(tenantDomain).clear(); - urisCache.remove(tenantDomain); - } - } - finally - { - writeLock.unlock(); - } - } - - /** - * Get prefixes from the cache - * - * @return prefixes - */ - private Map getPrefixesCtx() - { - return getPrefixesCtx(getTenantDomain()); - } - - /** - * Get prefixes from the cache - * - * @param tenantDomain - * @return prefixes - */ - private Map getPrefixesCtx(String tenantDomain) - { - Map prefixes = null; - try - { - readLock.lock(); - prefixes = prefixesCache.get(tenantDomain); - } - finally - { - readLock.unlock(); - } - - if (prefixes == null) - { - reset(); // reset caches - may have been invalidated (e.g. in a cluster) - - try - { - readLock.lock(); - prefixes = prefixesCache.get(tenantDomain); - } - finally - { - readLock.unlock(); - } - - if (prefixes == null) - { - // unexpected - throw new AlfrescoRuntimeException("Failed to re-initialise prefixesCache " + tenantDomain); - } - } - - return prefixes; - } - - /** - * Put prefixes into the cache - * - * @param tenantDomain - * @param prefixes - */ - private void putPrefixesCtx(String tenantDomain, Map prefixes) - { - try - { - writeLock.lock(); - prefixesCache.put(tenantDomain, prefixes); - } - finally - { - writeLock.unlock(); - } - } - - /** - * Remove prefixes from the cache - * - * @param tenantDomain - */ - private void removePrefixesCtx(String tenantDomain) - { - try - { - writeLock.lock(); - if (prefixesCache.get(tenantDomain) != null) - { - prefixesCache.get(tenantDomain).clear(); - prefixesCache.remove(tenantDomain); - } - } - finally - { - writeLock.unlock(); - } - } - - /** - * Local helper - returns tenant domain (or empty string if default non-tenant) - */ - private String getTenantDomain() - { - return tenantService.getCurrentUserDomain(); - } -} +/* + * Copyright (C) 2005-2007 Alfresco Software Limited. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + * As a special exception to the terms and conditions of version 2.0 of + * the GPL, you may redistribute this Program in connection with Free/Libre + * and Open Source Software ("FLOSS") applications as described in Alfresco's + * FLOSS exception. You should have recieved a copy of the text describing + * the FLOSS exception, and it is also available here: + * http://www.alfresco.com/legal/licensing" + */ +package org.alfresco.repo.dictionary; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.locks.Lock; +import java.util.concurrent.locks.ReadWriteLock; +import java.util.concurrent.locks.ReentrantReadWriteLock; + +import org.alfresco.error.AlfrescoRuntimeException; +import org.alfresco.repo.cache.SimpleCache; +import org.alfresco.repo.tenant.TenantService; +import org.alfresco.service.namespace.NamespaceException; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +/** + * Simple in-memory namespace DAO + */ +public class NamespaceDAOImpl implements NamespaceDAO +{ + private static final Log logger = LogFactory.getLog(NamespaceDAOImpl.class); + + private static final long serialVersionUID = -1085431310721591548L; + + /** + * Lock objects + */ + private ReadWriteLock lock = new ReentrantReadWriteLock(); + private Lock readLock = lock.readLock(); + private Lock writeLock = lock.writeLock(); + + // internal caches that are clusterable + private SimpleCache> urisCache; + private SimpleCache> prefixesCache; + + // Dependencies + private TenantService tenantService; + + + public void setTenantService(TenantService tenantService) + { + this.tenantService = tenantService; + } + + public void setUrisCache(SimpleCache> urisCache) + { + this.urisCache = urisCache; + } + + public void setPrefixesCache(SimpleCache> prefixesCache) + { + this.prefixesCache = prefixesCache; + } + + + private DictionaryDAO dictionaryDAO; + + public void registerDictionary(DictionaryDAO dictionaryDAO) + { + this.dictionaryDAO = dictionaryDAO; + } + + + /** + * Initialise empty namespaces + */ + public void init() + { + String tenantDomain = getTenantDomain(); + + putUrisCtx(tenantDomain, new ArrayList()); + putPrefixesCtx(tenantDomain, new HashMap()); + + if (logger.isDebugEnabled()) + { + logger.debug("Empty namespaces initialised"); + } + } + + /** + * Destroy the namespaces + */ + public void destroy() + { + String tenantDomain = getTenantDomain(); + + removeUrisCtx(tenantDomain); + removePrefixesCtx(tenantDomain); + + if (logger.isDebugEnabled()) + { + logger.debug("Namespaces destroyed"); + } + } + + /** + * Resets the namespaces (by resetting the dictionary) + */ + private void reset() + { + if (logger.isDebugEnabled()) + { + logger.debug("Resetting namespaces ..."); + } + + if (dictionaryDAO == null) + { + // Unexpected + throw new AlfrescoRuntimeException("Dictionary should be registered in order to perform reset"); + } + else + { + dictionaryDAO.reset(); + } + + if (logger.isDebugEnabled()) + { + logger.debug("... resetting namespaces completed"); + } + } + + /* (non-Javadoc) + * @see org.alfresco.repo.ref.NamespacePrefixResolver#getURIs() + */ + public Collection getURIs() + { + if (! tenantService.isTenantUser()) + { + return Collections.unmodifiableCollection(getUrisCtx()); + } + else + { + // Get tenant-specific URIs + List domainUris = getUrisCtx(); + + // Get non-tenant-specific URIs (and filter out, if overridden) + List urisFiltered = new ArrayList(); + for(String uri : getUrisCtx("")) + { + if (domainUris.contains(uri)) + { + // overridden, hence skip this default prefix + continue; + } + urisFiltered.add(uri); + } + + // default (non-overridden) + tenant-specific + urisFiltered.addAll(domainUris); + + return Collections.unmodifiableCollection(urisFiltered); + } + } + + + /* (non-Javadoc) + * @see org.alfresco.repo.ref.NamespacePrefixResolver#getPrefixes() + */ + public Collection getPrefixes() + { + if (! tenantService.isTenantUser()) + { + return Collections.unmodifiableCollection(getPrefixesCtx().keySet()); + } + else + { + // Get tenant-specific prefixes + Collection domainPrefixes = getPrefixesCtx().keySet(); + + // Get non-tenant-specific URIs (and filter out, if overridden) + List prefixesFiltered = new ArrayList(); + for(String prefix : getPrefixesCtx("").keySet()) + { + if (domainPrefixes.contains(prefix)) + { + // overridden, hence skip this default prefix + continue; + } + prefixesFiltered.add(prefix); + } + + // default (non-overridden) + tenant-specific + prefixesFiltered.addAll(domainPrefixes); + + return Collections.unmodifiableCollection(prefixesFiltered); + } + } + + + /* (non-Javadoc) + * @see org.alfresco.repo.dictionary.impl.NamespaceDAO#addURI(java.lang.String) + */ + public void addURI(String uri) + { + if (getUrisCtx().contains(uri)) + { + throw new NamespaceException("URI " + uri + " has already been defined"); + } + getUrisCtx().add(uri); + } + + + /* (non-Javadoc) + * @see org.alfresco.repo.dictionary.impl.NamespaceDAO#addPrefix(java.lang.String, java.lang.String) + */ + public void addPrefix(String prefix, String uri) + { + if (!getUrisCtx().contains(uri)) + { + throw new NamespaceException("Namespace URI " + uri + " does not exist"); + } + getPrefixesCtx().put(prefix, uri); + } + + + /* (non-Javadoc) + * @see org.alfresco.repo.dictionary.impl.NamespaceDAO#removeURI(java.lang.String) + */ + public void removeURI(String uri) + { + getUrisCtx().remove(uri); + } + + + /* (non-Javadoc) + * @see org.alfresco.repo.dictionary.impl.NamespaceDAO#removePrefix(java.lang.String) + */ + public void removePrefix(String prefix) + { + getPrefixesCtx().remove(prefix); + } + + + /* (non-Javadoc) + * @see org.alfresco.repo.ref.NamespacePrefixResolver#getNamespaceURI(java.lang.String) + */ + public String getNamespaceURI(String prefix) + { + if (! tenantService.isTenantUser()) + { + return getPrefixesCtx().get(prefix); + } + else + { + // first look for tenant-specific prefix + String uri = getPrefixesCtx().get(prefix); + if (uri != null) + { + // found tenant specific uri + return uri; + } + else + { + // try with default (non-tenant-specific) prefix + return getPrefixesCtx("").get(prefix); + } + } + } + + + /* (non-Javadoc) + * @see org.alfresco.repo.ref.NamespacePrefixResolver#getPrefixes(java.lang.String) + */ + public Collection getPrefixes(String URI) + { + if (! tenantService.isTenantUser()) + { + Collection uriPrefixes = new ArrayList(); + for (String key : getPrefixesCtx().keySet()) + { + String uri = getPrefixesCtx().get(key); + if ((uri != null) && (uri.equals(URI))) + { + uriPrefixes.add(key); + } + } + return uriPrefixes; + } + else + { + // check domain prefixes + Collection domainUriPrefixes = new ArrayList(); + for (String key : getPrefixesCtx().keySet()) + { + String uri = getPrefixesCtx().get(key); + if ((uri != null) && (uri.equals(URI))) + { + domainUriPrefixes.add(key); + } + } + + // check non-domain prefixes + Collection uriPrefixes = new ArrayList(); + for (String key : getPrefixesCtx("").keySet()) + { + String uri = getPrefixesCtx("").get(key); + if ((uri != null) && (uri.equals(URI))) + { + if (domainUriPrefixes != null) + { + if (domainUriPrefixes.contains(key)) + { + // overridden, hence skip this default prefix + continue; + } + } + + uriPrefixes.add(key); + } + } + + if (domainUriPrefixes != null) + { + // default (non-overridden) + domain + uriPrefixes.addAll(domainUriPrefixes); + } + + return uriPrefixes; + } + } + + /** + * Get URIs from the cache (in the context of the current user's tenant domain) + * + * @return URIs + */ + private List getUrisCtx() + { + return getUrisCtx(getTenantDomain()); + } + + /** + * Get URIs from the cache + * + * @param tenantDomain + * @return URIs + */ + private List getUrisCtx(String tenantDomain) + { + List uris = null; + try + { + readLock.lock(); + uris = urisCache.get(tenantDomain); + } + finally + { + readLock.unlock(); + } + + + if (uris == null) + { + reset(); // reset caches - may have been invalidated (e.g. in a cluster) + + try + { + readLock.lock(); + uris = urisCache.get(tenantDomain); + } + finally + { + readLock.unlock(); + } + + if (uris == null) + { + // unexpected + throw new AlfrescoRuntimeException("Failed to re-initialise urisCache " + tenantDomain); + } + } + return uris; + } + + /** + * Put URIs into the cache + * + * @param tenantDomain + * @param uris + */ + private void putUrisCtx(String tenantDomain, List uris) + { + try + { + writeLock.lock(); + urisCache.put(tenantDomain, uris); + } + finally + { + writeLock.unlock(); + } + } + + /** + * Remove URIs from the cache + * + * @param tenantDomain + */ + private void removeUrisCtx(String tenantDomain) + { + try + { + writeLock.lock(); + if (urisCache.get(tenantDomain) != null) + { + urisCache.get(tenantDomain).clear(); + urisCache.remove(tenantDomain); + } + } + finally + { + writeLock.unlock(); + } + } + + /** + * Get prefixes from the cache + * + * @return prefixes + */ + private Map getPrefixesCtx() + { + return getPrefixesCtx(getTenantDomain()); + } + + /** + * Get prefixes from the cache + * + * @param tenantDomain + * @return prefixes + */ + private Map getPrefixesCtx(String tenantDomain) + { + Map prefixes = null; + try + { + readLock.lock(); + prefixes = prefixesCache.get(tenantDomain); + } + finally + { + readLock.unlock(); + } + + if (prefixes == null) + { + reset(); // reset caches - may have been invalidated (e.g. in a cluster) + + try + { + readLock.lock(); + prefixes = prefixesCache.get(tenantDomain); + } + finally + { + readLock.unlock(); + } + + if (prefixes == null) + { + // unexpected + throw new AlfrescoRuntimeException("Failed to re-initialise prefixesCache " + tenantDomain); + } + } + + return prefixes; + } + + /** + * Put prefixes into the cache + * + * @param tenantDomain + * @param prefixes + */ + private void putPrefixesCtx(String tenantDomain, Map prefixes) + { + try + { + writeLock.lock(); + prefixesCache.put(tenantDomain, prefixes); + } + finally + { + writeLock.unlock(); + } + } + + /** + * Remove prefixes from the cache + * + * @param tenantDomain + */ + private void removePrefixesCtx(String tenantDomain) + { + try + { + writeLock.lock(); + if (prefixesCache.get(tenantDomain) != null) + { + prefixesCache.get(tenantDomain).clear(); + prefixesCache.remove(tenantDomain); + } + } + finally + { + writeLock.unlock(); + } + } + + /** + * Local helper - returns tenant domain (or empty string if default non-tenant) + */ + private String getTenantDomain() + { + return tenantService.getCurrentUserDomain(); + } +} diff --git a/source/java/org/alfresco/repo/node/NodeRefPropertyMethodInterceptor.java b/source/java/org/alfresco/repo/node/NodeRefPropertyMethodInterceptor.java index 7d83ebb2d9..60caa5be73 100644 --- a/source/java/org/alfresco/repo/node/NodeRefPropertyMethodInterceptor.java +++ b/source/java/org/alfresco/repo/node/NodeRefPropertyMethodInterceptor.java @@ -39,6 +39,7 @@ import org.alfresco.service.cmr.repository.NodeService; import org.alfresco.service.cmr.repository.datatype.DefaultTypeConverter; import org.alfresco.service.cmr.repository.datatype.TypeConversionException; import org.alfresco.service.namespace.QName; +import org.alfresco.util.ApplicationContextHelper; import org.aopalliance.intercept.MethodInterceptor; import org.aopalliance.intercept.MethodInvocation; import org.apache.commons.logging.Log; @@ -60,9 +61,9 @@ public class NodeRefPropertyMethodInterceptor implements MethodInterceptor private boolean filterOnSet = true; - private DictionaryService dictionaryService; + transient private DictionaryService dictionaryService; - private NodeService nodeService; + transient private NodeService nodeService; public boolean isFilterOnGet() { @@ -88,11 +89,29 @@ public class NodeRefPropertyMethodInterceptor implements MethodInterceptor { this.dictionaryService = dictionaryService; } + + private DictionaryService getDictionaryService() + { + if (dictionaryService == null) + { + dictionaryService = (DictionaryService) ApplicationContextHelper.getApplicationContext().getBean("dictionaryService"); + } + return dictionaryService; + } public void setNodeService(NodeService nodeService) { this.nodeService = nodeService; } + + private NodeService getNodeService() + { + if (nodeService == null) + { + nodeService = (NodeService) ApplicationContextHelper.getApplicationContext().getBean("mlAwareNodeService"); + } + return nodeService; + } @SuppressWarnings("unchecked") public Object invoke(MethodInvocation invocation) throws Throwable @@ -278,7 +297,7 @@ public class NodeRefPropertyMethodInterceptor implements MethodInterceptor */ private Serializable getValue(QName propertyQName, Serializable inboundValue) { - PropertyDefinition propertyDef = this.dictionaryService.getProperty(propertyQName); + PropertyDefinition propertyDef = this.getDictionaryService().getProperty(propertyQName); if (propertyDef == null) { return inboundValue; @@ -303,12 +322,12 @@ public class NodeRefPropertyMethodInterceptor implements MethodInterceptor try { NodeRef test = DefaultTypeConverter.INSTANCE.convert(NodeRef.class, value); - if (nodeService.exists(test)) + if (getNodeService().exists(test)) { if (propertyDef.getDataType().getName().equals(DataTypeDefinition.CATEGORY)) { - QName type = nodeService.getType(test); - if (dictionaryService.isSubClass(type, ContentModel.TYPE_CATEGORY)) + QName type = getNodeService().getType(test); + if (getDictionaryService().isSubClass(type, ContentModel.TYPE_CATEGORY)) { out.add(test); } @@ -338,12 +357,12 @@ public class NodeRefPropertyMethodInterceptor implements MethodInterceptor try { NodeRef test = DefaultTypeConverter.INSTANCE.convert(NodeRef.class, inboundValue); - if (nodeService.exists(test)) + if (getNodeService().exists(test)) { if (propertyDef.getDataType().getName().equals(DataTypeDefinition.CATEGORY)) { - QName type = nodeService.getType(test); - if (dictionaryService.isSubClass(type, ContentModel.TYPE_CATEGORY)) + QName type = getNodeService().getType(test); + if (getDictionaryService().isSubClass(type, ContentModel.TYPE_CATEGORY)) { return test; } diff --git a/source/java/org/alfresco/service/cmr/repository/TemplateImageResolver.java b/source/java/org/alfresco/service/cmr/repository/TemplateImageResolver.java index 24f74a1f54..3c10fee1f4 100644 --- a/source/java/org/alfresco/service/cmr/repository/TemplateImageResolver.java +++ b/source/java/org/alfresco/service/cmr/repository/TemplateImageResolver.java @@ -24,6 +24,8 @@ */ package org.alfresco.service.cmr.repository; +import java.io.Serializable; + /** * Interface contract for the conversion of file name to a fully qualified icon image path for use by * templating and scripting engines executing within the repository context. @@ -33,7 +35,7 @@ package org.alfresco.service.cmr.repository; * * @author Kevin Roast */ -public interface TemplateImageResolver +public interface TemplateImageResolver extends Serializable { /** * Resolve the qualified icon image path for the specified filename diff --git a/source/java/org/alfresco/service/cmr/workflow/WorkflowDefinition.java b/source/java/org/alfresco/service/cmr/workflow/WorkflowDefinition.java index 7e877972b3..d0c8c8c2da 100644 --- a/source/java/org/alfresco/service/cmr/workflow/WorkflowDefinition.java +++ b/source/java/org/alfresco/service/cmr/workflow/WorkflowDefinition.java @@ -24,21 +24,25 @@ */ package org.alfresco.service.cmr.workflow; +import java.io.Serializable; + /** * Workflow Definition Data Object * * @author davidc */ -public class WorkflowDefinition +public class WorkflowDefinition implements Serializable { - //XXarielb these should most likely all be private + private static final long serialVersionUID = -4320345925926816927L; +//XXarielb these should most likely all be private public final String id; public final String name; public final String version; public final String title; public final String description; - public final WorkflowTaskDefinition startTaskDefinition; + + transient private final WorkflowTaskDefinition startTaskDefinition; public WorkflowDefinition(final String id, final String name, @@ -97,6 +101,6 @@ public class WorkflowDefinition */ public String toString() { - return "WorkflowDefinition[id=" + id + ",name=" + name + ",version=" + version + ",title=" + title + ",startTask=" + ((startTaskDefinition == null) ? "undefined" : startTaskDefinition.toString()) + "]"; + return "WorkflowDefinition[id=" + id + ",name=" + name + ",version=" + version + ",title=" + title + ",startTask=" + ((getStartTaskDefinition() == null) ? "undefined" : getStartTaskDefinition().toString()) + "]"; } } diff --git a/source/java/org/alfresco/service/cmr/workflow/WorkflowInstance.java b/source/java/org/alfresco/service/cmr/workflow/WorkflowInstance.java index 415d1f9d76..774366396b 100644 --- a/source/java/org/alfresco/service/cmr/workflow/WorkflowInstance.java +++ b/source/java/org/alfresco/service/cmr/workflow/WorkflowInstance.java @@ -24,6 +24,7 @@ */ package org.alfresco.service.cmr.workflow; +import java.io.Serializable; import java.util.Date; import org.alfresco.service.cmr.repository.NodeRef; @@ -36,8 +37,10 @@ import org.alfresco.service.cmr.repository.NodeRef; * * @author davidc */ -public class WorkflowInstance +public class WorkflowInstance implements Serializable { + private static final long serialVersionUID = 4221926809419223452L; + /** Workflow Instance unique id */ public String id; diff --git a/source/java/org/alfresco/service/namespace/DynamicNamespacePrefixResolver.java b/source/java/org/alfresco/service/namespace/DynamicNamespacePrefixResolver.java index bf1b817346..d48a371e1f 100644 --- a/source/java/org/alfresco/service/namespace/DynamicNamespacePrefixResolver.java +++ b/source/java/org/alfresco/service/namespace/DynamicNamespacePrefixResolver.java @@ -41,6 +41,8 @@ import java.util.Set; public class DynamicNamespacePrefixResolver implements NamespaceService { + private static final long serialVersionUID = -7721089444629137409L; + /** * The delegate */ diff --git a/source/java/org/alfresco/service/namespace/NamespacePrefixResolver.java b/source/java/org/alfresco/service/namespace/NamespacePrefixResolver.java index 733222a33e..ecd4306fa0 100644 --- a/source/java/org/alfresco/service/namespace/NamespacePrefixResolver.java +++ b/source/java/org/alfresco/service/namespace/NamespacePrefixResolver.java @@ -24,6 +24,7 @@ */ package org.alfresco.service.namespace; +import java.io.Serializable; import java.util.Collection; import org.alfresco.service.Auditable; @@ -36,7 +37,7 @@ import org.alfresco.service.PublicService; * @author David Caruana */ @PublicService -public interface NamespacePrefixResolver +public interface NamespacePrefixResolver extends Serializable { /** * Gets the namespace URI registered for the given prefix diff --git a/source/java/org/alfresco/service/namespace/QNameMap.java b/source/java/org/alfresco/service/namespace/QNameMap.java index 8669bd707a..31e3e2a0ee 100644 --- a/source/java/org/alfresco/service/namespace/QNameMap.java +++ b/source/java/org/alfresco/service/namespace/QNameMap.java @@ -24,6 +24,7 @@ */ package org.alfresco.service.namespace; +import java.io.Serializable; import java.util.Collection; import java.util.HashMap; import java.util.Map; @@ -40,8 +41,10 @@ import org.apache.commons.logging.LogFactory; * * @author gavinc */ -public class QNameMap implements Map, Cloneable +public class QNameMap implements Map, Cloneable, Serializable { + private static final long serialVersionUID = 2077228225832792605L; + protected static Log logger = LogFactory.getLog(QNameMap.class); protected Map contents = new HashMap(16, 1.0f); protected NamespacePrefixResolver resolver = null; @@ -60,6 +63,19 @@ public class QNameMap implements Map, Cloneable this.resolver = resolver; } + + + /** + * Constructor for Serialization mechanism + * + */ + protected QNameMap() + { + super(); + } + + + /** * @see java.util.Map#size() */