Issue Details (XML | Word | Printable)

Key: UBA-7639
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Janak Mulani
Reporter: Daniel Grob
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
ULCBase

Properties instances are wrong encoded

Created: 17/Dec/08 09:12 PM   Updated: 12/Jun/09 02:53 PM
Component/s: core
Affects Version/s: UltraLightClient '08 Update 2
Fix Version/s: UltraLightClient '08 Update 2, UltraLightClient '08 Update 3

Issue Links:
Reference
 


 Description  « Hide
We use the MapCoder to code instances of the Properties class. However the Properties class is fundamentally different from the Map interface even if it implements the Map interface. As a result the default values for properties (specified in the constructor) are not encoded and are therefore lost!

To get the default values as well you should use the propertyNames() API instead of the keySet() or keys() API.

See http://os-lists.sun.com/thread.jspa?messageID=1501266 as problem description.



 All   Comments   Change History      Sort Order: Ascending order - Click to sort in descending order
Daniel Grob added a comment - 07/Jan/09 02:53 PM
Added PropertiesCoder class. Properties objects are no longer handled by the MapCoder class but by the newly added PropertiesCoder class.

Janak Mulani added a comment - 11/Jun/09 06:42 PM - edited
The encoding from Client to Server worked ok after the fix i ULC 2008 update 2. However, the encoding from server to client does not work as default properties are ignored by the marshalling mechanism of ULC. While replacing proxies with oids, ULC reinstantiates Properties but does not copy default properties.
import com.ulcjava.base.application.ULCButton;
import com.ulcjava.base.application.ULCFrame;
import com.ulcjava.base.client.UIButton;
import com.ulcjava.base.development.DevelopmentRunner;
import com.ulcjava.base.shared.logging.Level;
import com.ulcjava.testframework.ServerSideCommand;
import com.ulcjava.testframework.development.AbstractSimpleDevelopmentTestCase;
import com.ulcjava.testframework.development.DevelopmentTestEnvironmentAdapter;
import com.ulcjava.testframework.operator.ULCButtonOperator;
import com.ulcjava.testframework.operator.ULCFrameOperator;

import java.util.Properties;

public class PR7639ServerToClientTest extends AbstractSimpleDevelopmentTestCase {
    
    private MyULCButton fMyULCButton;
    private MyUIButton fUiButton;
    
    public void testPropertiesCoder() {
        ULCFrameOperator frame = new ULCFrameOperator("PR7639ServerToClientTest");
        final ULCButtonOperator button = new ULCButtonOperator(frame);
        
        Properties defaults = new Properties();
        defaults.setProperty("clientKeyInDefaults", "valueInDefault");
        defaults.put("clientKeyInDefaultNonStr", new Customer());
        
        final Properties clientProps = new Properties(defaults);
        clientProps.setProperty("clientKeyInProperties", "nameInProperties");
        clientProps.put("clientKeyInPropertiesNonStr", new Customer());
        
        fUiButton = (MyUIButton)button.getUIButton();
        fUiButton.setProperties(clientProps);
        fUiButton.sendPropToServer();
        
        runVoidCommand(new ServerSideCommand() {
            protected void proceedOnServer() throws Throwable {
                
                assertEquals(clientProps.getProperty("clientKeyInProperties"), fMyULCButton.getProperties().getProperty(
                        "clientKeyInProperties"));
                assertEquals(clientProps.getProperty("clientKeyInDefaults"), fMyULCButton.getProperties()
                        .getProperty("clientKeyInDefaults"));
                
                assertEquals(null, fMyULCButton.getProperties().getProperty("clietKeyInPropertiesNonStr"));
                assertEquals(null, fMyULCButton.getProperties().getProperty("clientKeyInDefaultsonStr"));
                
                fMyULCButton.sendPropToClient();
            }
        });
        
        assertEquals(fMyULCButton.getProperties().getProperty("serverKeyInProperties"), fUiButton.getProperties().getProperty(
                "serverKeyInProperties"));
        assertEquals(fMyULCButton.getProperties().getProperty("serverKeyInDefaults"), fUiButton.getProperties().getProperty(
                "serverKeyInDefaults"));
        
        assertEquals(null, fUiButton.getProperties().getProperty("serverKeyInPropertiesNonStr"));
        assertEquals(null, fUiButton.getProperties().getProperty("serverKeyInDefaultsonStr"));
        
    }
    
    protected void configure(DevelopmentTestEnvironmentAdapter adapter) {
        super.configure(adapter);
        adapter.setLogLevel(Level.INFO);
    }
    
    public static void main(String[] _args) {
        DevelopmentRunner.setApplicationClass(PR7639ServerToClientTest.class);
        DevelopmentRunner.main(_args);
    }
    
    public void start() {
        ULCFrame frame = new ULCFrame("PR7639ServerToClientTest");
        
        fMyULCButton = new MyULCButton("button");
        frame.getContentPane().add(fMyULCButton);
        frame.setSize(300, 200);
        frame.setDefaultCloseOperation(ULCFrame.TERMINATE_ON_CLOSE);
        frame.setVisible(true);
    }
    
    public static class Customer {
        private int id = 1;
        private String name = "Name";
    }
    
    public static class MyULCButton extends ULCButton {
        private Properties fProperties;
        
        public MyULCButton(String label) {
            super(label);
            
        }
        
        
        protected String typeString() {
            return MyUIButton.class.getName();
        }
        
        public void sendPropToClient() {
            Properties defaults = new Properties();
            defaults.setProperty("serverKeyInDefaults", "valueInDefault");
            defaults.put("serverKeyInDefaultNonStr", new Customer());
            
            fProperties = new Properties(defaults);
            fProperties.setProperty("serverKeyInProperties", "nameInProperties");
            fProperties.put("serverKeyInPropertiesNonStr", new Customer());
            invokeUI("setProperties", new Object[] {fProperties});
        }
        
        public Properties getProperties() {
            return fProperties;
        }
        
        public void updateProperties(Properties properties) {
            fProperties = properties;
        }
    }
    
    public static class MyUIButton extends UIButton {
        private Properties fProperties;
        
        public void setProperties(Properties properties) {
            fProperties = properties;
        }
        
        public void sendPropToServer() {
            invokeULC("updateProperties", new Object[] {fProperties});
        }
        
        public Properties getProperties() {
            return fProperties;
        }
    }
}