You are viewing a plain text version of this content. The canonical link for it is here.
Posted to wsrf-dev@ws.apache.org by ip...@apache.org on 2005/02/11 23:14:53 UTC

svn commit: r153464 - in incubator/apollo/trunk/src: java/org/apache/ws/resource/properties/impl/ java/org/apache/ws/util/ test/org/apache/ws/resource/properties/

Author: ips
Date: Fri Feb 11 14:14:52 2005
New Revision: 153464

URL: http://svn.apache.org/viewcvs?view=rev&rev=153464
Log:
beginnings of WS-RMD impl

Added:
    incubator/apollo/trunk/src/test/org/apache/ws/resource/properties/SushiMetadata.wsrmd
Modified:
    incubator/apollo/trunk/src/java/org/apache/ws/resource/properties/impl/XmlBeansResourcePropertyMetaData.java
    incubator/apollo/trunk/src/java/org/apache/ws/resource/properties/impl/XmlBeansResourcePropertySetMetaData.java
    incubator/apollo/trunk/src/java/org/apache/ws/util/XmlBeanUtils.java

Modified: incubator/apollo/trunk/src/java/org/apache/ws/resource/properties/impl/XmlBeansResourcePropertyMetaData.java
URL: http://svn.apache.org/viewcvs/incubator/apollo/trunk/src/java/org/apache/ws/resource/properties/impl/XmlBeansResourcePropertyMetaData.java?view=diff&r1=153463&r2=153464
==============================================================================
--- incubator/apollo/trunk/src/java/org/apache/ws/resource/properties/impl/XmlBeansResourcePropertyMetaData.java (original)
+++ incubator/apollo/trunk/src/java/org/apache/ws/resource/properties/impl/XmlBeansResourcePropertyMetaData.java Fri Feb 11 14:14:52 2005
@@ -20,136 +20,150 @@
 import org.apache.ws.resource.properties.ResourcePropertySet;
 import org.apache.ws.resource.properties.ResourcePropertySetMetaData;
 import org.apache.xmlbeans.SchemaProperty;
+import org.oasisOpen.docs.wsrf.x2004.x10.wsrfWSResourceMetadataDescriptor10Draft01.ModifiabilityType;
+import org.oasisOpen.docs.wsrf.x2004.x10.wsrfWSResourceMetadataDescriptor10Draft01.PropertyType;
+
 import javax.xml.namespace.QName;
 import java.math.BigInteger;
 
 /**
- * LOG-DONE
- * Apache XMLBeans-based implementation of resource property metadata.
+ * LOG-DONE Apache XMLBeans-based implementation of resource property metadata.
  *
  * @author Ian P. Springer
  */
 public class XmlBeansResourcePropertyMetaData
