geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jdil...@apache.org
Subject svn commit: r570606 [2/5] - in /geronimo/sandbox/gshell/trunk: ./ gshell-api/ gshell-api/src/main/java/org/apache/geronimo/gshell/command/ gshell-api/src/main/java/org/apache/geronimo/gshell/console/ gshell-api/src/main/java/org/apache/geronimo/gshell/...
Date Wed, 29 Aug 2007 02:17:20 GMT
Propchange: geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/ArgumentDescriptor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/ArgumentDescriptor.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/ArgumentDescriptor.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/CommandLineProcessor.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/CommandLineProcessor.java?rev=570606&view=auto
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/CommandLineProcessor.java (added)
+++ geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/CommandLineProcessor.java Tue Aug 28 19:17:11 2007
@@ -0,0 +1,361 @@
+/*
+ * 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.geronimo.gshell.clp;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeMap;
+
+import org.apache.geronimo.gshell.clp.handler.Handler;
+import org.apache.geronimo.gshell.clp.handler.Handlers;
+import org.apache.geronimo.gshell.clp.handler.Parameters;
+import org.apache.geronimo.gshell.clp.setter.CollectionFieldSetter;
+import org.apache.geronimo.gshell.clp.setter.FieldSetter;
+import org.apache.geronimo.gshell.clp.setter.MethodSetter;
+import org.apache.geronimo.gshell.clp.setter.Setter;
+
+/**
+ * Processes an object for command-line configuration annotations.
+ *
+ * @version $Rev$ $Date$
+ */
+public class CommandLineProcessor
+{
+    private final Object bean;
+
+    private final List<Handler> optionHandlers = new ArrayList<Handler>();
+
+    private final List<Handler> argumentHandlers = new ArrayList<Handler>();
+
+    private boolean stopAtNonOption = false;
+    
+    public CommandLineProcessor(final Object bean) throws IllegalAnnotationError {
+        assert bean != null;
+
+        this.bean = bean;
+
+        discoverDescriptors();
+    }
+
+    public Object getBean() {
+        return bean;
+    }
+    
+    public List<Handler> getOptionHandlers() {
+        return Collections.unmodifiableList(optionHandlers);
+    }
+
+    public List<Handler> getArgumentHandlers() {
+        return Collections.unmodifiableList(argumentHandlers);
+    }
+
+    public boolean getStopAtNonOption() {
+        return stopAtNonOption;
+    }
+
+    public void setStopAtNonOption(final boolean flag) {
+        stopAtNonOption = flag;
+    }
+    
+    //
+    // Discovery
+    //
+    
+    private void discoverDescriptors() {
+        // Recursively process all the methods/fields.
+        for (Class type=bean.getClass(); type!=null; type=type.getSuperclass()) {
+            // Discover methods
+            for (Method method : type.getDeclaredMethods()) {
+                Option option = method.getAnnotation(Option.class);
+                if (option != null) {
+                    addOption(new MethodSetter(bean, method), option);
+                }
+
+                Argument argument = method.getAnnotation(Argument.class);
+                if (argument != null) {
+                    addArgument(new MethodSetter(bean, method), argument);
+                }
+            }
+
+            // Discover fields
+            for (Field field : type.getDeclaredFields()) {
+                Option option = field.getAnnotation(Option.class);
+                if (option != null) {
+                    addOption(createFieldSetter(field), option);
+                }
+
+                Argument argument = field.getAnnotation(Argument.class);
+                if (argument != null) {
+                    addArgument(createFieldSetter(field), argument);
+                }
+            }
+        }
+
+        // Sanity check the argument indexes
+        for (int i=0; i< argumentHandlers.size(); i++) {
+        	if (argumentHandlers.get(i) == null) {
+                throw new IllegalAnnotationError("No argument annotation for index: " + i);
+        	}
+        }
+    }
+    
+    private Setter createFieldSetter(final Field field) {
+        assert field != null;
+
+        if (Collection.class.isAssignableFrom(field.getType())) {
+            return new CollectionFieldSetter(bean, field);
+        }
+        else {
+            return new FieldSetter(bean, field);
+        }
+    }
+
+    private void addArgument(final Setter setter, final Argument argument) {
+        Handler handler = Handlers.create(new ArgumentDescriptor(argument, setter.isMultiValued()), setter);
+    	int index = argument.index();
+
+        // Make sure the argument will fit in the list
+    	while (index >= argumentHandlers.size()) {
+    		argumentHandlers.add(null);
+    	}
+
+        if (argumentHandlers.get(index) != null) {
+            throw new IllegalAnnotationError("Duplicate argument index: " + index);
+        }
+
+        argumentHandlers.set(index, handler);
+    }
+
+    private void addOption(final Setter setter, final Option option) {
+        Handler handler = Handlers.create(new OptionDescriptor(option, setter.isMultiValued()), setter);
+        checkOptionNotInMap(option.name());
+
+        for (String alias : option.aliases()) {
+        	checkOptionNotInMap(alias);
+        }
+
+        optionHandlers.add(handler);
+    }
+
+	private void checkOptionNotInMap(final String name) throws IllegalAnnotationError {
+		if (findOptionByName(name) != null) {
+            throw new IllegalAnnotationError("Duplicate option name: " + name);
+        }
+	}
+
+    //
+    // Processing
+    //
+    
+    private class ParametersImpl
+        implements Parameters
+    {
+        private final String[] args;
+        
+        private int pos = 0;
+
+        private Handler handler;
+
+        public ParametersImpl(final String[] args) {
+            assert args != null;
+            
+            this.args = args;
+        }
+
+        private boolean hasMore() {
+            return pos < args.length;
+        }
+
+        private String current() {
+            return args[pos];
+        }
+
+        private void skip(final int n) {
+            pos += n;
+        }
+
+        private String getOptionName() {
+            return handler.descriptor.toString();
+        }
+
+        public String get(final int idx) throws ProcessingException {
+			if (pos + idx >= args.length) {
+                throw new ProcessingException(Messages.MISSING_OPERAND.format(getOptionName()));
+            }
+
+            return args[pos + idx];
+        }
+    }
+
+    public void process(final String... args) throws ProcessingException {
+        ParametersImpl params = new ParametersImpl(args);
+        Set<Handler> present = new HashSet<Handler>();
+        int argIndex = 0;
+        boolean processOptions = true;
+
+        //
+        // TODO: Need to rewrite some of this to allow more posix-style argument processing, like --foo=bar and --foo bar, and -vvvv
+        //
+        
+        while (params.hasMore()) {
+            String arg = params.current();
+            Handler handler;
+
+            if (processOptions && arg.startsWith("-")) {
+            	boolean isKeyValuePair = arg.indexOf('=') != -1;
+
+                // parse this as an option.
+                handler = isKeyValuePair ? findOptionHandler(arg) : findOptionByName(arg);
+
+                if (handler == null) {
+                    if (stopAtNonOption) {
+                        // Slurp up the remaining bits as arguments (including the option we just looked at)
+                        processOptions = false;
+                        continue;
+                    }
+                    else {
+                        // Unknown option, complain
+                        throw new ProcessingException(Messages.UNDEFINED_OPTION.format(arg));
+                    }
+                }
+                else {
+                    // known option; skip its name
+                    params.skip(1);
+                }
+            }
+            else {
+                // Complain if we have more arguments than we have handlers configured
+                if (argIndex >= argumentHandlers.size()) {
+            		Messages msg = argumentHandlers.size() == 0 ? Messages.NO_ARGUMENT_ALLOWED : Messages.TOO_MANY_ARGUMENTS;
+                    throw new ProcessingException(msg.format(arg));
+            	}
+
+            	// known argument
+            	handler = argumentHandlers.get(argIndex);
+            	if (!handler.descriptor.isMultiValued()) {
+            		argIndex++;
+                }
+            }
+
+            try {
+                //
+                // HACK: Hook up the current handler to the params for error message rendering
+                //
+                params.handler = handler;
+
+                // Invoker the handler and then skip arguments which it has eatten up
+                int consumed = handler.handle(params);
+                params.skip(consumed);
+            }
+            catch (StopProcessingOptionsNotification n) {
+                processOptions = false;
+            }
+
+            // Keep a list of the handlers which have been processed (for required validation below)
+            present.add(handler);
+        }
+
+        // Ensure that all required option handlers are present
+        for (Handler handler : optionHandlers) {
+            if (handler.descriptor.required() && !present.contains(handler)) {
+                throw new ProcessingException(Messages.REQUIRED_OPTION_MISSING.format(handler.descriptor.toString()));
+            }
+        }
+
+        // Ensure that all required argument handlers are present
+        for (Handler handler : argumentHandlers) {
+            if (handler.descriptor.required() && !present.contains(handler)) {
+                throw new ProcessingException(Messages.REQUIRED_ARGUMENT_MISSING.format(handler.descriptor.toString()));
+            }
+        }
+    }
+
+    //
+    // Option Handler Lookup
+    //
+    
+    private Handler findOptionHandler(String name) {
+		Handler handler = findOptionByName(name);
+
+        if (handler == null) {
+			// Have not found by its name, maybe its a property?
+			// Search for parts of the name (=prefix) - most specific first 
+			for (int i=name.length(); i>1; i--) {
+				String prefix = name.substring(0, i);
+				Map<String, Handler> possibleHandlers = filter(optionHandlers, prefix);
+				handler = possibleHandlers.get(prefix);
+
+                if (handler != null) {
+                    return handler;
+                }
+			}
+		}
+
+        return handler;
+	}
+
+    private Map<String, Handler> filter(List<Handler> handlers, String keyFilter) {
+		Map<String, Handler> map = new TreeMap<String, Handler>();
+
+        for (Handler handler : handlers) {
+			if (handlers.toString().startsWith(keyFilter)) {
+                map.put(handlers.toString(), handler);
+            }
+		}
+
+        return map;
+	}
+    
+    private Handler findOptionByName(String name) {
+		for (Handler handler : optionHandlers) {
+			OptionDescriptor option = (OptionDescriptor)handler.descriptor;
+
+            if (name.equals(option.name())) {
+				return handler;
+			}
+
+            for (String alias : option.aliases()) {
+				if (name.equals(alias)) {
+					return handler;
+				}
+			}
+		}
+
+        return null;
+	}
+
+    //
+    // Static Helpers
+    //
+
+    /*
+    public static void process(final Object bean, final String... args) throws ProcessingException {
+        CommandLineProcessor clp = new CommandLineProcessor(bean);
+        clp.process(args);
+    }
+    */
+}

