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