| package org.osbp.mysmartshop.dtos; |
| |
| import java.beans.PropertyChangeListener; |
| import java.io.Serializable; |
| import java.util.Collections; |
| import java.util.List; |
| import javax.validation.Valid; |
| import org.eclipse.osbp.dsl.common.datatypes.IDto; |
| import org.eclipse.osbp.dsl.dto.lib.MappingContext; |
| import org.eclipse.osbp.runtime.common.annotations.Dispose; |
| import org.eclipse.osbp.runtime.common.annotations.DomainReference; |
| import org.osbp.mysmartshop.dtos.BaseUUIDDto; |
| import org.osbp.mysmartshop.dtos.DtoTestBeanDto; |
| import org.osbp.mysmartshop.dtos.DtoTestChildContainmentDto; |
| import org.osbp.mysmartshop.dtos.DtoTestChildCrossRefDto; |
| |
| @SuppressWarnings("all") |
| public class DtoTestParentDto extends BaseUUIDDto implements IDto, Serializable, PropertyChangeListener { |
| private String string; |
| |
| @DomainReference |
| @Valid |
| private List<DtoTestChildContainmentDto> containmentChilds; |
| |
| @DomainReference |
| private List<DtoTestChildCrossRefDto> crossRefChilds; |
| |
| @DomainReference |
| private DtoTestChildCrossRefDto crossRefChild; |
| |
| @Valid |
| private DtoTestBeanDto beanx; |
| |
| public DtoTestParentDto() { |
| installLazyCollections(); |
| } |
| |
| /** |
| * Installs lazy collection resolving for entity {@link DtoTestParent} to the dto {@link DtoTestParentDto}. |
| * |
| */ |
| protected void installLazyCollections() { |
| super.installLazyCollections(); |
| containmentChilds = new org.eclipse.osbp.dsl.dto.lib.OppositeContainmentDtoList<>( |
| org.eclipse.osbp.dsl.dto.lib.MappingContext.getCurrent(), |
| DtoTestChildContainmentDto.class, "container.id", |
| (java.util.function.Supplier<Object> & Serializable) this::getId); |
| crossRefChilds = new org.eclipse.osbp.dsl.dto.lib.OppositeDtoList<>( |
| org.eclipse.osbp.dsl.dto.lib.MappingContext.getCurrent(), |
| DtoTestChildCrossRefDto.class, "container.id", |
| (java.util.function.Supplier<Object> & Serializable) this::getId); |
| } |
| |
| /** |
| * Checks whether the object is disposed. |
| * @throws RuntimeException if the object is disposed. |
| */ |
| private void checkDisposed() { |
| if (isDisposed()) { |
| throw new RuntimeException("Object already disposed: " + this); |
| } |
| } |
| |
| /** |
| * Calling dispose will destroy that instance. The internal state will be |
| * set to 'disposed' and methods of that object must not be used anymore. |
| * Each call will result in runtime exceptions.<br/> |
| * If this object keeps composition containments, these will be disposed too. |
| * So the whole composition containment tree will be disposed on calling this method. |
| */ |
| @Dispose |
| public void dispose() { |
| if (isDisposed()) { |
| return; |
| } |
| try { |
| // Dispose all the composition references. |
| if (this.containmentChilds != null) { |
| for (DtoTestChildContainmentDto dtoTestChildContainmentDto : this.containmentChilds) { |
| dtoTestChildContainmentDto.dispose(); |
| } |
| this.containmentChilds = null; |
| } |
| |
| } |
| finally { |
| super.dispose(); |
| } |
| |
| } |
| |
| /** |
| * Returns the string property or <code>null</code> if not present. |
| */ |
| public String getString() { |
| return this.string; |
| } |
| |
| /** |
| * Sets the <code>string</code> property to this instance. |
| * |
| * @param string - the property |
| * @throws RuntimeException if instance is <code>disposed</code> |
| * |
| */ |
| public void setString(final String string) { |
| firePropertyChange("string", this.string, this.string = string ); |
| } |
| |
| /** |
| * Returns an unmodifiable list of containmentChilds. |
| */ |
| public List<DtoTestChildContainmentDto> getContainmentChilds() { |
| return Collections.unmodifiableList(internalGetContainmentChilds()); |
| } |
| |
| /** |
| * Returns the list of <code>DtoTestChildContainmentDto</code>s thereby lazy initializing it. For internal use only! |
| * |
| * @return list - the resulting list |
| * |
| */ |
| public List<DtoTestChildContainmentDto> internalGetContainmentChilds() { |
| if (this.containmentChilds == null) { |
| this.containmentChilds = new java.util.ArrayList<DtoTestChildContainmentDto>(); |
| } |
| return this.containmentChilds; |
| } |
| |
| /** |
| * Adds the given dtoTestChildContainmentDto to this object. <p> |
| * Since the reference is a composition reference, the opposite reference <code>DtoTestChildContainmentDto#container</code> of the <code>dtoTestChildContainmentDto</code> will be handled automatically and no further coding is required to keep them in sync.<p> |
| * See {@link DtoTestChildContainmentDto#setContainer(DtoTestChildContainmentDto)}. |
| * |
| * @param dtoTestChildContainmentDto - the property |
| * @throws RuntimeException if instance is <code>disposed</code> |
| * |
| */ |
| public void addToContainmentChilds(final DtoTestChildContainmentDto dtoTestChildContainmentDto) { |
| checkDisposed(); |
| |
| dtoTestChildContainmentDto.setContainer(this); |
| } |
| |
| /** |
| * Removes the given dtoTestChildContainmentDto from this object. <p> |
| * |
| * @param dtoTestChildContainmentDto - the property |
| * @throws RuntimeException if instance is <code>disposed</code> |
| * |
| */ |
| public void removeFromContainmentChilds(final DtoTestChildContainmentDto dtoTestChildContainmentDto) { |
| checkDisposed(); |
| |
| dtoTestChildContainmentDto.setContainer(null); |
| } |
| |
| /** |
| * For internal use only! |
| */ |
| public void internalAddToContainmentChilds(final DtoTestChildContainmentDto dtoTestChildContainmentDto) { |
| |
| List<DtoTestChildContainmentDto> oldList = new java.util.ArrayList<>(internalGetContainmentChilds()); |
| internalGetContainmentChilds().add(dtoTestChildContainmentDto); |
| firePropertyChange("containmentChilds", oldList, internalGetContainmentChilds()); |
| } |
| |
| /** |
| * For internal use only! |
| */ |
| public void internalRemoveFromContainmentChilds(final DtoTestChildContainmentDto dtoTestChildContainmentDto) { |
| List<DtoTestChildContainmentDto> oldList = new java.util.ArrayList<>(internalGetContainmentChilds()); |
| internalGetContainmentChilds().remove(dtoTestChildContainmentDto); |
| firePropertyChange("containmentChilds", oldList, internalGetContainmentChilds()); |
| } |
| |
| /** |
| * Sets the <code>containmentChilds</code> property to this instance. |
| * Since the reference has an opposite reference, the opposite <code>DtoTestChildContainmentDto# |
| * container</code> of the <code>containmentChilds</code> will be handled automatically and no |
| * further coding is required to keep them in sync.<p> |
| * See {@link DtoTestChildContainmentDto#setContainer(DtoTestChildContainmentDto) |
| * |
| * @param containmentChilds - the property |
| * @throws RuntimeException if instance is <code>disposed</code> |
| * |
| */ |
| public void setContainmentChilds(final List<DtoTestChildContainmentDto> containmentChilds) { |
| checkDisposed(); |
| for (DtoTestChildContainmentDto dto : internalGetContainmentChilds().toArray(new DtoTestChildContainmentDto[this.containmentChilds.size()])) { |
| removeFromContainmentChilds(dto); |
| } |
| |
| if(containmentChilds == null) { |
| return; |
| } |
| |
| for (DtoTestChildContainmentDto dto : containmentChilds) { |
| addToContainmentChilds(dto); |
| } |
| } |
| |
| /** |
| * Returns an unmodifiable list of crossRefChilds. |
| */ |
| public List<DtoTestChildCrossRefDto> getCrossRefChilds() { |
| return Collections.unmodifiableList(internalGetCrossRefChilds()); |
| } |
| |
| /** |
| * Returns the list of <code>DtoTestChildCrossRefDto</code>s thereby lazy initializing it. For internal use only! |
| * |
| * @return list - the resulting list |
| * |
| */ |
| public List<DtoTestChildCrossRefDto> internalGetCrossRefChilds() { |
| if (this.crossRefChilds == null) { |
| this.crossRefChilds = new java.util.ArrayList<DtoTestChildCrossRefDto>(); |
| } |
| return this.crossRefChilds; |
| } |
| |
| /** |
| * Adds the given dtoTestChildCrossRefDto to this object. <p> |
| * Since the reference is a composition reference, the opposite reference <code>DtoTestChildCrossRefDto#container</code> of the <code>dtoTestChildCrossRefDto</code> will be handled automatically and no further coding is required to keep them in sync.<p> |
| * See {@link DtoTestChildCrossRefDto#setContainer(DtoTestChildCrossRefDto)}. |
| * |
| * @param dtoTestChildCrossRefDto - the property |
| * @throws RuntimeException if instance is <code>disposed</code> |
| * |
| */ |
| public void addToCrossRefChilds(final DtoTestChildCrossRefDto dtoTestChildCrossRefDto) { |
| checkDisposed(); |
| |
| dtoTestChildCrossRefDto.setContainer(this); |
| } |
| |
| /** |
| * Removes the given dtoTestChildCrossRefDto from this object. <p> |
| * |
| * @param dtoTestChildCrossRefDto - the property |
| * @throws RuntimeException if instance is <code>disposed</code> |
| * |
| */ |
| public void removeFromCrossRefChilds(final DtoTestChildCrossRefDto dtoTestChildCrossRefDto) { |
| checkDisposed(); |
| |
| dtoTestChildCrossRefDto.setContainer(null); |
| } |
| |
| /** |
| * For internal use only! |
| */ |
| public void internalAddToCrossRefChilds(final DtoTestChildCrossRefDto dtoTestChildCrossRefDto) { |
| |
| List<DtoTestChildCrossRefDto> oldList = new java.util.ArrayList<>(internalGetCrossRefChilds()); |
| internalGetCrossRefChilds().add(dtoTestChildCrossRefDto); |
| firePropertyChange("crossRefChilds", oldList, internalGetCrossRefChilds()); |
| } |
| |
| /** |
| * For internal use only! |
| */ |
| public void internalRemoveFromCrossRefChilds(final DtoTestChildCrossRefDto dtoTestChildCrossRefDto) { |
| List<DtoTestChildCrossRefDto> oldList = new java.util.ArrayList<>(internalGetCrossRefChilds()); |
| internalGetCrossRefChilds().remove(dtoTestChildCrossRefDto); |
| firePropertyChange("crossRefChilds", oldList, internalGetCrossRefChilds()); |
| } |
| |
| /** |
| * Sets the <code>crossRefChilds</code> property to this instance. |
| * Since the reference has an opposite reference, the opposite <code>DtoTestChildCrossRefDto# |
| * container</code> of the <code>crossRefChilds</code> will be handled automatically and no |
| * further coding is required to keep them in sync.<p> |
| * See {@link DtoTestChildCrossRefDto#setContainer(DtoTestChildCrossRefDto) |
| * |
| * @param crossRefChilds - the property |
| * @throws RuntimeException if instance is <code>disposed</code> |
| * |
| */ |
| public void setCrossRefChilds(final List<DtoTestChildCrossRefDto> crossRefChilds) { |
| checkDisposed(); |
| for (DtoTestChildCrossRefDto dto : internalGetCrossRefChilds().toArray(new DtoTestChildCrossRefDto[this.crossRefChilds.size()])) { |
| removeFromCrossRefChilds(dto); |
| } |
| |
| if(crossRefChilds == null) { |
| return; |
| } |
| |
| for (DtoTestChildCrossRefDto dto : crossRefChilds) { |
| addToCrossRefChilds(dto); |
| } |
| } |
| |
| /** |
| * Returns the crossRefChild property or <code>null</code> if not present. |
| */ |
| public DtoTestChildCrossRefDto getCrossRefChild() { |
| return this.crossRefChild; |
| } |
| |
| /** |
| * Sets the <code>crossRefChild</code> property to this instance. |
| * |
| * @param crossRefChild - the property |
| * @throws RuntimeException if instance is <code>disposed</code> |
| * |
| */ |
| public void setCrossRefChild(final DtoTestChildCrossRefDto crossRefChild) { |
| checkDisposed(); |
| firePropertyChange("crossRefChild", this.crossRefChild, this.crossRefChild = crossRefChild); |
| } |
| |
| /** |
| * Returns the beanx property. |
| */ |
| public DtoTestBeanDto getBeanx() { |
| if(this.beanx== null){ |
| this.beanx = new DtoTestBeanDto(); |
| } |
| return this.beanx; |
| } |
| |
| /** |
| * Sets the <code>beanx</code> property to this instance. |
| * |
| * @param beanx - the property |
| * @throws RuntimeException if instance is <code>disposed</code> |
| * |
| */ |
| public void setBeanx(final DtoTestBeanDto beanx) { |
| // ensure that embedded beans will notify their parent about changes |
| // so their dirty state can be handled properly |
| if (this.beanx != null) { |
| this.beanx.removePropertyChangeListener(this); |
| } |
| |
| firePropertyChange("beanx", this.beanx, this.beanx = beanx ); |
| |
| if (this.beanx != null) { |
| this.beanx.addPropertyChangeListener(this); |
| } |
| } |
| |
| public DtoTestParentDto createDto() { |
| return new DtoTestParentDto(); |
| } |
| |
| public DtoTestParentDto copy(final MappingContext context) { |
| checkDisposed(); |
| |
| if (context == null) { |
| throw new IllegalArgumentException("Context must not be null!"); |
| } |
| |
| if(context.isMaxLevel()){ |
| return null; |
| } |
| |
| // if context contains a copied instance of this object |
| // then return it |
| DtoTestParentDto newDto = context.get(this); |
| if(newDto != null){ |
| return newDto; |
| } |
| |
| try{ |
| context.increaseLevel(); |
| |
| newDto = createDto(); |
| context.register(this, newDto); |
| |
| // first copy the containments and attributes |
| copyContainments(this, newDto, context); |
| |
| // then copy cross references to ensure proper |
| // opposite references are copied too. |
| copyCrossReferences(this, newDto, context); |
| } finally { |
| context.decreaseLevel(); |
| } |
| |
| return newDto; |
| } |
| |
| public void copyContainments(final DtoTestParentDto dto, final DtoTestParentDto newDto, final MappingContext context) { |
| checkDisposed(); |
| |
| if (context == null) { |
| throw new IllegalArgumentException("Context must not be null!"); |
| } |
| |
| super.copyContainments(dto, newDto, context); |
| |
| // copy attributes and beans (beans if derived from entity model) |
| // copy string |
| newDto.setString(getString()); |
| // copy dto beanx |
| if(getBeanx() != null) { |
| newDto.setBeanx(getBeanx().copy(context)); |
| } |
| |
| // copy containment references (cascading is true) |
| // copy list of containmentChilds dtos |
| for(org.osbp.mysmartshop.dtos.DtoTestChildContainmentDto _dto : getContainmentChilds()) { |
| newDto.addToContainmentChilds(_dto.copy(context)); |
| } |
| } |
| |
| public void copyCrossReferences(final DtoTestParentDto dto, final DtoTestParentDto newDto, final org.eclipse.osbp.dsl.dto.lib.MappingContext context) { |
| checkDisposed(); |
| |
| if (context == null) { |
| throw new IllegalArgumentException("Context must not be null!"); |
| } |
| |
| super.copyCrossReferences(dto, newDto, context); |
| |
| // copy cross references (cascading is false) |
| // copy list of crossRefChilds dtos |
| for(org.osbp.mysmartshop.dtos.DtoTestChildCrossRefDto _dto : getCrossRefChilds()) { |
| newDto.addToCrossRefChilds(_dto.copy(context)); |
| } |
| // copy dto crossRefChild |
| if(getCrossRefChild() != null) { |
| newDto.setCrossRefChild(getCrossRefChild().copy(context)); |
| } |
| } |
| |
| public void propertyChange(final java.beans.PropertyChangeEvent event) { |
| Object source = event.getSource(); |
| |
| // forward the event from embeddable beans to all listeners. So the parent of the embeddable |
| // bean will become notified and its dirty state can be handled properly |
| if(source == beanx){ |
| firePropertyChange("beanx" + "_" + event.getPropertyName(), event.getOldValue(), event.getNewValue()); |
| } else |
| { |
| super.propertyChange(event); |
| } |
| } |
| } |