Propchange: geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/CommandLineProcessor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/CommandLineProcessor.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/CommandLineProcessor.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/Descriptor.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/Descriptor.java?rev=570606&view=auto
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/Descriptor.java (added)
+++ geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/Descriptor.java Tue Aug 28 19:17:11 2007
@@ -0,0 +1,68 @@
+/*
+ * 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.geronimo.gshell.clp;
+
+import org.apache.geronimo.gshell.clp.handler.Handler;
+
+/**
+ * Basic container for option and argument descriptors.
+ *
+ * @version $Rev$ $Date$
+ */
+public abstract class Descriptor
+{
+	private final String description;
+
+    private final String metaVar;
+
+    private final boolean required;
+
+    private final boolean multiValued;
+
+    private final Class<? extends Handler> handler;
+
+	protected Descriptor(final String description, final String metaVar, final boolean required, final Class<? extends Handler> handler, final boolean multiValued) {
+		this.description = description;
+		this.metaVar = metaVar;
+		this.required = required;
+		this.handler = handler;
+		this.multiValued = multiValued;
+	}
+
+	public String description() {
+		return description;
+	}
+
+	public String metaVar() {
+		return metaVar;
+	}
+
+	public boolean required() {
+		return required;
+	}
+
+	public Class<? extends Handler> handler() {
+		return handler;
+	}
+
+	public boolean isMultiValued() {
+		return multiValued;
+	}
+}
\ No newline at end of file

