Package org.apache.ws.resource.properties

Source Code of org.apache.ws.resource.properties.XmlBeansResourcePropertyUtils

/*=============================================================================*
*  Copyright 2004 The Apache Software Foundation
*
*  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.apache.ws.resource.properties;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.ws.resource.i18n.Keys;
import org.apache.ws.resource.i18n.MessagesImpl;
import org.apache.ws.resource.properties.impl.XmlBeansResourceProperty;
import org.apache.ws.util.i18n.Messages;
import org.apache.xmlbeans.XmlDateTime;

import javax.xml.rpc.JAXRPCException;
import java.util.Calendar;

/**
* A collection of utility methods for working with {@link XmlBeansResourceProperty}s.
*
* @author Ian Springer
*/
public abstract class XmlBeansResourcePropertyUtils
{
    private static final Log LOG = LogFactory.getLog( XmlBeansResourcePropertyUtils.class );
    public static final Messages MSG = MessagesImpl.getInstance();

    public static void setDateTimePropertyValue( XmlBeansResourceProperty prop,
                                                 Calendar time )
    {
        LOG.debug( MSG.getMessage( Keys.SET_PROP_TIME, prop.getMetaData().getName(), time.toString() ) );
        XmlDateTime propElem = getDateTimePropertyElement( prop );
        propElem.setCalendarValue( time );
    }

    public static Calendar getDateTimePropertyValue( XmlBeansResourceProperty prop )
    {
        XmlDateTime propElem = getDateTimePropertyElement( prop );
        return propElem != null ? propElem.getCalendarValue() : null;
    }

    private static XmlDateTime getDateTimePropertyElement( XmlBeansResourceProperty prop )
    {
        if ( prop == null )
        {
            throw new JAXRPCException( MSG.getMessage( Keys.PROP_NOT_DEFINED, prop.getMetaData().getName() ) );
        }
        XmlDateTime propElem;
        if ( ! prop.isEmpty() )
        {
            propElem = (XmlDateTime) prop.get( 0 );
        }
        else
        {
            propElem = null;
        }
        return propElem;
    }
}
TOP

Related Classes of org.apache.ws.resource.properties.XmlBeansResourcePropertyUtils

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.