[skycastle-commits] SF.net SVN: skycastle: [456] trunk/skycastle/modules

  • From: zzorn@xxxxxxxxxxxxxxxxxxxxx
  • To: skycastle-commits@xxxxxxxxxxxxx
  • Date: Mon, 14 Apr 2008 02:04:50 -0700

Revision: 456
          http://skycastle.svn.sourceforge.net/skycastle/?rev=456&view=rev
Author:   zzorn
Date:     2008-04-14 02:04:49 -0700 (Mon, 14 Apr 2008)

Log Message:
-----------
Added and partially implemented collection type properties.

Modified Paths:
--------------
    
trunk/skycastle/modules/core/src/main/java/org/skycastle/core/DefaultGameObject.java
    
trunk/skycastle/modules/core/src/main/java/org/skycastle/core/property/PropertyFacade.java
    
trunk/skycastle/modules/core/src/main/java/org/skycastle/core/property/PropertyFacadeImpl.java
    
trunk/skycastle/modules/core/src/test/java/org/skycastle/core/AbstractGameObjectPropertiesTest.java
    
trunk/skycastle/modules/utils/src/main/java/org/skycastle/util/parameters/ParameterMetadata.java
    
trunk/skycastle/modules/utils/src/main/java/org/skycastle/util/parameters/ParameterMetadataImpl.java
    
trunk/skycastle/modules/utils/src/main/java/org/skycastle/util/view2d/renderer/SolidColorRenderer2D.java

Added Paths:
-----------
    
trunk/skycastle/modules/core/src/main/java/org/skycastle/messaging/updates/property/CollectionPropertyItemAdded.java
    
trunk/skycastle/modules/core/src/main/java/org/skycastle/messaging/updates/property/CollectionPropertyItemRemoved.java

Modified: 
trunk/skycastle/modules/core/src/main/java/org/skycastle/core/DefaultGameObject.java
===================================================================
--- 
trunk/skycastle/modules/core/src/main/java/org/skycastle/core/DefaultGameObject.java
        2008-04-14 02:48:30 UTC (rev 455)
+++ 
trunk/skycastle/modules/core/src/main/java/org/skycastle/core/DefaultGameObject.java
        2008-04-14 09:04:49 UTC (rev 456)
@@ -248,10 +248,33 @@
         myPropertyFacade.removeProperty( propertyIdentifier );
     }
 
+    public void addPropertyItem( final String propertyIdentifier, final 
Serializable collectionPropertyItem )
+            throws ParameterValidationException
+    {
+        myPropertyFacade.addPropertyItem( propertyIdentifier, 
collectionPropertyItem );
+    }
+
+    public void removePropertyItem( final String propertyIdentifier, final 
Serializable collectionPropertyItem )
+            throws ParameterValidationException
+    {
+        myPropertyFacade.removePropertyItem( propertyIdentifier, 
collectionPropertyItem );
+    }
+
+    public void addPropertyMapping( final String propertyIdentifier, final 
Serializable key, final Serializable value )
+            throws ParameterValidationException
+    {
+        myPropertyFacade.addPropertyMapping( propertyIdentifier, key, value );
+    }
+
+    public void removePropertyMapping( final String propertyIdentifier, final 
Serializable key )
+            throws ParameterValidationException
+    {
+        myPropertyFacade.removePropertyMapping( propertyIdentifier, key );
+    }
+
     //----------------------------------------------------------------------
     // Task Implementation
 
