package example.filesystem.callback;
import example.filesystem.backend.FileSystem;
import org.apache.ws.resource.properties.ResourceProperty;
import org.apache.ws.resource.properties.SetResourcePropertyCallback;
import org.apache.ws.resource.properties.impl.CallbackFailedException;
import org.apache.xmlbeans.XmlString;
import org.apache.ws.resource.example.filesystem.CommentDocument;
import javax.xml.namespace.QName;
/**
* A callback for the Comment resource property.
*/
public class CommentCallback implements SetResourcePropertyCallback
{
FileSystem m_fileSystem;
public CommentCallback( FileSystem fileSystem )
{
m_fileSystem = fileSystem;
}
public void deleteProperty( QName propQName ) throws CallbackFailedException
{
m_fileSystem.setComment( null );
}
public void insertProperty( Object[] propElems ) throws CallbackFailedException
{
// Comment prop has cardinality of 0..1, so passed array will always have exactly one element
XmlString xString = (XmlString) propElems[0];
m_fileSystem.setComment( xString.getStringValue() );
}
public void updateProperty( Object[] propElems ) throws CallbackFailedException
{
insertProperty( propElems );
}
public ResourceProperty refreshProperty( ResourceProperty prop ) throws CallbackFailedException
{
String comment = m_fileSystem.getComment();
if ( comment != null )
{
if ( prop.isEmpty() )
{
CommentDocument commentDocXBean = CommentDocument.Factory.newInstance();
commentDocXBean.setComment( comment );
prop.add( commentDocXBean );
}
else
{
XmlString xString = (XmlString) prop.get( 0 );
xString.setStringValue( comment );
}
}
return prop;
}
}