Package org.apache.ws.resource.properties.v2004_06.porttype.impl

Source Code of org.apache.ws.resource.properties.v2004_06.porttype.impl.SetResourcePropertiesPortTypeImpl

/*=============================================================================*
*  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.v2004_06.porttype.impl;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.ws.resource.ResourceContext;
import org.apache.ws.resource.i18n.Keys;
import org.apache.ws.resource.i18n.MessagesImpl;
import org.apache.ws.resource.properties.NamespaceVersionHolder;
import org.apache.ws.resource.properties.v2004_06.impl.XmlBeansResourcePropertyValueChangeEvent;
import org.apache.ws.resource.properties.faults.InsertResourcePropertyRequestFailedFaultException;
import org.apache.ws.resource.properties.faults.SetResourcePropertyRequestFailedFaultException;
import org.apache.ws.resource.properties.faults.InvalidInsertResourcePropertiesRequestContentFaultException;
import org.apache.ws.resource.properties.faults.InvalidSetResourcePropertiesRequestContentFaultException;
import org.apache.ws.resource.properties.faults.DeleteResourcePropertyRequestFailedFaultException;
import org.apache.ws.resource.properties.faults.UpdateResourcePropertyRequestFailedFaultException;
import org.apache.ws.resource.properties.faults.InvalidUpdateResourcePropertiesRequestContentFaultException;
import org.apache.ws.resource.properties.impl.AbstractSetResourcePropertiesPortType;
import org.apache.ws.resource.properties.impl.AbstractXmlBeansResourcePropertyValueChangeEvent;
import org.apache.ws.resource.properties.v2004_06.porttype.SetResourcePropertiesPortType;
import org.apache.ws.resource.properties.v2004_06.impl.NamespaceVersionHolderImpl;
import org.apache.ws.util.i18n.Messages;
import org.apache.ws.util.XmlBeanUtils;
import org.apache.xmlbeans.XmlObject;
import org.oasisOpen.docs.wsrf.x2004.x06.wsrfWSResourceProperties12Draft01.DeleteType;
import org.oasisOpen.docs.wsrf.x2004.x06.wsrfWSResourceProperties12Draft01.InsertType;
import org.oasisOpen.docs.wsrf.x2004.x06.wsrfWSResourceProperties12Draft01.SetResourcePropertiesDocument;
import org.oasisOpen.docs.wsrf.x2004.x06.wsrfWSResourceProperties12Draft01.SetResourcePropertiesResponseDocument;
import org.oasisOpen.docs.wsrf.x2004.x06.wsrfWSResourceProperties12Draft01.UpdateType;

/**
* LOG-DONE An operation provider for wsrp:SetResourceProperties.
*
* @author Ian P. Springer
*/
public class SetResourcePropertiesPortTypeImpl
        extends AbstractSetResourcePropertiesPortType
        implements SetResourcePropertiesPortType
{

    private static final Log LOG = LogFactory.getLog( SetResourcePropertiesPortTypeImpl.class );
    private static final Messages MSG = MessagesImpl.getInstance();
    private static final NamespaceVersionHolder NAMESPACE_SET = new NamespaceVersionHolderImpl() ;

    /**
     * Creates a new {@link SetResourcePropertiesPortTypeImpl} object.
     *
     * @param resourceContext DOCUMENT_ME
     */
    public SetResourcePropertiesPortTypeImpl( ResourceContext resourceContext )
    {
        super( resourceContext );
    }

    /**
     * Implementation of the wsrp:SetResourceProperties operation.
     *
     * @param requestDoc the requestDoc XMLBean
     *
     * @return the response XMLBean
     *
     * @throws org.apache.ws.resource.properties.faults.InvalidResourcePropertyQNameFaultException
     *
     * @throws org.apache.ws.resource.faults.ResourceKeyHeaderNotFoundFaultException
     *
     */
    public SetResourcePropertiesResponseDocument setResourceProperties( SetResourcePropertiesDocument requestDoc )
    {
        if ( LOG.isDebugEnabled() )
        {
            LOG.debug( MSG.getMessage( Keys.SET_RP_REQ, requestDoc ) );
        }

        SetResourcePropertiesResponseDocument responseDoc = createResponseDocument();
        SetResourcePropertiesDocument.SetResourceProperties requestElem = requestDoc.getSetResourceProperties();

        InsertType[] insertElems = requestElem.getInsertArray();
        for ( int i = 0; i < insertElems.length; i++ )
        {
            XmlObject[] propElemsToBeInserted = XmlBeanUtils.getChildElements( insertElems[i] );
            try
            {
                insertResourceProperty( propElemsToBeInserted );
            }
            catch ( InsertResourcePropertyRequestFailedFaultException fault )
            {
                throw new SetResourcePropertyRequestFailedFaultException( getNamespaceSet(), fault.getFaultString() );
            }
            catch ( InvalidInsertResourcePropertiesRequestContentFaultException fault )
            {
                throw new InvalidSetResourcePropertiesRequestContentFaultException( getNamespaceSet(), fault.getFaultString() );
            }
        }

        DeleteType[] deleteElems = requestElem.getDeleteArray();
        for ( int i = 0; i < deleteElems.length; i++ )
        {
            try
            {
                deleteResourceProperty( deleteElems[i].getResourceProperty() );
            }
            catch ( DeleteResourcePropertyRequestFailedFaultException fault )
            {
                throw new SetResourcePropertyRequestFailedFaultException( getNamespaceSet(), fault.getFaultString() );
            }
        }

        UpdateType[] updateElems = requestElem.getUpdateArray();
        for ( int i = 0; i < updateElems.length; i++ )
        {
            XmlObject[] newPropElems = XmlBeanUtils.getChildElements( updateElems[i] );
            try
            {
                updateResourceProperty( newPropElems );
            }
            catch ( UpdateResourcePropertyRequestFailedFaultException fault )
            {
                throw new SetResourcePropertyRequestFailedFaultException( getNamespaceSet(), fault.getFaultString() );
            }
            catch ( InvalidUpdateResourcePropertiesRequestContentFaultException fault )
            {
                throw new InvalidSetResourcePropertiesRequestContentFaultException( getNamespaceSet(), fault.getFaultString() );
            }
        }

        return responseDoc;
    }

    private SetResourcePropertiesResponseDocument createResponseDocument()
    {
        SetResourcePropertiesResponseDocument responseDoc =
                SetResourcePropertiesResponseDocument.Factory.newInstance();
        responseDoc.addNewSetResourcePropertiesResponse();
        return responseDoc;
    }

    protected NamespaceVersionHolder getNamespaceSet()
    {
        return NAMESPACE_SET;
    }

    protected AbstractXmlBeansResourcePropertyValueChangeEvent getResourcePropertyValueChangeEvent(Object[] oldValue, Object[] newValue)
    {
        return new XmlBeansResourcePropertyValueChangeEvent(oldValue,newValue);
    }
}
TOP

Related Classes of org.apache.ws.resource.properties.v2004_06.porttype.impl.SetResourcePropertiesPortTypeImpl

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.