/** * 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()); } }
/** * 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); }
/** * 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; }
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());
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());