private static String getXsdTargetNamespace(final IResource iResource) { if (ModelUtil.isXsdFile(iResource)) { final String location = iResource.getLocation().toOSString(); final File resourceFile = new File(location); if (resourceFile.exists()) try { final XsdHeader header = XsdHeaderReader.readHeader(resourceFile); if (header != null) return header.getTargetNamespaceURI(); } catch (final TeiidException e) { ModelerCore.Util.log(IStatus.ERROR, e, e.getMessage()); } } return null; }
/** * Return IResource[] array representing the dependent IResource instances. The dependent * resources are found by reading the model imports declarations in the specified resource. Only * references to IResource instances that can be found in the workspace will be returned. If an * import declaration to one of the well-know Teiid Designer/EMF global resources such as * * <p>"http://www.metamatrix.com/metamodels/SimpleDatatypes-instance" * "http://www.w3.org/2001/XMLSchema" "http://www.w3.org/2001/MagicXMLSchema" * "http://www.w3.org/2001/XMLSchema-instance" is encountered, a corresponding IResource does not * exist in the workspace and, therefore, cannot be returned as part of the result. If the method * is called outside of the Eclipse runtime environment, or if the specified IResource is null or * cannot be found on the file system then an empty array will be returned. * * @param iResource the IResource to examine for import declarations. If null, or it not running * in a Eclipse runtime environment, an empty array will be returned. * @return the IResource[] references of dependent resources */ public static IResource[] getDependentResources(final IResource iResource) { if (iResource == null || getWorkspace() == null) return EMPTY_IRESOURCE_ARRAY; final File iResourceFile = iResource.getRawLocation().toFile(); if (!iResourceFile.exists()) return EMPTY_IRESOURCE_ARRAY; final Collection result = new ArrayList(); try { // Get the header information from the XSD file if (ModelUtil.isXsdFile(iResource)) { final XsdHeader header = XsdHeaderReader.readHeader(iResourceFile); if (header != null) { // Add all the imported schema locations String[] locations = header.getImportSchemaLocations(); for (int i = 0; i != locations.length; ++i) { final String location = locations[i]; IResource dependentIResource = findIResource(location); if (dependentIResource == null) { final String absolutePath = getAbsoluteLocation(iResourceFile, location); dependentIResource = findIResource(absolutePath); } if (dependentIResource != null && !result.contains(dependentIResource)) result.add(dependentIResource); } // Add all the included schema locations locations = header.getIncludeSchemaLocations(); for (int i = 0; i != locations.length; ++i) { final String location = locations[i]; IResource dependentIResource = findIResource(location); if (dependentIResource == null) { final String absolutePath = getAbsoluteLocation(iResourceFile, location); dependentIResource = findIResource(absolutePath); } if (dependentIResource != null && !result.contains(dependentIResource)) result.add(dependentIResource); } } // Get the header information from the XMI file } else if (ModelUtil.isModelFile(iResource)) { final XMIHeader header = XMIHeaderReader.readHeader(iResourceFile); if (header != null) { final ModelImportInfo[] infos = header.getModelImportInfos(); for (final ModelImportInfo info : infos) { IResource dependentIResource = null; final String location = info.getLocation(); final String path = info.getPath(); if (!CoreStringUtil.isEmpty(path)) dependentIResource = findIResource(path); else if (!CoreStringUtil.isEmpty(location)) { final String depPath = iResource.getFullPath().removeLastSegments(1).append(location).toString(); if (!isGlobalResource(depPath)) { dependentIResource = findIResource(depPath); if (dependentIResource == null) { final String absolutePath = getAbsoluteLocation(iResourceFile, location); dependentIResource = findIResource(absolutePath); } } } if (dependentIResource != null && !result.contains(dependentIResource)) result.add(dependentIResource); } } // Get the header information from the VDB archive file } else if (ModelUtil.isVdbArchiveFile(iResource)) { final XMIHeader header = ModelUtil.getXmiHeader(iResourceFile); if (header != null) { final ModelImportInfo[] infos = header.getModelImportInfos(); for (final ModelImportInfo info : infos) { IResource dependentIResource = null; final String location = info.getLocation(); final String path = info.getPath(); if (!CoreStringUtil.isEmpty(path)) dependentIResource = findIResource(path); else if (!CoreStringUtil.isEmpty(location)) if (!isGlobalResource(location)) { dependentIResource = findIResource(location); if (dependentIResource == null) { final String absolutePath = getAbsoluteLocation(iResourceFile, location); dependentIResource = findIResource(absolutePath); } } if (dependentIResource != null && !result.contains(dependentIResource)) result.add(dependentIResource); } } } } catch (final Exception err) { final Object[] params = new Object[] {iResource.getFullPath()}; final String msg = ModelerCore.Util.getString( "WorkspaceResourceFinderUtil.Error_getting_model_imports_from_resource", params); //$NON-NLS-1$ ModelerCore.Util.log(IStatus.ERROR, err, msg); } return (IResource[]) result.toArray(new IResource[result.size()]); }