JavaPropertiesPanel.java revision 6638c2755466ca601450700d5a39f390f23d4781
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at legal-notices/CDDLv1_0.txt.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information:
* Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*
*
* Copyright 2008-2010 Sun Microsystems, Inc.
* Portions Copyright 2011-2015 ForgeRock AS
*/
/**
* The panel where the user can specify the java arguments and java home to be
* used in the command-lines.
*
*/
public class JavaPropertiesPanel extends StatusGenericPanel
{
private static final long serialVersionUID = -7886215660289880597L;
private JTextField javaHome;
private JRadioButton useOpenDSJavaHome;
private JRadioButton useSpecifiedJavaHome;
private JRadioButton useOpenDSJavaArgs;
private JRadioButton useSpecifiedJavaArgs;
private JTable argumentsTable;
private JScrollPane argumentsScroll;
private AttributeCellEditor editor;
private JEditorPane lInitContents;
new HashSet<JavaArgumentsDescriptor>();
new HashSet<JavaArgumentsDescriptor>();
{
{
"start-ds", "import-ldif.offline", "backup.online", "base64",
"create-rc-script", "dsconfig", "dsreplication",
"export-ldif.online", "import-ldif.online", "ldapcompare",
"ldapdelete", "ldapmodify", "ldappasswordmodify", "ldapsearch",
"list-backends", "manage-account", "manage-tasks", "restore.online",
"stop-ds", "status", "control-panel", "uninstall", "setup",
"backup.offline", "encode-password", "export-ldif.offline",
"ldif-diff", "ldifmodify", "ldifsearch", "make-ldif",
"rebuild-index", "restore.offline", "upgrade",
"verify-index", "dbtest"
};
{
}
}
{
String[] relevantNames =
{
"start-ds", "import-ldif.offline", "backup.offline",
"export-ldif.offline",
"ldif-diff", "make-ldif", "rebuild-index", "restore.offline",
"verify-index", "dbtest"
};
{
}
}
private String readJavaHome;
private boolean readUseOpenDSJavaHome;
private boolean readUseOpenDSJavaArgs;
private boolean initialized;
private boolean previousLocal = true;
private LocalizableMessage READING_JAVA_SETTINGS =
JComponent[] comps;
/**
* Default constructor.
*
*/
public JavaPropertiesPanel()
{
super();
createLayout();
}
/** {@inheritDoc} */
public LocalizableMessage getTitle()
{
return INFO_CTRL_PANEL_JAVA_PROPERTIES_TITLE.get();
}
/** {@inheritDoc} */
public Component getPreferredFocusComponent()
{
return javaHome;
}
/** {@inheritDoc} */
public boolean requiresScroll()
{
return false;
}
/** {@inheritDoc} */
{
{
}
}
/**
* Creates the layout of the panel (but the contents are not populated here).
*/
private void createLayout()
{
useOpenDSJavaHome.setOpaque(false);
useSpecifiedJavaHome.setOpaque(false);
p.setOpaque(false);
useSpecifiedJavaArgs.setOpaque(false);
useOpenDSJavaArgs.setOpaque(false);
group = new ButtonGroup();
renderer);
editor = new AttributeCellEditor();
{
}
lInitContents.setVisible(false);
showAll =
{
{
}
});
// Just to create space.
new HashSet<JavaArgumentsDescriptor>();
comps = new JComponent[] {
};
}
/** {@inheritDoc} */
{
if (isLocal != previousLocal)
{
{
/** {@inheritDoc} */
public void run()
{
if (!isLocal)
{
setEnabledOK(false);
}
else
{
setEnabledOK(true);
}
}
});
}
}
/** {@inheritDoc} */
public void toBeDisplayed(boolean visible)
{
boolean isLocal = true;
{
}
{
initialized = true;
initContents();
}
}
/**
* Returns the names of all the command-line that can be displayed by this
* panel.
* @return the names of all the command-line that can be displayed by this
* panel.
*/
{
return allScriptNames;
}
/**
* Returns the names of the most important command-line to be displayed by
* this panel.
* @return the names of the most important command-line to be displayed by
* this panel.
*/
{
return relevantScriptNames;
}
/**
* Returns <CODE>true</CODE> if the user updated the contents and
* <CODE>false</CODE> otherwise.
* @return <CODE>true</CODE> if the user updated the contents and
* <CODE>false</CODE> otherwise.
*/
private boolean updatedByUser()
{
}
/**
* Returns the java arguments specified by the user.
* @return the java arguments specified by the user.
*/
{
new HashSet<JavaArgumentsDescriptor>();
{
}
{
{
{
break;
}
}
if (foundJavaArgument != null)
{
}
}
return args;
}
/**
* Filters the provided list of java arguments depending on the showing
* options (basically whether the 'Show All Command-lines' is selected or
* not).
* @param args the list of java arguments.
* @return a list of filtered java arguments (the ones that must be displayed
* in the table).
*/
{
if (showAll.isSelected())
{
return args;
}
else
{
new HashSet<JavaArgumentsDescriptor>();
{
{
{
break;
}
}
}
return filteredArgs;
}
}
/**
* Inits the contents of the table in the background.
*
*/
private void initContents()
{
{
/** {@inheritDoc} */
{
try
{
}
catch (Throwable t)
{
}
finally
{
}
if (readJavaHome == null)
{
{
if (readJavaHome != null)
{
break;
}
}
}
{
if (v != null)
{
}
else
{
}
}
return null;
}
/** {@inheritDoc} */
{
if (t == null)
{
}
else
{
if (t instanceof OpenDsException)
{
}
else
{
}
errorPane.setVisible(true);
}
}
};
}
/**
* Disables all the components. This is used when we are reading the
* java settings in the background.
*
*/
private void disableComponents()
{
setEnabledOK(false);
lInitContents.setVisible(true);
argumentsScroll.setVisible(false);
{
comp.setEnabled(false);
}
}
/**
* Enables all the components. This is used when we are reading the
* java settings in the background.
*
*/
private void enableComponents()
{
{
comp.setEnabled(true);
}
lInitContents.setVisible(false);
argumentsScroll.setVisible(true);
setEnabledOK(true);
}
/** {@inheritDoc} */
public void cancelClicked()
{
super.cancelClicked();
}
/** {@inheritDoc} */
public void okClicked()
{
if (f.length() > 0)
{
{
}
else if (!file.isDirectory())
{
}
else
{
{
}
}
}
{
{
{
}
}
{
private boolean isConfirmation = false;
{
if (defaultJVM == null)
{
}
if (useSpecifiedJavaHome.isSelected())
{
}
{
}
else
{
}
{
{
{
}
else
{
}
}
else
{
{
{
}
}
}
{
if (useSpecifiedJavaArgs.isSelected())
{
}
else
{
}
}
}
if (!errorMessages.isEmpty())
{
return errorMessages;
}
else
{
return confirmationMessages;
}
}
/** {@inheritDoc} */
Throwable t)
{
if (t == null)
{
boolean confirm = false;
{
}
{
}
else
{
confirm = true;
}
if (confirm)
{
launchTask();
}
}
else
{
if (t instanceof OpenDsException)
{
}
else
{
}
errorPane.setVisible(true);
}
}
};
return;
}
else
{
if (useSpecifiedJavaHome.isSelected())
{
}
else
{
{
}
}
}
}
/**
* Returns the java binary (the executable) for a given java home.
* @param javaHome the java home.
* @return the java binary (the executable) for the provided java home.
*/
{
if (isWindows())
{
}
else
{
}
return javaFile;
}
private void launchTask()
{
Utilities.getParentDialog(this),
{
}
{
dlg);
dlg.setVisible(true);
}
else
{
}
}
/**
* Returns the file containing the java properties.
* @return the file containing the java properties.
*/
private String getPropertiesFile()
{
}
private void updateContentsOfPanelWithReadValues()
{
if (readJavaHome != null)
{
}
else
{
}
}
/**
* Class containing the command-name and the associated java
* arguments.
*
*/
private class JavaArgumentsDescriptor
{
private String commandName;
private String javaArguments;
private int hashCode;
/**
* Constructor of the arguments descriptor.
* @param commandName the command-line name.
* @param javaArguments the java arguments.
*/
{
this.commandName = commandName;
this.javaArguments = javaArguments;
}
/**
* Returns the command-line name.
* @return the command-line name.
*/
public String getCommandName()
{
return commandName;
}
/**
* Returns the java arguments associated with the command-line.
* @return the java arguments associated with the command-line.
*/
public String getJavaArguments()
{
return javaArguments;
}
/** {@inheritDoc} */
public int hashCode()
{
return hashCode;
}
/** {@inheritDoc} */
{
return toString;
}
/** {@inheritDoc} */
{
if (o == this)
{
return true;
}
if (!(o instanceof JavaArgumentsDescriptor))
{
return false;
}
}
}
/**
* The table model used to display the java arguments.
*/
protected class JavaArgumentsTableModel extends SortableTableModel
implements Comparator<JavaArgumentsDescriptor>
{
private static final long serialVersionUID = 8288418995255677560L;
new HashSet<JavaArgumentsDescriptor>();
new ArrayList<JavaArgumentsDescriptor>();
private int sortColumn;
private boolean sortAscending = true;
/**
* Sets the data for this table model.
* @param newData the data for this table model.
*/
{
{
}
}
/**
* Compares two java argument descriptors.
* @param desc1 the first java argument descriptor.
* @param desc2 the second java argument descriptor.
* @return 1 if in terms of comparison the first element goes higher than
* the second one. Returns 0 if both elements are equal in terms of
* comparison. Returns -1 if the second element goes higher than the first
* one.
*/
{
int result;
int[] possibleResults = {
if (result == 0)
{
for (int i : possibleResults)
{
if (i != 0)
{
result = i;
break;
}
}
}
if (!sortAscending)
{
}
return result;
}
/**
* Updates the table model contents and sorts its contents depending on the
* sort options set by the user.
*/
public void forceResort()
{
}
/** {@inheritDoc} */
public int getColumnCount()
{
return COLUMN_NAMES.length;
}
/** {@inheritDoc} */
public int getRowCount()
{
}
/** {@inheritDoc} */
{
}
/** {@inheritDoc} */
return COLUMN_NAMES[col];
}
/**
* Returns the java argument descriptor in the provided row.
* @param row the row number.
* @return the java argument descriptor in the provided row.
*/
{
}
/**
* Returns whether the sort is ascending or descending.
* @return <CODE>true</CODE> if the sort is ascending and <CODE>false</CODE>
* otherwise.
*/
public boolean isSortAscending()
{
return sortAscending;
}
/**
* Sets whether to sort ascending of descending.
* @param sortAscending whether to sort ascending or descending.
*/
public void setSortAscending(boolean sortAscending)
{
this.sortAscending = sortAscending;
}
/**
* Returns the column index used to sort.
* @return the column index used to sort.
*/
public int getSortColumn()
{
return sortColumn;
}
/**
* Sets the column index used to sort.
* @param sortColumn column index used to sort..
*/
public void setSortColumn(int sortColumn)
{
this.sortColumn = sortColumn;
}
/** {@inheritDoc} */
return col != 0;
}
/** {@inheritDoc} */
{
}
private void updateDataArray()
{
new TreeSet<JavaArgumentsDescriptor>(this);
{
}
}
/**
* Returns an array of String with the String representation of the cells
* in the table.
* @param desc the java argument descriptor for which we want to get the
* cells.
* @return an array of String with the String representation of the cells
* in the table.
*/
{
{
}
{
}
{
}
}
}
/**
* The task in charge of updating the java properties.
*
*/
protected class JavaPropertiesTask extends Task
{
private String defaultJavaHome;
private boolean overwriteOpenDSJavaHome;
private boolean overwriteOpenDSJavaArgs;
new HashSet<JavaArgumentsDescriptor>();
/**
* The constructor of the task.
* @param info the control panel info.
* @param dlg the progress dialog that shows the progress of the task.
*/
{
}
/** {@inheritDoc} */
{
return Type.JAVA_SETTINGS_UPDATE;
}
/** {@inheritDoc} */
{
return backendSet;
}
/** {@inheritDoc} */
public LocalizableMessage getTaskDescription()
{
}
/** {@inheritDoc} */
{
if (!isServerRunning()
{
// All the operations are incompatible if they apply to this
// backend for safety. This is a short operation so the limitation
// has not a lot of impact.
{
return false;
}
}
return true;
}
/** {@inheritDoc} */
protected String getCommandLinePath()
{
return null;
}
/** {@inheritDoc} */
{
}
/** {@inheritDoc} */
public void runTask()
{
try
{
if (returnCode == 0)
{
}
else
{
}
}
catch (Throwable t)
{
lastException = t;
}
}
private int updateJavaSettings() throws IOException
{
try
{
{
{
}
else
{
break;
}
}
}
catch (IOException ioe)
{
// Not critical.
}
finally
{
}
try
{
{
}
{
}
{
{
}
}
}
finally
{
}
{
/** {@inheritDoc} */
public void run()
{
toString(),
}
});
// Launch the script
{
"--quiet"
};
}
}
}