List of usage examples for java.lang Package getName
public String getName()
From source file:api.wiki.WikiGenerator.java
private String javaDocLink(Method method) { Class<?> declaringClass = method.getDeclaringClass(); Package aPackage = declaringClass.getPackage(); Class<?>[] parameterTypes = method.getParameterTypes(); String groupIdSlashes = groupId.replace('.', '/'); String packageSlashes = aPackage.getName().replace('.', '/'); String parameterSlashes = stream(parameterTypes).map(Class::getName).collect(joining("-", "", "-")); String closestReleasedVersion = latestReleasedVersion(version); return "https://oss.sonatype.org/service/local/repositories/releases/archive/" + groupIdSlashes + "/" + artifactId + "/" + closestReleasedVersion + "/" + artifactId + "-" + closestReleasedVersion + "-javadoc.jar/!/" + packageSlashes + "/" + declaringClass.getSimpleName() + ".html#" + method.getName() + "-" + parameterSlashes; }
From source file:se.vgregion.portal.innovatinosslussen.domain.TypesBeanTest.java
private List<Class> getTypes(Class sampelTypeFromPack) throws ClassNotFoundException { Package aPackage = sampelTypeFromPack.getPackage(); URL url = sampelTypeFromPack.getResource("/"); File file = new File(url.getFile()); file = new File(file.getParent()); String sc = File.separator; String path = file.getParent() + sc + "target" + sc + "classes" + sc + aPackage.getName().replace('.', sc.charAt(0)) + sc; file = new File(path); List<Class> result = new ArrayList<Class>(); if (file != null && file.list() != null) { for (String clazzFileName : file.list()) { if (clazzFileName.endsWith(".class")) { clazzFileName = clazzFileName.substring(0, clazzFileName.indexOf(".class")); result.add(Class.forName(aPackage.getName() + "." + clazzFileName)); }/*from w ww . ja va2 s . c o m*/ } } else { System.out.println("File or its children did not exist " + file); } return result; }
From source file:com.link_intersystems.lang.reflect.Class2Test.java
@Test public void getPackage2() { Class2<?> genericDefinition = Class2.get(GenericClassWithBeanType.class); Package package1 = GenericClassWithBeanType.class.getPackage(); Package2 package2 = genericDefinition.getPackage(); assertEquals(package1.getName(), package2.getName()); }
From source file:RevEngAPI.java
/** Generate a .java file for the outline of the given class. */ public void doClass(Class c) throws IOException { className = c.getName();/*from ww w . ja va 2 s . c o m*/ // pre-compute offset for stripping package name classNameOffset = className.lastIndexOf('.') + 1; // Inner class if (className.indexOf('$') != -1) return; // get name, as String, with . changed to / String slashName = className.replace('.', '/'); String fileName = slashName + ".java"; System.out.println(className + " --> " + fileName); String dirName = slashName.substring(0, slashName.lastIndexOf("/")); new File(dirName).mkdirs(); // create the file. PrintWriter out = new PrintWriter(new FileWriter(fileName)); out.println("// Generated by RevEngAPI for class " + className); // If in a package, say so. Package pkg; if ((pkg = c.getPackage()) != null) { out.println("package " + pkg.getName() + ';'); out.println(); } // print class header int cMods = c.getModifiers(); printMods(cMods, out); out.print("class "); out.print(trim(c.getName())); out.print(' '); // XXX get superclass out.println('{'); // print constructors Constructor[] ctors = c.getDeclaredConstructors(); for (int i = 0; i < ctors.length; i++) { if (i == 0) { out.println(); out.println("\t// Constructors"); } Constructor cons = ctors[i]; int mods = cons.getModifiers(); if (Modifier.isPrivate(mods)) continue; out.print('\t'); printMods(mods, out); out.print(trim(cons.getName()) + "("); Class[] classes = cons.getParameterTypes(); for (int j = 0; j < classes.length; j++) { if (j > 0) out.print(", "); out.print(trim(classes[j].getName()) + ' ' + mkName(PREFIX_ARG, j)); } out.println(") {"); out.print("\t}"); } // print method names Method[] mems = c.getDeclaredMethods(); for (int i = 0; i < mems.length; i++) { if (i == 0) { out.println(); out.println("\t// Methods"); } Method m = mems[i]; if (m.getName().startsWith("access$")) continue; int mods = m.getModifiers(); if (Modifier.isPrivate(mods)) continue; out.print('\t'); printMods(mods, out); out.print(m.getReturnType()); out.print(' '); out.print(trim(m.getName()) + "("); Class[] classes = m.getParameterTypes(); for (int j = 0; j < classes.length; j++) { if (j > 0) out.print(", "); out.print(trim(classes[j].getName()) + ' ' + mkName(PREFIX_ARG, j)); } out.println(") {"); out.println("\treturn " + defaultValue(m.getReturnType()) + ';'); out.println("\t}"); } // print fields Field[] flds = c.getDeclaredFields(); for (int i = 0; i < flds.length; i++) { if (i == 0) { out.println(); out.println("\t// Fields"); } Field f = flds[i]; int mods = f.getModifiers(); if (Modifier.isPrivate(mods)) continue; out.print('\t'); printMods(mods, out); out.print(trim(f.getType().getName())); out.print(' '); out.print(f.getName()); if (Modifier.isFinal(mods)) { try { out.print(" = " + f.get(null)); } catch (IllegalAccessException ex) { out.print("; // " + ex.toString()); } } out.println(';'); } out.println("}"); //out.flush(); out.close(); }
From source file:org.qxsched.doc.afp.impl.AfpClasses.java
private void init() throws AfpException { // Get definitions AfpStructuredFieldDefinitions defs = AfpStructuredFieldDefinitions.instance(); // Get class loader ClassLoader ldr = Thread.currentThread().getContextClassLoader(); // Get package directory Package pkg = AfpClasses.class.getPackage(); String recClassBaseName = AfpRecord.class.getName().replaceFirst("^.*\\.", ""); String recClassBase = pkg.getName() + "." + recClassBaseName; // Iterate through all abbreviations and try and find classes Set<String> abbrevs = defs.getAbbrev(); for (String abbrev : abbrevs) { // Make class name String recordClassName = recClassBase + abbrev; if (LOG.isTraceEnabled()) { LOG.trace("AFP record class name: " + recordClassName); }/*w w w .ja va 2 s .c o m*/ // Load class Class<?> recordClass = null; try { recordClass = ldr.loadClass(recordClassName); } catch (ClassNotFoundException e) { } // Ignore null if (recordClass == null) { if (LOG.isTraceEnabled()) { LOG.trace("Ignoring unfound class: " + recordClassName); } continue; } // Ignore non AfpRecords if (!AfpRecord.class.isAssignableFrom(recordClass)) { if (LOG.isTraceEnabled()) { LOG.trace("Ignoring non AfpRecord: " + recordClassName); } continue; } // Map Integer code = defs.getCode(abbrev); recordCode2class.put(code, (Class<AfpRecord>) recordClass); recordAbbrev2class.put(abbrev, (Class<AfpRecord>) recordClass); } // Try finding al triplet classes this package implements String tripClassBaseName = AfpTriplet.class.getName().replaceFirst("^.*\\.", ""); String tripClassBase = pkg.getName() + "." + tripClassBaseName; for (int i = 0; i < 0x100; i++) { // Make class name String abbrev = StringUtils.leftPad(Integer.toString(i, 16).toUpperCase(), 2, '0'); String tripClassName = tripClassBase + abbrev; if (LOG.isTraceEnabled()) { LOG.trace("AFP triplet class name: " + tripClassName); } // Load class Class<?> tripClass = null; try { tripClass = ldr.loadClass(tripClassName); } catch (ClassNotFoundException e) { } // Ignore null if (tripClass == null) { if (LOG.isTraceEnabled()) { LOG.trace("Ignoring unfound class: " + tripClassName); } continue; } // Ignore non AfpTriplet if (!AfpTriplet.class.isAssignableFrom(tripClass)) { if (LOG.isTraceEnabled()) { LOG.trace("Ignoring non AfpTriplet: " + tripClassName); } continue; } // Map if (LOG.isTraceEnabled()) { LOG.trace("Found AfpTriplet: " + tripClassName); } tripletCode2class.put(i, (Class<AfpTriplet>) tripClass); } }
From source file:com.virtualparadigm.packman.processor.JPackageManagerOld.java
private static void archivePackage(Package installPackage, File packageManagerDataDir) { // create "archive" dir if it doesnt exist // create package archive dir (<package name>_v_<package version>) // copy contents of package metadata, autorun and patch file to archive dir try {/*from w ww . ja v a2 s. c o m*/ File archiveDir = new File(packageManagerDataDir.getAbsolutePath() + "/" + ARCHIVE_DIR_NAME); File archivePackageDir = new File(archiveDir.getAbsolutePath() + "/" + installPackage.getName() + "_v_" + installPackage.getVersion()); // if(!archivePackageDir.exists()) // { // archivePackageDir.mkdirs(); // } File archivePackageInstallDir = new File( archivePackageDir.getAbsolutePath() + "/" + JPackageManagerOld.INSTALL_DIR_NAME); if (!archivePackageInstallDir.exists()) { archivePackageInstallDir.mkdirs(); } File archivePackageUninstallDir = new File( archivePackageDir.getAbsolutePath() + "/" + JPackageManagerOld.UNINSTALL_DIR_NAME); if (!archivePackageUninstallDir.exists()) { archivePackageUninstallDir.mkdirs(); } // metadata archive dir FileUtils.copyDirectory( new File(packageManagerDataDir.getAbsolutePath() + "/" + TEMP_INSTALL_DIR_NAME + "/" + JPackageManagerOld.METADATA_DIR_NAME), new File(archivePackageDir.getAbsolutePath() + "/" + JPackageManagerOld.METADATA_DIR_NAME)); // install archive dir FileUtils.copyDirectory( new File(packageManagerDataDir.getAbsolutePath() + "/" + TEMP_INSTALL_DIR_NAME + "/" + JPackageManagerOld.AUTORUN_DIR_NAME + "/" + JPackageManagerOld.INSTALL_DIR_NAME), new File(archivePackageInstallDir.getAbsolutePath() + "/" + JPackageManagerOld.AUTORUN_DIR_NAME)); FileUtils.copyFileToDirectory( new File(packageManagerDataDir.getAbsolutePath() + "/" + TEMP_INSTALL_DIR_NAME + "/" + JPackageManagerOld.PATCH_DIR_NAME + "/" + JPackageManagerOld.PATCH_FILE_NAME), new File(archivePackageInstallDir.getAbsolutePath() + "/" + JPackageManagerOld.PATCH_DIR_NAME)); // uninstall archive dir FileUtils.copyDirectory( new File(packageManagerDataDir.getAbsolutePath() + "/" + TEMP_INSTALL_DIR_NAME + "/" + JPackageManagerOld.AUTORUN_DIR_NAME + "/" + JPackageManagerOld.UNINSTALL_DIR_NAME), new File(archivePackageUninstallDir.getAbsolutePath() + "/" + JPackageManagerOld.AUTORUN_DIR_NAME)); FileUtils.copyFileToDirectory( new File(packageManagerDataDir.getAbsolutePath() + "/" + TEMP_INSTALL_DIR_NAME + "/" + JPackageManagerOld.PATCH_DIR_NAME + "/" + JPackageManagerOld.PATCH_FILE_NAME), new File(archivePackageUninstallDir.getAbsolutePath() + "/" + JPackageManagerOld.PATCH_DIR_NAME)); } catch (Exception e) { logger.error("", e); } }
From source file:org.apache.hadoop.gateway.services.topology.impl.DefaultTopologyService.java
public void deployTopology(Topology t) { try {//w w w. j ava2 s . c om File temp = new File(directory.getAbsolutePath() + "/" + t.getName() + ".xml.temp"); Package topologyPkg = Topology.class.getPackage(); String pkgName = topologyPkg.getName(); String bindingFile = pkgName.replace(".", "/") + "/topology_binding-xml.xml"; Map<String, Object> properties = new HashMap<>(1); properties.put(JAXBContextProperties.OXM_METADATA_SOURCE, bindingFile); JAXBContext jc = JAXBContext.newInstance(pkgName, Topology.class.getClassLoader(), properties); Marshaller mr = jc.createMarshaller(); mr.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); mr.marshal(t, temp); File topology = new File(directory.getAbsolutePath() + "/" + t.getName() + ".xml"); if (!temp.renameTo(topology)) { FileUtils.forceDelete(temp); throw new IOException("Could not rename temp file"); } // This code will check if the topology is valid, and retrieve the errors if it is not. TopologyValidator validator = new TopologyValidator(topology.getAbsolutePath()); if (!validator.validateTopology()) { throw new SAXException(validator.getErrorString()); } } catch (JAXBException e) { auditor.audit(Action.DEPLOY, t.getName(), ResourceType.TOPOLOGY, ActionOutcome.FAILURE); log.failedToDeployTopology(t.getName(), e); } catch (IOException io) { auditor.audit(Action.DEPLOY, t.getName(), ResourceType.TOPOLOGY, ActionOutcome.FAILURE); log.failedToDeployTopology(t.getName(), io); } catch (SAXException sx) { auditor.audit(Action.DEPLOY, t.getName(), ResourceType.TOPOLOGY, ActionOutcome.FAILURE); log.failedToDeployTopology(t.getName(), sx); } reloadTopologies(); }
From source file:org.apache.drill.jdbc.proxy.InvocationReporterImpl.java
/** * Renders a type name. Uses simple names for common types (JDBC interfaces * and {code java.lang.*})./* w w w . j av a 2s . co m*/ */ private String formatType(final Class<?> type) { final String result; if (type.isArray()) { result = formatType(type.getComponentType()) + "[]"; } else { // Suppress package name for common (JDBC and java.lang) types, except // when would be ambiguous (e.g., java.sql.Date vs. java.util.Date). if (PACKAGES_TO_ABBREVIATE.contains(type.getPackage())) { int sameSimpleNameCount = 0; for (Package p : PACKAGES_TO_ABBREVIATE) { try { Class.forName(p.getName() + "." + type.getSimpleName()); sameSimpleNameCount++; } catch (ClassNotFoundException e) { // Nothing to do. } } if (1 == sameSimpleNameCount) { result = type.getSimpleName(); } else { // Multiple classes with same simple name, so would be ambiguous to // abbreviate, so use fully qualified name. result = type.getName(); } } else { result = type.getName(); } } return result; }
From source file:de.fischer.thotti.core.runner.NDRunner.java
protected TestSuite loadTestConfiguration() throws InvalidTestXMLConfigurationException { Package pkg = TestSuite.class.getPackage(); TestSuite suite = null;//from www .ja va2 s . co m try { JAXBContext jaxbContext = JAXBContext.newInstance(pkg.getName()); Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); suite = (TestSuite) unmarshaller.unmarshal(configResource); } catch (JAXBException e) { throw new InvalidTestXMLConfigurationException( "Error while " + "reading the test configuration file " + configResource.toExternalForm(), e); } return suite; }
From source file:com.haulmont.cuba.web.sys.CubaApplicationServlet.java
protected String getPackageName() { String pkgName;// w ww.j a v a 2 s . com final Package pkg = this.getClass().getPackage(); if (pkg != null) { pkgName = pkg.getName(); } else { final String className = this.getClass().getName(); pkgName = new String(className.toCharArray(), 0, className.lastIndexOf('.')); } return pkgName; }