Skip to content

Commit

Permalink
m-m-m/bean#7: getReadOnly() and WritableBean constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
hohwille committed May 5, 2024
1 parent 7c6594b commit 1d2795e
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import io.github.mmm.bean.Bean;
import io.github.mmm.bean.BeanName;
import io.github.mmm.bean.DynamicBean;
import io.github.mmm.bean.WritableBean;
import io.github.mmm.property.string.StringProperty;

/**
Expand All @@ -25,15 +26,26 @@ public class Person extends DynamicBean {
*/
public Person() {

super();
this(null);
}

/**
* The constructor.
*
* @param writable the {@link WritableBean} to wrap as {@link #isReadOnly() read-only} bean or {@code null} to create
* a mutable bean.
*/
public Person(WritableBean writable) {

super(writable);
this.FirstName = add().newString().withValidator().mandatory().and().build("FirstName");
this.LastName = add().newString().withValidator().mandatory().and().build("LastName");
}

@Override
protected AbstractBean create() {
protected AbstractBean create(WritableBean writable) {

return new Person();
return new Person(writable);
}

}
Original file line number Diff line number Diff line change
@@ -1,39 +1,51 @@
/* Copyright (c) The m-m-m Team, Licensed under the Apache License, Version 2.0
* http://www.apache.org/licenses/LICENSE-2.0 */
package io.github.mmm.ui.demo.shared.place.content.widget.data;

import io.github.mmm.bean.AbstractBean;
import io.github.mmm.bean.Bean;
import io.github.mmm.bean.BeanName;
import io.github.mmm.property.number.integers.IntegerProperty;
import io.github.mmm.property.string.StringProperty;

/**
* A {@link Bean} for testing.
*/
@BeanName("mmm.TestBean")
public class TestBean extends Bean {

/** Full name of person. */
public final StringProperty Name;

/** Age of person. */
public final IntegerProperty Age;

/**
* The constructor.
*/
public TestBean() {

super();
this.Name = add().newString().withValidator().mandatory().and().build("Name");
this.Age = add().newInteger("Age");
}

@Override
protected AbstractBean create() {

return new TestBean();
}

}
/* Copyright (c) The m-m-m Team, Licensed under the Apache License, Version 2.0
* http://www.apache.org/licenses/LICENSE-2.0 */
package io.github.mmm.ui.demo.shared.place.content.widget.data;

import io.github.mmm.bean.AbstractBean;
import io.github.mmm.bean.Bean;
import io.github.mmm.bean.BeanName;
import io.github.mmm.bean.WritableBean;
import io.github.mmm.property.number.integers.IntegerProperty;
import io.github.mmm.property.string.StringProperty;

/**
* A {@link Bean} for testing.
*/
@BeanName("mmm.TestBean")
public class TestBean extends Bean {

/** Full name of person. */
public final StringProperty Name;

/** Age of person. */
public final IntegerProperty Age;

/**
* The constructor.
*/
public TestBean() {

this(null);
}

/**
* The constructor.
*
* @param writable the {@link WritableBean} to wrap as {@link #isReadOnly() read-only} bean or {@code null} to create
* a mutable bean.
*/
public TestBean(WritableBean writable) {

super(writable);
this.Name = add().newString().withValidator().mandatory().and().build("Name");
this.Age = add().newInteger("Age");
}

@Override
protected AbstractBean create(WritableBean writable) {

return new TestBean(writable);
}

}

0 comments on commit 1d2795e

Please sign in to comment.