List of usage examples for java.lang Class getPackage
public Package getPackage()
From source file:org.apache.openjpa.util.ProxyManagerImpl.java
private static boolean isProxyable(Class<?> cls) { int mod = cls.getModifiers(); if (Modifier.isFinal(mod)) return false; if (Modifier.isProtected(mod) || Modifier.isPublic(mod)) return true; // Default scoped class, we can only extend if it is in the same package as the generated proxy. Ideally // we'd fix the code gen portion and place proxies in the same pacakge as the types being proxied. if (cls.getPackage().getName().equals("org.apache.openjpa.util")) return true; return false; }
From source file:org.kuali.rice.krad.service.impl.RemoteModuleServiceBase.java
/** * @see org.kuali.rice.krad.service.ModuleService#isResponsibleFor(java.lang.Class) *///from w w w . j ava2s . c o m @Override public boolean isResponsibleFor(Class businessObjectClass) { ModuleConfiguration mc = getModuleConfiguration(); if (mc == null) { throw new IllegalStateException( "Module configuration has not been initialized for the module service."); } if (businessObjectClass == null) { return false; } if (packagePrefixesMatchesDataObject(businessObjectClass)) { return true; } if (persistenceProvidersMatchDataObject(businessObjectClass)) { return true; } if (ExternalizableBusinessObject.class.isAssignableFrom(businessObjectClass)) { Class externalizableBusinessObjectInterface = ExternalizableBusinessObjectUtils .determineExternalizableBusinessObjectSubInterface(businessObjectClass); if (externalizableBusinessObjectInterface != null) { for (String prefix : getModuleConfiguration().getPackagePrefixes()) { if (externalizableBusinessObjectInterface.getPackage().getName().startsWith(prefix)) { return true; } } } } return false; }
From source file:org.apache.struts2.config.ClasspathPackageProvider.java
/** * Finds all parent packages by first looking at the ParentPackage annotation on the package, then the class * @param cls The action class// ww w . j av a 2 s . c o m * @return A list of unique packages to add */ private List<PackageConfig> findAllParentPackages(Class<?> cls) { List<PackageConfig> parents = new ArrayList<PackageConfig>(); // Favor parent package annotations from the package Set<String> parentNames = new LinkedHashSet<String>(); ParentPackage annotation = cls.getPackage().getAnnotation(ParentPackage.class); if (annotation != null) { parentNames.addAll(Arrays.asList(annotation.value())); } annotation = cls.getAnnotation(ParentPackage.class); if (annotation != null) { parentNames.addAll(Arrays.asList(annotation.value())); } if (parentNames.size() > 0) { for (String parent : parentNames) { PackageConfig parentPkg = configuration.getPackageConfig(parent); if (parentPkg == null) { throw new ConfigurationException( "ClasspathPackageProvider: Unable to locate parent package " + parent, annotation); } parents.add(parentPkg); } } return parents; }
From source file:de.taimos.dvalin.interconnect.model.maven.MetaModelHelper.java
private ImplementsDef createID(Class<?> clazz) { ImplementsDef id = new ImplementsDef(); id.setName(clazz.getSimpleName());/*from w w w . j a v a 2 s . c o m*/ id.setPkgName(clazz.getPackage().getName()); return id; }
From source file:org.debux.webmotion.server.convention.DefaultConventionScan.java
/** * Scan the filters by convention./*from ww w . j ava 2 s . co m*/ */ public List<FilterRule> scanFilters(Mapping mapping) { Pattern allPattern = Pattern.compile("/*"); Collection<Class<?>> filters = ReflectionUtils.getClassesBySuperClass(ConventionAllFilter.class); List<FilterRule> rules = new ArrayList<FilterRule>(filters.size()); for (Class<?> filter : filters) { FilterRule rule = new FilterRule(); rule.setMapping(mapping); rule.setLine(-1); rules.add(rule); rule.setMethods(Arrays.asList("*")); rule.setPattern(allPattern); Action action = new Action(); action.setType(Action.Type.ACTION); action.setFullName(filter.getName() + ".filter"); rule.setAction(action); } filters = ReflectionUtils.getClassesBySuperClass(ConventionPackageFilter.class); for (Class<?> filter : filters) { FilterRule rule = new FilterRule(); rule.setMapping(mapping); rule.setLine(-1); rules.add(rule); Package filterPackage = filter.getPackage(); if (filterPackage != null) { String packageName = filterPackage.getName(); String subPackageName = StringUtils.substringAfterLast(packageName, "."); String regexp = "/" + subPackageName.toLowerCase() + "/*"; rule.setPattern(Pattern.compile(regexp)); } else { rule.setPattern(allPattern); } rule.setMethods(Arrays.asList("*")); Action action = new Action(); action.setType(Action.Type.ACTION); action.setFullName(filter.getName() + ".filter"); rule.setAction(action); } return rules; }
From source file:com.wavemaker.tools.javaservice.JavaServiceDefinition.java
private void init(Class<?> serviceClass, Class<?> runtimeServiceClass) { ReflectTypeState typeState = new ReflectTypeState(); Collection<Method> methods = filterOverloadedMethods(ServerUtils.getClientExposedMethods(serviceClass)); for (Method m : methods) { initOperation(m, typeState);/*from ww w . j a va 2 s. c o m*/ } this.implementsCRUDService = runtimeServiceClass.isAssignableFrom(serviceClass); this.serviceClassName = serviceClass.getName(); if (this.implementsCRUDService) { for (TypeDefinition td : this.typeDefinitions) { ((ReflectTypeDefinition) td).setLiveService(this.implementsCRUDService); } } if (serviceClass.getPackage() == null) { this.packageName = null; } else { this.packageName = serviceClass.getPackage().getName(); } }
From source file:com.evolveum.midpoint.prism.parser.PrismBeanInspector.java
private String determineNamespaceUncached(Class<? extends Object> beanClass) { XmlType xmlType = beanClass.getAnnotation(XmlType.class); if (xmlType == null) { return null; }/*from w w w . j ava 2 s. com*/ String namespace = xmlType.namespace(); if (namespace == null || PrismBeanConverter.DEFAULT_PLACEHOLDER.equals(namespace)) { XmlSchema xmlSchema = beanClass.getPackage().getAnnotation(XmlSchema.class); namespace = xmlSchema.namespace(); } if (StringUtils.isBlank(namespace) || PrismBeanConverter.DEFAULT_PLACEHOLDER.equals(namespace)) { return null; } return namespace; }
From source file:com.evolveum.midpoint.prism.parser.PrismBeanInspector.java
private QName determineTypeForClassUncached(Class<? extends Object> beanClass) { XmlType xmlType = beanClass.getAnnotation(XmlType.class); if (xmlType == null) { return null; }// w ww . j a v a 2s. c o m String namespace = xmlType.namespace(); if (namespace == null || PrismBeanConverter.DEFAULT_PLACEHOLDER.equals(namespace)) { XmlSchema xmlSchema = beanClass.getPackage().getAnnotation(XmlSchema.class); namespace = xmlSchema.namespace(); } if (StringUtils.isBlank(namespace) || PrismBeanConverter.DEFAULT_PLACEHOLDER.equals(namespace)) { return null; } return new QName(namespace, xmlType.name()); }
From source file:org.springframework.data.rest.webmvc.config.RepositoryRestMvcConfiguration.java
@SuppressWarnings("unchecked") private Set<Class<?>> getProjections(Repositories repositories) { Set<String> packagesToScan = new HashSet<String>(); for (Class<?> domainType : repositories) { packagesToScan.add(domainType.getPackage().getName()); }//w w w . j a va 2 s . c o m AnnotatedTypeScanner scanner = new AnnotatedTypeScanner(Projection.class); scanner.setEnvironment(applicationContext.getEnvironment()); scanner.setResourceLoader(applicationContext); return scanner.findTypes(packagesToScan); }
From source file:org.tdar.core.service.ReflectionService.java
/** * Find all beans that implment the @link Persistable interface * /* w ww . j a v a 2s.co m*/ * @param cls * @return */ @SuppressWarnings("unchecked") public List<Pair<Field, Class<? extends Persistable>>> findAllPersistableFields(Class<?> cls) { List<Field> declaredFields = new ArrayList<>(); List<Pair<Field, Class<? extends Persistable>>> result = new ArrayList<>(); // iterate up the package hierarchy while (cls.getPackage().getName().startsWith(ORG_TDAR)) { CollectionUtils.addAll(declaredFields, cls.getDeclaredFields()); cls = cls.getSuperclass(); } for (Field field : declaredFields) { Class<? extends Persistable> type = null; // generic collections if (java.lang.reflect.Modifier.isStatic(field.getModifiers()) || java.lang.reflect.Modifier.isTransient(field.getModifiers()) || java.lang.reflect.Modifier.isFinal(field.getModifiers())) { continue; } if (Collection.class.isAssignableFrom(field.getType())) { ParameterizedType stringListType = (ParameterizedType) field.getGenericType(); if (Persistable.class.isAssignableFrom( (Class<? extends Persistable>) stringListType.getActualTypeArguments()[0])) { type = (Class<? extends Persistable>) stringListType.getActualTypeArguments()[0]; logger.trace("\t -> {}", type); // class java.lang.String. } } // singletons if (Persistable.class.isAssignableFrom(field.getType())) { type = (Class<? extends Persistable>) field.getType(); logger.trace("\t -> {}", type); // class java.lang.String. } // things to add if (type != null) { result.add(new Pair<Field, Class<? extends Persistable>>(field, type)); } } return result; }