/** Export the current string content of the sql display to a user-selected file */ public File exportSqlToFile(String fileNameString, String fileExtension, String fileOuputString) { // PERFORM ARG CHECK // Look for NULL or EMPTY strings CoreArgCheck.isNotNull(fileNameString); CoreArgCheck.isNotNull(fileExtension); CoreArgCheck.isNotNull(fileOuputString); CoreArgCheck.isNotEmpty(fileNameString); CoreArgCheck.isNotEmpty(fileExtension); CoreArgCheck.isNotEmpty(fileOuputString); // If there is no file extension, add .sql if (fileNameString.indexOf('.') == -1 && fileExtension != null) { fileNameString = fileNameString + "." + fileExtension; // $NON-NLS-1$ } FileWriter fileWriter = null; BufferedWriter outputBufferWriter = null; PrintWriter printWriter = null; try { fileWriter = new FileWriter(fileNameString); outputBufferWriter = new BufferedWriter(fileWriter); printWriter = new PrintWriter(outputBufferWriter); printWriter.write(fileOuputString); } catch (Exception e) { UiConstants.Util.log(IStatus.ERROR, e, UiConstants.Util.getString(EXPORT_PROBLEM)); } finally { // Clean up writers & buffers if (printWriter != null) { printWriter.close(); } try { if (outputBufferWriter != null) { outputBufferWriter.close(); } } catch (java.io.IOException e) { } try { if (fileWriter != null) { fileWriter.close(); } } catch (java.io.IOException e) { } } return new File(fileNameString); }
/** * Find the EObject having the specified UUID using the ObjectManager for the lookup. If an * EObject with this UUID cannot be found then null is returned. */ protected EObject lookupEObject(final String uuid) { CoreArgCheck.isNotEmpty(uuid); // Before searching by UUID make sure all resources associated with this QMI are loaded if (this.getResources() != null) { for (Iterator iter = this.getResources().iterator(); iter.hasNext(); ) { Resource r = (Resource) iter.next(); if (!r.isLoaded()) { try { r.load(Collections.EMPTY_MAP); } catch (IOException e) { TransformationPlugin.Util.log(IStatus.ERROR, e.getLocalizedMessage()); } } } } // Go to the Container ... EObject eObject = null; if (this.getContainer() != null) { eObject = (EObject) this.getContainer().getEObjectFinder().find(uuid); if (eObject != null) { // get the resource on the object Resource resource = eObject.eResource(); // check if this is among the resources is scope for this QMI if (this.getResources() != null) { Container cntr = ModelerCore.getContainer(resource); // If the resource exists in the same Container as the one associated with this QMI // but the resource is not in the scope of resources then return null if (cntr == this.getContainer() && !this.getResources().contains(resource)) { return null; } } } return eObject; } // We are in a non-container environment Iterator rsrs = this.getResources().iterator(); while (rsrs.hasNext()) { Resource rsrc = (Resource) rsrs.next(); if (rsrc instanceof MMXmiResource) { eObject = ((MMXmiResource) rsrc).getEObject(uuid); if (eObject != null) { return eObject; } } else if (rsrc instanceof XSDResourceImpl) { eObject = ((XSDResourceImpl) rsrc).getEObject(uuid); if (eObject != null) { return eObject; } } } return eObject; }
/** * @param runtimeType the Teiid runtime type being converted (never <code>null</code> or empty) * @return the model extension property definition type (newver <code>null</code>) * @throws IllegalArgumentException if argument cannot be converted to a valid type */ public static Type convertRuntimeType(String runtimeType) { CoreArgCheck.isNotEmpty(runtimeType, "runtimeType is empty"); // $NON-NLS-1$ for (Type type : Type.values()) { if (type.getRuntimeType().equals(runtimeType)) { return type; } } throw new IllegalArgumentException(NLS.bind(Messages.invalidRuntimeType, runtimeType)); }
/** * Get the short element from the given full name * * @param fullElementName * @return */ protected String getShortElementName(final String fullElementName) { CoreArgCheck.isNotEmpty(fullElementName); if (UuidUtil.isStringifiedUUID(fullElementName)) { return UuidUtil.stripPrefixFromUUID(fullElementName); } int index = fullElementName.lastIndexOf(DELIMITER_CHAR); if (index >= 0) { return fullElementName.substring(index + 1); } return fullElementName; }
/** * @param propId the property ID being checked (cannot be <code>null</code> or empty) * @param namespaceProvider the namespace provider used to determine the result (cannot be * <code>null</code>) * @return <code>true</code> if the identifier is a property definition ID for the specified * namespace provider */ public static boolean isExtensionPropertyId( String propId, NamespaceProvider namespaceProvider) { CoreArgCheck.isNotEmpty(propId, "propId is empty"); // $NON-NLS-1$ CoreArgCheck.isNotNull(namespaceProvider, "namespaceProvider is null"); // $NON-NLS-1$ String nsPrefix = namespaceProvider.getNamespacePrefix(); if (CoreStringUtil.isEmpty(nsPrefix)) { return false; } String propNsPrefix = getNamespacePrefix(propId); if (CoreStringUtil.isEmpty(propNsPrefix)) { return false; } return propNsPrefix.equals(nsPrefix); }
private Collection findEntitiesByName( final Object container, final String entityName, final char recordType, final boolean isPartialName) { CoreArgCheck.isNotEmpty(entityName); AbstractNameFinder finder = null; switch (recordType) { case IndexConstants.RECORD_TYPE.MODEL: finder = new ModelNameFinder(entityName, isPartialName); break; case IndexConstants.RECORD_TYPE.TABLE: finder = new TableNameFinder(entityName, isPartialName); break; case IndexConstants.RECORD_TYPE.CALLABLE: finder = new ProcedureNameFinder(entityName, isPartialName); break; case IndexConstants.RECORD_TYPE.CALLABLE_PARAMETER: case IndexConstants.RECORD_TYPE.COLUMN: finder = new ColumnNameFinder(entityName, isPartialName); break; case IndexConstants.RECORD_TYPE.RESULT_SET: case IndexConstants.RECORD_TYPE.INDEX: case IndexConstants.RECORD_TYPE.ACCESS_PATTERN: case IndexConstants.RECORD_TYPE.PRIMARY_KEY: case IndexConstants.RECORD_TYPE.UNIQUE_KEY: case IndexConstants.RECORD_TYPE.FOREIGN_KEY: finder = new ColumnNameFinder(entityName, isPartialName); break; case IndexConstants.RECORD_TYPE.SELECT_TRANSFORM: case IndexConstants.RECORD_TYPE.INSERT_TRANSFORM: case IndexConstants.RECORD_TYPE.UPDATE_TRANSFORM: case IndexConstants.RECORD_TYPE.DELETE_TRANSFORM: case IndexConstants.RECORD_TYPE.PROC_TRANSFORM: case IndexConstants.RECORD_TYPE.MAPPING_TRANSFORM: return getTransforMationsForTable(container, entityName, recordType, isPartialName); case IndexConstants.RECORD_TYPE.DATATYPE: // case IndexConstants.RECORD_TYPE.DATATYPE_ELEMENT: // case IndexConstants.RECORD_TYPE.DATATYPE_FACET: finder = new DatatypeNameFinder(entityName, isPartialName); break; case IndexConstants.RECORD_TYPE.VDB_ARCHIVE: case IndexConstants.RECORD_TYPE.ANNOTATION: case IndexConstants.RECORD_TYPE.PROPERTY: case IndexConstants.RECORD_TYPE.JOIN_DESCRIPTOR: break; default: throw new ModelerCoreRuntimeException( TransformationPlugin.Util.getString( "TransformationMetadata.No_known_index_file_type_associated_with_the_recordType_1", new Character(recordType))); // $NON-NLS-1$ } if (finder != null) { executeVisitor(container, finder, ModelVisitorProcessor.DEPTH_INFINITE); return finder.getMatchingEObjects(); } return Collections.EMPTY_LIST; }
/** * 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; }