Propchange: geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/Descriptor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/Descriptor.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/Descriptor.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/IllegalAnnotationError.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/IllegalAnnotationError.java?rev=570606&view=auto
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/IllegalAnnotationError.java (added)
+++ geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/IllegalAnnotationError.java Tue Aug 28 19:17:11 2007
@@ -0,0 +1,43 @@
+/*
+ * 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.geronimo.gshell.clp;
+
+/**
+ * Thrown to indicate that while processing an illegal annotation definition was discovered.
+ *
+ * @version $Rev$ $Date$
+ */
+public class IllegalAnnotationError
+    extends Error
+{
+	private static final long serialVersionUID = 1;
+
+	public IllegalAnnotationError(String message) {
+        super(message);
+    }
+
+    public IllegalAnnotationError(String message, Throwable cause) {
+        super(message, cause);
+    }
+
+    public IllegalAnnotationError(Throwable cause) {
+        super(cause);
+    }
+}

Propchange: geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/IllegalAnnotationError.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/IllegalAnnotationError.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/IllegalAnnotationError.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/Messages.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/Messages.java?rev=570606&view=auto
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/Messages.java (added)
+++ geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/Messages.java Tue Aug 28 19:17:11 2007
@@ -0,0 +1,53 @@
+/*
+ * 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.geronimo.gshell.clp;
+
+import java.text.MessageFormat;
+import java.util.ResourceBundle;
+
+/**
+ * Messages for the {@link org.apache.geronimo.gshell.clp} package. 
+ *
+ * @version $Rev$ $Date$
+ */
+enum Messages
+{
+    MISSING_OPERAND,
+    UNDEFINED_OPTION,
+    NO_ARGUMENT_ALLOWED,
+    REQUIRED_OPTION_MISSING,
+    TOO_MANY_ARGUMENTS,
+    REQUIRED_ARGUMENT_MISSING
+    ;
+
+    private static ResourceBundle bundle;
+
+    String format(Object... args) {
+        assert args != null;
+
+        synchronized (Messages.class) {
+            if (bundle == null) {
+                bundle = ResourceBundle.getBundle(Messages.class.getName());
+            }
+
+            return MessageFormat.format(bundle.getString(name()), args);
+        }
+    }
+}

Propchange: geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/Messages.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/Messages.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/Messages.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/Option.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/Option.java?rev=570606&view=auto
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/Option.java (added)
+++ geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/Option.java Tue Aug 28 19:17:11 2007
@@ -0,0 +1,53 @@
+/*
+ * 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.geronimo.gshell.clp;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+import org.apache.geronimo.gshell.clp.handler.Handler;
+
+/**
+ * Configures a field or method for processing as a command-line option.
+ *
+ * @version $Rev$ $Date$
+ */
+@Retention(RetentionPolicy.RUNTIME)
+@Target({ElementType.FIELD, ElementType.METHOD})
+public @interface Option
+{
+    String name();
+    
+    String[] aliases() default {};
+
+    String description() default "";
+
+    String metaVar() default "";
+
+    boolean required() default false;
+
+    boolean argumentRequired() default false;
+
+    Class<? extends Handler> handler() default Handler.class;
+    
+    boolean multiValued() default false;
+}

Propchange: geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/Option.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/Option.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/Option.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/OptionDescriptor.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/OptionDescriptor.java?rev=570606&view=auto
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/OptionDescriptor.java (added)
+++ geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/OptionDescriptor.java Tue Aug 28 19:17:11 2007
@@ -0,0 +1,73 @@
+/*
+ * 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.geronimo.gshell.clp;
+
+/**
+ * Descriptor for {@link Option} annotations.
+ *
+ * @version $Rev$ $Date$
+ */
+public class OptionDescriptor
+    extends Descriptor
+{
+    private final String name;
+    
+    private final String[] aliases;
+
+    private boolean argumentRequired;
+
+    public OptionDescriptor(final Option option, final boolean forceMultiValued) {
+        super(option.description(), option.metaVar(), option.required(), option.handler(), option.multiValued() || forceMultiValued);
+    	
+    	this.name = option.name();
+    	this.aliases = option.aliases();
+        this.argumentRequired = option.argumentRequired();
+    }
+    
+    public String name() {
+    	return name;
+    }
+    
+    public String[] aliases() {
+    	return aliases;
+    }
+
+    public boolean isArgumentRequired() {
+        return argumentRequired;
+    }
+    
+    @Override
+    public String toString() {
+    	if (aliases.length > 0) {
+    		String str = "";
+
+            for (String alias : aliases) {
+    			if (str.length() > 0) {
+    				str += ", ";
+    			}
+    			str += alias;
+    		}
+            
+            return name() + " (" + str + ")";
+    	}
+        
+        return name();
+    }
+}

