/** {@inheritDoc} */ public IHyperlink createHyperlink( String name, String target, Node node, Node parentNode, IDocument document, ITextViewer textViewer, IRegion hyperlinkRegion, IRegion cursor) { String parentName = null; if (parentNode != null) { parentName = parentNode.getNodeName(); } List<String> propertyPaths = new ArrayList<String>(); hyperlinkRegion = BeansEditorUtils.extractPropertyPathFromCursorPosition( hyperlinkRegion, cursor, target, propertyPaths); if ("bean".equals(parentName) && StringUtils.hasText(target)) { IFile file = BeansEditorUtils.getFile(document); String className = BeansEditorUtils.getClassNameForBean(file, node.getOwnerDocument(), parentNode); IType type = JdtUtils.getJavaType(file.getProject(), className); if (type != null) { IBeansConfig config = BeansCorePlugin.getModel().getConfig(file); if (config != null && parentNode instanceof Element) { IModelElement element = BeansModelUtils.getModelElement((Element) parentNode, config); int argIndex = getArgumentIndex(node); if (argIndex >= 0) { if (element instanceof IBean) { IBean bean = (IBean) element; int count = bean.getConstructorArguments().size(); if (count > 0) { try { Set<IMethod> methods = Introspector.getConstructors(type, count, false); Iterator<IMethod> iter = methods.iterator(); while (iter.hasNext()) { IMethod candidate = iter.next(); if (target.equalsIgnoreCase(candidate.getParameterNames()[argIndex])) { // return new JavaElementHyperlink(hyperlinkRegion, // candidate.getParameters()[argIndex]); // TODO: just a temporary workaround for making this Eclipse 3.6 compatible return new JavaElementHyperlink(hyperlinkRegion, candidate); } } } catch (JavaModelException e) { // do nothing } } } } } } } return null; }
/** {@inheritDoc} */ public void cleanup(IResource resource, IProgressMonitor monitor) throws CoreException { if (BeansCoreUtils.isBeansConfig(resource) && resource instanceof IFile) { IBeansConfig beansConfig = BeansCorePlugin.getModel().getConfig((IFile) resource); for (IBean bean : beansConfig.getBeans()) { BeansMetadataPlugin.getMetadataModel().clearBeanMetadata(bean); BeansMetadataPlugin.getMetadataModel().clearBeanProperties(bean); } // Notify that the model has changed. // ((BeansModel) BeansCorePlugin.getModel()).notifyListeners(beansConfig, Type.CHANGED); } }
@Override protected boolean selectFile(IFile element) { if ("pom.xml".equals(element.getName())) { return false; } IBeansProject project = BeansCorePlugin.getModel().getProject(element.getProject()); if (project != null) { IBeansConfig beansConfig = project.getConfig(element); return beansConfig == null; } return false; }
public static INamespaceDefinition getDefaultNamespaceDefinition() { INamespaceDefinitionResolver definitionResolver = BeansCorePlugin.getNamespaceDefinitionResolver(null); org.springframework.ide.eclipse.beans.core.model.INamespaceDefinition namespaceDefinition = definitionResolver.resolveNamespaceDefinition(DEFAULT_NAMESPACE_URI); IExtensionPoint point = Platform.getExtensionRegistry().getExtensionPoint(NAMESPACES_EXTENSION_POINT); if (point != null) { String namespaceURI = DEFAULT_NAMESPACE_URI; for (IExtension extension : point.getExtensions()) { for (IConfigurationElement config : extension.getConfigurationElements()) { if (namespaceURI.equals(config.getAttribute("uri"))) { String prefix = config.getAttribute("prefix"); if (!StringUtils.hasText(prefix) && namespaceDefinition != null) { prefix = namespaceDefinition.getPrefix(); } String schemaLocation = config.getAttribute("defaultSchemaLocation"); if (!StringUtils.hasText(schemaLocation) && namespaceDefinition != null) { schemaLocation = namespaceDefinition.getDefaultSchemaLocation(); } String uri = config.getAttribute("uri"); IImageAccessor image = null; if (config.getAttribute("icon") != null) { String ns = config.getDeclaringExtension().getNamespaceIdentifier(); String icon = config.getAttribute("icon"); image = new DefaultImageAccessor(ns, icon); } else if (namespaceDefinition != null) { image = new NamespaceDefinitionImageAccessor(namespaceDefinition); } return new DefaultNamespaceDefinition( prefix, uri, schemaLocation, namespaceDefinition.getUriMapping(), image); } } } } if (namespaceDefinition != null) { return new DefaultNamespaceDefinition( namespaceDefinition.getPrefix(), namespaceDefinition.getNamespaceUri(), namespaceDefinition.getDefaultSchemaLocation(), namespaceDefinition.getUriMapping(), new NamespaceDefinitionImageAccessor(namespaceDefinition)); } return null; }
@Override public String getText(Object element) { String label = super.getText(element); if (element instanceof IFile) { IBeansConfig bc = BeansCorePlugin.getModel().getConfig((IFile) element, true); if (bc instanceof IImportedBeansConfig) { label += " [imported]"; } if (bc != null && bc.getType() == IBeansConfig.Type.AUTO_DETECTED) { label += " [auto detected]"; } } else if (element instanceof ZipEntryStorage) { return ((ZipEntryStorage) element).getEntryName(); } if (label != null && label.startsWith(IBeansConfig.EXTERNAL_FILE_NAME_PREFIX)) { label = label.substring(IBeansConfig.EXTERNAL_FILE_NAME_PREFIX.length()); } return label; }
protected static List<INamespaceDefinition> getNamespaceDefinitions(IProject project) { List<INamespaceDefinition> namespaceDefinitions = new ArrayList<INamespaceDefinition>(); INamespaceDefinitionResolver definitionResolver = BeansCorePlugin.getNamespaceDefinitionResolver(project); Set<org.springframework.ide.eclipse.beans.core.model.INamespaceDefinition> detectedNamespaceDefinitions = definitionResolver.getNamespaceDefinitions(); IExtensionPoint point = Platform.getExtensionRegistry().getExtensionPoint(NAMESPACES_EXTENSION_POINT); if (point != null && !org.springframework.ide.eclipse.beans.core.namespaces.NamespaceUtils .useNamespacesFromClasspath(project)) { for (IExtension extension : point.getExtensions()) { for (IConfigurationElement config : extension.getConfigurationElements()) { String uri = config.getAttribute("uri"); org.springframework.ide.eclipse.beans.core.model.INamespaceDefinition namespaceDefinition = definitionResolver.resolveNamespaceDefinition(uri); detectedNamespaceDefinitions.remove(namespaceDefinition); String prefix = config.getAttribute("prefix"); if (!StringUtils.hasText(prefix) && namespaceDefinition != null) { prefix = namespaceDefinition.getPrefix(); } String schemaLocation = config.getAttribute("defaultSchemaLocation"); if (!StringUtils.hasText(schemaLocation) && namespaceDefinition != null) { schemaLocation = namespaceDefinition.getDefaultSchemaLocation(); } IImageAccessor image = null; if (config.getAttribute("icon") != null) { String ns = config.getDeclaringExtension().getNamespaceIdentifier(); String icon = config.getAttribute("icon"); image = new DefaultImageAccessor(ns, icon); } else if (namespaceDefinition != null) { image = new NamespaceDefinitionImageAccessor(namespaceDefinition); } DefaultNamespaceDefinition def = null; if (namespaceDefinition != null) { def = new DefaultNamespaceDefinition( prefix, uri, schemaLocation, namespaceDefinition.getUriMapping(), image); } else { def = new DefaultNamespaceDefinition( prefix, uri, schemaLocation, new Properties(), image); } // get schema locations from nested child elements IConfigurationElement[] schemaLocationConfigElements = config.getChildren("schemaLocation"); for (IConfigurationElement schemaLocationConfigElement : schemaLocationConfigElements) { def.addSchemaLocation(schemaLocationConfigElement.getAttribute("url")); } if (def.getSchemaLocations().size() == 0 && namespaceDefinition != null) { def.getSchemaLocations().addAll(namespaceDefinition.getSchemaLocations()); } namespaceDefinitions.add(def); } } } for (org.springframework.ide.eclipse.beans.core.model.INamespaceDefinition namespaceDefinition : detectedNamespaceDefinitions) { DefaultNamespaceDefinition def = new DefaultNamespaceDefinition( namespaceDefinition.getPrefix(), namespaceDefinition.getNamespaceUri(), namespaceDefinition.getDefaultSchemaLocation(), namespaceDefinition.getUriMapping(), new NamespaceDefinitionImageAccessor(namespaceDefinition)); def.getSchemaLocations().addAll(namespaceDefinition.getSchemaLocations()); namespaceDefinitions.add(def); } boolean foundPNamespace = false; boolean foundCNamespace = false; INamespaceDefinition defaultNamespace = null; // Remove the tool namespace as we don't want to surface on the UI for (INamespaceDefinition definition : new ArrayList<INamespaceDefinition>(namespaceDefinitions)) { if (TOOLS_NAMESPACE_URI.equals(definition.getNamespaceURI())) { namespaceDefinitions.remove(definition); } else if (DEFAULT_NAMESPACE_URI.equals(definition.getNamespaceURI())) { defaultNamespace = definition; } else if (P_NAMESPACE_URI.equals(definition.getNamespaceURI())) { foundPNamespace = true; } else if (C_NAMESPACE_URI.equals(definition.getNamespaceURI())) { foundCNamespace = true; } } if (!foundPNamespace && defaultNamespace != null) { // Add in p-Namespace if we found the default namespace namespaceDefinitions.add(P_NAMESPACE_DEFINITION); } if (!foundCNamespace && defaultNamespace != null) { // Add in c-Namespace if we found the default namespace // && is Spring 3.1 or greater Set<String> locations = defaultNamespace.getSchemaLocations(); for (String locationUri : locations) { if (isSpring31(locationUri)) { namespaceDefinitions.add(C_NAMESPACE_DEFINITION); break; } } } Collections.sort( namespaceDefinitions, new Comparator<INamespaceDefinition>() { public int compare(INamespaceDefinition o1, INamespaceDefinition o2) { if (o1 != null && o1.getDefaultNamespacePrefix() != null && o2 != null && o2.getDefaultNamespacePrefix() != null) { return o1.getDefaultNamespacePrefix().compareTo(o2.getDefaultNamespacePrefix()); } return 0; } }); return namespaceDefinitions; }
/** Filters out every {@link IFile} which is has unknown root elements in its XML content. */ @Override protected Set<IFile> filterMatchingFiles(Set<IFile> files) { // if project is a java project remove bin dirs from the list Set<String> outputDirectories = new HashSet<String>(); IJavaProject javaProject = JdtUtils.getJavaProject(project); if (javaProject != null) { try { // add default output directory outputDirectories.add(javaProject.getOutputLocation().toString()); // add source folder specific output directories for (IClasspathEntry entry : javaProject.getRawClasspath()) { if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE && entry.getOutputLocation() != null) { outputDirectories.add(entry.getOutputLocation().toString()); } } } catch (JavaModelException e) { BeansCorePlugin.log(e); } } Set<IFile> detectedFiles = new LinkedHashSet<IFile>(); for (IFile file : files) { boolean skip = false; // first check if the file sits in an output directory String path = file.getFullPath().toString(); for (String outputDirectory : outputDirectories) { if (path.startsWith(outputDirectory)) { skip = true; } } if (skip) { continue; } // check if the file is known Spring xml file IStructuredModel model = null; try { try { model = StructuredModelManager.getModelManager().getExistingModelForRead(file); } catch (RuntimeException e) { // sometimes WTP throws a NPE in concurrency situations } if (model == null) { model = StructuredModelManager.getModelManager().getModelForRead(file); } if (model != null) { IDOMDocument document = ((DOMModelImpl) model).getDocument(); if (document != null && document.getDocumentElement() != null) { String namespaceUri = document.getDocumentElement().getNamespaceURI(); if (applyNamespaceFilter(file, namespaceUri)) { detectedFiles.add(file); } } } } catch (IOException e) { BeansCorePlugin.log(e); } catch (CoreException e) { BeansCorePlugin.log(e); } finally { if (model != null) { model.releaseFromRead(); } } } return detectedFiles; }