/*=============================================================================*
* 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.impl;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.ws.Soap1_1Constants;
import org.apache.ws.resource.AbstractPortType;
import org.apache.ws.resource.PropertiesResource;
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.ResourcePropertyCallback;
import org.apache.ws.resource.properties.ResourcePropertySet;
import org.apache.ws.resource.properties.faults.ResourcePropertyRetrievalFailedFaultException;
import org.apache.ws.util.i18n.Messages;
import java.util.Iterator;
/**
* A version-neutral base class that is extended by all portType impls that make use of resource properties.
*
* @author Ian Springer
*/
public abstract class AbstractResourcePropertiesPortType
extends AbstractPortType
{
private static final Log LOG = LogFactory.getLog( AbstractResourcePropertiesPortType.class );
private static final Messages MSG = MessagesImpl.getInstance( );
/**
* Creates a new {@link AbstractResourcePropertiesPortType} object.
*
* @param resourceContext DOCUMENT_ME
*/
protected AbstractResourcePropertiesPortType( ResourceContext resourceContext )
{
super( resourceContext );
}
/**
* DOCUMENT_ME
*
* @return DOCUMENT_ME
*/
protected final ResourcePropertySet getProperties( )
{
if ( !( getResource( ) instanceof PropertiesResource ) )
{
throw new IllegalStateException( MSG.getMessage( Keys.CALL_WSRP_OP_ON_NOPROP ) );
}
return ( (PropertiesResource) getResource( ) ).getResourcePropertySet( );
}
/**
* DOCUMENT_ME
*/
protected void refreshAllProperties( )
{
Iterator iterator = getProperties( ).iterator( );
while ( iterator.hasNext( ) )
{
refreshProperty( (ResourceProperty) iterator.next( ) );
}
}
/**
* DOCUMENT_ME
*
* @param prop DOCUMENT_ME
*/
protected void refreshProperty( ResourceProperty prop )
{
ResourcePropertyCallback callBack = prop.getCallBack( );
if ( callBack != null )
{
try
{
callBack.refreshProperty( prop );
}
catch ( Exception e )
{
LOG.error( "Refresh Callback Failed on ResourceProperty named: "
+ prop.getMetaData( ).getName( ).toString( ), e );
throw new ResourcePropertyRetrievalFailedFaultException( Soap1_1Constants.FAULT_SERVER,
e.getLocalizedMessage( ) );
}
}
}
}