Propchange: geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/OptionDescriptor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/OptionDescriptor.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/OptionDescriptor.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/Printer.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/Printer.java?rev=570606&view=auto
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/Printer.java (added)
+++ geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/Printer.java Tue Aug 28 19:17:11 2007
@@ -0,0 +1,216 @@
+/*
+ * 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.geronimo.gshell.clp;
+
+import java.io.PrintWriter;
+import java.io.Writer;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+import java.util.ResourceBundle;
+
+import org.apache.geronimo.gshell.clp.handler.Handler;
+
+/**
+ * Helper to print formatted help and usage text.
+ *
+ * @version $Rev$ $Date$
+ */
+public class Printer
+{
+    private CommandLineProcessor processor;
+
+    public Printer(final CommandLineProcessor processor) {
+        assert processor != null;
+        
+        this.processor = processor;
+    }
+
+    private String getMetaVariable(final Handler handler, final ResourceBundle bundle) {
+        assert handler != null;
+
+        String token = handler.descriptor.metaVar();
+        if (token.length() == 0) {
+            token = handler.getDefaultMetaVariable();
+        }
+
+        if (token == null) {
+            return null;
+        }
+
+        if (bundle != null) {
+            String localized = bundle.getString(token);
+
+            if (localized != null) {
+                token = localized;
+            }
+        }
+
+        return token;
+    }
+
+    private String getNameAndMeta(final Handler handler, final ResourceBundle bundle) {
+        assert handler != null;
+
+        String str = (handler.descriptor instanceof ArgumentDescriptor) ? "" : handler.descriptor.toString();
+    	String meta = getMetaVariable(handler, bundle);
+
+        if (meta != null) {
+    		if (str.length() > 0) {
+    			str += " ";
+    		}
+    		str += meta;
+    	}
+        
+        return str;
+    }
+
+    private int getPrefixLen(final Handler handler, final ResourceBundle bundle) {
+        assert handler != null;
+
+        if (handler.descriptor.description().length() == 0) {
+			return 0;
+        }
+
+        return getNameAndMeta(handler, bundle).length();
+	}
+
+    public void printUsage(final Writer writer, final ResourceBundle bundle) {
+        assert writer != null;
+
+        PrintWriter out = new PrintWriter(writer);
+
+        List<Handler> argumentHandlers = new ArrayList<Handler>();
+        argumentHandlers.addAll(processor.getArgumentHandlers());
+
+        List<Handler> optionHandlers = new ArrayList<Handler>();
+        optionHandlers.addAll(processor.getOptionHandlers());
+
+        // For display purposes, we like the argument handlers in argument order, but the option handlers in alphabetical order
+        Collections.sort(optionHandlers, new Comparator<Handler>() {
+			public int compare(Handler a, Handler b) {
+				return a.descriptor.toString().compareTo(b.descriptor.toString());
+			}
+		});
+
+        // Compute the maximum length of the syntax column
+        int len = 0;
+
+        for (Handler handler : optionHandlers) {
+            int curLen = getPrefixLen(handler, bundle);
+            len = Math.max(len, curLen);
+        }
+
+        for (Handler handler : argumentHandlers) {
+            int curLen = getPrefixLen(handler, bundle);
+            len = Math.max(len, curLen);
+        }
+
+        // And then render the handler usage
+        for (Handler handler : argumentHandlers) {
+        	printHandler(out, handler, len, bundle);
+        }
+
+        for (Handler handler : optionHandlers) {
+        	printHandler(out, handler, len, bundle);
+        }
+
+        out.flush();
+    }
+
+    public void printUsage(final Writer writer) {
+        printUsage(writer, null);
+    }
+
+    private void printHandler(final PrintWriter out, final Handler handler, final int len, final ResourceBundle bundle) {
+        assert out != null;
+        assert handler != null;
+
+        //
+        // TODO: Expose these as configurables
+        //
+        
+        int terminalWidth = 80;
+        String prefix = "  ";
+        String separator = "    ";
+        int prefixSeperatorWidth = prefix.length() + separator.length();
+        int descriptionWidth = terminalWidth - len - prefixSeperatorWidth;
+
+        // Only render if their is a discription, else its hidden
+        String desc = handler.descriptor.description();
+        if (desc.length() == 0) {
+            return;
+        }
+
+        // Render the prefix and syntax
+        String nameAndMeta = getNameAndMeta(handler, bundle);
+        out.print(prefix);
+        out.print(nameAndMeta);
+
+        // Render the seperator
+        for (int i = nameAndMeta.length(); i < len; ++i) {
+            out.print(' ');
+       	}
+        out.print(separator);
+
+        // Localize the description if we can
+        if (bundle != null) {
+            desc = bundle.getString(desc);
+        }
+
+        // Render the description splitting it over multipule lines if its longer than column size
+        while (desc != null && desc.length() > 0) {
+            //
+            // TODO: Should relaly only split on words here...
+            //
+
+            int i = desc.indexOf('\n');
+
+            if (i >= 0 && i <= descriptionWidth) {
+                out.println(desc.substring(0, i));
+                desc = desc.substring(i + 1);
+
+                if (desc.length() > 0) {
+                    indent(out, len + prefixSeperatorWidth);
+                }
+
+                continue;
+            }
+
+            if (desc.length() <= descriptionWidth) {
+                out.println(desc);
+                break;
+            }
+
+            out.println(desc.substring(0, descriptionWidth));
+            desc = desc.substring(descriptionWidth);
+            indent(out, len + prefixSeperatorWidth);
+        }
+    }
+
+	private void indent(final PrintWriter out, int i) {
+        assert out != null;
+
+        for (; i>0; i--) {
+            out.print(' ');
+        }
+    }
+}

