public boolean isMofResourceLoaded(java.lang.String uri) { Resource res = getExistingMofResource(uri); return res != null && res.isLoaded(); }
/** * @see com.ibm.etools.commonarchive.Archive returns an immutable collection of the loaded * resources in the resource set */ public Collection getLoadedMofResources() { Collection resources = getResourceSet().getResources(); if (resources.isEmpty()) return Collections.EMPTY_LIST; List copyResources = new ArrayList(); copyResources.addAll(resources); List result = new ArrayList(copyResources.size()); Iterator iter = copyResources.iterator(); while (iter.hasNext()) { Resource res = (Resource) iter.next(); if (res.isLoaded()) result.add(res); } return result; }
/** * Handles installation of the adapter on a Resource * by adding the adapter to each of the directly contained objects. */ protected void setTarget(Resource target) { if (!target.isLoaded()) { unloadedResources.add(target); } List<EObject> contents = target.getContents(); for (int i = 0, size = contents.size(); i < size; ++i) { Notifier notifier = contents.get(i); addAdapter(notifier); } }
/** * Handles installation of the adapter on a Resource * by adding the adapter to each of the directly contained objects. */ protected void setTarget(Resource target) { if (!target.isLoaded()) { unloadedResources.add(target); } List<EObject> contents = target.getContents(); for (int i = 0, size = contents.size(); i < size; ++i) { Notifier notifier = contents.get(i); addAdapter(notifier); } }
@Override public Iterable<String> getAllModelNamesOfType(final String modelType) { synchronized (resourceSet) { // Make a copy to avoid ConcurrentModificationException List<Resource> resourceListCopy = new ArrayList<Resource>(resourceSet.getResources()); return resourceListCopy.stream().filter(input -> { return input != null && input.getURI().lastSegment().contains(".") && input.isLoaded() && modelType.equalsIgnoreCase(input.getURI().fileExtension()); }).map(from -> { return from.getURI().path(); }).collect(Collectors.toList()); } }
@Override public boolean apply(Resource input) { if (input != null && input.getURI().lastSegment().contains(".") && input.isLoaded()) { return modelType.equalsIgnoreCase(input.getURI().fileExtension()); } else { return false; } } });
/** * Return a Resource for * * @aUri. */ protected Resource getAndLoadLocalResource(URI aUri) { Resource resource = getLocalResource(aUri); if (null != resource && !resource.isLoaded()) { try { resource.load(Collections.EMPTY_MAP); // reload it } catch (IOException e) { // Ignore } } return resource; }
/** * return the WSDLResource if it exists, otherwise return null */ public Resource getWsdlResource(String path) { if (path == null || path.equals(""))return null; //$NON-NLS-1$ Resource res = null; try { res = getArtifactEditModel().getResource(URI.createURI(path)); } catch (Exception e) { // Ignore } WSDLServiceHelper serviceHelper = WSDLServiceExtManager.getServiceHelper(); if (res != null && res.isLoaded() && serviceHelper != null && serviceHelper.isWSDLResource(res)) return res; return null; } public IModelProvider create(IProject project) {
@Override protected List<EObject> findEObjectsOfType(Set<EClass> eClasses, IResourceDescriptions resourceDescriptions, ResourceSet resourceSet) { List<EObject> result = Lists.newArrayList(); for (Resource resource : resourceSet.getResources()) { if (!resource.isLoaded()) { try { resource.load(null); } catch (IOException e) { throw new WrappedException(e); } } } for (Iterator<Notifier> i = resourceSet.getAllContents(); i.hasNext();) { Notifier next = i.next(); if (next instanceof EObject && matches(eClasses, (EObject) next)) { result.add((EObject) next); } } return result; }
protected boolean processResource(IFile aFile, boolean isRemove) { Resource resource = getResource(aFile); if ((resource != null) || (recentlySavedFiles.contains(resource))){ if (resource.isModified()) { if (WorkbenchResourceHelper.isReferencedResource(resource)) { ReferencedResource refRes = (ReferencedResource) resource; if (!refRes.shouldForceRefresh()) return false; //Do not do anything } else return false; } if (isRemove) deferredRemoveResources.add(resource); else if (resource.isLoaded()) { if ( WorkbenchResourceHelper.isReferencedResource(resource)) { if(!WorkbenchResourceHelper.isConsistent((ReferencedResource)resource)) deferredUnloadResources.add(resource); } else deferredUnloadResources.add(resource); } } return false; }
public EObject getEObject(URI uri, boolean loadOnDemand) { if (isReleasing) return null; Resource resource = getResource(uri.trimFragment(), loadOnDemand); EObject result = null; if (resource != null && resource.isLoaded()) result = resource.getEObject(uri.fragment()); if (result == null) result = getEObjectFromHandlers(uri, loadOnDemand); return result; } /**
@Override protected List<IEObjectDescription> computeExportedObjects() { if (!getResource().isLoaded()) { try { getResource().load(null); } catch (IOException e) { log.error(e.getMessage(), e); return Collections.<IEObjectDescription> emptyList(); } } final List<IEObjectDescription> exportedEObjects = newArrayList(); IAcceptor<IEObjectDescription> acceptor = new IAcceptor<IEObjectDescription>() { public void accept(IEObjectDescription eObjectDescription) { exportedEObjects.add(eObjectDescription); } }; TreeIterator<EObject> allProperContents = EcoreUtil.getAllProperContents(getResource(), false); while (allProperContents.hasNext()) { EObject content = allProperContents.next(); if (!strategy.createEObjectDescriptions(content, acceptor)) allProperContents.prune(); } return exportedEObjects; }
public void notifyChanged(Notification notification) { Resource res = (Resource) notification.getNotifier(); if (notification.getEventType() == Notification.SET && notification.getFeatureID(null) == Resource.RESOURCE__IS_LOADED && !res.isLoaded()) { J2EEApplicationItemProvider.this.children.remove(app); res.eAdapters().remove(ResourceAdapter.this); fireNotifyChanged(new J2EENotificationImpl(app, Notification.MOVE, (Object) null, (Object) null, 0)); } } }
@Override public Set<String> removeAllModelsOfType(final String modelType) { Set<String> ret = new HashSet<>(); synchronized (resourceSet) { // Make a copy to avoid ConcurrentModificationException List<Resource> resourceListCopy = new ArrayList<Resource>(resourceSet.getResources()); for (Resource resource : resourceListCopy) { if (resource != null && resource.getURI().lastSegment().contains(".") && resource.isLoaded()) { if (modelType.equalsIgnoreCase(resource.getURI().fileExtension())) { logger.debug("Removing resource '{}'", resource.getURI().lastSegment()); ret.add(resource.getURI().lastSegment()); resourceSet.getResources().remove(resource); notifyListeners(resource.getURI().lastSegment(), EventType.REMOVED); } } } } return ret; }
@Override public Set<String> removeAllModelsOfType(final String modelType) { Set<String> ret = new HashSet<>(); synchronized (resourceSet) { // Make a copy to avoid ConcurrentModificationException List<Resource> resourceListCopy = new ArrayList<Resource>(resourceSet.getResources()); for (Resource resource : resourceListCopy) { if (resource != null && resource.getURI().lastSegment().contains(".") && resource.isLoaded()) { if (modelType.equalsIgnoreCase(resource.getURI().fileExtension())) { logger.debug("Removing resource '{}'", resource.getURI().lastSegment()); ret.add(resource.getURI().lastSegment()); resourceSet.getResources().remove(resource); notifyListeners(resource.getURI().lastSegment(), EventType.REMOVED); } } } } return ret; }
@Override public void reloadAllModelsOfType(final String modelType) { synchronized (resourceSet) { // Make a copy to avoid ConcurrentModificationException List<Resource> resourceListCopy = new ArrayList<Resource>(resourceSet.getResources()); for (Resource resource : resourceListCopy) { if (resource != null && resource.getURI().lastSegment().contains(".") && resource.isLoaded()) { if (modelType.equalsIgnoreCase(resource.getURI().fileExtension())) { XtextResource xtextResource = (XtextResource) resource; // It's not sufficient to discard the derived state. // The quick & dirts solution is to reparse the whole resource. // We trigger this by dummy updating the resource. logger.debug("Refreshing resource '{}'", resource.getURI().lastSegment()); xtextResource.update(1, 0, ""); notifyListeners(resource.getURI().lastSegment(), EventType.MODIFIED); } } } } }
@Override public void reloadAllModelsOfType(final String modelType) { synchronized (resourceSet) { // Make a copy to avoid ConcurrentModificationException List<Resource> resourceListCopy = new ArrayList<Resource>(resourceSet.getResources()); for (Resource resource : resourceListCopy) { if (resource != null && resource.getURI().lastSegment().contains(".") && resource.isLoaded()) { if (modelType.equalsIgnoreCase(resource.getURI().fileExtension())) { XtextResource xtextResource = (XtextResource) resource; // It's not sufficient to discard the derived state. // The quick & dirts solution is to reparse the whole resource. // We trigger this by dummy updating the resource. logger.debug("Refreshing resource '{}'", resource.getURI().lastSegment()); xtextResource.update(1, 0, ""); notifyListeners(resource.getURI().lastSegment(), EventType.MODIFIED); } } } } }
/** * Disposes me by unloading my resource, if and only if I created it in * the first place. If I was loaded from an existing resource, then it is * the client's responsibility to manage it. * * @since 1.2 */ public void dispose() { if (shouldDisposeResource && (resource != null)) { if (resource.isLoaded()) { resource.unload(); } if (resource.getResourceSet() != null) { resource.getResourceSet().getResources().remove(resource); } resource = null; } } }
/** * Disposes me by unloading my resource, if and only if I created it in * the first place. If I was loaded from an existing resource, then it is * the client's responsibility to manage it. * * @since 1.2 */ public void dispose() { if (shouldDisposeResource && (resource != null)) { if (resource.isLoaded()) { resource.unload(); } if (resource.getResourceSet() != null) { resource.getResourceSet().getResources().remove(resource); } resource = null; } } }
private void addRegisterEcoreFile(String fileName) throws IllegalArgumentException, SecurityException { Resource res = resourceSet.getResource(createURI(fileName), true); if (res == null) { throw new ConfigurationException("Couldn't find resource under " + fileName); } if (!res.isLoaded()) { try { res.load(null); } catch (IOException e) { throw new ConfigurationException("Couldn't load resource under " + fileName + " : " + e.getMessage()); } } List<EObject> result = res.getContents(); for (EObject object : result) { if (object instanceof EPackage) { registerPackage(fileName, object); } for (final TreeIterator<EObject> it = object.eAllContents(); it.hasNext();) { EObject child = it.next(); if (child instanceof EPackage) { registerPackage(fileName, child); } } } }