/** * @see * org.teiid.designer.core.validation.ObjectValidationRule#validate(org.eclipse.emf.ecore.EObject, * org.teiid.designer.core.validation.ValidationContext) * @since 4.2 */ @Override public void validate(final EObject eObject, final ValidationContext context) { CoreArgCheck.isNotNull(context); CoreArgCheck.isNotNull(eObject); // get uniqueness preference status final int status = context.getPreferenceStatus(ValidationPreferences.EOBJECT_UUID_UNIQUENESS, IStatus.ERROR); if (status == IStatus.OK) { return; } // if the eObject is a model annotation then // is already being validation by ModelAnnoattionUuidRule if (eObject instanceof ModelAnnotation) { return; } final ModelEditor editor = ModelerCore.getModelEditor(); final String uuidString = ModelerCore.getObjectIdString(eObject); if (uuidString == null) { final String pathInModel = editor.getModelRelativePathIncludingModel(eObject).toString(); final ValidationResult result = new ValidationResultImpl(eObject); // create validation problem and add it to the result final ValidationProblem problem = new ValidationProblemImpl( 0, IStatus.ERROR, ModelerCore.Util.getString("EObjectUuidRule.0", pathInModel)); // $NON-NLS-1$ problem.setHasPreference(context.hasPreferences()); result.addProblem(problem); context.addResult(result); } else { boolean isDuplicate = context.containsUuid(uuidString); if (isDuplicate) { final String pathInModel = editor.getModelRelativePathIncludingModel(eObject).toString(); final ValidationResult result = new ValidationResultImpl(eObject); String modelName = editor.getModelName(eObject); // create validation problem and addit to the result final ValidationProblem problem = new ValidationProblemImpl( 0, status, ModelerCore.Util.getString( "EObjectUuidRule.1", pathInModel, uuidString, modelName)); // $NON-NLS-1$ problem.setHasPreference(context.hasPreferences()); result.addProblem(problem); context.addResult(result); } else { context.addUuidToContext(uuidString); } } }
/** * @see * org.teiid.designer.core.validation.ObjectValidationRule#validate(org.eclipse.emf.ecore.EObject, * org.teiid.designer.core.validation.ValidationContext) * @since 4.2 */ @Override public void validate(final EObject eObject, final ValidationContext context) { CoreArgCheck.isNotNull(context); CoreArgCheck.isInstanceOf(ModelAnnotation.class, eObject); final ModelEditor editor = ModelerCore.getModelEditor(); String uuidString = ModelerCore.getObjectIdString(eObject); if (uuidString == null) { final String pathInModel = editor.getModelRelativePathIncludingModel(eObject).toString(); final ValidationResult result = new ValidationResultImpl(eObject); // create validation problem and add it to the result final ValidationProblem problem = new ValidationProblemImpl( 0, IStatus.ERROR, ModelerCore.Util.getString("ModelAnnotationUuidRule.0", pathInModel)); // $NON-NLS-1$ result.addProblem(problem); context.addResult(result); } else { boolean isDuplicate = context.containsUuid(uuidString); if (isDuplicate) { final String pathInModel = editor.getModelRelativePathIncludingModel(eObject).toString(); final ValidationResult result = new ValidationResultImpl(eObject); String modelName = editor.getModelName(eObject); // create validation problem and addit to the result final ValidationProblem problem = new ValidationProblemImpl( 0, IStatus.ERROR, ModelerCore.Util.getString( "ModelAnnotationUuidRule.1", pathInModel, uuidString, modelName)); //$NON-NLS-1$ result.addProblem(problem); context.addResult(result); } else { context.addUuidToContext(uuidString); } } }
/** * Return a collection EMF resource matching the specified model name. * * @param modelName The name of the model whose resource/s are returned * @return The collection of EMD resources */ private Collection findResourcesByName(final String modelName) { CoreArgCheck.isNotEmpty(modelName); // get the collection of resources to check Collection rsrcs = new ArrayList( (this.getResources() != null ? this.getResources() : getContainer().getResources())); // Add the system models to the collection if not already there Resource[] systemModels = ModelerCore.getSystemVdbResources(); for (int i = 0; i != systemModels.length; ++i) { Resource systemModel = systemModels[i]; if (!rsrcs.contains(systemModel)) { rsrcs.add(systemModel); } } // get the editor to get the name of the resources ModelEditor modelEditor = ModelerCore.getModelEditor(); // find all the resource the match the model name Collection resources = new ArrayList(1); // get the index selector to limit the resource search IndexSelector selector = this.getIndexSelector(); if (selector != null && selector instanceof ModelResourceIndexSelector) { // the selector has reference to the resource and references to its imports ModelResourceIndexSelector resourceSelector = (ModelResourceIndexSelector) selector; // try finding the entity in the selectors resource Resource modelResource = resourceSelector.getResource(); String resourceName = modelEditor.getModelName(modelResource); if (resourceName.equalsIgnoreCase(modelName)) { resources.add(modelResource); } else { // check if any if any of the imported resources have the same name Iterator importIter = resourceSelector.getModelImports().iterator(); while (importIter.hasNext()) { ModelImport modelImport = (ModelImport) importIter.next(); String importName = modelImport.getName(); if (importName.equalsIgnoreCase(modelName)) { // compare the import path of the model to the path in the resource String importPath = modelImport.getPath(); for (Iterator resourceIter = rsrcs.iterator(); resourceIter.hasNext(); ) { Resource resource = (Resource) resourceIter.next(); String resourceUri = URI.decode(resource.getURI().toString()); if (CoreStringUtil.endsWithIgnoreCase(resourceUri, importPath)) { resources.add(resource); break; } } } } } } else { // find the resource that matches the model name for (Iterator resourceIter = rsrcs.iterator(); resourceIter.hasNext(); ) { Resource resource = (Resource) resourceIter.next(); String resourceName = modelEditor.getModelName(resource); if (resourceName.equalsIgnoreCase(modelName)) { resources.add(resource); break; } } } if (!resources.isEmpty()) { return resources; } // all open resources as model could not be found return rsrcs; }