You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@oodt.apache.org by sm...@apache.org on 2010/03/01 22:17:27 UTC
svn commit: r917722 [2/3] - in
/incubator/oodt/cas-commons/trunk/src/main/java/gov/nasa/jpl/oodt/cas/commons:
database/ date/ exec/ filter/ io/ option/ option/handler/ option/parser/
option/required/ option/util/ option/validator/ pagination/ spring/ s...
Modified: incubator/oodt/cas-commons/trunk/src/main/java/gov/nasa/jpl/oodt/cas/commons/io/LoggerOutputStream.java
URL: http://svn.apache.org/viewvc/incubator/oodt/cas-commons/trunk/src/main/java/gov/nasa/jpl/oodt/cas/commons/io/LoggerOutputStream.java?rev=917722&r1=917721&r2=917722&view=diff
==============================================================================
--- incubator/oodt/cas-commons/trunk/src/main/java/gov/nasa/jpl/oodt/cas/commons/io/LoggerOutputStream.java (original)
+++ incubator/oodt/cas-commons/trunk/src/main/java/gov/nasa/jpl/oodt/cas/commons/io/LoggerOutputStream.java Mon Mar 1 21:17:24 2010
@@ -1,71 +1,84 @@
-//Copyright (c) 2008, California Institute of Technology.
-//ALL RIGHTS RESERVED. U.S. Government sponsorship acknowledged.
-//
-//$Id$
-
-package gov.nasa.jpl.oodt.cas.commons.io;
-
-//JDK imports
-import java.io.IOException;
-import java.io.OutputStream;
-import java.nio.CharBuffer;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-/**
- *
- * @author bfoster
- * @version $Revision$
- *
- * <p>
- * Describe your class here
- * </p>.
- */
-public class LoggerOutputStream extends OutputStream {
-
- private Logger logger;
-
- private CharBuffer buffer;
-
- private Level logLevel;
-
- public LoggerOutputStream(Logger logger) throws InstantiationException {
- this(logger, Level.INFO);
- }
-
- public LoggerOutputStream(Logger logger, Level logLevel)
- throws InstantiationException {
- this(logger, 512, logLevel);
- }
-
- public LoggerOutputStream(Logger logger, int numOfBytesPerWrite)
- throws InstantiationException {
- this(logger, numOfBytesPerWrite, Level.INFO);
- }
-
- public LoggerOutputStream(Logger logger, int numOfBytesPerWrite,
- Level logLevel) throws InstantiationException {
- this.logger = logger;
- this.buffer = CharBuffer.wrap(new char[numOfBytesPerWrite]);
- this.logLevel = logLevel;
- }
-
- public void write(int b) throws IOException {
- if (this.buffer.hasRemaining()) {
- this.buffer.put((char) b);
- if (!this.buffer.hasRemaining())
- this.flush();
- } else
- this.logger.log(this.logLevel, ((char) b) + "");
- }
-
- public void flush() {
- if (this.buffer.position() > 0) {
- char[] flushContext = new char[this.buffer.position()];
- System.arraycopy(this.buffer.array(), 0, flushContext, 0, this.buffer.position());
- this.logger.log(this.logLevel, new String(flushContext));
- this.buffer.clear();
- }
- }
-
-}
+/*
+ * 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 gov.nasa.jpl.oodt.cas.commons.io;
+
+//JDK imports
+import java.io.IOException;
+import java.io.OutputStream;
+import java.nio.CharBuffer;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ *
+ * @author bfoster
+ * @version $Revision$
+ *
+ * <p>
+ * Describe your class here
+ * </p>.
+ */
+public class LoggerOutputStream extends OutputStream {
+
+ private Logger logger;
+
+ private CharBuffer buffer;
+
+ private Level logLevel;
+
+ public LoggerOutputStream(Logger logger) throws InstantiationException {
+ this(logger, Level.INFO);
+ }
+
+ public LoggerOutputStream(Logger logger, Level logLevel)
+ throws InstantiationException {
+ this(logger, 512, logLevel);
+ }
+
+ public LoggerOutputStream(Logger logger, int numOfBytesPerWrite)
+ throws InstantiationException {
+ this(logger, numOfBytesPerWrite, Level.INFO);
+ }
+
+ public LoggerOutputStream(Logger logger, int numOfBytesPerWrite,
+ Level logLevel) throws InstantiationException {
+ this.logger = logger;
+ this.buffer = CharBuffer.wrap(new char[numOfBytesPerWrite]);
+ this.logLevel = logLevel;
+ }
+
+ public void write(int b) throws IOException {
+ if (this.buffer.hasRemaining()) {
+ this.buffer.put((char) b);
+ if (!this.buffer.hasRemaining())
+ this.flush();
+ } else
+ this.logger.log(this.logLevel, ((char) b) + "");
+ }
+
+ public void flush() {
+ if (this.buffer.position() > 0) {
+ char[] flushContext = new char[this.buffer.position()];
+ System.arraycopy(this.buffer.array(), 0, flushContext, 0, this.buffer.position());
+ this.logger.log(this.logLevel, new String(flushContext));
+ this.buffer.clear();
+ }
+ }
+
+}
Modified: incubator/oodt/cas-commons/trunk/src/main/java/gov/nasa/jpl/oodt/cas/commons/option/CmdLineOption.java
URL: http://svn.apache.org/viewvc/incubator/oodt/cas-commons/trunk/src/main/java/gov/nasa/jpl/oodt/cas/commons/option/CmdLineOption.java?rev=917722&r1=917721&r2=917722&view=diff
==============================================================================
--- incubator/oodt/cas-commons/trunk/src/main/java/gov/nasa/jpl/oodt/cas/commons/option/CmdLineOption.java (original)
+++ incubator/oodt/cas-commons/trunk/src/main/java/gov/nasa/jpl/oodt/cas/commons/option/CmdLineOption.java Mon Mar 1 21:17:24 2010
@@ -1,196 +1,209 @@
-//Copyright (c) 2008, California Institute of Technology.
-//ALL RIGHTS RESERVED. U.S. Government sponsorship acknowledged.
-//
-//$Id$
-
-package gov.nasa.jpl.oodt.cas.commons.option;
-
-//JDK imports
-import java.util.LinkedList;
-import java.util.List;
-
-//OODT imports
-import gov.nasa.jpl.oodt.cas.commons.option.handler.CmdLineOptionHandler;
-import gov.nasa.jpl.oodt.cas.commons.option.handler.StdCmdLineOptionHandler;
-import gov.nasa.jpl.oodt.cas.commons.option.required.RequiredOption;
-import gov.nasa.jpl.oodt.cas.commons.option.validator.CmdLineOptionValidator;
-import gov.nasa.jpl.oodt.cas.commons.spring.SpringSetIdInjectionType;
-
-/**
- *
- * @author bfoster
- * @version $Revision$
- *
- * <p>Describe your class here</p>
- *
- */
-public class CmdLineOption implements Comparable<CmdLineOption>, SpringSetIdInjectionType {
-
- private String shortOption;
-
- private String longOption;
-
- private String description;
-
- private String optionArgName;
-
- private boolean required;
-
- private List<RequiredOption> requiredOptions;
-
- private boolean hasArgs;
-
- private boolean performAndQuit;
-
- private String id;
-
- private Class<?> type;
-
- private CmdLineOptionHandler handler;
-
- private List<CmdLineOptionValidator> validators;
-
- public CmdLineOption() {
- this.optionArgName = "arg";
- this.required = false;
- this.hasArgs = false;
- this.performAndQuit = false;
- this.requiredOptions = new LinkedList<RequiredOption>();
- this.handler = new StdCmdLineOptionHandler();
- this.validators = new LinkedList<CmdLineOptionValidator>();
- }
-
- public CmdLineOption(String shortOption, String longOption,
- String description, boolean hasArgs) {
- this();
- this.id = longOption;
- this.shortOption = shortOption;
- this.longOption = longOption;
- this.description = description;
- this.hasArgs = hasArgs;
- }
-
- public Class<?> getType() {
- return type;
- }
-
- public void setType(Class<?> type) {
- this.type = type;
- }
-
- public String getId() {
- return id;
- }
-
- public void setId(String id) {
- this.id = id;
- }
-
- public void setHandler(CmdLineOptionHandler handler) {
- this.handler = handler;
- }
-
- public CmdLineOptionHandler getHandler() {
- return this.handler;
- }
-
- public List<CmdLineOptionValidator> getValidators() {
- return this.validators;
- }
-
- public void setValidators(List<CmdLineOptionValidator> validators) {
- this.validators = validators;
- }
-
- public String getShortOption() {
- return shortOption;
- }
-
- public void setShortOption(String shortOption) {
- this.shortOption = shortOption;
- }
-
- public String getLongOption() {
- return longOption;
- }
-
- public void setLongOption(String longOption) {
- this.longOption = longOption;
- }
-
- public String getDescription() {
- return description;
- }
-
- public void setDescription(String description) {
- this.description = description;
- }
-
- public boolean hasArgs() {
- return hasArgs;
- }
-
- public void setHasArgs(boolean hasArgs) {
- this.hasArgs = hasArgs;
- }
-
- public void setOptionArgName(String optionArgName) {
- this.optionArgName = optionArgName;
- }
-
- public String getOptionArgName() {
- return optionArgName;
- }
-
- public void setRequired(boolean required) {
- this.required = required;
- }
-
- public boolean isRequired() {
- return required;
- }
-
- public List<RequiredOption> getRequiredOptions() {
- return this.requiredOptions;
- }
-
- public void setRequiredOptions(List<RequiredOption> requiredOptions) {
- this.requiredOptions = requiredOptions;
- if (this.requiredOptions.size() > 0)
- this.required = true;
- }
-
- public boolean isPerformAndQuit() {
- return performAndQuit;
- }
-
- public void setPerformAndQuit(boolean performAndQuit) {
- this.performAndQuit = performAndQuit;
- }
-
- public int compareTo(CmdLineOption cmdLineOption) {
- int thisScore = (this.required ? 2 : 0)
- - (this.requiredOptions.size() > 0 ? 1 : 0);
- int compareScore = (cmdLineOption.required ? 2 : 0)
- - (cmdLineOption.requiredOptions.size() > 0 ? 1 : 0);
- if ((!this.required && !cmdLineOption.required)
- || thisScore == compareScore) {
- if (this.shortOption != null && cmdLineOption.shortOption != null)
- return this.shortOption.compareTo(cmdLineOption.shortOption);
- else
- return this.longOption.compareTo(cmdLineOption.longOption);
- } else {
- return new Integer(compareScore).compareTo(thisScore);
- }
- }
-
- public boolean equals(Object obj) {
- if (obj instanceof CmdLineOption) {
- CmdLineOption compareObj = (CmdLineOption) obj;
- return compareObj.shortOption.equals(this.shortOption)
- || compareObj.longOption.equals(this.longOption);
- } else
- return false;
- }
-
-}
+/*
+ * 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 gov.nasa.jpl.oodt.cas.commons.option;
+
+//JDK imports
+import java.util.LinkedList;
+import java.util.List;
+
+//OODT imports
+import gov.nasa.jpl.oodt.cas.commons.option.handler.CmdLineOptionHandler;
+import gov.nasa.jpl.oodt.cas.commons.option.handler.StdCmdLineOptionHandler;
+import gov.nasa.jpl.oodt.cas.commons.option.required.RequiredOption;
+import gov.nasa.jpl.oodt.cas.commons.option.validator.CmdLineOptionValidator;
+import gov.nasa.jpl.oodt.cas.commons.spring.SpringSetIdInjectionType;
+
+/**
+ *
+ * @author bfoster
+ * @version $Revision$
+ *
+ * <p>Describe your class here</p>
+ *
+ */
+public class CmdLineOption implements Comparable<CmdLineOption>, SpringSetIdInjectionType {
+
+ private String shortOption;
+
+ private String longOption;
+
+ private String description;
+
+ private String optionArgName;
+
+ private boolean required;
+
+ private List<RequiredOption> requiredOptions;
+
+ private boolean hasArgs;
+
+ private boolean performAndQuit;
+
+ private String id;
+
+ private Class<?> type;
+
+ private CmdLineOptionHandler handler;
+
+ private List<CmdLineOptionValidator> validators;
+
+ public CmdLineOption() {
+ this.optionArgName = "arg";
+ this.required = false;
+ this.hasArgs = false;
+ this.performAndQuit = false;
+ this.requiredOptions = new LinkedList<RequiredOption>();
+ this.handler = new StdCmdLineOptionHandler();
+ this.validators = new LinkedList<CmdLineOptionValidator>();
+ }
+
+ public CmdLineOption(String shortOption, String longOption,
+ String description, boolean hasArgs) {
+ this();
+ this.id = longOption;
+ this.shortOption = shortOption;
+ this.longOption = longOption;
+ this.description = description;
+ this.hasArgs = hasArgs;
+ }
+
+ public Class<?> getType() {
+ return type;
+ }
+
+ public void setType(Class<?> type) {
+ this.type = type;
+ }
+
+ public String getId() {
+ return id;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ public void setHandler(CmdLineOptionHandler handler) {
+ this.handler = handler;
+ }
+
+ public CmdLineOptionHandler getHandler() {
+ return this.handler;
+ }
+
+ public List<CmdLineOptionValidator> getValidators() {
+ return this.validators;
+ }
+
+ public void setValidators(List<CmdLineOptionValidator> validators) {
+ this.validators = validators;
+ }
+
+ public String getShortOption() {
+ return shortOption;
+ }
+
+ public void setShortOption(String shortOption) {
+ this.shortOption = shortOption;
+ }
+
+ public String getLongOption() {
+ return longOption;
+ }
+
+ public void setLongOption(String longOption) {
+ this.longOption = longOption;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ public boolean hasArgs() {
+ return hasArgs;
+ }
+
+ public void setHasArgs(boolean hasArgs) {
+ this.hasArgs = hasArgs;
+ }
+
+ public void setOptionArgName(String optionArgName) {
+ this.optionArgName = optionArgName;
+ }
+
+ public String getOptionArgName() {
+ return optionArgName;
+ }
+
+ public void setRequired(boolean required) {
+ this.required = required;
+ }
+
+ public boolean isRequired() {
+ return required;
+ }
+
+ public List<RequiredOption> getRequiredOptions() {
+ return this.requiredOptions;
+ }
+
+ public void setRequiredOptions(List<RequiredOption> requiredOptions) {
+ this.requiredOptions = requiredOptions;
+ if (this.requiredOptions.size() > 0)
+ this.required = true;
+ }
+
+ public boolean isPerformAndQuit() {
+ return performAndQuit;
+ }
+
+ public void setPerformAndQuit(boolean performAndQuit) {
+ this.performAndQuit = performAndQuit;
+ }
+
+ public int compareTo(CmdLineOption cmdLineOption) {
+ int thisScore = (this.required ? 2 : 0)
+ - (this.requiredOptions.size() > 0 ? 1 : 0);
+ int compareScore = (cmdLineOption.required ? 2 : 0)
+ - (cmdLineOption.requiredOptions.size() > 0 ? 1 : 0);
+ if ((!this.required && !cmdLineOption.required)
+ || thisScore == compareScore) {
+ if (this.shortOption != null && cmdLineOption.shortOption != null)
+ return this.shortOption.compareTo(cmdLineOption.shortOption);
+ else
+ return this.longOption.compareTo(cmdLineOption.longOption);
+ } else {
+ return new Integer(compareScore).compareTo(thisScore);
+ }
+ }
+
+ public boolean equals(Object obj) {
+ if (obj instanceof CmdLineOption) {
+ CmdLineOption compareObj = (CmdLineOption) obj;
+ return compareObj.shortOption.equals(this.shortOption)
+ || compareObj.longOption.equals(this.longOption);
+ } else
+ return false;
+ }
+
+}
Modified: incubator/oodt/cas-commons/trunk/src/main/java/gov/nasa/jpl/oodt/cas/commons/option/CmdLineOptionInstance.java
URL: http://svn.apache.org/viewvc/incubator/oodt/cas-commons/trunk/src/main/java/gov/nasa/jpl/oodt/cas/commons/option/CmdLineOptionInstance.java?rev=917722&r1=917721&r2=917722&view=diff
==============================================================================
--- incubator/oodt/cas-commons/trunk/src/main/java/gov/nasa/jpl/oodt/cas/commons/option/CmdLineOptionInstance.java (original)
+++ incubator/oodt/cas-commons/trunk/src/main/java/gov/nasa/jpl/oodt/cas/commons/option/CmdLineOptionInstance.java Mon Mar 1 21:17:24 2010
@@ -1,59 +1,72 @@
-//Copyright (c) 2008, California Institute of Technology.
-//ALL RIGHTS RESERVED. U.S. Government sponsorship acknowledged.
-//
-//$Id$
-
-package gov.nasa.jpl.oodt.cas.commons.option;
-
-//JDK imports
-import java.util.LinkedList;
-import java.util.List;
-
-/**
- *
- * @author bfoster
- * @version $Revision$
- *
- * <p>Describe your class here</p>.
- */
-public class CmdLineOptionInstance {
-
- private CmdLineOption option;
- private List<String> values;
-
- public CmdLineOptionInstance() {
- this.option = null;
- this.values = new LinkedList<String>();
- }
-
- public CmdLineOptionInstance(CmdLineOption option, List<String> values) {
- this.option = option;
- this.values = values;
- }
-
- public CmdLineOption getOption() {
- return option;
- }
-
- public void setOption(CmdLineOption option) {
- this.option = option;
- }
-
- public List<String> getValues() {
- return values;
- }
-
- public void setValues(List<String> values) {
- this.values = values;
- }
-
- public boolean equals(Object obj) {
- if (obj instanceof CmdLineOptionInstance) {
- CmdLineOptionInstance compareObj = (CmdLineOptionInstance) obj;
- return compareObj.option.equals(this.option)
- && compareObj.values.equals(this.values);
- } else
- return false;
- }
-
-}
+/*
+ * 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 gov.nasa.jpl.oodt.cas.commons.option;
+
+//JDK imports
+import java.util.LinkedList;
+import java.util.List;
+
+/**
+ *
+ * @author bfoster
+ * @version $Revision$
+ *
+ * <p>Describe your class here</p>.
+ */
+public class CmdLineOptionInstance {
+
+ private CmdLineOption option;
+ private List<String> values;
+
+ public CmdLineOptionInstance() {
+ this.option = null;
+ this.values = new LinkedList<String>();
+ }
+
+ public CmdLineOptionInstance(CmdLineOption option, List<String> values) {
+ this.option = option;
+ this.values = values;
+ }
+
+ public CmdLineOption getOption() {
+ return option;
+ }
+
+ public void setOption(CmdLineOption option) {
+ this.option = option;
+ }
+
+ public List<String> getValues() {
+ return values;
+ }
+
+ public void setValues(List<String> values) {
+ this.values = values;
+ }
+
+ public boolean equals(Object obj) {
+ if (obj instanceof CmdLineOptionInstance) {
+ CmdLineOptionInstance compareObj = (CmdLineOptionInstance) obj;
+ return compareObj.option.equals(this.option)
+ && compareObj.values.equals(this.values);
+ } else
+ return false;
+ }
+
+}
Modified: incubator/oodt/cas-commons/trunk/src/main/java/gov/nasa/jpl/oodt/cas/commons/option/handler/BeanInfo.java
URL: http://svn.apache.org/viewvc/incubator/oodt/cas-commons/trunk/src/main/java/gov/nasa/jpl/oodt/cas/commons/option/handler/BeanInfo.java?rev=917722&r1=917721&r2=917722&view=diff
==============================================================================
--- incubator/oodt/cas-commons/trunk/src/main/java/gov/nasa/jpl/oodt/cas/commons/option/handler/BeanInfo.java (original)
+++ incubator/oodt/cas-commons/trunk/src/main/java/gov/nasa/jpl/oodt/cas/commons/option/handler/BeanInfo.java Mon Mar 1 21:17:24 2010
@@ -1,39 +1,52 @@
-//Copyright (c) 2008, California Institute of Technology.
-//ALL RIGHTS RESERVED. U.S. Government sponsorship acknowledged.
-//
-//$Id$
-
-package gov.nasa.jpl.oodt.cas.commons.option.handler;
-
-/**
- *
- * @author bfoster
- * @version $Revision$
- *
- * <p>Wraps information about how to invoke a property value into a given bean</p>.
- */
-public class BeanInfo {
-
- private Object bean;
- private String methodName;
-
- public BeanInfo() {
- }
-
- public Object getBean() {
- return bean;
- }
-
- public void setBean(Object bean) {
- this.bean = bean;
- }
-
- public String getMethodName() {
- return methodName;
- }
-
- public void setMethodName(String methodName) {
- this.methodName = methodName;
- }
-
-}
+/*
+ * 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 gov.nasa.jpl.oodt.cas.commons.option.handler;
+
+/**
+ *
+ * @author bfoster
+ * @version $Revision$
+ *
+ * <p>Wraps information about how to invoke a property value into a given bean</p>.
+ */
+public class BeanInfo {
+
+ private Object bean;
+ private String methodName;
+
+ public BeanInfo() {
+ }
+
+ public Object getBean() {
+ return bean;
+ }
+
+ public void setBean(Object bean) {
+ this.bean = bean;
+ }
+
+ public String getMethodName() {
+ return methodName;
+ }
+
+ public void setMethodName(String methodName) {
+ this.methodName = methodName;
+ }
+
+}
Modified: incubator/oodt/cas-commons/trunk/src/main/java/gov/nasa/jpl/oodt/cas/commons/option/handler/CmdLineOptionBeanHandler.java
URL: http://svn.apache.org/viewvc/incubator/oodt/cas-commons/trunk/src/main/java/gov/nasa/jpl/oodt/cas/commons/option/handler/CmdLineOptionBeanHandler.java?rev=917722&r1=917721&r2=917722&view=diff
==============================================================================
--- incubator/oodt/cas-commons/trunk/src/main/java/gov/nasa/jpl/oodt/cas/commons/option/handler/CmdLineOptionBeanHandler.java (original)
+++ incubator/oodt/cas-commons/trunk/src/main/java/gov/nasa/jpl/oodt/cas/commons/option/handler/CmdLineOptionBeanHandler.java Mon Mar 1 21:17:24 2010
@@ -1,134 +1,147 @@
-//Copyright (c) 2008, California Institute of Technology.
-//ALL RIGHTS RESERVED. U.S. Government sponsorship acknowledged.
-//
-//$Id$
-
-package gov.nasa.jpl.oodt.cas.commons.option.handler;
-
-//JDK imports
-import java.io.File;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.util.Arrays;
-import java.util.HashSet;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Set;
-
-//OODT imports
-import gov.nasa.jpl.oodt.cas.commons.option.CmdLineOption;
-import gov.nasa.jpl.oodt.cas.commons.spring.SpringSetIdInjectionType;
-
-//Spring imports
-import org.apache.commons.lang.StringUtils;
-import org.springframework.beans.factory.annotation.Required;
-
-/**
- *
- * @author bfoster
- * @version $Revision$
- *
- * <p>Describe your class here</p>.
- */
-public class CmdLineOptionBeanHandler extends CmdLineOptionHandler {
-
- private List<BeanInfo> applyToBeans;
-
- @Required
- public void setApplyToBeans(List<BeanInfo> applyToBeans) {
- this.applyToBeans = applyToBeans;
- }
-
- public void handleOption(CmdLineOption option, List<String> values) {
- try {
- for (BeanInfo applyToBean : this.applyToBeans) {
- Class type = (option.getType() != null) ? option.getType()
- : String.class;
- Object[] vals = null;
- if (values.size() != 0) {
- vals = this.convertToType(values, type);
- } else {
- vals = this.convertToType(Arrays
- .asList(new String[] { "true" }), type = Boolean.TYPE);
- }
- try {
- if (applyToBean.getMethodName() != null) {
- applyToBean.getBean().getClass().getMethod(
- applyToBean.getMethodName(), type).invoke(
- applyToBean.getBean(), vals);
- } else {
- applyToBean.getBean().getClass().getMethod(
- "set" + StringUtils.capitalize(option.getId()),
- type).invoke(applyToBean.getBean(), vals);
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- public String getCustomOptionUsage(CmdLineOption option) {
- Set<String> affectedClasses = new HashSet<String>();
- for (BeanInfo beanInfo : applyToBeans) {
- if (beanInfo.getBean() instanceof SpringSetIdInjectionType)
- affectedClasses.add(((SpringSetIdInjectionType) beanInfo
- .getBean()).getId());
- else
- affectedClasses.add(beanInfo.getBean().getClass().getName());
- }
- return "Affects: " + affectedClasses.toString();
- }
-
- private Object[] convertToType(List<String> values, Class type)
- throws MalformedURLException, ClassNotFoundException {
- if (type.equals(File.class)) {
- List<Object> files = new LinkedList<Object>();
- for (String value : values)
- files.add(new File(value));
- return files.toArray(new Object[files.size()]);
- } else if (type.equals(Boolean.class) || type.equals(Boolean.TYPE)) {
- List<Object> booleans = new LinkedList<Object>();
- for (String value : values)
- booleans.add(value.toLowerCase().trim().equals("true"));
- return booleans.toArray(new Object[booleans.size()]);
- } else if (type.equals(URL.class)) {
- List<Object> urls = new LinkedList<Object>();
- for (String value : values)
- urls.add(new URL(value));
- return urls.toArray(new Object[urls.size()]);
- } else if (type.equals(Class.class)) {
- List<Object> classes = new LinkedList<Object>();
- for (String value : values)
- classes.add(Class.forName(value));
- return classes.toArray(new Object[classes.size()]);
- } else if (type.equals(List.class)) {
- return new Object[] { values };
- } else if (type.equals(Integer.class) || type.equals(Integer.TYPE)) {
- List<Object> ints = new LinkedList<Object>();
- for (String value : values)
- ints.add(new Integer(value));
- return ints.toArray(new Object[ints.size()]);
- } else if (type.equals(Long.class) || type.equals(Long.TYPE)) {
- List<Object> longs = new LinkedList<Object>();
- for (String value : values)
- longs.add(new Long(value));
- return longs.toArray(new Object[longs.size()]);
- } else if (type.equals(Double.class) || type.equals(Double.TYPE)) {
- List<Object> doubles = new LinkedList<Object>();
- for (String value : values)
- doubles.add(new Double(value));
- return doubles.toArray(new Object[doubles.size()]);
- } else if (type.equals(String.class)) {
- StringBuffer combinedString = new StringBuffer("");
- for (String value : values)
- combinedString.append(value + " ");
- return new String[] { combinedString.toString().trim() };
- } else {
- return values.toArray(new Object[values.size()]);
- }
- }
-
-}
+/*
+ * 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 gov.nasa.jpl.oodt.cas.commons.option.handler;
+
+//JDK imports
+import java.io.File;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Set;
+
+//OODT imports
+import gov.nasa.jpl.oodt.cas.commons.option.CmdLineOption;
+import gov.nasa.jpl.oodt.cas.commons.spring.SpringSetIdInjectionType;
+
+//Spring imports
+import org.apache.commons.lang.StringUtils;
+import org.springframework.beans.factory.annotation.Required;
+
+/**
+ *
+ * @author bfoster
+ * @version $Revision$
+ *
+ * <p>Describe your class here</p>.
+ */
+public class CmdLineOptionBeanHandler extends CmdLineOptionHandler {
+
+ private List<BeanInfo> applyToBeans;
+
+ @Required
+ public void setApplyToBeans(List<BeanInfo> applyToBeans) {
+ this.applyToBeans = applyToBeans;
+ }
+
+ public void handleOption(CmdLineOption option, List<String> values) {
+ try {
+ for (BeanInfo applyToBean : this.applyToBeans) {
+ Class type = (option.getType() != null) ? option.getType()
+ : String.class;
+ Object[] vals = null;
+ if (values.size() != 0) {
+ vals = this.convertToType(values, type);
+ } else {
+ vals = this.convertToType(Arrays
+ .asList(new String[] { "true" }), type = Boolean.TYPE);
+ }
+ try {
+ if (applyToBean.getMethodName() != null) {
+ applyToBean.getBean().getClass().getMethod(
+ applyToBean.getMethodName(), type).invoke(
+ applyToBean.getBean(), vals);
+ } else {
+ applyToBean.getBean().getClass().getMethod(
+ "set" + StringUtils.capitalize(option.getId()),
+ type).invoke(applyToBean.getBean(), vals);
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ public String getCustomOptionUsage(CmdLineOption option) {
+ Set<String> affectedClasses = new HashSet<String>();
+ for (BeanInfo beanInfo : applyToBeans) {
+ if (beanInfo.getBean() instanceof SpringSetIdInjectionType)
+ affectedClasses.add(((SpringSetIdInjectionType) beanInfo
+ .getBean()).getId());
+ else
+ affectedClasses.add(beanInfo.getBean().getClass().getName());
+ }
+ return "Affects: " + affectedClasses.toString();
+ }
+
+ private Object[] convertToType(List<String> values, Class type)
+ throws MalformedURLException, ClassNotFoundException {
+ if (type.equals(File.class)) {
+ List<Object> files = new LinkedList<Object>();
+ for (String value : values)
+ files.add(new File(value));
+ return files.toArray(new Object[files.size()]);
+ } else if (type.equals(Boolean.class) || type.equals(Boolean.TYPE)) {
+ List<Object> booleans = new LinkedList<Object>();
+ for (String value : values)
+ booleans.add(value.toLowerCase().trim().equals("true"));
+ return booleans.toArray(new Object[booleans.size()]);
+ } else if (type.equals(URL.class)) {
+ List<Object> urls = new LinkedList<Object>();
+ for (String value : values)
+ urls.add(new URL(value));
+ return urls.toArray(new Object[urls.size()]);
+ } else if (type.equals(Class.class)) {
+ List<Object> classes = new LinkedList<Object>();
+ for (String value : values)
+ classes.add(Class.forName(value));
+ return classes.toArray(new Object[classes.size()]);
+ } else if (type.equals(List.class)) {
+ return new Object[] { values };
+ } else if (type.equals(Integer.class) || type.equals(Integer.TYPE)) {
+ List<Object> ints = new LinkedList<Object>();
+ for (String value : values)
+ ints.add(new Integer(value));
+ return ints.toArray(new Object[ints.size()]);
+ } else if (type.equals(Long.class) || type.equals(Long.TYPE)) {
+ List<Object> longs = new LinkedList<Object>();
+ for (String value : values)
+ longs.add(new Long(value));
+ return longs.toArray(new Object[longs.size()]);
+ } else if (type.equals(Double.class) || type.equals(Double.TYPE)) {
+ List<Object> doubles = new LinkedList<Object>();
+ for (String value : values)
+ doubles.add(new Double(value));
+ return doubles.toArray(new Object[doubles.size()]);
+ } else if (type.equals(String.class)) {
+ StringBuffer combinedString = new StringBuffer("");
+ for (String value : values)
+ combinedString.append(value + " ");
+ return new String[] { combinedString.toString().trim() };
+ } else {
+ return values.toArray(new Object[values.size()]);
+ }
+ }
+
+}
Modified: incubator/oodt/cas-commons/trunk/src/main/java/gov/nasa/jpl/oodt/cas/commons/option/handler/CmdLineOptionHandler.java
URL: http://svn.apache.org/viewvc/incubator/oodt/cas-commons/trunk/src/main/java/gov/nasa/jpl/oodt/cas/commons/option/handler/CmdLineOptionHandler.java?rev=917722&r1=917721&r2=917722&view=diff
==============================================================================
--- incubator/oodt/cas-commons/trunk/src/main/java/gov/nasa/jpl/oodt/cas/commons/option/handler/CmdLineOptionHandler.java (original)
+++ incubator/oodt/cas-commons/trunk/src/main/java/gov/nasa/jpl/oodt/cas/commons/option/handler/CmdLineOptionHandler.java Mon Mar 1 21:17:24 2010
@@ -1,44 +1,57 @@
-//Copyright (c) 2008, California Institute of Technology.
-//ALL RIGHTS RESERVED. U.S. Government sponsorship acknowledged.
-//
-//$Id$
-
-package gov.nasa.jpl.oodt.cas.commons.option.handler;
-
-//JDK imports
-import java.util.List;
-
-//OODT imports
-import gov.nasa.jpl.oodt.cas.commons.option.CmdLineOption;
-
-//Spring imports
-import org.apache.commons.lang.StringUtils;
-
-/**
- *
- * @author bfoster
- * @version $Revision$
- *
- * <p>Describe your class here</p>.
- */
-public abstract class CmdLineOptionHandler {
-
- public String getOptionUsage(CmdLineOption option) {
- String argName = option.hasArgs() ? " <" + option.getOptionArgName()
- + ">" : "";
- String outputString = " -"
- + StringUtils.rightPad(option.getShortOption() + ",", 7) + "--"
- + StringUtils.rightPad((option.getLongOption() + argName), 49)
- + option.getDescription();
- if (!option.isRequired())
- outputString = "[" + outputString.substring(1) + "]";
- else if (option.getRequiredOptions().size() > 0)
- outputString = "{" + outputString.substring(1) + "}";
- return outputString;
- }
-
- public abstract void handleOption(CmdLineOption option, List<String> values);
-
- public abstract String getCustomOptionUsage(CmdLineOption option);
-
-}
+/*
+ * 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 gov.nasa.jpl.oodt.cas.commons.option.handler;
+
+//JDK imports
+import java.util.List;
+
+//OODT imports
+import gov.nasa.jpl.oodt.cas.commons.option.CmdLineOption;
+
+//Spring imports
+import org.apache.commons.lang.StringUtils;
+
+/**
+ *
+ * @author bfoster
+ * @version $Revision$
+ *
+ * <p>Describe your class here</p>.
+ */
+public abstract class CmdLineOptionHandler {
+
+ public String getOptionUsage(CmdLineOption option) {
+ String argName = option.hasArgs() ? " <" + option.getOptionArgName()
+ + ">" : "";
+ String outputString = " -"
+ + StringUtils.rightPad(option.getShortOption() + ",", 7) + "--"
+ + StringUtils.rightPad((option.getLongOption() + argName), 49)
+ + option.getDescription();
+ if (!option.isRequired())
+ outputString = "[" + outputString.substring(1) + "]";
+ else if (option.getRequiredOptions().size() > 0)
+ outputString = "{" + outputString.substring(1) + "}";
+ return outputString;
+ }
+
+ public abstract void handleOption(CmdLineOption option, List<String> values);
+
+ public abstract String getCustomOptionUsage(CmdLineOption option);
+
+}
Modified: incubator/oodt/cas-commons/trunk/src/main/java/gov/nasa/jpl/oodt/cas/commons/option/handler/StdCmdLineOptionHandler.java
URL: http://svn.apache.org/viewvc/incubator/oodt/cas-commons/trunk/src/main/java/gov/nasa/jpl/oodt/cas/commons/option/handler/StdCmdLineOptionHandler.java?rev=917722&r1=917721&r2=917722&view=diff
==============================================================================
--- incubator/oodt/cas-commons/trunk/src/main/java/gov/nasa/jpl/oodt/cas/commons/option/handler/StdCmdLineOptionHandler.java (original)
+++ incubator/oodt/cas-commons/trunk/src/main/java/gov/nasa/jpl/oodt/cas/commons/option/handler/StdCmdLineOptionHandler.java Mon Mar 1 21:17:24 2010
@@ -1,32 +1,45 @@
-//Copyright (c) 2008, California Institute of Technology.
-//ALL RIGHTS RESERVED. U.S. Government sponsorship acknowledged.
-//
-//$Id$
-
-package gov.nasa.jpl.oodt.cas.commons.option.handler;
-
-//JDK imports
-import java.util.List;
-
-import gov.nasa.jpl.oodt.cas.commons.option.CmdLineOption;
-
-/**
- *
- * @author bfoster
- * @version $Revision$
- *
- * <p>Describe your class here</p>.
- */
-public class StdCmdLineOptionHandler extends CmdLineOptionHandler {
-
- @Override
- public String getCustomOptionUsage(CmdLineOption option) {
- return "";
- }
-
- @Override
- public void handleOption(CmdLineOption option, List<String> values) {
- // do nothing
- }
-
-}
+/*
+ * 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 gov.nasa.jpl.oodt.cas.commons.option.handler;
+
+//JDK imports
+import java.util.List;
+
+import gov.nasa.jpl.oodt.cas.commons.option.CmdLineOption;
+
+/**
+ *
+ * @author bfoster
+ * @version $Revision$
+ *
+ * <p>Describe your class here</p>.
+ */
+public class StdCmdLineOptionHandler extends CmdLineOptionHandler {
+
+ @Override
+ public String getCustomOptionUsage(CmdLineOption option) {
+ return "";
+ }
+
+ @Override
+ public void handleOption(CmdLineOption option, List<String> values) {
+ // do nothing
+ }
+
+}
Modified: incubator/oodt/cas-commons/trunk/src/main/java/gov/nasa/jpl/oodt/cas/commons/option/parser/CmdLineOptionParser.java
URL: http://svn.apache.org/viewvc/incubator/oodt/cas-commons/trunk/src/main/java/gov/nasa/jpl/oodt/cas/commons/option/parser/CmdLineOptionParser.java?rev=917722&r1=917721&r2=917722&view=diff
==============================================================================
--- incubator/oodt/cas-commons/trunk/src/main/java/gov/nasa/jpl/oodt/cas/commons/option/parser/CmdLineOptionParser.java (original)
+++ incubator/oodt/cas-commons/trunk/src/main/java/gov/nasa/jpl/oodt/cas/commons/option/parser/CmdLineOptionParser.java Mon Mar 1 21:17:24 2010
@@ -1,96 +1,109 @@
-//Copyright (c) 2008, California Institute of Technology.
-//ALL RIGHTS RESERVED. U.S. Government sponsorship acknowledged.
-//
-//$Id$
-
-package gov.nasa.jpl.oodt.cas.commons.option.parser;
-
-//JDK imports
-import java.io.IOException;
-import java.io.PrintStream;
-import java.util.LinkedList;
-import java.util.List;
-
-//OODT imports
-import gov.nasa.jpl.oodt.cas.commons.option.CmdLineOption;
-import gov.nasa.jpl.oodt.cas.commons.option.CmdLineOptionInstance;
-import gov.nasa.jpl.oodt.cas.commons.option.util.CmdLineOptionUtils;
-import gov.nasa.jpl.oodt.cas.commons.option.util.CmdLineOptionsUsagePrinter;
-
-/**
- *
- * @author bfoster
- * @version $Revision$
- *
- * <p>Describe your class here</p>.
- */
-public class CmdLineOptionParser {
-
- private List<CmdLineOption> validOptions;
-
- public List<CmdLineOption> getValidOptions() {
- return validOptions;
- }
-
- public void setValidOptions(List<CmdLineOption> validOptions) {
- this.validOptions = validOptions;
- }
-
- public List<CmdLineOptionInstance> parse(String[] args) throws IOException {
- List<CmdLineOptionInstance> optionInstances = new LinkedList<CmdLineOptionInstance>();
- if (args.length < 1)
- throw new IOException(
- "Must specify options : type -h or --help for info");
-
- for (int j = 0; j < args.length; j++) {
- String curArg = args[j];
-
- // print usage and quit if -h or --help is given
- if (curArg.equals("-h") || curArg.equals("--help")) {
- CmdLineOptionsUsagePrinter.printUsage(new PrintStream(
- System.out), this.validOptions);
- System.exit(0);
- }
-
- if (curArg.startsWith("-")) {
- // check if long or short version was used
- if (curArg.startsWith("--"))
- curArg = curArg.substring(2);
- else
- curArg = curArg.substring(1);
-
- // check if option is a valid one
- CmdLineOption curOption = CmdLineOptionUtils.getOptionByName(
- curArg, validOptions);
- if (curOption == null)
- throw new IOException("Invalid option '" + curArg + "'");
-
- // check if option has arguments
- List<String> values = new LinkedList<String>();
- if (curOption.hasArgs()) {
- while (j + 1 < args.length && !args[j + 1].startsWith("-"))
- values.add(args[++j]);
- if (values.size() < 1)
- throw new IOException("Option " + curArg
- + " should have at least one argument");
- }
-
- //check if is a perform and quit option
- if (curOption.isPerformAndQuit()) {
- curOption.getHandler().handleOption(curOption, values);
- System.exit(0);
- }
-
- // add to list of option instances
- optionInstances
- .add(new CmdLineOptionInstance(curOption, values));
-
- } else {
- throw new IOException("Argument with no option flag '" + curArg
- + "'");
- }
- }
- return optionInstances;
- }
-
-}
+/*
+ * 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 gov.nasa.jpl.oodt.cas.commons.option.parser;
+
+//JDK imports
+import java.io.IOException;
+import java.io.PrintStream;
+import java.util.LinkedList;
+import java.util.List;
+
+//OODT imports
+import gov.nasa.jpl.oodt.cas.commons.option.CmdLineOption;
+import gov.nasa.jpl.oodt.cas.commons.option.CmdLineOptionInstance;
+import gov.nasa.jpl.oodt.cas.commons.option.util.CmdLineOptionUtils;
+import gov.nasa.jpl.oodt.cas.commons.option.util.CmdLineOptionsUsagePrinter;
+
+/**
+ *
+ * @author bfoster
+ * @version $Revision$
+ *
+ * <p>Describe your class here</p>.
+ */
+public class CmdLineOptionParser {
+
+ private List<CmdLineOption> validOptions;
+
+ public List<CmdLineOption> getValidOptions() {
+ return validOptions;
+ }
+
+ public void setValidOptions(List<CmdLineOption> validOptions) {
+ this.validOptions = validOptions;
+ }
+
+ public List<CmdLineOptionInstance> parse(String[] args) throws IOException {
+ List<CmdLineOptionInstance> optionInstances = new LinkedList<CmdLineOptionInstance>();
+ if (args.length < 1)
+ throw new IOException(
+ "Must specify options : type -h or --help for info");
+
+ for (int j = 0; j < args.length; j++) {
+ String curArg = args[j];
+
+ // print usage and quit if -h or --help is given
+ if (curArg.equals("-h") || curArg.equals("--help")) {
+ CmdLineOptionsUsagePrinter.printUsage(new PrintStream(
+ System.out), this.validOptions);
+ System.exit(0);
+ }
+
+ if (curArg.startsWith("-")) {
+ // check if long or short version was used
+ if (curArg.startsWith("--"))
+ curArg = curArg.substring(2);
+ else
+ curArg = curArg.substring(1);
+
+ // check if option is a valid one
+ CmdLineOption curOption = CmdLineOptionUtils.getOptionByName(
+ curArg, validOptions);
+ if (curOption == null)
+ throw new IOException("Invalid option '" + curArg + "'");
+
+ // check if option has arguments
+ List<String> values = new LinkedList<String>();
+ if (curOption.hasArgs()) {
+ while (j + 1 < args.length && !args[j + 1].startsWith("-"))
+ values.add(args[++j]);
+ if (values.size() < 1)
+ throw new IOException("Option " + curArg
+ + " should have at least one argument");
+ }
+
+ //check if is a perform and quit option
+ if (curOption.isPerformAndQuit()) {
+ curOption.getHandler().handleOption(curOption, values);
+ System.exit(0);
+ }
+
+ // add to list of option instances
+ optionInstances
+ .add(new CmdLineOptionInstance(curOption, values));
+
+ } else {
+ throw new IOException("Argument with no option flag '" + curArg
+ + "'");
+ }
+ }
+ return optionInstances;
+ }
+
+}
Modified: incubator/oodt/cas-commons/trunk/src/main/java/gov/nasa/jpl/oodt/cas/commons/option/required/RequiredOption.java
URL: http://svn.apache.org/viewvc/incubator/oodt/cas-commons/trunk/src/main/java/gov/nasa/jpl/oodt/cas/commons/option/required/RequiredOption.java?rev=917722&r1=917721&r2=917722&view=diff
==============================================================================
--- incubator/oodt/cas-commons/trunk/src/main/java/gov/nasa/jpl/oodt/cas/commons/option/required/RequiredOption.java (original)
+++ incubator/oodt/cas-commons/trunk/src/main/java/gov/nasa/jpl/oodt/cas/commons/option/required/RequiredOption.java Mon Mar 1 21:17:24 2010
@@ -1,60 +1,73 @@
-//Copyright (c) 2008, California Institute of Technology.
-//ALL RIGHTS RESERVED. U.S. Government sponsorship acknowledged.
-//
-//$Id$
-
-package gov.nasa.jpl.oodt.cas.commons.option.required;
-
-//OODT imports
-import java.util.LinkedList;
-import java.util.List;
-
-/**
- *
- * @author bfoster
- * @version $Revision$
- *
- * <p>Describe your class here</p>.
- */
-public class RequiredOption {
-
- private List<String> optionValues;
- private String optionLongName;
- private boolean requireAllValues;
-
- public RequiredOption() {
- this.optionValues = new LinkedList<String>();
- this.requireAllValues = false;
- }
-
- public List<String> getOptionValues() {
- return optionValues;
- }
-
- public void setOptionValues(List<String> optionValues) {
- this.optionValues = optionValues;
- }
-
- public boolean isRequireAllValues() {
- return requireAllValues;
- }
-
- public void setRequireAllValues(boolean requireAllValues) {
- this.requireAllValues = requireAllValues;
- }
-
- public String getOptionLongName() {
- return optionLongName;
- }
-
- public void setOptionLongName(String optionLongName) {
- this.optionLongName = optionLongName;
- }
-
- public String toString() {
- return (this.requireAllValues ? "All" : "At least one")
- + " of the following values must be specified for option --"
- + this.optionLongName + " " + this.optionValues;
- }
-
-}
+/*
+ * 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 gov.nasa.jpl.oodt.cas.commons.option.required;
+
+//OODT imports
+import java.util.LinkedList;
+import java.util.List;
+
+/**
+ *
+ * @author bfoster
+ * @version $Revision$
+ *
+ * <p>Describe your class here</p>.
+ */
+public class RequiredOption {
+
+ private List<String> optionValues;
+ private String optionLongName;
+ private boolean requireAllValues;
+
+ public RequiredOption() {
+ this.optionValues = new LinkedList<String>();
+ this.requireAllValues = false;
+ }
+
+ public List<String> getOptionValues() {
+ return optionValues;
+ }
+
+ public void setOptionValues(List<String> optionValues) {
+ this.optionValues = optionValues;
+ }
+
+ public boolean isRequireAllValues() {
+ return requireAllValues;
+ }
+
+ public void setRequireAllValues(boolean requireAllValues) {
+ this.requireAllValues = requireAllValues;
+ }
+
+ public String getOptionLongName() {
+ return optionLongName;
+ }
+
+ public void setOptionLongName(String optionLongName) {
+ this.optionLongName = optionLongName;
+ }
+
+ public String toString() {
+ return (this.requireAllValues ? "All" : "At least one")
+ + " of the following values must be specified for option --"
+ + this.optionLongName + " " + this.optionValues;
+ }
+
+}
Modified: incubator/oodt/cas-commons/trunk/src/main/java/gov/nasa/jpl/oodt/cas/commons/option/util/CmdLineOptionUtils.java
URL: http://svn.apache.org/viewvc/incubator/oodt/cas-commons/trunk/src/main/java/gov/nasa/jpl/oodt/cas/commons/option/util/CmdLineOptionUtils.java?rev=917722&r1=917721&r2=917722&view=diff
==============================================================================
--- incubator/oodt/cas-commons/trunk/src/main/java/gov/nasa/jpl/oodt/cas/commons/option/util/CmdLineOptionUtils.java (original)
+++ incubator/oodt/cas-commons/trunk/src/main/java/gov/nasa/jpl/oodt/cas/commons/option/util/CmdLineOptionUtils.java Mon Mar 1 21:17:24 2010
@@ -1,155 +1,168 @@
-//Copyright (c) 2008, California Institute of Technology.
-//ALL RIGHTS RESERVED. U.S. Government sponsorship acknowledged.
-//
-//$Id$
-
-package gov.nasa.jpl.oodt.cas.commons.option.util;
-
-//JDK imports
-import java.io.IOException;
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-
-//OODT imports
-import gov.nasa.jpl.oodt.cas.commons.option.CmdLineOption;
-import gov.nasa.jpl.oodt.cas.commons.option.CmdLineOptionInstance;
-import gov.nasa.jpl.oodt.cas.commons.option.parser.CmdLineOptionParser;
-import gov.nasa.jpl.oodt.cas.commons.option.required.RequiredOption;
-import gov.nasa.jpl.oodt.cas.commons.option.validator.CmdLineOptionValidator;
-
-//Spring imports
-import org.springframework.context.ApplicationContext;
-
-/**
- *
- * @author bfoster
- * @version $Revision$
- *
- * <p>Describe your class here</p>.
- */
-public class CmdLineOptionUtils {
-
- private CmdLineOptionUtils() {
- }
-
- public static CmdLineOption getOptionByName(String optionName,
- List<CmdLineOption> options) {
- for (CmdLineOption option : options)
- if (option.getLongOption().equals(optionName)
- || option.getShortOption().equals(optionName))
- return option;
- return null;
- }
-
- public static CmdLineOptionInstance getOptionInstanceByName(
- String optionName, List<CmdLineOptionInstance> optionInsts) {
- for (CmdLineOptionInstance optionInst : optionInsts)
- if (optionInst.getOption().getLongOption().equals(optionName)
- || optionInst.getOption().getShortOption().equals(
- optionName))
- return optionInst;
- return null;
- }
-
- public static List<String> getOptionValues(String optionName,
- List<CmdLineOptionInstance> options) {
- for (CmdLineOptionInstance optionInst : options)
- if (optionInst.getOption().getLongOption().equals(optionName)
- || optionInst.getOption().getShortOption().equals(
- optionName))
- return optionInst.getValues();
- return null;
- }
-
- public static List<CmdLineOption> getOptions(ApplicationContext appContext) {
- List<CmdLineOption> options = new LinkedList<CmdLineOption>();
- Map optionsMap = appContext.getBeansOfType(CmdLineOption.class);
- for (Iterator<Entry> iter = optionsMap.entrySet().iterator(); iter
- .hasNext();)
- options.add((CmdLineOption) iter.next().getValue());
- return options;
- }
-
- public static List<CmdLineOptionInstance> loadValidateAndHandleInstances(
- ApplicationContext appContext, String[] args) throws IOException {
-
- // parse args
- CmdLineOptionParser parser = new CmdLineOptionParser();
- List<CmdLineOption> supportedOptions = CmdLineOptionUtils
- .getOptions(appContext);
- parser.setValidOptions(supportedOptions);
- List<CmdLineOptionInstance> optionInstances = parser.parse(args);
-
- // check that required args have been specified
- List<CmdLineOption> reqOptions = CmdLineOptionUtils
- .getRequiredOptions(supportedOptions);
- List<CmdLineOption> unsetReqOptions = CmdLineOptionUtils
- .getRequiredOptionsNotSet(optionInstances, reqOptions);
- for (CmdLineOption unsetReqOption : unsetReqOptions) {
- if (unsetReqOption.getRequiredOptions().size() > 0) {
- for (RequiredOption reqOption : unsetReqOption
- .getRequiredOptions()) {
- CmdLineOptionInstance optionInst = getOptionInstanceByName(
- reqOption.getOptionLongName(), optionInstances);
- if (optionInst != null
- && ((reqOption.isRequireAllValues() && optionInst
- .getValues().containsAll(
- reqOption.getOptionValues())) || (!reqOption
- .isRequireAllValues() && !Collections
- .disjoint(optionInst.getValues(), reqOption
- .getOptionValues()))))
- throw new IOException("Option "
- + unsetReqOption.getId() + " is required");
- }
- } else
- throw new IOException("Option " + unsetReqOption.getId()
- + " is required");
- }
-
- // validate options
- for (CmdLineOptionInstance optionInst : optionInstances) {
- for (CmdLineOptionValidator validator : optionInst.getOption()
- .getValidators())
- if (!validator.validate(optionInst))
- throw new IOException("Option "
- + optionInst.getOption().getId()
- + " failed validation");
- }
-
- // if all looks good . . . handle options
- for (CmdLineOptionInstance optionInst : optionInstances)
- optionInst.getOption().getHandler().handleOption(
- optionInst.getOption(), optionInst.getValues());
-
- return optionInstances;
- }
-
- public static List<CmdLineOption> getRequiredOptionsNotSet(
- List<CmdLineOptionInstance> optionInsts,
- List<CmdLineOption> reqOptions) {
- List<CmdLineOption> nonSetRequiredOptions = new LinkedList<CmdLineOption>();
- TOP: for (CmdLineOption reqOption : reqOptions) {
- for (CmdLineOptionInstance optionInst : optionInsts) {
- if (reqOption.equals(optionInst.getOption()))
- continue TOP;
- }
- nonSetRequiredOptions.add(reqOption);
- }
- return nonSetRequiredOptions;
- }
-
- public static List<CmdLineOption> getRequiredOptions(
- List<CmdLineOption> options) {
- List<CmdLineOption> requiredOptions = new LinkedList<CmdLineOption>();
- for (CmdLineOption option : options) {
- if (option.isRequired())
- requiredOptions.add(option);
- }
- return requiredOptions;
- }
-
-}
+/*
+ * 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 gov.nasa.jpl.oodt.cas.commons.option.util;
+
+//JDK imports
+import java.io.IOException;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+
+//OODT imports
+import gov.nasa.jpl.oodt.cas.commons.option.CmdLineOption;
+import gov.nasa.jpl.oodt.cas.commons.option.CmdLineOptionInstance;
+import gov.nasa.jpl.oodt.cas.commons.option.parser.CmdLineOptionParser;
+import gov.nasa.jpl.oodt.cas.commons.option.required.RequiredOption;
+import gov.nasa.jpl.oodt.cas.commons.option.validator.CmdLineOptionValidator;
+
+//Spring imports
+import org.springframework.context.ApplicationContext;
+
+/**
+ *
+ * @author bfoster
+ * @version $Revision$
+ *
+ * <p>Describe your class here</p>.
+ */
+public class CmdLineOptionUtils {
+
+ private CmdLineOptionUtils() {
+ }
+
+ public static CmdLineOption getOptionByName(String optionName,
+ List<CmdLineOption> options) {
+ for (CmdLineOption option : options)
+ if (option.getLongOption().equals(optionName)
+ || option.getShortOption().equals(optionName))
+ return option;
+ return null;
+ }
+
+ public static CmdLineOptionInstance getOptionInstanceByName(
+ String optionName, List<CmdLineOptionInstance> optionInsts) {
+ for (CmdLineOptionInstance optionInst : optionInsts)
+ if (optionInst.getOption().getLongOption().equals(optionName)
+ || optionInst.getOption().getShortOption().equals(
+ optionName))
+ return optionInst;
+ return null;
+ }
+
+ public static List<String> getOptionValues(String optionName,
+ List<CmdLineOptionInstance> options) {
+ for (CmdLineOptionInstance optionInst : options)
+ if (optionInst.getOption().getLongOption().equals(optionName)
+ || optionInst.getOption().getShortOption().equals(
+ optionName))
+ return optionInst.getValues();
+ return null;
+ }
+
+ public static List<CmdLineOption> getOptions(ApplicationContext appContext) {
+ List<CmdLineOption> options = new LinkedList<CmdLineOption>();
+ Map optionsMap = appContext.getBeansOfType(CmdLineOption.class);
+ for (Iterator<Entry> iter = optionsMap.entrySet().iterator(); iter
+ .hasNext();)
+ options.add((CmdLineOption) iter.next().getValue());
+ return options;
+ }
+
+ public static List<CmdLineOptionInstance> loadValidateAndHandleInstances(
+ ApplicationContext appContext, String[] args) throws IOException {
+
+ // parse args
+ CmdLineOptionParser parser = new CmdLineOptionParser();
+ List<CmdLineOption> supportedOptions = CmdLineOptionUtils
+ .getOptions(appContext);
+ parser.setValidOptions(supportedOptions);
+ List<CmdLineOptionInstance> optionInstances = parser.parse(args);
+
+ // check that required args have been specified
+ List<CmdLineOption> reqOptions = CmdLineOptionUtils
+ .getRequiredOptions(supportedOptions);
+ List<CmdLineOption> unsetReqOptions = CmdLineOptionUtils
+ .getRequiredOptionsNotSet(optionInstances, reqOptions);
+ for (CmdLineOption unsetReqOption : unsetReqOptions) {
+ if (unsetReqOption.getRequiredOptions().size() > 0) {
+ for (RequiredOption reqOption : unsetReqOption
+ .getRequiredOptions()) {
+ CmdLineOptionInstance optionInst = getOptionInstanceByName(
+ reqOption.getOptionLongName(), optionInstances);
+ if (optionInst != null
+ && ((reqOption.isRequireAllValues() && optionInst
+ .getValues().containsAll(
+ reqOption.getOptionValues())) || (!reqOption
+ .isRequireAllValues() && !Collections
+ .disjoint(optionInst.getValues(), reqOption
+ .getOptionValues()))))
+ throw new IOException("Option "
+ + unsetReqOption.getId() + " is required");
+ }
+ } else
+ throw new IOException("Option " + unsetReqOption.getId()
+ + " is required");
+ }
+
+ // validate options
+ for (CmdLineOptionInstance optionInst : optionInstances) {
+ for (CmdLineOptionValidator validator : optionInst.getOption()
+ .getValidators())
+ if (!validator.validate(optionInst))
+ throw new IOException("Option "
+ + optionInst.getOption().getId()
+ + " failed validation");
+ }
+
+ // if all looks good . . . handle options
+ for (CmdLineOptionInstance optionInst : optionInstances)
+ optionInst.getOption().getHandler().handleOption(
+ optionInst.getOption(), optionInst.getValues());
+
+ return optionInstances;
+ }
+
+ public static List<CmdLineOption> getRequiredOptionsNotSet(
+ List<CmdLineOptionInstance> optionInsts,
+ List<CmdLineOption> reqOptions) {
+ List<CmdLineOption> nonSetRequiredOptions = new LinkedList<CmdLineOption>();
+ TOP: for (CmdLineOption reqOption : reqOptions) {
+ for (CmdLineOptionInstance optionInst : optionInsts) {
+ if (reqOption.equals(optionInst.getOption()))
+ continue TOP;
+ }
+ nonSetRequiredOptions.add(reqOption);
+ }
+ return nonSetRequiredOptions;
+ }
+
+ public static List<CmdLineOption> getRequiredOptions(
+ List<CmdLineOption> options) {
+ List<CmdLineOption> requiredOptions = new LinkedList<CmdLineOption>();
+ for (CmdLineOption option : options) {
+ if (option.isRequired())
+ requiredOptions.add(option);
+ }
+ return requiredOptions;
+ }
+
+}
Modified: incubator/oodt/cas-commons/trunk/src/main/java/gov/nasa/jpl/oodt/cas/commons/option/util/CmdLineOptionsUsagePrinter.java
URL: http://svn.apache.org/viewvc/incubator/oodt/cas-commons/trunk/src/main/java/gov/nasa/jpl/oodt/cas/commons/option/util/CmdLineOptionsUsagePrinter.java?rev=917722&r1=917721&r2=917722&view=diff
==============================================================================
--- incubator/oodt/cas-commons/trunk/src/main/java/gov/nasa/jpl/oodt/cas/commons/option/util/CmdLineOptionsUsagePrinter.java (original)
+++ incubator/oodt/cas-commons/trunk/src/main/java/gov/nasa/jpl/oodt/cas/commons/option/util/CmdLineOptionsUsagePrinter.java Mon Mar 1 21:17:24 2010
@@ -1,82 +1,95 @@
-//Copyright (c) 2008, California Institute of Technology.
-//ALL RIGHTS RESERVED. U.S. Government sponsorship acknowledged.
-//
-//$Id$
-
-package gov.nasa.jpl.oodt.cas.commons.option.util;
-
-//JDK imports
-import java.io.PrintStream;
-import java.util.Collections;
-import java.util.List;
-
-//OODT imports
-import gov.nasa.jpl.oodt.cas.commons.option.CmdLineOption;
-
-//Spring imports
-import org.apache.commons.lang.StringUtils;
-
-/**
- *
- * @author bfoster
- * @version $Revision$
- *
- * <p>Describe your class here</p>.
- */
-public class CmdLineOptionsUsagePrinter {
-
- private CmdLineOptionsUsagePrinter() {
- }
-
- public static void printUsage(PrintStream ps, List<CmdLineOption> options) {
- ps.println(createPrintableHeader(options));
- }
-
- private static String createPrintableHeader(List<CmdLineOption> options) {
- sortOptions(options);
- StringBuffer outputString = new StringBuffer(
- "-----------------------------------------------------------------------------------------------------------------\n");
- outputString.append("|" + StringUtils.rightPad(" Short", 7) + "|"
- + StringUtils.rightPad(" Long", 50) + "| Description\n");
- outputString
- .append("-----------------------------------------------------------------------------------------------------------------\n");
- for (CmdLineOption option : options) {
- outputString.append(option.getHandler().getOptionUsage(option)
- + "\n"
- + getFormattedString(option.getHandler()
- .getCustomOptionUsage(option), 62, 139));
- if (option.getRequiredOptions().size() > 0)
- outputString.append(getFormattedString("RequiredOptions: "
- + option.getRequiredOptions() + "\n", 62, 139));
- else
- outputString.append("\n");
- }
- outputString
- .append("-----------------------------------------------------------------------------------------------------------------");
- return outputString.toString();
- }
-
- private static void sortOptions(List<CmdLineOption> options) {
- Collections.sort(options);
- }
-
- private static String getFormattedString(String string, int startIndex,
- int endIndex) {
- StringBuffer outputString = new StringBuffer("");
- String[] splitStrings = StringUtils.split(string, " ");
- StringBuffer curLine = null;
- for (int i = 0; i < splitStrings.length; i++) {
- curLine = new StringBuffer("");
- curLine.append(splitStrings[i] + " ");
-
- for (; i + 1 < splitStrings.length
- && curLine.length() + splitStrings[i + 1].length() <= (endIndex - startIndex); i++)
- curLine.append(splitStrings[i + 1] + " ");
-
- outputString.append(StringUtils.repeat(" ", startIndex)
- + curLine.toString() + "\n");
- }
- return outputString.toString();
- }
-
-}
+/*
+ * 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 gov.nasa.jpl.oodt.cas.commons.option.util;
+
+//JDK imports
+import java.io.PrintStream;
+import java.util.Collections;
+import java.util.List;
+
+//OODT imports
+import gov.nasa.jpl.oodt.cas.commons.option.CmdLineOption;
+
+//Spring imports
+import org.apache.commons.lang.StringUtils;
+
+/**
+ *
+ * @author bfoster
+ * @version $Revision$
+ *
+ * <p>Describe your class here</p>.
+ */
+public class CmdLineOptionsUsagePrinter {
+
+ private CmdLineOptionsUsagePrinter() {
+ }
+
+ public static void printUsage(PrintStream ps, List<CmdLineOption> options) {
+ ps.println(createPrintableHeader(options));
+ }
+
+ private static String createPrintableHeader(List<CmdLineOption> options) {
+ sortOptions(options);
+ StringBuffer outputString = new StringBuffer(
+ "-----------------------------------------------------------------------------------------------------------------\n");
+ outputString.append("|" + StringUtils.rightPad(" Short", 7) + "|"
+ + StringUtils.rightPad(" Long", 50) + "| Description\n");
+ outputString
+ .append("-----------------------------------------------------------------------------------------------------------------\n");
+ for (CmdLineOption option : options) {
+ outputString.append(option.getHandler().getOptionUsage(option)
+ + "\n"
+ + getFormattedString(option.getHandler()
+ .getCustomOptionUsage(option), 62, 139));
+ if (option.getRequiredOptions().size() > 0)
+ outputString.append(getFormattedString("RequiredOptions: "
+ + option.getRequiredOptions() + "\n", 62, 139));
+ else
+ outputString.append("\n");
+ }
+ outputString
+ .append("-----------------------------------------------------------------------------------------------------------------");
+ return outputString.toString();
+ }
+
+ private static void sortOptions(List<CmdLineOption> options) {
+ Collections.sort(options);
+ }
+
+ private static String getFormattedString(String string, int startIndex,
+ int endIndex) {
+ StringBuffer outputString = new StringBuffer("");
+ String[] splitStrings = StringUtils.split(string, " ");
+ StringBuffer curLine = null;
+ for (int i = 0; i < splitStrings.length; i++) {
+ curLine = new StringBuffer("");
+ curLine.append(splitStrings[i] + " ");
+
+ for (; i + 1 < splitStrings.length
+ && curLine.length() + splitStrings[i + 1].length() <= (endIndex - startIndex); i++)
+ curLine.append(splitStrings[i + 1] + " ");
+
+ outputString.append(StringUtils.repeat(" ", startIndex)
+ + curLine.toString() + "\n");
+ }
+ return outputString.toString();
+ }
+
+}
Modified: incubator/oodt/cas-commons/trunk/src/main/java/gov/nasa/jpl/oodt/cas/commons/option/validator/AllowedArgsCmdLineOptionValidator.java
URL: http://svn.apache.org/viewvc/incubator/oodt/cas-commons/trunk/src/main/java/gov/nasa/jpl/oodt/cas/commons/option/validator/AllowedArgsCmdLineOptionValidator.java?rev=917722&r1=917721&r2=917722&view=diff
==============================================================================
--- incubator/oodt/cas-commons/trunk/src/main/java/gov/nasa/jpl/oodt/cas/commons/option/validator/AllowedArgsCmdLineOptionValidator.java (original)
+++ incubator/oodt/cas-commons/trunk/src/main/java/gov/nasa/jpl/oodt/cas/commons/option/validator/AllowedArgsCmdLineOptionValidator.java Mon Mar 1 21:17:24 2010
@@ -1,57 +1,70 @@
-//Copyright (c) 2008, California Institute of Technology.
-//ALL RIGHTS RESERVED. U.S. Government sponsorship acknowledged.
-//
-//$Id$
-
-package gov.nasa.jpl.oodt.cas.commons.option.validator;
-
-//JDK imports
-import java.util.LinkedList;
-import java.util.List;
-import java.util.logging.Level;
-
-//OODT imports
-import gov.nasa.jpl.oodt.cas.commons.option.CmdLineOptionInstance;
-
-//Spring imports
-import org.springframework.beans.factory.annotation.Required;
-
-/**
- *
- * @author bfoster
- * @version $Revision$
- *
- * <p>Describe your class here</p>.
- */
-public class AllowedArgsCmdLineOptionValidator implements
- CmdLineOptionValidator {
-
- private List<String> allowedArgs;
-
- public AllowedArgsCmdLineOptionValidator() {
- this.allowedArgs = new LinkedList<String>();
- }
-
- public boolean validate(CmdLineOptionInstance optionInst) {
- for (String value : optionInst.getValues()) {
- if (!allowedArgs.contains(value)) {
- LOG.log(Level.SEVERE, "Option value " + value
- + " is not allowed for option "
- + optionInst.getOption().getId()
- + " - Allowed values = " + this.getAllowedArgs());
- return false;
- }
- }
- return true;
- }
-
- public List<String> getAllowedArgs() {
- return allowedArgs;
- }
-
- @Required
- public void setAllowedArgs(List<String> allowedArgs) {
- this.allowedArgs = allowedArgs;
- }
-
-}
+/*
+ * 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 gov.nasa.jpl.oodt.cas.commons.option.validator;
+
+//JDK imports
+import java.util.LinkedList;
+import java.util.List;
+import java.util.logging.Level;
+
+//OODT imports
+import gov.nasa.jpl.oodt.cas.commons.option.CmdLineOptionInstance;
+
+//Spring imports
+import org.springframework.beans.factory.annotation.Required;
+
+/**
+ *
+ * @author bfoster
+ * @version $Revision$
+ *
+ * <p>Describe your class here</p>.
+ */
+public class AllowedArgsCmdLineOptionValidator implements
+ CmdLineOptionValidator {
+
+ private List<String> allowedArgs;
+
+ public AllowedArgsCmdLineOptionValidator() {
+ this.allowedArgs = new LinkedList<String>();
+ }
+
+ public boolean validate(CmdLineOptionInstance optionInst) {
+ for (String value : optionInst.getValues()) {
+ if (!allowedArgs.contains(value)) {
+ LOG.log(Level.SEVERE, "Option value " + value
+ + " is not allowed for option "
+ + optionInst.getOption().getId()
+ + " - Allowed values = " + this.getAllowedArgs());
+ return false;
+ }
+ }
+ return true;
+ }
+
+ public List<String> getAllowedArgs() {
+ return allowedArgs;
+ }
+
+ @Required
+ public void setAllowedArgs(List<String> allowedArgs) {
+ this.allowedArgs = allowedArgs;
+ }
+
+}
Modified: incubator/oodt/cas-commons/trunk/src/main/java/gov/nasa/jpl/oodt/cas/commons/option/validator/ArgRegExpCmdLineOptionValidator.java
URL: http://svn.apache.org/viewvc/incubator/oodt/cas-commons/trunk/src/main/java/gov/nasa/jpl/oodt/cas/commons/option/validator/ArgRegExpCmdLineOptionValidator.java?rev=917722&r1=917721&r2=917722&view=diff
==============================================================================
--- incubator/oodt/cas-commons/trunk/src/main/java/gov/nasa/jpl/oodt/cas/commons/option/validator/ArgRegExpCmdLineOptionValidator.java (original)
+++ incubator/oodt/cas-commons/trunk/src/main/java/gov/nasa/jpl/oodt/cas/commons/option/validator/ArgRegExpCmdLineOptionValidator.java Mon Mar 1 21:17:24 2010
@@ -1,41 +1,54 @@
-//Copyright (c) 2008, California Institute of Technology.
-//ALL RIGHTS RESERVED. U.S. Government sponsorship acknowledged.
-//
-//$Id$
-
-package gov.nasa.jpl.oodt.cas.commons.option.validator;
-
-//JDK imports
-import java.util.logging.Level;
-import java.util.regex.Pattern;
-
-//OODT imports
-import gov.nasa.jpl.oodt.cas.commons.option.CmdLineOptionInstance;
-
-/**
- *
- * @author bfoster
- * @version $Revision$
- *
- * <p>Describe your class here</p>.
- */
-public class ArgRegExpCmdLineOptionValidator extends
- AllowedArgsCmdLineOptionValidator {
-
- @Override
- public boolean validate(CmdLineOptionInstance optionInst) {
- TOP: for (String value : optionInst.getValues()) {
- for (String regex : this.getAllowedArgs()) {
- if (Pattern.matches(regex, value))
- continue TOP;
- }
- LOG.log(Level.SEVERE, "Option value " + value
- + " is not allowed for option "
- + optionInst.getOption().getId() + " - Allowed values = "
- + this.getAllowedArgs());
- return false;
- }
- return true;
- }
-
-}
+/*
+ * 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 gov.nasa.jpl.oodt.cas.commons.option.validator;
+
+//JDK imports
+import java.util.logging.Level;
+import java.util.regex.Pattern;
+
+//OODT imports
+import gov.nasa.jpl.oodt.cas.commons.option.CmdLineOptionInstance;
+
+/**
+ *
+ * @author bfoster
+ * @version $Revision$
+ *
+ * <p>Describe your class here</p>.
+ */
+public class ArgRegExpCmdLineOptionValidator extends
+ AllowedArgsCmdLineOptionValidator {
+
+ @Override
+ public boolean validate(CmdLineOptionInstance optionInst) {
+ TOP: for (String value : optionInst.getValues()) {
+ for (String regex : this.getAllowedArgs()) {
+ if (Pattern.matches(regex, value))
+ continue TOP;
+ }
+ LOG.log(Level.SEVERE, "Option value " + value
+ + " is not allowed for option "
+ + optionInst.getOption().getId() + " - Allowed values = "
+ + this.getAllowedArgs());
+ return false;
+ }
+ return true;
+ }
+
+}