List of usage examples for org.springframework.ide.eclipse.beans.core.model IBeansProject getProject
IProject getProject();
From source file:org.springframework.ide.eclipse.beans.core.internal.model.BeansJavaConfig.java
public BeansJavaConfig(IBeansProject project, IType configClass, String configClassName, Type type) { super(project, BeansConfigFactory.JAVA_CONFIG_TYPE + configClassName, type); this.configClass = configClass; this.configClassName = configClassName; modificationTimestamp = IResource.NULL_STAMP; if (this.configClass != null) { IResource resource = this.configClass.getResource(); if (resource != null && resource instanceof IFile) { file = (IFile) resource;/*from ww w . j av a 2s .c o m*/ } else { IClassFile classFile = configClass.getClassFile(); PackageFragment pkg = (PackageFragment) configClass.getPackageFragment(); IPackageFragmentRoot root = (IPackageFragmentRoot) pkg.getParent(); if (root.isArchive()) { IPath zipPath = root.getPath(); String classFileName = classFile.getElementName(); String path = Util.concatWith(pkg.names, classFileName, '/'); file = new ExternalFile(zipPath.toFile(), path, project.getProject()); } } } if (file == null || !file.exists()) { modificationTimestamp = IResource.NULL_STAMP; String msg = "Beans Java config class '" + configClassName + "' not accessible"; problems = new CopyOnWriteArraySet<ValidationProblem>(); problems.add(new ValidationProblem(IMarker.SEVERITY_ERROR, msg, file, -1)); } else { modificationTimestamp = file.getModificationStamp(); try { file.setSessionProperty(IBeansConfig.CONFIG_FILE_TAG, IBeansConfig.CONFIG_FILE_TAG_VALUE); } catch (CoreException e) { BeansCorePlugin.log(new Status(IStatus.WARNING, BeansCorePlugin.PLUGIN_ID, String.format("Error occured while tagging config file '%s'", file.getFullPath()), e)); } } }
From source file:org.springframework.ide.eclipse.beans.core.internal.model.BeansJavaConfig.java
@Override protected void readConfig() { if (!isModelPopulated) { w.lock();/* w w w .j a v a2 s . c om*/ if (this.isModelPopulated) { w.unlock(); return; } try { if (this.configClass == null) { return; } IBeansProject beansProject = BeansModelUtils.getParentOfClass(this, IBeansProject.class); if (beansProject == null) { return; } final ClassLoader cl = JdtUtils.getClassLoader(beansProject.getProject(), ApplicationContext.class.getClassLoader()); if (cl.getResource(this.configClass.getFullyQualifiedName().replace('.', '/') + ".class") == null) { return; } Callable<Integer> loadBeanDefinitionOperation = new Callable<Integer>() { public Integer call() throws Exception { // Obtain thread context classloader and override with the project classloader ClassLoader threadClassLoader = Thread.currentThread().getContextClassLoader(); Thread.currentThread().setContextClassLoader(cl); // Create special ReaderEventListener that essentially just passes through component definitions ReaderEventListener eventListener = new BeansConfigPostProcessorReaderEventListener(); problemReporter = new BeansConfigProblemReporter(); beanNameGenerator = new UniqueBeanNameGenerator(BeansJavaConfig.this); registry = new ScannedGenericBeanDefinitionSuppressingBeanDefinitionRegistry(); try { registerAnnotationProcessors(eventListener); registerBean(eventListener, cl); IBeansConfigPostProcessor[] postProcessors = BeansConfigPostProcessorFactory .createPostProcessor(ConfigurationClassPostProcessor.class.getName()); for (IBeansConfigPostProcessor postProcessor : postProcessors) { executePostProcessor(postProcessor, eventListener); } } finally { // Reset the context classloader Thread.currentThread().setContextClassLoader(threadClassLoader); LogFactory.release(cl); //Otherwise permgen leak? } return 0; } }; FutureTask<Integer> task = new FutureTask<Integer>(loadBeanDefinitionOperation); BeansCorePlugin.getExecutorService().submit(task); task.get(BeansCorePlugin.getDefault().getPreferenceStore() .getInt(BeansCorePlugin.TIMEOUT_CONFIG_LOADING_PREFERENCE_ID), TimeUnit.SECONDS); } catch (TimeoutException e) { problems.add(new ValidationProblem(IMarker.SEVERITY_ERROR, "Loading of configuration '" + this.configClass.getFullyQualifiedName() + "' took more than " + BeansCorePlugin.getDefault().getPreferenceStore() .getInt(BeansCorePlugin.TIMEOUT_CONFIG_LOADING_PREFERENCE_ID) + "sec", file, 1)); } catch (Exception e) { problems.add(new ValidationProblem(IMarker.SEVERITY_ERROR, String.format("Error occured processing Java config '%s'. See Error Log for more details", e.getCause().getMessage()), getElementResource())); BeansCorePlugin.log(new Status(IStatus.INFO, BeansCorePlugin.PLUGIN_ID, String.format("Error occured processing '%s'", this.configClass.getFullyQualifiedName()), e.getCause())); } finally { // Prepare the internal cache of all children for faster access List<ISourceModelElement> allChildren = new ArrayList<ISourceModelElement>(imports); allChildren.addAll(aliases.values()); allChildren.addAll(components); allChildren.addAll(beans.values()); Collections.sort(allChildren, new Comparator<ISourceModelElement>() { public int compare(ISourceModelElement element1, ISourceModelElement element2) { return element1.getElementStartLine() - element2.getElementStartLine(); } }); this.children = allChildren.toArray(new IModelElement[allChildren.size()]); this.isModelPopulated = true; w.unlock(); } } }