Categories:
Audio (13)
Biotech (29)
Bytecode (36)
Database (77)
Framework (7)
Game (7)
General (507)
Graphics (53)
I/O (35)
IDE (2)
JAR Tools (101)
JavaBeans (21)
JDBC (121)
JDK (426)
JSP (20)
Logging (108)
Mail (58)
Messaging (8)
Network (84)
PDF (97)
Report (7)
Scripting (84)
Security (32)
Server (121)
Servlet (26)
SOAP (24)
Testing (54)
Web (15)
XML (309)
Collections:
Other Resources:
Apache Commons CLI Source Code Files
Apache Commons CLI Source Code Files are provided in the source package file commons-cli-1.5.0-sources.jar.
You can download commons-cli-1.5.0-src.zip as described in the previous tutorial and go to the "src/main/java/" sub-folder to view Source Code files.
You can also browse Apache Commons CLI Source Code files below:
✍: FYIcenter.com
⏎ org/apache/commons/cli/TypeHandler.java
/* Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ package org.apache.commons.cli; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.net.MalformedURLException; import java.net.URL; import java.util.Date; /** * This is a temporary implementation. TypeHandler will handle the pluggableness of OptionTypes and it will direct all * of these types of conversion functionalities to ConvertUtils component in Commons already. BeanUtils I think. */ public class TypeHandler { /** * Returns the class whose name is {@code classname}. * * @param classname the class name * @return The class if it is found * @throws ParseException if the class could not be found */ public static Class<?> createClass(final String classname) throws ParseException { try { return Class.forName(classname); } catch (final ClassNotFoundException e) { throw new ParseException("Unable to find the class: " + classname); } } /** * Returns the date represented by {@code str}. * <p> * This method is not yet implemented and always throws an {@link UnsupportedOperationException}. * * @param str the date string * @return The date if {@code str} is a valid date string, otherwise return null. * @throws UnsupportedOperationException always */ public static Date createDate(final String str) { throw new UnsupportedOperationException("Not yet implemented"); } /** * Returns the File represented by {@code str}. * * @param str the File location * @return The file represented by {@code str}. */ public static File createFile(final String str) { return new File(str); } /** * Returns the File[] represented by {@code str}. * <p> * This method is not yet implemented and always throws an {@link UnsupportedOperationException}. * * @param str the paths to the files * @return The File[] represented by {@code str}. * @throws UnsupportedOperationException always */ public static File[] createFiles(final String str) { // to implement/port: // return FileW.findFiles(str); throw new UnsupportedOperationException("Not yet implemented"); } /** * Create a number from a String. If a . is present, it creates a Double, otherwise a Long. * * @param str the value * @return the number represented by {@code str} * @throws ParseException if {@code str} is not a number */ public static Number createNumber(final String str) throws ParseException { try { if (str.indexOf('.') != -1) { return Double.valueOf(str); } return Long.valueOf(str); } catch (final NumberFormatException e) { throw new ParseException(e.getMessage()); } } /** * Create an Object from the classname and empty constructor. * * @param classname the argument value * @return the initialized object * @throws ParseException if the class could not be found or the object could not be created */ public static Object createObject(final String classname) throws ParseException { final Class<?> cl; try { cl = Class.forName(classname); } catch (final ClassNotFoundException cnfe) { throw new ParseException("Unable to find the class: " + classname); } try { return cl.newInstance(); } catch (final Exception e) { throw new ParseException(e.getClass().getName() + "; Unable to create an instance of: " + classname); } } /** * Returns the URL represented by {@code str}. * * @param str the URL string * @return The URL in {@code str} is well-formed * @throws ParseException if the URL in {@code str} is not well-formed */ public static URL createURL(final String str) throws ParseException { try { return new URL(str); } catch (final MalformedURLException e) { throw new ParseException("Unable to parse the URL: " + str); } } /** * Returns the {@code Object} of type {@code clazz} with the value of {@code str}. * * @param str the command line value * @param clazz the class representing the type of argument * @param <T> type of argument * @return The instance of {@code clazz} initialized with the value of {@code str}. * @throws ParseException if the value creation for the given class failed */ @SuppressWarnings("unchecked") // returned value will have type T because it is fixed by clazz public static <T> T createValue(final String str, final Class<T> clazz) throws ParseException { if (PatternOptionBuilder.STRING_VALUE == clazz) { return (T) str; } if (PatternOptionBuilder.OBJECT_VALUE == clazz) { return (T) createObject(str); } if (PatternOptionBuilder.NUMBER_VALUE == clazz) { return (T) createNumber(str); } if (PatternOptionBuilder.DATE_VALUE == clazz) { return (T) createDate(str); } if (PatternOptionBuilder.CLASS_VALUE == clazz) { return (T) createClass(str); } if (PatternOptionBuilder.FILE_VALUE == clazz) { return (T) createFile(str); } if (PatternOptionBuilder.EXISTING_FILE_VALUE == clazz) { return (T) openFile(str); } if (PatternOptionBuilder.FILES_VALUE == clazz) { return (T) createFiles(str); } if (PatternOptionBuilder.URL_VALUE == clazz) { return (T) createURL(str); } throw new ParseException("Unable to handle the class: " + clazz); } /** * Returns the {@code Object} of type {@code obj} with the value of {@code str}. * * @param str the command line value * @param obj the type of argument * @return The instance of {@code obj} initialized with the value of {@code str}. * @throws ParseException if the value creation for the given object type failed */ public static Object createValue(final String str, final Object obj) throws ParseException { return createValue(str, (Class<?>) obj); } /** * Returns the opened FileInputStream represented by {@code str}. * * @param str the file location * @return The file input stream represented by {@code str}. * @throws ParseException if the file is not exist or not readable */ public static FileInputStream openFile(final String str) throws ParseException { try { return new FileInputStream(str); } catch (final FileNotFoundException e) { throw new ParseException("Unable to find file: " + str); } } }
⏎ org/apache/commons/cli/TypeHandler.java
Or download all of them as a single archive file:
File name: commons-cli-1.5.0-sources.jar File size: 63124 bytes Release date: 2021-10-27 Download
⇒ Download Apache Commons CLI 1.4 Binary Package
⇐ Download Apache Commons CLI Source Package
2018-10-25, 14333👍, 0💬
Popular Posts:
What Is activation.jar? I heard it's related to JAF (JavaBeans Activation Framework) 1.1? The if you...
What Is commons-io-2.11.jar? commons-io-2.11.jar is the JAR file for Commons IO 2.5, which is a libr...
What JAR files are required to run dom\Counter.java provided in the Apache Xerces package? You can f...
JDK 11 jdk.crypto.ec.jmod is the JMOD file for JDK 11 Crypto EC module. JDK 11 Crypto EC module comp...
maven-core-3.5.4.jar is the JAR file for Apache Maven 3.5.4 Core module. Apache Maven is a software ...