You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by jk...@apache.org on 2003/11/02 23:14:03 UTC
cvs commit: jakarta-commons-sandbox/cli/src/java/org/apache/commons/cli2/defaults Defaults.java DefaultsFactory.java
jkeyes 2003/11/02 14:14:03
Added: cli/src/test/org/apache/commons/cli2/defaults/impl
PreferencesImplTest.java PropertiesImplTest.java
PropertiesBackedPreferences.java
PreferencesFactoryImpl.java
cli/src/java/org/apache/commons/cli2/defaults/impl
PreferencesImpl.java PropertiesImpl.java
cli/src/java/org/apache/commons/cli2/defaults Defaults.java
DefaultsFactory.java
Log:
- defaults work WIP (properties and JDK 1.4.2 prefs)
Revision Changes Path
1.1 jakarta-commons-sandbox/cli/src/test/org/apache/commons/cli2/defaults/impl/PreferencesImplTest.java
Index: PreferencesImplTest.java
===================================================================
/*
* $Header: /home/cvs/jakarta-commons-sandbox/cli/src/test/org/apache/commons/cli2/defaults/impl/PreferencesImplTest.java,v 1.1 2003/11/02 22:14:03 jkeyes Exp $
* $Revision: 1.1 $
* $Date: 2003/11/02 22:14:03 $
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Commons", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache GroupImpl.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
*/
package org.apache.commons.cli2.defaults.impl;
import java.util.prefs.Preferences;
import java.util.prefs.PreferencesFactory;
import junit.framework.TestCase;
import org.apache.commons.cli2.defaults.Defaults;
import org.apache.commons.cli2.defaults.DefaultsFactory;
/**
* @author John Keyes
*/
public class PreferencesImplTest extends TestCase {
public void testCreatePreferencesDefaults() {
PreferencesFactory factory = new PreferencesFactoryImpl();
final Preferences prefs = factory.systemRoot();
Defaults defaults =
DefaultsFactory.createDefaults(
"org.apache.commons.cli2.defaults.impl.PreferencesImpl",
prefs);
assertEquals(PreferencesImpl.class, defaults.getClass());
}
public void testNullConfiguration() throws Exception {
try {
Defaults defaults =
DefaultsFactory.createDefaults(
"org.apache.commons.cli2.defaults.impl.PreferencesImpl",
null);
fail("Expected IllegalArgumentException not caught");
}
catch (final IllegalArgumentException exp) {
}
}
}
1.1 jakarta-commons-sandbox/cli/src/test/org/apache/commons/cli2/defaults/impl/PropertiesImplTest.java
Index: PropertiesImplTest.java
===================================================================
/*
* $Header: /home/cvs/jakarta-commons-sandbox/cli/src/test/org/apache/commons/cli2/defaults/impl/PropertiesImplTest.java,v 1.1 2003/11/02 22:14:03 jkeyes Exp $
* $Revision: 1.1 $
* $Date: 2003/11/02 22:14:03 $
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Commons", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache GroupImpl.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
*/
package org.apache.commons.cli2.defaults.impl;
import java.util.Properties;
import junit.framework.TestCase;
import org.apache.commons.cli2.defaults.Defaults;
import org.apache.commons.cli2.defaults.DefaultsFactory;
/**
* @author John Keyes
*/
public class PropertiesImplTest extends TestCase {
public void testCreatePropertiesDefaults() throws Exception {
final Properties props = new Properties();
Defaults defaults =
DefaultsFactory.createDefaults(
"org.apache.commons.cli2.defaults.impl.PropertiesImpl",
props);
assertEquals(PropertiesImpl.class, defaults.getClass());
}
public void testNullConfiguration() throws Exception {
try {
Defaults defaults =
DefaultsFactory.createDefaults(
"org.apache.commons.cli2.defaults.impl.PropertiesImpl",
null);
fail("Expected IllegalArgumentException not caught");
}
catch (final IllegalArgumentException exp) {
}
}
}
1.1 jakarta-commons-sandbox/cli/src/test/org/apache/commons/cli2/defaults/impl/PropertiesBackedPreferences.java
Index: PropertiesBackedPreferences.java
===================================================================
/*
* $Header: /home/cvs/jakarta-commons-sandbox/cli/src/test/org/apache/commons/cli2/defaults/impl/PropertiesBackedPreferences.java,v 1.1 2003/11/02 22:14:03 jkeyes Exp $
* $Revision: 1.1 $
* $Date: 2003/11/02 22:14:03 $
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Commons", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache GroupImpl.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
*/
package org.apache.commons.cli2.defaults.impl;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Properties;
import java.util.prefs.AbstractPreferences;
import java.util.prefs.BackingStoreException;
/**
* @author jkeyes
*
* To change the template for this generated type comment go to
* Window - Preferences - Java - Code Generation - Code and Comments
*/
public class PropertiesBackedPreferences extends AbstractPreferences {
Properties props;
Map childNodes;
PropertiesBackedPreferences(
final AbstractPreferences prefs,
final String name) {
super(prefs, name);
this.props = new Properties();
this.childNodes = new HashMap(13);
}
PropertiesBackedPreferences(final String name) {
this(null, name);
}
/* (non-Javadoc)
* @see java.util.prefs.AbstractPreferences#putSpi(java.lang.String, java.lang.String)
*/
protected void putSpi(String key, String value) {
this.props.put(key, value);
}
/* (non-Javadoc)
* @see java.util.prefs.AbstractPreferences#getSpi(java.lang.String)
*/
protected String getSpi(String key) {
return (String) this.props.get(key);
}
/* (non-Javadoc)
* @see java.util.prefs.AbstractPreferences#removeSpi(java.lang.String)
*/
protected void removeSpi(String key) {
this.childNodes.remove(key);
}
/* (non-Javadoc)
* @see java.util.prefs.AbstractPreferences#removeNodeSpi()
*/
protected void removeNodeSpi() throws BackingStoreException {
this.childNodes.clear();
this.props.clear();
}
/* (non-Javadoc)
* @see java.util.prefs.AbstractPreferences#keysSpi()
*/
protected String[] keysSpi() throws BackingStoreException {
String[] names = new String[this.props.size()];
int count = 0;
for (final Enumeration enum = this.props.elements();
enum.hasMoreElements();) {
names[count++] = (String) enum.nextElement();
}
return names;
}
/* (non-Javadoc)
* @see java.util.prefs.AbstractPreferences#childrenNamesSpi()
*/
protected String[] childrenNamesSpi() throws BackingStoreException {
String[] names = new String[this.childNodes.size()];
int count = 0;
for (final Iterator iter = this.childNodes.keySet().iterator();
iter.hasNext();) {
names[count++] = (String) iter.next();
}
return names;
}
/* (non-Javadoc)
* @see java.util.prefs.AbstractPreferences#childSpi(java.lang.String)
*/
protected AbstractPreferences childSpi(String name) {
if (this.childNodes.containsKey(name)) {
return (AbstractPreferences) this.childNodes.get(name);
}
return new PropertiesBackedPreferences(this, name);
}
/* (non-Javadoc)
* @see java.util.prefs.AbstractPreferences#syncSpi()
*/
protected void syncSpi() throws BackingStoreException {
}
/* (non-Javadoc)
* @see java.util.prefs.AbstractPreferences#flushSpi()
*/
protected void flushSpi() throws BackingStoreException {
}
}
1.1 jakarta-commons-sandbox/cli/src/test/org/apache/commons/cli2/defaults/impl/PreferencesFactoryImpl.java
Index: PreferencesFactoryImpl.java
===================================================================
/*
* $Header: /home/cvs/jakarta-commons-sandbox/cli/src/test/org/apache/commons/cli2/defaults/impl/PreferencesFactoryImpl.java,v 1.1 2003/11/02 22:14:03 jkeyes Exp $
* $Revision: 1.1 $
* $Date: 2003/11/02 22:14:03 $
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Commons", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache GroupImpl.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
*/
package org.apache.commons.cli2.defaults.impl;
import java.util.prefs.Preferences;
import java.util.prefs.PreferencesFactory;
/**
* @author John Keyes
*/
public class PreferencesFactoryImpl implements PreferencesFactory {
/* (non-Javadoc)
* @see java.util.prefs.PreferencesFactory#systemRoot()
*/
public Preferences systemRoot() {
return new PropertiesBackedPreferences("");
}
/* (non-Javadoc)
* @see java.util.prefs.PreferencesFactory#userRoot()
*/
public Preferences userRoot() {
return new PropertiesBackedPreferences("user");
}
}
1.1 jakarta-commons-sandbox/cli/src/java/org/apache/commons/cli2/defaults/impl/PreferencesImpl.java
Index: PreferencesImpl.java
===================================================================
/*
* $Header: /home/cvs/jakarta-commons-sandbox/cli/src/java/org/apache/commons/cli2/defaults/impl/PreferencesImpl.java,v 1.1 2003/11/02 22:14:03 jkeyes Exp $
* $Revision: 1.1 $
* $Date: 2003/11/02 22:14:03 $
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Commons", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache GroupImpl.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
*/
package org.apache.commons.cli2.defaults.impl;
import java.util.prefs.Preferences;
import org.apache.commons.cli2.defaults.Defaults;
/**
* @author John Keyes
*/
public class PreferencesImpl implements Defaults {
private Preferences prefs;
public void init(final Object configuration) {
if (!(configuration instanceof Preferences)) {
throw new IllegalArgumentException("not a prefs");
}
this.prefs = (Preferences) configuration;
}
public String get(String name) {
return prefs.get(name, null);
}
}
1.1 jakarta-commons-sandbox/cli/src/java/org/apache/commons/cli2/defaults/impl/PropertiesImpl.java
Index: PropertiesImpl.java
===================================================================
/*
* $Header: /home/cvs/jakarta-commons-sandbox/cli/src/java/org/apache/commons/cli2/defaults/impl/PropertiesImpl.java,v 1.1 2003/11/02 22:14:03 jkeyes Exp $
* $Revision: 1.1 $
* $Date: 2003/11/02 22:14:03 $
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Commons", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache GroupImpl.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
*/
package org.apache.commons.cli2.defaults.impl;
import java.util.Properties;
import org.apache.commons.cli2.defaults.Defaults;
/**
* @author John Keyes
*/
public class PropertiesImpl implements Defaults {
private Properties properties;
public void init(final Object configuration) {
if (!(configuration instanceof Properties)) {
throw new IllegalArgumentException("not a props");
}
this.properties = (Properties) configuration;
}
public String get(String name) {
return properties.getProperty(name);
}
}
1.1 jakarta-commons-sandbox/cli/src/java/org/apache/commons/cli2/defaults/Defaults.java
Index: Defaults.java
===================================================================
/*
* $Header: /home/cvs/jakarta-commons-sandbox/cli/src/java/org/apache/commons/cli2/defaults/Defaults.java,v 1.1 2003/11/02 22:14:03 jkeyes Exp $
* $Revision: 1.1 $
* $Date: 2003/11/02 22:14:03 $
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Commons", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache GroupImpl.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
*/
package org.apache.commons.cli2.defaults;
/**
* @author John Keyes
*/
public interface Defaults {
/**
* Initialize the Defaults with the specified configuration
* object.
*
* @param configuration
* the object used for configuration
*/
void init(Object configuration);
/**
* Return the value for the specified option.
*
* @param name
* the name of the Option
*
* @return String
* the default value for the specified option
*/
String get(String name);
}
1.1 jakarta-commons-sandbox/cli/src/java/org/apache/commons/cli2/defaults/DefaultsFactory.java
Index: DefaultsFactory.java
===================================================================
/*
* $Header: /home/cvs/jakarta-commons-sandbox/cli/src/java/org/apache/commons/cli2/defaults/DefaultsFactory.java,v 1.1 2003/11/02 22:14:03 jkeyes Exp $
* $Revision: 1.1 $
* $Date: 2003/11/02 22:14:03 $
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Commons", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache GroupImpl.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
*/
package org.apache.commons.cli2.defaults;
/**
* @author John Keyes
*/
public class DefaultsFactory {
public static Defaults createDefaults(
final String implName,
final Object configuration) {
if (implName == null) {
throw new IllegalArgumentException("cannot specify null impl");
}
Class impl = null;
try {
impl = Thread
.currentThread()
.getContextClassLoader()
.loadClass(implName);
}
catch (final ClassNotFoundException ctxExp) {
try {
impl = DefaultsFactory.class
.getClassLoader()
.loadClass(implName);
}
catch (final ClassNotFoundException classExp) {
throw new IllegalArgumentException("could not find impl");
}
}
try {
final Defaults defaults = (Defaults) impl.newInstance();
defaults.init(configuration);
return defaults;
}
catch (final InstantiationException exp) {
throw new IllegalArgumentException("inst");
}
catch (final IllegalAccessException exp) {
throw new IllegalArgumentException("ill");
}
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org