List of usage examples for java.security CodeSource getLocation
public final URL getLocation()
From source file:com.cisco.oss.foundation.monitoring.RMIMonitoringAgent.java
private static URL getSpringUrl() { final ProtectionDomain protectionDomain = RemoteInvocation.class.getProtectionDomain(); String errorMessage = "creation of jar file failed for UNKNOWN reason"; if (protectionDomain == null) { errorMessage = "class protection domain is null"; } else {//from ww w .j a v a 2 s . c o m final CodeSource codeSource = protectionDomain.getCodeSource(); if (codeSource == null) { errorMessage = "class code source is null"; } else { final URL location = codeSource.getLocation(); if (location == null) { errorMessage = "class code source location is null"; } else { return location; } } } throw new UnsupportedOperationException(errorMessage); }
From source file:org.nuclos.server.report.ejb3.ReportFacadeBean.java
public static String getClassPathFor(Class<?>... classes) { StringBuilder sb = new StringBuilder(); for (Class<?> clazz : classes) { if (sb.length() > 0) { sb.append(File.pathSeparator); }//ww w. j av a 2 s . c o m try { ProtectionDomain protectionDomain = clazz.getProtectionDomain(); CodeSource codeSource = protectionDomain.getCodeSource(); URL location = codeSource.getLocation(); String path = location.getFile(); path = URLDecoder.decode(path, "UTF-8"); sb.append(path); } catch (Exception e) { throw new NuclosFatalException("Cannot configure JasperReports classpath ", e); } } return sb.toString(); }
From source file:com.servicelibre.jxsl.scenario.XslScenario.java
private static String getImplementationInfo(Class<?> componentClass) { // TODO if Saxon, add info from productTitle. Otherwise check jar // manifest for Implementation-Version, Implementation-Vendor at least. /*//from ww w . j a v a 2s . c om * Name: org/apache/xalan/ * Comment: Main Xalan engine implementing * TrAX/JAXP Specification-Title: Java API for XML Processing * Specification-Vendor: Sun Microsystems Inc. * Specification-Version: 1.3 * Implementation-Title: org.apache.xalan * Implementation-Version: 2.7.1 * Implementation-Vendor: Apache Software Foundation * Implementation-URL: http://xml.apache.org/xalan-j/ */ CodeSource source = componentClass.getProtectionDomain().getCodeSource(); return MessageFormat.format("{0} [{1}]", componentClass.getName(), source == null ? "Java Runtime" : source.getLocation()); }
From source file:Main.java
public Main() { Class cls = this.getClass(); ProtectionDomain pDomain = cls.getProtectionDomain(); CodeSource cSource = pDomain.getCodeSource(); URL loc = cSource.getLocation(); }
From source file:org.java.plugin.standard.StandardPluginClassLoader.java
private static URL getClassBaseUrl(final Class cls) { ProtectionDomain pd = cls.getProtectionDomain(); if (pd != null) { CodeSource cs = pd.getCodeSource(); if (cs != null) { return cs.getLocation(); }//from ww w . ja v a 2 s . co m } return null; }
From source file:org.openmrs.module.ModuleClassLoader.java
/** * Get the base class url of the given <code>cls</code>. Used for checking against system class * loads vs classloader loads//from w w w .j a v a 2 s.co m * * @param cls Class name * @return URL to the class */ private static URL getClassBaseUrl(final Class<?> cls) { ProtectionDomain pd = cls.getProtectionDomain(); if (pd != null) { CodeSource cs = pd.getCodeSource(); if (cs != null) { return cs.getLocation(); } } return null; }
From source file:ClassVersionInfo.java
public ClassVersionInfo(String name, ClassLoader loader) throws ClassNotFoundException { this.name = name; Class c = loader.loadClass(name); CodeSource cs = c.getProtectionDomain().getCodeSource(); if (cs != null) location = cs.getLocation(); if (c.isInterface() == false) { ObjectStreamClass osc = ObjectStreamClass.lookup(c); if (osc != null) { serialVersion = osc.getSerialVersionUID(); try { c.getDeclaredField("serialVersionUID"); hasExplicitSerialVersionUID = true; } catch (NoSuchFieldException e) { hasExplicitSerialVersionUID = false; }/*from w ww . j a v a 2 s . co m*/ } } }
From source file:org.diffkit.common.DKRuntime.java
private URL getClassLocation() { ProtectionDomain protectionDomain = this.getClass().getProtectionDomain(); CodeSource codeSource = protectionDomain.getCodeSource(); return codeSource.getLocation(); }
From source file:org.devtoolbox.errorhandling.impl.OnErrorFileMoverTest.java
public @Before void setUp() throws IOException { unitUnderTest = new OnErrorFileMover(); java.security.ProtectionDomain pd = OnErrorFileMoverTest.class.getProtectionDomain(); java.security.CodeSource cs = pd.getCodeSource(); java.net.URL url = cs.getLocation(); java.io.File f = new File(url.getFile()); rootFolderPath = f.getAbsolutePath(); FileUtils.deleteDirectory(new File(rootFolderPath + fileSeparator + processingFolderPath)); FileUtils.deleteDirectory(new File(rootFolderPath + fileSeparator + errorFolderPath)); FileUtils.copyFile(new java.io.File("src/test/resources/org/devtoolbox/errorhandling/" + fileName), new java.io.File(rootFolderPath + fileSeparator + processingFolderPath + fileSeparator + fileName)); }
From source file:com.arykow.autotools.generator.App.java
private void generate() throws Exception { File directory = new File(projectDirectory); if (!directory.isDirectory()) { throw new RuntimeException(); }//from w w w . j ava 2s. c om File output = new File(directory, projectName); if (output.exists()) { if (projectForced) { if (!output.isDirectory()) { throw new RuntimeException(); } } else { throw new RuntimeException(); } } else if (!output.mkdir()) { throw new RuntimeException(); } CodeSource src = getClass().getProtectionDomain().getCodeSource(); if (src != null) { URL jar = src.getLocation(); ZipInputStream zip = new ZipInputStream(jar.openStream()); while (true) { ZipEntry e = zip.getNextEntry(); if (e == null) break; if (!e.isDirectory() && e.getName().startsWith(String.format("%s", templateName))) { // generate(output, e); StringWriter writer = new StringWriter(); IOUtils.copy(zip, writer); String content = writer.toString(); Map<String, String> expressions = new HashMap<String, String>(); expressions.put("author", "Karim DRIDI"); expressions.put("name_undescore", projectName); expressions.put("license", "<Place your desired license here.>"); expressions.put("name", projectName); expressions.put("version", "1.0"); expressions.put("copyright", "Your copyright notice"); expressions.put("description", "Hello World in C++,"); for (Map.Entry<String, String> entry : expressions.entrySet()) { content = content.replaceAll(String.format("<project\\.%s>", entry.getKey()), entry.getValue()); } String name = e.getName().substring(templateName.length() + 1); if ("gitignore".equals(name)) { name = ".gitignore"; } File file = new File(output, name); File parent = file.getParentFile(); if (parent.exists()) { if (!parent.isDirectory()) { throw new RuntimeException(); } } else { if (!parent.mkdirs()) { throw new RuntimeException(); } } OutputStream stream = new FileOutputStream(file); IOUtils.copy(new StringReader(content), stream); IOUtils.closeQuietly(stream); } } } }