List of usage examples for java.lang Class getPackage
public Package getPackage()
From source file:reconf.infra.i18n.BundleSettings.java
public BundleSettings(Class<?> cls) { className = cls.getSimpleName();// w w w . j a v a2 s.co m String[] packages = StringUtils.split(cls.getPackage().getName(), '.'); if (packages.length == 0 || packages.length == 1) { throw new IllegalArgumentException("only meant to be used inside reconf"); } headPackageName = packages[1]; if (packages.length >= 2) { tailPackageName = StringUtils.substringAfter(cls.getPackage().getName(), "reconf." + headPackageName + "."); } else { tailPackageName = StringUtils.EMPTY; } }
From source file:fr.univlorraine.mondossierweb.config.DebugConfig.java
/** * Branche customizableTraceInterceptor sur les mthodes public des classes du package controllers * @return/* w ww. ja va 2 s . co m*/ */ @Bean public Advisor controllersAdvisor() { return new StaticMethodMatcherPointcutAdvisor(customizableTraceInterceptor()) { private static final long serialVersionUID = 5897279987213542868L; @Override public boolean matches(Method method, Class<?> clazz) { return Modifier.isPublic(method.getModifiers()) && clazz.getPackage() != null && clazz.getPackage().getName().startsWith(UserController.class.getPackage().getName()); } }; }
From source file:pt.webdetails.cdb.util.PackageResolver.java
public PackageResolver(Class<?> classe) { this.classLoader = classe.getClassLoader(); this.basePath = classe.getPackage().getName().replaceAll("\\.", "/"); }
From source file:org.apache.axis2.jaxws.runtime.description.marshal.impl.PackageSetBuilder.java
/** * For each data element, we need the package for both the element and its type. * * @param cls Class representing element, type or both * @param namespace of the element/*www . j av a 2 s .c o m*/ * @param localPart of the element * @param set with both type and element packages set */ private static void setTypeAndElementPackages(Class cls, String namespace, String localPart, TreeSet<String> set, MarshalServiceRuntimeDescription msrd) { // Get the element and type classes Class eClass = getElement(cls, msrd); Class tClass = getType(cls); // Set the package for the type if (tClass != null) { Package typePkg = tClass.getPackage(); //For primitive types there is no package String pkg = (typePkg != null) ? typePkg.getName() : null; if (pkg != null) { set.add(pkg); set.add("@" + pkg); // Indicates a package from an actual class reference (versus namespace) set.add("[" + tClass.getCanonicalName() + "]"); // Indicates a actual class reference } // If there is an xmlType, and it maps to a package then add // an override if the package is different. if (pkg != null) { AnnotationDesc ad = msrd.getAnnotationDesc(tClass); if (ad != null && ad.hasXmlType()) { String ns = ad.getXmlTypeNamespace(); if (ns != null && ns.length() > 0) { List pkgs = makePackages(ns); if (pkgs != null) { for (int i = 0; i < pkgs.size(); i++) { String pkg2 = (String) pkgs.get(i); if (!pkg.equals(pkg2)) { String override = pkg + " > " + pkg2; if (!set.contains(override)) { set.add(override); if (log.isDebugEnabled()) { log.debug("Adding override=" + override); } } } } } } } } addXmlSeeAlsoPackages(tClass, msrd, set); } // Set the package for the element if (tClass != eClass) { if (eClass == null) { // A null or empty namespace indicates that the element is // unqualified. This can occur if the parameter is represented as a child element // in doc/lit wrapped. The package is determined from the wrapper element in such casses. if (namespace != null && namespace.length() > 0) { // Use default namespace to package algorithm List pkgs = makePackages(namespace); if (pkgs != null) { set.addAll(pkgs); } } } else { Package elementPkg = eClass.getPackage(); String pkg = (elementPkg != null) ? elementPkg.getName() : null; if (pkg != null) { set.add(pkg); set.add("@" + pkg); // Indicates a package from an actual class reference (versus namespace) set.add("[" + eClass.getCanonicalName() + "]"); // Indicates a actual class reference } if (pkg != null) { AnnotationDesc ad = msrd.getAnnotationDesc(tClass); if (ad != null && ad.hasXmlRootElement()) { String ns = ad.getXmlRootElementNamespace(); if (ns != null && ns.length() > 0) { List pkgs = makePackages(ns); if (pkgs != null) { for (int i = 0; i < pkgs.size(); i++) { String pkg2 = (String) pkgs.get(i); if (!pkg.equals(pkg2)) { String override = pkg + " > " + pkg2; if (!set.contains(override)) { set.add(override); if (log.isDebugEnabled()) { log.debug("Adding override=" + override); } } } } } } } } addXmlSeeAlsoPackages(tClass, msrd, set); } } }
From source file:capital.scalable.restdocs.javadoc.JavadocReaderImpl.java
private String classToRelativePath(Class<?> clazz) { String packageName = clazz.getPackage().getName(); String packageDir = packageName.replace(".", File.separator); String className = clazz.getCanonicalName().replaceAll(packageName + "\\.?", ""); return new File(packageDir, className + ".json").getPath(); }
From source file:org.rhq.enterprise.gui.common.framework.ServerInfoUIBean.java
private String getManifestVersion(Class clazz) { String version = null;/*from w w w . ja v a 2s . c om*/ try { Package pkg = clazz.getPackage(); if (pkg != null) { version = pkg.getImplementationVersion(); if (version == null) { version = pkg.getSpecificationVersion(); } } } catch (Exception e) { log.error("Error while looking up manifest version for " + clazz + ".", e); } return version; }
From source file:com.consol.citrus.admin.service.spring.filter.GetSpringBeanFilter.java
/** * Constructor using bean definition id as field. *//*from w w w. j a v a 2 s .c om*/ public GetSpringBeanFilter(String id, Class<?> type) { this.elementName = type.getAnnotation(XmlRootElement.class).name(); this.elementNamespace = type.getPackage().getAnnotation(XmlSchema.class).namespace(); this.id = id; }
From source file:net.lightbody.bmp.proxy.jetty.util.jmx.ModelMBeanImpl.java
/** Create MBean for Object. * Attempts to create an MBean for the object by searching the * package and class name space. For example an object of the * type <PRE>//from w w w . j av a 2s. c o m * class com.acme.MyClass extends com.acme.util.BaseClass * </PRE> * Then this method would look for the following * classes:<UL> * <LI>com.acme.MyClassMBean * <LI>com.acme.jmx.MyClassMBean * <LI>com.acme.util.BaseClassMBean * <LI>com.acme.util.jmx.BaseClassMBean * </UL> * @param o The object * @return A new instance of an MBean for the object or null. */ public static ModelMBean mbeanFor(Object o) { try { Class oClass = o.getClass(); ClassLoader loader = oClass.getClassLoader(); ModelMBean mbean = null; boolean jmx = false; Class[] interfaces = null; int i = 0; while (mbean == null && oClass != null) { Class focus = interfaces == null ? oClass : interfaces[i]; String pName = focus.getPackage().getName(); String cName = focus.getName().substring(pName.length() + 1); String mName = pName + (jmx ? ".jmx." : ".") + cName + "MBean"; try { Class mClass = loader.loadClass(mName); if (log.isTraceEnabled()) log.trace("mbeanFor " + o + " mClass=" + mClass); mbean = (ModelMBean) mClass.newInstance(); mbean.setManagedResource(o, "objectReference"); if (log.isDebugEnabled()) log.debug("mbeanFor " + o + " is " + mbean); return mbean; } catch (ClassNotFoundException e) { if (e.toString().endsWith("MBean")) { if (log.isTraceEnabled()) log.trace(e.toString()); } else log.warn(LogSupport.EXCEPTION, e); } catch (Error e) { log.warn(LogSupport.EXCEPTION, e); mbean = null; } catch (Exception e) { log.warn(LogSupport.EXCEPTION, e); mbean = null; } if (jmx) { if (interfaces != null) { i++; if (i >= interfaces.length) { interfaces = null; oClass = oClass.getSuperclass(); } } else { interfaces = oClass.getInterfaces(); i = 0; if (interfaces == null || interfaces.length == 0) { interfaces = null; oClass = oClass.getSuperclass(); } } } jmx = !jmx; } } catch (Exception e) { LogSupport.ignore(log, e); } return null; }
From source file:org.mule.module.xml.transformer.jaxb.JAXBTransformerResolver.java
protected boolean hasJaxbAnnotations(Class annotatedType) { String p = annotatedType.getPackage() == null ? "" : annotatedType.getPackage().getName(); for (int i = 0; i < ignoredPackages.length; i++) { if (p.startsWith(ignoredPackages[i])) return false; }//from w w w . ja v a2 s . co m try { return AnnotationUtils.hasAnnotationWithPackage("javax.xml.bind.annotation", annotatedType); } catch (IOException e) { logger.warn("Failed to scan class for Jaxb annotations: " + annotatedType, e); return false; } }
From source file:org.springframework.boot.ResourceBanner.java
protected String getApplicationVersion(Class<?> sourceClass) { Package sourcePackage = (sourceClass == null ? null : sourceClass.getPackage()); return (sourcePackage == null ? null : sourcePackage.getImplementationVersion()); }