ThingWorx Edge Java SDK > Application Details > Defining Properties > Example of Creating a Property Definition with Aspects
Example of Creating a Property Definition with Aspects
This topic shows an example of creating a property definition, with a name, description, and base type, and then adding an aspect collection. The example shown below includes the following aspects: dataChangeType, dataChangeThreshold, cacheTime, isPersistent, isReadOnly, pushType, and a default value for the property. Once all the aspects are added to the collection, the aspects are set to the property definition, and the property definition is associated with the VirtualThing instance.
Example 3. Property Definition with Aspects

//Create the property definition with name, description, and baseType
PropertyDefinition property1 = new PropertyDefinition(
"Property1",
"Description for Property1",
BaseTypes.BOOLEAN);

//Create an aspect collection to hold all of the different aspects
AspectCollection aspects = new AspectCollection();

//Add the dataChangeType aspect
aspects.put(Aspects.ASPECT_DATACHANGETYPE,
new StringPrimitive(DataChangeType.NEVER.name()));

//Add the dataChangeThreshold aspect
aspects.put(Aspects.ASPECT_DATACHANGETHRESHOLD, new NumberPrimitive(0.0));

//Add the cacheTime aspect
aspects.put(Aspects.ASPECT_CACHETIME, new IntegerPrimitive(0));

//Add the isPersistent aspect
aspects.put(Aspects.ASPECT_ISPERSISTENT, new BooleanPrimitive(false));

//Add the isReadOnly aspect
aspects.put(Aspects.ASPECT_ISREADONLY, new BooleanPrimitive(false));

//Add the pushType aspect
aspects.put("pushType", new StringPrimitive(DataChangeType.NEVER.name()));

//Add the defaultValue aspect
aspects.put(Aspects.ASPECT_DEFAULTVALUE, new BooleanPrimitive(true));

//Set the aspects of the property definition
property1.setAspects(aspects);

//Add the property definition to the VirtualThing
this.defineProperty(property1);
Was this helpful?