You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lu...@apache.org on 2010/11/04 23:24:59 UTC
svn commit: r1031298 - in
/myfaces/commons/branches/jsf_11/myfaces-commons-converters: ./
src/main/java/org/apache/myfaces/commons/converter/
src/main/resources/META-INF/
Author: lu4242
Date: Thu Nov 4 22:24:59 2010
New Revision: 1031298
URL: http://svn.apache.org/viewvc?rev=1031298&view=rev
Log:
MFCOMMONS-12 Add ConverterBase class to allow create converters that evaluate EL expressions at render time
Added:
myfaces/commons/branches/jsf_11/myfaces-commons-converters/src/main/java/org/apache/myfaces/commons/converter/ConverterBase.java
myfaces/commons/branches/jsf_11/myfaces-commons-converters/src/main/java/org/apache/myfaces/commons/converter/ConverterBaseTag.java
myfaces/commons/branches/jsf_11/myfaces-commons-converters/src/main/java/org/apache/myfaces/commons/converter/ConverterBaseTagHandler.java
myfaces/commons/branches/jsf_11/myfaces-commons-converters/src/main/java/org/apache/myfaces/commons/converter/_AttachedListStateWrapper.java
myfaces/commons/branches/jsf_11/myfaces-commons-converters/src/main/java/org/apache/myfaces/commons/converter/_AttachedStateWrapper.java
myfaces/commons/branches/jsf_11/myfaces-commons-converters/src/main/java/org/apache/myfaces/commons/converter/_ConverterRule.java
myfaces/commons/branches/jsf_11/myfaces-commons-converters/src/main/resources/META-INF/converterClass11.vm
Modified:
myfaces/commons/branches/jsf_11/myfaces-commons-converters/pom.xml
myfaces/commons/branches/jsf_11/myfaces-commons-converters/src/main/resources/META-INF/tagConverterClass11.vm
Modified: myfaces/commons/branches/jsf_11/myfaces-commons-converters/pom.xml
URL: http://svn.apache.org/viewvc/myfaces/commons/branches/jsf_11/myfaces-commons-converters/pom.xml?rev=1031298&r1=1031297&r2=1031298&view=diff
==============================================================================
--- myfaces/commons/branches/jsf_11/myfaces-commons-converters/pom.xml (original)
+++ myfaces/commons/branches/jsf_11/myfaces-commons-converters/pom.xml Thu Nov 4 22:24:59 2010
@@ -56,6 +56,12 @@
</goals>
</execution>
<execution>
+ <id>make_converters</id>
+ <goals>
+ <goal>make-converters</goal>
+ </goals>
+ </execution>
+ <execution>
<id>make_converter_tags</id>
<goals>
<goal>make-converter-tags</goal>
Added: myfaces/commons/branches/jsf_11/myfaces-commons-converters/src/main/java/org/apache/myfaces/commons/converter/ConverterBase.java
URL: http://svn.apache.org/viewvc/myfaces/commons/branches/jsf_11/myfaces-commons-converters/src/main/java/org/apache/myfaces/commons/converter/ConverterBase.java?rev=1031298&view=auto
==============================================================================
--- myfaces/commons/branches/jsf_11/myfaces-commons-converters/src/main/java/org/apache/myfaces/commons/converter/ConverterBase.java (added)
+++ myfaces/commons/branches/jsf_11/myfaces-commons-converters/src/main/java/org/apache/myfaces/commons/converter/ConverterBase.java Thu Nov 4 22:24:59 2010
@@ -0,0 +1,332 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.commons.converter;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+
+import javax.faces.application.FacesMessage;
+import javax.faces.component.StateHolder;
+import javax.faces.context.FacesContext;
+import javax.faces.convert.Converter;
+import javax.faces.el.ValueBinding;
+
+import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFConverter;
+import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFProperty;
+import org.apache.myfaces.commons.util.MessageUtils;
+
+/**
+ * Base converter implementation for Apache MyFaces Commons Converters.
+ *
+ */
+@JSFConverter(
+ configExcluded = true,
+ evaluateELOnExecution = true,
+ tagClass = "org.apache.myfaces.commons.converter.ConverterBaseTag",
+ tagHandler = "org.apache.myfaces.commons.converter.ConverterBaseTagHandler")
+public abstract class ConverterBase implements StateHolder, Converter {
+
+ private String _summaryMessage = null;
+ private String _detailMessage = null;
+ private boolean _transient = false;
+
+ /**
+ * alternate conversion error summary message format string
+ *
+ * @return The summary message to be displayed
+ */
+ @JSFProperty
+ public String getSummaryMessage()
+ {
+ if (_summaryMessage != null) return _summaryMessage;
+ ValueBinding vb = getValueBinding("summaryMessage");
+ return vb != null ? getStringValue(getFacesContext(), vb) : null;
+ }
+
+ /**
+ *
+ * @param message The summary message to be displayed.
+ */
+ public void setSummaryMessage(String message) {
+ _summaryMessage = message;
+ }
+
+ /**
+ * alternate conversion error detail message format string
+ * (use 'message' and 'detailMessage' alternatively)
+ *
+ * @return The detail message.
+ */
+ @JSFProperty
+ public String getDetailMessage() {
+ if (_detailMessage != null) return _detailMessage;
+ ValueBinding vb = getValueBinding("detailMessage");
+ return vb != null ? getStringValue(getFacesContext(), vb) : null;
+ }
+
+ /**
+ *
+ * @param message The detail message to be displayed.
+ */
+ public void setDetailMessage(String message) {
+ _detailMessage = message;
+ }
+
+
+ /**
+ * @param context
+ */
+ public Object saveState(FacesContext context) {
+ Object[] state = new Object[3];
+ state[0] = _summaryMessage;
+ state[1] = _detailMessage;
+ state[2] = saveValueBindingMap(context);
+ return state;
+ }
+
+ public void restoreState(FacesContext context, Object state) {
+ Object[] values = (Object[]) state;
+ _summaryMessage = (String) values[0];
+ _detailMessage = (String) values[1];
+ restoreValueBindingMap(context, values[2]);
+ }
+
+ public boolean isTransient() {
+ return _transient;
+ }
+
+ public void setTransient(boolean newTransientValue) {
+ _transient = newTransientValue;
+ }
+
+ // Utility methods
+
+ /**
+ * @param defaultMessage The default message we would expect.
+ * @param args Arguments for parsing this message.
+ * @return FacesMessage
+ */
+ protected FacesMessage getFacesMessage(String defaultMessage, Object[] args) {
+ FacesMessage msg;
+
+ if (getSummaryMessage() == null && getDetailMessage() == null)
+ {
+ msg = MessageUtils.getMessage(FacesMessage.SEVERITY_ERROR, defaultMessage, args);
+ } else {
+ Locale locale = MessageUtils.getCurrentLocale();
+ String summaryText = MessageUtils.substituteParams(locale, getSummaryMessage(), args);
+ String detailText = MessageUtils.substituteParams(locale, getDetailMessage(), args);
+ msg = new FacesMessage(FacesMessage.SEVERITY_ERROR, summaryText, detailText);
+ }
+ return msg;
+ }
+
+ // --------------------- borrowed from UIComponentBase ------------
+
+ private Map _valueBindingMap = null;
+
+ public ValueBinding getValueBinding(String name)
+ {
+ if (name == null) throw new NullPointerException("name");
+ if (_valueBindingMap == null)
+ {
+ return null;
+ }
+ else
+ {
+ return (ValueBinding)_valueBindingMap.get(name);
+ }
+ }
+
+ public void setValueBinding(String name,
+ ValueBinding binding)
+ {
+ if (name == null) throw new NullPointerException("name");
+ if (_valueBindingMap == null)
+ {
+ _valueBindingMap = new HashMap();
+ }
+ _valueBindingMap.put(name, binding);
+ }
+
+ private Object saveValueBindingMap(FacesContext context)
+ {
+ if (_valueBindingMap != null)
+ {
+ int initCapacity = (_valueBindingMap.size() * 4 + 3) / 3;
+ HashMap stateMap = new HashMap(initCapacity);
+ for (Iterator it = _valueBindingMap.entrySet().iterator(); it.hasNext(); )
+ {
+ Map.Entry entry = (Map.Entry)it.next();
+ stateMap.put(entry.getKey(),
+ saveAttachedState(context, entry.getValue()));
+ }
+ return stateMap;
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ private void restoreValueBindingMap(FacesContext context, Object stateObj)
+ {
+ if (stateObj != null)
+ {
+ Map stateMap = (Map)stateObj;
+ int initCapacity = (stateMap.size() * 4 + 3) / 3;
+ _valueBindingMap = new HashMap(initCapacity);
+ for (Iterator it = stateMap.entrySet().iterator(); it.hasNext(); )
+ {
+ Map.Entry entry = (Map.Entry)it.next();
+ _valueBindingMap.put(entry.getKey(),
+ restoreAttachedState(context, entry.getValue()));
+ }
+ }
+ else
+ {
+ _valueBindingMap = null;
+ }
+ }
+
+ /**
+ * Serializes objects which are "attached" to this component but which are
+ * not UIComponent children of it. Examples are converter and listener
+ * objects. To be precise, it returns an object which implements
+ * java.io.Serializable, and which when serialized will persist the
+ * state of the provided object.
+ * <p>
+ * If the attachedObject is a List then every object in the list is saved
+ * via a call to this method, and the returned wrapper object contains
+ * a List object.
+ * <p>
+ * If the object implements StateHolder then the object's saveState is
+ * called immediately, and a wrapper is returned which contains both
+ * this saved state and the original class name. However in the case
+ * where the StateHolder.isTransient method returns true, null is
+ * returned instead.
+ * <p>
+ * If the object implements java.io.Serializable then the object is simply
+ * returned immediately; standard java serialization will later be used
+ * to store this object.
+ * <p>
+ * In all other cases, a wrapper is returned which simply stores the type
+ * of the provided object. When deserialized, a default instance of that
+ * type will be recreated.
+ */
+ public static Object saveAttachedState(FacesContext context,
+ Object attachedObject)
+ {
+ if (attachedObject == null) return null;
+ if (attachedObject instanceof List)
+ {
+ List lst = new ArrayList(((List)attachedObject).size());
+ for (Iterator it = ((List)attachedObject).iterator(); it.hasNext(); )
+ {
+ lst.add(saveAttachedState(context, it.next()));
+ }
+ return new _AttachedListStateWrapper(lst);
+ }
+ else if (attachedObject instanceof StateHolder)
+ {
+ if (((StateHolder)attachedObject).isTransient())
+ {
+ return null;
+ }
+ else
+ {
+ return new _AttachedStateWrapper(attachedObject.getClass(),
+ ((StateHolder)attachedObject).saveState(context));
+ }
+ }
+ else if (attachedObject instanceof Serializable)
+ {
+ return attachedObject;
+ }
+ else
+ {
+ return new _AttachedStateWrapper(attachedObject.getClass(), null);
+ }
+ }
+
+ public static Object restoreAttachedState(FacesContext context,
+ Object stateObj)
+ throws IllegalStateException
+ {
+ if (context == null) throw new NullPointerException("context");
+ if (stateObj == null) return null;
+ if (stateObj instanceof _AttachedListStateWrapper)
+ {
+ List lst = ((_AttachedListStateWrapper)stateObj).getWrappedStateList();
+ List restoredList = new ArrayList(lst.size());
+ for (Iterator it = lst.iterator(); it.hasNext(); )
+ {
+ restoredList.add(restoreAttachedState(context, it.next()));
+ }
+ return restoredList;
+ }
+ else if (stateObj instanceof _AttachedStateWrapper)
+ {
+ Class clazz = ((_AttachedStateWrapper)stateObj).getClazz();
+ Object restoredObject;
+ try
+ {
+ restoredObject = clazz.newInstance();
+ }
+ catch (InstantiationException e)
+ {
+ throw new RuntimeException("Could not restore StateHolder of type " + clazz.getName() + " (missing no-args constructor?)", e);
+ }
+ catch (IllegalAccessException e)
+ {
+ throw new RuntimeException(e);
+ }
+ if (restoredObject instanceof StateHolder)
+ {
+ Object wrappedState = ((_AttachedStateWrapper)stateObj).getWrappedStateObject();
+ ((StateHolder)restoredObject).restoreState(context, wrappedState);
+ }
+ return restoredObject;
+ }
+ else
+ {
+ return stateObj;
+ }
+ }
+
+
+ protected FacesContext getFacesContext()
+ {
+ return FacesContext.getCurrentInstance();
+ }
+ protected String getStringValue(FacesContext context, ValueBinding vb)
+ {
+ Object value = vb.getValue(context);
+ if (value != null)
+ {
+ return value.toString();
+ }
+ return null;
+ }
+}
Added: myfaces/commons/branches/jsf_11/myfaces-commons-converters/src/main/java/org/apache/myfaces/commons/converter/ConverterBaseTag.java
URL: http://svn.apache.org/viewvc/myfaces/commons/branches/jsf_11/myfaces-commons-converters/src/main/java/org/apache/myfaces/commons/converter/ConverterBaseTag.java?rev=1031298&view=auto
==============================================================================
--- myfaces/commons/branches/jsf_11/myfaces-commons-converters/src/main/java/org/apache/myfaces/commons/converter/ConverterBaseTag.java (added)
+++ myfaces/commons/branches/jsf_11/myfaces-commons-converters/src/main/java/org/apache/myfaces/commons/converter/ConverterBaseTag.java Thu Nov 4 22:24:59 2010
@@ -0,0 +1,92 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.commons.converter;
+
+import javax.faces.context.FacesContext;
+import javax.faces.convert.Converter;
+import javax.faces.el.ValueBinding;
+import javax.faces.webapp.ConverterTag;
+import javax.faces.webapp.UIComponentTag;
+import javax.servlet.jsp.JspException;
+
+/**
+ * ConverterBaseTag provides support for ConverterBase subclasses.
+ * ConverterBaseTag subclass tld entries should include the following to pick up attribute defintions.
+ * &ext_converter_base_attributes;
+ *
+ * @author mkienenb (latest modification by $Author: lu4242 $)
+ * @version $Revision: 706423 $
+ */
+public abstract class ConverterBaseTag extends ConverterTag {
+ private static final long serialVersionUID = 4416508071412794682L;
+ private String _detailMessage = null;
+ private String _summaryMessage = null;
+
+ public void setDetailMessage(String detailMessage)
+ {
+ _detailMessage = detailMessage;
+ }
+
+ public void setSummaryMessage(String summaryMessage)
+ {
+ _summaryMessage = summaryMessage;
+ }
+
+ protected Converter createConverter() throws JspException
+ {
+ ConverterBase converter = (ConverterBase) super.createConverter();
+
+ FacesContext facesContext = FacesContext.getCurrentInstance();
+
+ if (_detailMessage != null)
+ {
+ if (UIComponentTag.isValueReference(_detailMessage))
+ {
+ ValueBinding vb = facesContext.getApplication().createValueBinding(_detailMessage);
+ converter.setValueBinding("detailMessage",vb);
+ }
+ else
+ {
+ converter.setDetailMessage(_detailMessage);
+ }
+ }
+
+ if (_summaryMessage != null)
+ {
+ if (UIComponentTag.isValueReference(_summaryMessage))
+ {
+ ValueBinding vb = facesContext.getApplication().createValueBinding(_summaryMessage);
+ converter.setValueBinding("summaryMessage",vb);
+ }
+ else
+ {
+ converter.setSummaryMessage(_summaryMessage);
+ }
+ }
+
+ return converter;
+ }
+
+ public void release()
+ {
+ super.release();
+ _detailMessage = null;
+ _summaryMessage = null;
+ }
+}
Added: myfaces/commons/branches/jsf_11/myfaces-commons-converters/src/main/java/org/apache/myfaces/commons/converter/ConverterBaseTagHandler.java
URL: http://svn.apache.org/viewvc/myfaces/commons/branches/jsf_11/myfaces-commons-converters/src/main/java/org/apache/myfaces/commons/converter/ConverterBaseTagHandler.java?rev=1031298&view=auto
==============================================================================
--- myfaces/commons/branches/jsf_11/myfaces-commons-converters/src/main/java/org/apache/myfaces/commons/converter/ConverterBaseTagHandler.java (added)
+++ myfaces/commons/branches/jsf_11/myfaces-commons-converters/src/main/java/org/apache/myfaces/commons/converter/ConverterBaseTagHandler.java Thu Nov 4 22:24:59 2010
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.commons.converter;
+
+import com.sun.facelets.tag.MetaRuleset;
+import com.sun.facelets.tag.jsf.ConvertHandler;
+import com.sun.facelets.tag.jsf.ConverterConfig;
+
+public class ConverterBaseTagHandler extends ConvertHandler
+{
+
+ public ConverterBaseTagHandler(ConverterConfig config)
+ {
+ super(config);
+ }
+
+ @Override
+ protected MetaRuleset createMetaRuleset(Class type)
+ {
+ MetaRuleset ruleSet = super.createMetaRuleset(type);
+
+ //Add rule to handle EL expressions
+ ruleSet.addRule(_ConverterRule.Instance);
+
+ return ruleSet;
+ }
+}
Added: myfaces/commons/branches/jsf_11/myfaces-commons-converters/src/main/java/org/apache/myfaces/commons/converter/_AttachedListStateWrapper.java
URL: http://svn.apache.org/viewvc/myfaces/commons/branches/jsf_11/myfaces-commons-converters/src/main/java/org/apache/myfaces/commons/converter/_AttachedListStateWrapper.java?rev=1031298&view=auto
==============================================================================
--- myfaces/commons/branches/jsf_11/myfaces-commons-converters/src/main/java/org/apache/myfaces/commons/converter/_AttachedListStateWrapper.java (added)
+++ myfaces/commons/branches/jsf_11/myfaces-commons-converters/src/main/java/org/apache/myfaces/commons/converter/_AttachedListStateWrapper.java Thu Nov 4 22:24:59 2010
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.commons.converter;
+
+import java.io.Serializable;
+import java.util.List;
+
+/**
+ * @author Manfred Geiler (latest modification by $Author: bdudney $)
+ * @version $Revision: 225333 $ $Date: 2005-07-26 17:49:19 +0200 (Di, 26 Jul 2005) $
+ */
+class _AttachedListStateWrapper
+ implements Serializable
+{
+ private static final long serialVersionUID = -3958718149793179776L;
+ private List _wrappedStateList;
+
+ public _AttachedListStateWrapper(List wrappedStateList)
+ {
+ _wrappedStateList = wrappedStateList;
+ }
+
+ public List getWrappedStateList()
+ {
+ return _wrappedStateList;
+ }
+}
Added: myfaces/commons/branches/jsf_11/myfaces-commons-converters/src/main/java/org/apache/myfaces/commons/converter/_AttachedStateWrapper.java
URL: http://svn.apache.org/viewvc/myfaces/commons/branches/jsf_11/myfaces-commons-converters/src/main/java/org/apache/myfaces/commons/converter/_AttachedStateWrapper.java?rev=1031298&view=auto
==============================================================================
--- myfaces/commons/branches/jsf_11/myfaces-commons-converters/src/main/java/org/apache/myfaces/commons/converter/_AttachedStateWrapper.java (added)
+++ myfaces/commons/branches/jsf_11/myfaces-commons-converters/src/main/java/org/apache/myfaces/commons/converter/_AttachedStateWrapper.java Thu Nov 4 22:24:59 2010
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.commons.converter;
+
+import java.io.Serializable;
+
+/**
+ * @author Manfred Geiler (latest modification by $Author: bdudney $)
+ * @version $Revision: 225333 $ $Date: 2005-07-26 17:49:19 +0200 (Di, 26 Jul 2005) $
+ */
+class _AttachedStateWrapper
+ implements Serializable
+{
+ private static final long serialVersionUID = 4948301780259917764L;
+ private Class _class;
+ private Object _wrappedStateObject;
+
+ /**
+ * @param clazz null means wrappedStateObject is a List of state objects
+ * @param wrappedStateObject
+ */
+ public _AttachedStateWrapper(Class clazz, Object wrappedStateObject)
+ {
+ if (wrappedStateObject != null && !(wrappedStateObject instanceof Serializable))
+ {
+ throw new IllegalArgumentException("Attached state for Object of type " + clazz + " (Class " + wrappedStateObject.getClass().getName() + ") is not serializable");
+ }
+ _class = clazz;
+ _wrappedStateObject = wrappedStateObject;
+ }
+
+ public Class getClazz()
+ {
+ return _class;
+ }
+
+ public Object getWrappedStateObject()
+ {
+ return _wrappedStateObject;
+ }
+}
Added: myfaces/commons/branches/jsf_11/myfaces-commons-converters/src/main/java/org/apache/myfaces/commons/converter/_ConverterRule.java
URL: http://svn.apache.org/viewvc/myfaces/commons/branches/jsf_11/myfaces-commons-converters/src/main/java/org/apache/myfaces/commons/converter/_ConverterRule.java?rev=1031298&view=auto
==============================================================================
--- myfaces/commons/branches/jsf_11/myfaces-commons-converters/src/main/java/org/apache/myfaces/commons/converter/_ConverterRule.java (added)
+++ myfaces/commons/branches/jsf_11/myfaces-commons-converters/src/main/java/org/apache/myfaces/commons/converter/_ConverterRule.java Thu Nov 4 22:24:59 2010
@@ -0,0 +1,73 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.commons.converter;
+
+import com.sun.facelets.FaceletContext;
+import com.sun.facelets.el.LegacyValueBinding;
+import com.sun.facelets.tag.MetaRule;
+import com.sun.facelets.tag.Metadata;
+import com.sun.facelets.tag.MetadataTarget;
+import com.sun.facelets.tag.TagAttribute;
+
+final class _ConverterRule extends MetaRule {
+
+ final static class ValueBindingMetadata extends Metadata {
+
+ private final String name;
+
+ private final TagAttribute attr;
+
+ private final Class type;
+
+ public ValueBindingMetadata(String name, Class type, TagAttribute attr) {
+ this.name = name;
+ this.attr = attr;
+ this.type = type;
+ }
+
+ public void applyMetadata(FaceletContext ctx, Object instance) {
+ ((ConverterBase) instance).setValueBinding(this.name,
+ new LegacyValueBinding(this.attr.getValueExpression(ctx,
+ this.type)));
+ }
+
+ }
+
+ public final static _ConverterRule Instance = new _ConverterRule();
+
+ public _ConverterRule() {
+ super();
+ }
+
+ public Metadata applyRule(String name, TagAttribute attribute,
+ MetadataTarget meta) {
+ if (meta.isTargetInstanceOf(ConverterBase.class)) {
+
+ // if component and dynamic, then must set expression
+ if (!attribute.isLiteral()) {
+ Class type = meta.getPropertyType(name);
+ if (type == null) {
+ type = Object.class;
+ }
+ return new ValueBindingMetadata(name, type, attribute);
+ }
+ }
+ return null;
+ }
+}
Added: myfaces/commons/branches/jsf_11/myfaces-commons-converters/src/main/resources/META-INF/converterClass11.vm
URL: http://svn.apache.org/viewvc/myfaces/commons/branches/jsf_11/myfaces-commons-converters/src/main/resources/META-INF/converterClass11.vm?rev=1031298&view=auto
==============================================================================
--- myfaces/commons/branches/jsf_11/myfaces-commons-converters/src/main/resources/META-INF/converterClass11.vm (added)
+++ myfaces/commons/branches/jsf_11/myfaces-commons-converters/src/main/resources/META-INF/converterClass11.vm Thu Nov 4 22:24:59 2010
@@ -0,0 +1,219 @@
+## Velocity template used to generate JSF1.1-compatible converter classes
+## from converter meta-data.
+##
+## Note that there are only one type of converter generation:
+## * "subclass mode" (use annotated class as a parent class)
+##
+## Variable $converter refers to a ConverterMeta object to process
+## Variable $utils refers to an instance of MyfacesUtils.
+##
+##
+## The java package of the generated class is always the same as
+## the package in which the annotated class exists.
+##
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package ${converter.packageName};
+
+import javax.faces.el.ValueBinding;
+import javax.faces.context.FacesContext;
+$utils.importTagClasses($converter)
+
+#if ($converter.isTemplate())
+#set ($generatedClassParent = $converter.sourceClassParentClassName)
+#else
+#set ($generatedClassParent = $converter.sourceClassName)
+#end
+// Generated from class ${converter.sourceClassName}.
+//
+// WARNING: This file was automatically generated. Do not edit it directly,
+// or you will lose your changes.
+public class ${utils.getClassFromFullClass($converter.className)} extends $generatedClassParent
+#if ($converter.implements)
+ implements $converter.implements
+#end
+{
+
+#if ($converter.converterId)
+ static public final String VALIDATOR_ID =
+ "$converter.converterId";
+#end
+
+ public ${utils.getClassFromFullClass($converter.className)}()
+ {
+ }
+
+#set ($propertyList = ${converter.propertyConverterList})
+
+#foreach( $property in $propertyList )
+#set ($field = $property.fieldName)
+#set ($type = $utils.getClassFromFullClass($property.className))
+#if($utils.getDefaultValueField($property))
+#set ($defaultValue = $utils.getDefaultValueField($property))
+#else
+#set ($defaultValue = false)
+#end
+ // Property: $property.name
+#if ($property.isLiteralOnly() || $property.isTagExcluded() )
+ private $type $field #if($defaultValue) = $defaultValue;#{else};#{end}
+
+
+#else
+ private $type $field;
+
+#end
+#if($utils.isPrimitiveClass($type) && !$property.isTagExcluded() )
+ private boolean ${field}Set;
+
+#if ($property.isSetMethod())
+ $property.setMethodScope boolean $utils.getPrefixedPropertyName("isSet", $property.name)()
+ {
+ return ${field}Set;
+ }
+#end
+#end
+#if($property.isLocalMethod())
+#if("boolean" == $type)
+#set ($methodName = $utils.getPrefixedPropertyName("isLocal", $property.name))
+#else
+#set ($methodName = $utils.getPrefixedPropertyName("getLocal", $property.name))
+#end
+ final $property.localMethodScope $type ${methodName}()
+ {
+ return $field;
+ }
+
+#end
+ public $type $utils.getMethodReaderFromProperty($property.name, $type)()
+ {
+#if ($property.isTagExcluded() || $property.isLiteralOnly() || !($converter.isEvaluateELOnExecution()))
+ return $field;
+#else
+#if ($utils.isPrimitiveClass($type))
+ if (${field}Set)
+#else
+ if ($field != null)
+#end
+ {
+ return $field;
+ }
+ ValueBinding vb = getValueBinding("$property.name");
+ if (vb != null)
+ {
+#if ($utils.isPrimitiveClass($type))
+ return ($utils.castIfNecessary($type) vb.getValue(getFacesContext())).${type}Value();
+#else
+#set ($pritype = $utils.getPrimitiveType($property.className))
+#if ($utils.isPrimitiveClass($pritype))
+ Object value = vb == null ? null : vb.getValue(getFacesContext());
+ if (!(value instanceof $type)){
+ value = ${type}.valueOf(value.toString());
+ }
+ return $utils.castIfNecessary($type) value;
+#else
+ return $utils.castIfNecessary($type) vb.getValue(getFacesContext());
+#end
+#end
+ }
+#if ($defaultValue)
+ return $defaultValue;
+#elseif ($utils.isPrimitiveClass($type))
+ return $utils.primitiveDefaultValue($type);
+#else
+ return null;
+#end
+#end
+ }
+
+ public void $utils.getPrefixedPropertyName("set", $property.name)($type $utils.getVariableFromName($property.name))
+ {
+ this.$field = $utils.getVariableFromName($property.name);
+#if ($utils.isPrimitiveClass($type) && !$property.isTagExcluded() )
+ this.${field}Set = true;
+#end
+ }
+#end
+
+ public Object saveState(FacesContext facesContext)
+ {
+#set ($primitiveCount = $propertyList.size() + 1)
+#foreach( $property in $propertyList )
+#if($utils.isPrimitiveClass($property.className))
+#set ($primitiveCount = $primitiveCount + 1)
+#end
+#end
+ Object[] values = new Object[$primitiveCount];
+ values[0] = super.saveState(facesContext);
+#set ($arrayIndex = 0)
+#foreach( $property in $propertyList )
+#set ($field = $property.fieldName)
+#set ($type = $property.className)
+#set ($arrayIndex = $arrayIndex + 1)
+#if ($property.jspName == "converter" && $property.isMethodBinding() )
+ values[$arrayIndex] = saveAttachedState(facesContext,${field}List);
+#elseif ( $property.isStateHolder() )## || $utils.isConverter($type)
+ values[$arrayIndex] = saveAttachedState(facesContext,$field);
+#elseif($utils.isPrimitiveClass($type))
+#if ($type == "boolean")
+ values[$arrayIndex] = ${utils.getBoxedClass($type)}.valueOf($field);
+#else
+ values[$arrayIndex] = new ${utils.getBoxedClass($type)}($field);
+#end
+#else
+ values[$arrayIndex] = $field;
+#end
+#if($utils.isPrimitiveClass($type) && !$property.isTagExcluded())
+#set ($arrayIndex = $arrayIndex + 1)
+ values[$arrayIndex] = Boolean.valueOf(${field}Set);
+#end
+#end
+ return values;
+ }
+
+ public void restoreState(FacesContext facesContext, Object state)
+ {
+ Object[] values = (Object[])state;
+ super.restoreState(facesContext,values[0]);
+#set ($arrayIndex = 0)
+#foreach( $property in $propertyList )
+#set ($field = $property.fieldName)
+#set ($type = $property.className)
+#set ($arrayIndex = $arrayIndex + 1)
+#if ( $property.isStateHolder() )
+#if ($property.jspName == "converter" && $property.isMethodBinding() )
+ ${field}List = (List<Converter>) restoreAttachedState(facesContext,values[$arrayIndex]);
+#elseif ($utils.isList($type))
+ $field = (List) restoreAttachedState(facesContext,values[$arrayIndex]);
+#else
+ $field = $utils.castIfNecessary($type) restoreAttachedState(facesContext,values[$arrayIndex]);
+#end
+#elseif ($utils.isConverter($type))
+ $field = (Converter) restoreAttachedState(facesContext,values[$arrayIndex]);
+#elseif ($utils.isPrimitiveClass($type))
+ $field = ($utils.castIfNecessary($type) values[$arrayIndex]).${type}Value();
+#else
+ $field = $utils.castIfNecessary($type) values[$arrayIndex];
+#end
+#if($utils.isPrimitiveClass($type) && !$property.isTagExcluded() )
+#set ($arrayIndex = $arrayIndex + 1)
+ ${field}Set = ((Boolean) values[$arrayIndex]).booleanValue();
+#end
+#end
+ }
+}
Modified: myfaces/commons/branches/jsf_11/myfaces-commons-converters/src/main/resources/META-INF/tagConverterClass11.vm
URL: http://svn.apache.org/viewvc/myfaces/commons/branches/jsf_11/myfaces-commons-converters/src/main/resources/META-INF/tagConverterClass11.vm?rev=1031298&r1=1031297&r2=1031298&view=diff
==============================================================================
--- myfaces/commons/branches/jsf_11/myfaces-commons-converters/src/main/resources/META-INF/tagConverterClass11.vm (original)
+++ myfaces/commons/branches/jsf_11/myfaces-commons-converters/src/main/resources/META-INF/tagConverterClass11.vm Thu Nov 4 22:24:59 2010
@@ -74,6 +74,10 @@ public class $utils.getClassFromFullClas
{
if (UIComponentTag.isValueReference($field))
{
+#if ($converter.isEvaluateELOnExecution() && !($property.isLiteralOnly()))
+ ValueBinding vb = facesContext.getApplication().createValueBinding($field);
+ converter.setValueBinding("$property.name", vb);
+#else
ValueBinding vb = facesContext.getApplication().createValueBinding($field);
#if ($utils.isPrimitiveClass($property.className))
converter.${utils.getPrefixedPropertyName("set",$property.name)}(${utils.getBoxedClass($className)}.valueOf(vb.getValue(facesContext).toString()).${property.className}Value());
@@ -111,6 +115,7 @@ public class $utils.getClassFromFullClas
#else
converter.${utils.getPrefixedPropertyName("set",$property.name)}(($property.className) vb.getValue(facesContext));
#end
+#end
}
else
{
@@ -156,4 +161,4 @@ public class $utils.getClassFromFullClas
$field = $empty;
#end
}
-}
\ No newline at end of file
+}