protected ArrayList createListCompletions(Package setOfCompletions) { ArrayList listOfCompletions = new ArrayList(); for (Item i : setOfCompletions) { try { try { if (i instanceof ClassName) { String fullName = getFullName(setOfCompletions.getName(), ((ClassName) i).getName()); Class clazz = getClass().getClassLoader().loadClass(fullName); Constructor[] ctor = clazz.getConstructors(); for (Constructor c : ctor) { String cotrCompletion = createConstructorCompletion(c.toString()); listOfCompletions.add(new BasicCompletion(defaultProvider, cotrCompletion)); } listOfCompletions.add(new BasicCompletion(defaultProvider, i.getName() + ".")); } } catch (NoClassDefFoundError e) { e.printStackTrace(); } } catch (Exception e) { e.printStackTrace(); } listOfCompletions.add(new BasicCompletion(defaultProvider, i.getName())); } return listOfCompletions; }
/** * This method returns the supermost class of the class passed that is in the same package as * class * * @author aarti_sharma * @param objClass * @return */ public static Class getSupermostClassInPackage(Object obj) { Class objClass = obj.getClass(); Package objPackage = objClass.getPackage(); Logger.out.debug("Input Class: " + objClass.getName() + " Package:" + objPackage.getName()); PersistentClass persistentClass = cfg.getClassMapping(objClass); if (persistentClass != null && persistentClass.getSuperclass() != null) { Logger.out.debug( objPackage.getName() + " " + persistentClass.getName() + "*********" + persistentClass.getSuperclass().getMappedClass().getPackage().getName()); Logger.out.debug( "!!!!!!!!!!! " + persistentClass .getSuperclass() .getMappedClass() .getPackage() .getName() .equals(objPackage.getName())); do { persistentClass = persistentClass.getSuperclass(); } while (persistentClass != null); Logger.out.debug( "Supermost class in the same package:" + persistentClass.getMappedClass().getName()); } else { return objClass; } return persistentClass.getMappedClass(); }
public void addPackages(Package pkg, GwtcServiceImpl gwtc, boolean recursive) { Iterable<ClassFile> iter; if (recursive) { iter = classpath.get().findClassesBelowPackage(pkg.getName()); } else { iter = classpath.get().findClassesInPackage(pkg.getName()); } for (ClassFile file : iter) { X_Log.info(getClass(), "Scanning file ", file); if ("package-info".equals(file.getEnclosedName())) { Package p = GwtReflect.getPackage(file.getPackage()); if (!finishedPackages.contains(p)) { gwtcService.addPackage(p, false); } } else { try { Class<?> cls = Thread.currentThread().getContextClassLoader().loadClass(file.getName()); if (!finishedClasses.contains(cls)) { gwtc.addClass(cls); } } catch (ClassNotFoundException e) { X_Log.warn(getClass(), "Unable to load class ", file); } } } }
public static void importPackage(ScriptEngine e, Package pkg, Bindings... b) { try { if (b.length == 0) { e.eval("importPackage(Packages." + pkg.getName() + ")"); } else { e.eval("importPackage(Packages." + pkg.getName() + ")", b[0]); } } catch (ScriptException e1) { throw new RuntimeException(e1); } }
protected void addGwtcPackage(Gwtc gwtc, Package pkg, boolean recursive) { String name = pkg.getName(); int i = name.lastIndexOf('.'); name = Character.toUpperCase(name.charAt(i + 1)) + name.substring(i + 2) + "_Package"; GwtcUnit node = nodes.get(pkg); String inherit = node.generateGwtXml(gwtc, pkg.getName(), name); inheritGwtXml(inherit); addGwtcSettings(gwtc); maybeAddAncestors(gwtc, pkg); if (recursive) { needChildren.add(pkg); } }
protected Class<?> findImpl(Class<T> iface) { Package pkg = iface.getPackage(); String pkgName = (pkg != null) ? pkg.getName() : DEFAULT_PACKAGE_NAME; String clsName = iface.getSimpleName(); Class<?> implClass = null; // look up in the following orders // 1. package.name.ClassNameImpl // 2. package.name.impl.ClassNameImpl // 3. package.name.impl.ClassName // 4. package.name.DefaultClassName // 5. package.name.DefaultHandler String[] lookups = { pkgName + "." + clsName + "Impl", pkgName + ".impl." + clsName + "Impl", pkgName + ".impl." + clsName, pkgName + "." + "Default" + clsName, pkgName + "." + "DefaultHandler" }; try { implClass = new ClassNameLookup(lookups, iface).lookup(); } catch (NotFound e) { // ignore logIntentionallyIgnoredCatch(log, e); } if (log.isLoggable(Level.FINE)) { log.fine("findImpl[iface=" + iface + ", implClass=" + String.valueOf(implClass) + "]"); } return implClass; }
public ClassMeta getClassInfo(Class<?> cls) { final Package pkg = cls.getPackage(); URL loadedFrom = null; try { loadedFrom = cls.getProtectionDomain().getCodeSource().getLocation(); } catch (Throwable t) { Log.warn(t, "Failed to get source for %s", cls); } final API apiAnnotation = pkg.getAnnotation(API.class); final ApiInfo apiInfo = apiAnnotation != null ? new ApiInfo(apiAnnotation) : null; Map<File, Set<String>> mods = Maps.newHashMap(); for (ModCandidate candidate : table.getCandidatesFor(pkg.getName())) { if (!candidate.getClassList().contains(cls.getName().replace('.', '/'))) continue; final File candidateFile = candidate.getModContainer(); Set<String> modIds = Sets.newHashSet(); mods.put(candidateFile, modIds); for (ModContainer mod : candidate.getContainedMods()) modIds.add(mod.getModId()); } return new ClassMeta(cls, loadedFrom, apiInfo, mods); }
/** * Gets an system property value. * * @param parameterName the Name or the parameter. * @return String value or null if not found */ protected String getSystemProperty(String parameterName) { String val = null; String pkgName; final Package pkg = systemPropertyBaseClass.getPackage(); if (pkg != null) { pkgName = pkg.getName(); } else { final String className = systemPropertyBaseClass.getName(); int index = className.lastIndexOf('.'); if (index >= 0) { pkgName = className.substring(0, index); } else { pkgName = null; } } if (pkgName == null) { pkgName = ""; } else { pkgName += '.'; } val = System.getProperty(pkgName + parameterName); if (val != null) { return val; } // Try lowercased system properties val = System.getProperty(pkgName + parameterName.toLowerCase()); return val; }
protected void addAllPackages(Package pkg) { Gwtc gwtc = pkg.getAnnotation(Gwtc.class); if (gwtc != null && addPackage(pkg)) { addGwtcPackage(gwtc, pkg, false); } String parentName = pkg.getName(); int ind = parentName.lastIndexOf('.'); while (ind > -1) { parentName = parentName.substring(0, ind); ind = parentName.lastIndexOf('.'); pkg = GwtReflect.getPackage(parentName); X_Log.debug(getClass(), "Checking parent package", "'" + parentName + "'", pkg != null); if (pkg != null) { gwtc = pkg.getAnnotation(Gwtc.class); if (gwtc != null && addPackage(pkg)) { addGwtcPackage(gwtc, pkg, false); } } } pkg = GwtReflect.getPackage(""); if (pkg != null) { gwtc = pkg.getAnnotation(Gwtc.class); if (gwtc != null && addPackage(pkg)) { addGwtcPackage(gwtc, pkg, false); } } }
/** * Get the {@link JAXBContext} from an existing {@link Class} object. If the class's owning * package is a valid JAXB package, this method redirects to {@link #getFromCache(Package)} * otherwise a new JAXB context is created and NOT cached. * * @param aClass The class for which the JAXB context is to be created. May not be <code>null * </code>. * @param aClassLoader Class loader to use. May be <code>null</code> in which case the default * class loader is used. * @return Never <code>null</code>. */ @Nonnull public JAXBContext getFromCache( @Nonnull final Class<?> aClass, @Nullable final ClassLoader aClassLoader) { ValueEnforcer.notNull(aClass, "Class"); final Package aPackage = aClass.getPackage(); if (aPackage.getAnnotation(XmlSchema.class) != null) { // Redirect to cached version return getFromCache(aPackage, aClassLoader); } // E.g. an internal class - try anyway! if (GlobalDebug.isDebugMode()) s_aLogger.info("Creating JAXB context for class " + aClass.getName()); if (aClassLoader != null) s_aLogger.warn( "Package " + aPackage.getName() + " does not seem to be JAXB generated. Therefore a new JAXBContext is created and the provided ClassLoader is ignored!"); try { return JAXBContext.newInstance(aClass); } catch (final JAXBException ex) { final String sMsg = "Failed to create JAXB context for class '" + aClass.getName() + "'"; s_aLogger.error(sMsg + ": " + ex.getMessage()); throw new IllegalArgumentException(sMsg, ex); } }
public HashMap<String, Package> load() { HashMap<String, Package> packages = new HashMap<String, Package>(); File inFile = obtainFile(); if (null == inFile) { System.out.println(String.format("[KITS] Unable to load %s.", filename)); return packages; } try { BufferedReader reader = new BufferedReader(new FileReader(inFile)); String line = null; while ((line = reader.readLine()) != null) { if (line.startsWith("#")) continue; String[] tokens = line.split(";"); if (tokens.length < 2) continue; Package newPkg = makePackage(tokens); if (null != newPkg) { packages.put(newPkg.getName(), newPkg); } } reader.close(); } catch (Exception e) { System.out.println(e.getStackTrace()); } return packages; }
public static Map<Package, ClassLoader[]> getPackageMap( List<ClassLoader> classLoaders, Set<String> ignorePackages) { Map<Package, ClassLoader[]> answer = new HashMap<Package, ClassLoader[]>(); ClassLoader[] globalClassLoaders = { Thread.currentThread().getContextClassLoader(), ClassScanner.class.getClassLoader() }; Set<Package> packages = new HashSet<Package>(); add(answer, Package.getPackages(), globalClassLoaders, ignorePackages); ClassLoader[] classLoaderArray = new ClassLoader[classLoaders.size()]; classLoaders.toArray(classLoaderArray); for (ClassLoader classLoader : classLoaders) { Package[] loaderPackages = findPackagesForClassLoader(classLoader); add(answer, loaderPackages, classLoaderArray, ignorePackages); } SortedSet<String> names = new TreeSet<String>(); for (Package aPackage : packages) { names.add(aPackage.getName()); } for (String name : names) { LOG.info("Got package " + name); } return answer; }
public static File getClassDirectory(Package pakage) { Set<Class<?>> classes = new LinkedHashSet<Class<?>>(); boolean flag = true; // 是否循环迭代 String packName = pakage.getName(); // String packName = "org.jdom"; String packDir = packName.replace(".", "/"); Enumeration<URL> dir; String filePath = null; try { dir = Thread.currentThread().getContextClassLoader().getResources(packDir); while (dir.hasMoreElements()) { URL url = dir.nextElement(); // System.out.println("url:***" + url); String protocol = url.getProtocol(); // 获得协议号 if ("file".equals(protocol)) { // System.err.println("file类型的扫描"); filePath = URLDecoder.decode(url.getFile(), "UTF-8"); } } } catch (IOException e) { e.printStackTrace(); } File file = new File(filePath); if (file.exists()) { return file; } else { return null; } }
// Serialize the bean using the specified namespace prefix & uri public String serialize(Object bean) throws IntrospectionException, IllegalAccessException { // Use the class name as the name of the root element String className = bean.getClass().getName(); String rootElementName = null; if (bean.getClass().isAnnotationPresent(ObjectXmlAlias.class)) { AnnotatedElement annotatedElement = bean.getClass(); ObjectXmlAlias aliasAnnotation = annotatedElement.getAnnotation(ObjectXmlAlias.class); rootElementName = aliasAnnotation.value(); } // Use the package name as the namespace URI Package pkg = bean.getClass().getPackage(); nsURI = pkg.getName(); // Remove a trailing semi-colon (;) if present (i.e. if the bean is an array) className = StringUtils.deleteTrailingChar(className, ';'); StringBuffer sb = new StringBuffer(className); String objectName = sb.delete(0, sb.lastIndexOf(".") + 1).toString(); domDocument = createDomDocument(objectName); document = domDocument.getDocument(); Element root = document.getDocumentElement(); // Parse the bean elements getBeanElements(root, rootElementName, className, bean); StringBuffer xml = new StringBuffer(); if (prettyPrint) xml.append(domDocument.serialize(lineSeperator, indentChars, includeXmlProlog)); else xml.append(domDocument.serialize(includeXmlProlog)); if (!includeTypeInfo) { int index = xml.indexOf(root.getNodeName()); xml.delete(index - 1, index + root.getNodeName().length() + 2); xml.delete(xml.length() - root.getNodeName().length() - 4, xml.length()); } return xml.toString(); }
/** * Returns the correct implementation instance for the interface <code>type</code>. For convention * the implentation is named <code>InterfaceName + Impl</code>. * * @param type The interface type * @return The correct ModelProxy subclass (if exists), a ModelProxy instance otherwise * @throws MalformedModelException is the interface or the implementation are not well formed * (they don't respect the conventions). * @throws ModelRuntimeException is any error occurs during the instantiation */ protected ModelProxy createInstance(Class type) { Class backClass; if (implementations.containsKey(type)) backClass = implementations.get(type); else { /* type never seen */ try { Package pkg = type.getPackage(); String pkgN = pkg == null ? "" : pkg.getName(); backClass = Class.forName(pkgN + tableName(type) + CommonStatic.getImplementationSuffix()); } catch (Exception e) { backClass = ModelProxy.class; } Validator.validateModel(type, backClass); initFieldsTypes(type); implementations.put(type, backClass); } ModelProxy impl = null; try { impl = (ModelProxy) backClass.newInstance(); } catch (Exception e) { throw new ModelRuntimeException(e.getMessage()); } return impl; }
public boolean isNonTerminal(Class clazz) { Package pack = clazz.getPackage(); if (pack == null) { // z.B. bei int[] return false; } return patternListFilter.filter(pack.getName()); }
/** * Generates a simplified name from a {@link Class}. Similar to {@link Class#getSimpleName()}, but * it works fine with anonymous classes. */ public static String simpleClassName(Class<?> clazz) { Package pkg = clazz.getPackage(); if (pkg != null) { return clazz.getName().substring(pkg.getName().length() + 1); } else { return clazz.getName(); } }
private String getPath(Class<?> clazz) { Package clazzPackage = clazz.getPackage(); String packagePath = clazzPackage.getName(); if (packagePath != null && packagePath.length() > 0) { return packagePath + "." + clazz.getSimpleName(); } return clazz.getSimpleName(); }
/** * Creates a filter that selects all {@literal @CmdLine} {@link Arg}s found in classes that are * members of the given package or its sub-packages. * * @param pkg The ancestor package of classes whose command line args will be selected. * @return A filter that selects only command line args declared in classes that are members of * the given {@code pkg} or its sub-packages. */ public static Predicate<Field> selectAllPackagesUnderHere(final Package pkg) { Preconditions.checkNotNull(pkg); final String prefix = pkg.getName() + '.'; return Predicates.or( selectPackage(pkg), field -> { return field.getDeclaringClass().getPackage().getName().startsWith(prefix); }); }
@SuppressWarnings("rawtypes") protected boolean expectInstance(Class clz) { Package pkg = clz.getPackage(); if (pkg == null) { return false; } else { return pkg.getName().startsWith("com.astamuse.asta4d."); } }
protected Package makePackage(String[] tokens) { String[] pkgInfo = tokens[0].split(":"); if (2 > pkgInfo.length) { System.out.println("Invalid Package: " + tokens[0]); return null; } String pkgName = pkgInfo[0]; if (pkgName.equalsIgnoreCase("list") || pkgName.equalsIgnoreCase("reload") || pkgName.equalsIgnoreCase("cooling")) { System.out.println("Invalid Package name: " + pkgName); return null; } Package pkg; int cooldown; try { cooldown = Integer.parseInt(pkgInfo[1]); } catch (NumberFormatException ex) { cooldown = 0; } pkg = new Package(pkgName, cooldown); String[] itemInfo; int quantity; Material item; for (int i = 1; i < tokens.length; i++) { itemInfo = tokens[i].split(":"); if (2 > itemInfo.length) { continue; } try { quantity = Integer.parseInt(itemInfo[1]); } catch (NumberFormatException ex) { quantity = 1; } item = Material.getMaterial(itemInfo[0]); if (item != null) { pkg.addItem(item, quantity); } else { System.out.println("Invalid package item: " + itemInfo[0]); } } if (0 >= pkg.getNumItems()) { System.out.println("Package has no valid items: " + pkg.getName()); return null; } return pkg; }
// @SuppressWarnings("unchecked") public static String getAppPath(Class<?> cls) { // 检查用户传入的参数是否为空 if (cls == null) throw new java.lang.IllegalArgumentException("参数不能为空!"); ClassLoader loader = cls.getClassLoader(); // 获得类的全名,包括包名 String clsName = cls.getName() + ".class"; // 获得传入参数所在的包 Package pack = cls.getPackage(); String path = ""; // 如果不是匿名包,将包名转化为路径 if (pack != null) { String packName = pack.getName(); // 此处简单判定是否是Java基础类库,防止用户传入JDK内置的类库 if (packName.startsWith("java.") || packName.startsWith("javax.")) throw new java.lang.IllegalArgumentException("不要传送系统类!"); // 在类的名称中,去掉包名的部分,获得类的文件名 clsName = clsName.substring(packName.length() + 1); // 判定包名是否是简单包名,如果是,则直接将包名转换为路径, if (packName.indexOf(".") < 0) path = packName + "/"; else { // 否则按照包名的组成部分,将包名转换为路径 int start = 0, end = 0; end = packName.indexOf("."); while (end != -1) { path = path + packName.substring(start, end) + "/"; start = end + 1; end = packName.indexOf(".", start); } path = path + packName.substring(start) + "/"; } } // 调用ClassLoader的getResource方法,传入包含路径信息的类文件名 java.net.URL url = loader.getResource(path + clsName); // 从URL对象中获取路径信息 String realPath = url.getPath(); // 去掉路径信息中的协议名"file:" int pos = realPath.indexOf("file:"); if (pos > -1) realPath = realPath.substring(pos + 5); // 去掉路径信息最后包含类文件信息的部分,得到类所在的路径 pos = realPath.indexOf(path + clsName); realPath = realPath.substring(0, pos - 1); // 如果类文件被打包到JAR等文件中时,去掉对应的JAR等打包文件名 if (realPath.endsWith("!")) realPath = realPath.substring(0, realPath.lastIndexOf("/")); /*------------------------------------------------------------ ClassLoader的getResource方法使用了utf-8对路径信息进行了编码,当路径 中存在中文和空格时,他会对这些字符进行转换,这样,得到的往往不是我们想要 的真实路径,在此,调用了URLDecoder的decode方法进行解码,以便得到原始的 中文及空格路径 -------------------------------------------------------------*/ try { realPath = java.net.URLDecoder.decode(realPath, "utf-8"); } catch (Exception e) { throw new RuntimeException(e); } System.out.println("realPath----->" + realPath); return realPath; }
/** * Determine imports for the given bundle. Based on the user settings, this method will consider * only the the test hierarchy until the testing framework is found or all classes available * inside the test bundle. * * <p>Note that split packages are not supported. * * @return */ private String[] determineImports() { boolean useTestClassOnly = false; // no jar entry present, bail out. if (jarEntries == null || jarEntries.isEmpty()) { logger.debug("No test jar content detected, generating bundle imports from the test class"); useTestClassOnly = true; } else if (createManifestOnlyFromTestClass()) { logger.info("Using the test class for generating bundle imports"); useTestClassOnly = true; } else logger.info("Using all classes in the jar for the generation of bundle imports"); // className, class resource Map entries; if (useTestClassOnly) { entries = new LinkedHashMap(4); // get current class (test class that bootstraps the OSGi infrastructure) Class<?> clazz = getClass(); String clazzPackage = null; String endPackage = AbstractOnTheFlyBundleCreatorTests.class.getPackage().getName(); do { // consider inner classes as well List classes = new ArrayList(4); classes.add(clazz); CollectionUtils.mergeArrayIntoCollection(clazz.getDeclaredClasses(), classes); for (Iterator iterator = classes.iterator(); iterator.hasNext(); ) { Class<?> classToInspect = (Class) iterator.next(); Package pkg = classToInspect.getPackage(); if (pkg != null) { clazzPackage = pkg.getName(); String classFile = ClassUtils.getClassFileName(classToInspect); entries.put( classToInspect.getName().replace('.', '/').concat(ClassUtils.CLASS_FILE_SUFFIX), new InputStreamResource(classToInspect.getResourceAsStream(classFile))); } // handle default package else { logger.warn("Could not find package for class " + classToInspect + "; ignoring..."); } } clazz = clazz.getSuperclass(); } while (!endPackage.equals(clazzPackage)); } else entries = jarEntries; return determineImportsFor(entries); }
/** * Helper method called to check whether it is acceptable to create a new class in package that * given class is part of. This is used to prevent certain class of failures, related to access * limitations: for example, we can not add classes in sealed packages, or core Java packages * (java.*). * * @since 2.2.1 */ public static boolean canAddClassInPackageOf(Class<?> cls) { final Package beanPackage = cls.getPackage(); if (beanPackage != null) { // 01-May-2013, tatu: How about "javax."? if (beanPackage.isSealed() || beanPackage.getName().startsWith("java.")) { return false; } } return true; }
// Implementation methods // ------------------------------------------------------------------------- protected void addPackageResources( Package aPackage, Map<String, ClassResource> urlSet, ClassLoader[] classLoaders) { String packageName = aPackage.getName(); String relativePath = getPackageRelativePath(packageName); List<URL> resources = getResources(relativePath, classLoaders); for (URL resource : resources) { String key = getJavaResourceKey(resource); urlSet.put(key, new ClassResource(packageName, resource)); } }
public FactTemplateError( final Package pkg, final BaseDescr descr, final Object object, final String message) { super(descr.getResource()); this.namespace = pkg.getName(); this.pkg = pkg; this.descr = descr; this.object = object; this.message = message; this.line = new int[] {(this.descr != null) ? this.descr.getLine() : -1}; }
/** * This will return the package name - if the package is null, it will work it out from the class * name (this is in cases where funky classloading is used). */ public static String getPackageName(Class<?> clazz, Package pkg) { String pkgName = ""; if (pkg == null) { int index = clazz.getName().lastIndexOf('.'); if (index != -1) pkgName = clazz.getName().substring(0, index); } else { pkgName = pkg.getName(); } return pkgName; }
private void addBeanMapping( WSDDService service, Class<?> clazz, Collection<Class<?>> mappedClasses) { while (clazz != null) { while (clazz.isArray()) { clazz = clazz.getComponentType(); } if (!needsMapping(clazz)) return; if (mappedClasses.contains(clazz)) return; mappedClasses.add(clazz); for (Method m : clazz.getDeclaredMethods()) { if (!m.isSynthetic() && m.getName().startsWith("get") && m.getParameterTypes().length == 0 && (m.getModifiers() & Modifier.PUBLIC) != 0) { addBeanMapping(service, m.getReturnType(), mappedClasses); } } WSDDBeanMapping m = new WSDDBeanMapping(); m.setLanguageSpecificType(clazz); Package p = clazz.getPackage(); if (p == null) { // arrayちゃんと処理できてる? // System.out.println(clazz); } String packageName = p != null ? p.getName() : ""; String simpleName = clazz.getSimpleName(); boolean qnameSet = false; for (Pair<String, String> n : namespaceMappings) { if (packageName.startsWith(n.getFirst())) { String rest = packageName.substring(n.getFirst().length()).replace('.', '/'); String nsPrefix = n.getSecond(); if (rest.length() > 0) { rest = rest + "/"; if (nsPrefix.endsWith("/") && rest.charAt(0) == '/') { rest = rest.substring(1); } } m.setQName(new QName(n.getSecond() + rest, simpleName)); qnameSet = true; break; } } if (!qnameSet) { m.setQName(new QName("uri:" + packageName + "/", simpleName)); } m.setSerializer(WSDDConstants.BEAN_SERIALIZER_FACTORY); m.setDeserializer(WSDDConstants.BEAN_DESERIALIZER_FACTORY); service.addTypeMapping(m); clazz = clazz.getSuperclass(); } }
/** Find (and load) all classes in a given package. The search relies on a directory listing. */ public static Iterable<Class<?>> getClassesInPackage(Package p) { LinkedList<Class<?>> l = new LinkedList<Class<?>>(); String name = p.getName(); System.out.println("Package to be listed: " + name); name = name.replace('.', File.separatorChar); File dir = new File(name); System.out.println("Absolute path of package: " + dir.getAbsoluteFile()); if (!dir.exists()) throw new RuntimeException("Can't find package!"); for (String f : dir.list()) if (f.endsWith(".class")) { String classname = f.substring(0, f.length() - 6); try { Class<?> clss = Class.forName(p.getName() + "." + classname); l.add(clss); } catch (ClassNotFoundException e) { // Ignore exception } } return l; }
/** * @see * org.apache.wicket.resource.loader.ComponentStringResourceLoader#loadStringResource(java.lang.Class, * java.lang.String, java.util.Locale, java.lang.String, java.lang.String) */ @Override public String loadStringResource( Class<?> clazz, final String key, final Locale locale, final String style, final String variation) { if (clazz == null) { return null; } // Load the properties associated with the path IPropertiesFactory propertiesFactory = getPropertiesFactory(); while (true) { Package pkg = clazz.getPackage(); String packageName = (pkg == null) ? "" : pkg.getName(); packageName = packageName.replace('.', '/'); do { // Create the base path String path = filename; if (packageName.length() > 0) { path = packageName + "/" + path; } // Iterator over all the combinations IResourceNameIterator iter = newResourceNameIterator(path, locale, style, variation); while (iter.hasNext()) { String newPath = iter.next(); Properties props = propertiesFactory.load(clazz, newPath); if (props != null) { // Lookup the value String value = props.getString(key); if (value != null) { return value; } } } // Didn't find the key yet, continue searching if possible packageName = Strings.beforeLast(packageName, '/'); } while (packageName.length() > 0); clazz = clazz.getSuperclass(); if (clazz == null) { break; } } // not found return null; }