List of usage examples for java.lang ClassLoader getSystemClassLoader
@CallerSensitive public static ClassLoader getSystemClassLoader()
From source file:eu.sisob.api.sisobcrawlingworks.CrawlerResearchesPagesV3Test.java
@Test public void TestingRESTServices() { if (true) {/*w w w . j a va 2 s . c o m*/ assertEquals(true, true); return; } String test_dirname = "test-data"; String crawler_data_path = "crawler-data"; ResearchersCrawlerService.setServiceSettings(crawler_data_path, ClassLoader.getSystemClassLoader().getResource("eu/sisob/uma/crawler/keywords"), true, true); ResearchersCrawlerService.createInstance(); // File keywords_dir = new File(keywords_dirname); // if(!(keywords_dir).exists()) // { // FileFootils.copyResourcesRecursively(ClassLoader.getSystemClassLoader().getResource("eu/sisob/uma/crawler/keywords"), keywords_dir); // } String sInstitutionName = "AMC"; String seed = "http://www.amc.edu/"; String contain_pattern = seed.replace("http://www.", ""); int index = contain_pattern.indexOf("/"); if (index == -1) index = contain_pattern.length() - 1; contain_pattern = contain_pattern.substring(0, index); String sUnitOfAssessment_Description = "cbc"; List<String> department_web_addresses = new ArrayList<String>(); department_web_addresses.add("http://www.amc.edu/research/cbc/"); List<ResearcherNameInfo> researchers = new ArrayList<ResearcherNameInfo>(); /* * Crawling to search the researchers */ CrawlerResearchesPagesV3Controller controllerReseachers = null; try { String university_subject_crawler_data_folder = test_dirname + File.separator + sInstitutionName.replace(" ", ".") + "_" + sUnitOfAssessment_Description.replace(" ", ".") + "-crawler-data"; controllerReseachers = new CrawlerResearchesPagesV3Controller(university_subject_crawler_data_folder, new File(crawler_data_path), researchers); String sSeeds = ""; for (String s : department_web_addresses) { controllerReseachers.addSeed(s); sSeeds += s + ","; } controllerReseachers.setPolitenessDelay(200); controllerReseachers.setMaximumCrawlDepth(3); controllerReseachers.setMaximumPagesToFetch(-1); controllerReseachers.setContainPattern(contain_pattern); controllerReseachers.clearInterestingUrlsDetected(); Logger.getLogger("root").info("Begin crawling: " + sUnitOfAssessment_Description + " - " + sInstitutionName + " - [" + StringUtils.join(department_web_addresses, ",") + "]"); long lTimerAux = java.lang.System.currentTimeMillis(); controllerReseachers.start(CrawlerResearchesPagesV3.class, 1); controllerReseachers.postProcessResults(); lTimerAux = java.lang.System.currentTimeMillis() - lTimerAux; Logger.getLogger("root") .info("End crawling: " + sUnitOfAssessment_Description + " - " + sInstitutionName + " - Time: " + lTimerAux + " ms - [" + StringUtils.join(department_web_addresses, ",") + "]"); } catch (Exception ex) { Logger.getLogger("root").error(ex.getMessage(), ex); } ResearchersCrawlerService.releaseInstance(); }
From source file:org.springframework.data.gemfire.support.AbstractFactoryBeanSupportUnitTests.java
@Test public void setAndGetBeanClassLoader() { assertThat(factoryBeanSupport.getBeanClassLoader()).isNull(); ClassLoader mockClassLoader = mock(ClassLoader.class); factoryBeanSupport.setBeanClassLoader(mockClassLoader); assertThat(factoryBeanSupport.getBeanClassLoader()).isSameAs(mockClassLoader); ClassLoader systemClassLoader = ClassLoader.getSystemClassLoader(); factoryBeanSupport.setBeanClassLoader(systemClassLoader); assertThat(factoryBeanSupport.getBeanClassLoader()).isSameAs(systemClassLoader); factoryBeanSupport.setBeanClassLoader(null); assertThat(factoryBeanSupport.getBeanClassLoader()).isNull(); }
From source file:com.quinsoft.zeidon.standardoe.ApplicationList.java
/** * Loads the list of applications from %ZEIDON%/zeidon.app */// w w w .ja v a 2 s .co m ApplicationList(HomeDirectory home, ZeidonLogger logger) { logger.info("Loading application list"); this.home = home; Map<String, ApplicationImpl> apps = new HashMap<String, ApplicationImpl>(); // First try loading the resources. ClassLoader classLoader = getClass().getClassLoader(); if (classLoader == null) classLoader = ClassLoader.getSystemClassLoader(); try { for (Enumeration<URL> element = classLoader.getResources("zeidon.app"); element.hasMoreElements();) { URL url = element.nextElement(); logger.info("Loading applications from resource %s", url.getFile()); InputStream stream = url.openStream(); ApplicationHandler appHandler = new ApplicationHandler(apps); PortableFileReader.ReadPortableFile(stream, logger, appHandler); } } catch (Exception e) { throw ZeidonException.wrapException(e).appendMessage("Error while attempting to load zeidon.app"); } if (!StringUtils.isBlank(home.getHomeDirectory())) { String filename = FilenameUtils.concat(home.getHomeDirectory(), "zeidon.app"); try { InputStream inputStream = JoeUtils.getInputStream(null, filename, logger.getClass().getClassLoader()); if (inputStream == null) logger.info("No zeidon.app found via ZEIDON_HOME."); else { logger.info("Loading apps using ZEIDON_HOME (%s)/zeidon.app", home.getHomeDirectory()); ApplicationHandler appHandler = new ApplicationHandler(apps); PortableFileReader.ReadPortableFile(inputStream, logger, appHandler); } } catch (Exception e) { throw ZeidonException.wrapException(e).prependFilename(filename); } } if (apps.size() == 0) throw new ZeidonException("No resources named zeidon.app found."); applications = ImmutableMap.copyOf(apps); }
From source file:org.apache.hadoop.hbase.io.compress.Compression.java
/** * Returns the classloader to load the Codec class from. *///from ww w . ja va2s. c om private static ClassLoader getClassLoaderForCodec() { ClassLoader cl = Thread.currentThread().getContextClassLoader(); if (cl == null) { cl = Compression.class.getClassLoader(); } if (cl == null) { cl = ClassLoader.getSystemClassLoader(); } if (cl == null) { throw new RuntimeException("A ClassLoader to load the Codec could not be determined"); } return cl; }
From source file:org.cloudml.connectors.FlexiantConnector.java
@SuppressWarnings("restriction") public FlexiantConnector(String endPoint, String login, String secretKey) throws MalformedURLException { this.endpoint = endPoint; System.setProperty("jsse.enableSNIExtension", "false"); journal.log(Level.INFO, ">> Connecting to Flexiant ..."); URL url = ClassLoader.getSystemClassLoader().getResource("UserAdmin.wsdl"); // Get the UserAPI UserAPI api = new UserAPI(url, new QName("http://extility.flexiant.net", "UserAPI")); // and set the service port on the service service = api.getUserServicePort();//from www . ja va 2 s . c om // Get the binding provider BindingProvider portBP = (BindingProvider) service; // and set the service endpoint portBP.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endPoint); journal.log(Level.INFO, ">> Authenticating ..."); // and the caller's authentication details and password portBP.getRequestContext().put(BindingProvider.USERNAME_PROPERTY, login); portBP.getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, secretKey); }
From source file:com.galeoconsulting.leonardinius.groovy.GroovyRegistrarImpl.java
private GroovyClassLoader getClassLoader() { if (gcl == null) { synchronized (lock) { if (gcl == null) { final ClassLoader chainedClassLoader = this.scriptService.getClassLoader( getClass().getClassLoader(), Script.class.getClassLoader(), UserManager.class.getClassLoader(), ClassLoader.getSystemClassLoader()); gcl = new GroovyClassLoader(chainedClassLoader); }/* w w w . ja v a 2 s . com*/ } } return gcl; }
From source file:com.samples.platform.service.common.GetServiceStatusOperation.java
/** * @param message/*from w w w .ja va2 s . co m*/ * the {@link JAXBElement} containing a * {@link GetServiceStatusRequestType}. * @return the {@link JAXBElement} with a * {@link GetServiceStatusResponseType}. */ @InsightEndPoint @ServiceActivator public final JAXBElement<GetServiceStatusResponseType> getServiceStatus( final JAXBElement<GetServiceStatusRequestType> message) { this.logger.debug("+getServiceStatus"); GetServiceStatusResponseType response = this.of.createGetServiceStatusResponseType(); try { PropertyType p; ClassLoader cl; URL[] urls; ClassLoader sysCl = ClassLoader.getSystemClassLoader(); response.setStatus("Service is available"); /* System properties */ p = new PropertyType(); p.setName("System Properties"); response.getDetails().add(p); TreeSet<String> propertyNames = new TreeSet<String>(); propertyNames.addAll(System.getProperties().stringPropertyNames()); for (String propertyName : propertyNames) { p.getValue().add(new StringBuffer(64).append(propertyName).append("=") .append(System.getProperty(propertyName)).toString()); } /* Application properties. */ p = new PropertyType(); p.setName("Application loaded properties"); response.getDetails().add(p); propertyNames.clear(); propertyNames.addAll(this.properties.stringPropertyNames()); for (String propertyName : propertyNames) { p.getValue().add(new StringBuffer(64).append(propertyName).append("=") .append(this.properties.getProperty(propertyName)).toString()); } /* Current lass loader */ cl = this.getClass().getClassLoader(); p = new PropertyType(); p.setName("This ClassLoader"); response.getDetails().add(p); p.getValue().add(cl.getClass().getName()); if (URLClassLoader.class.isInstance(cl)) { urls = ((URLClassLoader) cl).getURLs(); p.getValue().add(new StringBuffer("Url: ").append(urls.length).toString()); for (URL url : urls) { p.getValue().add(url.toString()); } } cl = cl.getParent(); while (cl != sysCl) { p = new PropertyType(); p.setName("Parent Classloader"); response.getDetails().add(p); p.getValue().add(cl.getClass().getName()); if (URLClassLoader.class.isInstance(cl)) { urls = ((URLClassLoader) cl).getURLs(); p.getValue().add(new StringBuffer("Url: ").append(urls.length).toString()); for (URL url : urls) { p.getValue().add(url.toString()); } } cl = cl.getParent(); } /* System class loader */ cl = sysCl; p = new PropertyType(); p.setName("SystemClassLoader"); response.getDetails().add(p); p.getValue().add(cl.getClass().getName()); if (URLClassLoader.class.isInstance(cl)) { urls = ((URLClassLoader) cl).getURLs(); p.getValue().add(new StringBuffer("Url: ").append(urls.length).toString()); for (URL url : urls) { p.getValue().add(url.toString()); } } } catch (Throwable e) { this.logger.error(e.getMessage(), e); } finally { this.logger.debug("-getServiceStatus #{}, #f{}", response/* .get() */ != null ? 1 : 0, response.getFailure().size()); } return this.of.createGetServiceStatusResponse(response); }
From source file:org.dhatim.util.ClassUtil.java
/** * Load the specified class./* w ww.j ava 2 s . co m*/ * * @param className * The name of the class to load. * @param caller * The class of the caller. * @return The specified class. * @throws ClassNotFoundException * If the class cannot be found. */ public static Class forName(final String className, final Class caller) throws ClassNotFoundException { final ClassLoader threadClassLoader = Thread.currentThread().getContextClassLoader(); Class primitiveClass = primitives.get(className); if (primitiveClass != null) { return primitiveClass; } if (threadClassLoader != null) { try { return threadClassLoader.loadClass(className); } catch (final ClassNotFoundException cnfe) { } // ignore } ClassLoader classLoader = caller.getClassLoader(); if (classLoader != null) { try { return classLoader.loadClass(className); } catch (final ClassNotFoundException cnfe) { } // ignore } return Class.forName(className, true, ClassLoader.getSystemClassLoader()); }
From source file:com.controlj.experiment.bulktrend.trendclient.TrendClient.java
@SuppressWarnings("unchecked") private <T> T loadClass(String className, Class<T> interfaceClass) { try {// w w w .j av a 2s . c o m Class<?> clazz = ClassLoader.getSystemClassLoader().loadClass(className); if (!interfaceClass.isAssignableFrom(clazz)) { System.err.println("Error, " + className + " does not implement " + interfaceClass.getName()); System.exit(-1); } return (T) clazz.newInstance(); } catch (ClassNotFoundException e) { System.err.println("Error, can't find class of " + className); System.exit(-1); } catch (InstantiationException e) { System.err.println("Error, can't instatiate class of " + className); System.exit(-1); } catch (IllegalAccessException e) { System.err.println("Error, can't access class of " + className); System.exit(-1); } return null; }
From source file:org.ploin.web.flow.FlowControl.java
/** * This method read the "ploinFlows.xml" and build an object-graph. * The object-graph is a List of Flow-Ojbects. * * @see Flow/* ww w.ja v a 2 s . c om*/ * @return List<Flow>, object-graph */ public List<Flow> readFlows() { List<Flow> flows = new ArrayList<Flow>(); try { ClassLoader loader = Thread.currentThread().getContextClassLoader(); if (loader == null) loader = ClassLoader.getSystemClassLoader(); URL url = loader.getResource("ploinFlows.xml"); SAXReader reader = new SAXReader(); Document document = reader.read(url); Element root = document.getRootElement(); String authSource = null; // authoritiySource String appName = null; // applicationName String acceddDeniedPage = null; Boolean disableUrlNavigation = Boolean.FALSE; Set<String> viewsForAllFlows = new HashSet<String>(); Set<String> ignoreFlows = new HashSet<String>(); for (Iterator<Element> i = root.elementIterator(); i.hasNext();) { Element flow = (Element) i.next(); if ("ignoreViews".equalsIgnoreCase(flow.getName())) { for (Iterator<Element> e = flow.elementIterator(); e.hasNext();) { Element view = (Element) e.next(); if ("view".equalsIgnoreCase(view.getName())) { ignoreFlows.add(view.getStringValue()); } } } else if ("viewsForAllFlows".equalsIgnoreCase(flow.getName())) { for (Iterator<Element> e = flow.elementIterator(); e.hasNext();) { Element view = (Element) e.next(); if ("view".equalsIgnoreCase(view.getName())) { viewsForAllFlows.add(view.getStringValue()); } } } else if ("disableUrlNavigation".equalsIgnoreCase(flow.getName())) { try { disableUrlNavigation = Boolean.parseBoolean(flow.getStringValue()); } catch (Exception e) { log.error("ERROR by parsing boolean. ", e); } } else if ("accessDeniedPage".equalsIgnoreCase(flow.getName())) { acceddDeniedPage = flow.getStringValue(); } else if ("appName".equalsIgnoreCase(flow.getName())) { appName = flow.getStringValue(); } else if ("authoritySource".equalsIgnoreCase(flow.getName())) { authSource = flow.getStringValue(); } else if ("flow".equalsIgnoreCase(flow.getName())) { Flow flowItem = new Flow(); flowItem.setFlowId(flow.attribute("id").getValue()); log.debug("read ID: " + flow.attribute("id").getValue()); for (Iterator<Element> e = flow.elementIterator(); e.hasNext();) { Element flowChild = (Element) e.next(); if ("views".equalsIgnoreCase(flowChild.getName())) { for (Iterator<Element> t = flowChild.elementIterator(); t.hasNext();) { Element view = (Element) t.next(); if ("view".equalsIgnoreCase(view.getName())) { flowItem.addView(view.getStringValue()); } } } else if ("attributes".equalsIgnoreCase(flowChild.getName())) { for (Iterator<Element> t = flowChild.elementIterator(); t.hasNext();) { Element attribute = (Element) t.next(); if ("attribute".equalsIgnoreCase(attribute.getName())) { flowItem.addAttribute(attribute.getStringValue()); } } } else if ("includeAuthorities".equalsIgnoreCase(flowChild.getName()) || "includeAuthoritys".equalsIgnoreCase(flowChild.getName())) { for (Iterator<Element> t = flowChild.elementIterator(); t.hasNext();) { Element auth = (Element) t.next(); if ("authority".equalsIgnoreCase(auth.getName())) { flowItem.addIncludeAuthority(auth.getStringValue()); } } } else if ("excludeAuthorities".equalsIgnoreCase(flowChild.getName()) || "excludeAuthoritys".equalsIgnoreCase(flowChild.getName())) { for (Iterator<Element> t = flowChild.elementIterator(); t.hasNext();) { Element auth = (Element) t.next(); if ("authority".equalsIgnoreCase(auth.getName())) { flowItem.addExcludeAuthority(auth.getStringValue()); } } } else if ("beforeFlowAction".equalsIgnoreCase(flowChild.getName())) { flowItem.setBeforeFlowAction(flowChild.getStringValue()); } else if ("afterFlowAction".equalsIgnoreCase(flowChild.getName())) { flowItem.setAfterFlowAction(flowChild.getStringValue()); } else if ("beforeLifecycleAction".equalsIgnoreCase(flowChild.getName())) { flowItem.setBeforeLifecycleAction(flowChild.getStringValue()); } else if ("afterLifecycleAction".equalsIgnoreCase(flowChild.getName())) { flowItem.setAfterLifecycleAction(flowChild.getStringValue()); } else if ("subFlows".equalsIgnoreCase(flowChild.getName())) { for (Iterator<Element> t = flowChild.elementIterator(); t.hasNext();) { Element flowId = (Element) t.next(); if ("flowId".equalsIgnoreCase(flowId.getName())) { flowItem.addSubFlow(flowId.getStringValue()); } } } } flowItem.setAuthoritySource(authSource); flowItem.setAppName(appName); flowItem.setAccessDeniedPage(acceddDeniedPage); if (viewsForAllFlows.size() > 0) { for (String view : viewsForAllFlows) { flowItem.addView(view); } } flowItem.setIgnoreViews(ignoreFlows); flowItem.setDisableUrlNavigation(disableUrlNavigation); flows.add(flowItem); } } } catch (Exception e) { log.error("ERROR in ploinFlow ", e); } return flows; }