@Override public void destroy() { MethodIdentifier mi = new MethodIdentifier(portletName, "", MethodType.DESTROY); List<AnnotatedMethod> meths = getMethods(mi); if (meths.size() == 0) { // If no init method, log debug trace and return if (isDebug) { StringBuilder txt = new StringBuilder(128); txt.append("Destroy method not found for portlet: ").append(portletName); LOG.debug(txt.toString()); } return; } assert meths.size() == 1; AnnotatedMethod meth = meths.get(0); // Set up the method arguments and do the incovation Object[] args = new Object[] {}; try { invokePortletMethod(meth, args); } catch (Exception e) { } }
@Override public boolean equals(Object o) { boolean eq = false; if (o instanceof MethodIdentifier) { if (o == this) { eq = true; } else { MethodIdentifier mi = (MethodIdentifier) o; if (equals(portletName, mi.portletName)) { if (equals(type, mi.type)) { if (equals(dispatchId, mi.dispatchId)) { eq = true; } } } } } return eq; }
/** * Returns a list of methods to be invoked for the given method identifier. * * @param mi * The method identifier * @return A list of methods. may be empty. */ private List<AnnotatedMethod> getMethods(MethodIdentifier mi) { // get the method from the store. If the requested method cannot // be found, // retry with the default dispatch ID (""). if (isDebug) { LOG.debug("Retrieving method for method identifier: " + mi.toString()); } List<AnnotatedMethod> meths = methodStore.getMethods(mi); if (meths.isEmpty()) { Object id = mi.getId(); if ((id != null) && (id instanceof String) && ((String) id).length() > 0) { mi.setId(""); if (isDebug) { LOG.debug("Retrying retrieval with method identifier: " + mi.toString()); } meths = methodStore.getMethods(mi); } } return meths; }
if (mi.getType() == ACTION && am.getAnnotation() != null) { ActionMethod anno = (ActionMethod) am.getAnnotation(); for (PortletQName pqn : anno.publishingEvents()) { } else if (mi.getType() == EVENT && am.getAnnotation() != null) { EventMethod anno = (EventMethod) am.getAnnotation(); for (PortletQName pqn : anno.publishingEvents()) { if (mi.getType() == EVENT && procqns.size() > 0) { List<QName> qns = procEvtRefs.get(mi.getName()); if (qns != null) { EventMethod anno = (EventMethod) am.getAnnotation(); StringBuilder txt = new StringBuilder(128); txt.append("Duplicate processing event QName. Portlet name: "); txt.append(mi.getName()); 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()); return false; StringBuilder txt = new StringBuilder(128); txt.append("Missing processing event QName. Portlet name: "); txt.append(mi.getName()); txt.append(", Annotation: @EventMethod"); txt.append(", Class: ").append(am.getJavaMethod().getDeclaringClass().getCanonicalName());
assert (mi.getType() == EVENT) && (mi.getId() instanceof QName); QName oldqn = (QName) mi.getId(); assert oldqn.getNamespaceURI().equals(XMLConstants.NULL_NS_URI); QName newqn = new QName(ns, oldqn.getLocalPart()); MethodIdentifier newmi = new MethodIdentifier(mi); newmi.setId(newqn);
if (mi.getType() == MethodType.RENDER) { String mode = (String) mi.getId(); if (mode.equalsIgnoreCase("view") || mode.equalsIgnoreCase("help") || mode.equalsIgnoreCase("edit")) { List<AnnotatedMethod> meths = ams.getMethods(mi); if (mi.getType() == MethodType.RESOURCE) { List<AnnotatedMethod> meths = ams.getMethods(mi); for (AnnotatedMethod meth : meths) { MethodIdentifier mi = new MethodIdentifier(pd.getPortletName(), qn, MethodType.EVENT); ams.removeMethod(mi); am = getMethod(cls, "init", METH_INI); if (am != null) { MethodIdentifier mi = new MethodIdentifier(pd.getPortletName(), "", MethodType.INIT); if (ams.getMethods(mi).size() == 0) { ams.addMethod(mi, am); MethodIdentifier mi = new MethodIdentifier(pd.getPortletName(), "", MethodType.DESTROY); if (ams.getMethods(mi).size() == 0) { ams.addMethod(mi, am); MethodIdentifier mi = new MethodIdentifier(pd.getPortletName(), "", MethodType.ACTION); if (ams.getMethods(mi).size() == 0) { ams.addMethod(mi, am); MethodIdentifier mi = new MethodIdentifier(pd.getPortletName(), "", MethodType.EVENT); if (ams.getMethods(mi).size() == 0) { ams.addMethod(mi, am);
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()); list = null;
@Override public void processEvent(EventRequest req, EventResponse resp) throws PortletException, IOException { QName qn = req.getEvent().getQName(); MethodIdentifier mi = new MethodIdentifier(portletName, qn, MethodType.EVENT); List<AnnotatedMethod> meths = getMethods(mi); if (meths.size() == 0) { // retry with empty string (for portlet class processEvent method, for // example) mi.setId(""); meths = getMethods(mi); if (meths.size() == 0) { // If an event to be processed, but event method could not be found, // add appropriate error string. StringBuilder txt = new StringBuilder(128); txt.append("Event method not found. Event qname=").append(qn); LOG.warn(txt.toString()); return; } } assert meths.size() == 1; AnnotatedMethod meth = meths.get(0); // Set up the method arguments and do the incovation Object[] args = new Object[] { req, resp }; invokePortletMethod(meth, args); }
/** * Returns the stored methods for the given portlet name. * * @param portletName The portlet name * @return Set of method identifiers. The Set is empty if there are no * methods available */ public Set<MethodIdentifier> getMethodIDsForPortlet(String portletName) { Set<MethodIdentifier> meths = new HashSet<MethodIdentifier>(); for (MethodIdentifier mi : methods.keySet()) { if (mi.getName().equals(portletName)) { meths.add(mi); } } return meths; }
/** * 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(); }
/** * Removes the stored methods for the given portlet name. * * @param portletName The portlet name */ public void removeMethodsForPortlet(String portletName) { Set<MethodIdentifier> meths = new HashSet<MethodIdentifier>(); for (MethodIdentifier mi : methods.keySet()) { if (mi.getName().equals(portletName)) { meths.add(mi); } } for (MethodIdentifier mi : meths) { methods.remove(mi); } portletNames.remove(portletName); }
/** * 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; }
@Override public void init(PortletConfig config) throws PortletException { this.config = config; MethodIdentifier mi = new MethodIdentifier(portletName, "", MethodType.INIT); List<AnnotatedMethod> meths = getMethods(mi); if (meths.size() == 0) { // If no init method, log debug trace and return if (isDebug) { StringBuilder txt = new StringBuilder(128); txt.append("Init method not found for portlet: ").append(portletName); LOG.debug(txt.toString()); } return; } assert meths.size() == 1; AnnotatedMethod meth = meths.get(0); // Set up the method arguments and do the invocation Object[] args = new Object[] { config }; try { invokePortletMethod(meth, args); } catch (Throwable t) { throw new PortletException("Portlet could not be initialized.", t); } }
@Override public void processAction(ActionRequest req, ActionResponse resp) throws PortletException, IOException { String an = req.getActionParameters().getValue(ACTION_NAME); String id = (an != null) ? an : ""; MethodIdentifier mi = new MethodIdentifier(portletName, id, MethodType.ACTION); List<AnnotatedMethod> meths = getMethods(mi); if (meths.size() == 0) { // If an action URL was activated, but action method could not be // found, // add appropriate error string. StringBuilder txt = new StringBuilder(128); txt.append("Action method not found. Action name=\"").append(an).append("\""); LOG.warn(txt.toString()); return; } assert meths.size() == 1; AnnotatedMethod meth = meths.get(0); // Set up the method arguments and do the incovation Object[] args = new Object[] { req, resp }; invokePortletMethod(meth, args); }
MethodIdentifier mi = new MethodIdentifier(portletName, dispatchId, type); ams.addMethod(mi, pm);
MethodIdentifier mi = new MethodIdentifier(portletName, id, MethodType.RENDER);
MethodIdentifier mi = new MethodIdentifier(portletName, id, MethodType.RESOURCE);
MethodIdentifier mi = new MethodIdentifier(portletName, id, MethodType.HEADER);