001: /**
002: * $Id: ConfigurationBean.java,v 1.1 2005/06/25 05:34:51 hc109819 Exp $
003: * Copyright 2005 Sun Microsystems, Inc. All
004: * rights reserved. Use of this product is subject
005: * to license terms. Federal Acquisitions:
006: * Commercial Software -- Government Users
007: * Subject to Standard License Terms and
008: * Conditions.
009: *
010: * Sun, Sun Microsystems, the Sun logo, and Sun ONE
011: * are trademarks or registered trademarks of Sun Microsystems,
012: * Inc. in the United States and other countries.
013: */package com.sun.portal.admin.console.ssoa;
014:
015: public class ConfigurationBean implements Comparable {
016:
017: public static final String ID_SEPARATOR = "|";
018: private String name = "";
019: private String dn = "";
020: // Basis is not needed to select the configuration from the datastore,
021: // but is used quite often when viewing the configuration in the GUI
022: private String basis = "";
023: // Label is used when viewing the configuration in the GUI
024: private String label = "";
025:
026: public ConfigurationBean(String dn, String name, String basis) {
027: this .dn = dn;
028: this .name = name;
029: this .basis = basis;
030: this .label = dn;
031: }
032:
033: public ConfigurationBean(String dn, String name) {
034: this .dn = dn;
035: this .name = name;
036: this .label = dn;
037: }
038:
039: public ConfigurationBean(String id) {
040: setId(id);
041: }
042:
043: public String getDn() {
044: return dn;
045: }
046:
047: public void setDn(String dn) {
048: this .dn = dn;
049: }
050:
051: public String getName() {
052: return name;
053: }
054:
055: public void setName(String name) {
056: this .name = name;
057: }
058:
059: public String getLabel() {
060: return label;
061: }
062:
063: public void setLabel(String label) {
064: this .label = label;
065: }
066:
067: public String getBasis() {
068: return basis;
069: }
070:
071: public void setBasis(String basis) {
072: this .basis = basis;
073: }
074:
075: public String getId() {
076: return dn + ID_SEPARATOR + name;
077: }
078:
079: public void setId(String id) {
080: int mark = id.indexOf(ID_SEPARATOR);
081: if (mark > -1) {
082: this .dn = id.substring(0, mark);
083: this .name = id.substring(mark);
084: } else {
085: this .name = id;
086: this .dn = ListConfigurationsBean.GLOBAL_LOCATION_DN;
087: }
088: this .label = this .dn;
089: }
090:
091: // Compare based on configuration name, then to dn, then to basis
092: // The only way a duplicate name will happen is for multiple dns, or
093: // multiple basis (very unlikely, but may as well cover it)
094: public int compareTo(Object o) {
095: ConfigurationBean cb = (ConfigurationBean) o;
096: int nameCompare = this .name.compareToIgnoreCase(cb.getName());
097: if (nameCompare == 0) {
098: // Check if dn is non-null
099: if (dn != null) {
100: // Whenever a label doesn't match a dn - make sure it
101: // ends up at top.
102: boolean isMatchingLabel = dn.equals(label);
103: boolean otherMatchingLabel = cb.getDn().equals(
104: cb.getLabel());
105: if (isMatchingLabel && !otherMatchingLabel) {
106: return 1;
107: }
108: if (!isMatchingLabel && otherMatchingLabel) {
109: return -1;
110: }
111: if (!isMatchingLabel && !otherMatchingLabel) {
112: return this .label
113: .compareToIgnoreCase(cb.getLabel());
114: }
115: return this .dn.compareToIgnoreCase(cb.getDn());
116: }
117: // Make sure basis is non-null
118: if (basis != null) {
119: return this.basis.compareToIgnoreCase(cb.getBasis());
120: }
121: }
122: return nameCompare;
123: }
124: }
|