-
     public final void run()
             throws Exception
     {

Modified: 
trunk/skycastle/modules/core/src/main/java/org/skycastle/core/property/PropertyFacade.java
===================================================================
--- 
trunk/skycastle/modules/core/src/main/java/org/skycastle/core/property/PropertyFacade.java
  2008-04-14 02:48:30 UTC (rev 455)
+++ 
trunk/skycastle/modules/core/src/main/java/org/skycastle/core/property/PropertyFacade.java
  2008-04-14 09:04:49 UTC (rev 456)
@@ -6,6 +6,8 @@
 import org.skycastle.util.parameters.validators.ParameterValidator;
 
 import java.io.Serializable;
+import java.util.Collection;
+import java.util.Map;
 import java.util.Set;
 
 /**
@@ -66,7 +68,7 @@
      * @param propertyIdentifier a Java style identifier for the property.
      * @param initialValue       initial value for the property.
      *
-     * @throws ParameterValidationException a {@link 
org.skycastle.util.parameters.ParameterValidationException} describing the 
error if there was a problem with adding the property
+     * @throws ParameterValidationException a {@link 
ParameterValidationException} describing the error if there was a problem with 
adding the property
      *                                      or setting the initial property 
value
      */
     void addProperty( String propertyIdentifier,
@@ -81,7 +83,7 @@
      * @param initialValue       initial value for the property.
      * @param propertyMetadata   metadata for the property.
      *
-     * @throws ParameterValidationException a {@link 
org.skycastle.util.parameters.ParameterValidationException} describing the 
error if there was a problem with adding the property
+     * @throws ParameterValidationException a {@link 
ParameterValidationException} describing the error if there was a problem with 
adding the property
      *                                      or setting the initial property 
value
      */
     void addProperty( String propertyIdentifier,
@@ -100,7 +102,7 @@
      * @param validators         an array / variable length list with 
validators to use for restricting the
      *                           possible property values.
      *
-     * @throws ParameterValidationException a {@link 
org.skycastle.util.parameters.ParameterValidationException} describing the 
error if there was a problem with adding the property
+     * @throws ParameterValidationException a {@link 
ParameterValidationException} describing the error if there was a problem with 
adding the property
      *                                      or setting the initial property 
value
      */
     void addProperty( String propertyIdentifier,
@@ -121,7 +123,7 @@
      * @param validators         an array / variable length list with 
validators to use for restricting the
      *                           possible property values.
      *
-     * @throws ParameterValidationException a {@link 
org.skycastle.util.parameters.ParameterValidationException} describing the 
error if there was a problem with adding the property
+     * @throws ParameterValidationException a {@link 
ParameterValidationException} describing the error if there was a problem with 
adding the property
      *                                      or setting the initial property 
value
      */
     <T extends Serializable> void addProperty( String propertyIdentifier,
@@ -136,12 +138,56 @@
      *
      * @param propertyIdentifier the identifier of the property to remove.
      *
-     * @throws ParameterValidationException a {@link 
org.skycastle.util.parameters.ParameterValidationException} describing the 
error if there was a problem with adding the property
+     * @throws ParameterValidationException a {@link 
ParameterValidationException} describing the error if there was a problem with 
adding the property
      *                                      or setting the initial property 
value
-     * @throws ParameterValidationException a {@link 
org.skycastle.util.parameters.ParameterValidationException} describing the 
error if there was a problem with adding the property
-     *                                      or setting the initial property 
value
      */
     void removeProperty( String propertyIdentifier )
             throws ParameterValidationException;
 
+
+    /**
+     * Adds an item to a collection property.
+     *
+     * @param propertyIdentifier     the identifier of a property to add an 
item to.  The property should be of a {@link Collection} type.
+     * @param collectionPropertyItem the item to add to the collection.
+     *
+     * @throws ParameterValidationException a {@link 
ParameterValidationException} describing the error if there was a problem.
+     */
+    void addPropertyItem( String propertyIdentifier, Serializable 
collectionPropertyItem )
+            throws ParameterValidationException;
+
+    /**
+     * Removes an item from a collection property.
+     *
+     * @param propertyIdentifier     the identifier of a property to remove 
the item from.  The property should be of a {@link Collection} type.
+     * @param collectionPropertyItem the item to remove, if found.  The first 
instance of this item will be removed from the collection.
+     *
+     * @throws ParameterValidationException a {@link 
ParameterValidationException} describing the error if there was a problem.
+     */
+    void removePropertyItem( String propertyIdentifier, Serializable 
collectionPropertyItem )
+            throws ParameterValidationException;
+
+    /**
+     * Adds an entry to a map property.
+     *
+     * @param propertyIdentifier the identifier of the property to add to.  
The property should be of a {@link Map} type.
+     * @param key                the key of the new mapping.  If it is the 
same as an existing key, that key will be replaced.
+     * @param value              the value to associate with the key.
+     *
+     * @throws ParameterValidationException a {@link 
ParameterValidationException} describing the error if there was a problem.
+     */
+    void addPropertyMapping( String propertyIdentifier, Serializable key, 
Serializable value )
+            throws ParameterValidationException;
+
+    /**
+     * Removes an entry from a map property.
+     *
+     * @param propertyIdentifier the identifier of a property to remove the 
item from.  The property should be of a {@link Map} type.
+     * @param key                the key of the entry to remove, if found.
+     *
+     * @throws ParameterValidationException a {@link 
ParameterValidationException} describing the error if there was a problem.
+     */
+    void removePropertyMapping( String propertyIdentifier, Serializable key )
+            throws ParameterValidationException;
+
 }

Modified: 
trunk/skycastle/modules/core/src/main/java/org/skycastle/core/property/PropertyFacadeImpl.java
===================================================================
--- 
trunk/skycastle/modules/core/src/main/java/org/skycastle/core/property/PropertyFacadeImpl.java
      2008-04-14 02:48:30 UTC (rev 455)
+++ 
trunk/skycastle/modules/core/src/main/java/org/skycastle/core/property/PropertyFacadeImpl.java
      2008-04-14 09:04:49 UTC (rev 456)
@@ -3,6 +3,7 @@
 import org.skycastle.core.AbstractFacade;
 import org.skycastle.core.GameObject;
 import org.skycastle.core.GameObjectContext;
+import org.skycastle.messaging.updates.property.CollectionPropertyItemAdded;
 import org.skycastle.messaging.updates.property.PropertyAddedMessage;
 import org.skycastle.messaging.updates.property.PropertyChangedMessage;
 import org.skycastle.messaging.updates.property.PropertyRemovedMessage;
@@ -14,10 +15,10 @@
 import org.skycastle.util.parameters.ParameterValidationException;
 import org.skycastle.util.parameters.ValidationError;
 import org.skycastle.util.parameters.validators.ParameterValidator;
+import org.skycastle.util.uiidentity.UiMetadataImpl;
 
 import java.io.Serializable;
-import java.util.Collections;
-import java.util.Set;
+import java.util.*;
 
 /**
  * @author Hans Häggström
@@ -45,6 +46,7 @@
     private static final String COULD_NOT_SET_PROPERTY_VALUE = "Could not set 
property value";
     private static final String PROBLEM_WHEN_ADDING_PROPERTY = "Problem when 
adding property";
     private static final String PROBLEM_WHEN_REMOVING_PROPERTY = "Problem when 
removing property";
+    private static final String PROBLEM_WHEN_ADDING_COLLECTION_PROPERTY_ITEM = 
"Can not add collection property item";
 
     //======================================================================
     // Public Methods
@@ -134,7 +136,8 @@
 
     public void addProperty( final String propertyIdentifier,
                              final Serializable initialValue,
-                             final ParameterMetadata propertyMetadata ) throws 
ParameterValidationException
+                             final ParameterMetadata propertyMetadata )
+            throws ParameterValidationException
     {
         ParameterChecker.checkNotNull( propertyIdentifier, 
"propertyIdentifier" );
         ParameterChecker.checkNotNull( propertyMetadata, "propertyMetadata" );
@@ -200,14 +203,14 @@
                                                       final T initialValue,
                                                       final Class<T> type,
                                                       final String description,
-                                                      final 
ParameterValidator... validators ) throws ParameterValidationException
+                                                      final 
ParameterValidator... validators )
+            throws ParameterValidationException
     {
         // Create metadata
         final ParameterMetadataImpl propertyMetadata =
                 new ParameterMetadataImpl( type,
                                            false,
-                                           
StringUtilities.camelCaseToUserReadableString( propertyIdentifier ),
-                                           description );
+                                           new UiMetadataImpl( 
StringUtilities.camelCaseToUserReadableString( propertyIdentifier ), 
description ) );
 
         // Add validators to metadata
         for ( final ParameterValidator validator : validators )
@@ -219,7 +222,8 @@
     }
 
 
-    public void removeProperty( final String propertyIdentifier ) throws 
ParameterValidationException
+    public void removeProperty( final String propertyIdentifier )
+            throws ParameterValidationException
     {
         if ( !hasProperty( propertyIdentifier ) )
         {
@@ -235,4 +239,89 @@
                                                                            
propertyIdentifier ) );
     }
 
+    public void addPropertyItem( final String propertyIdentifier, final 
Serializable collectionPropertyItem )
+            throws ParameterValidationException
+    {
+        // Check that the property exists
+        ensurePropertyExists( propertyIdentifier, 
PROBLEM_WHEN_ADDING_COLLECTION_PROPERTY_ITEM );
+
+        final ParameterMetadata propertyMetadata = getPropertyMetadata( 
propertyIdentifier );
+
+        // Check that the type is correct
+        if ( !Collection.class.isAssignableFrom( propertyMetadata.getType() ) )
+        {
+            throw new ParameterValidationException( 
PROBLEM_WHEN_ADDING_COLLECTION_PROPERTY_ITEM,
+                                                    new ValidationError( 
propertyIdentifier,
+                                                                         "The 
parameter is not a Collection type." ) );
+        }
+
+        // Check that the vaue is acceptable
+        final ValidationError validationError = 
propertyMetadata.getValueMetadata().validateParameter( collectionPropertyItem, 
propertyIdentifier );
+        if ( validationError != null )
+        {
+            throw new ParameterValidationException( 
PROBLEM_WHEN_ADDING_COLLECTION_PROPERTY_ITEM, validationError );
+        }
+
+        // Add property
+        Collection collection = (Collection) myPropertyValues.get( 
propertyIdentifier );
+        if ( collection == null )
+        {
+            // Create missing collection
+            if ( List.class.isAssignableFrom( propertyMetadata.getType() ) )
+            {
+                collection = new ArrayList();
+            }
+            else if ( Set.class.isAssignableFrom( propertyMetadata.getType() ) 
)
+            {
+                collection = new HashSet();
+            }
+            else
+            {
+                throw new ParameterValidationException( 
PROBLEM_WHEN_ADDING_COLLECTION_PROPERTY_ITEM,
+                                                        new ValidationError( 
propertyIdentifier,
+                                                                             
"Do not know how to create a new instance of the collection type '" + 
propertyMetadata.getType() + "' " ) );
+            }
+
+            myPropertyValues.put( propertyIdentifier, collection );
+        }
+
+        //noinspection unchecked
+        collection.add( collectionPropertyItem );
+
+        // Notify about addition
+        getGameObject().sendUpdateToObservers( new 
CollectionPropertyItemAdded( getId(), propertyIdentifier, 
collectionPropertyItem ) );
+    }
+
+    public void removePropertyItem( final String propertyIdentifier, final 
Serializable collectionPropertyItem )
+            throws ParameterValidationException
+    {
+        throw new UnsupportedOperationException( "This method has not yet been 
implemented." ); // IMPLEMENT
+    }
+
+    public void addPropertyMapping( final String propertyIdentifier, final 
Serializable key, final Serializable value )
+            throws ParameterValidationException
+    {
+        throw new UnsupportedOperationException( "This method has not yet been 
implemented." ); // IMPLEMENT
+    }
+
+    public void removePropertyMapping( final String propertyIdentifier, final 
Serializable key )
+            throws ParameterValidationException
+    {
+        throw new UnsupportedOperationException( "This method has not yet been 
implemented." ); // IMPLEMENT
+    }
+
+    //======================================================================
+    // Private Methods
+
+    private void ensurePropertyExists( final String propertyIdentifier, final 
String message )
+            throws ParameterValidationException
+    {
+        if ( !hasProperty( propertyIdentifier ) )
+        {
+            throw new ParameterValidationException( message,
+                                                    new ValidationError( 
propertyIdentifier,
+                                                                         "No 
property with name '" + propertyIdentifier + "' exists for this object." ) );
+        }
+    }
+
 }

Added: 
trunk/skycastle/modules/core/src/main/java/org/skycastle/messaging/updates/property/CollectionPropertyItemAdded.java
===================================================================
--- 
trunk/skycastle/modules/core/src/main/java/org/skycastle/messaging/updates/property/CollectionPropertyItemAdded.java
                                (rev 0)
+++ 
trunk/skycastle/modules/core/src/main/java/org/skycastle/messaging/updates/property/CollectionPropertyItemAdded.java
        2008-04-14 09:04:49 UTC (rev 456)
@@ -0,0 +1,67 @@
+package org.skycastle.messaging.updates.property;
+
+import org.skycastle.core.GameObjectContext;
+import org.skycastle.core.GameObjectId;
+import org.skycastle.messaging.updates.MemberUpdateMessage;
+import org.skycastle.util.parameters.ValidationError;
+
+import java.io.Serializable;
+import java.util.Set;
+
+/**
+ * Indicates that an item was added to a collection property.
+ *
+ * @author Hans Haggstrom
+ */
+public final class CollectionPropertyItemAdded
+        extends MemberUpdateMessage
+{
+
+    //======================================================================
+    // Private Fields
+
+    private final Serializable myAddedItem;
+
+    //======================================================================
+    // Private Constants
+
+    private static final long serialVersionUID = 1L;
+
+    //======================================================================
+    // Public Methods
+
+    //----------------------------------------------------------------------
+    // Constructors
+
+    public CollectionPropertyItemAdded( final GameObjectId updatedObjectId, 
final String memberIdentifier, final Serializable addedItem )
+    {
+        super( updatedObjectId, memberIdentifier );
+
+        myAddedItem = addedItem;
+    }
+
+    //----------------------------------------------------------------------
+    // Message Implementation
+
+    @Override
+    public ValidationError validate( final Set<String> allowedContainedTypes, 
final String errorPrefix )
+    {
+        ValidationError validationError = super.validate( 
allowedContainedTypes, errorPrefix );
+
+        if ( validationError == null )
+        {
+            validationError = checkValue( myAddedItem, "addedItem", 
allowedContainedTypes );
+        }
+
+        return validationError;
+    }
+
+    //----------------------------------------------------------------------
+    // UpdateMessage Implementation
+
+    public void applyStateChangeToModel( final GameObjectContext 
gameObjectContext )
+    {
+        throw new UnsupportedOperationException( "This method has not yet been 
implemented." ); // IMPLEMENT
+    }
+
+}

Added: 
trunk/skycastle/modules/core/src/main/java/org/skycastle/messaging/updates/property/CollectionPropertyItemRemoved.java
===================================================================
--- 
trunk/skycastle/modules/core/src/main/java/org/skycastle/messaging/updates/property/CollectionPropertyItemRemoved.java
                              (rev 0)
+++ 
trunk/skycastle/modules/core/src/main/java/org/skycastle/messaging/updates/property/CollectionPropertyItemRemoved.java
      2008-04-14 09:04:49 UTC (rev 456)
@@ -0,0 +1,67 @@
+package org.skycastle.messaging.updates.property;
+
+import org.skycastle.core.GameObjectContext;
+import org.skycastle.core.GameObjectId;
+import org.skycastle.messaging.updates.MemberUpdateMessage;
+import org.skycastle.util.parameters.ValidationError;
+
+import java.io.Serializable;
+import java.util.Set;
+
+/**
+ * Indicates that an item was removed from a collection property.
+ *
+ * @author Hans Haggstrom
+ */
+public final class CollectionPropertyItemRemoved
+        extends MemberUpdateMessage
+{
+
+    //======================================================================
+    // Private Fields
+
+    private final Serializable myRemovedItem;
+
+    //======================================================================
+    // Private Constants
+
+    private static final long serialVersionUID = 1L;
+
+    //======================================================================
+    // Public Methods
+
+    //----------------------------------------------------------------------
+    // Constructors
+
+    public CollectionPropertyItemRemoved( final GameObjectId updatedObjectId, 
final String memberIdentifier, final Serializable removedItem )
+    {
+        super( updatedObjectId, memberIdentifier );
+
+        myRemovedItem = removedItem;
+    }
+
+    //----------------------------------------------------------------------
+    // Message Implementation
+
+    @Override
+    public ValidationError validate( final Set<String> allowedContainedTypes, 
final String errorPrefix )
+    {
+        ValidationError validationError = super.validate( 
allowedContainedTypes, errorPrefix );
+
+        if ( validationError == null )
+        {
+            validationError = checkValue( myRemovedItem, "addedItem", 
allowedContainedTypes );
+        }
+
+        return validationError;
+    }
+
+    //----------------------------------------------------------------------
+    // UpdateMessage Implementation
+
+    public void applyStateChangeToModel( final GameObjectContext 
gameObjectContext )
+    {
+        throw new UnsupportedOperationException( "This method has not yet been 
implemented." ); // IMPLEMENT
+    }
+
+}
\ No newline at end of file

Modified: 
trunk/skycastle/modules/core/src/test/java/org/skycastle/core/AbstractGameObjectPropertiesTest.java
===================================================================
--- 
trunk/skycastle/modules/core/src/test/java/org/skycastle/core/AbstractGameObjectPropertiesTest.java
 2008-04-14 02:48:30 UTC (rev 455)
+++ 
trunk/skycastle/modules/core/src/test/java/org/skycastle/core/AbstractGameObjectPropertiesTest.java
 2008-04-14 09:04:49 UTC (rev 456)
@@ -12,8 +12,10 @@
 import org.skycastle.util.parameters.ParameterMetadataImpl;
 import org.skycastle.util.parameters.ParameterValidationException;
 import org.skycastle.util.parameters.validators.notnull.NotNullValidator;
+import org.skycastle.util.uiidentity.UiMetadataImpl;
 
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.List;
 import java.util.Set;
 
@@ -31,6 +33,10 @@
     private GameObject myGameObject;
 
     private List<Message> mySentMessages;
+
+    //======================================================================
+    // Private Constants
+
     private static final String SOME_OTHER_GAME_OBJECT_ID = 
"GameObject_SomeOtherObjectMaybePlayer";
 
     //======================================================================
@@ -39,7 +45,8 @@
     //----------------------------------------------------------------------
     // Test Methods
 
-    public void testAddingAlreadyContainedProperty() throws Exception
+    public void testAddingAlreadyContainedProperty()
+            throws Exception
     {
         myGameObject.addProperty( "lunch", "Onion Soup" );
         assertEquals( 1, getNumberOfProperties() );
@@ -56,7 +63,8 @@
     }
 
 
-    public void testAddingPropertyWithInvalidIdentifier() throws Exception
+    public void testAddingPropertyWithInvalidIdentifier()
+            throws Exception
     {
         try
         {
@@ -71,7 +79,8 @@
     }
 
 
-    public void testAddingPropertyWithInvalidInitialValue() throws Exception
+    public void testAddingPropertyWithInvalidInitialValue()
+            throws Exception
     {
         try
         {
@@ -87,8 +96,28 @@
         assertEquals( 0, getNumberOfProperties() );
     }
 
+    public void testAddingToCollectionProperty()
+            throws Exception
+    {
+        final ParameterMetadataImpl valueMetadata = new ParameterMetadataImpl( 
String.class,
+                                                                               
true,
+                                                                               
new UiMetadataImpl( "Dish", "Name of lunch dish" ) );
+        myGameObject.addProperty( "menu",
+                                  new ArrayList(),
+                                  new ParameterMetadataImpl( List.class,
+                                                             true,
+                                                             new 
UiMetadataImpl( "Menu", "This is what's for lunch" ),
+                                                             valueMetadata ) );
 
-    public void testGetPropertyIdentifiers() throws Exception
+        myGameObject.addPropertyItem( "menu", "bread" );
+        myGameObject.addPropertyItem( "menu", "water" );
+
+        assertEquals( Arrays.asList( "bread", "water" ), 
myGameObject.getPropertyValue( "menu", null ) );
+    }
+
+
+    public void testGetPropertyIdentifiers()
+            throws Exception
     {
         setupTodaysMenu();
 
@@ -101,13 +130,15 @@
     }
 
 
-    public void testGettingNonExistingProperty() throws Exception
+    public void testGettingNonExistingProperty()
+            throws Exception
     {
         assertEquals( "Pizza", myGameObject.getPropertyValue( "dinner", 
"Pizza" ) );
     }
 
 
-    public void testListeningToPropertyUpdateMessages() throws Exception
+    public void testListeningToPropertyUpdateMessages()
+            throws Exception
     {
         myGameObject.addProperty( "nightSnack", "Noodles" );
         myGameObject.setPropertyValue( "nightSnack", "Chicken Nuggets" );
@@ -129,7 +160,8 @@
     }
 
 
-    public void testPropertyAddingModificationAndRemovalWithMessages() throws 
Exception
+    public void testPropertyAddingModificationAndRemovalWithMessages()
+            throws Exception
     {
         assertEquals( 0, getNumberOfProperties() );
 
@@ -159,7 +191,8 @@
     }
 
 
-    public void testPropertyExists() throws Exception
+    public void testPropertyExists()
+            throws Exception
     {
         assertFalse( myGameObject.hasProperty( "dinner" ) );
 
@@ -172,7 +205,8 @@
     }
 
 
-    public void testPropertySetAndGet() throws Exception
+    public void testPropertySetAndGet()
+            throws Exception
     {
         myGameObject.addProperty( "dinner",
                                   "Broccoli Soup",
@@ -185,7 +219,8 @@
     }
 
 
-    public void testRemoveProperty() throws Exception
+    public void testRemoveProperty()
+            throws Exception
     {
         setupTodaysMenu();
 
@@ -199,7 +234,8 @@
     }
 
 
-    public void testRemovingNonExistingProperty() throws Exception
+    public void testRemovingNonExistingProperty()
+            throws Exception
     {
         try
         {
@@ -212,7 +248,8 @@
     }
 
 
-    public void testSetBoolean() throws Exception
+    public void testSetBoolean()
+            throws Exception
     {
         myGameObject.addProperty( "lunchtime", false );
         myGameObject.setPropertyValue( "lunchtime", true );
@@ -220,7 +257,8 @@
     }
 
 
-    public void testSettingNonExistingProperty() throws Exception
+    public void testSettingNonExistingProperty()
+            throws Exception
     {
         try
         {
@@ -236,7 +274,8 @@
     // Protected Methods
 
     @Override
-    protected void setUp() throws Exception
+    protected void setUp()
+            throws Exception
     {
         GameContext.setGameObjectContext( new UnitTestingContext() );
 
@@ -289,7 +328,8 @@
     }
 
 
-    private void setupTodaysMenu() throws ParameterValidationException
+    private void setupTodaysMenu()
+            throws ParameterValidationException
     {
         myGameObject.addProperty( "breakfast", "Porridge" );
         myGameObject.addProperty( "secondBreakfast", "Ham and eggs" );

Modified: 
trunk/skycastle/modules/utils/src/main/java/org/skycastle/util/parameters/ParameterMetadata.java
===================================================================
--- 
trunk/skycastle/modules/utils/src/main/java/org/skycastle/util/parameters/ParameterMetadata.java
    2008-04-14 02:48:30 UTC (rev 455)
+++ 
trunk/skycastle/modules/utils/src/main/java/org/skycastle/util/parameters/ParameterMetadata.java
    2008-04-14 09:04:49 UTC (rev 456)
@@ -5,6 +5,7 @@
 
 import java.io.Serializable;
 import java.util.Collection;
+import java.util.Map;
 
 /**
  * Metadata about a single parameter or property.
@@ -45,4 +46,21 @@
     ValidationError validateParameter( Object parameter, String 
parameterIdentifier );
 
 
+    /**
+     * @return the metadata for the values in a {@link Collection} or {@link 
Map} type parameter.
+     *         If the type is not a Collection or Map, this can be null.
+     */
+    ParameterMetadata getValueMetadata();
+
+    /**
+     * @return the metadata for the keys in a {@link Map} type parameter.
+     *         If the type is not a Map, this can be null.
+     */
+    ParameterMetadata getKeyMetadata();
+
+    /**
+     * @return if the described parameter is of type {@link ParameterSet} or a 
similar object, then a {@link ParameterSetMetadata} can be specified
+     *         for it, otherwise this is null.
+     */
+    ParameterSetMetadata getParameterSetMetadata();
 }

Modified: 
trunk/skycastle/modules/utils/src/main/java/org/skycastle/util/parameters/ParameterMetadataImpl.java
===================================================================
--- 
trunk/skycastle/modules/utils/src/main/java/org/skycastle/util/parameters/ParameterMetadataImpl.java
        2008-04-14 02:48:30 UTC (rev 455)
+++ 
trunk/skycastle/modules/utils/src/main/java/org/skycastle/util/parameters/ParameterMetadataImpl.java
        2008-04-14 09:04:49 UTC (rev 456)
@@ -5,10 +5,7 @@
 import org.skycastle.util.uiidentity.UiMetadata;
 import org.skycastle.util.uiidentity.UiMetadataImpl;
 
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
+import java.util.*;
 
 /**
  * {@inheritDoc}
@@ -24,6 +21,11 @@
     private final List<ParameterValidator> myValidators = new 
ArrayList<ParameterValidator>( 3 );
     private final UiMetadataImpl myUiMetadata;
 
+    private final ParameterMetadata myValueMetadata;
+    private final ParameterMetadata myKeyMetadata;
+
+    private ParameterSetMetadata myParameterSetMetadata = null;
+
     private boolean myRequired;
     private Class myType;
 
@@ -39,7 +41,7 @@
      */
     public ParameterMetadataImpl( final Class type )
     {
-        this( type, false, null, null );
+        this( type, false, new UiMetadataImpl(), null, null );
     }
 
 
@@ -51,22 +53,25 @@
     public ParameterMetadataImpl( final Class type,
                                   final boolean required )
     {
-        this( type, required, null, null );
+        this( type, required, new UiMetadataImpl(), null, null );
     }
 
-
-    /**
-     * @param type             the type that the parameter should be. Can be a 
concrete type, like Double or Integer, or
-     *                         a more abstract type, such as Number.
-     * @param required         true if the parameter is required, false if it 
is optional.
-     * @param userReadableName user readable name for this {@link UiMetadata}.
-     */
+/*
+*/
+/**
+ * @param type             the type that the parameter should be. Can be a 
concrete type, like Double or Integer, or
+ *                         a more abstract type, such as Number.
+ * @param required         true if the parameter is required, false if it is 
optional.
+ * @param userReadableName user readable name for this {@link UiMetadata}.
+ */
+/*
     public ParameterMetadataImpl( final Class type,
                                   final boolean required,
                                   final String userReadableName )
     {
         this( type, required, userReadableName, null );
     }
+*/
 
 
     /**
@@ -79,50 +84,93 @@
                                   final boolean required,
                                   final UiMetadataImpl uiMetadata )
     {
-        ParameterChecker.checkNotNull( uiMetadata, "uiMetadata" );
-        myUiMetadata = uiMetadata;
+        this( type, required, uiMetadata, null, null );
+    }
 
-        setType( type );
-        setRequired( required );
+/*
+*/
+/**
+ * @param type             the type that the parameter should be. Can be a 
concrete type, like Double or Integer, or
+ *                         a more abstract type, such as Number.
+ * @param required         true if the parameter is required, false if it is 
optional.
+ * @param userReadableName user readable name for this {@link UiMetadata}.
+ * @param description      description of this {@link UiMetadata}.  Can be 
used in tooltips, etc.
+ */
+/*
+    public ParameterMetadataImpl( final Class type,
+                                  final boolean required,
+                                  final String userReadableName,
+                                  final String description )
+    {
+        this( type, required, userReadableName, description, null );
     }
+*/
 
-
     /**
-     * @param type the type that the parameter should be. Can be a concrete 
type, like Double or Integer, or a more
-     *             abstract type, such as Number.
+     * @param type          the type that the parameter should be. Can be a 
concrete type, like Double or Integer, or a
+     *                      more abstract type, such as Number.
+     * @param required      true if the parameter is required, false if it is 
optional.
+     * @param uiMetadata    user readable description of the parameter.
+     * @param valueMetadata If the type is a {@link Collection} or {@link Map} 
type, this describes the metadata for the contained values.
+     *                      If the type is something else, this is not used 
and should be null.
      */
-    public final void setType( final Class type )
+    public ParameterMetadataImpl( final Class type,
+                                  final boolean required,
+                                  final UiMetadataImpl uiMetadata,
+                                  final ParameterMetadata valueMetadata )
     {
-        ParameterChecker.checkNotNull( type, "type" );
-        myType = type;
+        this( type, required, uiMetadata, valueMetadata, null );
     }
 
-
     /**
-     * @param required true if the parameter is required, false if it is 
optional.
+     * @param type                 the type that the parameter should be. Can 
be a concrete type, like Double or Integer, or a
+     *                             more abstract type, such as Number.
+     * @param required             true if the parameter is required, false if 
it is optional.
+     * @param uiMetadata           user readable description of the parameter.
+     * @param parameterSetMetadata if the described parameter is of type 
{@link ParameterSet} or a similar object, then a {@link ParameterSetMetadata} 
can be specified
+     *                             for it.
      */
-    public final void setRequired( final boolean required )
+    public ParameterMetadataImpl( final Class type,
+                                  final boolean required,
+                                  final UiMetadataImpl uiMetadata,
+                                  final ParameterSetMetadata 
parameterSetMetadata )
     {
-        myRequired = required;
+        this( type, required, uiMetadata, null, null );
+
+        myParameterSetMetadata = parameterSetMetadata;
     }
 
-
     /**
-     * @param type             the type that the parameter should be. Can be a 
concrete type, like Double or Integer, or
-     *                         a more abstract type, such as Number.
-     * @param required         true if the parameter is required, false if it 
is optional.
-     * @param userReadableName user readable name for this {@link 
org.skycastle.util.uiidentity.UiMetadata}.
-     * @param description      description of this {@link UiMetadata}.  Can be 
used in tooltips, etc.
+     * @param type          the type that the parameter should be. Can be a 
concrete type, like Double or Integer, or a
+     *                      more abstract type, such as Number.
+     * @param required      true if the parameter is required, false if it is 
optional.
+     * @param uiMetadata    user readable description of the parameter.
+     * @param valueMetadata If the type is a {@link Collection} or {@link Map} 
type, this describes the metadata for the contained values.
+     *                      If the type is something else, this is not used 
and should be null.
+     * @param keyMetadata   If the type is a {@link Map} type, this describes 
the metadata for the contained keys.
+     *                      If the type is something else, this is not used 
and should be null.
      */
     public ParameterMetadataImpl( final Class type,
                                   final boolean required,
-                                  final String userReadableName,
-                                  final String description )
+                                  final UiMetadataImpl uiMetadata,
+                                  final ParameterMetadata valueMetadata,
+                                  final ParameterMetadata keyMetadata )
     {
-        this( type, required, userReadableName, description, null );
+        ParameterChecker.checkNotNull( uiMetadata, "uiMetadata" );
+        myUiMetadata = uiMetadata;
+        myValueMetadata = valueMetadata;
+        myKeyMetadata = keyMetadata;
+
+        setType( type );
+        setRequired( required );
     }
 
+    //----------------------------------------------------------------------
+    // ParameterMetadata Implementation
 
+    /*
+    */
+
     /**
      * @param type             the type that the parameter should be. Can be a 
concrete type, like Double or Integer, or
      *                         a more abstract type, such as Number.
@@ -132,21 +180,19 @@
      * @param iconPath         a path to get the icon from, for this {@link 
UiMetadata}. The path isrelative to whatever
      *                         media or resource directory is used.
      */
+/*
     public ParameterMetadataImpl( final Class type,
                                   final boolean required,
                                   final String userReadableName,
                                   final String description,
                                   final String iconPath )
     {
-        myUiMetadata = new UiMetadataImpl( userReadableName, description, 
iconPath );
-
-        setType( type );
-        setRequired( required );
+        this( type, required, new UiMetadataImpl( userReadableName, 
description, iconPath ), null, null );
     }
+*/
 
     //----------------------------------------------------------------------
     // ParameterMetadata Implementation
-
     public UiMetadata getUiMetadata()
     {
         return myUiMetadata;
@@ -164,7 +210,6 @@
         return myRequired;
     }
 
-
     public Collection<ParameterValidator> getValidators()
     {
         return Collections.unmodifiableList( myValidators );
@@ -190,13 +235,91 @@
             }
         }
 
+        // Check contained values for collection types
+        if ( parameter != null &&
+             Collection.class.isAssignableFrom( myType ) )
+        {
+            final Collection collection = (Collection) parameter;
+
+            int i = 0;
+            for ( Object value : collection )
+            {
+                final ValidationError error = 
myValueMetadata.validateParameter( value, parameterIdentifier + "[" + i + "]" );
+                if ( error != null )
+                {
+                    return error;
+                }
+                i++;
+            }
+        }
+
+        // Check contained entries for map types
+        if ( parameter != null &&
+             Map.class.isAssignableFrom( myType ) )
+        {
+            final Map map = (Map) parameter;
+
+            for ( Iterator it = map.entrySet().iterator(); it.hasNext(); )
+            {
+                Map.Entry entry = (Map.Entry) it.next();
+
+                final String identifier = parameterIdentifier + "{" + 
entry.getKey() + "}";
+
+                final ValidationError keyError = 
myKeyMetadata.validateParameter( entry.getKey(), identifier );
+                if ( keyError != null )
+                {
+                    return keyError;
+                }
+
+                final ValidationError valueError = 
myValueMetadata.validateParameter( entry.getValue(), identifier );
+                if ( valueError != null )
+                {
+                    return valueError;
+                }
+            }
+        }
+
         return null;
     }
 
+    public ParameterMetadata getValueMetadata()
+    {
+        return myValueMetadata;
+    }
+
+    public ParameterMetadata getKeyMetadata()
+    {
+        return myKeyMetadata;
+    }
+
+    public ParameterSetMetadata getParameterSetMetadata()
+    {
+        return myParameterSetMetadata;
+    }
+
     //----------------------------------------------------------------------
     // Other Public Methods
 
     /**
+     * @param type the type that the parameter should be. Can be a concrete 
type, like Double or Integer, or a more
+     *             abstract type, such as Number.
+     */
+    public final void setType( final Class type )
+    {
+        ParameterChecker.checkNotNull( type, "type" );
+        myType = type;
+    }
+
+
+    /**
+     * @param required true if the parameter is required, false if it is 
optional.
+     */
+    public final void setRequired( final boolean required )
+    {
+        myRequired = required;
+    }
+
+    /**
      * Adds the specified ParameterValidator.
      *
      * @param addedParameterValidator should not be null or already added.

Modified: 
trunk/skycastle/modules/utils/src/main/java/org/skycastle/util/view2d/renderer/SolidColorRenderer2D.java
===================================================================
--- 
trunk/skycastle/modules/utils/src/main/java/org/skycastle/util/view2d/renderer/SolidColorRenderer2D.java
    2008-04-14 02:48:30 UTC (rev 455)
+++ 
trunk/skycastle/modules/utils/src/main/java/org/skycastle/util/view2d/renderer/SolidColorRenderer2D.java
    2008-04-14 09:04:49 UTC (rev 456)
@@ -5,6 +5,7 @@
 import org.skycastle.util.parameters.ParameterSet;
 import org.skycastle.util.parameters.ParameterSetMetadataImpl;
 import org.skycastle.util.region.RectangularRegion;
+import org.skycastle.util.uiidentity.UiMetadataImpl;
 import org.skycastle.util.view2d.camera.Camera2D;
 
 import java.awt.Color;
@@ -103,7 +104,7 @@
         final ParameterSetMetadataImpl metadata = new 
ParameterSetMetadataImpl();
 
         metadata.setMetadata( "color",
-                              new ParameterMetadataImpl( Color.class, false, 
"Color", "The solid color to render" ) );
+                              new ParameterMetadataImpl( Color.class, false, 
new UiMetadataImpl( "Color", "The solid color to render" ) ) );
 
         return metadata;
     }


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

Other related posts:

  • » [skycastle-commits] SF.net SVN: skycastle: [456] trunk/skycastle/modules