List of usage examples for java.lang Class getPackage
public Package getPackage()
From source file:org.cleverbus.core.camel.JaxbElementParseFailTest.java
protected JaxbDataFormat getDataFormat(Class<?> xmlClass) { JaxbDataFormat dataFormat = new JaxbDataFormat(false); dataFormat.setContextPath(xmlClass.getPackage().getName()); dataFormat.setSchema("classpath:org/cleverbus/core/camel/jaxb/mock.xsd"); return dataFormat; }
From source file:com.consol.citrus.admin.service.spring.filter.GetSpringBeansFilter.java
/** * Constructor using bean definition type as field. */// w w w . j av a 2s . co m public GetSpringBeansFilter(Class<?> type) { this.elementName = type.getAnnotation(XmlRootElement.class).name(); this.elementNamespace = type.getPackage().getAnnotation(XmlSchema.class).namespace(); }
From source file:com.predic8.membrane.core.interceptor.javascript.JavascriptInterceptor.java
private HashMap<String, Object> getHttpPackageClasses() throws IOException, ClassNotFoundException { String httpPackage = "com.predic8.membrane.core.http"; HashMap<String, Object> result = new HashMap<>(); List<Class<?>> classes = ClassFinder.find(router.getBeanFactory().getClassLoader(), httpPackage); for (Class c : classes) { if (c.getPackage().getName().equals(httpPackage) && !c.getSimpleName().isEmpty()) result.put(c.getSimpleName(), c); }/*w w w.j a va 2s.c o m*/ return result; }
From source file:org.mule.config.transformer.AbstractAnnotatedTransformerArgumentResolver.java
protected boolean findAnnotation(Class annotatedType) throws IOException { if (annotatedType.getPackage() == null) { return false; }/*w ww .j a v a 2s . co m*/ for (String ignoredPackage : ignoredPackages) { if (annotatedType.getPackage().getName().startsWith(ignoredPackage)) { return false; } } return AnnotationUtils.hasAnnotationWithPackage(getAnnotationsPackageName(), annotatedType); }
From source file:com.yahoo.elide.core.EntityDictionary.java
/** * Return first matching annotation from class, parents or package. * * @param entityClass Entity class type/*from w w w . j a v a 2 s . c o m*/ * @param annotationClassList List of sought annotations * @return annotation found */ public static Annotation getFirstAnnotation(Class<?> entityClass, List<Class<? extends Annotation>> annotationClassList) { Annotation annotation = null; for (Class<?> cls = entityClass; annotation == null && cls != null; cls = cls.getSuperclass()) { for (Class<? extends Annotation> annotationClass : annotationClassList) { annotation = cls.getAnnotation(annotationClass); if (annotation != null) { break; } } } // no class annotation, try packages for (Package pkg = entityClass.getPackage(); annotation == null && pkg != null; pkg = getParentPackage(pkg)) { for (Class<? extends Annotation> annotationClass : annotationClassList) { annotation = pkg.getAnnotation(annotationClass); if (annotation != null) { break; } } } return annotation; }
From source file:com.gargoylesoftware.htmlunit.javascript.configuration.JavaScriptConfigurationTest.java
/** * Return the classes inside the specified package and its sub-packages. * @param klass a class inside that package * @return a list of class names//from w w w .j a v a 2 s . c o m */ public static List<String> getClassesForPackage(final Class<?> klass) { final List<String> list = new ArrayList<>(); File directory = null; final String relPath = klass.getName().replace('.', '/') + ".class"; final URL resource = JavaScriptConfiguration.class.getClassLoader().getResource(relPath); if (resource == null) { throw new RuntimeException("No resource for " + relPath); } final String fullPath = resource.getFile(); try { directory = new File(resource.toURI()).getParentFile(); } catch (final URISyntaxException e) { throw new RuntimeException(klass.getName() + " (" + resource + ") does not appear to be a valid URL", e); } catch (final IllegalArgumentException e) { directory = null; } if (directory != null && directory.exists()) { addClasses(directory, klass.getPackage().getName(), list); } else { try { String jarPath = fullPath.replaceFirst("[.]jar[!].*", ".jar").replaceFirst("file:", ""); if (System.getProperty("os.name").toLowerCase(Locale.ROOT).contains("win")) { jarPath = jarPath.replace("%20", " "); } final JarFile jarFile = new JarFile(jarPath); for (final Enumeration<JarEntry> entries = jarFile.entries(); entries.hasMoreElements();) { final String entryName = entries.nextElement().getName(); if (entryName.endsWith(".class")) { list.add(entryName.replace('/', '.').replace('\\', '.').replace(".class", "")); } } jarFile.close(); } catch (final IOException e) { throw new RuntimeException(klass.getPackage().getName() + " does not appear to be a valid package", e); } } return list; }
From source file:br.msf.commons.util.IOUtils.java
/** * Reads the properties of a classpath resource file, named after a class. * <p/>//from w w w.jav a 2s .com * Example:<br/> * if the given class fully qualified name is: * <pre>"org.mycomp.MyClass"</pre> * this method will look for a properties file named: * <pre>"/org/mycomp/MyClass.properties"</pre> * on the classpath. * <p/> * Accordingly to the Standard Java Specifications, Properties files are ISO-8859-1 encoded. * * @param clazz The class witch the resource is named after. * @return The properties of the resource file pointed by the given path. * @throws RuntimeIOException If something goes wrong opening the file stream. */ public static Properties readProperties(final Class clazz) { if (clazz == null) { return null; } return readProperties(clazz.getPackage(), clazz.getSimpleName(), clazz.getClassLoader()); }
From source file:edu.wisc.cypress.dm.CypressJaxbTest.java
private <T> T unmarshall(String resource, Class<T> clazz) throws Exception { final JAXBContext context = JAXBContext.newInstance(clazz.getPackage().getName()); final Unmarshaller unmarshaller = context.createUnmarshaller(); final InputStream xmlStream = this.getClass().getResourceAsStream(resource); try {/*w w w .ja va2s .c o m*/ assertNotNull(xmlStream); final JAXBElement<T> statements = unmarshaller.unmarshal(new StreamSource(xmlStream), clazz); return statements.getValue(); } finally { IOUtils.closeQuietly(xmlStream); } }
From source file:org.failearly.dataz.internal.template.support.test.message.basic.AbstractTemplateObjectMessage.java
private String stripPackageName(Class<?> clazz) { return StringUtils.removeStart(clazz.getCanonicalName(), clazz.getPackage().getName() + "."); }
From source file:org.apache.streams.data.MoreoverXmlActivitySerializer.java
private JAXBContext createContext(Class articleClass) { JAXBContext context;/* ww w. j ava 2s. co m*/ try { context = JAXBContext.newInstance(articleClass.getPackage().getName(), ObjectFactory.class.getClassLoader()); } catch (JAXBException e) { throw new IllegalStateException("Unable to create JAXB Context for Moreover data", e); } return context; }