/* (non-Javadoc) * @see org.alfresco.service.cmr.dictionary.ModelDefinition#getNamespaces() */ public Collection<NamespaceDefinition> getNamespaces() { List<NamespaceDefinition> namespaces = new ArrayList<NamespaceDefinition>(); for (M2Namespace namespace : model.getNamespaces()) { namespaces.add(new M2NamespaceDefinition(this, namespace.getUri(), namespace.getPrefix())); } return namespaces; }
/* (non-Javadoc) * @see org.alfresco.service.cmr.dictionary.ModelDefinition#isNamespaceDefined(java.lang.String) */ public boolean isNamespaceDefined(String uri) { for (M2Namespace namespace : model.getNamespaces()) { if (namespace.getUri().equals(uri)) { return true; } } return false; }
/** * Create a local namespace prefix resolver containing the namespaces defined and imported in the * model * * @param model model definition * @param namespaceDAO namespace DAO * @return the local namespace prefix resolver */ private NamespacePrefixResolver createLocalPrefixResolver( M2Model model, NamespaceDAO namespaceDAO) { // Retrieve set of existing URIs for validation purposes Collection<String> uris = namespaceDAO.getURIs(); // Create a namespace prefix resolver based on imported and defined // namespaces within the model DynamicNamespacePrefixResolver prefixResolver = new DynamicNamespacePrefixResolver(null); for (M2Namespace imported : model.getImports()) { String uri = imported.getUri(); if (!uris.contains(uri)) { throw new NamespaceException( "URI " + uri + " cannot be imported as it is not defined (with prefix " + imported.getPrefix()); } prefixResolver.registerNamespace(imported.getPrefix(), uri); } for (M2Namespace defined : model.getNamespaces()) { prefixResolver.registerNamespace(defined.getPrefix(), defined.getUri()); } return prefixResolver; }
/** Perform the actual repository access, checking for the existence of a valid transaction */ private void onDictionaryInitInTxn() { if (AlfrescoTransactionSupport.getTransactionReadState() == TxnReadState.TXN_NONE) { throw new IllegalStateException( "The Repository-based dictionary initialization has to be done in the context of a transaction."); } long startTime = System.currentTimeMillis(); if (logger.isTraceEnabled()) { String tenantDomain = tenantAdminService.getCurrentUserDomain(); logger.trace( "onDictionaryInit: [" + Thread.currentThread() + "]" + (tenantDomain.equals(TenantService.DEFAULT_DOMAIN) ? "" : " (Tenant: " + tenantDomain + ")")); } Collection<QName> modelsBefore = dictionaryDAO.getModels(true); // note: re-entrant int modelsBeforeCnt = (modelsBefore != null ? modelsBefore.size() : 0); List<String> loadedModels = new ArrayList<String>(); if (this.repositoryModelsLocations != null) { // URI to model map Map<String, DynamicModelInfo> modelMap = new HashMap<String, DynamicModelInfo>(); if (logger.isTraceEnabled()) { logger.trace("onDictionaryInit: locations=" + this.repositoryModelsLocations); } // Register the models found in the repository for (RepositoryLocation repositoryLocation : this.repositoryModelsLocations) { StoreRef storeRef = repositoryLocation.getStoreRef(); if (!nodeService.exists(storeRef)) { logger.info("StoreRef '" + storeRef + "' does not exist"); continue; // skip this location } List<NodeRef> nodeRefs = null; if (repositoryLocation.getQueryLanguage().equals(RepositoryLocation.LANGUAGE_PATH)) { nodeRefs = getNodes(storeRef, repositoryLocation, ContentModel.TYPE_DICTIONARY_MODEL); if (nodeRefs.size() > 0) { for (NodeRef dictionaryModel : nodeRefs) { try { // Ignore if the node is a working copy or archived, or if its inactive if (!(nodeService.hasAspect(dictionaryModel, ContentModel.ASPECT_WORKING_COPY) || nodeService.hasAspect(dictionaryModel, ContentModel.ASPECT_ARCHIVED))) { Boolean isActive = (Boolean) nodeService.getProperty(dictionaryModel, ContentModel.PROP_MODEL_ACTIVE); if ((isActive != null) && (isActive.booleanValue() == true)) { M2Model model = createM2Model(dictionaryModel); if (model != null) { if (logger.isTraceEnabled()) { logger.trace( "onDictionaryInit: " + model.getName() + " (" + dictionaryModel + ")"); } for (M2Namespace namespace : model.getNamespaces()) { modelMap.put( namespace.getUri(), new DynamicModelInfo(repositoryLocation, model, dictionaryModel)); } } } } } catch (InvalidNodeRefException inre) { // ignore - model no longer exists if (logger.isDebugEnabled()) { logger.debug("onDictionaryInit: " + inre + " (assume concurrently deleted)"); } continue; } } } } else { logger.error( "Unsupported query language for models location: " + repositoryLocation.getQueryLanguage()); } } // Load the models ensuring that they are loaded in the correct order for (Map.Entry<String, DynamicModelInfo> entry : modelMap.entrySet()) { RepositoryLocation importedLocation = entry.getValue().location; M2Model importedModel = entry.getValue().model; loadModel(modelMap, loadedModels, importedModel, importedLocation); notifyDynamicModelLoaded(entry.getValue()); } } Collection<QName> modelsAfter = dictionaryDAO.getModels(true); int modelsAfterCnt = (modelsAfter != null ? modelsAfter.size() : 0); if (logger.isDebugEnabled()) { String tenantDomain = tenantAdminService.getCurrentUserDomain(); logger.debug( "Model count: before=" + modelsBeforeCnt + ", load/update=" + loadedModels.size() + ", after=" + modelsAfterCnt + " in " + (System.currentTimeMillis() - startTime) + " msecs [" + Thread.currentThread() + "] " + (tenantDomain.equals(TenantService.DEFAULT_DOMAIN) ? "" : " (Tenant: " + tenantDomain + ")")); } }