Skip to content

Commit b120308

Browse files
author
John Keyes
committed
- updated javadoc
git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/cli/trunk@267479 13f79535-47bb-0310-9956-ffa450edef68
1 parent c51e61f commit b120308

3 files changed

Lines changed: 193 additions & 53 deletions

File tree

src/java/org/apache/commons/cli2/validation/ClassValidator.java

Lines changed: 75 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
/**
2-
* Copyright 2003-2004 The Apache Software Foundation
1+
/*
2+
* Copyright 2003-2005 The Apache Software Foundation
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -29,11 +29,24 @@ public class ClassValidator implements Validator {
2929
private static final ResourceHelper resources =
3030
ResourceHelper.getResourceHelper(ClassValidator.class);
3131

32+
/** whether the class argument is loadable */
3233
private boolean loadable;
34+
35+
/** whether to create an instance of the class */
3336
private boolean instance;
3437

38+
/** the classloader to load classes from */
3539
private ClassLoader loader;
3640

41+
/**
42+
* Validate each argument value in the specified List against this instances
43+
* permitted attributes.
44+
*
45+
* If a value is valid then it's <code>String</code> value in the list is
46+
* replaced with it's <code>Class</code> value or instance.
47+
*
48+
* @see org.apache.commons.cli2.validation.Validator#validate(java.util.List)
49+
*/
3750
public void validate(final List values) throws InvalidArgumentException {
3851

3952
for (final ListIterator i = values.listIterator(); i.hasNext();) {
@@ -80,48 +93,34 @@ public void validate(final List values) throws InvalidArgumentException {
8093
}
8194
}
8295

83-
protected boolean isPotentialClassName(final String name) {
84-
final char[] chars = name.toCharArray();
85-
86-
boolean expectingStart = true;
87-
88-
for (int i = 0; i < chars.length; ++i) {
89-
final char c = chars[i];
90-
if (expectingStart) {
91-
if (!Character.isJavaIdentifierStart(c)) {
92-
return false;
93-
}
94-
expectingStart = false;
95-
}
96-
else {
97-
if (c == '.') {
98-
expectingStart = true;
99-
}
100-
else if (!Character.isJavaIdentifierPart(c)) {
101-
return false;
102-
}
103-
}
104-
}
105-
return !expectingStart;
106-
}
107-
10896
/**
109-
* @return true iff class must be loadable to be valid
97+
* Returns whether the argument value must represent a
98+
* class that is loadable.
99+
*
100+
* @return whether the argument value must represent a
101+
* class that is loadable.
110102
*/
111103
public boolean isLoadable() {
112104
return loadable;
113105
}
114106

115107
/**
116-
* true iff class must be loadable to be valid
117-
* @param loadable new loadable value
108+
* Specifies whether the argument value must represent a
109+
* class that is loadable.
110+
*
111+
* @param loadable whether the argument value must
112+
* represent a class that is loadable.
118113
*/
119114
public void setLoadable(boolean loadable) {
120115
this.loadable = loadable;
121116
}
122117

123118
/**
124-
* @return the classloader to resolve classes in
119+
* Returns the {@link ClassLoader} used to resolve and load
120+
* the classes specified by the argument values.
121+
*
122+
* @return the {@link ClassLoader} used to resolve and load
123+
* the classes specified by the argument values.
125124
*/
126125
public ClassLoader getClassLoader() {
127126
if (loader == null) {
@@ -132,23 +131,65 @@ public ClassLoader getClassLoader() {
132131
}
133132

134133
/**
135-
* @param loader the classloader to resolve classes in
134+
* Specifies the {@link ClassLoader} used to resolve and load
135+
* the classes specified by the argument values.
136+
*
137+
* @param loader the {@link ClassLoader} used to resolve and load
138+
* the classes specified by the argument values.
136139
*/
137140
public void setClassLoader(ClassLoader loader) {
138141
this.loader = loader;
139142
}
140143

141144
/**
142-
* @return true iff class instance is needed to be valid
145+
* Returns whether the argument value must represent a
146+
* class that can be instantiated.
147+
*
148+
* @return whether the argument value must represent a
149+
* class that can be instantiated.
143150
*/
144151
public boolean isInstance() {
145152
return instance;
146153
}
147154

148155
/**
149-
* @param instance true iff class instance is needed to be valid
156+
* Specifies whether the argument value must represent a
157+
* class that can be instantiated.
158+
*
159+
* @param loadable whether the argument value must
160+
* represent a class that can be instantiated.
150161
*/
151162
public void setInstance(boolean instance) {
152163
this.instance = instance;
153164
}
165+
166+
/**
167+
* Returns whether the specified name is allowed as
168+
* a Java class name.
169+
*/
170+
protected boolean isPotentialClassName(final String name) {
171+
final char[] chars = name.toCharArray();
172+
173+
boolean expectingStart = true;
174+
175+
for (int i = 0; i < chars.length; ++i) {
176+
final char c = chars[i];
177+
if (expectingStart) {
178+
if (!Character.isJavaIdentifierStart(c)) {
179+
return false;
180+
}
181+
expectingStart = false;
182+
}
183+
else {
184+
if (c == '.') {
185+
expectingStart = true;
186+
}
187+
else if (!Character.isJavaIdentifierPart(c)) {
188+
return false;
189+
}
190+
}
191+
}
192+
return !expectingStart;
193+
}
194+
154195
}

src/java/org/apache/commons/cli2/validation/EnumValidator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2003-2004 The Apache Software Foundation
2+
* Copyright 2003-2005 The Apache Software Foundation
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

0 commit comments

Comments
 (0)