public interface Bean
generic
properties
. Unlike plain old Java Beans this offers a lot of advanced features:
BeanAccess.getProperties()
. No greedy introspection
via reflection for each access but only once per Bean
interface.dynamic
beans. E.g. if
read data from Database, XML, or JSON you can still map "undefined" properties in your Bean
. This way a
client can receive an object from a newer version of a database or (REST-)service with added properties that will be
kept in the object and send back when the Bean
is written back.#equals(Object)
, #hashCode()
, or
#toString()
. Also general getters and setters are automatically implemented.Bean
interface via default methods including custom
implementations of equals
and hashCode
if needed.create
a read-only
view of your object to pass by reference without side-effects.WritableProperty
is based on JavaFx Property
supporting listeners and bindings but also additional features such as
generic type information
.validation support
. This can be configured via
Bean-Validation standard (JSR303) or even more efficient and reusable via custom properties or in default methods for
the properties of your Bean
interface.from
and
to
JSON is already build in and is extremely efficient. If
you need custom datatypes you can simply extend GenericProperty
and tweak the JSON mapping as needed. No
separate classes for mapping from or to JSON are required - also not for database if you use Java standard datatypes
as value and keep your custom logic in the property.Bean
interface as in the following example:
public interface AddressBean extendsIn order to create a new instance ofBean
{StringProperty
Street();StringProperty
HouseNumber();StringProperty
PostalCode();StringProperty
City();StringProperty
Country(); // if you want you may also define regular getters and setters as well String getStreet(); void setStreet(String street); }
AddressBean
simply do this:
public void MyClass { @If you are very pragmatic do not likeInject
privateBeanFactory
beanFactory; public void doSomething() { AddressBean address = this.beanFactory.create
(AddressBean.class); address.Street().setValue("Baker Street"); address.HouseNumber().setValue("1a"); address.PostalCode().setValue("6wn7ta"); address.City().setValue("Rafferty"); address.Country().setValue("Gerryland"); for (Property <?> property: address.access()
.getProperties()
) { System.out.println("Property '" + property.getName()
+ "' of type ' + property.getType()
+ ' has value '" + property.getValue()
+ "'."); } } }
Ioc
you can also use
BeanFactoryImpl.getInstance()
. For most simplistic fabrication you can create a
static method to your Bean
: static AddressBean create() { return BeanFactoryImpl.getInstance().create(AddressBean.class); }
Modifier and Type | Method and Description |
---|---|
BeanAccess |
access() |
BeanAccess access()
BeanAccess
with all generic features and methods on a Bean
. These are encapsulated in
BeanAccess
to avoid polluting this Bean
interface itself with additional methods and for
better compatibility on enhancements.Copyright © 2001–2016 mmm-Team. All rights reserved.