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/10/20 23:40:44 UTC
cvs commit: jakarta-commons-sandbox/cli/src/java/org/apache/commons/cli2/validation UrlValidator.java FileValidator.java DateValidator.java NumberValidator.java InvalidArgumentException.java ClassValidator.java
jkeyes 2003/10/20 14:40:44
Modified: cli/src/java/org/apache/commons/cli2/validation
UrlValidator.java FileValidator.java
DateValidator.java NumberValidator.java
InvalidArgumentException.java ClassValidator.java
Log:
- added Apache license
- fixed author tag
Revision Changes Path
1.2 +109 -58 jakarta-commons-sandbox/cli/src/java/org/apache/commons/cli2/validation/UrlValidator.java
Index: UrlValidator.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/cli/src/java/org/apache/commons/cli2/validation/UrlValidator.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- UrlValidator.java 18 Oct 2003 22:00:17 -0000 1.1
+++ UrlValidator.java 20 Oct 2003 21:40:44 -0000 1.2
@@ -1,58 +1,109 @@
-/*
- * Created on 25-Aug-2003
- *
- * To change the template for this generated file go to
- * Window - Preferences - Java - Code Generation - Code and Comments
- */
-package org.apache.commons.cli2.validation;
-
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.util.List;
-import java.util.ListIterator;
-
-/**
- * @author Rob
- *
- * To change the template for this generated type comment go to
- * Window - Preferences - Java - Code Generation - Code and Comments
- */
-public class UrlValidator implements Validator {
-
- private String protocol = null;
-
- /* (non-Javadoc)
- * @see org.apache.commons.cli2.validation.Validator#validate(java.util.List)
- */
- public void validate(final List values) throws InvalidArgumentException {
- for (final ListIterator i = values.listIterator(); i.hasNext();) {
- final String name = (String) i.next();
- try {
- final URL url = new URL(name);
-
- if (protocol != null && !protocol.equals(url.getProtocol())) {
- throw new InvalidArgumentException(name);
- }
-
- i.set(url);
- } catch (final MalformedURLException mue) {
- throw new InvalidArgumentException(
- "Cannot understand url: " + name);
- }
- }
- }
-
- /**
- * @return
- */
- public String getProtocol() {
- return protocol;
- }
-
- /**
- * @param protocol
- */
- public void setProtocol(String protocol) {
- this.protocol = protocol;
- }
-}
+/*
+ * $Header$
+ * $Revision$
+ * $Date$
+ *
+ * ====================================================================
+ *
+ * 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.validation;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.List;
+import java.util.ListIterator;
+
+/**
+ * @author Rob Oxspring
+ */
+public class UrlValidator implements Validator {
+
+ private String protocol = null;
+
+ /* (non-Javadoc)
+ * @see org.apache.commons.cli2.validation.Validator#validate(java.util.List)
+ */
+ public void validate(final List values) throws InvalidArgumentException {
+ for (final ListIterator i = values.listIterator(); i.hasNext();) {
+ final String name = (String) i.next();
+ try {
+ final URL url = new URL(name);
+
+ if (protocol != null && !protocol.equals(url.getProtocol())) {
+ throw new InvalidArgumentException(name);
+ }
+
+ i.set(url);
+ } catch (final MalformedURLException mue) {
+ throw new InvalidArgumentException(
+ "Cannot understand url: " + name);
+ }
+ }
+ }
+
+ /**
+ * @return
+ */
+ public String getProtocol() {
+ return protocol;
+ }
+
+ /**
+ * @param protocol
+ */
+ public void setProtocol(String protocol) {
+ this.protocol = protocol;
+ }
+}
1.2 +204 -153 jakarta-commons-sandbox/cli/src/java/org/apache/commons/cli2/validation/FileValidator.java
Index: FileValidator.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/cli/src/java/org/apache/commons/cli2/validation/FileValidator.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- FileValidator.java 18 Oct 2003 22:00:17 -0000 1.1
+++ FileValidator.java 20 Oct 2003 21:40:44 -0000 1.2
@@ -1,153 +1,204 @@
-/*
- * Created on 25-Aug-2003
- *
- * To change the template for this generated file go to
- * Window - Preferences - Java - Code Generation - Code and Comments
- */
-package org.apache.commons.cli2.validation;
-
-import java.io.File;
-import java.util.List;
-import java.util.ListIterator;
-
-/**
- * @author Rob
- *
- * To change the template for this generated type comment go to
- * Window - Preferences - Java - Code Generation - Code and Comments
- */
-public class FileValidator implements Validator {
-
- public static FileValidator getExistingInstance() {
- final FileValidator validator = new FileValidator();
- validator.setExisting(true);
- return validator;
- }
-
- public static FileValidator getExistingFileInstance() {
- final FileValidator validator = new FileValidator();
- validator.setExisting(true);
- validator.setFile(true);
- return validator;
- }
-
- public static FileValidator getExistingDirectoryInstance() {
- final FileValidator validator = new FileValidator();
- validator.setExisting(true);
- validator.setDirectory(true);
- return validator;
- }
-
- private boolean readable = false;
- private boolean writable = false;
- private boolean existing = false;
- private boolean directory = false;
- private boolean file = false;
- private boolean hidden = false;
-
- /* (non-Javadoc)
- * @see org.apache.commons.cli2.validation.Validator#validate(java.util.List)
- */
- public void validate(final List values) throws InvalidArgumentException {
- for (final ListIterator i = values.listIterator(); i.hasNext();) {
- final String name = (String) i.next();
- final File f = new File(name);
-
- if ((existing && !f.exists())
- || (file && !f.isFile())
- || (directory && !f.isDirectory())
- || (hidden && !f.isHidden())
- || (readable && !f.canRead())
- || (writable && !f.canWrite())) {
-
- throw new InvalidArgumentException(name);
- } else {
- i.set(f);
- }
- }
- }
-
- /**
- * @return
- */
- public boolean isDirectory() {
- return directory;
- }
-
- /**
- * @param directory
- */
- public void setDirectory(boolean directory) {
- this.directory = directory;
- }
-
- /**
- * @return
- */
- public boolean isExisting() {
- return existing;
- }
-
- /**
- * @param existing
- */
- public void setExisting(boolean existing) {
- this.existing = existing;
- }
-
- /**
- * @return
- */
- public boolean isFile() {
- return file;
- }
-
- /**
- * @param file
- */
- public void setFile(boolean file) {
- this.file = file;
- }
-
- /**
- * @return
- */
- public boolean isHidden() {
- return hidden;
- }
-
- /**
- * @param hidden
- */
- public void setHidden(boolean hidden) {
- this.hidden = hidden;
- }
-
- /**
- * @return
- */
- public boolean isReadable() {
- return readable;
- }
-
- /**
- * @param readable
- */
- public void setReadable(boolean readable) {
- this.readable = readable;
- }
-
- /**
- * @return
- */
- public boolean isWritable() {
- return writable;
- }
-
- /**
- * @param writable
- */
- public void setWritable(boolean writable) {
- this.writable = writable;
- }
-}
+/*
+ * $Header$
+ * $Revision$
+ * $Date$
+ *
+ * ====================================================================
+ *
+ * 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.validation;
+
+import java.io.File;
+import java.util.List;
+import java.util.ListIterator;
+
+/**
+ * @author Rob Oxspring
+ */
+public class FileValidator implements Validator {
+
+ public static FileValidator getExistingInstance() {
+ final FileValidator validator = new FileValidator();
+ validator.setExisting(true);
+ return validator;
+ }
+
+ public static FileValidator getExistingFileInstance() {
+ final FileValidator validator = new FileValidator();
+ validator.setExisting(true);
+ validator.setFile(true);
+ return validator;
+ }
+
+ public static FileValidator getExistingDirectoryInstance() {
+ final FileValidator validator = new FileValidator();
+ validator.setExisting(true);
+ validator.setDirectory(true);
+ return validator;
+ }
+
+ private boolean readable = false;
+ private boolean writable = false;
+ private boolean existing = false;
+ private boolean directory = false;
+ private boolean file = false;
+ private boolean hidden = false;
+
+ /* (non-Javadoc)
+ * @see org.apache.commons.cli2.validation.Validator#validate(java.util.List)
+ */
+ public void validate(final List values) throws InvalidArgumentException {
+ for (final ListIterator i = values.listIterator(); i.hasNext();) {
+ final String name = (String) i.next();
+ final File f = new File(name);
+
+ if ((existing && !f.exists())
+ || (file && !f.isFile())
+ || (directory && !f.isDirectory())
+ || (hidden && !f.isHidden())
+ || (readable && !f.canRead())
+ || (writable && !f.canWrite())) {
+
+ throw new InvalidArgumentException(name);
+ } else {
+ i.set(f);
+ }
+ }
+ }
+
+ /**
+ * @return
+ */
+ public boolean isDirectory() {
+ return directory;
+ }
+
+ /**
+ * @param directory
+ */
+ public void setDirectory(boolean directory) {
+ this.directory = directory;
+ }
+
+ /**
+ * @return
+ */
+ public boolean isExisting() {
+ return existing;
+ }
+
+ /**
+ * @param existing
+ */
+ public void setExisting(boolean existing) {
+ this.existing = existing;
+ }
+
+ /**
+ * @return
+ */
+ public boolean isFile() {
+ return file;
+ }
+
+ /**
+ * @param file
+ */
+ public void setFile(boolean file) {
+ this.file = file;
+ }
+
+ /**
+ * @return
+ */
+ public boolean isHidden() {
+ return hidden;
+ }
+
+ /**
+ * @param hidden
+ */
+ public void setHidden(boolean hidden) {
+ this.hidden = hidden;
+ }
+
+ /**
+ * @return
+ */
+ public boolean isReadable() {
+ return readable;
+ }
+
+ /**
+ * @param readable
+ */
+ public void setReadable(boolean readable) {
+ this.readable = readable;
+ }
+
+ /**
+ * @return
+ */
+ public boolean isWritable() {
+ return writable;
+ }
+
+ /**
+ * @param writable
+ */
+ public void setWritable(boolean writable) {
+ this.writable = writable;
+ }
+}
1.2 +161 -110 jakarta-commons-sandbox/cli/src/java/org/apache/commons/cli2/validation/DateValidator.java
Index: DateValidator.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/cli/src/java/org/apache/commons/cli2/validation/DateValidator.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- DateValidator.java 18 Oct 2003 22:00:17 -0000 1.1
+++ DateValidator.java 20 Oct 2003 21:40:44 -0000 1.2
@@ -1,110 +1,161 @@
-/*
- * Created on 25-Aug-2003
- *
- * To change the template for this generated file go to
- * Window - Preferences - Java - Code Generation - Code and Comments
- */
-package org.apache.commons.cli2.validation;
-
-import java.text.DateFormat;
-import java.text.ParsePosition;
-import java.util.Date;
-import java.util.List;
-import java.util.ListIterator;
-
-/**
- * @author Rob
- *
- * To change the template for this generated type comment go to
- * Window - Preferences - Java - Code Generation - Code and Comments
- */
-public class DateValidator implements Validator {
-
- public static DateValidator getDateInstance() {
- return new DateValidator(DateFormat.getDateInstance());
- }
-
- public static DateValidator getTimeInstance() {
- return new DateValidator(DateFormat.getTimeInstance());
- }
-
- public static DateValidator getDateTimeInstance() {
- return new DateValidator(DateFormat.getDateTimeInstance());
- }
-
- public final DateFormat[] formats;
-
- private Date minimum;
- private Date maximum;
-
- public DateValidator() {
- this(DateFormat.getInstance());
- }
-
- public DateValidator(final DateFormat format) {
- this.formats = new DateFormat[] { format };
- }
-
- public DateValidator(final List formats) {
- this.formats =
- (DateFormat[]) formats.toArray(new DateFormat[formats.size()]);
- }
-
- /* (non-Javadoc)
- * @see org.apache.commons.cli2.validation.Validator#validate(java.util.List)
- */
- public void validate(final List values) throws InvalidArgumentException {
- for (final ListIterator i = values.listIterator(); i.hasNext();) {
- final String value = (String) i.next();
-
- Date date = null;
- for (int f = 0; f < formats.length && date == null; ++f) {
- final ParsePosition pp = new ParsePosition(0);
- date = formats[f].parse(value, pp);
- if (pp.getIndex() < value.length()) {
- date = null;
- }
- }
-
- if ((minimum != null && date.getTime() < minimum.getTime())
- || (maximum != null && date.getTime() > maximum.getTime())) {
- throw new InvalidArgumentException("Out of range: " + value);
- }
-
- if (date == null) {
- throw new InvalidArgumentException(value);
- }
-
- i.set(date);
- }
- }
-
- /**
- * @return
- */
- public Date getMaximum() {
- return maximum;
- }
-
- /**
- * @param maximum
- */
- public void setMaximum(Date maximum) {
- this.maximum = maximum;
- }
-
- /**
- * @return
- */
- public Date getMinimum() {
- return minimum;
- }
-
- /**
- * @param minimum
- */
- public void setMinimum(Date minimum) {
- this.minimum = minimum;
- }
-
-}
+/*
+ * $Header$
+ * $Revision$
+ * $Date$
+ *
+ * ====================================================================
+ *
+ * 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.validation;
+
+import java.text.DateFormat;
+import java.text.ParsePosition;
+import java.util.Date;
+import java.util.List;
+import java.util.ListIterator;
+
+/**
+ * @author Rob Oxspring
+ */
+public class DateValidator implements Validator {
+
+ public static DateValidator getDateInstance() {
+ return new DateValidator(DateFormat.getDateInstance());
+ }
+
+ public static DateValidator getTimeInstance() {
+ return new DateValidator(DateFormat.getTimeInstance());
+ }
+
+ public static DateValidator getDateTimeInstance() {
+ return new DateValidator(DateFormat.getDateTimeInstance());
+ }
+
+ public final DateFormat[] formats;
+
+ private Date minimum;
+ private Date maximum;
+
+ public DateValidator() {
+ this(DateFormat.getInstance());
+ }
+
+ public DateValidator(final DateFormat format) {
+ this.formats = new DateFormat[] { format };
+ }
+
+ public DateValidator(final List formats) {
+ this.formats =
+ (DateFormat[]) formats.toArray(new DateFormat[formats.size()]);
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.commons.cli2.validation.Validator#validate(java.util.List)
+ */
+ public void validate(final List values) throws InvalidArgumentException {
+ for (final ListIterator i = values.listIterator(); i.hasNext();) {
+ final String value = (String) i.next();
+
+ Date date = null;
+ for (int f = 0; f < formats.length && date == null; ++f) {
+ final ParsePosition pp = new ParsePosition(0);
+ date = formats[f].parse(value, pp);
+ if (pp.getIndex() < value.length()) {
+ date = null;
+ }
+ }
+
+ if ((minimum != null && date.getTime() < minimum.getTime())
+ || (maximum != null && date.getTime() > maximum.getTime())) {
+ throw new InvalidArgumentException("Out of range: " + value);
+ }
+
+ if (date == null) {
+ throw new InvalidArgumentException(value);
+ }
+
+ i.set(date);
+ }
+ }
+
+ /**
+ * @return
+ */
+ public Date getMaximum() {
+ return maximum;
+ }
+
+ /**
+ * @param maximum
+ */
+ public void setMaximum(Date maximum) {
+ this.maximum = maximum;
+ }
+
+ /**
+ * @return
+ */
+ public Date getMinimum() {
+ return minimum;
+ }
+
+ /**
+ * @param minimum
+ */
+ public void setMinimum(Date minimum) {
+ this.minimum = minimum;
+ }
+
+}
1.2 +160 -109 jakarta-commons-sandbox/cli/src/java/org/apache/commons/cli2/validation/NumberValidator.java
Index: NumberValidator.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/cli/src/java/org/apache/commons/cli2/validation/NumberValidator.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- NumberValidator.java 18 Oct 2003 22:00:17 -0000 1.1
+++ NumberValidator.java 20 Oct 2003 21:40:44 -0000 1.2
@@ -1,109 +1,160 @@
-/*
- * Created on 25-Aug-2003
- *
- * To change the template for this generated file go to
- * Window - Preferences - Java - Code Generation - Code and Comments
- */
-package org.apache.commons.cli2.validation;
-
-import java.text.NumberFormat;
-import java.text.ParsePosition;
-import java.util.List;
-import java.util.ListIterator;
-
-/**
- * @author Rob
- *
- * To change the template for this generated type comment go to
- * Window - Preferences - Java - Code Generation - Code and Comments
- */
-public class NumberValidator implements Validator {
-
- public static NumberValidator getCurrencyInstance() {
- return new NumberValidator(NumberFormat.getCurrencyInstance());
- }
-
- public static NumberValidator getIntegerInstance() {
- return new NumberValidator(NumberFormat.getIntegerInstance());
- }
-
- public static NumberValidator getPercentInstance() {
- return new NumberValidator(NumberFormat.getPercentInstance());
- }
-
- public static NumberValidator getNumberInstance() {
- return new NumberValidator(NumberFormat.getNumberInstance());
- }
-
- private final NumberFormat format;
- private Number minimum = null;
- private Number maximum = null;
-
- public NumberValidator() {
- this(NumberFormat.getInstance());
- }
-
- public NumberValidator(final NumberFormat format) {
- this.format = format;
- }
-
- /* (non-Javadoc)
- * @see org.apache.commons.cli2.validation.Validator#validate(java.util.List)
- */
- public void validate(final List values) throws InvalidArgumentException {
- for (final ListIterator i = values.listIterator(); i.hasNext();) {
- final String value = (String) i.next();
-
- final ParsePosition pp = new ParsePosition(0);
- final Number number = format.parse(value, pp);
- if (pp.getIndex() < value.length()) {
- throw new InvalidArgumentException(value);
- }
-
- if ((minimum != null
- && number.doubleValue() < minimum.doubleValue())
- || (maximum != null
- && number.doubleValue() > maximum.doubleValue())) {
- throw new InvalidArgumentException("Out of range: " + value);
- }
-
- i.set(number);
- }
- }
-
- /**
- * @return
- */
- public NumberFormat getFormat() {
- return format;
- }
-
- /**
- * @return
- */
- public Number getMaximum() {
- return maximum;
- }
-
- /**
- * @param maximum
- */
- public void setMaximum(Number maximum) {
- this.maximum = maximum;
- }
-
- /**
- * @return
- */
- public Number getMinimum() {
- return minimum;
- }
-
- /**
- * @param minimum
- */
- public void setMinimum(Number minimum) {
- this.minimum = minimum;
- }
-
-}
+/*
+ * $Header$
+ * $Revision$
+ * $Date$
+ *
+ * ====================================================================
+ *
+ * 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.validation;
+
+import java.text.NumberFormat;
+import java.text.ParsePosition;
+import java.util.List;
+import java.util.ListIterator;
+
+/**
+ * @author Rob Oxspring
+ */
+public class NumberValidator implements Validator {
+
+ public static NumberValidator getCurrencyInstance() {
+ return new NumberValidator(NumberFormat.getCurrencyInstance());
+ }
+
+ public static NumberValidator getIntegerInstance() {
+ return new NumberValidator(NumberFormat.getIntegerInstance());
+ }
+
+ public static NumberValidator getPercentInstance() {
+ return new NumberValidator(NumberFormat.getPercentInstance());
+ }
+
+ public static NumberValidator getNumberInstance() {
+ return new NumberValidator(NumberFormat.getNumberInstance());
+ }
+
+ private final NumberFormat format;
+ private Number minimum = null;
+ private Number maximum = null;
+
+ public NumberValidator() {
+ this(NumberFormat.getInstance());
+ }
+
+ public NumberValidator(final NumberFormat format) {
+ this.format = format;
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.commons.cli2.validation.Validator#validate(java.util.List)
+ */
+ public void validate(final List values) throws InvalidArgumentException {
+ for (final ListIterator i = values.listIterator(); i.hasNext();) {
+ final String value = (String) i.next();
+
+ final ParsePosition pp = new ParsePosition(0);
+ final Number number = format.parse(value, pp);
+ if (pp.getIndex() < value.length()) {
+ throw new InvalidArgumentException(value);
+ }
+
+ if ((minimum != null
+ && number.doubleValue() < minimum.doubleValue())
+ || (maximum != null
+ && number.doubleValue() > maximum.doubleValue())) {
+ throw new InvalidArgumentException("Out of range: " + value);
+ }
+
+ i.set(number);
+ }
+ }
+
+ /**
+ * @return
+ */
+ public NumberFormat getFormat() {
+ return format;
+ }
+
+ /**
+ * @return
+ */
+ public Number getMaximum() {
+ return maximum;
+ }
+
+ /**
+ * @param maximum
+ */
+ public void setMaximum(Number maximum) {
+ this.maximum = maximum;
+ }
+
+ /**
+ * @return
+ */
+ public Number getMinimum() {
+ return minimum;
+ }
+
+ /**
+ * @param minimum
+ */
+ public void setMinimum(Number minimum) {
+ this.minimum = minimum;
+ }
+
+}
1.2 +71 -19 jakarta-commons-sandbox/cli/src/java/org/apache/commons/cli2/validation/InvalidArgumentException.java
Index: InvalidArgumentException.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/cli/src/java/org/apache/commons/cli2/validation/InvalidArgumentException.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- InvalidArgumentException.java 18 Oct 2003 22:00:17 -0000 1.1
+++ InvalidArgumentException.java 20 Oct 2003 21:40:44 -0000 1.2
@@ -1,19 +1,71 @@
-/*
- * Created on 25-Aug-2003
- *
- * To change the template for this generated file go to
- * Window - Preferences - Java - Code Generation - Code and Comments
- */
-package org.apache.commons.cli2.validation;
-
-/**
- * @author Rob
- *
- * To change the template for this generated type comment go to
- * Window - Preferences - Java - Code Generation - Code and Comments
- */
-public class InvalidArgumentException extends Exception {
- public InvalidArgumentException(final String value) {
- super(value);
- }
-}
+/*
+ * $Header$
+ * $Revision$
+ * $Date$
+ *
+ * ====================================================================
+ *
+ * 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.validation;
+
+/**
+ * @author Rob Oxspring
+ */
+public class InvalidArgumentException extends Exception {
+
+ public InvalidArgumentException(final String message) {
+ super(message);
+ }
+}
1.2 +185 -128 jakarta-commons-sandbox/cli/src/java/org/apache/commons/cli2/validation/ClassValidator.java
Index: ClassValidator.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/cli/src/java/org/apache/commons/cli2/validation/ClassValidator.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ClassValidator.java 18 Oct 2003 22:00:17 -0000 1.1
+++ ClassValidator.java 20 Oct 2003 21:40:44 -0000 1.2
@@ -1,128 +1,185 @@
-/*
- * Created on 25-Aug-2003
- *
- * To change the template for this generated file go to
- * Window - Preferences - Java - Code Generation - Code and Comments
- */
-package org.apache.commons.cli2.validation;
-
-import java.util.List;
-import java.util.ListIterator;
-
-/**
- * @author Rob
- *
- * To change the template for this generated type comment go to
- * Window - Preferences - Java - Code Generation - Code and Comments
- */
-public class ClassValidator implements Validator {
-
- private boolean loadable = false;
- private boolean instance = false;
-
- private ClassLoader loader;
-
- /* (non-Javadoc)
- * @see org.apache.commons.cli2.validation.Validator#validate(java.util.List)
- */
- public void validate(final List values) throws InvalidArgumentException {
- for (final ListIterator i = values.listIterator(); i.hasNext();) {
- final String name = (String) i.next();
-
- if (!isPotentialClassName(name)) {
- throw new InvalidArgumentException("Bad class name: " + name);
- }
-
- if (loadable || instance) {
- if (loader == null) {
- loader = getClass().getClassLoader();
- }
- try {
- final Class clazz = loader.loadClass(name);
- if(instance){
- i.set(clazz.newInstance());
- }
- else{
- i.set(clazz);
- }
- } catch (ClassNotFoundException cnfe) {
- throw new InvalidArgumentException(
- "Class not found: " + name);
- } catch (IllegalAccessException iae) {
- throw new InvalidArgumentException(
- "Cannot create instance: " + name);
- } catch (InstantiationException iae) {
- throw new InvalidArgumentException(
- "Cannot create instance: " + name);
- }
- }
- }
- }
-
- protected boolean isPotentialClassName(final String name) {
- final char[] chars = name.toCharArray();
-
- boolean expectingStart = true;
-
- for (int i = 0; i < chars.length; ++i) {
- final char c = chars[i];
- if (expectingStart) {
- if (!Character.isJavaIdentifierStart(c)) {
- return false;
- } else {
- expectingStart = false;
- }
- } else {
- if (c == '.') {
- expectingStart = true;
- } else if (!Character.isJavaIdentifierPart(c)) {
- return false;
- }
- }
- }
- return !expectingStart;
- }
-
- /**
- * @return
- */
- public boolean isLoadable() {
- return loadable;
- }
-
- /**
- * @param loadable
- */
- public void setLoadable(boolean loadable) {
- this.loadable = loadable;
- }
-
- /**
- * @return
- */
- public ClassLoader getLoader() {
- return loader;
- }
-
- /**
- * @param loader
- */
- public void setLoader(ClassLoader loader) {
- this.loader = loader;
- }
-
- /**
- * @return
- */
- public boolean isInstance() {
- return instance;
- }
-
- /**
- * @param instance
- */
- public void setInstance(boolean instance) {
- this.instance = instance;
- }
-
-}
+/*
+ * $Header$
+ * $Revision$
+ * $Date$
+ *
+ * ====================================================================
+ *
+ * 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.validation;
+
+import java.util.List;
+import java.util.ListIterator;
+
+/**
+ * @author Rob Oxspring
+ */
+public class ClassValidator implements Validator {
+
+ private boolean loadable = false;
+ private boolean instance = false;
+
+ private ClassLoader loader;
+
+ /* (non-Javadoc)
+ * @see org.apache.commons.cli2.validation.Validator#validate(java.util.List)
+ */
+ public void validate(final List values) throws InvalidArgumentException {
+ for (final ListIterator i = values.listIterator(); i.hasNext();) {
+ final String name = (String) i.next();
+
+ if (!isPotentialClassName(name)) {
+ throw new InvalidArgumentException("Bad class name: " + name);
+ }
+
+ if (loadable || instance) {
+ if (loader == null) {
+ loader = getClass().getClassLoader();
+ }
+ try {
+ final Class clazz = loader.loadClass(name);
+ if (instance) {
+ i.set(clazz.newInstance());
+ }
+ else {
+ i.set(clazz);
+ }
+ }
+ catch (ClassNotFoundException cnfe) {
+ throw new InvalidArgumentException(
+ "Class not found: " + name);
+ }
+ catch (IllegalAccessException iae) {
+ throw new InvalidArgumentException(
+ "Cannot create instance: " + name);
+ }
+ catch (InstantiationException iae) {
+ throw new InvalidArgumentException(
+ "Cannot create instance: " + name);
+ }
+ }
+ }
+ }
+
+ protected boolean isPotentialClassName(final String name) {
+ final char[] chars = name.toCharArray();
+
+ boolean expectingStart = true;
+
+ for (int i = 0; i < chars.length; ++i) {
+ final char c = chars[i];
+ if (expectingStart) {
+ if (!Character.isJavaIdentifierStart(c)) {
+ return false;
+ }
+ else {
+ expectingStart = false;
+ }
+ }
+ else {
+ if (c == '.') {
+ expectingStart = true;
+ }
+ else if (!Character.isJavaIdentifierPart(c)) {
+ return false;
+ }
+ }
+ }
+ return !expectingStart;
+ }
+
+ /**
+ * @return
+ */
+ public boolean isLoadable() {
+ return loadable;
+ }
+
+ /**
+ * @param loadable
+ */
+ public void setLoadable(boolean loadable) {
+ this.loadable = loadable;
+ }
+
+ /**
+ * @return
+ */
+ public ClassLoader getLoader() {
+ return loader;
+ }
+
+ /**
+ * @param loader
+ */
+ public void setLoader(ClassLoader loader) {
+ this.loader = loader;
+ }
+
+ /**
+ * @return
+ */
+ public boolean isInstance() {
+ return instance;
+ }
+
+ /**
+ * @param instance
+ */
+ public void setInstance(boolean instance) {
+ this.instance = instance;
+ }
+
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org