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

Source Code of org.apache.ws.resource.properties.v1_2.porttype.impl.GetMultipleResourcePropertiesProvider

/*=============================================================================*
*  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.v1_2.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.ResourceProperty;
import org.apache.ws.resource.properties.faults.InvalidResourcePropertyQNameFaultException;
import org.apache.ws.resource.properties.v1_2.porttype.GetMultipleResourcePropertiesPortType;
import org.apache.ws.util.XmlBeanUtils;
import org.apache.ws.util.i18n.Messages;
import org.apache.xmlbeans.XmlObject;
import org.oasisOpen.docs.wsrf.x2004.x06.wsrfWSResourceProperties12Draft01.GetMultipleResourcePropertiesDocument;
import org.oasisOpen.docs.wsrf.x2004.x06.wsrfWSResourceProperties12Draft01.GetMultipleResourcePropertiesResponseDocument;

import javax.xml.namespace.QName;
import java.util.Iterator;

/**
* LOG-DONE An operation provider for wsrp:GetMultipleResourceProperties.
*
* @author Ian P. Springer
*/
public class GetMultipleResourcePropertiesProvider
        extends AbstractResourcePropertiesPortType
        implements GetMultipleResourcePropertiesPortType
{

    private static final Log LOG = LogFactory.getLog( GetMultipleResourcePropertiesProvider.class );
    private static final Messages MSG = MessagesImpl.getInstance();

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

    /**
     * Implementation of the wsrp:GetMultipleResourceProperties operation.
     *
     * @param requestDoc the requestDoc XMLBean
     *
     * @return the response XMLBean
     *
     * @throws InvalidResourcePropertyQNameFaultException
     *
     * @throws org.apache.ws.resource.faults.ResoureKeyHeaderNotFoundFaultException
     *
     */
    public GetMultipleResourcePropertiesResponseDocument getMultipleResourceProperties( GetMultipleResourcePropertiesDocument requestDoc )
    {
        if ( LOG.isDebugEnabled() )
        {
            LOG.debug( MSG.getMessage( Keys.GET_MULTI_RP_REQ,
                    requestDoc.toString() ) );
        }

        GetMultipleResourcePropertiesResponseDocument responseDoc = createResponseDocument();
        QName[] propNames =
                requestDoc.getGetMultipleResourceProperties().getResourcePropertyArray();

        for ( int i = 0; i < propNames.length; i++ )
        {
            ResourceProperty prop = getProperties().get( propNames[i] );
            if ( prop == null )
            {
                throw new InvalidResourcePropertyQNameFaultException( propNames[i] );
            }
            refreshProperty( prop );
            if ( prop == null )
            {
                throw new InvalidResourcePropertyQNameFaultException( propNames[i] );
            }

            addPropertyToResponse( prop,
                    responseDoc.getGetMultipleResourcePropertiesResponse() );
        }

        return responseDoc;
    }

    private void addPropertyToResponse( ResourceProperty prop,
                                        GetMultipleResourcePropertiesResponseDocument.GetMultipleResourcePropertiesResponse response )
    {
        Iterator propElemIter = prop.iterator();
        while ( propElemIter.hasNext() )
        {
            XmlObject propElem = (XmlObject) propElemIter.next();
            XmlBeanUtils.addChildElement( response, propElem );
        }
    }

    private GetMultipleResourcePropertiesResponseDocument createResponseDocument()
    {
        GetMultipleResourcePropertiesResponseDocument responseDoc =
                GetMultipleResourcePropertiesResponseDocument.Factory.newInstance();
        responseDoc.addNewGetMultipleResourcePropertiesResponse();
        return responseDoc;
    }

}
TOP

Related Classes of org.apache.ws.resource.properties.v1_2.porttype.impl.GetMultipleResourcePropertiesProvider

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.