-   implements ResourcePropertyMetaData
+        implements ResourcePropertyMetaData
 {
-   //private static final Log LOG = LogFactory.getLog( XmlBeansResourcePropertyMetaData.class );
-   private SchemaProperty              m_schemaProp;
-   private boolean                     m_isReadOnly;
-   private ResourcePropertySetMetaData m_setMetaData;
-
-   /**
-    * Creates a new {@link XmlBeansResourcePropertyMetaData} object.
-    *
-    * @param schemaProp DOCUMENT_ME
-    * @param isReadOnly DOCUMENT_ME
-    */
-   public XmlBeansResourcePropertyMetaData( SchemaProperty schemaProp,
-                                            boolean        isReadOnly )
-   {
-      m_schemaProp    = schemaProp;
-      m_isReadOnly    = isReadOnly;
-   }
-
-   /**
-    * Creates a new {@link XmlBeansResourcePropertyMetaData} object.
-    *
-    * @param schemaProp DOCUMENT_ME
-    */
-   public XmlBeansResourcePropertyMetaData( SchemaProperty schemaProp )
-   {
-      this( schemaProp, false );
-   }
-
-   /**
-    * DOCUMENT_ME
-    *
-    * @return DOCUMENT_ME
-    */
-   public int getMaxOccurs(  )
-   {
-      BigInteger maxOccurs = m_schemaProp.getMaxOccurs(  );
-      return ( maxOccurs != null ) ? maxOccurs.intValue(  ) : ( -1 );
-   }
-
-   /**
-    * DOCUMENT_ME
-    *
-    * @return DOCUMENT_ME
-    */
-   public int getMinOccurs(  )
-   {
-      return m_schemaProp.getMinOccurs(  ).intValue(  );
-   }
-
-   /**
-    * DOCUMENT_ME
-    *
-    * @return DOCUMENT_ME
-    */
-   public QName getName(  )
-   {
-      return m_schemaProp.getName(  );
-   }
-
-   /**
-    * DOCUMENT_ME
-    *
-    * @return DOCUMENT_ME
-    */
-   public boolean isNillable(  )
-   {
-      return m_schemaProp.hasNillable(  ) == SchemaProperty.CONSISTENTLY;
-   }
-
-   /**
-    * DOCUMENT_ME
-    *
-    * @return DOCUMENT_ME
-    */
-   public boolean isReadOnly(  )
-   {
-      return m_isReadOnly;
-   }
-
-   /**
-    * DOCUMENT_ME
-    *
-    * @return DOCUMENT_ME
-    */
-   public ResourcePropertySetMetaData getSetMetaData(  )
-   {
-      synchronized ( this )
-      {
-         if ( m_setMetaData == null )
-         {
-            m_setMetaData = new XmlBeansResourcePropertySetMetaData( m_schemaProp.getContainerType(  ) );
-         }
-      }
-
-      return m_setMetaData;
-   }
-
-   /**
-    * DOCUMENT_ME
-    *
-    * @return DOCUMENT_ME
-    */
-   public Class getType(  )
-   {
-      return m_schemaProp.getType(  ).getJavaClass(  );
-   }
-
-   /**
-    * DOCUMENT_ME
-    *
-    * @param propSet DOCUMENT_ME
-    *
-    * @return DOCUMENT_ME
-    */
-   public ResourceProperty create( ResourcePropertySet propSet )
-   {
-      return new XmlBeansResourceProperty( this, (XmlBeansResourcePropertySet) propSet );
-   }
+    //private static final Log LOG = LogFactory.getLog( XmlBeansResourcePropertyMetaData.class );
+    private SchemaProperty m_schemaProp;
+    private boolean m_isReadOnly;
+    private ResourcePropertySetMetaData m_setMetaData;
+
+    /**
+     * Creates a new {@link XmlBeansResourcePropertyMetaData} object.
+     *
+     * @param schemaProp DOCUMENT_ME
+     */
+    public XmlBeansResourcePropertyMetaData( SchemaProperty schemaProp )
+    {
+        this( schemaProp, false );
+    }
+
+    /**
+     * Creates a new {@link XmlBeansResourcePropertyMetaData} object based on the specified
+     * xsd:element schema property and wsrmd:Property.
+     *
+     * @param schemaProp DOCUMENT_ME
+     * @param propDesc
+     */
+    public XmlBeansResourcePropertyMetaData( SchemaProperty schemaProp, PropertyType propDesc )
+    {
+        this( schemaProp, propDesc != null ? propDesc.getModifiability().intValue() == ModifiabilityType.INT_READ_ONLY : false );
+    }
+
+    /**
+     * Creates a new {@link XmlBeansResourcePropertyMetaData} object.
+     *
+     * @param schemaProp DOCUMENT_ME
+     * @param isReadOnly DOCUMENT_ME
+     */
+    public XmlBeansResourcePropertyMetaData( SchemaProperty schemaProp,
+                                             boolean isReadOnly )
+    {
+        m_schemaProp = schemaProp;
+        m_isReadOnly = isReadOnly;
+    }
+    
+    /**
+     * DOCUMENT_ME
+     *
+     * @return DOCUMENT_ME
+     */
+    public int getMaxOccurs()
+    {
+        BigInteger maxOccurs = m_schemaProp.getMaxOccurs();
+        return ( maxOccurs != null ) ? maxOccurs.intValue() : ( -1 );
+    }
+
+    /**
+     * DOCUMENT_ME
+     *
+     * @return DOCUMENT_ME
+     */
+    public int getMinOccurs()
+    {
+        return m_schemaProp.getMinOccurs().intValue();
+    }
+
+    /**
+     * DOCUMENT_ME
+     *
+     * @return DOCUMENT_ME
+     */
+    public QName getName()
+    {
+        return m_schemaProp.getName();
+    }
+
+    /**
+     * DOCUMENT_ME
+     *
+     * @return DOCUMENT_ME
+     */
+    public boolean isNillable()
+    {
+        return m_schemaProp.hasNillable() == SchemaProperty.CONSISTENTLY;
+    }
+
+    /**
+     * DOCUMENT_ME
+     *
+     * @return DOCUMENT_ME
+     */
+    public boolean isReadOnly()
+    {
+        return m_isReadOnly;
+    }
+
+    /**
+     * DOCUMENT_ME
+     *
+     * @return DOCUMENT_ME
+     */
+    public ResourcePropertySetMetaData getSetMetaData()
+    {
+        synchronized ( this )
+        {
+            if ( m_setMetaData == null )
+            {
+                m_setMetaData = new XmlBeansResourcePropertySetMetaData( m_schemaProp.getContainerType() );
+            }
+        }
+
+        return m_setMetaData;
+    }
+
+    /**
+     * DOCUMENT_ME
+     *
+     * @return DOCUMENT_ME
+     */
+    public Class getType()
+    {
+        return m_schemaProp.getType().getJavaClass();
+    }
+
+    /**
+     * DOCUMENT_ME
+     *
+     * @param propSet DOCUMENT_ME
+     *
+     * @return DOCUMENT_ME
+     */
+    public ResourceProperty create( ResourcePropertySet propSet )
+    {
+        return new XmlBeansResourceProperty( this, (XmlBeansResourcePropertySet) propSet );
+    }
 
     public boolean isAny()
     {

Modified: incubator/apollo/trunk/src/java/org/apache/ws/resource/properties/impl/XmlBeansResourcePropertySetMetaData.java
URL: http://svn.apache.org/viewcvs/incubator/apollo/trunk/src/java/org/apache/ws/resource/properties/impl/XmlBeansResourcePropertySetMetaData.java?view=diff&r1=153463&r2=153464
==============================================================================
--- incubator/apollo/trunk/src/java/org/apache/ws/resource/properties/impl/XmlBeansResourcePropertySetMetaData.java (original)
+++ incubator/apollo/trunk/src/java/org/apache/ws/resource/properties/impl/XmlBeansResourcePropertySetMetaData.java Fri Feb 11 14:14:52 2005
@@ -22,10 +22,13 @@
 import org.apache.ws.resource.properties.ResourcePropertyMetaData;
 import org.apache.ws.resource.properties.ResourcePropertySet;
 import org.apache.ws.resource.properties.ResourcePropertySetMetaData;
+import org.apache.ws.util.XmlBeanUtils;
 import org.apache.ws.util.i18n.Messages;
 import org.apache.xmlbeans.SchemaProperty;
 import org.apache.xmlbeans.SchemaType;
 import org.apache.xmlbeans.XmlObject;
+import org.oasisOpen.docs.wsrf.x2004.x10.wsrfWSResourceMetadataDescriptor10Draft01.MetadataDescriptorType;
+import org.oasisOpen.docs.wsrf.x2004.x10.wsrfWSResourceMetadataDescriptor10Draft01.PropertyType;
 
 import javax.xml.namespace.QName;
 import java.lang.reflect.Method;
@@ -38,105 +41,133 @@
  * @author Ian P. Springer
  */
 public class XmlBeansResourcePropertySetMetaData
-      implements ResourcePropertySetMetaData
+        implements ResourcePropertySetMetaData
 {
 
-   private static final Log LOG = LogFactory.getLog( XmlBeansResourcePropertySetMetaData.class );
-   private static final Messages MSG = MessagesImpl.getInstance();
+    private static final Log LOG = LogFactory.getLog( XmlBeansResourcePropertySetMetaData.class );
+    private static final Messages MSG = MessagesImpl.getInstance();
 
-   private final SchemaType m_schemaType;
-   private final Map m_propMetaDatas = new HashMap();
+    private final SchemaType m_schemaType;
+    private final Map m_propMetaDatas = new HashMap();
 
-   /**
-    * Creates a new {@link XmlBeansResourcePropertySetMetaData} object.
-    *
-    * @param schemaType DOCUMENT_ME
-    */
-   public XmlBeansResourcePropertySetMetaData( SchemaType schemaType )
-   {
-      if ( !schemaType.isDocumentType() )
-      {
-         throw new IllegalArgumentException( MSG.getMessage( Keys.SCHEMA_MUST_BE_DOC) );
-      }
-
-      m_schemaType = schemaType;
-      SchemaProperty[] elemTypes = m_schemaType.getElementProperties()[0].getType().getElementProperties();
-      for ( int i = 0; i < elemTypes.length; i++ )
-      {
-         m_propMetaDatas.put( elemTypes[i].getName(),
-               new XmlBeansResourcePropertyMetaData( elemTypes[i] ) );
-      }
-   }
-
-   /**
-    * DOCUMENT_ME
-    *
-    * @return DOCUMENT_ME
-    */
-   public QName getName()
-   {
-      return m_schemaType.getDocumentElementName();
-   }
-
-   /**
-    * DOCUMENT_ME
-    *
-    * @return DOCUMENT_ME
-    */
-   public boolean isOpenContent()
-   {
-      SchemaType[] anonTypes = m_schemaType.getAnonymousTypes();
-      for ( int i = 0; i < anonTypes.length; i++ )
-      {
-         if ( anonTypes[i].hasElementWildcards() )
-         {
-            return true;
-         }
-      }
-
-      return false;
-   }
-
-   /**
-    * DOCUMENT_ME
-    *
-    * @param name DOCUMENT_ME
-    *
-    * @return DOCUMENT_ME
-    */
-   public ResourcePropertyMetaData getPropertyMetaData( QName name )
-   {
-      return (ResourcePropertyMetaData) m_propMetaDatas.get( name );
-   }
-
-   /**
-    * DOCUMENT_ME
-    *
-    * @return DOCUMENT_ME
-    */
-   public ResourcePropertyMetaData[] getPropertyMetaDatas()
-   {
-      return (ResourcePropertyMetaData[]) m_propMetaDatas.values().toArray( new ResourcePropertyMetaData[0] );
-   }
-
-   /**
-    * DOCUMENT_ME
-    *
-    * @return DOCUMENT_ME
-    */
-   public ResourcePropertySet create()
-   {
-      try
-      {
-         Class factoryClass = Class.forName( m_schemaType.getFullJavaName() + "$Factory" );
-         LOG.debug( MSG.getMessage( Keys.CREATING_PROPSET, factoryClass ) );
-         Method newInstanceMethod = factoryClass.getMethod( "newInstance", null );
-         XmlObject propsDocXBean = (XmlObject) newInstanceMethod.invoke( null, new Object[0] );
-         return new XmlBeansResourcePropertySet( propsDocXBean );
-      }
-      catch ( Exception e )
-      {
-         throw new RuntimeException( e );
-      }
-   }
+    /**
+     * Creates a new {@link XmlBeansResourcePropertySetMetaData} object.
+     *
+     * @param schemaType DOCUMENT_ME
+     */
+    public XmlBeansResourcePropertySetMetaData( SchemaType schemaType )
+    {
+        this( schemaType, null );
+    }
+
+    /**
+     * Creates a new {@link XmlBeansResourcePropertySetMetaData} object.
+     *
+     * @param schemaType DOCUMENT_ME
+     */
+    public XmlBeansResourcePropertySetMetaData( SchemaType schemaType, MetadataDescriptorType metaDataDesc )
+    {
+        if ( !schemaType.isDocumentType() )
+        {
+            throw new IllegalArgumentException( MSG.getMessage( Keys.SCHEMA_MUST_BE_DOC ) );
+        }
+        m_schemaType = schemaType;
+        SchemaProperty[] elemTypes = m_schemaType.getElementProperties()[0].getType().getElementProperties();
+        for ( int i = 0; i < elemTypes.length; i++ )
+        {
+            PropertyType propDesc = getPropertyDesc( metaDataDesc, elemTypes[i].getName() );
+            m_propMetaDatas.put( elemTypes[i].getName(),
+                    new XmlBeansResourcePropertyMetaData( elemTypes[i], propDesc ) );
+        }
+    }
+
+    /**
+     * DOCUMENT_ME
+     *
+     * @return DOCUMENT_ME
+     */
+    public QName getName()
+    {
+        return m_schemaType.getDocumentElementName();
+    }
+
+    /**
+     * DOCUMENT_ME
+     *
+     * @return DOCUMENT_ME
+     */
+    public boolean isOpenContent()
+    {
+        SchemaType[] anonTypes = m_schemaType.getAnonymousTypes();
+        for ( int i = 0; i < anonTypes.length; i++ )
+        {
+            if ( anonTypes[i].hasElementWildcards() )
+            {
+                return true;
+            }
+        }
+
+        return false;
+    }
+
+    /**
+     * DOCUMENT_ME
+     *
+     * @param name DOCUMENT_ME
+     *
+     * @return DOCUMENT_ME
+     */
+    public ResourcePropertyMetaData getPropertyMetaData( QName name )
+    {
+        return (ResourcePropertyMetaData) m_propMetaDatas.get( name );
+    }
+
+    /**
+     * DOCUMENT_ME
+     *
+     * @return DOCUMENT_ME
+     */
+    public ResourcePropertyMetaData[] getPropertyMetaDatas()
+    {
+        return (ResourcePropertyMetaData[]) m_propMetaDatas.values().toArray( new ResourcePropertyMetaData[0] );
+    }
+
+    /**
+     * DOCUMENT_ME
+     *
+     * @return DOCUMENT_ME
+     */
+    public ResourcePropertySet create()
+    {
+        try
+        {
+            Class factoryClass = Class.forName( m_schemaType.getFullJavaName() + "$Factory" );
+            LOG.debug( MSG.getMessage( Keys.CREATING_PROPSET, factoryClass ) );
+            Method newInstanceMethod = factoryClass.getMethod( "newInstance", null );
+            XmlObject propsDocXBean = (XmlObject) newInstanceMethod.invoke( null, new Object[0] );
+            return new XmlBeansResourcePropertySet( propsDocXBean );
+        }
+        catch ( Exception e )
+        {
+            throw new RuntimeException( e );
+        }
+    }
+
+    private static PropertyType getPropertyDesc( MetadataDescriptorType metadataDesc, QName propName )
+    {
+        if ( metadataDesc != null )
+        {
+            PropertyType[] propDescs = metadataDesc.getPropertyArray();
+            for ( int i = 0; i < propDescs.length; i++ )
+            {
+                QName name = XmlBeanUtils.getAttributeValueAsQName( propDescs[i], new QName( "", "path" ) );
+                if ( name.equals( propName ) )
+                {
+                    return propDescs[i];
+                }
+            }
+        }
+        return null;
+    }
+    
 }

Modified: incubator/apollo/trunk/src/java/org/apache/ws/util/XmlBeanUtils.java
URL: http://svn.apache.org/viewcvs/incubator/apollo/trunk/src/java/org/apache/ws/util/XmlBeanUtils.java?view=diff&r1=153463&r2=153464
==============================================================================
--- incubator/apollo/trunk/src/java/org/apache/ws/util/XmlBeanUtils.java (original)
+++ incubator/apollo/trunk/src/java/org/apache/ws/util/XmlBeanUtils.java Fri Feb 11 14:14:52 2005
@@ -217,6 +217,42 @@
     }
 
     /**
+     * @param xBean
+     *
+     * @return
+     */
+    public static QName getValueAsQName( XmlObject xBean )
+    {
+        String value = getValue( xBean );
+        return toQName( value, xBean );
+    }
+
+    /**
+     *
+     * @param xBean
+     * @param attribName
+     * @return
+     */
+    public static String getAttributeValue( XmlObject xBean, QName attribName )
+    {
+        XmlCursor xCursor = xBean.newCursor();
+        String value = xCursor.getAttributeText( attribName );
+        xCursor.dispose();
+        return value;
+    }
+
+    /**
+     * @param xBean
+     *
+     * @return
+     */
+    public static QName getAttributeValueAsQName( XmlObject xBean, QName attribName )
+    {
+        String value = getAttributeValue( xBean, attribName );
+        return toQName( value, xBean );
+    }
+
+    /**
      * Returns a Map keyed on Element QName to a List containing the "Any" XmlObjects types.
      * <p/>
      * The way we determine that an element is an Any is by asking for the element property of the schemaType for the
@@ -463,4 +499,23 @@
         return xBean;
     }
 
+    private static QName toQName( String value, XmlObject xBean )
+    {
+        int colonIndex = value.indexOf( ':' );
+        String nsURI;
+        if ( colonIndex != -1 )
+        {
+            String prefix = value.substring( 0, colonIndex );
+            XmlCursor xCursor = xBean.newCursor();
+            nsURI = xCursor.namespaceForPrefix( prefix );
+            xCursor.dispose();
+        }
+        else
+        {
+            nsURI = "";
+        }
+        String localName = value.substring( colonIndex + 1 );
+        return new QName( nsURI, localName );
+    }
+    
 }

Added: incubator/apollo/trunk/src/test/org/apache/ws/resource/properties/SushiMetadata.wsrmd
URL: http://svn.apache.org/viewcvs/incubator/apollo/trunk/src/test/org/apache/ws/resource/properties/SushiMetadata.wsrmd?view=auto&rev=153464
==============================================================================
--- incubator/apollo/trunk/src/test/org/apache/ws/resource/properties/SushiMetadata.wsrmd (added)
+++ incubator/apollo/trunk/src/test/org/apache/ws/resource/properties/SushiMetadata.wsrmd Fri Feb 11 14:14:52 2005
@@ -0,0 +1,6 @@
+<?xml version="1.0"?>
+
+<Blah />
+
+<!-- TODO -->
+



---------------------------------------------------------------------
To unsubscribe, e-mail: apollo-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: apollo-dev-help@ws.apache.org