List of usage examples for java.lang Class getPackage
public Package getPackage()
From source file:org.codehaus.enunciate.modules.xfire_client.EnunciatedClientOperationBinding.java
/** * Loads the set of output properties for the specified operation. * * @param op The operation./*from www . ja va 2s . co m*/ * @return The output properties. */ protected OperationBeanInfo getResponseInfo(OperationInfo op) throws XFireFault { Method method = op.getMethod(); Class ei = method.getDeclaringClass(); Package pckg = ei.getPackage(); if ((this.annotations.hasSOAPBindingAnnotation(method)) && (this.annotations.getSOAPBindingAnnotation(method) .getParameterStyle() == SOAPBindingAnnotation.PARAMETER_STYLE_BARE)) { //bare method... return new OperationBeanInfo(method.getReturnType(), null); } else { String responseWrapperClassName; ResponseWrapperAnnotation responseWrapperInfo = annotations.getResponseWrapperAnnotation(method); if ((responseWrapperInfo != null) && (responseWrapperInfo.className() != null) && (responseWrapperInfo.className().length() > 0)) { responseWrapperClassName = responseWrapperInfo.className(); } else { StringBuffer builder = new StringBuffer(pckg == null ? "" : pckg.getName()); if (builder.length() > 0) { builder.append("."); } builder.append("jaxws."); String methodName = method.getName(); builder.append(PropertyUtil.capitalize(methodName)).append("Response"); responseWrapperClassName = builder.toString(); } Class wrapperClass; try { wrapperClass = ClassLoaderUtils.loadClass(responseWrapperClassName, getClass()); } catch (ClassNotFoundException e) { LOG.debug("Unabled to find response wrapper class " + responseWrapperClassName + "... Operation " + op.getQName() + " will not be able to recieve..."); return null; } return new OperationBeanInfo(wrapperClass, loadOrderedProperties(wrapperClass)); } }
From source file:de.fu_berlin.inf.dpp.misc.pico.DotGraphMonitor.java
private String printClassName(final Class<?> clazz) { String className = clazz.getName(); return "'" + className.substring(className.lastIndexOf(".") + 1) + "\\n" + clazz.getPackage().getName() + "'"; }
From source file:de.escalon.hypermedia.hydra.serialize.JacksonHydraSerializer.java
private Map<String, Object> getTerms(Object bean, Class<?> mixInClass) throws IntrospectionException, IllegalAccessException, NoSuchFieldException { // define terms from package or type in context final Class<?> beanClass = bean.getClass(); Map<String, Object> termsMap = getAnnotatedTerms(beanClass.getPackage(), beanClass.getPackage().getName()); Map<String, Object> classTermsMap = getAnnotatedTerms(beanClass, beanClass.getName()); Map<String, Object> mixinTermsMap = getAnnotatedTerms(mixInClass, beanClass.getName()); // class terms override package terms termsMap.putAll(classTermsMap);//from w w w . j ava 2s . com // mixin terms override class terms termsMap.putAll(mixinTermsMap); final Field[] fields = beanClass.getDeclaredFields(); for (Field field : fields) { final Expose fieldExpose = field.getAnnotation(Expose.class); if (Enum.class.isAssignableFrom(field.getType())) { Map<String, String> map = new LinkedHashMap<String, String>(); termsMap.put(field.getName(), map); if (fieldExpose != null) { map.put(AT_ID, fieldExpose.value()); } map.put(AT_TYPE, AT_VOCAB); final Enum value = (Enum) field.get(bean); final Expose enumValueExpose = getAnnotation(value.getClass().getField(value.name()), Expose.class); // TODO redefine actual enum value to exposed on enum value definition if (enumValueExpose != null) { termsMap.put(value.toString(), enumValueExpose.value()); } else { // might use upperToCamelCase if nothing is exposed final String camelCaseEnumValue = WordUtils .capitalizeFully(value.toString(), new char[] { '_' }).replaceAll("_", ""); termsMap.put(value.toString(), camelCaseEnumValue); } } else { if (fieldExpose != null) { termsMap.put(field.getName(), fieldExpose.value()); } } } // TODO do this recursively for nested beans and collect as long as // nested beans have same vocab // expose getters in context final BeanInfo beanInfo = Introspector.getBeanInfo(beanClass); final PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors(); for (PropertyDescriptor propertyDescriptor : propertyDescriptors) { final Method method = propertyDescriptor.getReadMethod(); final Expose expose = method.getAnnotation(Expose.class); if (expose != null) { termsMap.put(propertyDescriptor.getName(), expose.value()); } } return termsMap; }
From source file:org.tangram.view.AbstractTemplateResolver.java
/** * @throws IOException - in subclasses not this one *//*from w w w . j a v a 2 s.c om*/ protected T lookupView(String viewName, Locale locale, Object content, String key) throws IOException { Class<? extends Object> cls = content.getClass(); T view = null; Set<String> alreadyChecked = new HashSet<>(); List<Object> allInterfaces = new ArrayList<>(); while ((view == null) && (cls != null)) { String pack = (cls.getPackage() == null) ? "" : cls.getPackage().getName(); view = checkView(viewName, pack, cls.getSimpleName(), key, locale); if (view == null) { for (Object i : ClassUtils.getAllInterfaces(cls)) { if (allInterfaces.contains(i)) { allInterfaces.remove(i); } // if } // for for (Object i : ClassUtils.getAllInterfaces(cls)) { allInterfaces.add(i); } // for } // if cls = cls.getSuperclass(); } // while // Walk down interfaces if (view == null) { for (Object i : allInterfaces) { Class<? extends Object> c = (Class<? extends Object>) i; LOG.debug("lookupView() type to check templates for {}", c.getName()); if (!(alreadyChecked.contains(c.getName()))) { alreadyChecked.add(c.getName()); String interfacePackage = (c.getPackage() == null) ? "" : c.getPackage().getName(); view = checkView(viewName, interfacePackage, c.getSimpleName(), key, locale); if (view != null) { break; } // if } // if } // for } // if return view; }
From source file:com.phoenixnap.oss.ramlapisync.javadoc.JavaDocExtractor.java
/** * Extracts the Java Doc for a specific class from its Source code as well as any superclasses or implemented * interfaces.// w ww.j a va 2 s . com * * @param clazz The Class for which to get javadoc * @return A parsed documentation store with the class's Javadoc or empty if none is found. */ public JavaDocStore getJavaDoc(Class<?> clazz) { if (clazz.isArray()) { clazz = clazz.getComponentType(); } // we need to start off from some base directory if (baseDir == null || clazz.isPrimitive()) { return new JavaDocStore(); } String classPackage = clazz.getPackage() == null ? "" : clazz.getPackage().getName(); // lets eliminate some stardard stuff if (classPackage.startsWith("java") || (classPackage.startsWith("org") && (classPackage.startsWith("org.hibernate") || classPackage.startsWith("org.raml") || classPackage.startsWith("org.springframework")))) { return new JavaDocStore(); } if (javaDocCache.containsKey(clazz)) { return javaDocCache.get(clazz); } logger.debug("Getting Javadoc for: " + clazz.getSimpleName()); JavaDocStore javaDoc = new JavaDocStore(); try { File file = FileSearcher.fileSearch(baseDir, clazz); if (file != null) { logger.debug("Found: " + file.getAbsolutePath()); FileInputStream in = new FileInputStream(file); CompilationUnit cu; try { // parse the file cu = JavaParser.parse(in); } finally { in.close(); } // visit and print the class docs names new ClassVisitor(javaDoc).visit(cu, null); // visit and print the methods names new MethodVisitor(javaDoc).visit(cu, null); // visit and print the field names new FieldVisitor(javaDoc).visit(cu, null); } else { logger.warn("*** WARNING: Missing Source for: " + clazz.getSimpleName() + ". JavaDoc Unavailable."); } } catch (Exception ex) { logger.error(ex.getMessage(), ex); } // After we complete this class, we need to check its parents and interfaces to extract as much documentation as // possible if (clazz.getInterfaces() != null && clazz.getInterfaces().length > 0) { for (Class<?> interfaceClass : clazz.getInterfaces()) { javaDoc.merge(getJavaDoc(interfaceClass)); } } if (clazz.getSuperclass() != null && !clazz.getSuperclass().equals(Object.class)) { javaDoc.merge(getJavaDoc(clazz.getSuperclass())); } javaDocCache.put(clazz, javaDoc); return javaDoc; }
From source file:org.androidtransfuse.adapter.ASTEquivalenceTest.java
@Test public void example() throws ClassNotFoundException { TestCompiler compiler = new TestCompiler(); String className = "example.test.TestClass"; String source = "package example.test; public class TestClass{}"; compiler.add(className, source);//from ww w . ja v a2 s .com compiler.compile(); byte[] byteCode = compiler.getByteCode(className); Class<?> aClass = Class.forName(className, true, new SimpleClassLoader(className, byteCode)); assertEquals("example.test", aClass.getPackage().getName()); assertEquals("TestClass", aClass.getSimpleName()); }
From source file:org.brushingbits.jnap.struts2.config.RestControllerConfigBuilder.java
@Override protected void buildConfiguration(Set<Class> classes) { Map<String, PackageConfig.Builder> packageConfigs = new HashMap<String, PackageConfig.Builder>(); for (Class controllerClass : classes) { // Determine the controller package String controllerPackage = controllerClass.getPackage().getName(); if (LOG.isDebugEnabled()) { LOG.debug("Processing class [#0] in package [#1]", controllerClass.getName(), controllerPackage); }// w w w. j ava 2s .c o m String namespace = determineControllerNamespace(controllerClass); String actionName = determineActionName(controllerClass); PackageConfig.Builder defaultPackageConfig = getPackageConfig(packageConfigs, namespace, controllerPackage, controllerClass, null); Map<String, ActionMethodConfigBean> methods = findActionMethods(controllerClass); for (Iterator<String> iter = methods.keySet().iterator(); iter.hasNext();) { String methodName = iter.next(); ActionMethodConfigBean method = methods.get(methodName); method.setNamespace(namespace); method.setActionName(actionName); createActionConfig(defaultPackageConfig, controllerClass, method); } } // Add the new actions to the configuration Set<String> packageNames = packageConfigs.keySet(); for (String packageName : packageNames) { configuration.addPackageConfig(packageName, packageConfigs.get(packageName).build()); } }
From source file:org.xulux.dataprovider.bean.BeanDataProvider.java
/** * @param clazz the class/* ww w .j a v a 2s . c o m*/ * @return the plaing bean name for the specified class */ public String getPlainBeanName(Class clazz) { int pLength = clazz.getPackage().getName().length(); String mapName = clazz.getName().substring(pLength + 1); return mapName; }
From source file:org.beangle.struts2.convention.config.SmartActionConfigBuilder.java
protected PackageConfig.Builder getPackageConfig(Profile profile, final Map<String, PackageConfig.Builder> packageConfigs, Action action, final Class<?> actionClass) { // // w w w . j a v a2 s . c om String actionPkg = actionClass.getPackage().getName(); PackageConfig parentPkg = null; while (StringUtils.contains(actionPkg, '.')) { parentPkg = configuration.getPackageConfig(actionPkg); if (null != parentPkg) { break; } else { actionPkg = StringUtils.substringBeforeLast(actionPkg, "."); } } if (null == parentPkg) { actionPkg = defaultParentPackage; parentPkg = configuration.getPackageConfig(actionPkg); } if (parentPkg == null) { throw new ConfigurationException( "Unable to locate parent package [" + actionClass.getPackage().getName() + "]"); } String actionPackage = actionClass.getPackage().getName(); PackageConfig.Builder pkgConfig = packageConfigs.get(actionPackage); if (pkgConfig == null) { PackageConfig myPkg = configuration.getPackageConfig(actionPackage); if (null != myPkg) { pkgConfig = new PackageConfig.Builder(myPkg); } else { pkgConfig = new PackageConfig.Builder(actionPackage).namespace(action.getNamespace()) .addParent(parentPkg); logger.debug("Created package config named {} with a namespace {}", actionPackage, action.getNamespace()); } packageConfigs.put(actionPackage, pkgConfig); } return pkgConfig; }
From source file:org.apache.axis2.jaxws.client.dispatch.JAXBDispatch.java
public Message createMessageFromValue(Object value) { Message message = null;//from w w w .j av a 2s. c o m if (value == null) { if (log.isDebugEnabled()) { log.debug("Dispatch invoked with null parameter Value"); log.debug("creating empty soap message"); } try { return createEmptyMessage(Protocol.getProtocolForBinding(endpointDesc.getClientBindingID())); } catch (XMLStreamException e) { throw ExceptionFactory.makeWebServiceException(e); } } try { JAXBBlockFactory factory = (JAXBBlockFactory) FactoryRegistry.getFactory(JAXBBlockFactory.class); Class clazz = value.getClass(); JAXBBlockContext context = null; if (jaxbContext != null) { context = new JAXBBlockContext(jaxbContext); } else { context = new JAXBBlockContext(clazz.getPackage().getName()); } // The protocol of the Message that is created should be based // on the binding information available. Protocol proto = Protocol.getProtocolForBinding(endpointDesc.getClientBindingID()); // Create a block from the value elementQName = XMLRootElementUtil.getXmlRootElementQNameFromObject(value); Block block = factory.createFrom(value, context, elementQName); MessageFactory mf = (MessageFactory) FactoryRegistry.getFactory(MessageFactory.class); if (mode.equals(Mode.PAYLOAD)) { // Normal case message = mf.create(proto); message.setBodyBlock(block); } else { // Message mode..rare case // Create Message from block message = mf.createFrom(block, null, proto); } } catch (Exception e) { throw ExceptionFactory.makeWebServiceException(e); } return message; }