Package example.filesystem.callback

Source Code of example.filesystem.callback.CommentCallback

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;
    }
}
TOP

Related Classes of example.filesystem.callback.CommentCallback

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.