/*
*
* SchemaCrawler
* http://sourceforge.net/projects/schemacrawler
* Copyright (c) 2000-2010, Sualeh Fatehi.
*
* This library is free software; you can redistribute it and/or modify it under the terms
* of the GNU Lesser General Public License as published by the Free Software Foundation;
* either version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with this
* library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307, USA.
*
*/
package schemacrawler.build;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import schemacrawler.schema.JdbcDriverProperty;
import sf.util.Utility;
/**
* Represents a JDBC driver property, and it's value. Created from
* metadata returned by a JDBC call, and other sources of information.
*
* @author Sualeh Fatehi sualeh@hotmail.com
*/
final class MutableJdbcDriverProperty
extends PropertyMetadata
implements JdbcDriverProperty
{
public final class JdbcDriverPropertyBuilder
extends PropertyBuilder
{
private static final long serialVersionUID = 8030156654422512161L;
private String description;
private boolean required;
private final List<String> choices;
public JdbcDriverPropertyBuilder(final String name, final Object value)
{
super(name, (Serializable) value);
choices = new ArrayList<String>();
}
public void addChoice(final String choice)
{
if (!Utility.isBlank(choice))
{
choices.add(choice);
}
}
public JdbcDriverProperty build()
{
return new MutableJdbcDriverProperty(this);
}
public String[] getChoices()
{
if (choices != null)
{
return choices.toArray(new String[choices.size()]);
}
else
{
return new String[0];
}
}
public String getDescription()
{
if (description != null)
{
return description;
}
else
{
return "";
}
}
@Override
public String getValue()
{
return (String) super.getValue();
}
public boolean isRequired()
{
return required;
}
public void setDescription(final String description)
{
this.description = description;
}
public void setRequired(final boolean required)
{
this.required = required;
}
}
private static final long serialVersionUID = 8030156654422512161L;
private final String description;
private final boolean required;
private final String[] choices;
MutableJdbcDriverProperty(final JdbcDriverPropertyBuilder builder)
{
super(builder);
description = builder.description;
required = builder.required;
choices = builder.getChoices();
}
public int compareTo(final JdbcDriverProperty otherProperty)
{
if (otherProperty == null)
{
return -1;
}
else
{
return getName().toLowerCase().compareTo(otherProperty.getName()
.toLowerCase());
}
}
/**
* {@inheritDoc}
*
* @see schemacrawler.schema.JdbcDriverProperty#getChoices()
*/
public String[] getChoices()
{
if (choices != null)
{
return choices;
}
else
{
return new String[0];
}
}
/**
* {@inheritDoc}
*
* @see schemacrawler.schema.JdbcDriverProperty#getDescription()
*/
public String getDescription()
{
if (description != null)
{
return description;
}
else
{
return "";
}
}
/**
* {@inheritDoc}
*/
@Override
public String getValue()
{
return (String) super.getValue();
}
/**
* {@inheritDoc}
*
* @see schemacrawler.schema.JdbcDriverProperty#isRequired()
*/
public boolean isRequired()
{
return required;
}
}