felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rickh...@apache.org
Subject svn commit: r940616 - in /felix/trunk/gogo/runtime/src/main/java/org: apache/felix/gogo/runtime/shell/Reflective.java osgi/service/command/Flag.java osgi/service/command/Option.java
Date Mon, 03 May 2010 21:05:14 GMT
Author: rickhall
Date: Mon May  3 21:05:13 2010
New Revision: 940616

URL: http://svn.apache.org/viewvc?rev=940616&view=rev
Log:
Fix processing of flags; options not tested yet.

Modified:
    felix/trunk/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/shell/Reflective.java
    felix/trunk/gogo/runtime/src/main/java/org/osgi/service/command/Flag.java
    felix/trunk/gogo/runtime/src/main/java/org/osgi/service/command/Option.java

Modified: felix/trunk/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/shell/Reflective.java
URL: http://svn.apache.org/viewvc/felix/trunk/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/shell/Reflective.java?rev=940616&r1=940615&r2=940616&view=diff
==============================================================================
--- felix/trunk/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/shell/Reflective.java
(original)
+++ felix/trunk/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/shell/Reflective.java
Mon May  3 21:05:13 2010
@@ -172,26 +172,27 @@ public class Reflective {
 	 * @throws Exception
 	 */
 	@SuppressWarnings("unchecked")
-	private int coerce(CommandSession session, Object target, Method m,
+    private int coerce(CommandSession session, Object target, Method m,
 			Class<?> types[], Object out[], List<Object> in) throws Exception {
 		Annotation[][] pas = m.getParameterAnnotations();
 
+        int start = 0;
 		for (int argIndex = 0; argIndex < pas.length; argIndex++) {
 			Annotation as[] = pas[argIndex];
 			for (int a = 0; a < as.length; a++) {
-				if (as[a].getClass() == Option.class) {
+                if (as[a] instanceof Option) {
 					Option o = (Option) as[a];
 					out[argIndex] = coerce(session, target, types[argIndex], o
 							.dflt());
-				} else if (as[a].getClass() == Flag.class) {
-					Flag o = (Flag) as[a];
+                    start = argIndex + 1;
+                } else if (as[a] instanceof Flag) {
 					out[argIndex] = coerce(session, target, types[argIndex],
 							false);
+                    start = argIndex + 1;
 				}
 			}
 		}
 
-		
 		in = new ArrayList(in);
 		for (Iterator<Object> i = in.iterator(); i.hasNext();) {
 			Object item = i.next();
@@ -201,7 +202,7 @@ public class Reflective {
 					for (int argIndex = 0; argIndex < pas.length; argIndex++) {
 						Annotation as[] = pas[argIndex];
 						for (int a = 0; a < as.length; a++) {
-							if (as[a].getClass() == Option.class) {
+                            if (as[a] instanceof Option) {
 								Option o = (Option) as[a];
 								if (o.name().equals(option)) {
 									i.remove();
@@ -211,7 +212,7 @@ public class Reflective {
 									out[argIndex] = coerce(session, target,
 											types[argIndex], value);
 								}
-							} else if (as[a].getClass() == Flag.class) {
+                            } else if (as[a] instanceof Flag) {
 								Flag o = (Flag) as[a];
 								if (o.name().equals(option)) {
 									i.remove();
@@ -224,49 +225,50 @@ public class Reflective {
 				}
 			}
 		}
-		int start = 0;
-		while (start < out.length) {
-			out[start] = null;
+
+		int i = start;
+		while (i < out.length) {
+			out[i] = null;
 			try {
 				// Try to convert one argument
 				// derek: add empty array as extra argument
 				// out[i] = coerce(session, target, types[i], in.get(i));
-				if (start == in.size()) {
-					out[start] = NO_MATCH;
+				if (in.size() == 0) {
+					out[i] = NO_MATCH;
 				} else {
-					out[start] = coerce(session, target, types[start], in.get(start));
+					out[i] = coerce(session, target, types[i], in.get(0));
+                    if (out[i] != NO_MATCH) {
+                        in.remove(0);
+                    }
 				}
 
-				if (out[start] == NO_MATCH) {
+				if (out[i] == NO_MATCH) {
 					// Failed
 					// No match, check for varargs
-					if (types[start].isArray() && start == types.length - 1) {
+					if (types[i].isArray() && i == types.length - 1) {
 						// Try to parse the remaining arguments in an array
-						Class<?> component = types[start].getComponentType();
-						Object components = Array.newInstance(component, in
-								.size()
-								- start);
-						int n = start;
-						while (start < in.size()) {
-							Object t = coerce(session, target, component, in
-									.get(start));
+						Class<?> component = types[i].getComponentType();
+						Object components = Array.newInstance(component, in.size());
+						int n = i;
+						while (in.size() > 0) {
+							Object t = coerce(session, target, component, in.remove(0));
 							if (t == NO_MATCH) {
 								return -1;
 							}
-							Array.set(components, start - n, t);
-							start++;
+							Array.set(components, i - n, t);
+							i++;
 						}
 						out[n] = components;
 						// Is last element, so we will quite hereafter
 						// return n;
-						if (start == in.size()) {
-							++start;
+						if (in.size() == 0) {
+							++i;
 						}
-						return start; // derek - return number of args converted
+						return i; // derek - return number of args converted
 					}
 					return -1;
 				}
-				start++;
+				i++;
 			} catch (Exception e) {
 				System.err.println("Reflective:" + e);
 				e.printStackTrace();
@@ -277,7 +279,7 @@ public class Reflective {
 				return -1;
 			}
 		}
-		return start;
+		return i;
 	}
 
 	Object coerce(CommandSession session, Object target, Class<?> type,

Modified: felix/trunk/gogo/runtime/src/main/java/org/osgi/service/command/Flag.java
URL: http://svn.apache.org/viewvc/felix/trunk/gogo/runtime/src/main/java/org/osgi/service/command/Flag.java?rev=940616&r1=940615&r2=940616&view=diff
==============================================================================
--- felix/trunk/gogo/runtime/src/main/java/org/osgi/service/command/Flag.java (original)
+++ felix/trunk/gogo/runtime/src/main/java/org/osgi/service/command/Flag.java Mon May  3 21:05:13
2010
@@ -1,6 +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.osgi.service.command;
 
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Retention(RetentionPolicy.RUNTIME)
+@Target({ElementType.PARAMETER})
 public @interface Flag {
 	String name();
-	String help() default "no help";
 }

Modified: felix/trunk/gogo/runtime/src/main/java/org/osgi/service/command/Option.java
URL: http://svn.apache.org/viewvc/felix/trunk/gogo/runtime/src/main/java/org/osgi/service/command/Option.java?rev=940616&r1=940615&r2=940616&view=diff
==============================================================================
--- felix/trunk/gogo/runtime/src/main/java/org/osgi/service/command/Option.java (original)
+++ felix/trunk/gogo/runtime/src/main/java/org/osgi/service/command/Option.java Mon May  3
21:05:13 2010
@@ -1,6 +1,31 @@
+/*
+ * 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.osgi.service.command;
 
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Retention(RetentionPolicy.RUNTIME)
+@Target({ElementType.PARAMETER})
 public @interface Option {
 	String name();
 	String dflt();
-}
+}
\ No newline at end of file



Mime
View raw message