/** * helper method for extracting the portlet methods from the portlet class. * * @param cls * @param name * @param md * @return */ private AnnotatedMethod getMethod(Class<?> cls, String name, MethodDescription md) { AnnotatedMethod am = null; try { Method meth = cls.getMethod(name, md.getArgTypes()); am = new AnnotatedMethod(cls, null, meth, md); } catch (Exception e) { if (isDebug) { StringBuilder txt = new StringBuilder(); txt.append("Could not retrieve method from portlet class."); txt.append(" Method name: ").append(name); txt.append(", Class: ").append(cls.getCanonicalName()); txt.append(", Argument types: ").append(md.getArgTypes()); LOG.debug(txt.toString()); } } return am; }
/** * Activate the methods by providing them with a bean manager. * Sort the method lists for the method types that can have multiple * entries. * * @param bm */ public void activateMethods(BeanManager bm) { beanMgr = bm; Collection<List<AnnotatedMethod>> methlists = methods.values(); for (List<AnnotatedMethod> list : methlists) { Collections.sort(list, new AnnotatedMethodComparator()); for (AnnotatedMethod meth : list) { meth.activate(bm); } } }
/** * Sets the bean instance for all annotated methods for a given portlet that are members of * a configured portlet class to ensure that all annotated methods of the portlet class use * the same bean instance. * * @param portletName The portlet name * @param cls The class * @param beanInstance The instance to use */ public void setPortletClassInstance(String portletName, Class<?> cls, Object beanInstance) { for (MethodIdentifier mi : getMethodIDsForPortlet(portletName)) { List<AnnotatedMethod> list = methods.get(mi); for (AnnotatedMethod am : list) { if (am.getBeanClass().equals(cls)) { am.setPortletClassInstance(beanInstance); } } } }
/** * Returns the annotated method for a given identifier. * * It's a programming error if this method is used when multiple methods could be expected. * * @param mi The method identifier * @return The annotated method, or <code>null</code> if none was found. */ public AnnotatedMethod getMethod(MethodIdentifier mi) { AnnotatedMethod pm = null; List<AnnotatedMethod> list = methods.get(mi); if (list != null) { assert list.size() == 1; assert !list.get(0).getDescription().isAllowMultiple(); pm = list.get(0); } if (isTrace) { StringBuilder txt = new StringBuilder(128); txt.append("Retrieved annotated method for: ").append(mi.toString()); txt.append(", Method: ").append(pm == null ? "null" : pm.toString()); LOG.trace(txt.toString()); } return pm; }
result = meth.invoke(args); } catch (InvocationTargetException ite) { Throwable t = ite.getCause(); String msg = "Problem invoking " + meth.toString() + ". Unknown InvocationTargetException Cause. "; throw new PortletException(msg, ite); } catch (RuntimeException re) { throw re; } catch (Exception e) { String msg = "Problem invoking " + meth.toString() + ". "; throw new PortletException(msg + e.getMessage());
return; LOG.debug("Processing async dispatch. method: " + meth.toString()); meths.add(meth); } else { ServeResourceMethod rm = (ServeResourceMethod) meth.getAnnotation(); if (rm != null) { if (rm.characterEncoding().length() > 0) { if (meth.getDescription().getVariant() == SignatureVariant.VOID_RESOURCEREQ_RESOURCERESP) { args = new Object[] { req, resp }; LOG.debug("Async processing was started during method: " + meth.toString()); req.setAttribute(PortletInvokerService.ASYNC_METHOD, meth); break; if (meth.getDescription().getVariant() == SignatureVariant.STRING_VOID) { if (result != null) { assert result instanceof String;
HeaderMethod hm = (HeaderMethod) meth.getAnnotation(); if ((hm != null) && !hm.contentType().matches("(^$|\\*|\\*/\\*|text/\\*)")) { resp.setContentType(hm.contentType()); if (meth.getDescription().getVariant() == SignatureVariant.VOID_HEADERREQ_HEADERRESP) { args = new Object[] { req, resp }; if (meth.getDescription().getVariant() == SignatureVariant.STRING_VOID) { if (result != null) { assert result instanceof String;
if (mi.getType() == ACTION && am.getAnnotation() != null) { ActionMethod anno = (ActionMethod) am.getAnnotation(); for (PortletQName pqn : anno.publishingEvents()) { String uri = pqn.namespaceURI().trim(); pubqns.add(qn); } else if (mi.getType() == EVENT && am.getAnnotation() != null) { EventMethod anno = (EventMethod) am.getAnnotation(); for (PortletQName pqn : anno.publishingEvents()) { String uri = pqn.namespaceURI().trim(); EventMethod anno = (EventMethod) am.getAnnotation(); for (PortletQName pqn : anno.processingEvents()) { QName qn = new QName(pqn.namespaceURI(), pqn.localPart()); txt.append(", QName: ").append(qn); txt.append(", Annotation: @EventMethod"); txt.append(", Class: ").append(am.getJavaMethod().getDeclaringClass().getCanonicalName()); summary.addErrorString(mi.getName(), txt.toString()); LOG.warn(txt.toString()); txt.append(mi.getName()); txt.append(", Annotation: @EventMethod"); txt.append(", Class: ").append(am.getJavaMethod().getDeclaringClass().getCanonicalName()); summary.addErrorString(mi.getName(), txt.toString()); LOG.warn(txt.toString());
/** * The annotated method is activated by using the specified BeanManager to * obtain a reference to a bean that can be used for method invocation. * * @param bm The BeanManager, may be null if non-bean class */ public void activate(BeanManager bm) { beanMgr = bm; if (bm != null) { Set<Bean<?>> beans = bm.getBeans(beanClass); bean = bm.resolve(beans); assert bean != null; } if (isTrace) { StringBuilder txt = new StringBuilder(128); txt.append("ID: ").append(toString()); txt.append(", beanMgr == null?: ").append(beanMgr == null); txt.append(", bean == null?: ").append(bean == null); LOG.trace(txt.toString()); } }
@Override public int compare(AnnotatedMethod o1, AnnotatedMethod o2) { assert (o1 != null) && (o2 != null); return Integer.compare(o1.getOrdinal(), o2.getOrdinal()); }
Class<?> cls = am.getBeanClass(); if (!processedClasses.contains(cls)) { processedClasses.add(cls);
List<AnnotatedMethod> meths = ams.getMethods(mi); for (AnnotatedMethod meth : meths) { RenderMethod rm = (RenderMethod) meth.getAnnotation(); String mimeType = "*/*"; if (rm != null) { List<AnnotatedMethod> meths = ams.getMethods(mi); for (AnnotatedMethod meth : meths) { ServeResourceMethod srm = (ServeResourceMethod) meth.getAnnotation(); if (srm != null && srm.asyncSupported()) { pd.setAsyncSupported(true);
if (!am.getDescription().isAllowMultiple()) { StringBuilder txt = new StringBuilder(128); txt.append("Duplicate method specification. Method identifier: "); txt.append(mi.toString()); txt.append(" / Method 1: ").append(list.get(0).toString()); txt.append(" / Method 2: ").append(am.toString()); summary.addErrorString(mi.getName(), txt.toString()); LOG.warn("Disallowed duplicate entry: " + mi.toString());
RenderMethod rm = (RenderMethod) meth.getAnnotation(); if ((rm != null) && !rm.contentType().matches("(^$|\\*|\\*/\\*|text/\\*)")) { resp.setContentType(rm.contentType()); if (meth.getDescription().getVariant() == SignatureVariant.VOID_RENDERREQ_RENDERRESP) { args = new Object[] { req, resp }; if (meth.getDescription().getVariant() == SignatureVariant.STRING_VOID) { if (result != null) { assert result instanceof String;
/** * Returns a String representation of the stored methods. * * @return String */ public String getMethodsAsString() { List<MethodIdentifier> meths = new ArrayList<MethodIdentifier>(); meths.addAll(methods.keySet()); Collections.sort(meths, new MethodIdentifierComparator()); StringBuilder txt = new StringBuilder(256); txt.append("Stored methods: "); for (MethodIdentifier mi : meths) { txt.append("\n\t").append(mi.toString()); for (AnnotatedMethod pm : methods.get(mi)) { txt.append("\n\t\t").append(pm.toString()); } } return txt.toString(); }
/** * Invoke the method with the arguments provided. It is expected that this method is called * is called by a proxy or facade for the method / class. * * @param args Arguments * @return Object returned by method * @throws IllegalAccessException * @throws IllegalArgumentException * @throws InvocationTargetException */ public Object invoke(Object... args) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException { if (!isPortletClass) { // get the reference for beans other than portlet classes in order to respect the // scope of the bean. if (isTrace) { StringBuilder txt = new StringBuilder(); txt.append("ID: ").append(toString()); txt.append(", beanMgr == null?").append(beanMgr == null); txt.append(", bean == null?").append(bean == null); LOG.trace(txt.toString()); } beanInstance = beanMgr.getReference(bean, bean.getBeanClass(), beanMgr.createCreationalContext(bean)); } return meth.invoke(beanInstance, args); }
AnnotatedMethod pm = new AnnotatedMethod(anno, beanClass, meth, desc); for (String portletName : portletNames) {