Author: ips Date: Sat Jan 22 16:18:40 2005 New Revision: 126169 URL: http://svn.apache.org/viewcvs?view=rev&rev=126169 Log: added generic event/listener interfaces for propChange notif
Added: incubator/apollo/trunk/src/java/org/apache/ws/resource/properties/ResourcePropertyValueChangeEvent.java incubator/apollo/trunk/src/java/org/apache/ws/resource/properties/ResourcePropertyValueChangeListener.java incubator/apollo/trunk/src/java/org/apache/ws/resource/properties/v1_2/porttype/impl/XmlBeansResourcePropertyValueChangeEvent.java Modified: incubator/apollo/trunk/src/java/org/apache/ws/resource/properties/ResourceProperty.java incubator/apollo/trunk/src/java/org/apache/ws/resource/properties/impl/XmlBeansResourceProperty.java incubator/apollo/trunk/src/java/org/apache/ws/resource/properties/v1_2/porttype/impl/SetResourcePropertiesProvider.java Modified: incubator/apollo/trunk/src/java/org/apache/ws/resource/properties/ResourceProperty.java Url: http://svn.apache.org/viewcvs/incubator/apollo/trunk/src/java/org/apache/ws/resource/properties/ResourceProperty.java?view=diff&rev=126169&p1=incubator/apollo/trunk/src/java/org/apache/ws/resource/properties/ResourceProperty.java&r1=126168&p2=incubator/apollo/trunk/src/java/org/apache/ws/resource/properties/ResourceProperty.java&r2=126169 ============================================================================== --- incubator/apollo/trunk/src/java/org/apache/ws/resource/properties/ResourceProperty.java (original) +++ incubator/apollo/trunk/src/java/org/apache/ws/resource/properties/ResourceProperty.java Sat Jan 22 16:18:40 2005 @@ -145,4 +145,7 @@ */ ResourcePropertyCallback getCallBack(); + ResourcePropertyValueChangeListener getChangeListener(); + + void setChangeListener( ResourcePropertyValueChangeListener listenerValue ); } Added: incubator/apollo/trunk/src/java/org/apache/ws/resource/properties/ResourcePropertyValueChangeEvent.java Url: http://svn.apache.org/viewcvs/incubator/apollo/trunk/src/java/org/apache/ws/resource/properties/ResourcePropertyValueChangeEvent.java?view=auto&rev=126169 ============================================================================== --- (empty file) +++ incubator/apollo/trunk/src/java/org/apache/ws/resource/properties/ResourcePropertyValueChangeEvent.java Sat Jan 22 16:18:40 2005 @@ -0,0 +1,38 @@ +/* + * 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; + +/** + * @author Ian P. Springer (Hewlett-Packard Company) + */ +public interface ResourcePropertyValueChangeEvent +{ + + /** + * Returns the old value of the property, as an array of property elements; may be null. + * + * @return the old value of the property, as an array of property elements; may be null + */ + Object[] getOldValue(); + + /** + * Returns the new value of the property, as an array of property elements; may be null. + * + * @return the new value of the property, as an array of property elements; may be null + */ + Object[] getNewValue(); + +} Added: incubator/apollo/trunk/src/java/org/apache/ws/resource/properties/ResourcePropertyValueChangeListener.java Url: http://svn.apache.org/viewcvs/incubator/apollo/trunk/src/java/org/apache/ws/resource/properties/ResourcePropertyValueChangeListener.java?view=auto&rev=126169 ============================================================================== --- (empty file) +++ incubator/apollo/trunk/src/java/org/apache/ws/resource/properties/ResourcePropertyValueChangeListener.java Sat Jan 22 16:18:40 2005 @@ -0,0 +1,35 @@ +/* + * 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; + +import java.util.EventListener; + +/** + * @author Ian P. Springer (Hewlett-Packard Company) + */ +public interface ResourcePropertyValueChangeListener extends EventListener +{ + + /** + * A method that is called whenever a particular resource property's value changes as + * the result of the Insert, Delete, or Update component of a SetResourceProperties + * request. + * + * @param propValueChangeEvent + */ + void propertyChanged( ResourcePropertyValueChangeEvent propValueChangeEvent ); + +} Modified: incubator/apollo/trunk/src/java/org/apache/ws/resource/properties/impl/XmlBeansResourceProperty.java Url: http://svn.apache.org/viewcvs/incubator/apollo/trunk/src/java/org/apache/ws/resource/properties/impl/XmlBeansResourceProperty.java?view=diff&rev=126169&p1=incubator/apollo/trunk/src/java/org/apache/ws/resource/properties/impl/XmlBeansResourceProperty.java&r1=126168&p2=incubator/apollo/trunk/src/java/org/apache/ws/resource/properties/impl/XmlBeansResourceProperty.java&r2=126169 ============================================================================== --- incubator/apollo/trunk/src/java/org/apache/ws/resource/properties/impl/XmlBeansResourceProperty.java (original) +++ incubator/apollo/trunk/src/java/org/apache/ws/resource/properties/impl/XmlBeansResourceProperty.java Sat Jan 22 16:18:40 2005 @@ -23,12 +23,14 @@ import org.apache.ws.resource.properties.ResourcePropertyCallback; import org.apache.ws.resource.properties.ResourcePropertyMetaData; import org.apache.ws.resource.properties.ResourcePropertySet; +import org.apache.ws.resource.properties.ResourcePropertyValueChangeListener; import org.apache.ws.util.XmlBeanUtils; import org.apache.ws.util.i18n.Messages; import org.apache.xmlbeans.XmlAnySimpleType; import org.apache.xmlbeans.XmlObject; import org.apache.xmlbeans.XmlOptions; import org.w3c.dom.Element; + import javax.xml.soap.SOAPElement; import java.util.ArrayList; import java.util.Iterator; @@ -41,307 +43,318 @@ * @author Ian P. Springer */ public class XmlBeansResourceProperty - implements ResourceProperty + implements ResourceProperty { - private static final Messages MSG = MessagesImpl.getInstance( ); + private static final Messages MSG = MessagesImpl.getInstance(); - private ResourcePropertyMetaData m_metaData; - private XmlBeansResourcePropertySet m_propSet; - private List m_propElems = new ArrayList( ); - private ResourcePropertyCallback m_callBack; - - /** - * Creates a new [EMAIL PROTECTED] XmlBeansResourceProperty} object. - * - * @param metaData DOCUMENT_ME - * @param propSet DOCUMENT_ME - */ - public XmlBeansResourceProperty( ResourcePropertyMetaData metaData, - XmlBeansResourcePropertySet propSet ) - { - m_metaData = metaData; - m_propSet = propSet; - } - - /** - * DOCUMENT_ME - * - * @return DOCUMENT_ME - */ - public ResourcePropertyCallback getCallBack( ) - { - return m_callBack; - } - - /** - * DOCUMENT_ME - * - * @param callback DOCUMENT_ME - */ - public void setCallback( ResourcePropertyCallback callback ) - { - m_callBack = callback; - } - - /** - * @return - */ - public boolean isEmpty( ) - { - return m_propElems.isEmpty( ); - } - - /** - * DOCUMENT_ME - * - * @return DOCUMENT_ME - */ - public ResourcePropertyMetaData getMetaData( ) - { - return m_metaData; - } - - /** - * @return - */ - public ResourcePropertySet getSet( ) - { - return m_propSet; - } - - /** - * DOCUMENT_ME - * - * @param propElem DOCUMENT_ME - * - * @throws MetaDataViolationException if the name of the element to be added does not match the name associated with this property - */ - public void add( Object propElem ) - { - XmlObject propXBean = toPropXBean( propElem ); - trimValue( propXBean ); - load( propXBean ); - XmlBeanUtils.addChildElement( m_propSet.toXmlObject( ), - propXBean ); - } - - /** - * @see org.apache.ws.resource.properties.ResourceProperty#clear() - */ - public void clear( ) - { - XmlBeanUtils.removeChildElements( m_propSet.toXmlObject( ), - m_metaData.getName( ) ); - m_propElems.clear( ); - } - - /** - * DOCUMENT_ME - * - * @param index DOCUMENT_ME - * - * @return DOCUMENT_ME - */ - public Object get( int index ) - { - return m_propElems.get( index ); - } - - /** - * DOCUMENT_ME - * - * @return DOCUMENT_ME - */ - public Iterator iterator( ) - { - return m_propElems.iterator( ); - } - - /** - * This method loads a property element XMLBean, which is already in the resource properties document, into this - * [EMAIL PROTECTED] XmlBeansResourceProperty}. It is called by [EMAIL PROTECTED] XmlBeansResourcePropertySet#XmlBeansResourcePropertySet(org.apache.xmlbeans.XmlObject)} - * to populate newly created [EMAIL PROTECTED] XmlBeansResourceProperty} objects. - * - * @param propXBean a property element XMLBean that is already in the resource properties document - * - * @throws MetaDataViolationException if the name of the element to be added does not match the name associated with this property - */ - public void load( XmlObject propXBean ) - { - if ( !XmlBeanUtils.getName( propXBean ).equals( m_metaData.getName( ) ) ) - { - throw new MetaDataViolationException( MSG.getMessage( Keys.PROP_MUST_BE_NAMED, - m_metaData.getName( ) ) ); - } - m_propElems.add( propXBean ); - } - - /** - * DOCUMENT_ME - * - * @param propElem DOCUMENT_ME - * - * @return DOCUMENT_ME - */ - public boolean remove( Object propElem ) - { - XmlObject propXBeanToRemove; - try - { - propXBeanToRemove = XmlBeanUtils.toXmlObject( propElem ); - } - catch ( Exception e ) - { - throw new IllegalArgumentException( MSG.getMessage( Keys.UNABLE_TO_CONVERT_TO_XMLOBJECT ) ); - } - - if ( propXBeanToRemove.schemaType( ).getName( ).equals( m_metaData.getName( ) ) ) - { - throw new IllegalArgumentException( MSG.getMessage( Keys.PROP_ELEM_TO_REMOVE_MST_B_NAMED, - m_metaData.getName( ) ) ); - } - - for ( int index = 0; index < m_propElems.size( ); index++ ) - { - XmlObject propXBean = (org.apache.xmlbeans.XmlObject) m_propElems.get( index ); - if ( propXBean.valueEquals( propXBeanToRemove ) ) - { - XmlBeanUtils.remove( propXBean ); - m_propElems.remove( index ); - return true; - } - } - - return false; - } - - /** - * @see ResourceProperty#set(int, Object) - */ - public void set( int index, - Object propElem ) - { - XmlObject propXBean = toPropXBean( propElem ); - if ( !XmlBeanUtils.getName( propXBean ).equals( m_metaData.getName( ) ) ) - { - throw new IllegalArgumentException( MSG.getMessage( Keys.PROP_SET_MST_B_NAMED, - m_metaData.getName( ) ) ); - } - - if ( index >= m_propElems.size( ) ) - { - throw new IndexOutOfBoundsException( MSG.getMessage( Keys.INDEX_MST_B_GTR0, - Integer.toString( m_propElems.size( ) ) ) ); - } - - XmlObject currentPropXBean = (XmlObject) m_propElems.get( index ); - trimValue( propXBean ); - currentPropXBean.set( propXBean ); - } - - /** - * @see ResourceProperty#size() - */ - public int size( ) - { - return m_propElems.size( ); - } - - /** - * @see ResourceProperty#toElements() - */ - public Element[] toElements( ) - throws SerializationException - { - List elems = new ArrayList( ); - for ( int i = 0; i < m_propElems.size( ); i++ ) - { - XmlObject propXBean = (XmlObject) m_propElems.get( i ); - elems.add( propXBean.newDomNode( ) ); - } - - return (Element[]) elems.toArray( new Element[0] ); - } - - /** - * DOCUMENT_ME - * - * @return DOCUMENT_ME - * - * @throws SerializationException DOCUMENT_ME - */ - public SOAPElement[] toSOAPElements( ) - throws SerializationException - { - try - { - return XmlBeanUtils.toSOAPElementArray( (XmlObject[]) m_propElems.toArray( new XmlObject[0] ) ); - } - catch ( Exception e ) - { - throw new SerializationException( e ); - } - } - - /** - * DOCUMENT_ME - * - * @return DOCUMENT_ME - */ - public String toString( ) - { - return toXML( ); - } - - /** - * DOCUMENT_ME - * - * @return DOCUMENT_ME - */ - public String toXML( ) - { - StringBuffer buf = new StringBuffer( ); - for ( int i = 0; i < m_propElems.size( ); i++ ) - { - XmlObject propXBean = (XmlObject) m_propElems.get( i ); - buf.append( propXBean.xmlText( new XmlOptions().setSaveOuter().setSavePrettyPrint() ) ); - } - return buf.toString( ); - } - - /** - * @return - */ - public XmlObject[] toXmlObjects( ) - { - return (XmlObject[]) m_propElems.toArray( new XmlObject[0] ); - } - - private XmlObject toPropXBean( Object propElem ) - { - XmlObject propXBean; - try - { - propXBean = XmlBeanUtils.getRootElement( XmlBeanUtils.toXmlObject( propElem ) ); - } - catch ( Exception e ) - { - throw new IllegalArgumentException( MSG.getMessage( Keys.UNABLE_TO_CONVERT_TO_XMLOBJECT ) ); - } - - return propXBean; - } - - private void trimValue( XmlObject propXBean ) - { - // TODO: make this a configurable option - if ( propXBean instanceof XmlAnySimpleType ) - { - XmlAnySimpleType simplePropXBean = (XmlAnySimpleType) propXBean; - String untrimmedValue = simplePropXBean.getStringValue( ); - String trimmedValue = ( untrimmedValue != null ) ? untrimmedValue.trim( ) : null; - simplePropXBean.setStringValue( trimmedValue ); - } - } + private ResourcePropertyMetaData m_metaData; + private XmlBeansResourcePropertySet m_propSet; + private List m_propElems = new ArrayList(); + private ResourcePropertyCallback m_callBack; + private ResourcePropertyValueChangeListener m_changeListener; + + /** + * Creates a new [EMAIL PROTECTED] XmlBeansResourceProperty} object. + * + * @param metaData DOCUMENT_ME + * @param propSet DOCUMENT_ME + */ + public XmlBeansResourceProperty( ResourcePropertyMetaData metaData, + XmlBeansResourcePropertySet propSet ) + { + m_metaData = metaData; + m_propSet = propSet; + } + + /** + * DOCUMENT_ME + * + * @return DOCUMENT_ME + */ + public ResourcePropertyCallback getCallBack() + { + return m_callBack; + } + + /** + * DOCUMENT_ME + * + * @param callback DOCUMENT_ME + */ + public void setCallback( ResourcePropertyCallback callback ) + { + m_callBack = callback; + } + + /** + * @return + */ + public boolean isEmpty() + { + return m_propElems.isEmpty(); + } + + /** + * DOCUMENT_ME + * + * @return DOCUMENT_ME + */ + public ResourcePropertyMetaData getMetaData() + { + return m_metaData; + } + + /** + * @return + */ + public ResourcePropertySet getSet() + { + return m_propSet; + } + + /** + * DOCUMENT_ME + * + * @param propElem DOCUMENT_ME + * + * @throws MetaDataViolationException if the name of the element to be added does not match the name associated with this property + */ + public void add( Object propElem ) + { + XmlObject propXBean = toPropXBean( propElem ); + trimValue( propXBean ); + load( propXBean ); + XmlBeanUtils.addChildElement( m_propSet.toXmlObject(), + propXBean ); + } + + /** + * @see org.apache.ws.resource.properties.ResourceProperty#clear() + */ + public void clear() + { + XmlBeanUtils.removeChildElements( m_propSet.toXmlObject(), + m_metaData.getName() ); + m_propElems.clear(); + } + + /** + * DOCUMENT_ME + * + * @param index DOCUMENT_ME + * + * @return DOCUMENT_ME + */ + public Object get( int index ) + { + return m_propElems.get( index ); + } + + /** + * DOCUMENT_ME + * + * @return DOCUMENT_ME + */ + public Iterator iterator() + { + return m_propElems.iterator(); + } + + /** + * This method loads a property element XMLBean, which is already in the resource properties document, into this + * [EMAIL PROTECTED] XmlBeansResourceProperty}. It is called by [EMAIL PROTECTED] XmlBeansResourcePropertySet#XmlBeansResourcePropertySet(org.apache.xmlbeans.XmlObject)} + * to populate newly created [EMAIL PROTECTED] XmlBeansResourceProperty} objects. + * + * @param propXBean a property element XMLBean that is already in the resource properties document + * + * @throws MetaDataViolationException if the name of the element to be added does not match the name associated with this property + */ + public void load( XmlObject propXBean ) + { + if ( !XmlBeanUtils.getName( propXBean ).equals( m_metaData.getName() ) ) + { + throw new MetaDataViolationException( MSG.getMessage( Keys.PROP_MUST_BE_NAMED, + m_metaData.getName() ) ); + } + m_propElems.add( propXBean ); + } + + /** + * DOCUMENT_ME + * + * @param propElem DOCUMENT_ME + * + * @return DOCUMENT_ME + */ + public boolean remove( Object propElem ) + { + XmlObject propXBeanToRemove; + try + { + propXBeanToRemove = XmlBeanUtils.toXmlObject( propElem ); + } + catch ( Exception e ) + { + throw new IllegalArgumentException( MSG.getMessage( Keys.UNABLE_TO_CONVERT_TO_XMLOBJECT ) ); + } + + if ( propXBeanToRemove.schemaType().getName().equals( m_metaData.getName() ) ) + { + throw new IllegalArgumentException( MSG.getMessage( Keys.PROP_ELEM_TO_REMOVE_MST_B_NAMED, + m_metaData.getName() ) ); + } + + for ( int index = 0; index < m_propElems.size(); index++ ) + { + XmlObject propXBean = (org.apache.xmlbeans.XmlObject) m_propElems.get( index ); + if ( propXBean.valueEquals( propXBeanToRemove ) ) + { + XmlBeanUtils.remove( propXBean ); + m_propElems.remove( index ); + return true; + } + } + + return false; + } + + /** + * @see ResourceProperty#set(int, Object) + */ + public void set( int index, + Object propElem ) + { + XmlObject propXBean = toPropXBean( propElem ); + if ( !XmlBeanUtils.getName( propXBean ).equals( m_metaData.getName() ) ) + { + throw new IllegalArgumentException( MSG.getMessage( Keys.PROP_SET_MST_B_NAMED, + m_metaData.getName() ) ); + } + + if ( index >= m_propElems.size() ) + { + throw new IndexOutOfBoundsException( MSG.getMessage( Keys.INDEX_MST_B_GTR0, + Integer.toString( m_propElems.size() ) ) ); + } + + XmlObject currentPropXBean = (XmlObject) m_propElems.get( index ); + trimValue( propXBean ); + currentPropXBean.set( propXBean ); + } + + /** + * @see ResourceProperty#size() + */ + public int size() + { + return m_propElems.size(); + } + + /** + * @see ResourceProperty#toElements() + */ + public Element[] toElements() + throws SerializationException + { + List elems = new ArrayList(); + for ( int i = 0; i < m_propElems.size(); i++ ) + { + XmlObject propXBean = (XmlObject) m_propElems.get( i ); + elems.add( propXBean.newDomNode() ); + } + + return (Element[]) elems.toArray( new Element[0] ); + } + + /** + * DOCUMENT_ME + * + * @return DOCUMENT_ME + * + * @throws SerializationException DOCUMENT_ME + */ + public SOAPElement[] toSOAPElements() + throws SerializationException + { + try + { + return XmlBeanUtils.toSOAPElementArray( (XmlObject[]) m_propElems.toArray( new XmlObject[0] ) ); + } + catch ( Exception e ) + { + throw new SerializationException( e ); + } + } + + /** + * DOCUMENT_ME + * + * @return DOCUMENT_ME + */ + public String toString() + { + return toXML(); + } + + /** + * DOCUMENT_ME + * + * @return DOCUMENT_ME + */ + public String toXML() + { + StringBuffer buf = new StringBuffer(); + for ( int i = 0; i < m_propElems.size(); i++ ) + { + XmlObject propXBean = (XmlObject) m_propElems.get( i ); + buf.append( propXBean.xmlText( new XmlOptions().setSaveOuter().setSavePrettyPrint() ) ); + } + return buf.toString(); + } + + /** + * @return + */ + public XmlObject[] toXmlObjects() + { + return (XmlObject[]) m_propElems.toArray( new XmlObject[0] ); + } + + public ResourcePropertyValueChangeListener getChangeListener() + { + return m_changeListener; + } + + public void setChangeListener( ResourcePropertyValueChangeListener changeListener ) + { + m_changeListener = changeListener; + } + + private XmlObject toPropXBean( Object propElem ) + { + XmlObject propXBean; + try + { + propXBean = XmlBeanUtils.getRootElement( XmlBeanUtils.toXmlObject( propElem ) ); + } + catch ( Exception e ) + { + throw new IllegalArgumentException( MSG.getMessage( Keys.UNABLE_TO_CONVERT_TO_XMLOBJECT ) ); + } + + return propXBean; + } + + private void trimValue( XmlObject propXBean ) + { + // TODO: make this a configurable option + if ( propXBean instanceof XmlAnySimpleType ) + { + XmlAnySimpleType simplePropXBean = (XmlAnySimpleType) propXBean; + String untrimmedValue = simplePropXBean.getStringValue(); + String trimmedValue = ( untrimmedValue != null ) ? untrimmedValue.trim() : null; + simplePropXBean.setStringValue( trimmedValue ); + } + } } Modified: incubator/apollo/trunk/src/java/org/apache/ws/resource/properties/v1_2/porttype/impl/SetResourcePropertiesProvider.java Url: http://svn.apache.org/viewcvs/incubator/apollo/trunk/src/java/org/apache/ws/resource/properties/v1_2/porttype/impl/SetResourcePropertiesProvider.java?view=diff&rev=126169&p1=incubator/apollo/trunk/src/java/org/apache/ws/resource/properties/v1_2/porttype/impl/SetResourcePropertiesProvider.java&r1=126168&p2=incubator/apollo/trunk/src/java/org/apache/ws/resource/properties/v1_2/porttype/impl/SetResourcePropertiesProvider.java&r2=126169 ============================================================================== --- incubator/apollo/trunk/src/java/org/apache/ws/resource/properties/v1_2/porttype/impl/SetResourcePropertiesProvider.java (original) +++ incubator/apollo/trunk/src/java/org/apache/ws/resource/properties/v1_2/porttype/impl/SetResourcePropertiesProvider.java Sat Jan 22 16:18:40 2005 @@ -41,6 +41,7 @@ import org.oasisOpen.docs.wsrf.x2004.x06.wsrfWSResourceProperties12Draft01.UpdateType; import javax.xml.namespace.QName; +import java.util.Iterator; /** * LOG-DONE An operation provider for wsrp:SetResourceProperties. @@ -139,7 +140,6 @@ } throwFaultIfPropertyIsReadOnly( prop ); throwFaultIfDeletionViolatesSchema( prop ); - //refreshProperty( prop ); try { deletePropertyCallback( prop ); @@ -148,7 +148,13 @@ { throw new SetResourcePropertyRequestFailedFaultException( re.toString() ); } + Object[] oldValue = getValue( prop ); prop.clear(); + Object[] newValue = null; + if ( prop.getChangeListener() != null ) + { + firePropChangeEvent( prop, oldValue, newValue ); + } } /** @@ -198,6 +204,7 @@ throw new SetResourcePropertyRequestFailedFaultException( re.toString() ); } + Object[] oldValue = getValue( prop ); for ( int i = 0; i < propElemsToBeInserted.length; i++ ) { try @@ -209,14 +216,16 @@ throw new InvalidSetResourcePropertiesRequestContentFaultException( mdve ); } } + Object[] newValue = getValue( prop ); + if ( prop.getChangeListener() != null ) + { + firePropChangeEvent( prop, oldValue, newValue ); + } } - private ResourceProperty createAnyProperty(QName propName) + private void firePropChangeEvent( ResourceProperty prop, Object[] oldValue, Object[] newValue ) { - ResourceProperty prop; - ResourcePropertyMetaData propMetaData = new AnyResourcePropertyMetaData( propName ); - prop = propMetaData.create( getProperties() ); - return prop; + prop.getChangeListener().propertyChanged( new XmlBeansResourcePropertyValueChangeEvent( oldValue, newValue ) ); } /** @@ -241,8 +250,6 @@ QName propName = XmlBeanUtils.getName( newPropElems[0] ); ResourceProperty prop = getProperty( propName ); - //refreshProperty( prop ); - throwFaultIfPropertyIsReadOnly( prop ); throwFaultIfElementNamesHeterogenous( newPropElems ); throwFaultIfUpdateViolatesSchema( prop, newPropElems ); @@ -256,9 +263,10 @@ throw new SetResourcePropertyRequestFailedFaultException( re.toString() ); } + Object[] oldValue = getValue( prop ); + // TODO: we might need to clone the oldValue elems, since we might be destroying them when we call clear() below try { - prop.clear(); for ( int i = 0; i < newPropElems.length; i++ ) { @@ -269,6 +277,29 @@ { throw new InvalidSetResourcePropertiesRequestContentFaultException( mdve ); } + Object[] newValue = getValue( prop ); + if ( prop.getChangeListener() != null ) + { + firePropChangeEvent( prop, oldValue, newValue ); + } + } + + private ResourceProperty createAnyProperty(QName propName) + { + ResourcePropertyMetaData propMetaData = new AnyResourcePropertyMetaData( propName ); + return propMetaData.create( getProperties() ); + } + + private Object[] getValue( ResourceProperty prop ) + { + Object[] value = new Object[prop.size()]; + Iterator propElemIter = prop.iterator(); + int i = 0; + while ( propElemIter.hasNext() ) + { + value[i++] = propElemIter.next(); + } + return value; } private ResourceProperty getProperty( QName propName ) @@ -283,7 +314,6 @@ throw new InvalidResourcePropertyQNameFaultException( propName ); } } - return prop; } @@ -313,7 +343,8 @@ } private void throwFaultIfInsertionViolatesSchema( ResourceProperty prop, XmlObject[] propElemsToBeInserted ) - { //todo probably need to check this for xsd:any to check for possible violations + { + //todo probably need to check this for xsd:any to check for possible violations if ( prop.getMetaData().getMaxOccurs() != -1 &&( prop.size() + propElemsToBeInserted.length ) > prop.getMetaData().getMaxOccurs() ) { throw new InvalidSetResourcePropertiesRequestContentFaultException( MSG.getMessage( Keys.ERROR_PROPERTY_INSERT_VIOLATES_SCHEMA, Added: incubator/apollo/trunk/src/java/org/apache/ws/resource/properties/v1_2/porttype/impl/XmlBeansResourcePropertyValueChangeEvent.java Url: http://svn.apache.org/viewcvs/incubator/apollo/trunk/src/java/org/apache/ws/resource/properties/v1_2/porttype/impl/XmlBeansResourcePropertyValueChangeEvent.java?view=auto&rev=126169 ============================================================================== --- (empty file) +++ incubator/apollo/trunk/src/java/org/apache/ws/resource/properties/v1_2/porttype/impl/XmlBeansResourcePropertyValueChangeEvent.java Sat Jan 22 16:18:40 2005 @@ -0,0 +1,88 @@ +/* + * 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.ws.XmlObjectWrapper; +import org.apache.ws.resource.properties.ResourcePropertyValueChangeEvent; +import org.apache.ws.util.XmlBeanUtils; +import org.apache.xmlbeans.XmlObject; +import org.oasisOpen.docs.wsrf.x2004.x06.wsrfWSResourceProperties12Draft01.ResourcePropertyValueChangeNotificationDocument; +import org.oasisOpen.docs.wsrf.x2004.x06.wsrfWSResourceProperties12Draft01.ResourcePropertyValueChangeNotificationType; + +/** + * @author Ian P. Springer (Hewlett-Packard Company) + */ +public class XmlBeansResourcePropertyValueChangeEvent implements ResourcePropertyValueChangeEvent, XmlObjectWrapper +{ + + private Object[] m_oldValue; + private Object[] m_newValue; + private ResourcePropertyValueChangeNotificationDocument m_propValueChangeNotifDocXBean; + + public XmlBeansResourcePropertyValueChangeEvent( Object[] oldValue, Object[] newValue ) + { + m_oldValue = oldValue; + m_newValue = newValue; + m_propValueChangeNotifDocXBean = buildPropValueChangeNotifDocXmlBean( oldValue, newValue ); + } + + public Object[] getOldValue() + { + return m_oldValue; + } + + public Object[] getNewValue() + { + return m_newValue; + } + + public XmlObject getXmlObject() + { + return m_propValueChangeNotifDocXBean; + } + + private ResourcePropertyValueChangeNotificationDocument buildPropValueChangeNotifDocXmlBean( Object[] oldValue, Object[] newValue ) + { + ResourcePropertyValueChangeNotificationDocument propValueChangeNotifDocXBean = ResourcePropertyValueChangeNotificationDocument.Factory.newInstance(); + ResourcePropertyValueChangeNotificationType propValueChangeNotifXBean = propValueChangeNotifDocXBean.addNewResourcePropertyValueChangeNotification(); + ResourcePropertyValueChangeNotificationType.OldValue oldValueXBean = propValueChangeNotifXBean.addNewOldValue(); + if ( oldValue != null ) + { + for ( int i = 0; i < oldValue.length; i++ ) + { + XmlBeanUtils.addChildElement( oldValueXBean, (XmlObject) oldValue[i] ); + } + } + else + { + oldValueXBean.setNil(); + } + ResourcePropertyValueChangeNotificationType.NewValue newValueXBean = propValueChangeNotifXBean.addNewNewValue(); + if ( newValue != null ) + { + for ( int i = 0; i < oldValue.length; i++ ) + { + XmlBeanUtils.addChildElement( newValueXBean, (XmlObject) newValue[i] ); + } + } + else + { + newValueXBean.setNil(); + } + return propValueChangeNotifDocXBean; + } + +} --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