Propchange: geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/Printer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/Printer.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/Printer.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/ProcessingException.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/ProcessingException.java?rev=570606&view=auto
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/ProcessingException.java (added)
+++ geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/ProcessingException.java Tue Aug 28 19:17:11 2007
@@ -0,0 +1,43 @@
+/*
+ * 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.geronimo.gshell.clp;
+
+/**
+ * Thrown to indicate a problem processing command line arguments and options.
+ *
+ * @version $Rev$ $Date$
+ */
+public class ProcessingException
+    extends Exception
+{
+	private static final long serialVersionUID = 1;
+
+	public ProcessingException(String message) {
+        super(message);
+    }
+
+    public ProcessingException(String message, Throwable cause) {
+        super(message, cause);
+    }
+
+    public ProcessingException(Throwable cause) {
+        super(cause);
+    }
+}

Propchange: geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/ProcessingException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/ProcessingException.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/ProcessingException.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/StopProcessingOptionsNotification.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/StopProcessingOptionsNotification.java?rev=570606&view=auto
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/StopProcessingOptionsNotification.java (added)
+++ geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/StopProcessingOptionsNotification.java Tue Aug 28 19:17:11 2007
@@ -0,0 +1,30 @@
+/*
+ * 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.geronimo.gshell.clp;
+
+/**
+ * Thrown by a handler to instruct the processor to treat all remaining tokens as arguments.
+ *
+ * @version $Rev$ $Date$
+ */
+public class StopProcessingOptionsNotification
+    extends Error
+{
+}

Propchange: geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/StopProcessingOptionsNotification.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/StopProcessingOptionsNotification.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/StopProcessingOptionsNotification.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/handler/BooleanHandler.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/handler/BooleanHandler.java?rev=570606&view=auto
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/handler/BooleanHandler.java (added)
+++ geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/handler/BooleanHandler.java Tue Aug 28 19:17:11 2007
@@ -0,0 +1,71 @@
+/*
+ * 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.geronimo.gshell.clp.handler;
+
+import org.apache.geronimo.gshell.clp.ArgumentDescriptor;
+import org.apache.geronimo.gshell.clp.Descriptor;
+import org.apache.geronimo.gshell.clp.OptionDescriptor;
+import org.apache.geronimo.gshell.clp.ProcessingException;
+import org.apache.geronimo.gshell.clp.setter.Setter;
+
+/**
+ * Handler for boolean types.
+ *
+ * @version $Rev$ $Date$
+ */
+public class BooleanHandler
+    extends Handler<Boolean>
+{
+	public BooleanHandler(final Descriptor desc, final Setter<? super Boolean> setter) {
+        super(desc, setter);
+    }
+
+    @Override
+    public int handle(final Parameters params) throws ProcessingException {
+        assert params != null;
+        
+        if (descriptor instanceof ArgumentDescriptor) {
+            String token = params.get(0);
+            boolean value = Boolean.parseBoolean(token);
+            setter.set(value);
+
+            return 1;
+    	}
+        else {
+            if (((OptionDescriptor)descriptor).isArgumentRequired()) {
+                String token = params.get(0);
+                boolean value = Boolean.parseBoolean(token);
+                setter.set(value);
+    
+                return 1;
+            }
+            else {
+                setter.set(true);
+
+                return 0;
+            }
+        }
+    }
+
+    @Override
+    public String getDefaultMetaVariable() {
+        return null;
+    }
+}

Propchange: geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/handler/BooleanHandler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/handler/BooleanHandler.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/handler/BooleanHandler.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/handler/DoubleHandler.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/handler/DoubleHandler.java?rev=570606&view=auto
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/handler/DoubleHandler.java (added)
+++ geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/handler/DoubleHandler.java Tue Aug 28 19:17:11 2007
@@ -0,0 +1,53 @@
+/*
+ * 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.geronimo.gshell.clp.handler;
+
+import org.apache.geronimo.gshell.clp.Descriptor;
+import org.apache.geronimo.gshell.clp.ProcessingException;
+import org.apache.geronimo.gshell.clp.setter.Setter;
+
+/**
+ * Handler for double types.
+ *
+ * @version $Rev$ $Date$
+ */
+public class DoubleHandler
+    extends Handler<Double>
+{
+    public DoubleHandler(final Descriptor desc, final Setter<? super Double> setter) {
+        super(desc, setter);
+    }
+
+    @Override
+    public int handle(final Parameters params) throws ProcessingException {
+        assert params != null;
+
+        String token = params.get(0);
+        double value = Double.parseDouble(token);
+        setter.set(value);
+        
+        return 1;
+    }
+
+    @Override
+    public String getDefaultMetaVariable() {
+        return "N";
+    }
+}

