001/* 002 * The contents of this file are subject to the terms of the Common Development and 003 * Distribution License (the License). You may not use this file except in compliance with the 004 * License. 005 * 006 * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the 007 * specific language governing permission and limitations under the License. 008 * 009 * When distributing Covered Software, include this CDDL Header Notice in each file and include 010 * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL 011 * Header, with the fields enclosed by brackets [] replaced by your own identifying 012 * information: "Portions Copyright [year] [name of copyright owner]". 013 * 014 * Copyright 2008 Sun Microsystems, Inc. 015 */ 016 017package org.opends.guitools.uninstaller; 018 019import java.io.IOException; 020import java.util.Iterator; 021 022import org.opends.admin.ads.ADSContext; 023import org.opends.quicksetup.Configuration; 024import org.opends.quicksetup.Installation; 025import org.opends.quicksetup.util.Utils; 026 027/** 028 * This is a convenience class used to represent the current configuraton and 029 * status of the server to know which kind of questions we must ask to the user 030 * (the server is running, it is configured for replication, it contains an 031 * ADS...). 032 * 033 * The difference with Installation class is that it provides read only 034 * information that is computed in the constructor of the class and not 035 * on demand. This way we can construct the object outside the event thread 036 * and then read it inside the event thread without blocking the display. 037 */ 038public class UninstallData 039{ 040 private boolean isServerRunning; 041 private boolean isADS; 042 private boolean isReplicationServer; 043 private int replicationServerPort; 044 045 /** 046 * The constructor for UninstallData. 047 * @param installation the object describing the installation. 048 * @throws IOException if there was an error retrieving the current 049 * installation configuration. 050 */ 051 public UninstallData(Installation installation) throws IOException 052 { 053 isServerRunning = installation.getStatus().isServerRunning(); 054 Configuration conf = new Configuration(installation, 055 installation.getCurrentConfigurationFile()); 056 Iterator<String> it = conf.getBaseDNs().iterator(); 057 while (it.hasNext() && !isADS) 058 { 059 isADS = Utils.areDnsEqual(it.next(), 060 ADSContext.getAdministrationSuffixDN()); 061 } 062 isReplicationServer = conf.isReplicationServer(); 063 replicationServerPort = conf.getReplicationPort(); 064 } 065 066 /** 067 * Returns whether this server is configured as an ADS or not. 068 * @return <CODE>true</CODE> if the server is configured as an ADS and 069 * <CODE>false</CODE> otherwise. 070 */ 071 public boolean isADS() { 072 return isADS; 073 } 074 075 /** 076 * Returns whether this server is configured as a replication server or not. 077 * @return <CODE>true</CODE> if the server is configured as a replication 078 * server and <CODE>false</CODE> otherwise. 079 */ 080 public boolean isReplicationServer() { 081 return isReplicationServer; 082 } 083 084 /** 085 * Returns whether this server is running or not. 086 * @return <CODE>true</CODE> if the server is running and <CODE>false</CODE> 087 * otherwise. 088 */ 089 public boolean isServerRunning() { 090 return isServerRunning; 091 } 092 093 /** 094 * Returns the port of the replication server. -1 if it is not defined. 095 * @return the port of the replication server. -1 if it is not defined. 096 */ 097 public int getReplicationServerPort() { 098 return replicationServerPort; 099 } 100}