//
// This file is part of the OpenNMS(R) Application.
//
// OpenNMS(R) is Copyright (C) 2006 The OpenNMS Group, Inc.  All rights reserved.
// OpenNMS(R) is a derivative work, containing both original code, included code and modified
// code that was published under the GNU General Public License. Copyrights for modified 
// and included code are below.
//
// OpenNMS(R) is a registered trademark of The OpenNMS Group, Inc.
//
// Original code base Copyright (C) 1999-2001 Oculan Corp.  All rights reserved.
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//
// For more information contact:
// OpenNMS Licensing       <license@opennms.org>
//     http://www.opennms.org/
//     http://www.opennms.com/
//
package org.opennms.netmgt.model;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

import org.springframework.core.style.ToStringCreator;


@Entity
@Table(name="categories")
public class OnmsCategory implements Serializable {

    private static final long serialVersionUID = 4694348093332239377L;

    /** identifier field */
    private Integer m_id;
    
    /** persistent field */
    private String m_name;
    
    /** persistent field */
    private String m_description;

    public OnmsCategory(String name, String descr) {
        m_name = name;
        m_description = descr;
    }

    /** default constructor */
    public OnmsCategory() {
    }
    
    public OnmsCategory(String name) {
        this();
        setName(name);
    }

    @Id
    @Column(name="categoryid")
    @SequenceGenerator(name="categorySequence", sequenceName="catNxtId")
    @GeneratedValue(generator="categorySequence")
    public Integer getId() {
        return m_id;
    }

    public void setId(Integer id) {
        m_id = id;
    }

    @Column(name="categoryName", unique=true, nullable=false)
    public String getName() {
        return m_name;
    }
    public void setName(String name) {
        m_name = name;
    }

    @Column(name="categoryDescription")
	public String getDescription() {
		return m_description;
	}
	public void setDescription(String description) {
		m_description = description;
	}
	
	//Still trying to figure this out....
//	/**
//	 * @hibernate.set name="cn" lazy="true" cascade="save-update" table="category_node"
//	 * @hibernate.key column="categoryid"
//	 * @hibernate.many-to-many class="org.opennms.model.OnmsNode" column="nodeid"
//	 * @return a <code>Set</code> of OnmsNodes matching the category
//	 */
//	public Set getNodes(OnmsCustomCategory category) {
//		return m_nodes;
//	}

    public String toString() {
        return new ToStringCreator(this)
            .append("id", getId())
            .append("name", getName())
            .append("description", getDescription())
            .toString();
    }

    public boolean equals(Object obj) {
        if (obj instanceof OnmsCategory) {
            OnmsCategory t = (OnmsCategory)obj;
            return m_name.equals(t.m_name);
        }
        return false;
    }

    public int hashCode() {
        return m_name.hashCode();
    }

}

@@ -1429,24 +1429,46 @@
 erializable;
+%0Aimport java.util.Set;
 %0A%0Aimport jav
@@ -1593,16 +1593,126 @@
 nce.Id;%0A
+import javax.persistence.JoinColumn;%0Aimport javax.persistence.JoinTable;%0Aimport javax.persistence.ManyToMany;%0A
 import j
@@ -1920,16 +1920,42 @@
 alizable
+, Comparable%3COnmsCategory%3E
  %7B%0A%0A    
@@ -2204,16 +2204,58 @@
 ption;%0A%0A
+    private Set%3COnmsNode%3E m_memberNodes;%0A%0A
     publ
@@ -3581,16 +3581,401 @@
 es;%0A//%09%7D
+%0A        %0A    @ManyToMany%0A    @JoinTable(name = %22category_node%22,%0A               joinColumns = %7B @JoinColumn(name = %22categoryId%22) %7D,%0A               inverseJoinColumns = %7B @JoinColumn(name = %22nodeId%22) %7D)%0A    public Set%3COnmsNode%3E getMemberNodes() %7B%0A        return m_memberNodes;%0A    %7D%0A%0A    public void setMemberNodes(Set%3COnmsNode%3E memberNodes) %7B%0A        m_memberNodes = memberNodes;%0A    %7D
 %0A%0A    pu
@@ -4437,24 +4437,24 @@
 ashCode() %7B%0A
-
         retu
@@ -4482,10 +4482,113 @@
 %0A    %7D%0A%0A
+    public int compareTo(OnmsCategory o) %7B%0A        return m_name.compareToIgnoreCase(o.m_name);%0A    %7D%0A%0A
 %7D%0A

Implement Comparable. Add getter/setter for member nodes.