From: <id...@us...> - 2009-04-27 11:32:07
|
Revision: 182 http://cse-ip.svn.sourceforge.net/cse-ip/?rev=182&view=rev Author: idueppe Date: 2009-04-27 11:31:17 +0000 (Mon, 27 Apr 2009) Log Message: ----------- IN PROGRESS: Refactoring of cdmm... Should be compilable and tests are green Modified Paths: -------------- trunk/cse-ip/sc-cdmm/src/main/java/de/campussource/cse/cdmm/domain/AddReferenceVisitor.java trunk/cse-ip/sc-cdmm/src/main/java/de/campussource/cse/cdmm/domain/ReferenceType.java trunk/cse-ip/sc-cdmm/src/main/java/de/campussource/cse/cdmm/domain/ReferencesVisitor.java trunk/cse-ip/sc-cdmm/src/main/java/de/campussource/cse/cdmm/domain/Visitor.java Modified: trunk/cse-ip/sc-cdmm/src/main/java/de/campussource/cse/cdmm/domain/AddReferenceVisitor.java =================================================================== --- trunk/cse-ip/sc-cdmm/src/main/java/de/campussource/cse/cdmm/domain/AddReferenceVisitor.java 2009-04-27 11:30:54 UTC (rev 181) +++ trunk/cse-ip/sc-cdmm/src/main/java/de/campussource/cse/cdmm/domain/AddReferenceVisitor.java 2009-04-27 11:31:17 UTC (rev 182) @@ -4,8 +4,9 @@ /** * Visitor to add Reference to an entity object. + * * @author Ingo Dueppe - * + * */ public class AddReferenceVisitor implements Visitor { @@ -15,8 +16,10 @@ /** * - * @param target entity object to be add as reference - * @param type of reference that will be added + * @param target + * entity object to be add as reference + * @param type + * of reference that will be added */ public AddReferenceVisitor(Entity target, ReferenceType type) { this.type = type; @@ -31,25 +34,38 @@ @Override public void visit(Category category) { - // TODO Auto-generated method stub - throw new NotImplementedException(); + switch (type) { + case CATEGORY: + category.addToParentCategory((Category) target); + break; + case COURSE: + ((Course)target).addToCategory(category); + break; + case PARENT: + category.setParent((Category) target); + break; + default: + throw new IllegalStateException("Reference type doesn't apply to entity."); + } } @Override public void visit(Course course) { switch (type) { - case CATEGORY: - course.addToCategory((Category) target); - break; - case WORKGROUP: - ((Course) target).addAsWorkgroupTo(course); - break; - case PARENT: - course.setParent((Course) target); - break; - case ROLE: - course.addRole((Role)target); - break; + case CATEGORY: + course.addToCategory((Category) target); + break; + case WORKGROUP: + ((Course) target).addAsWorkgroupTo(course); + break; + case PARENT: + course.setParent((Course) target); + break; + case ROLE: + course.addRole((Role) target); + break; + default: + throw new IllegalStateException("Reference type doesn't apply to entity."); } } Modified: trunk/cse-ip/sc-cdmm/src/main/java/de/campussource/cse/cdmm/domain/ReferenceType.java =================================================================== --- trunk/cse-ip/sc-cdmm/src/main/java/de/campussource/cse/cdmm/domain/ReferenceType.java 2009-04-27 11:30:54 UTC (rev 181) +++ trunk/cse-ip/sc-cdmm/src/main/java/de/campussource/cse/cdmm/domain/ReferenceType.java 2009-04-27 11:31:17 UTC (rev 182) @@ -1,5 +1,11 @@ package de.campussource.cse.cdmm.domain; +/** + * Enumeration of all types of references between objects within the domain modell + * + * @author Ingo Dueppe + * + */ public enum ReferenceType { ACCOUNT, Modified: trunk/cse-ip/sc-cdmm/src/main/java/de/campussource/cse/cdmm/domain/ReferencesVisitor.java =================================================================== --- trunk/cse-ip/sc-cdmm/src/main/java/de/campussource/cse/cdmm/domain/ReferencesVisitor.java 2009-04-27 11:30:54 UTC (rev 181) +++ trunk/cse-ip/sc-cdmm/src/main/java/de/campussource/cse/cdmm/domain/ReferencesVisitor.java 2009-04-27 11:31:17 UTC (rev 182) @@ -10,6 +10,14 @@ */ public abstract class ReferencesVisitor implements Visitor { + /** + * Is call for each endpoint of outgoing references of an entity + * @param target entity of the reference + * @param source entity of the reference + */ + public abstract void foundReference(Entity target, Entity source, ReferenceType type); + + @Override public void visit(Account account) { for (Role role : account.getRoles()) { @@ -60,17 +68,12 @@ @Override public void visit(Role role) { - if (role.getCourse() != null) + if (role.getCourse() != null) { foundReference(role.getCourse(), role, ReferenceType.COURSE); - if (role.getAccount() != null) + } + if (role.getAccount() != null) { foundReference(role.getAccount(), role, ReferenceType.ACCOUNT); + } } - /** - * Is call for each endpoint of outgoing references of an entity - * @param target entity of the reference - * @param source entity of the reference - */ - public abstract void foundReference(Entity target, Entity source, ReferenceType type); - } Modified: trunk/cse-ip/sc-cdmm/src/main/java/de/campussource/cse/cdmm/domain/Visitor.java =================================================================== --- trunk/cse-ip/sc-cdmm/src/main/java/de/campussource/cse/cdmm/domain/Visitor.java 2009-04-27 11:30:54 UTC (rev 181) +++ trunk/cse-ip/sc-cdmm/src/main/java/de/campussource/cse/cdmm/domain/Visitor.java 2009-04-27 11:31:17 UTC (rev 182) @@ -1,7 +1,8 @@ package de.campussource.cse.cdmm.domain; /** - * Visitor for Domain + * Visitor for domain object model + * * @author Ingo Dueppe * */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <id...@us...> - 2009-04-27 11:32:32
|
Revision: 183 http://cse-ip.svn.sourceforge.net/cse-ip/?rev=183&view=rev Author: idueppe Date: 2009-04-27 11:31:38 +0000 (Mon, 27 Apr 2009) Log Message: ----------- code polishing Modified Paths: -------------- trunk/cse-ip/sc-cdmm/src/main/java/de/campussource/cse/cdmm/domain/Account.java trunk/cse-ip/sc-cdmm/src/main/java/de/campussource/cse/cdmm/domain/Attribute.java trunk/cse-ip/sc-cdmm/src/main/java/de/campussource/cse/cdmm/domain/Category.java trunk/cse-ip/sc-cdmm/src/main/java/de/campussource/cse/cdmm/domain/Course.java trunk/cse-ip/sc-cdmm/src/main/java/de/campussource/cse/cdmm/domain/State.java trunk/cse-ip/sc-cdmm/src/main/java/de/campussource/cse/cdmm/domain/TransientAttribute.java Modified: trunk/cse-ip/sc-cdmm/src/main/java/de/campussource/cse/cdmm/domain/Account.java =================================================================== --- trunk/cse-ip/sc-cdmm/src/main/java/de/campussource/cse/cdmm/domain/Account.java 2009-04-27 11:31:17 UTC (rev 182) +++ trunk/cse-ip/sc-cdmm/src/main/java/de/campussource/cse/cdmm/domain/Account.java 2009-04-27 11:31:38 UTC (rev 183) @@ -51,7 +51,32 @@ setId(id); } + @XmlElementWrapper(name=Constants.ROLES) + @XmlElement(name=Constants.ROLE) + public List<Role> getRoles() { + return roles; + } + + public void setRoles(List<Role> roles) { + this.roles = roles; + } + /** + * Convenience method to check if account is member of a group + * @param group group to check membership of + * @return membership state of account and given group + */ + public boolean isInGroup(Group group){ + if (group == null){ + return false; + } + if (group.getMembers()==null){ + return false; + } + return (group.getMembers().contains(this)); + } + + /** * Convenience method to add an account to a group * @param group group account should be added to * @return success of operation @@ -77,7 +102,7 @@ group.setMembers(accounts); return true; } - + /** * Convenience method to remove an account from a group * @param group group to remove account from @@ -98,23 +123,23 @@ group.setMembers(accounts); return true; } + + @XmlElementWrapper(name=Constants.GROUPS) + @XmlElement(name=Constants.GROUP) + @XmlIDREF + public List<Group> getGroups() { + return groups; + } + + public void setGroups(List<Group> groups) { + this.groups = groups; + } - /** - * Convenience method to check if account is member of a group - * @param group group to check membership of - * @return membership state of account and given group - */ - public boolean isInGroup(Group group){ - if (group == null){ - return false; - } - if (group.getMembers()==null){ - return false; - } - return (group.getMembers().contains(this)); + public void accept(Visitor visitor) { + visitor.visit(this); } - - @Override + + @Override public boolean equals(Object obj) { if (this == obj) { return true; @@ -141,29 +166,4 @@ public String toString() { return new ToStringBuilder(this, ToStringStyle.DEFAULT_STYLE).append(this.getId()).toString(); } - - @XmlElementWrapper(name=Constants.ROLES) - @XmlElement(name=Constants.ROLE) - public List<Role> getRoles() { - return roles; - } - - public void setRoles(List<Role> roles) { - this.roles = roles; - } - - @XmlElementWrapper(name=Constants.GROUPS) - @XmlElement(name=Constants.GROUP) - @XmlIDREF - public List<Group> getGroups() { - return groups; - } - - public void setGroups(List<Group> groups) { - this.groups = groups; - } - - public void accept(Visitor visitor) { - visitor.visit(this); - } } Modified: trunk/cse-ip/sc-cdmm/src/main/java/de/campussource/cse/cdmm/domain/Attribute.java =================================================================== --- trunk/cse-ip/sc-cdmm/src/main/java/de/campussource/cse/cdmm/domain/Attribute.java 2009-04-27 11:31:17 UTC (rev 182) +++ trunk/cse-ip/sc-cdmm/src/main/java/de/campussource/cse/cdmm/domain/Attribute.java 2009-04-27 11:31:38 UTC (rev 183) @@ -6,7 +6,10 @@ import javax.xml.bind.annotation.XmlType; import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; +import org.apache.commons.lang.builder.ToStringBuilder; +import org.apache.commons.lang.builder.ToStringStyle; + /** * Attribute entity object * @author Sebastian Roekens @@ -55,5 +58,43 @@ public void setValue(String value) { this.value = value; } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((name == null) ? 0 : name.hashCode()); + result = prime * result + (trans ? 1231 : 1237); + result = prime * result + ((value == null) ? 0 : value.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Attribute other = (Attribute) obj; + if (name == null) { + if (other.name != null) + return false; + } else if (!name.equals(other.name)) + return false; + if (trans != other.trans) + return false; + if (value == null) { + if (other.value != null) + return false; + } else if (!value.equals(other.value)) + return false; + return true; + } + public String toString() { + return new ToStringBuilder(this, ToStringStyle.DEFAULT_STYLE).append(name).append(value).toString(); + } + } Modified: trunk/cse-ip/sc-cdmm/src/main/java/de/campussource/cse/cdmm/domain/Category.java =================================================================== --- trunk/cse-ip/sc-cdmm/src/main/java/de/campussource/cse/cdmm/domain/Category.java 2009-04-27 11:31:17 UTC (rev 182) +++ trunk/cse-ip/sc-cdmm/src/main/java/de/campussource/cse/cdmm/domain/Category.java 2009-04-27 11:31:38 UTC (rev 183) @@ -39,10 +39,10 @@ private Category parent; @OneToMany(mappedBy = Constants.PARENT, cascade = { CascadeType.REMOVE }) - private List<Category> children = new ArrayList<Category>(); + private List<Category> children = new ArrayList<Category>(5); @ManyToMany(mappedBy = Constants.CATEGORIES) - private List<Course> courses = new ArrayList<Course>(); + private List<Course> courses = new ArrayList<Course>(5); public Category() { } Modified: trunk/cse-ip/sc-cdmm/src/main/java/de/campussource/cse/cdmm/domain/Course.java =================================================================== --- trunk/cse-ip/sc-cdmm/src/main/java/de/campussource/cse/cdmm/domain/Course.java 2009-04-27 11:31:17 UTC (rev 182) +++ trunk/cse-ip/sc-cdmm/src/main/java/de/campussource/cse/cdmm/domain/Course.java 2009-04-27 11:31:38 UTC (rev 183) @@ -40,7 +40,7 @@ private Course parent; @OneToMany(mappedBy=Constants.PARENT, cascade=CascadeType.REMOVE) - private List<Course> workgroups = new ArrayList<Course>(3); + private List<Course> workgroups = new ArrayList<Course>(2); @ManyToMany(cascade={CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REFRESH}) @JoinTable( @@ -114,10 +114,6 @@ return true; } - public String toString() { - return new ToStringBuilder(this, ToStringStyle.DEFAULT_STYLE).toString(); - } - @XmlElement(name=Constants.PARENT) @XmlIDREF public Course getParent() { @@ -158,10 +154,6 @@ public void setRoles(List<Role> roles) { this.roles = roles; } - - public void accept(Visitor visitor) { - visitor.visit(this); - } public void addRole(Role role) { if (role != null) { @@ -170,5 +162,13 @@ } } + public void accept(Visitor visitor) { + visitor.visit(this); + } + + public String toString() { + return new ToStringBuilder(this, ToStringStyle.DEFAULT_STYLE).toString(); + } + } Modified: trunk/cse-ip/sc-cdmm/src/main/java/de/campussource/cse/cdmm/domain/State.java =================================================================== --- trunk/cse-ip/sc-cdmm/src/main/java/de/campussource/cse/cdmm/domain/State.java 2009-04-27 11:31:17 UTC (rev 182) +++ trunk/cse-ip/sc-cdmm/src/main/java/de/campussource/cse/cdmm/domain/State.java 2009-04-27 11:31:38 UTC (rev 183) @@ -1,7 +1,31 @@ package de.campussource.cse.cdmm.domain; -public enum State{ - NOT_EXISTS, - KNOWN, - EXISTS, + +import javax.xml.bind.annotation.XmlEnum; +import javax.xml.bind.annotation.XmlEnumValue; +import javax.xml.bind.annotation.XmlType; + +/** + * State of the domain objects. + * + * <ul> + * <li><strong>NOT_EXISTS</strong> <br/> An entity that doesn't exists within the database. This is an initial temporary state. </li> + * <li><strong>KNOWN</strong> <br/> An entity that is referenced by existing entities, but was not until now explicit created by an event.</li> + * <li><strong>EXISTS</strong> <br/> An entity that exists in the database. </li> + * <li><strong>DELETED</strong> <br> An entity that is marked as deleted.</li> + * <ul> + * + * @author Ingo Dueppe + * @author Sebastian Roekens + */ +@XmlEnum +@XmlType(name="STATE", namespace=Constants.NAMESPACE_DATATYPES) +public enum State { + @XmlEnumValue(value="NOT_EXISTS") + NOT_EXISTS, + @XmlEnumValue(value="KNOWN") + KNOWN, + @XmlEnumValue(value="EXISTS") + EXISTS, + @XmlEnumValue(value="DELETED") DELETED } Modified: trunk/cse-ip/sc-cdmm/src/main/java/de/campussource/cse/cdmm/domain/TransientAttribute.java =================================================================== --- trunk/cse-ip/sc-cdmm/src/main/java/de/campussource/cse/cdmm/domain/TransientAttribute.java 2009-04-27 11:31:17 UTC (rev 182) +++ trunk/cse-ip/sc-cdmm/src/main/java/de/campussource/cse/cdmm/domain/TransientAttribute.java 2009-04-27 11:31:38 UTC (rev 183) @@ -4,14 +4,16 @@ /** * Representation of an attribute object, which should not be saved persistent + * * @author Sebastian Roekens - * + * */ @XmlTransient public class TransientAttribute extends Attribute { - public TransientAttribute(){} - public TransientAttribute(String name, String value){ + public TransientAttribute() {} + + public TransientAttribute(String name, String value) { setName(name); setValue(value); setTransient(true); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ro...@us...> - 2009-05-14 12:38:08
|
Revision: 213 http://cse-ip.svn.sourceforge.net/cse-ip/?rev=213&view=rev Author: roekens Date: 2009-05-14 12:28:00 +0000 (Thu, 14 May 2009) Log Message: ----------- - fixed equals and hashCode methods in domain package Modified Paths: -------------- trunk/cse-ip/sc-cdmm/src/main/java/de/campussource/cse/cdmm/domain/Account.java trunk/cse-ip/sc-cdmm/src/main/java/de/campussource/cse/cdmm/domain/Course.java trunk/cse-ip/sc-cdmm/src/main/java/de/campussource/cse/cdmm/domain/Entity.java trunk/cse-ip/sc-cdmm/src/main/java/de/campussource/cse/cdmm/domain/Group.java trunk/cse-ip/sc-cdmm/src/main/java/de/campussource/cse/cdmm/domain/Role.java Modified: trunk/cse-ip/sc-cdmm/src/main/java/de/campussource/cse/cdmm/domain/Account.java =================================================================== --- trunk/cse-ip/sc-cdmm/src/main/java/de/campussource/cse/cdmm/domain/Account.java 2009-05-14 11:54:08 UTC (rev 212) +++ trunk/cse-ip/sc-cdmm/src/main/java/de/campussource/cse/cdmm/domain/Account.java 2009-05-14 12:28:00 UTC (rev 213) @@ -171,15 +171,6 @@ } } - @Override - public int hashCode() { - if (this.getId() == null) { - return super.hashCode(); - } else { - return this.getId().hashCode(); - } - } - public String toString() { return new ToStringBuilder(this, ToStringStyle.DEFAULT_STYLE).append(this.getId()).toString(); } Modified: trunk/cse-ip/sc-cdmm/src/main/java/de/campussource/cse/cdmm/domain/Course.java =================================================================== --- trunk/cse-ip/sc-cdmm/src/main/java/de/campussource/cse/cdmm/domain/Course.java 2009-05-14 11:54:08 UTC (rev 212) +++ trunk/cse-ip/sc-cdmm/src/main/java/de/campussource/cse/cdmm/domain/Course.java 2009-05-14 12:28:00 UTC (rev 213) @@ -221,5 +221,19 @@ return new ToStringBuilder(this, ToStringStyle.DEFAULT_STYLE).toString(); } - + @Override + public boolean equals(Object other) { + if (this == other) { + return true; + } + if (!(other instanceof Course)) { + return false; + } + if (this.getId() == null) { + return super.equals( other ); + } + else { + return this.getId().equals(((Course)other).getId()); + } + } } Modified: trunk/cse-ip/sc-cdmm/src/main/java/de/campussource/cse/cdmm/domain/Entity.java =================================================================== --- trunk/cse-ip/sc-cdmm/src/main/java/de/campussource/cse/cdmm/domain/Entity.java 2009-05-14 11:54:08 UTC (rev 212) +++ trunk/cse-ip/sc-cdmm/src/main/java/de/campussource/cse/cdmm/domain/Entity.java 2009-05-14 12:28:00 UTC (rev 213) @@ -121,30 +121,31 @@ return new ToStringBuilder(this, ToStringStyle.DEFAULT_STYLE).append(id).toString(); } - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((id == null) ? 0 : id.hashCode()); - return result; - } + @Override + public int hashCode() { + if (this.getId() == null) { + return super.hashCode(); + } + else { + return this.getId().hashCode(); + } + } - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - Entity other = (Entity) obj; - if (id == null) { - if (other.id != null) - return false; - } else if (!id.equals(other.id)) - return false; - return true; - } + @Override + public boolean equals(Object other) { + if (this == other) { + return true; + } + if (!(other instanceof Entity)) { + return false; + } + if (this.getId() == null) { + return super.equals( other ); + } + else { + return this.getId().equals(((Entity)other).getId()); + } + } public boolean isOlder(Date when) { return (date == null) || date.before(when); Modified: trunk/cse-ip/sc-cdmm/src/main/java/de/campussource/cse/cdmm/domain/Group.java =================================================================== --- trunk/cse-ip/sc-cdmm/src/main/java/de/campussource/cse/cdmm/domain/Group.java 2009-05-14 11:54:08 UTC (rev 212) +++ trunk/cse-ip/sc-cdmm/src/main/java/de/campussource/cse/cdmm/domain/Group.java 2009-05-14 12:28:00 UTC (rev 213) @@ -41,31 +41,23 @@ setId(id); } - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (!(obj instanceof Group)) { - return false; - } - if (this.getId() == null) { - return false; - } else { - return this.getId().equals(((Group) obj).getId()); - } - } + @Override + public boolean equals(Object other) { + if (this == other) { + return true; + } + if (!(other instanceof Group)) { + return false; + } + if (this.getId() == null) { + return super.equals( other ); + } + else { + return this.getId().equals(((Group)other).getId()); + } + } @Override - public int hashCode() { - if (this.getId() == null) { - return super.hashCode(); - } else { - return this.getId().hashCode(); - } - } - - @Override public String toString() { return new ToStringBuilder(this, ToStringStyle.DEFAULT_STYLE).append(this.getId()).toString(); } Modified: trunk/cse-ip/sc-cdmm/src/main/java/de/campussource/cse/cdmm/domain/Role.java =================================================================== --- trunk/cse-ip/sc-cdmm/src/main/java/de/campussource/cse/cdmm/domain/Role.java 2009-05-14 11:54:08 UTC (rev 212) +++ trunk/cse-ip/sc-cdmm/src/main/java/de/campussource/cse/cdmm/domain/Role.java 2009-05-14 12:28:00 UTC (rev 213) @@ -136,4 +136,20 @@ visitor.visit(this); } + @Override + public boolean equals(Object other) { + if (this == other) { + return true; + } + if (!(other instanceof Role)) { + return false; + } + if (this.getId() == null) { + return super.equals( other ); + } + else { + return this.getId().equals(((Role)other).getId()); + } + } + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |