ImporterComponent.java

Index Score
org.alfresco.repo.importer
Alfresco

View: Reasons, Metrics, Source Code

These are the metrics that contribute to the Enerjy Score for this file, ranked by impact. So the metrics listed at the top influence the score to a greater extent that the metrics listed at the bottom.

MetricDescription
EXEC_COMMENTSComments in executable code
LINE_COMMENTNumber of line comments
DECL_COMMENTSComments in declarations
SIZESize of the file in bytes
EXITSProcedure exits
LINESNumber of lines in the source file
LOCLines of code
INTERFACE_COMPLEXITYInterface complexity
OPERANDSNumber of operands
RETURNSNumber of return points from functions
BLOCKSNumber of blocks
COMMENTSComment lines
CYCLOMATICCyclomatic complexity
UNIQUE_OPERANDSNumber of unique operands
PROGRAM_LENGTHHalstead program length
OPERATORSNumber of operators
JAVA0144JAVA0144 Line exceeds maximum M characters
PROGRAM_VOCABHalstead program vocabulary
PARAMSNumber of formal parameter declarations
LOGICAL_LINESNumber of statements
COMPARISONSNumber of comparison operators
ELOCEffective lines of code
FUNCTIONSNumber of function declarations
DOC_COMMENTNumber of javadoc comment lines
JAVA0108JAVA0108 Incorrect javadoc: no @param tag for 'parameter'
JAVA0109JAVA0109 Incorrect javadoc: no parameter 'parameter'
JAVA0081JAVA0081 Boolean literal in comparison
JAVA0034JAVA0034 Missing braces in if statement
BLOCK_COMMENTNumber of block comment lines
WHITESPACENumber of whitespace lines
JAVA0179JAVA0179 Local variable hides visible field
JAVA0173JAVA0173 Unused method parameter
JAVA0100JAVA0100 Class contains N non-final fields (maximum: M)
NEST_DEPTHMaximum nesting depth
UNIQUE_OPERATORSNumber of unique operators
JAVA0117JAVA0117 Missing javadoc: method 'method'
JAVA0128JAVA0128 Public constructor in non-public class
PROGRAM_VOLUMEHalstead program volume
JAVA0136JAVA0136 N methods defined in class (maximum: M)
JAVA0288JAVA0288 Inconsistent null check
JAVA0130JAVA0130 Non-static method does not use instance fields
JAVA0145JAVA0145 Tab character used in source file
/* * 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.importer; import java.io.IOException; import java.io.InputStream; import java.io.Reader; import java.io.Serializable; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; import org.alfresco.error.AlfrescoRuntimeException; import org.alfresco.model.ContentModel; import org.alfresco.repo.policy.BehaviourFilter; import org.alfresco.service.cmr.dictionary.AssociationDefinition; import org.alfresco.service.cmr.dictionary.ChildAssociationDefinition; import org.alfresco.service.cmr.dictionary.ClassDefinition; import org.alfresco.service.cmr.dictionary.DataTypeDefinition; import org.alfresco.service.cmr.dictionary.DictionaryService; import org.alfresco.service.cmr.dictionary.TypeDefinition; import org.alfresco.service.cmr.repository.ChildAssociationRef; import org.alfresco.service.cmr.repository.ContentData; import org.alfresco.service.cmr.repository.ContentService; import org.alfresco.service.cmr.repository.ContentWriter; import org.alfresco.service.cmr.repository.InvalidNodeRefException; import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.NodeService; import org.alfresco.service.cmr.repository.XPathException; import org.alfresco.service.cmr.repository.datatype.DefaultTypeConverter; import org.alfresco.service.cmr.rule.RuleService; import org.alfresco.service.cmr.search.ResultSet; import org.alfresco.service.cmr.search.SearchParameters; import org.alfresco.service.cmr.search.SearchService; import org.alfresco.service.cmr.security.AccessPermission; import org.alfresco.service.cmr.security.AccessStatus; import org.alfresco.service.cmr.security.AuthenticationService; import org.alfresco.service.cmr.security.AuthorityService; import org.alfresco.service.cmr.security.OwnableService; import org.alfresco.service.cmr.security.PermissionService; import org.alfresco.service.cmr.view.ImportPackageHandler; import org.alfresco.service.cmr.view.ImporterBinding; import org.alfresco.service.cmr.view.ImporterException; import org.alfresco.service.cmr.view.ImporterProgress; import org.alfresco.service.cmr.view.ImporterService; import org.alfresco.service.cmr.view.Location; import org.alfresco.service.cmr.view.ImporterBinding.UUID_BINDING; import org.alfresco.service.namespace.NamespaceService; import org.alfresco.service.namespace.QName; import org.alfresco.util.ParameterCheck; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.core.io.DefaultResourceLoader; import org.springframework.core.io.Resource; import org.springframework.core.io.ResourceLoader; import org.springframework.util.StringUtils; import org.xml.sax.ContentHandler; /** * Default implementation of the Importer Service * * @author David Caruana */ public class ImporterComponent implements ImporterService { // Logger private static final Log logger = LogFactory.getLog(ImporterComponent.class); // default importer // TODO: Allow registration of plug-in parsers (by namespace) private Parser viewParser; // supporting services private NamespaceService namespaceService; private DictionaryService dictionaryService; private BehaviourFilter behaviourFilter; private NodeService nodeService; private SearchService searchService; private ContentService contentService; private RuleService ruleService; private PermissionService permissionService; private AuthorityService authorityService; private AuthenticationService authenticationService; private OwnableService ownableService; // binding markers private static final String START_BINDING_MARKER = "${"; private static final String END_BINDING_MARKER = "}"; /** * @param viewParser the default parser */ public void setViewParser(Parser viewParser) { this.viewParser = viewParser; } /** * @param nodeService the node service */ public void setNodeService(NodeService nodeService) { this.nodeService = nodeService; } /** * @param searchService the service to perform path searches */ public void setSearchService(SearchService searchService) { this.searchService = searchService; } /** * @param contentService the content service */ public void setContentService(ContentService contentService) { this.contentService = contentService; } /** * @param dictionaryService the dictionary service */ public void setDictionaryService(DictionaryService dictionaryService) { this.dictionaryService = dictionaryService; } /** * @param namespaceService the namespace service */ public void setNamespaceService(NamespaceService namespaceService) { this.namespaceService = namespaceService; } /** * @param behaviourFilter policy behaviour filter */ public void setBehaviourFilter(BehaviourFilter behaviourFilter) { this.behaviourFilter = behaviourFilter; } /** * TODO: Remove this in favour of appropriate rule disabling * * @param ruleService rule service */ public void setRuleService(RuleService ruleService) { this.ruleService = ruleService; } /** * @param permissionService permissionService */ public void setPermissionService(PermissionService permissionService) { this.permissionService = permissionService; } /** * @param authorityService authorityService */ public void setAuthorityService(AuthorityService authorityService) { this.authorityService = authorityService; } /** * @param authenticationService authenticationService */ public void setAuthenticationService(AuthenticationService authenticationService) { this.authenticationService = authenticationService; } /** * @param ownableService ownableService */ public void setOwnableService(OwnableService ownableService) { this.ownableService = ownableService; } /* (non-Javadoc) * @see org.alfresco.service.cmr.view.ImporterService#importView(java.io.InputStreamReader, org.alfresco.service.cmr.view.Location, java.util.Properties, org.alfresco.service.cmr.view.ImporterProgress) */ public void importView(Reader viewReader, Location location, ImporterBinding binding, ImporterProgress progress) { NodeRef nodeRef = getNodeRef(location, binding); parserImport(nodeRef, location.getChildAssocType(), viewReader, new DefaultStreamHandler(), binding, progress); } /* (non-Javadoc) * @see org.alfresco.service.cmr.view.ImporterService#importView(org.alfresco.service.cmr.view.ImportPackageHandler, org.alfresco.service.cmr.view.Location, org.alfresco.service.cmr.view.ImporterBinding, org.alfresco.service.cmr.view.ImporterProgress) */ public void importView(ImportPackageHandler importHandler, Location location, ImporterBinding binding, ImporterProgress progress) throws ImporterException { importHandler.startImport(); Reader dataFileReader = importHandler.getDataStream(); NodeRef nodeRef = getNodeRef(location, binding); parserImport(nodeRef, location.getChildAssocType(), dataFileReader, importHandler, binding, progress); importHandler.endImport(); } /** * Get Node Reference from Location * * @param location the location to extract node reference from * @param binding import configuration * @return node reference */ private NodeRef getNodeRef(Location location, ImporterBinding binding) { ParameterCheck.mandatory("Location", location); // Establish node to import within NodeRef nodeRef = location.getNodeRef(); if (nodeRef == null) { // If a specific node has not been provided, default to the root nodeRef = nodeService.getRootNode(location.getStoreRef()); } // Resolve to path within node, if one specified String path = location.getPath(); if (path != null && path.length() >0) { // Create a valid path and search path = bindPlaceHolder(path, binding); path = createValidPath(path); List<NodeRef> nodeRefs = searchService.selectNodes(nodeRef, path, null, namespaceService, false); if (nodeRefs.size() == 0) { throw new ImporterException("Path " + path + " within node " + nodeRef + " does not exist - the path must resolve to a valid location"); } if (nodeRefs.size() > 1) { throw new ImporterException("Path " + path + " within node " + nodeRef + " found too many locations - the path must resolve to one location"); } nodeRef = nodeRefs.get(0); } // TODO: Check Node actually exists return nodeRef; } /** * Bind the specified value to the passed configuration values if it is a place holder * * @param value the value to bind * @param binding the configuration properties to bind to * @return the bound value */ private String bindPlaceHolder(String value, ImporterBinding binding) { if (binding != null) { int iStartBinding = value.indexOf(START_BINDING_MARKER); while (iStartBinding != -1) { int iEndBinding = value.indexOf(END_BINDING_MARKER, iStartBinding + START_BINDING_MARKER.length()); if (iEndBinding == -1) { throw new ImporterException("Cannot find end marker " + END_BINDING_MARKER + " within value " + value); } String key = value.substring(iStartBinding + START_BINDING_MARKER.length(), iEndBinding); String keyValue = binding.getValue(key); if (keyValue == null) { logger.warn("No binding value for placeholder (will default to empty string): " + value); } value = StringUtils.replace(value, START_BINDING_MARKER + key + END_BINDING_MARKER, keyValue == null ? "" : keyValue); iStartBinding = value.indexOf(START_BINDING_MARKER); } } return value; } /** * Create a valid path * * @param path * @return */ private String createValidPath(String path) { StringBuffer validPath = new StringBuffer(path.length()); String[] segments = StringUtils.delimitedListToStringArray(path, "/"); for (int i = 0; i < segments.length; i++) { if (segments[i] != null && segments[i].length() > 0) { String[] qnameComponents = QName.splitPrefixedQName(segments[i]); QName segmentQName = QName.createQName(qnameComponents[0], QName.createValidLocalName(qnameComponents[1]), namespaceService); validPath.append(segmentQName.toPrefixString()); } if (i < (segments.length -1)) { validPath.append("/"); } } return validPath.toString(); } /** * Perform Import via Parser * * @param nodeRef node reference to import under * @param childAssocType the child association type to import under * @param inputStream the input stream to import from * @param streamHandler the content property import stream handler * @param binding import configuration * @param progress import progress */ public void parserImport(NodeRef nodeRef, QName childAssocType, Reader viewReader, ImportPackageHandler streamHandler, ImporterBinding binding, ImporterProgress progress) { ParameterCheck.mandatory("Node Reference", nodeRef); ParameterCheck.mandatory("View Reader", viewReader); ParameterCheck.mandatory("Stream Handler", streamHandler); Importer nodeImporter = new NodeImporter(nodeRef, childAssocType, binding, streamHandler, progress); try { nodeImporter.start(); viewParser.parse(viewReader, nodeImporter); nodeImporter.end(); } catch(RuntimeException e) { nodeImporter.error(e); throw e; } } /** * Perform import via Content Handler * * @param nodeRef node reference to import under * @param childAssocType the child association type to import under * @param handler the import content handler * @param binding import configuration * @param progress import progress * @return content handler to interact with */ public ContentHandler handlerImport(NodeRef nodeRef, QName childAssocType, ImportContentHandler handler, ImporterBinding binding, ImporterProgress progress) { ParameterCheck.mandatory("Node Reference", nodeRef); DefaultContentHandler defaultHandler = new DefaultContentHandler(handler); ImportPackageHandler streamHandler = new ContentHandlerStreamHandler(defaultHandler); Importer nodeImporter = new NodeImporter(nodeRef, childAssocType, binding, streamHandler, progress); defaultHandler.setImporter(nodeImporter); return defaultHandler; } /** * Encapsulate how a node is imported into the repository */ public interface NodeImporterStrategy { /** * Import a node * * @param node to import */ public NodeRef importNode(ImportNode node); } /** * Default Importer strategy * * @author David Caruana */ private class NodeImporter implements Importer { private NodeRef rootRef; private QName rootAssocType; private ImporterBinding binding; private ImporterProgress progress; private ImportPackageHandler streamHandler; private NodeImporterStrategy importStrategy; private UpdateExistingNodeImporterStrategy updateStrategy; private QName[] excludedClasses; // Import tracking private List<ImportedNodeRef> nodeRefs = new ArrayList<ImportedNodeRef>(); /** * Construct * * @param rootRef * @param rootAssocType * @param binding * @param progress */ private NodeImporter(NodeRef rootRef, QName rootAssocType, ImporterBinding binding, ImportPackageHandler streamHandler, ImporterProgress progress) { this.rootRef = rootRef; this.rootAssocType = rootAssocType; this.binding = binding; this.progress = progress; this.streamHandler = streamHandler; this.importStrategy = createNodeImporterStrategy(binding == null ? null : binding.getUUIDBinding()); this.updateStrategy = new UpdateExistingNodeImporterStrategy(); // initialise list of content models to exclude from import if (binding == null || binding.getExcludedClasses() == null) { this.excludedClasses = new QName[] { ContentModel.ASPECT_REFERENCEABLE, ContentModel.ASPECT_VERSIONABLE }; } else { this.excludedClasses = binding.getExcludedClasses(); } } /** * Create Node Importer Strategy * * @param uuidBinding UUID Binding * @return Node Importer Strategy */ private NodeImporterStrategy createNodeImporterStrategy(ImporterBinding.UUID_BINDING uuidBinding) { if (uuidBinding == null) { return new CreateNewNodeImporterStrategy(true); } else if (uuidBinding.equals(UUID_BINDING.CREATE_NEW)) { return new CreateNewNodeImporterStrategy(true); } else if (uuidBinding.equals(UUID_BINDING.CREATE_NEW_WITH_UUID)) { return new CreateNewNodeImporterStrategy(false); } else if (uuidBinding.equals(UUID_BINDING.REMOVE_EXISTING)) { return new RemoveExistingNodeImporterStrategy(); } else if (uuidBinding.equals(UUID_BINDING.REPLACE_EXISTING)) { return new ReplaceExistingNodeImporterStrategy(); } else if (uuidBinding.equals(UUID_BINDING.UPDATE_EXISTING)) { return new UpdateExistingNodeImporterStrategy(); } else if (uuidBinding.equals(UUID_BINDING.THROW_ON_COLLISION)) { return new ThrowOnCollisionNodeImporterStrategy(); } else { return new CreateNewNodeImporterStrategy(true); } } /* (non-Javadoc) * @see org.alfresco.repo.importer.Importer#getRootRef() */ public NodeRef getRootRef() { return rootRef; } /* (non-Javadoc) * @see org.alfresco.repo.importer.Importer#getRootAssocType() */ public QName getRootAssocType() { return rootAssocType; } /* (non-Javadoc) * @see org.alfresco.repo.importer.Importer#start() */ public void start() { reportStarted(); } /* (non-Javadoc) * @see org.alfresco.repo.importer.Importer#importMetaData(java.util.Map) */ public void importMetaData(Map<QName, String> properties) { // Determine if we're importing a complete repository String path = properties.get(QName.createQName(NamespaceService.REPOSITORY_VIEW_1_0_URI, "exportOf")); if (path != null && path.equals("/")) { // Only allow complete repository import into root NodeRef storeRootRef = nodeService.getRootNode(rootRef.getStoreRef()); if (!storeRootRef.equals(rootRef)) { throw new ImporterException("A complete repository package cannot be imported here"); } } } /* (non-Javadoc) * @see org.alfresco.repo.importer.Importer#importNode(org.alfresco.repo.importer.ImportNode) */ public NodeRef importNode(ImportNode context) { // import node NodeRef nodeRef; if (context.isReference()) { nodeRef = linkNode(context); } else { nodeRef = importStrategy.importNode(context); } // apply aspects for (QName aspect : context.getNodeAspects()) { if (nodeService.hasAspect(nodeRef, aspect) == false) { nodeService.addAspect(nodeRef, aspect, null); // all properties previously added reportAspectAdded(nodeRef, aspect); } } // import content, if applicable for (Map.Entry<QName,Serializable> property : context.getProperties().entrySet()) { // filter out content properties (they're imported later) DataTypeDefinition valueDataType = context.getPropertyDataType(property.getKey()); if (valueDataType != null && valueDataType.getName().equals(DataTypeDefinition.CONTENT)) { // the property may be a single value or a collection - handle both Object objVal = property.getValue(); if (objVal instanceof String) { importContent(nodeRef, property.getKey(), (String)objVal); } else if (objVal instanceof Collection) { for (String value : (Collection<String>)objVal) { importContent(nodeRef, property.getKey(), value); } } } } return nodeRef; } /** * Link an existing Node * * @param context node to link in * @return node reference of child linked in */ private NodeRef linkNode(ImportNode context) { ImportParent parentContext = context.getParentContext(); NodeRef parentRef = parentContext.getParentRef(); // determine the node reference to link to String uuid = context.getUUID(); if (uuid == null || uuid.length() == 0) { throw new ImporterException("Node reference does not specify a reference to follow."); } NodeRef referencedRef = new NodeRef(rootRef.getStoreRef(), uuid); // Note: do not link references that are defined in the root of the import if (!parentRef.equals(getRootRef())) { // determine child assoc type QName assocType = getAssocType(context); AssociationDefinition assocDef = dictionaryService.getAssociation(assocType); if (assocDef.isChild()) { // determine child name QName childQName = getChildName(context); if (childQName == null) { String name = (String)nodeService.getProperty(referencedRef, ContentModel.PROP_NAME); if (name == null || name.length() == 0) { throw new ImporterException("Cannot determine node reference child name"); } String localName = QName.createValidLocalName(name); childQName = QName.createQName(assocType.getNamespaceURI(), localName); } // create the secondary link nodeService.addChild(parentRef, referencedRef, assocType, childQName); reportNodeLinked(referencedRef, parentRef, assocType, childQName); } else { nodeService.createAssociation(parentRef, referencedRef, assocType); reportNodeLinked(parentRef, referencedRef, assocType, null); } } // second, perform any specified udpates to the node updateStrategy.importNode(context); return referencedRef; } /** * Import Node Content. * <p> * The content URL, if present, will be a local URL. This import copies the content * from the local URL to a server-assigned location. * * @param nodeRef containing node * @param propertyName the name of the content-type property * @param contentData the identifier of the content to import */ private void importContent(NodeRef nodeRef, QName propertyName, String importContentData) { // bind import content data description importContentData = bindPlaceHolder(importContentData, binding); if (importContentData != null && importContentData.length() > 0) { DataTypeDefinition dataTypeDef = dictionaryService.getDataType(DataTypeDefinition.CONTENT); ContentData contentData = (ContentData)DefaultTypeConverter.INSTANCE.convert(dataTypeDef, importContentData); String contentUrl = contentData.getContentUrl(); if (contentUrl != null && contentUrl.length() > 0) { // import the content from the url InputStream contentStream = streamHandler.importStream(contentUrl); ContentWriter writer = contentService.getWriter(nodeRef, propertyName, true); writer.setEncoding(contentData.getEncoding()); writer.setMimetype(contentData.getMimetype()); writer.putContent(contentStream); reportContentCreated(nodeRef, contentUrl); } } } /* (non-Javadoc) * @see org.alfresco.repo.importer.Importer#childrenImported(org.alfresco.service.cmr.repository.NodeRef) */ public void childrenImported(NodeRef nodeRef) { behaviourFilter.enableBehaviours(nodeRef); ruleService.enableRules(nodeRef); } /* (non-Javadoc) * @see org.alfresco.repo.importer.Importer#resolvePath(java.lang.String) */ public NodeRef resolvePath(String path) { NodeRef referencedRef = null; if (path != null && path.length() > 0) { referencedRef = resolveImportedNodeRef(rootRef, path); } return referencedRef; } /* * (non-Javadoc) * @see org.alfresco.repo.importer.Importer#isExcludedClass(org.alfresco.service.namespace.QName) */ public boolean isExcludedClass(QName className) { for (QName excludedClass : excludedClasses) { if (excludedClass.equals(className)) { return true; } } return false; } /* (non-Javadoc) * @see org.alfresco.repo.importer.Importer#end() */ public void end() { // Bind all node references to destination space for (ImportedNodeRef importedRef : nodeRefs) { Serializable refProperty = null; if (importedRef.value != null) { if (importedRef.value instanceof Collection) { Collection<String> unresolvedRefs = (Collection<String>)importedRef.value; List<NodeRef> resolvedRefs = new ArrayList<NodeRef>(unresolvedRefs.size()); for (String unresolvedRef : unresolvedRefs) { if (unresolvedRef != null) { NodeRef nodeRef = resolveImportedNodeRef(importedRef.context.getNodeRef(), unresolvedRef); // TODO: Provide a better mechanism for invalid references? e.g. report warning if (nodeRef != null) { resolvedRefs.add(nodeRef); } } } refProperty = (Serializable)resolvedRefs; } else { refProperty = resolveImportedNodeRef(importedRef.context.getNodeRef(), (String)importedRef.value); // TODO: Provide a better mechanism for invalid references? e.g. report warning } } // Set node reference on source node Set<QName> disabledBehaviours = getDisabledBehaviours(importedRef.context); try { for (QName disabledBehaviour: disabledBehaviours) { behaviourFilter.disableBehaviour(importedRef.context.getNodeRef(), disabledBehaviour); } nodeService.setProperty(importedRef.context.getNodeRef(), importedRef.property, refProperty); if (progress != null) { progress.propertySet(importedRef.context.getNodeRef(), importedRef.property, refProperty); } } finally { behaviourFilter.enableBehaviours(importedRef.context.getNodeRef()); } } reportCompleted(); } /* * (non-Javadoc) * @see org.alfresco.repo.importer.Importer#error(java.lang.Throwable) */ public void error(Throwable e) { behaviourFilter.enableAllBehaviours(); reportError(e); } /** * Get the child name to import node under * * @param context the node * @return the child name */ private QName getChildName(ImportNode context) { QName assocType = getAssocType(context); QName childQName = null; // Determine child name String childName = context.getChildName(); if (childName != null) { childName = bindPlaceHolder(childName, binding); String[] qnameComponents = QName.splitPrefixedQName(childName); childQName = QName.createQName(qnameComponents[0], QName.createValidLocalName(qnameComponents[1]), namespaceService); } else { Map<QName, Serializable> typeProperties = context.getProperties(); String name = (String)typeProperties.get(ContentModel.PROP_NAME); if (name != null && name.length() > 0) { name = bindPlaceHolder(name, binding); String localName = QName.createValidLocalName(name); childQName = QName.createQName(assocType.getNamespaceURI(), localName); } } return childQName; } /** * Get appropriate child association type for node to import under * * @param context node to import * @return child association type name */ private QName getAssocType(ImportNode context) { QName assocType = context.getParentContext().getAssocType(); if (assocType != null) { // return explicitly set association type return assocType; } // // Derive association type // // build type and aspect list for node List<QName> nodeTypes = new ArrayList<QName>(); nodeTypes.add(context.getTypeDefinition().getName()); for (QName aspect : context.getNodeAspects()) { nodeTypes.add(aspect); } // build target class types for parent Map<QName, QName> targetTypes = new HashMap<QName, QName>(); QName parentType = nodeService.getType(context.getParentContext().getParentRef()); ClassDefinition classDef = dictionaryService.getClass(parentType); Map<QName, ChildAssociationDefinition> childAssocDefs = classDef.getChildAssociations(); for (ChildAssociationDefinition childAssocDef : childAssocDefs.values()) { targetTypes.put(childAssocDef.getTargetClass().getName(), childAssocDef.getName()); } Set<QName> parentAspects = nodeService.getAspects(context.getParentContext().getParentRef()); for (QName parentAspect : parentAspects) { classDef = dictionaryService.getClass(parentAspect); childAssocDefs = classDef.getChildAssociations(); for (ChildAssociationDefinition childAssocDef : childAssocDefs.values()) { targetTypes.put(childAssocDef.getTargetClass().getName(), childAssocDef.getName()); } } // find target class that is closest to node type or aspects QName closestAssocType = null; int closestHit = 1; for (QName nodeType : nodeTypes) { for (QName targetType : targetTypes.keySet()) { QName testType = nodeType; int howClose = 1; while (testType != null) { howClose--; if (targetType.equals(testType) && howClose < closestHit) { closestAssocType = targetTypes.get(targetType); closestHit = howClose; break; } ClassDefinition testTypeDef = dictionaryService.getClass(testType); testType = (testTypeDef == null) ? null : testTypeDef.getParentName(); } } } return closestAssocType; } /** * For the given import node, return the behaviours to disable during import * * @param context import node * @return the disabled behaviours */ private Set<QName> getDisabledBehaviours(ImportNode context) { Set<QName> classNames = new HashSet<QName>(); // disable the type TypeDefinition typeDef = context.getTypeDefinition(); classNames.add(typeDef.getName()); // disable the aspects imported on the node classNames.addAll(context.getNodeAspects()); // note: do not disable default aspects that are not imported on the node. // this means they'll be added on import return classNames; } /** * Bind properties * * @param properties * @return */ private Map<QName, Serializable> bindProperties(ImportNode context) { Map<QName, Serializable> properties = context.getProperties(); Map<QName, Serializable> boundProperties = new HashMap<QName, Serializable>(properties.size()); for (QName property : properties.keySet()) { // get property datatype DataTypeDefinition valueDataType = context.getPropertyDataType(property); // filter out content properties (they're imported later) if (valueDataType != null && valueDataType.getName().equals(DataTypeDefinition.CONTENT)) { continue; } // get property value Serializable value = properties.get(property); // bind property value to configuration and convert to appropriate type if (value instanceof Collection) { List<Serializable> boundCollection = new ArrayList<Serializable>(); for (String collectionValue : (Collection<String>)value) { Serializable objValue = bindValue(context, property, valueDataType, collectionValue); boundCollection.add(objValue); } value = (Serializable)boundCollection; } else { value = bindValue(context, property, valueDataType, (String)value); } // choose to provide property on node creation or at end of import for lazy binding if (valueDataType != null && (valueDataType.getName().equals(DataTypeDefinition.NODE_REF) || valueDataType.getName().equals(DataTypeDefinition.CATEGORY))) { // record node reference for end-of-import binding ImportedNodeRef importedRef = new ImportedNodeRef(context, property, value); nodeRefs.add(importedRef); } else { // property ready to be set on Node creation / update boundProperties.put(property, value); } } return boundProperties; } /** * Bind property value * * @param valueType value type * @param value string form of value * @return the bound value */ private Serializable bindValue(ImportNode context, QName property, DataTypeDefinition valueType, String value) { Serializable objValue = null; if (value != null && valueType != null) { String strValue = bindPlaceHolder(value, binding); if ((valueType.getName().equals(DataTypeDefinition.NODE_REF) || valueType.getName().equals(DataTypeDefinition.CATEGORY))) { objValue = strValue; } else { objValue = (Serializable)DefaultTypeConverter.INSTANCE.convert(valueType, strValue); } } return objValue; } /** * Resolve imported reference relative to specified node * * @param sourceNodeRef context to resolve within * @param importedRef reference to resolve * @return */ private NodeRef resolveImportedNodeRef(NodeRef sourceNodeRef, String importedRef) { // Resolve path to node reference NodeRef nodeRef = null; importedRef = bindPlaceHolder(importedRef, binding); if (importedRef.equals("/")) { nodeRef = sourceNodeRef; } else if (importedRef.startsWith("/")) { // resolve absolute path SearchParameters searchParameters = new SearchParameters(); searchParameters.addStore(sourceNodeRef.getStoreRef()); searchParameters.setLanguage(SearchService.LANGUAGE_LUCENE); searchParameters.setQuery("PATH:\"" + importedRef + "\""); searchParameters.excludeDataInTheCurrentTransaction((binding == null) ? true : !binding.allowReferenceWithinTransaction()); ResultSet resultSet = null; try { resultSet = searchService.query(searchParameters); if (resultSet.length() > 0) { nodeRef = resultSet.getNodeRef(0); } } catch(UnsupportedOperationException e) { List<NodeRef> nodeRefs = searchService.selectNodes(sourceNodeRef, importedRef, null, namespaceService, false); if (nodeRefs.size() > 0) { nodeRef = nodeRefs.get(0); } } finally { if (resultSet != null) { resultSet.close(); } } } else { // determine if node reference if (NodeRef.isNodeRef(importedRef)) { nodeRef = new NodeRef(importedRef); } else { // resolve relative path try { List<NodeRef> nodeRefs = searchService.selectNodes(sourceNodeRef, importedRef, null, namespaceService, false); if (nodeRefs.size() > 0) { nodeRef = nodeRefs.get(0); } } catch(XPathException e) { nodeRef = new NodeRef(importedRef); } catch(AlfrescoRuntimeException e1) { // Note: Invalid reference format - try path search instead } } } return nodeRef; } /** * Helper to report start of import */ private void reportStarted() { if (progress != null) { progress.started(); } } /** * Helper to report end of import */ private void reportCompleted() { if (progress != null) { progress.completed(); } } /** * Helper to report error * * @param e */ private void reportError(Throwable e) { if (progress != null) { progress.error(e); } } /** * Helper to report node created progress * * @param progress * @param childAssocRef */ private void reportNodeCreated(ChildAssociationRef childAssocRef) { if (progress != null) { progress.nodeCreated(childAssocRef.getChildRef(), childAssocRef.getParentRef(), childAssocRef.getTypeQName(), childAssocRef.getQName()); } } /** * Helper to report node linked progress * * @param progress * @param childAssocRef */ private void reportNodeLinked(NodeRef childRef, NodeRef parentRef, QName assocType, QName childName) { if (progress != null) { progress.nodeLinked(childRef, parentRef, assocType, childName); } } /** * Helper to report content created progress * * @param progress * @param nodeRef * @param sourceUrl */ private void reportContentCreated(NodeRef nodeRef, String sourceUrl) { if (progress != null) { progress.contentCreated(nodeRef, sourceUrl); } } /** * Helper to report aspect added progress * * @param progress * @param nodeRef * @param aspect */ private void reportAspectAdded(NodeRef nodeRef, QName aspect) { if (progress != null) { progress.aspectAdded(nodeRef, aspect); } } /** * Helper to report property set progress * * @param progress * @param nodeRef * @param properties */ private void reportPropertySet(NodeRef nodeRef, Map<QName, Serializable> properties) { if (progress != null && properties != null) { for (QName property : properties.keySet()) { progress.propertySet(nodeRef, property, properties.get(property)); } } } /** * Helper to report permission set progress * * @param nodeRef * @param permissions */ private void reportPermissionSet(NodeRef nodeRef, List<AccessPermission> permissions) { if (progress != null && permissions != null) { for (AccessPermission permission : permissions) { progress.permissionSet(nodeRef, permission); } } } /** * Import strategy where imported nodes are always created regardless of whether a * node of the same UUID already exists in the repository */ private class CreateNewNodeImporterStrategy implements NodeImporterStrategy { // force allocation of new UUID, even if one already specified private boolean assignNewUUID; /** * Construct * * @param newUUID force allocation of new UUID */ public CreateNewNodeImporterStrategy(boolean assignNewUUID) { this.assignNewUUID = assignNewUUID; } /* * (non-Javadoc) * @see org.alfresco.repo.importer.ImporterComponent.NodeImporterStrategy#importNode(org.alfresco.repo.importer.ImportNode) */ public NodeRef importNode(ImportNode node) { TypeDefinition nodeType = node.getTypeDefinition(); NodeRef parentRef = node.getParentContext().getParentRef(); QName assocType = getAssocType(node); QName childQName = getChildName(node); if (childQName == null) { throw new ImporterException("Cannot determine child name of node (type: " + nodeType.getName() + ")"); } // Create initial node (but, first disable behaviour for the node to be created) Set<QName> disabledBehaviours = getDisabledBehaviours(node); List<QName> alreadyDisabledBehaviours = new ArrayList<QName>(); for (QName disabledBehaviour: disabledBehaviours) { boolean alreadyDisabled = behaviourFilter.disableBehaviour(disabledBehaviour); if (alreadyDisabled) { alreadyDisabledBehaviours.add(disabledBehaviour); } } disabledBehaviours.removeAll(alreadyDisabledBehaviours); // Build initial map of properties Map<QName, Serializable> initialProperties = bindProperties(node); // Assign UUID if already specified on imported node if (!assignNewUUID && node.getUUID() != null) { initialProperties.put(ContentModel.PROP_NODE_UUID, node.getUUID()); } // Create Node ChildAssociationRef assocRef = nodeService.createNode(parentRef, assocType, childQName, nodeType.getName(), initialProperties); NodeRef nodeRef = assocRef.getChildRef(); // Note: non-admin authorities take ownership of new nodes if (!(authorityService.hasAdminAuthority() || authenticationService.isCurrentUserTheSystemUser())) { ownableService.takeOwnership(nodeRef); } // apply permissions List<AccessPermission> permissions = null; AccessStatus writePermission = permissionService.hasPermission(nodeRef, PermissionService.CHANGE_PERMISSIONS); if (authenticationService.isCurrentUserTheSystemUser() || writePermission.equals(AccessStatus.ALLOWED)) { permissions = node.getAccessControlEntries(); for (AccessPermission permission : permissions) { permissionService.setPermission(nodeRef, permission.getAuthority(), permission.getPermission(), permission.getAccessStatus().equals(AccessStatus.ALLOWED)); } // note: apply inheritance after setting permissions as this may affect whether you can apply permissions boolean inheritPermissions = node.getInheritPermissions(); if (!inheritPermissions) { permissionService.setInheritParentPermissions(nodeRef, false); } } // Disable behaviour for the node until the complete node (and its children have been imported) for (QName disabledBehaviour : disabledBehaviours) { behaviourFilter.enableBehaviour(disabledBehaviour); } for (QName disabledBehaviour : disabledBehaviours) { behaviourFilter.disableBehaviour(nodeRef, disabledBehaviour); } // TODO: Replace this with appropriate rule/action import handling ruleService.disableRules(nodeRef); // Report creation reportNodeCreated(assocRef); reportPropertySet(nodeRef, initialProperties); reportPermissionSet(nodeRef, permissions); // return newly created node reference return nodeRef; } } /** * Importer strategy where an existing node (one with the same UUID) as a node being * imported is first removed. The imported node is placed in the location specified * at import time. */ private class RemoveExistingNodeImporterStrategy implements NodeImporterStrategy { private NodeImporterStrategy createNewStrategy = new CreateNewNodeImporterStrategy(false); /* * (non-Javadoc) * @see org.alfresco.repo.importer.ImporterComponent.NodeImporterStrategy#importNode(org.alfresco.repo.importer.ImportNode) */ public NodeRef importNode(ImportNode node) { // remove existing node, if node to import has a UUID and an existing node of the same // uuid already exists String uuid = node.getUUID(); if (uuid != null && uuid.length() > 0) { NodeRef existingNodeRef = new NodeRef(rootRef.getStoreRef(), uuid); if (nodeService.exists(existingNodeRef)) { // remove primary parent link forcing deletion ChildAssociationRef childAssocRef = nodeService.getPrimaryParent(existingNodeRef); // TODO: Check for root node nodeService.removeChild(childAssocRef.getParentRef(), childAssocRef.getChildRef()); } } // import as if a new node into current import parent location return createNewStrategy.importNode(node); } } /** * Importer strategy where an existing node (one with the same UUID) as a node being * imported is first removed. The imported node is placed under the parent of the removed * node. */ private class ReplaceExistingNodeImporterStrategy implements NodeImporterStrategy { private NodeImporterStrategy createNewStrategy = new CreateNewNodeImporterStrategy(false); /* * (non-Javadoc) * @see org.alfresco.repo.importer.ImporterComponent.NodeImporterStrategy#importNode(org.alfresco.repo.importer.ImportNode) */ public NodeRef importNode(ImportNode node) { // replace existing node, if node to import has a UUID and an existing node of the same // uuid already exists String uuid = node.getUUID(); if (uuid != null && uuid.length() > 0) { NodeRef existingNodeRef = new NodeRef(rootRef.getStoreRef(), uuid); if (nodeService.exists(existingNodeRef)) { // remove primary parent link forcing deletion ChildAssociationRef childAssocRef = nodeService.getPrimaryParent(existingNodeRef); nodeService.removeChild(childAssocRef.getParentRef(), childAssocRef.getChildRef()); // update the parent context of the node being imported to the parent of the node just deleted node.getParentContext().setParentRef(childAssocRef.getParentRef()); node.getParentContext().setAssocType(childAssocRef.getTypeQName()); } } // import as if a new node return createNewStrategy.importNode(node); } } /** * Import strategy where an error is thrown when importing a node that has the same UUID * of an existing node in the repository. */ private class ThrowOnCollisionNodeImporterStrategy implements NodeImporterStrategy { private NodeImporterStrategy createNewStrategy = new CreateNewNodeImporterStrategy(false); /* * (non-Javadoc) * @see org.alfresco.repo.importer.ImporterComponent.NodeImporterStrategy#importNode(org.alfresco.repo.importer.ImportNode) */ public NodeRef importNode(ImportNode node) { // if node to import has a UUID and an existing node of the same uuid already exists // then throw an error String uuid = node.getUUID(); if (uuid != null && uuid.length() > 0) { NodeRef existingNodeRef = new NodeRef(rootRef.getStoreRef(), uuid); if (nodeService.exists(existingNodeRef)) { throw new InvalidNodeRefException("Node " + existingNodeRef + " already exists", existingNodeRef); } } // import as if a new node return createNewStrategy.importNode(node); } } /** * Import strategy where imported nodes are updated if a node with the same UUID * already exists in the repository. * * Note: this will only allow incremental update of an existing node - it does not * delete properties or associations. */ private class UpdateExistingNodeImporterStrategy implements NodeImporterStrategy { private NodeImporterStrategy createNewStrategy = new CreateNewNodeImporterStrategy(false); /* * (non-Javadoc) * @see org.alfresco.repo.importer.ImporterComponent.NodeImporterStrategy#importNode(org.alfresco.repo.importer.ImportNode) */ public NodeRef importNode(ImportNode node) { // replace existing node, if node to import has a UUID and an existing node of the same // uuid already exists String uuid = node.getUUID(); if (uuid != null && uuid.length() > 0) { NodeRef existingNodeRef = new NodeRef(rootRef.getStoreRef(), uuid); if (nodeService.exists(existingNodeRef)) { // do the update Map<QName, Serializable> existingProperties = nodeService.getProperties(existingNodeRef); Map<QName, Serializable> updateProperties = bindProperties(node); if (updateProperties != null && updateProperties.size() > 0) { existingProperties.putAll(updateProperties); nodeService.setProperties(existingNodeRef, existingProperties); } // Apply permissions List<AccessPermission> permissions = null; AccessStatus writePermission = permissionService.hasPermission(existingNodeRef, PermissionService.CHANGE_PERMISSIONS); if (authenticationService.isCurrentUserTheSystemUser() || writePermission.equals(AccessStatus.ALLOWED)) { boolean inheritPermissions = node.getInheritPermissions(); if (!inheritPermissions) { permissionService.setInheritParentPermissions(existingNodeRef, false); } permissions = node.getAccessControlEntries(); for (AccessPermission permission : permissions) { permissionService.setPermission(existingNodeRef, permission.getAuthority(), permission.getPermission(), permission.getAccessStatus().equals(AccessStatus.ALLOWED)); } } // report update reportPropertySet(existingNodeRef, updateProperties); reportPermissionSet(existingNodeRef, permissions); return existingNodeRef; } } // import as if a new node return createNewStrategy.importNode(node); } } } /** * Imported Node Reference * * @author David Caruana */ private static class ImportedNodeRef { /** * Construct * * @param context * @param property * @param value */ private ImportedNodeRef(ImportNode context, QName property, Serializable value) { this.context = context; this.property = property; this.value = value; } private ImportNode context; private QName property; private Serializable value; } /** * Default Import Stream Handler * * @author David Caruana */ private static class DefaultStreamHandler implements ImportPackageHandler { /* (non-Javadoc) * @see org.alfresco.service.cmr.view.ImportPackageHandler#startImport() */ public void startImport() { } /* (non-Javadoc) * @see org.alfresco.service.cmr.view.ImportStreamHandler#importStream(java.lang.String) */ public InputStream importStream(String content) { ResourceLoader loader = new DefaultResourceLoader(); Resource resource = loader.getResource(content); if (resource.exists() == false) { throw new ImporterException("Content URL " + content + " does not exist."); } try { return resource.getInputStream(); } catch(IOException e) { throw new ImporterException("Failed to retrieve input stream for content URL " + content); } } /* (non-Javadoc) * @see org.alfresco.service.cmr.view.ImportPackageHandler#getDataStream() */ public Reader getDataStream() { return null; } /* (non-Javadoc) * @see org.alfresco.service.cmr.view.ImportPackageHandler#endImport() */ public void endImport() { } } /** * Default Import Stream Handler * * @author David Caruana */ private static class ContentHandlerStreamHandler implements ImportPackageHandler { private ImportContentHandler handler; /** * Construct * * @param handler */ private ContentHandlerStreamHandler(ImportContentHandler handler) { this.handler = handler; } /* (non-Javadoc) * @see org.alfresco.service.cmr.view.ImportPackageHandler#startImport() */ public void startImport() { } /* (non-Javadoc) * @see org.alfresco.service.cmr.view.ImportStreamHandler#importStream(java.lang.String) */ public InputStream importStream(String content) { return handler.importStream(content); } /* (non-Javadoc) * @see org.alfresco.service.cmr.view.ImportPackageHandler#getDataStream() */ public Reader getDataStream() { return null; } /* (non-Javadoc) * @see org.alfresco.service.cmr.view.ImportPackageHandler#endImport() */ public void endImport() { } } }

The table below shows all metrics for ImporterComponent.java.

MetricValueDescription
BLOCKS193.00Number of blocks
BLOCK_COMMENT106.00Number of block comment lines
COMMENTS463.00Comment lines
COMMENT_DENSITY 0.77Comment density
COMPARISONS114.00Number of comparison operators
CYCLOMATIC186.00Cyclomatic complexity
DECL_COMMENTS83.00Comments in declarations
DOC_COMMENT271.00Number of javadoc comment lines
ELOC605.00Effective lines of code
EXEC_COMMENTS72.00Comments in executable code
EXITS180.00Procedure exits
FUNCTIONS65.00Number of function declarations
HALSTEAD_DIFFICULTY89.95Halstead difficulty
HALSTEAD_EFFORT 0.00Halstead effort
INTERFACE_COMPLEXITY214.00Interface complexity
JAVA0001 0.00JAVA0001 Package name does not contain only lower case letters
JAVA0002 0.00JAVA0002 Package name does not begin with a top level domain name or country code
JAVA0003 0.00JAVA0003 Minimize use of on-demand (.*) imports
JAVA0004 0.00JAVA0004 Unnecessary import from java.lang
JAVA0005 0.00JAVA0005 Imports not in specified order
JAVA0006 0.00JAVA0006 Empty finally block
JAVA0007 0.00JAVA0007 Should not declare public field
JAVA0008 0.00JAVA0008 Empty catch block
JAVA0009 0.00JAVA0009 Protected member in final class
JAVA0010 0.00JAVA0010 Non-instantiable class does not contain a non-private static member
JAVA0011 0.00JAVA0011 Abstract class does not contain an abstract method
JAVA0012 0.00JAVA0012 Non-constructor method with same name as declaring class
JAVA0013 0.00JAVA0013 Non-blank final field is not static
JAVA0014 0.00JAVA0014 Class with only static members has non-private constructor
JAVA0015 0.00JAVA0015 Package class contains public nested type
JAVA0016 0.00JAVA0016 Abstract class contains public constructor
JAVA0017 0.00JAVA0017 Class name does not have required form
JAVA0018 0.00JAVA0018 Method name does not have required form
JAVA0019 0.00JAVA0019 Interface name does not have required form
JAVA0020 0.00JAVA0020 Field name does not have required form
JAVA0021 0.00JAVA0021 Interface method name does not have required form
JAVA0022 0.00JAVA0022 Static final field name does not have required form
JAVA0023 0.00JAVA0023 Empty finalize method
JAVA0024 0.00JAVA0024 Empty class
JAVA0025 0.00JAVA0025 Method override is empty
JAVA0026 0.00JAVA0026 Finalize method with parameters
JAVA0029 0.00JAVA0029 Private method not used
JAVA0030 0.00JAVA0030 Private field not used
JAVA0031 0.00JAVA0031 Case statement not properly closed
JAVA0032 0.00JAVA0032 Switch statement missing default
JAVA0033 0.00JAVA0033 default: not last case in switch statement
JAVA0034 0.00JAVA0034 Missing braces in if statement
JAVA0035 0.00JAVA0035 Missing braces in for statement
JAVA0036 0.00JAVA0036 Missing braces in while statement
JAVA0038 0.00JAVA0038 Non-case label in switch statement
JAVA0039 0.00JAVA0039 Break statement with label
JAVA0040 0.00JAVA0040 Switch statement contains N cases (maximum: M)
JAVA0041 0.00JAVA0041 Nested synchronized block
JAVA0042 0.00JAVA0042 Empty synchronized statement
JAVA0043 0.00JAVA0043 Inner class does not use outer class
JAVA0044 0.00JAVA0044 Serializable class with no instance variables
JAVA0045 0.00JAVA0045 Serializable class with only transient fields
JAVA0046 0.00JAVA0046 Name of class not derived from Exception ends with 'Exception'
JAVA0047 0.00JAVA0047 Serializable class derives from invalid base class
JAVA0048 0.00JAVA0048 Name of class derived from Exception does not end with 'Exception'
JAVA0049 1.00JAVA0049 Nested block at depth N (maximum: M)
JAVA0050 0.00JAVA0050 Class derives from java.lang.Error
JAVA0051 0.00JAVA0051 Class derives from java.lang.RuntimeException
JAVA0052 0.00JAVA0052 Class derives from java.lang.Throwable
JAVA0053 0.00JAVA0053 Unused label
JAVA0054 0.00JAVA0054 Inheritance depth N exceeds maximum M
JAVA0055 0.00JAVA0055 Class should be interface
JAVA0056 0.00JAVA0056 Unnecessary abstract modifier for interface or annotation
JAVA0057 0.00JAVA0057 Unnecessary default constructor
JAVA0058 0.00JAVA0058 Constructor calls super()
JAVA0059 0.00JAVA0059 Method override only calls super()
JAVA0061 0.00JAVA0061 Inaccessible member in anonymous class
JAVA0062 0.00JAVA0062 Public class missing public member or protected constructor
JAVA0063 0.00JAVA0063 Identifier name should not contain '$'
JAVA0064 0.00JAVA0064 N variations of identifier name (maximum: M)
JAVA0065 0.00JAVA0065 Unnecessary final modifier for method in final class
JAVA0066 0.00JAVA0066 Unnecessary modifier for interface nested type
JAVA0067 0.00JAVA0067 Array descriptor on identifier name
JAVA0068 0.00JAVA0068 Modifiers not declared in recommended order
JAVA0071 0.00JAVA0071 Strings compared with ==
JAVA0073 0.00JAVA0073 Integer division in floating-point context
JAVA0074 0.00JAVA0074 Use of Object.notify()
JAVA0075 0.00JAVA0075 Method parameter hides field
JAVA0076 0.00JAVA0076 Use of magic number
JAVA0077 0.00JAVA0077 Private field not used in declaring class
JAVA0078 0.00JAVA0078 Floating point values compared with ==
JAVA0079 0.00JAVA0079 Use of instance to reference static member
JAVA0080 0.00JAVA0080 Import declaration not used
JAVA0081 2.00JAVA0081 Boolean literal in comparison
JAVA0082 0.00JAVA0082 Unnecessary widening cast
JAVA0083 0.00JAVA0083 Unnecessary instanceof test
JAVA0084 0.00JAVA0084 Should use compound assignment operator
JAVA0085 0.00JAVA0085 Use of sun.* class
JAVA0087 0.00JAVA0087 Use of Thread.sleep()
JAVA0089 0.00JAVA0089 Use of restricted package
JAVA0092 0.00JAVA0092 Use of restricted type
JAVA0093 0.00JAVA0093 Redundant assignment
JAVA0094 0.00JAVA0094 Field hides a superclass field
JAVA0095 0.00JAVA0095 Uninitialized private field
JAVA0096 0.00JAVA0096 Field in nested class hides outer field
JAVA0098 0.00JAVA0098 Minimize use of implicit field initializers
JAVA0100 2.00JAVA0100 Class contains N non-final fields (maximum: M)
JAVA0101 0.00JAVA0101 Unnecessary modifier for field in interface
JAVA0102 0.00JAVA0102 Last statement in finalize() not super.finalize()
JAVA0103 0.00JAVA0103 Explicit call to finalize()
JAVA0104 0.00JAVA0104 finalize() only calls super.finalize()
JAVA0105 0.00JAVA0105 Duplicate import declaration
JAVA0106 0.00JAVA0106 Unnecessary import from current package
JAVA010811.00JAVA0108 Incorrect javadoc: no @param tag for 'parameter'
JAVA010910.00JAVA0109 Incorrect javadoc: no parameter 'parameter'
JAVA0110 1.00JAVA0110 Incorrect javadoc: no @return tag
JAVA0111 0.00JAVA0111 Incorrect javadoc: @return tag for void method
JAVA0112 0.00JAVA0112 Incorrect javadoc: no exception 'exception' in throws
JAVA0113 0.00JAVA0113 Incorrect javadoc: no @author tag
JAVA0114 1.00JAVA0114 Incorrect javadoc: no @version tag
JAVA0115 0.00JAVA0115 Incorrect javadoc: no @throws or @exception tag for 'exception'
JAVA0116 0.00JAVA0116 Missing javadoc: field 'field'
JAVA0117 0.00JAVA0117 Missing javadoc: method 'method'
JAVA0118 0.00JAVA0118 Missing javadoc: type 'type'
JAVA0119 0.00JAVA0119 Control variable changed within body of for loop
JAVA0123 0.00JAVA0123 Use all three components of for loop
JAVA0125 0.00JAVA0125 Continue statement with label
JAVA0126 1.00JAVA0126 Method declares unchecked exception in throws
JAVA0128 1.00JAVA0128 Public constructor in non-public class
JAVA0130 1.00JAVA0130 Non-static method does not use instance fields
JAVA0131 0.00JAVA0131 Compatible method does not override base
JAVA0132 0.00JAVA0132 Method overload with compatible signature
JAVA0133 0.00JAVA0133 Non-synchronized method overrides synchronized method
JAVA0135 0.00JAVA0135 Only one of Object.equals and Object.hashCode defined: missing 'method'
JAVA0136 1.00JAVA0136 N methods defined in class (maximum: M)
JAVA0137 1.00JAVA0137 Non-abstract class missing constructor
JAVA0138 1.00JAVA0138 N parameters defined for method (maximum: M)
JAVA0139 0.00JAVA0139 Definition of main other than public static void main(java.lang.String[])
JAVA0141 1.00JAVA0141 Unnecessary modifier for method in interface
JAVA0143 0.00JAVA0143 Synchronized method
JAVA014425.00JAVA0144 Line exceeds maximum M characters
JAVA014526.00JAVA0145 Tab character used in source file
JAVA0150 0.00JAVA0150 java.lang.Error (or subclass) thrown
JAVA0153 0.00JAVA0153 Inefficient conversion of integer to string
JAVA0159 0.00JAVA0159 Inefficient conversion of string to integer
JAVA0160 0.00JAVA0160 Method does not throw specified exception
JAVA0161 0.00JAVA0161 Conditional wait() not in loop
JAVA0163 0.00JAVA0163 Empty statement
JAVA0165 0.00JAVA0165 Conflicting return statement in finally block
JAVA0166 1.00JAVA0166 Generic exception caught
JAVA0167 0.00JAVA0167 ThreadDeath not rethrown
JAVA0169 0.00JAVA0169 Unnecessary catch block: exception 'exception'
JAVA0170 0.00JAVA0170 Caught exception not derived from java.lang.Exception
JAVA0171 0.00JAVA0171 Unused local variable
JAVA0173 2.00JAVA0173 Unused method parameter
JAVA0174 0.00JAVA0174 Assigned local variable never used
JAVA0175 0.00JAVA0175 Successive assignment to variable
JAVA0176 0.00JAVA0176 Local variable name does not have required form
JAVA0177 1.00JAVA0177 Variable declaration missing initializer
JAVA0179 2.00JAVA0179 Local variable hides visible field
JAVA0233 0.00JAVA0233 Definition of serialVersionUID other than 'private static final long serialVersionUID'
JAVA0234 0.00JAVA0234 Class is Serializable but does not define serialVersionUID
JAVA0235 0.00JAVA0235 Class defines serialVersionUID but does not implement Serializable
JAVA0236 0.00JAVA0236 Attempt to clone an object which does not implement Cloneable
JAVA0237 0.00JAVA0237 Class implements Cloneable but does not have public clone method
JAVA0238 0.00JAVA0238 Clone method does not call super.clone()
JAVA0239 0.00JAVA0239 Class declares 'readObject' or 'writeObject' but does not implement Serializable
JAVA0240 0.00JAVA0240 Serializable class which declares readObject or writeObject but not both
JAVA0241 0.00JAVA0241 'readObject' or 'writeObject' should be declared private in Serializable class
JAVA0242 0.00JAVA0242 Transient field in non-Serializable class
JAVA0243 0.00JAVA0243 'readResolve' or 'writeReplace' should be declared private or protected
JAVA0244 0.00JAVA0244 Field or method name in subclass differs only by case from inherited field or method
JAVA0245 0.00JAVA0245 JUnit TestCase with non-trivial constructor
JAVA0246 0.00JAVA0246 JUnit assertXXX statement missing message parameter
JAVA0247 0.00JAVA0247 JUnit 'setUp()' and 'tearDown()' should call super method
JAVA0248 0.00JAVA0248 JUnit method 'setUp' or 'tearDown' with incorrect signature
JAVA0249 0.00JAVA0249 JUnit TestCase 'suite()' should be declared static
JAVA0250 0.00JAVA0250 JUnit TestCase declares testXXX method with incorrect signature
JAVA0251 0.00JAVA0251 Use '%n' for line breaks in printf/format for platform independence
JAVA0252 0.00JAVA0252 'enum' is a Java 1.5 reserved word
JAVA0253 0.00JAVA0253 Not all enum constants consumed in switch statement
JAVA0254 0.00JAVA0254 Use enhanced for loop construct instead of Iterator
JAVA0255 0.00JAVA0255 Result of method invocation not used
JAVA0256 0.00JAVA0256 Assignment of external collection/array to field
JAVA0257 0.00JAVA0257 Use of 'Constant Interface' anti-pattern
JAVA0258 0.00JAVA0258 Implement Iterable for foreach compatibility
JAVA0259 0.00JAVA0259 Return of collection/array field
JAVA0260 0.00JAVA0260 Use 'enum' instead of Enumerated Type pattern
JAVA0261 0.00JAVA0261 Use specialized Enum collection types
JAVA0262 0.00JAVA0262 Use of char in integer context
JAVA0263 0.00JAVA0263 Long literal ends with 'l' instead of 'L'
JAVA0264 0.00JAVA0264 Integer math in long context - check for overflow
JAVA0265 0.00JAVA0265 Use of Throwable.printStackTrace()
JAVA0266 0.00JAVA0266 Use of System.out
JAVA0267 0.00JAVA0267 Use of System.err
JAVA0269 0.00JAVA0269 Contents of StringBuffer never used
JAVA0270 0.00JAVA0270 Use Java 5.0 enhanced for loop construct to iterate over all elements in an array
JAVA0271 0.00JAVA0271 Minimize use of on-demand (.*) static imports
JAVA0272 0.00JAVA0272 Thread.run() called
JAVA0273 0.00JAVA0273 Non-final derivative of Thread calls start() in constructor
JAVA0274 0.00JAVA0274 Serializable class has a synchronized readObject()
JAVA0275 0.00JAVA0275 Serializable class has a synchronized writeObject() and no other synchronized methods
JAVA0276 0.00JAVA0276 Unnecessary use of String constructor
JAVA0277 0.00JAVA0277 Iterator.next() implementation does not throw NoSuchElementException
JAVA0278 0.00JAVA0278 Unnecessary use of Boolean constructor
JAVA0279 0.00JAVA0279 Serialization method readObject or readObjectNoData calls an overridable method
JAVA0280 0.00JAVA0280 IllegalMonitorStateException caught
JAVA0281 0.00JAVA0281 Iterator.next() not called in loop
JAVA0282 0.00JAVA0282 Call to Iterator.next() in loop which does not test Iterator.hasNext()
JAVA0283 0.00JAVA0283 Control variable not updated in loop body
JAVA0284 0.00JAVA0284 Explicit garbage collection
JAVA0285 0.00JAVA0285 Dereference of potentially null variable
JAVA0286 0.00JAVA0286 Dereference of null variable
JAVA0287 0.00JAVA0287 Unnecessary null check
JAVA0288 1.00JAVA0288 Inconsistent null check
LINES1615.00Number of lines in the source file
LINE_COMMENT86.00Number of line comments
LOC1012.00Lines of code
LOGICAL_LINES399.00Number of statements
LOOPS 3.00Number of loops
NEST_DEPTH 7.00Maximum nesting depth
OPERANDS2230.00Number of operands
OPERATORS3822.00Number of operators
PARAMS89.00Number of formal parameter declarations
PROGRAM_LENGTH6052.00Halstead program length
PROGRAM_VOCAB710.00Halstead program vocabulary
PROGRAM_VOLUME 0.00Halstead program volume
RETURNS125.00Number of return points from functions
SIZE64107.00Size of the file in bytes
UNIQUE_OPERANDS657.00Number of unique operands
UNIQUE_OPERATORS53.00Number of unique operators
WHITESPACE140.00Number of whitespace lines