All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.ajax4jsf.framework.skin.SkinPropertyResolver Maven / Gradle / Ivy

/**
 * Licensed under the Common Development and Distribution License,
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *   http://www.sun.com/cddl/
 *   
 * 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.ajax4jsf.framework.skin;

import javax.faces.context.FacesContext;
import javax.faces.el.EvaluationException;
import javax.faces.el.PropertyNotFoundException;
import javax.faces.el.PropertyResolver;

import org.ajax4jsf.framework.util.message.Messages;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * Resolve Skin propertyes.
 * @author [email protected] (latest modification by $Author: slava_kabanovich $)
 * @version $Revision: 1.2 $ $Date: 2006/07/12 14:59:32 $
 *
 */
public class SkinPropertyResolver extends PropertyResolver {
	
	private static final Log log = LogFactory.getLog(SkinPropertyResolver.class);
	private PropertyResolver parent = null;

	/**
	 * @param parent
	 */
	public SkinPropertyResolver(PropertyResolver parent) {
		this.parent = parent;
	}

	/* (non-Javadoc)
	 * @see javax.faces.el.PropertyResolver#getType(java.lang.Object, int)
	 */
	public Class getType(Object base, int index) throws EvaluationException, PropertyNotFoundException {
		if (base instanceof Skin) {
			if(log.isDebugEnabled()){
				log.debug(Messages.getMessage(Messages.ACESSING_SKIN_PROPERTY_AS_ARRAY_ERROR));
			}
			return null;
		}
		return parent.getType(base, index);
	}

	/* (non-Javadoc)
	 * @see javax.faces.el.PropertyResolver#getType(java.lang.Object, java.lang.Object)
	 */
	public Class getType(Object base, Object property) throws EvaluationException, PropertyNotFoundException {
		if (base instanceof Skin) {
			Skin skin = (Skin) base;
			if(property instanceof String){
				return skin.getParameter(FacesContext.getCurrentInstance(),(String) property).getClass();
			}
			if(log.isDebugEnabled()){
				log.debug(Messages.getMessage(Messages.ACESSING_SKIN_PROPERTY_ERROR));
			}
			return null;
		}
		return parent.getType(base, property);
	}

	/* (non-Javadoc)
	 * @see javax.faces.el.PropertyResolver#getValue(java.lang.Object, int)
	 */
	public Object getValue(Object base, int index) throws EvaluationException, PropertyNotFoundException {
		if (base instanceof Skin) {
			if(log.isDebugEnabled()){
				log.debug(Messages.getMessage(Messages.ACESSING_SKIN_PROPERTY_AS_ARRAY_ERROR));
			}
			return null;
		}
		return parent.getValue(base, index);
	}

	/* (non-Javadoc)
	 * @see javax.faces.el.PropertyResolver#getValue(java.lang.Object, java.lang.Object)
	 */
	public Object getValue(Object base, Object property) throws EvaluationException, PropertyNotFoundException {
		if (base instanceof Skin) {
			Skin skin = (Skin) base;
			if(property instanceof String){
				return skin.getParameter(FacesContext.getCurrentInstance(),(String) property);
			}
			if(log.isDebugEnabled()){
				log.debug(Messages.getMessage(Messages.ACESSING_SKIN_PROPERTY_ERROR));
			}
			return null;
		}
		return parent.getValue(base, property);
	}

	/* (non-Javadoc)
	 * @see javax.faces.el.PropertyResolver#isReadOnly(java.lang.Object, int)
	 */
	public boolean isReadOnly(Object base, int arg1) throws EvaluationException, PropertyNotFoundException {
		if (base instanceof Skin) {
			return true;
		}
		return parent.isReadOnly(base, arg1);
	}

	/* (non-Javadoc)
	 * @see javax.faces.el.PropertyResolver#isReadOnly(java.lang.Object, java.lang.Object)
	 */
	public boolean isReadOnly(Object base, Object arg1) throws EvaluationException, PropertyNotFoundException {
		if (base instanceof Skin) {
			return true;
		}
		return parent.isReadOnly(base, arg1);
	}

	/* (non-Javadoc)
	 * @see javax.faces.el.PropertyResolver#setValue(java.lang.Object, int, java.lang.Object)
	 */
	public void setValue(Object base, int index, Object value) throws EvaluationException, PropertyNotFoundException {
		if (base instanceof Skin) {
			throw new EvaluationException(Messages.getMessage(Messages.SKIN_PROPERTIES_READ_ONLY_ERROR));
		}
		parent.setValue(base, index, value);
	}

	/* (non-Javadoc)
	 * @see javax.faces.el.PropertyResolver#setValue(java.lang.Object, java.lang.Object, java.lang.Object)
	 */
	public void setValue(Object base, Object property, Object value) throws EvaluationException, PropertyNotFoundException {
		if (base instanceof Skin) {
			throw new EvaluationException(Messages.getMessage(Messages.SKIN_PROPERTIES_READ_ONLY_ERROR));
		}
		parent.setValue(base, property, value);
	}


}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy