List of usage examples for java.lang Class getPackage
public Package getPackage()
From source file:Main.java
public static <T> T deserialize(Class<T> res, InputStream is) throws JAXBException { String pkg = res.getPackage().getName(); JAXBContext jc = getCachedContext(pkg); Unmarshaller u = jc.createUnmarshaller(); u.setEventHandler(new DefaultValidationEventHandler()); return res.cast(u.unmarshal(is)); }
From source file:Main.java
/** * Similar to {@link #isCglibGetCallbacks}, need to suppress * a cyclic reference to resolve [JACKSON-103] *//* w w w . jav a2 s . c om*/ protected static boolean isGroovyMetaClassSetter(AnnotatedMethod am) { Class<?> argType = am.getRawParameterType(0); Package pkg = argType.getPackage(); if (pkg != null && pkg.getName().startsWith("groovy.lang")) { return true; } return false; }
From source file:de.metas.ui.web.config.SwaggerConfig.java
@SuppressWarnings("unused") private static final Predicate<RequestHandler> basePackages(final Class<?>... classes) { final Set<Predicate<RequestHandler>> predicates = new HashSet<>(classes.length); for (final Class<?> clazz : classes) { final String packageName = clazz.getPackage().getName(); predicates.add(RequestHandlerSelectors.basePackage(packageName)); }/* ww w . j a va2 s . c o m*/ if (predicates.size() == 1) { return predicates.iterator().next(); } return Predicates.or(predicates); }
From source file:Main.java
/** * Attempts to unmarshal an XML document from an InputStream. * * @param inputStream InputStream to unmarshal XML from. * @param type JAXB class of the returned object. Must be in the same package as other relevant JAXB classes. * @param <T> the type of the returned object * @return the unmarshalled JAXB object//from w w w .j a v a 2s .c o m * @throws JAXBException if an unexpected error occurs while unmarshalling */ public static <T> T unmarshal(InputStream inputStream, Class<T> type) throws JAXBException { JAXBContext jaxbContext = JAXBContext.newInstance(type.getPackage().getName()); Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); @SuppressWarnings("unchecked") JAXBElement<T> jaxbElement = (JAXBElement<T>) unmarshaller.unmarshal(inputStream); return jaxbElement.getValue(); }
From source file:annis.test.TestHelper.java
private static String packagePath(Class<?> clazz) { String packageDeclaration = clazz.getPackage().toString(); String path = packageDeclaration.replaceFirst("package ", "").replaceAll("\\.", "/") + "/"; return path;//from w w w. j a v a 2 s . c o m }
From source file:Main.java
@SuppressWarnings("unchecked") public static <T> T unmarshallXml(Class<T> clazz, InputStream in) throws JAXBException, UnsupportedEncodingException { String className = clazz.getPackage().getName(); JAXBContext context = JAXBContext.newInstance(className); Unmarshaller unmarshaller = context.createUnmarshaller(); //Reader reader = new IgnoreIllegalCharactersXmlReader(in); Reader reader = new InputStreamReader(in, "UTF-8"); InputSource is = new InputSource(reader); is.setEncoding("UTF-8"); Object result = unmarshaller.unmarshal(is); //file); return (T) result; }
From source file:org.apache.aries.blueprint.plugin.FilteredClassFinder.java
private static Set<Class<?>> filterByBasePackages(Set<Class<?>> rawClasses, Collection<String> packageNames) { Set<Class<?>> filteredClasses = new HashSet<Class<?>>(); for (Class<?> clazz : rawClasses) { for (String packageName : packageNames) { if (clazz.getPackage().getName().startsWith(packageName)) { filteredClasses.add(clazz); continue; }/*from ww w . j a v a2s . c om*/ } } //System.out.println("Raw: " + rawClasses); //System.out.println("Filtered: " + beanClasses); return filteredClasses; }
From source file:com.edmunds.autotest.ClassUtil.java
private static boolean isClassUnderRootPackage(AutoTestConfig config, Class<?> cls) { return cls.getPackage().getName().startsWith(config.getRootPackage()); }
From source file:org.drombler.commons.client.util.ResourceBundleUtils.java
private static ResourceBundle getResourceBundle(Class<?> type, String baseName) { return getResourceBundle(type.getPackage().getName(), baseName, type.getClassLoader()); }
From source file:Main.java
public static List<Field> getAccessibleFields(Class<?> clazz, Class<?> limit) { Package topPackage = clazz.getPackage(); List<Field> fieldList = new ArrayList<Field>(); int topPackageHash = topPackage == null ? 0 : topPackage.hashCode(); boolean top = true; do {/* w w w.j ava2 s.co m*/ if (clazz == null) { break; } Field[] declaredFields = clazz.getDeclaredFields(); for (Field field : declaredFields) { if (top == true) { // add all top declared fields fieldList.add(field); continue; } int modifier = field.getModifiers(); if (Modifier.isPrivate(modifier) == true) { continue; // ignore super private fields } if (Modifier.isPublic(modifier) == true) { addFieldIfNotExist(fieldList, field); // add super public methods continue; } if (Modifier.isProtected(modifier) == true) { addFieldIfNotExist(fieldList, field); // add super protected methods continue; } // add super default methods from the same package Package pckg = field.getDeclaringClass().getPackage(); int pckgHash = pckg == null ? 0 : pckg.hashCode(); if (pckgHash == topPackageHash) { addFieldIfNotExist(fieldList, field); } } top = false; } while ((clazz = clazz.getSuperclass()) != limit); return fieldList; }