List of usage examples for java.lang Class getPackage
public Package getPackage()
From source file:gov.nyc.doitt.gis.geoclient.service.configuration.AppConfig.java
public String getImplementationVersion(Class<?> clazz) { Package pkg = clazz.getPackage(); if (pkg == null) { return "UNKNOWN"; }// www . j a v a 2 s . com return pkg.getImplementationVersion(); }
From source file:org.echocat.jomon.spring.application.XmlBasedApplicationContextRequirement.java
@Nonnull public XmlBasedApplicationContextRequirement withConfiguration(@Nonnull Class<?> relation, @Nonnull String file) {/*from ww w . j a v a2s . com*/ _configurationFiles.add( new ClassPathResource(relation.getPackage().getName().replace('.', '/') + "/" + file, relation)); return this; }
From source file:com.gradecak.alfresco.mvc.aop.PackageAutoProxyCreator.java
/** * Identify as bean to proxy if the bean name is in the configured base package. *//* ww w. ja va 2s . co m*/ protected Object[] getAdvicesAndAdvisorsForBean(final Class<?> beanClass, final String beanName, final TargetSource targetSource) { if (this.basePackage != null) { if (beanClass != null && beanClass.getPackage() != null && beanClass.getPackage().getName().equals(basePackage)) { return PROXY_WITHOUT_ADDITIONAL_INTERCEPTORS; } } return DO_NOT_PROXY; }
From source file:org.mili.core.resource.DefaultResourceManagerFactory.java
/** * Creates a resource manager for class and locale. The base name is generated by the * package. By example : java -> java, java.lang -> java-lang, java.lang.core -> java-lang<br/> * Default packages are not supported!/* w w w .j ava 2s .c o m*/ * * @param cls class * @param locale locale * @return resource manager */ public ResourceManager create(Class<?> cls, Locale locale) { Validate.notNull(cls, "class cannot be null!"); Validate.notNull(locale, "locale cannot be null!"); String bn = this.createBasename(cls.getPackage().getName()); Validate.notEmpty(bn, "basename cannot be empty!"); return new ResourceHelper(cls, locale, bn); }
From source file:name.martingeisse.api.handler.misc.ClasspathResourceHandler.java
@Override public void handle(final ApiRequestCycle requestCycle, final ApiRequestPathChain path) throws Exception { HttpServletResponse response = requestCycle.getResponse(); // set headers if (characterEncoding != null) { response.setCharacterEncoding(characterEncoding); }//w ww . java 2 s .c o m response.setContentType(contentType); // write the resource to the response body Class<?> scope = (this.classpathScope == null ? getClass() : this.classpathScope); String packageName = scope.getPackage().getName(); String internalPath = "/" + packageName.replace('.', '/') + '/' + classpathFilename; try (InputStream inputStream = scope.getResourceAsStream(internalPath)) { if (inputStream == null) { throw new Exception("classpath resource not found: " + internalPath); } try (OutputStream outputStream = requestCycle.getOutputStream()) { IOUtils.copy(inputStream, outputStream); outputStream.flush(); } } }
From source file:com.ottogroup.bi.spqr.repository.CachedComponentClassLoaderTest.java
/** * Test case for {@link CachedComponentClassLoader#loadClass(String)} * being provided a reference towards a external class *//* w ww . j a va 2 s . co m*/ @Test public void testPackage_withExternalClassReference() throws ClassNotFoundException { CachedComponentClassLoader cl = new CachedComponentClassLoader( CachedComponentClassLoader.class.getClassLoader()); Class<?> c = cl.loadClass("com.fasterxml.jackson.databind.JsonNode"); Assert.assertEquals("Values must be equal", c.getPackage().getName(), "com.fasterxml.jackson.databind"); }
From source file:com.espertech.esper.util.PopulateUtil.java
private static Class findInterfaceImplementation(Map<String, Object> properties, Class topClass, EngineImportService engineImportService) throws ExprValidationException { String message = "Failed to find implementation for interface " + topClass.getName(); // Allow to populate the special "class" field if (!properties.containsKey(CLASS_PROPERTY_NAME)) { throw new ExprValidationException(message + ", for interfaces please specified the '" + CLASS_PROPERTY_NAME/*from ww w .j av a 2 s .co m*/ + "' field that provides the class name either as a simple class name or fully qualified"); } Class clazz = null; String className = (String) properties.get(CLASS_PROPERTY_NAME); try { clazz = JavaClassHelper.getClassForName(className); } catch (ClassNotFoundException e) { if (!className.contains(".")) { className = topClass.getPackage().getName() + "." + className; try { clazz = JavaClassHelper.getClassForName(className); } catch (ClassNotFoundException ex) { } } if (clazz == null) { throw new ExprValidationPropertyException( message + ", could not find class by name '" + className + "'"); } } if (!JavaClassHelper.isSubclassOrImplementsInterface(clazz, topClass)) { throw new ExprValidationException(message + ", class " + JavaClassHelper.getClassNameFullyQualPretty(clazz) + " does not implement the interface"); } return clazz; }
From source file:org.springframework.boot.context.properties.ValidatedLocalValidatorFactoryBean.java
@Override public boolean supports(Class<?> type) { if (!super.supports(type)) { return false; }//from ww w. ja v a2 s . c o m if (AnnotatedElementUtils.hasAnnotation(type, Validated.class)) { return true; } if (type.getPackage() != null && type.getPackage().getName().startsWith("org.springframework.boot")) { return false; } if (getConstraintsForClass(type).isBeanConstrained()) { logger.warn("The @ConfigurationProperties bean " + type + " contains validation constraints but had not been annotated " + "with @Validated."); } return true; }
From source file:se.vgregion.portal.innovatinosslussen.domain.TypesBeanTest.java
private List<Class> getTypes(Class sampelTypeFromPack) throws ClassNotFoundException { Package aPackage = sampelTypeFromPack.getPackage(); URL url = sampelTypeFromPack.getResource("/"); File file = new File(url.getFile()); file = new File(file.getParent()); String sc = File.separator; String path = file.getParent() + sc + "target" + sc + "classes" + sc + aPackage.getName().replace('.', sc.charAt(0)) + sc; file = new File(path); List<Class> result = new ArrayList<Class>(); if (file != null && file.list() != null) { for (String clazzFileName : file.list()) { if (clazzFileName.endsWith(".class")) { clazzFileName = clazzFileName.substring(0, clazzFileName.indexOf(".class")); result.add(Class.forName(aPackage.getName() + "." + clazzFileName)); }/* w w w.java2 s . c om*/ } } else { System.out.println("File or its children did not exist " + file); } return result; }
From source file:org.androidtransfuse.adapter.PackageClass.java
/** * Constructor that parses the class package and name from the input class * * @param inputClass input//from ww w . jav a 2 s .c o m */ public PackageClass(Class<?> inputClass) { String canonicalName = inputClass.getCanonicalName(); if (inputClass.getPackage() != null) { this.pkg = inputClass.getPackage().getName(); if (canonicalName != null) { this.fileName = canonicalName.substring(this.pkg.length() + 1); } else { this.fileName = inputClass.getName().substring(inputClass.getPackage().getName().length() + 1) .replace('$', '.'); } } else { this.fileName = canonicalName; this.pkg = null; } }