Propchange: geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/handler/DoubleHandler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/handler/DoubleHandler.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/handler/DoubleHandler.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/handler/EnumHandler.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/handler/EnumHandler.java?rev=570606&view=auto
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/handler/EnumHandler.java (added)
+++ geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/handler/EnumHandler.java Tue Aug 28 19:17:11 2007
@@ -0,0 +1,81 @@
+/*
+ * 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.geronimo.gshell.clp.handler;
+
+import org.apache.geronimo.gshell.clp.Descriptor;
+import org.apache.geronimo.gshell.clp.ProcessingException;
+import org.apache.geronimo.gshell.clp.setter.Setter;
+
+/**
+ * Handler for enum types.
+ *
+ * @version $Rev$ $Date$
+ */
+public class EnumHandler<T extends Enum<T>>
+    extends Handler<T>
+{
+    private final Class<T> enumType;
+
+    public EnumHandler(final Descriptor desc, final Setter<? super T> setter, final Class<T> enumType) {
+        super(desc, setter);
+
+        assert enumType != null;
+        
+        this.enumType = enumType;
+    }
+
+    @Override
+    public int handle(final Parameters params) throws ProcessingException {
+        assert params != null;
+        
+        String token = params.get(0);
+        T value = null;
+
+        for (T constant : enumType.getEnumConstants()) {
+            if (constant.name().equalsIgnoreCase(token)) {
+                value = constant;
+                break;
+            }
+        }
+
+        if (value == null) {
+            throw new ProcessingException(Messages.ILLEGAL_OPERAND.format(descriptor.toString(), token));
+        }
+
+        setter.set(value);
+        
+        return 1;
+    }
+
+    @Override
+    public String getDefaultMetaVariable() {
+    	StringBuffer buff = new StringBuffer();
+    	buff.append("[");
+
+        for (T constants : enumType.getEnumConstants()) {
+			buff.append(constants).append(" | ");
+		}
+
+        buff.delete(buff.length()-3, buff.length());
+    	buff.append("]");
+
+        return buff.toString();
+    }
+}

Propchange: geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/handler/EnumHandler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/handler/EnumHandler.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/handler/EnumHandler.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/handler/FileHandler.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/handler/FileHandler.java?rev=570606&view=auto
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/handler/FileHandler.java (added)
+++ geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/handler/FileHandler.java Tue Aug 28 19:17:11 2007
@@ -0,0 +1,54 @@
+/*
+ * 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.geronimo.gshell.clp.handler;
+
+import java.io.File;
+
+import org.apache.geronimo.gshell.clp.Descriptor;
+import org.apache.geronimo.gshell.clp.ProcessingException;
+import org.apache.geronimo.gshell.clp.setter.Setter;
+
+/**
+ * Handler for file types.
+ *
+ * @version $Rev$ $Date$
+ */
+public class FileHandler
+    extends Handler<File>
+{
+    public FileHandler(final Descriptor desc, final Setter<? super File> setter) {
+        super(desc, setter);
+    }
+
+    @Override
+    public int handle(final Parameters params) throws ProcessingException {
+        assert params != null;
+
+        String token = params.get(0);
+        setter.set(new File(token));
+        
+        return 1;
+    }
+
+    @Override
+    public String getDefaultMetaVariable() {
+        return "FILE";
+    }
+}

Propchange: geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/handler/FileHandler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/handler/FileHandler.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/handler/FileHandler.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/handler/Handler.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/handler/Handler.java?rev=570606&view=auto
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/handler/Handler.java (added)
+++ geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/handler/Handler.java Tue Aug 28 19:17:11 2007
@@ -0,0 +1,48 @@
+/*
+ * 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.geronimo.gshell.clp.handler;
+
+import org.apache.geronimo.gshell.clp.Descriptor;
+import org.apache.geronimo.gshell.clp.ProcessingException;
+import org.apache.geronimo.gshell.clp.setter.Setter;
+
+/**
+ * Provides the basic mechanism to handle custom option and argument processing.
+ *
+ * @version $Rev$ $Date$
+ */
+public abstract class Handler<T>
+{
+    public final Descriptor descriptor;
+
+    public final Setter<? super T> setter;
+
+    protected Handler(final Descriptor descriptor, final Setter<? super T> setter) {
+        assert descriptor != null;
+        assert setter != null;
+        
+        this.descriptor = descriptor;
+        this.setter = setter;
+    }
+
+    public abstract int handle(Parameters params) throws ProcessingException;
+
+    public abstract String getDefaultMetaVariable();
+}

