de.smartics.properties.tutorial.property.expressions
Class PropertyExpressionsTutorial

Package class diagram package PropertyExpressionsTutorial
java.lang.Object
  extended by de.smartics.properties.tutorial.property.expressions.PropertyExpressionsTutorial

@Document(title="Property Expressions",
          sortKey="basics0060")
@DocCategory(value="basics")
public class PropertyExpressionsTutorial
     
     
extends Object

This tutorial introduces how to add expressions to the property declaration.

Expressions allow to declare default values and to construct property values out of other property values.


Constructor Summary
PropertyExpressionsTutorial()
           
 
Method Summary
 void composedUrlValue()
           The URL property of homePageUrl is per default constructed by host and port.
 void overrideValues()
           If the default values of properties are overridden, the expressions take the correct current value (as you would expect).
 void overrideValuesAtRuntime()
           So here is the example where we change a read-write property, using a properties key.
 void overrideValuesAtRuntimeFailsForReadOnlyProperties()
           If the property is changed, the composed property also reflects the change (as one would expect).
 void setUp()
           
 void simpleIntValue()
           The property port defaults to 808.
 void simpleStringValue()
           The property host defaults to localhost.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PropertyExpressionsTutorial

public PropertyExpressionsTutorial()
Method Detail

setUp

public void setUp()

simpleStringValue

@DocSection
public void simpleStringValue()

The property host defaults to localhost.


simpleIntValue

@DocSection
public void simpleIntValue()

The property port defaults to 808.


composedUrlValue

@DocSection
public void composedUrlValue()
                      throws MalformedURLException

The URL property of homePageUrl is per default constructed by host and port.

Throws:
MalformedURLException

overrideValues

@DocSection
public void overrideValues()
                    throws MalformedURLException

If the default values of properties are overridden, the expressions take the correct current value (as you would expect).

The properties definition is this:

Here is how we access the home page URL property:

Throws:
MalformedURLException

overrideValuesAtRuntimeFailsForReadOnlyProperties

@DocSection
public void overrideValuesAtRuntimeFailsForReadOnlyProperties()
                                                       throws MalformedURLException

If the property is changed, the composed property also reflects the change (as one would expect). But the property has to be marked as AccessType.READ_WRITE.

It would be more elegant and less error prone, if the key is fetched from the property set as shown in the next example.

Throws:
MalformedURLException

overrideValuesAtRuntime

@DocSection
public void overrideValuesAtRuntime()
                             throws MalformedURLException

So here is the example where we change a read-write property, using a properties key.

Throws:
MalformedURLException


Copyright © 2012-2013 Kronseder & Reiner GmbH - smartics. All Rights Reserved.