Java Code Examples for org.netbeans.api.java.classpath.ClassPath#getClassLoader()
The following examples show how to use
org.netbeans.api.java.classpath.ClassPath#getClassLoader() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JavaUtil.java From netbeans with Apache License 2.0 | 6 votes |
public static Class getType(Project project, String typeName) { List<ClassPath> classPaths = SourceGroupSupport.gerClassPath(project); for (ClassPath cp : classPaths) { try { Class ret = Util.getPrimitiveType(typeName); if (ret != null) { return ret; } ClassLoader cl = cp.getClassLoader(true); ret = Util.getGenericRawType(typeName, cl); if (ret != null) { return ret; } if (cl != null) { return cl.loadClass(typeName); } } catch (ClassNotFoundException ex) { //Logger.global.log(Level.INFO, ex.getLocalizedMessage(), ex); } } return null; }
Example 2
Source File: RestWrapperForSoapGenerator.java From netbeans with Apache License 2.0 | 6 votes |
public Class getType(Project project, String typeName) { List<ClassPath> classPaths = getClassPath(project); for (ClassPath cp : classPaths) { try { Class ret = getPrimitiveType(typeName); if (ret != null) { return ret; } ClassLoader cl = cp.getClassLoader(true); ret = getGenericRawType(typeName, cl); if (ret != null) { return ret; } if (cl != null) { return cl.loadClass(typeName); } } catch (ClassNotFoundException ex) { //Logger.global.log(Level.INFO, ex.getLocalizedMessage(), ex); } } return null; }
Example 3
Source File: Util.java From netbeans with Apache License 2.0 | 6 votes |
public static Class getType(Project project, String typeName) { List<ClassPath> classPaths = SourceGroupSupport.gerClassPath(project); for (ClassPath cp : classPaths) { try { Class ret = Util.getPrimitiveType(typeName); if (ret != null) { return ret; } ClassLoader cl = cp.getClassLoader(true); ret = getGenericRawType(typeName, cl); if (ret != null) { return ret; } if (cl != null) { return cl.loadClass(typeName); } } catch (ClassNotFoundException ex) { //Logger.global.log(Level.INFO, ex.getLocalizedMessage(), ex); } } return null; }
Example 4
Source File: ProjectHelper.java From jeddict with Apache License 2.0 | 6 votes |
public static Class getType(Project project, String typeName) { List<ClassPath> classPaths = gerClassPath(project); for (ClassPath cp : classPaths) { try { Class ret = JavaUtil.getPrimitiveType(typeName); if (ret != null) { return ret; } ClassLoader cl = cp.getClassLoader(true); ret = getGenericRawType(typeName, cl); if (ret != null) { return ret; } if (cl != null) { return cl.loadClass(typeName); } } catch (ClassNotFoundException ex) { //Logger.global.log(Level.INFO, ex.getLocalizedMessage(), ex); } } return null; }
Example 5
Source File: ProjectClassLoader.java From netbeans with Apache License 2.0 | 5 votes |
static ClassLoader getUpToDateClassLoader(FileObject fileInProject, ClassLoader clSoFar) { ClassLoader existingCL = clSoFar instanceof ProjectClassLoader ? ((ProjectClassLoader)clSoFar).projectClassLoaderDelegate : clSoFar; ClassPath classPath = ClassPath.getClassPath(fileInProject, ClassPath.EXECUTE); ClassLoader actualCL = classPath != null ? classPath.getClassLoader(true) : null; if (actualCL == existingCL) return clSoFar; if (actualCL == null) return null; return new ProjectClassLoader(actualCL, ClassPath.getClassPath(fileInProject, ClassPath.SOURCE)); }
Example 6
Source File: ClassNodeCache.java From netbeans with Apache License 2.0 | 5 votes |
public ParsingClassLoader( @NonNull ClassPath path, @NonNull CompilerConfiguration config, @NonNull ClassNodeCache cache) { super(path.getClassLoader(true), config); this.config = config; this.path = path; this.cache = cache; }
Example 7
Source File: EjbFacadeWizardPanel2.java From netbeans with Apache License 2.0 | 5 votes |
private boolean statelessIfaceOnProjectCP() { ClassPath cp = ClassPath.getClassPath(project.getProjectDirectory(), ClassPath.COMPILE); ClassLoader cl = cp.getClassLoader(true); try { Class.forName(EjbFacadeWizardIterator.EJB_STATELESS, false, cl); } catch (ClassNotFoundException cnfe) { return false; } return true; }
Example 8
Source File: JpaControllerSetupPanelVisual.java From netbeans with Apache License 2.0 | 4 votes |
boolean valid(WizardDescriptor wizard) { // List<Entity> entities = (List<Entity>) wizard.getProperty(WizardProperties.ENTITY_CLASS); // String controllerPkg = getPackage(); // // boolean filesAlreadyExist = false; // String troubleMaker = ""; // for (Entity entity : entities) { // String entityClass = entity.getClass2(); // String simpleClassName = JSFClientGenerator.simpleClassName(entityClass); // String firstLower = simpleClassName.substring(0, 1).toLowerCase() + simpleClassName.substring(1); // String folder = jsfFolder.getText().endsWith("/") ? jsfFolder.getText() : jsfFolder.getText() + "/"; // folder = folder + firstLower; // String controller = controllerPkg + "." + simpleClassName + "Controller"; // String fqn = getPackage().length() > 0 ? getPackage().replace('.', '/') + "/" + simpleClassName : simpleClassName; // if (getLocationValue().getRootFolder().getFileObject(fqn + "Controller.java") != null) { // filesAlreadyExist = true; // troubleMaker = controllerPkg + "." + simpleClassName + "Controller.java"; // break; // } // if (getLocationValue().getRootFolder().getFileObject(fqn + "Converter.java") != null) { // filesAlreadyExist = true; // troubleMaker = controllerPkg + "." + simpleClassName + "Converter.java"; // break; // } // } // if (filesAlreadyExist) { // wizard.putProperty("WizardPanel_errorMessage", // NOI18N // NbBundle.getMessage(JpaControllerSetupPanelVisual.class, "MSG_FilesAlreadyExist", troubleMaker)); // return false; // } // wizard.putProperty("WizardPanel_errorMessage", null); // NOI18N if (Util.isContainerManaged(project)) { ClassPath cp = ClassPath.getClassPath(getLocationValue().getRootFolder(), ClassPath.COMPILE); ClassLoader cl = cp.getClassLoader(true); try { Class.forName("javax.transaction.UserTransaction", false, cl); } catch (ClassNotFoundException cnfe) { wizard.putProperty("WizardPanel_errorMessage", NbBundle.getMessage(JpaControllerSetupPanelVisual.class, "ERR_UserTransactionUnavailable")); return false; } catch (java.lang.UnsupportedClassVersionError err) { // wizard.putProperty("WizardPanel_errorMessage", NbBundle.getMessage(JpaControllerSetupPanelVisual.class, "ERR_UserTransactionJavaVersion")); // return false; } } // Sources srcs = (Sources) project.getLookup().lookup(Sources.class); // SourceGroup sgWeb[] = srcs.getSourceGroups("doc_root"); //NOI18N fixme(mbohm): move into constant // FileObject pagesRootFolder = sgWeb[0].getRootFolder(); // File pagesRootFolderAsFile = FileUtil.toFile(pagesRootFolder); // String jsfFolderText = jsfFolder.getText(); // try { // String canonPath = new File(pagesRootFolderAsFile, jsfFolderText).getCanonicalPath(); // } // catch (IOException ioe) { // wizard.putProperty("WizardPanel_errorMessage", NbBundle.getMessage(JpaControllerSetupPanelVisual.class, "ERR_JsfTargetChooser_InvalidJsfFolder")); // return false; // } String packageName = getPackage(); if (packageName.trim().equals("")) { // NOI18N wizard.putProperty("WizardPanel_errorMessage", NbBundle.getMessage(JpaControllerSetupPanelVisual.class, "ERR_JavaTargetChooser_CantUseDefaultPackage")); return false; } if (!JavaIdentifiers.isValidPackageName(packageName)) { wizard.putProperty("WizardPanel_errorMessage", NbBundle.getMessage(JpaControllerSetupPanelVisual.class,"ERR_JavaTargetChooser_InvalidPackage")); //NOI18N return false; } if (!SourceGroups.isFolderWritable(getLocationValue(), packageName)) { wizard.putProperty("WizardPanel_errorMessage", NbBundle.getMessage(JpaControllerSetupPanelVisual.class, "ERR_JavaTargetChooser_UnwritablePackage")); //NOI18N return false; } wizard.putProperty("WizardPanel_errorMessage", null); // NOI18N return true; }
Example 9
Source File: ResourceBundles.java From netbeans with Apache License 2.0 | 4 votes |
private Map<String, ResourceBundleInfo> createResourceBundleMapAndFileChangeListeners() { Map<String, ResourceBundleInfo> result = new HashMap<>(); ClassPathProvider provider = project.getLookup().lookup(ClassPathProvider.class); if (provider == null) { return null; } Sources sources = ProjectUtils.getSources(project); if (sources == null) { return null; } SourceGroup[] sourceGroups = sources.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA); for (ResourceBundle bundle : getBundles(new ResolverContext())) { String bundleFile = bundle.getBaseName(); for (SourceGroup sourceGroup : sourceGroups) { FileObject rootFolder = sourceGroup.getRootFolder(); for (String classPathType : new String[]{ClassPath.SOURCE, ClassPath.COMPILE}) { ClassPath classPath = ClassPath.getClassPath(rootFolder, classPathType); if (classPath == null) { continue; } ClassLoader classLoader = classPath.getClassLoader(false); try { // TODO - rewrite listening on all (localized) files String resourceFileName = new StringBuilder() .append(bundleFile.replace(".", "/")) .append(".properties") .toString(); //NOI18N URL url = classLoader.getResource(resourceFileName); if(url != null) { LOGGER.finer(String.format("Found %s URL for resource bundle %s", url, resourceFileName )); FileObject fileObject = URLMapper.findFileObject(url); if(fileObject != null) { if (fileObject.canWrite()) { fileObject.addFileChangeListener( WeakListeners.create(FileChangeListener.class, FILE_CHANGE_LISTENER, fileObject)); LOGGER.finer(String.format("Added FileChangeListener to file %s", fileObject )); } } else { LOGGER.fine(String.format("Cannot map %s URL to FileObject!", url)); } } java.util.ResourceBundle found = java.util.ResourceBundle.getBundle(bundleFile, Locale.getDefault(), classLoader); result.put(bundleFile, new ResourceBundleInfo(bundle.getFiles(), found, bundle.getVar())); break; // found the bundle in source cp, skip searching compile cp } catch (MissingResourceException exception) { continue; } } } } return result; }
Example 10
Source File: DynamicDriverClassLoader.java From jeddict with Apache License 2.0 | 4 votes |
public DynamicDriverClassLoader(ModelerFile file) { super(Thread.currentThread().getContextClassLoader()); ClassPath classPath = ClassPath.getClassPath(file.getFileObject(), ClassPath.EXECUTE); projectClassLoader = classPath != null ? new ChildClassLoader(classPath.getClassLoader(true), new DetectClass(this.getParent())) : null; baseClassLoader = new ChildClassLoader(this.getClass().getClassLoader(), new DetectClass(this.getParent())); }