Propchange: geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/handler/Handler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/handler/Handler.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/handler/Handler.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/handler/Handlers.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/handler/Handlers.java?rev=570606&view=auto
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/handler/Handlers.java (added)
+++ geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/handler/Handlers.java Tue Aug 28 19:17:11 2007
@@ -0,0 +1,124 @@
+/*
+ * 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.geronimo.gshell.clp.handler;
+
+import java.io.File;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.geronimo.gshell.clp.Descriptor;
+import org.apache.geronimo.gshell.clp.IllegalAnnotationError;
+import org.apache.geronimo.gshell.clp.setter.Setter;
+
+/**
+ * Provides access to handlers.
+ *
+ * @version $Rev$ $Date$
+ */
+public class Handlers
+{
+    private static final Map<Class,Constructor<? extends Handler>> handlerClasses = Collections.synchronizedMap(new HashMap<Class,Constructor<? extends Handler>>());
+
+    private static Constructor<? extends Handler> createHandlerFactory(final Class<? extends Handler> type) {
+        assert type != null;
+
+        try {
+            return type.getConstructor(Descriptor.class, Setter.class);
+        }
+        catch (NoSuchMethodException e) {
+            throw new IllegalArgumentException("Handler is missing required constructor: " + type);
+        }
+    }
+
+    private static Constructor<? extends Handler> getHandlerFactory(final Class type) {
+        assert type != null;
+
+        Constructor<? extends Handler> factory = handlerClasses.get(type);
+
+        if (factory == null) {
+            throw new IllegalAnnotationError("No handler registered for type: " + type);    
+        }
+
+        return factory;
+    }
+
+    public static Handler create(final Descriptor desc, final Setter setter) {
+        assert desc != null;
+        assert setter != null;
+
+        Constructor<? extends Handler> factory;
+        Class<? extends Handler> handlerType = desc.handler();
+
+        if (handlerType == Handler.class) {
+            Class valueType = setter.getType();
+
+            // Enum requires some special handling
+            if (Enum.class.isAssignableFrom(valueType)) {
+                return new EnumHandler(desc, setter, valueType);
+            }
+
+            factory = Handlers.getHandlerFactory(valueType);
+        }
+        else {
+            factory = Handlers.createHandlerFactory(handlerType);
+        }
+
+        try {
+            return factory.newInstance(desc, setter);
+        }
+        catch (InstantiationException e) {
+            throw new IllegalAnnotationError(e);
+        }
+        catch (IllegalAccessException e) {
+            throw new IllegalAnnotationError(e);
+        }
+        catch (InvocationTargetException e) {
+            throw new IllegalAnnotationError(e);
+        }
+    }
+
+    //
+    // Registration
+    //
+
+    public static void register(final Class valueType, final Class<? extends Handler> handlerType) {
+        assert valueType != null;
+        assert handlerType != null;
+        assert Handler.class.isAssignableFrom(handlerType);
+
+        Constructor<? extends Handler> factory = createHandlerFactory(handlerType);
+
+        handlerClasses.put(valueType, factory);
+    }
+
+    static {
+        register(Boolean.class, BooleanHandler.class);
+        register(boolean.class, BooleanHandler.class);
+        register(File.class, FileHandler.class);
+        register(Integer.class, IntegerHandler.class);
+        register(int.class, IntegerHandler.class);
+        register(Double.class, DoubleHandler.class);
+        register(double.class, DoubleHandler.class);
+        register(String.class, StringHandler.class);
+    }
+}

Propchange: geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/handler/Handlers.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/handler/Handlers.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/handler/Handlers.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/handler/IntegerHandler.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/handler/IntegerHandler.java?rev=570606&view=auto
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/handler/IntegerHandler.java (added)
+++ geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/handler/IntegerHandler.java Tue Aug 28 19:17:11 2007
@@ -0,0 +1,53 @@
+/*
+ * 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.geronimo.gshell.clp.handler;
+
+import org.apache.geronimo.gshell.clp.Descriptor;
+import org.apache.geronimo.gshell.clp.ProcessingException;
+import org.apache.geronimo.gshell.clp.setter.Setter;
+
+/**
+ * Handler for integer types.
+ *
+ * @version $Rev$ $Date$
+ */
+public class IntegerHandler
+    extends Handler<Integer>
+{
+	public IntegerHandler(final Descriptor desc, final Setter<? super Integer> setter) {
+		super(desc, setter);
+	}
+
+    @Override
+	public int handle(final Parameters params) throws ProcessingException {
+		assert params != null;
+
+        String token = params.get(0);
+        int value = Integer.parseInt(token);
+        setter.set(value);
+        
+        return 1;
+	}
+
+    @Override
+	public String getDefaultMetaVariable() {
+		return "N";
+	}
+}

Propchange: geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/handler/IntegerHandler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/handler/IntegerHandler.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/handler/IntegerHandler.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/handler/Messages.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/handler/Messages.java?rev=570606&view=auto
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/handler/Messages.java (added)
+++ geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/handler/Messages.java Tue Aug 28 19:17:11 2007
@@ -0,0 +1,49 @@
+/*
+ * 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.geronimo.gshell.clp.handler;
+
+import java.text.MessageFormat;
+import java.util.ResourceBundle;
+
+/**
+ * Messages for the {@link org.apache.geronimo.gshell.clp.handler} package.
+ *
+ * @version $Rev$ $Date$
+ */
+enum Messages
+{
+    ILLEGAL_OPERAND,
+    ILLEGAL_BOOLEAN,
+    ;
+
+    private static ResourceBundle bundle;
+
+    String format(Object... args) {
+        assert args != null;
+        
+        synchronized (Messages.class) {
+            if (bundle == null) {
+                bundle = ResourceBundle.getBundle(Messages.class.getName());
+            }
+            
+            return MessageFormat.format(bundle.getString(name()), args);
+        }
+    }
+}

Propchange: geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/handler/Messages.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/handler/Messages.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/handler/Messages.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/handler/Parameters.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/handler/Parameters.java?rev=570606&view=auto
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/handler/Parameters.java (added)
+++ geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/handler/Parameters.java Tue Aug 28 19:17:11 2007
@@ -0,0 +1,32 @@
+/*
+ * 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.geronimo.gshell.clp.handler;
+
+import org.apache.geronimo.gshell.clp.ProcessingException;
+
+/**
+ * Provides handlers with access to parameters to be consumed while processing.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface Parameters
+{
+    String get(int i) throws ProcessingException;
+}

Propchange: geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/handler/Parameters.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/handler/Parameters.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/handler/Parameters.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/handler/StopHandler.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/handler/StopHandler.java?rev=570606&view=auto
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/handler/StopHandler.java (added)
+++ geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/handler/StopHandler.java Tue Aug 28 19:17:11 2007
@@ -0,0 +1,48 @@
+/*
+ * 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.geronimo.gshell.clp.handler;
+
+import org.apache.geronimo.gshell.clp.Descriptor;
+import org.apache.geronimo.gshell.clp.ProcessingException;
+import org.apache.geronimo.gshell.clp.StopProcessingOptionsNotification;
+import org.apache.geronimo.gshell.clp.setter.Setter;
+
+/**
+ * Handler to abort further option processing (and soak up remaining tokens as arguments).
+ *
+ * @version $Rev$ $Date$
+ */
+public class StopHandler
+    extends Handler<String>
+{
+    public StopHandler(Descriptor desc, Setter<? super String> setter) {
+        super(desc, setter);
+    }
+
+    @Override
+    public int handle(final Parameters params) throws ProcessingException {
+        throw new StopProcessingOptionsNotification();
+    }
+
+    @Override
+    public String getDefaultMetaVariable() {
+        return "ARGUMENTS";
+    }
+}

