3853N/A/*
3853N/A * CDDL HEADER START
3853N/A *
3853N/A * The contents of this file are subject to the terms of the
3853N/A * Common Development and Distribution License, Version 1.0 only
3853N/A * (the "License"). You may not use this file except in compliance
3853N/A * with the License.
3853N/A *
3853N/A * You can obtain a copy of the license at
3853N/A * trunk/opends/resource/legal-notices/OpenDS.LICENSE
3853N/A * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
3853N/A * See the License for the specific language governing permissions
3853N/A * and limitations under the License.
3853N/A *
3853N/A * When distributing Covered Code, include this CDDL HEADER in each
3853N/A * file and include the License file at
3853N/A * trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
3853N/A * add the following below this CDDL HEADER, with the fields enclosed
3853N/A * by brackets "[]" replaced with your own identifying information:
3853N/A * Portions Copyright [yyyy] [name of copyright owner]
3853N/A *
3853N/A * CDDL HEADER END
3853N/A *
3853N/A *
5014N/A * Copyright 2008-2010 Sun Microsystems, Inc.
3853N/A */
3853N/A
3853N/Apackage org.opends.guitools.controlpanel.ui.nodes;
3853N/A
3853N/Aimport javax.swing.Icon;
3853N/Aimport javax.swing.tree.DefaultMutableTreeNode;
3853N/A
3853N/Aimport org.opends.guitools.controlpanel.browser.BasicNodeError;
3853N/Aimport org.opends.server.types.DN;
3853N/Aimport org.opends.server.types.LDAPURL;
3853N/Aimport org.opends.server.types.RDN;
3853N/A
3853N/A/**
3853N/A * The basic node used to render entries in the 'Manage Entries' tree.
3853N/A *
3853N/A */
3853N/Apublic class BasicNode extends DefaultMutableTreeNode {
3853N/A
3853N/A private static final long serialVersionUID = 5441658731908509872L;
3853N/A private String localDn;
3853N/A private String localRdn;
3853N/A private String localRdnWithAttributeName;
3853N/A private LDAPURL remoteUrl;
3853N/A private String remoteRdn;
3853N/A private String remoteRdnWithAttributeName;
3853N/A
3853N/A private boolean isLeaf;
3853N/A private boolean refreshNeededOnExpansion = true;
3853N/A private boolean obsolete;
3853N/A private BasicNodeError error;
3853N/A
3853N/A private String[] referral;
3853N/A private int numSubOrdinates;
3853N/A
5130N/A // This is required for the case where there is an undefined number of
5130N/A // subordinates (for instance in the case of the changelog).
5130N/A private boolean hasSubOrdinates;
5130N/A
3853N/A private String displayName;
3853N/A private Icon icon;
3853N/A private int fontStyle;
3853N/A
3853N/A private boolean sizeLimitReached = false;
3853N/A
3853N/A private String[] objectClassValues;
3853N/A
3853N/A /**
3853N/A * Constructor.
3853N/A * @param dn the DN of the entry.
3853N/A */
3853N/A public BasicNode(String dn) {
3853N/A localDn = dn;
3853N/A localRdn = extractRDN(localDn);
3853N/A localRdnWithAttributeName = extractRDN(localDn, true);
3853N/A isLeaf = true;
3853N/A refreshNeededOnExpansion = true;
3853N/A numSubOrdinates = -1;
5130N/A hasSubOrdinates = false;
3853N/A displayName = "";
3853N/A }
3853N/A
3853N/A
3853N/A /**
3853N/A * Returns the DN of the local entry.
3853N/A * @return the DN of the local entry.
3853N/A */
3853N/A public String getDN() {
3853N/A return localDn;
3853N/A }
3853N/A
3853N/A /**
3853N/A * Returns the RDN value of the local entry.
3853N/A * @return the RDN value of the local entry.
3853N/A */
3853N/A public String getRDN() {
3853N/A return localRdn;
3853N/A }
3853N/A
3853N/A /**
3853N/A * Returns the RDN (with the attribute name) of the local entry.
3853N/A * @return the RDN (with the attribute name) of the local entry.
3853N/A */
3853N/A public String getRDNWithAttributeName() {
3853N/A return localRdnWithAttributeName;
3853N/A }
3853N/A
3853N/A /**
3853N/A * Returns the URL of the remote entry (if the node does not represent a
3853N/A * referral it will be <CODE>null</CODE>).
3853N/A * @return the URL of the remote entry (if the node does not represent a
3853N/A * referral it will be <CODE>null</CODE>).
3853N/A */
3853N/A public LDAPURL getRemoteUrl() {
3853N/A return remoteUrl;
3853N/A }
3853N/A
3853N/A /**
3853N/A * Sets the remote URL of the node.
3853N/A * @param url the remote URL of the node.
3853N/A */
3853N/A public void setRemoteUrl(LDAPURL url) {
3853N/A remoteUrl = url;
5014N/A if (remoteUrl != null)
5014N/A {
5014N/A remoteRdn = extractRDN(remoteUrl.getRawBaseDN());
5014N/A remoteRdnWithAttributeName = extractRDN(remoteUrl.getRawBaseDN(), true);
5014N/A }
5014N/A else
5014N/A {
5014N/A remoteRdn = null;
5014N/A remoteRdnWithAttributeName = null;
5014N/A }
3853N/A }
3853N/A
3853N/A /**
3853N/A * Sets the remote URL of the node.
3853N/A * @param url the remote URL of the node.
3853N/A */
3853N/A public void setRemoteUrl(String url) {
3853N/A try
3853N/A {
3853N/A if (url == null)
3853N/A {
3853N/A remoteUrl = null;
3853N/A }
3853N/A else
3853N/A {
3853N/A remoteUrl = LDAPURL.decode(url, false);
3853N/A }
3853N/A if (remoteUrl == null) {
3853N/A remoteRdn = null;
3853N/A remoteRdnWithAttributeName = null;
3853N/A }
3853N/A else {
3853N/A remoteRdn = extractRDN(remoteUrl.getRawBaseDN());
3853N/A remoteRdnWithAttributeName = extractRDN(remoteUrl.getRawBaseDN(), true);
3853N/A }
3853N/A }
3853N/A catch (Throwable t)
3853N/A {
3853N/A throw new IllegalArgumentException(
3853N/A "The provided url: "+url+" is not valid:"+t, t);
3853N/A }
3853N/A }
3853N/A
3853N/A /**
3853N/A * Returns the RDN value of the remote entry. If the node does not
3853N/A * represent a referral it will return <CODE>null</CODE>.
3853N/A * @return the RDN value of the remote entry.
3853N/A */
3853N/A public String getRemoteRDN() {
3853N/A return remoteRdn;
3853N/A }
3853N/A
3853N/A /**
3853N/A * Returns the RDN value of the remote entry (with the name of the attribute).
3853N/A * If the node does not represent a referral it will return <CODE>null</CODE>.
3853N/A * @return the RDN value of the remote entry (with the name of the attribute).
3853N/A */
3853N/A public String getRemoteRDNWithAttributeName() {
3853N/A return remoteRdnWithAttributeName;
3853N/A }
3853N/A
3853N/A
3853N/A /**
3853N/A * Sets whether the node is a leaf or not.
3853N/A * @param isLeaf whether the node is a leaf or not.
3853N/A */
3853N/A public void setLeaf(boolean isLeaf) {
3853N/A this.isLeaf = isLeaf;
3853N/A }
3853N/A
3853N/A /**
3853N/A * Returns <CODE>true</CODE> if the node is a leaf and <CODE>false</CODE>
3853N/A * otherwise.
3853N/A * @return <CODE>true</CODE> if the node is a leaf and <CODE>false</CODE>
3853N/A * otherwise.
3853N/A */
3853N/A public boolean isLeaf() {
3853N/A return isLeaf;
3853N/A }
3853N/A
3853N/A /**
3853N/A * Returns <CODE>true</CODE> if the node must be refreshed when it is expanded
3853N/A * and <CODE>false</CODE> otherwise.
3853N/A * @return <CODE>true</CODE> if the node must be refreshed when it is expanded
3853N/A * and <CODE>false</CODE> otherwise.
3853N/A */
3853N/A public boolean isRefreshNeededOnExpansion() {
3853N/A return refreshNeededOnExpansion;
3853N/A }
3853N/A
3853N/A /**
3853N/A * Sets whether the node must be refreshed when it is expanded or not.
3853N/A * @param refreshNeededOnExpansion whether the node must be refreshed when it
3853N/A * is expanded or not.
3853N/A */
3853N/A public void setRefreshNeededOnExpansion(boolean refreshNeededOnExpansion) {
3853N/A this.refreshNeededOnExpansion = refreshNeededOnExpansion;
3853N/A }
3853N/A
3853N/A /**
3853N/A * Returns whether the node is obsolete (and must be refreshed) or not.
3853N/A * @return <CODE>true</CODE> if the node is obsolete and <CODE>false</CODE>
3853N/A * otherwise.
3853N/A */
3853N/A public boolean isObsolete() {
3853N/A return obsolete;
3853N/A }
3853N/A
3853N/A /**
3853N/A * Sets whether this is node is obsolete (and must be refreshed) or not.
3853N/A * @param obsolete whether this is node is obsolete (and must be refreshed) or
3853N/A * not.
3853N/A */
3853N/A public void setObsolete(boolean obsolete) {
3853N/A this.obsolete = obsolete;
3853N/A }
3853N/A
3853N/A /**
3853N/A * Returns the error that occurred when updating the node. Returns
3853N/A * <CODE>null</CODE> if no error occurred.
3853N/A * @return the error that occurred when updating the node. Returns
3853N/A * <CODE>null</CODE> if no error occurred.
3853N/A */
3853N/A public BasicNodeError getError() {
3853N/A return error;
3853N/A }
3853N/A
3853N/A /**
3853N/A * Sets the error that occurred when updating the node.
3853N/A * @param error the error.
3853N/A */
3853N/A public void setError(BasicNodeError error) {
3853N/A this.error = error;
3853N/A }
3853N/A
3853N/A
3853N/A /**
3853N/A * Cached LDAP attributes
3853N/A */
3853N/A
3853N/A /**
3853N/A * Returns the number of subordinates of the entry.
3853N/A * @return the number of subordinates of the entry.
3853N/A */
3853N/A public int getNumSubOrdinates() {
3853N/A return numSubOrdinates;
3853N/A }
3853N/A
3853N/A /**
3853N/A * Sets the number of subordinates of the entry.
3853N/A * @param number the number of subordinates of the entry.
3853N/A */
3853N/A public void setNumSubOrdinates(int number) {
3853N/A numSubOrdinates = number;
3853N/A }
3853N/A
3853N/A /**
5130N/A * Returns whether the entry has subordinates or not.
5130N/A * @return {@code true} if the entry has subordinates and {@code false}
5130N/A * otherwise.
5130N/A */
5130N/A public boolean hasSubOrdinates() {
5130N/A return hasSubOrdinates;
5130N/A }
5130N/A
5130N/A /**
5130N/A * Sets the whether the entry has subordinates or not.
5130N/A * @param hasSubOrdinates whether the entry has subordinates or not.
5130N/A */
5130N/A public void setHasSubOrdinates(boolean hasSubOrdinates) {
5130N/A this.hasSubOrdinates = hasSubOrdinates;
5130N/A }
5130N/A
5130N/A /**
3853N/A * Returns the referrals of the entry. Returns <CODE>null</CODE> if this node
3853N/A * is not a referral.
3853N/A * @return the referrals of the entry. Returns <CODE>null</CODE> if this node
3853N/A * is not a referral.
3853N/A */
3853N/A public String[] getReferral() {
3853N/A return referral;
3853N/A }
3853N/A
3853N/A /**
3853N/A * Sets the referrals of the entry.
3853N/A * @param referral the referrals of the entry.
3853N/A */
3853N/A public void setReferral(String[] referral) {
3853N/A this.referral = referral;
3853N/A }
3853N/A
3853N/A
3853N/A /**
3853N/A * Rendering
3853N/A */
3853N/A /**
3853N/A * {@inheritDoc}
3853N/A */
3853N/A public String toString() {
3853N/A return getDisplayName();
3853N/A }
3853N/A
3853N/A /**
3853N/A * Returns the label that will be used to display the entry.
3853N/A * @return the label that will be used to display the entry.
3853N/A */
3853N/A public String getDisplayName() {
3853N/A return displayName;
3853N/A }
3853N/A
3853N/A /**
3853N/A * Sets the label that will be used to display the entry.
3853N/A * @param name the label that will be used to display the entry.
3853N/A */
3853N/A public void setDisplayName(String name) {
3853N/A displayName = name;
3853N/A }
3853N/A
3853N/A /**
3853N/A * Returns the icon associated with this node.
3853N/A * @return the icon associated with this node.
3853N/A */
3853N/A public Icon getIcon() {
3853N/A return icon;
3853N/A }
3853N/A
3853N/A
3853N/A /**
3853N/A * Sets the icon associated with this node.
3853N/A * @param icon the icon associated with this node.
3853N/A */
3853N/A public void setIcon(Icon icon) {
3853N/A this.icon = icon;
3853N/A }
3853N/A
3853N/A /**
3853N/A * Returns the font style to be used to render this node.
3853N/A * @return the font style to be used to render this node.
3853N/A */
3853N/A public int getFontStyle() {
3853N/A return fontStyle;
3853N/A }
3853N/A
3853N/A /**
3853N/A * Sets the font style to be used to render this node.
3853N/A * @param style the font style to be used to render this node.
3853N/A */
3853N/A public void setFontStyle(int style) {
3853N/A fontStyle = style;
3853N/A }
3853N/A
3853N/A
3853N/A /**
3853N/A * Returns the object class values associated with the entry.
3853N/A * @return the object class values associated with the entry.
3853N/A */
3853N/A public String[] getObjectClassValues() {
3853N/A return objectClassValues;
3853N/A }
3853N/A
3853N/A /**
3853N/A * Sets the object class values associated with the entry.
3853N/A * @param objectClassValues the object class values associated with the entry.
3853N/A */
3853N/A public void setObjectClassValues(String[] objectClassValues) {
3853N/A this.objectClassValues = objectClassValues;
3853N/A }
3853N/A
3853N/A /**
3853N/A * Extracts the RDN value from a DN.
3853N/A * @param dn the DN.
3853N/A * @param showAttributeName whether the result must include the attribute name
3853N/A * or not.
3853N/A * @return the RDN value from the DN.
3853N/A */
3853N/A public static String extractRDN(String dn, boolean showAttributeName) {
3853N/A String result;
3853N/A if (dn == null)
3853N/A {
3853N/A result = null;
3853N/A }
3853N/A else
3853N/A {
3853N/A try
3853N/A {
3853N/A DN dnObj = DN.decode(dn);
3853N/A if (dnObj.getNumComponents() >= 1) {
3853N/A RDN rdn = dnObj.getRDN();
3853N/A if (showAttributeName)
3853N/A {
3853N/A result = rdn.toString();
3853N/A }
3853N/A else
3853N/A {
4134N/A result = rdn.getAttributeValue(0).getValue().toString();
3853N/A }
3853N/A }
3853N/A else {
3853N/A result = "";
3853N/A }
3853N/A }
3853N/A catch (Throwable t)
3853N/A {
3853N/A throw new IllegalArgumentException(
3853N/A "The provided argument is not a valid dn: "+t, t);
3853N/A }
3853N/A }
3853N/A return result;
3853N/A }
3853N/A
3853N/A /**
3853N/A * Extracts the RDN value from the DN. The value does not include the name
3853N/A * of the attribute.
3853N/A * @param dn the DN.
3853N/A * @return the RDN value from the DN.
3853N/A */
3853N/A public static String extractRDN(String dn) {
3853N/A return extractRDN(dn, false);
3853N/A }
3853N/A
3853N/A
3853N/A /**
3853N/A * Returns <CODE>true</CODE> if the size limit was reached updating this node
3853N/A * (and searching its children) and <CODE>false</CODE> otherwise.
3853N/A * @return <CODE>true</CODE> if the size limit was reached updating this node
3853N/A * (and searching its children) and <CODE>false</CODE> otherwise.
3853N/A */
3853N/A public boolean isSizeLimitReached()
3853N/A {
3853N/A return sizeLimitReached;
3853N/A }
3853N/A
3853N/A
3853N/A /**
3853N/A * Sets whether the size limit was reached updating this node
3853N/A * (and searching its children).
3853N/A * @param sizeLimitReached whether the size limit was reached updating this
3853N/A * node (and searching its children).
3853N/A */
3853N/A public void setSizeLimitReached(boolean sizeLimitReached)
3853N/A {
3853N/A this.sizeLimitReached = sizeLimitReached;
3853N/A }
3853N/A}