| /** |
| * |
| * Copyright (c) 2011, 2016 - Loetz GmbH&Co.KG (69115 Heidelberg, Germany) |
| * |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License 2.0 |
| * which accompanies this distribution, and is available at |
| * https://www.eclipse.org/legal/epl-2.0/ |
| * |
| * SPDX-License-Identifier: EPL-2.0 |
| * |
| * Contributors: |
| * Florian Pirchner - Initial implementation |
| * |
| */ |
| package de.compex.ecview.extension.tests.dtos; |
| |
| import java.beans.PropertyChangeListener; |
| import java.beans.PropertyChangeSupport; |
| import java.io.Serializable; |
| import java.util.Date; |
| 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; |
| |
| @SuppressWarnings("all") |
| public class Person implements IDto, Serializable, PropertyChangeListener { |
| private PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport(this); |
| |
| @Dispose |
| private boolean disposed; |
| |
| private String name = java.util.UUID.randomUUID().toString(); |
| |
| private String name2; |
| |
| private int age; |
| |
| @Valid |
| private Date birthday; |
| |
| /** |
| * @return true, if the object is disposed. |
| * Disposed means, that it is prepared for garbage collection and may not be used anymore. |
| * Accessing objects that are already disposed will cause runtime exceptions. |
| * |
| */ |
| public boolean isDisposed() { |
| return this.disposed; |
| } |
| |
| /** |
| * @see PropertyChangeSupport#addPropertyChangeListener(PropertyChangeListener) |
| */ |
| public void addPropertyChangeListener(final PropertyChangeListener listener) { |
| propertyChangeSupport.addPropertyChangeListener(listener); |
| } |
| |
| /** |
| * @see PropertyChangeSupport#addPropertyChangeListener(String, PropertyChangeListener) |
| */ |
| public void addPropertyChangeListener(final String propertyName, final PropertyChangeListener listener) { |
| propertyChangeSupport.addPropertyChangeListener(propertyName, listener); |
| } |
| |
| /** |
| * @see PropertyChangeSupport#removePropertyChangeListener(PropertyChangeListener) |
| */ |
| public void removePropertyChangeListener(final PropertyChangeListener listener) { |
| propertyChangeSupport.removePropertyChangeListener(listener); |
| } |
| |
| /** |
| * @see PropertyChangeSupport#removePropertyChangeListener(String, PropertyChangeListener) |
| */ |
| public void removePropertyChangeListener(final String propertyName, final PropertyChangeListener listener) { |
| propertyChangeSupport.removePropertyChangeListener(propertyName, listener); |
| } |
| |
| /** |
| * @see PropertyChangeSupport#firePropertyChange(String, Object, Object) |
| */ |
| public void firePropertyChange(final String propertyName, final Object oldValue, final Object newValue) { |
| propertyChangeSupport.firePropertyChange(propertyName, oldValue, newValue); |
| } |
| |
| /** |
| * 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; |
| } |
| firePropertyChange("disposed", this.disposed, this.disposed = true); |
| } |
| |
| /** |
| * Installs lazy collection resolving for entity {@link } to the dto {@link Person}. |
| * |
| */ |
| protected void installLazyCollections() { |
| |
| } |
| |
| /** |
| * Returns the name property or <code>null</code> if not present. |
| */ |
| public String getName() { |
| return this.name; |
| } |
| |
| /** |
| * Sets the <code>name</code> property to this instance. |
| * |
| * @param name - the property |
| * @throws RuntimeException if instance is <code>disposed</code> |
| * |
| */ |
| public void setName(final String name) { |
| firePropertyChange("name", this.name, this.name = name ); |
| installLazyCollections(); |
| } |
| |
| /** |
| * Returns the name2 property or <code>null</code> if not present. |
| */ |
| public String getName2() { |
| return this.name2; |
| } |
| |
| /** |
| * Sets the <code>name2</code> property to this instance. |
| * |
| * @param name2 - the property |
| * @throws RuntimeException if instance is <code>disposed</code> |
| * |
| */ |
| public void setName2(final String name2) { |
| firePropertyChange("name2", this.name2, this.name2 = name2 ); |
| } |
| |
| /** |
| * Returns the age property or <code>null</code> if not present. |
| */ |
| public int getAge() { |
| return this.age; |
| } |
| |
| /** |
| * Sets the <code>age</code> property to this instance. |
| * |
| * @param age - the property |
| * @throws RuntimeException if instance is <code>disposed</code> |
| * |
| */ |
| public void setAge(final int age) { |
| firePropertyChange("age", this.age, this.age = age ); |
| } |
| |
| /** |
| * Returns the birthday property or <code>null</code> if not present. |
| */ |
| public Date getBirthday() { |
| return this.birthday; |
| } |
| |
| /** |
| * Sets the <code>birthday</code> property to this instance. |
| * |
| * @param birthday - the property |
| * @throws RuntimeException if instance is <code>disposed</code> |
| * |
| */ |
| public void setBirthday(final Date birthday) { |
| firePropertyChange("birthday", this.birthday, this.birthday = birthday ); |
| } |
| |
| @Override |
| public boolean equals(final Object obj) { |
| if (this == obj) |
| return true; |
| if (obj == null) |
| return false; |
| if (getClass() != obj.getClass()) |
| return false; |
| Person other = (Person) obj; |
| if (this.name == null) { |
| if (other.name != null) |
| return false; |
| } else if (!this.name.equals(other.name)) |
| return false; |
| return true; |
| } |
| |
| @Override |
| public int hashCode() { |
| int prime = 31; |
| int result = 1; |
| result = prime * result + ((this.name== null) ? 0 : this.name.hashCode()); |
| return result; |
| } |
| |
| public Person createDto() { |
| return new Person(); |
| } |
| |
| public Person 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 |
| Person 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 Person dto, final Person newDto, final MappingContext context) { |
| checkDisposed(); |
| |
| if (context == null) { |
| throw new IllegalArgumentException("Context must not be null!"); |
| } |
| |
| |
| // copy attributes and beans (beans if derived from entity model) |
| // copy name |
| newDto.setName(getName()); |
| // copy name2 |
| newDto.setName2(getName2()); |
| // copy age |
| newDto.setAge(getAge()); |
| // copy birthday |
| newDto.setBirthday(getBirthday()); |
| |
| // copy containment references (cascading is true) |
| } |
| |
| public void copyCrossReferences(final Person dto, final Person newDto, final org.eclipse.osbp.dsl.dto.lib.MappingContext context) { |
| checkDisposed(); |
| |
| if (context == null) { |
| throw new IllegalArgumentException("Context must not be null!"); |
| } |
| |
| |
| // copy cross references (cascading is false) |
| } |
| |
| 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 |
| { |
| // no super class available to forward event |
| } |
| } |
| } |