| 1 |
/* |
|---|
| 2 |
* (C) Copyright 2007 Nuxeo SAS (http://nuxeo.com/) and contributors. |
|---|
| 3 |
* |
|---|
| 4 |
* All rights reserved. This program and the accompanying materials |
|---|
| 5 |
* are made available under the terms of the GNU Lesser General Public License |
|---|
| 6 |
* (LGPL) version 2.1 which accompanies this distribution, and is available at |
|---|
| 7 |
* http://www.gnu.org/licenses/lgpl.html |
|---|
| 8 |
* |
|---|
| 9 |
* This library is distributed in the hope that it will be useful, |
|---|
| 10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|---|
| 12 |
* Lesser General Public License for more details. |
|---|
| 13 |
* |
|---|
| 14 |
* Contributors: |
|---|
| 15 |
* Nuxeo - initial API and implementation |
|---|
| 16 |
* |
|---|
| 17 |
* $Id$ |
|---|
| 18 |
*/ |
|---|
| 19 |
|
|---|
| 20 |
package org.nuxeo.ecm.platform.ui.web.binding; |
|---|
| 21 |
|
|---|
| 22 |
import java.io.Serializable; |
|---|
| 23 |
|
|---|
| 24 |
import javax.faces.application.Application; |
|---|
| 25 |
import javax.faces.context.FacesContext; |
|---|
| 26 |
import javax.faces.el.MethodBinding; |
|---|
| 27 |
|
|---|
| 28 |
import org.apache.commons.logging.Log; |
|---|
| 29 |
import org.apache.commons.logging.LogFactory; |
|---|
| 30 |
import org.nuxeo.ecm.platform.ui.web.util.ComponentTagUtils; |
|---|
| 31 |
|
|---|
| 32 |
/** |
|---|
| 33 |
* Meta method binding, used to invoke the EL expression that is already the |
|---|
| 34 |
* result of a method binding. |
|---|
| 35 |
* <p> |
|---|
| 36 |
* For instance it is useful to use this binding to provide action links defined |
|---|
| 37 |
* in NXActions extensions with links like |
|---|
| 38 |
* #{documentAction.createDocument('Domain')}. |
|---|
| 39 |
* <p> |
|---|
| 40 |
* There is no more than one level of abstraction: |
|---|
| 41 |
* <ul> |
|---|
| 42 |
* <li> the binding method value can be a standard method binding (with |
|---|
| 43 |
* parameters or not) ; |
|---|
| 44 |
* <li> the binding method value can result in another binding method value |
|---|
| 45 |
* after being invoke, in which case it is reinvoked again using the same |
|---|
| 46 |
* context ; |
|---|
| 47 |
* <li> no further method invoking will be performed. |
|---|
| 48 |
* </ul> |
|---|
| 49 |
* |
|---|
| 50 |
* @author <a href="mailto:at@nuxeo.com">Anahide Tchertchian</a> |
|---|
| 51 |
* @Deprecated use {@link MetaMethodExpression} |
|---|
| 52 |
*/ |
|---|
| 53 |
@Deprecated |
|---|
| 54 |
public class MetaMethodBinding extends MethodBinding implements Serializable { |
|---|
| 55 |
|
|---|
| 56 |
private static final long serialVersionUID = -2721042412903607760L; |
|---|
| 57 |
|
|---|
| 58 |
private static final Log log = LogFactory.getLog(MetaMethodBinding.class); |
|---|
| 59 |
|
|---|
| 60 |
private final MethodBinding originalMethodBinding; |
|---|
| 61 |
|
|---|
| 62 |
public MetaMethodBinding(MethodBinding originalMethodBinding) { |
|---|
| 63 |
this.originalMethodBinding = originalMethodBinding; |
|---|
| 64 |
} |
|---|
| 65 |
|
|---|
| 66 |
@Override |
|---|
| 67 |
public Class getType(FacesContext facesContext) { |
|---|
| 68 |
// assume String is returned |
|---|
| 69 |
return String.class; |
|---|
| 70 |
} |
|---|
| 71 |
|
|---|
| 72 |
@Override |
|---|
| 73 |
public Object invoke(FacesContext context, Object[] params) { |
|---|
| 74 |
Object res = null; |
|---|
| 75 |
if (originalMethodBinding != null) { |
|---|
| 76 |
res = originalMethodBinding.invoke(context, params); |
|---|
| 77 |
if (res instanceof String) { |
|---|
| 78 |
MethodBinding newMeth; |
|---|
| 79 |
String expression = (String) res; |
|---|
| 80 |
if (ComponentTagUtils.isValueReference(expression)) { |
|---|
| 81 |
Application app = context.getApplication(); |
|---|
| 82 |
newMeth = app.createMethodBinding(expression, null); |
|---|
| 83 |
} else { |
|---|
| 84 |
newMeth = new ActionMethodBinding(expression); |
|---|
| 85 |
} |
|---|
| 86 |
if (newMeth != null) { |
|---|
| 87 |
//try { |
|---|
| 88 |
res = newMeth.invoke(context, null); |
|---|
| 89 |
/*} catch (Exception err) { |
|---|
| 90 |
log.error(String.format( |
|---|
| 91 |
"Error processing action expression %s: %s", |
|---|
| 92 |
expression, err)); |
|---|
| 93 |
res = null; |
|---|
| 94 |
}*/ |
|---|
| 95 |
} |
|---|
| 96 |
} |
|---|
| 97 |
} |
|---|
| 98 |
return res; |
|---|
| 99 |
} |
|---|
| 100 |
|
|---|
| 101 |
} |
|---|