Package org.internna.iwebmvc.dwr

Source Code of org.internna.iwebmvc.dwr.RatingConverter

/*
* Copyright 2002-2007 the original author or authors.
*
* Licensed 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.internna.iwebmvc.dwr;

import org.directwebremoting.ConversionException;
import org.directwebremoting.extend.InboundVariable;
import org.directwebremoting.extend.NonNestedOutboundVariable;
import org.directwebremoting.extend.OutboundContext;
import org.directwebremoting.extend.OutboundVariable;
import org.internna.iwebmvc.IWebMvcException;
import org.internna.iwebmvc.model.Rating;
import static org.internna.iwebmvc.utils.StringUtils.hasText;

/**
* DWR converter for Rating model class.
*
* @author Jose Noheda
* @since 2.0
*/
public class RatingConverter extends AbstractConverter {

    @Override public Object convertInbound(Class<?> paramType, InboundVariable data) throws ConversionException {
      if (!data.isNull()) {
            Rating rating = new Rating();
            try {
                String points = data.getValue();
                rating.setRating(hasText(points) ? Double.parseDouble(points) : 0D);
                return rating;
            } catch (Exception e) {
                throw new ConversionException(paramType, new IWebMvcException("Could not convert Rating from: " + data, e));
            }
      }
        return null;
    }

    @Override public OutboundVariable convertOutbound(Object data, OutboundContext outctx) throws ConversionException {
        return new NonNestedOutboundVariable(data == null ? "0" : String.valueOf(((Rating) data).getRating()));
    }

}
TOP

Related Classes of org.internna.iwebmvc.dwr.RatingConverter

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.