Propchange: geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/handler/StopHandler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/handler/StopHandler.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/handler/StopHandler.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/handler/StringHandler.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/handler/StringHandler.java?rev=570606&view=auto
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/handler/StringHandler.java (added)
+++ geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/handler/StringHandler.java Tue Aug 28 19:17:11 2007
@@ -0,0 +1,52 @@
+/*
+ * 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.geronimo.gshell.clp.handler;
+
+import org.apache.geronimo.gshell.clp.Descriptor;
+import org.apache.geronimo.gshell.clp.ProcessingException;
+import org.apache.geronimo.gshell.clp.setter.Setter;
+
+/**
+ * Handler for string types.
+ *
+ * @version $Rev$ $Date$
+ */
+public class StringHandler
+    extends Handler<String>
+{
+    public StringHandler(Descriptor desc, Setter<? super String> setter) {
+        super(desc, setter);
+    }
+
+    @Override
+    public int handle(final Parameters params) throws ProcessingException {
+        assert params != null;
+
+        String token = params.get(0);
+        setter.set(token);
+        
+        return 1;
+    }
+
+    @Override
+    public String getDefaultMetaVariable() {
+        return "VAL";
+    }
+}

Propchange: geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/handler/StringHandler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/handler/StringHandler.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/handler/StringHandler.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/handler/package-info.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/handler/package-info.java?rev=570606&view=auto
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/handler/package-info.java (added)
+++ geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/handler/package-info.java Tue Aug 28 19:17:11 2007
@@ -0,0 +1,25 @@
+/*
+ * 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.
+ */
+
+/**
+ * Provides support for custom option and argument processing.
+ *
+ * @version $Rev$ $Date$
+ */
+package org.apache.geronimo.gshell.clp.handler;

Propchange: geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/handler/package-info.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/handler/package-info.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/handler/package-info.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/package-info.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/package-info.java?rev=570606&view=auto
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/package-info.java (added)
+++ geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/package-info.java Tue Aug 28 19:17:11 2007
@@ -0,0 +1,25 @@
+/*
+ * 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.
+ */
+
+/**
+ * Annotation-based command-line processing support.
+ *
+ * @version $Rev$ $Date$
+ */
+package org.apache.geronimo.gshell.clp;

Propchange: geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/package-info.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/package-info.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/package-info.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/setter/CollectionFieldSetter.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/setter/CollectionFieldSetter.java?rev=570606&view=auto
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/setter/CollectionFieldSetter.java (added)
+++ geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/setter/CollectionFieldSetter.java Tue Aug 28 19:17:11 2007
@@ -0,0 +1,99 @@
+/*
+ * 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.geronimo.gshell.clp.setter;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.geronimo.gshell.clp.IllegalAnnotationError;
+
+/**
+ * Setter for fields of collection types.  Currently supports lists and sets.
+ *
+ * @version $Rev$ $Date$
+ */
+public class CollectionFieldSetter
+    extends FieldSetter
+{
+    public CollectionFieldSetter(final Object bean, final Field field) {
+        super(bean, field);
+
+        if (!Collection.class.isAssignableFrom(field.getType())) {
+            throw new IllegalAnnotationError(Messages.ILLEGAL_FIELD_SIGNATURE.format(field.getType()));
+        }
+    }
+
+    public boolean isMultiValued() {
+    	return true;
+    }
+
+    public Class getType() {
+        Type type = field.getGenericType();
+
+        if (type instanceof ParameterizedType) {
+            ParameterizedType ptype = (ParameterizedType)type;
+            type = ptype.getActualTypeArguments()[0];
+            
+            if (type instanceof Class) {
+                return (Class)type;
+            }
+        }
+
+        // FIXME: This is certainly not valid, Should default to String probably
+        return Object.class;
+    }
+
+    protected void doSet(final Object value) throws IllegalAccessException {
+        Object obj = field.get(bean);
+
+        // If the field is not set, then create a new instance of the collection and set it
+        if (obj == null) {
+            if (List.class.isAssignableFrom(field.getType())) {
+                obj = new ArrayList();
+            }
+            else if (Set.class.isAssignableFrom(field.getType())) {
+                obj = new HashSet();
+            }
+            else {
+                //
+                // TODO: Add support for the default collection types
+                //
+                
+                throw new IllegalAnnotationError("Unsupported collection type: " + field.getType());
+            }
+
+            field.set(bean, obj);
+        }
+
+        // This should never happen
+        if (!(obj instanceof Collection)) {
+            throw new IllegalAnnotationError("Field is not a collection type: " + field);
+        }
+
+        // noinspection unchecked
+        ((Collection)obj).add(value);
+    }
+}

Propchange: geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/setter/CollectionFieldSetter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/setter/CollectionFieldSetter.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/sandbox/gshell/trunk/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/setter/CollectionFieldSetter.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message