commons-attributes-2.2/ 40755 0 0 0 10464315317 12252 5 ustar 0 0 commons-attributes-2.2/unittest/ 40755 0 0 0 10464315317 14131 5 ustar 0 0 commons-attributes-2.2/unittest/src/ 40755 0 0 0 10464315317 14720 5 ustar 0 0 commons-attributes-2.2/unittest/src/cl2/ 40755 0 0 0 10464315317 15400 5 ustar 0 0 commons-attributes-2.2/unittest/src/test/ 40755 0 0 0 10464315316 15676 5 ustar 0 0 commons-attributes-2.2/unittest/src/test/org/ 40755 0 0 0 10464315316 16465 5 ustar 0 0 commons-attributes-2.2/unittest/src/test/org/apache/ 40755 0 0 0 10464315316 17706 5 ustar 0 0 commons-attributes-2.2/unittest/src/test/org/apache/commons/ 40755 0 0 0 10464315316 21361 5 ustar 0 0 commons-attributes-2.2/unittest/src/test/org/apache/commons/attributes/ 40755 0 0 0 10464315316 23547 5 ustar 0 0 commons-attributes-2.2/unittest/src/test/org/apache/commons/attributes/test/ 40755 0 0 0 10464315317 24527 5 ustar 0 0 commons-attributes-2.2/unittest/src/test/org/apache/commons/attributes/test/samples/ 40755 0 0 0 10464315317 26173 5 ustar 0 0 commons-attributes-2.2/unittest/src/cl1/ 40755 0 0 0 10464315317 15377 5 ustar 0 0 commons-attributes-2.2/unittest/src/java/ 40755 0 0 0 10464315317 15641 5 ustar 0 0 commons-attributes-2.2/compiler/ 40755 0 0 0 10464315317 14064 5 ustar 0 0 commons-attributes-2.2/compiler/src/ 40755 0 0 0 10464315316 14652 5 ustar 0 0 commons-attributes-2.2/compiler/src/java/ 40755 0 0 0 10464315316 15573 5 ustar 0 0 commons-attributes-2.2/compiler/src/java/org/ 40755 0 0 0 10464315316 16362 5 ustar 0 0 commons-attributes-2.2/compiler/src/java/org/apache/ 40755 0 0 0 10464315316 17603 5 ustar 0 0 commons-attributes-2.2/compiler/src/java/org/apache/commons/ 40755 0 0 0 10464315316 21256 5 ustar 0 0 commons-attributes-2.2/compiler/src/java/org/apache/commons/attributes/ 40755 0 0 0 10464315317 23445 5 ustar 0 0 commons-attributes-2.2/compiler/src/java/org/apache/commons/attributes/compiler/ 40755 0 0 0 10464315317 25257 5 ustar 0 0 commons-attributes-2.2/compiler/src/java/org/apache/commons/attributes/validation/ 40755 0 0 0 10464315317 25577 5 ustar 0 0 commons-attributes-2.2/compiler/src/java/org/apache/commons/attributes/javadoc/ 40755 0 0 0 10464315317 25054 5 ustar 0 0 commons-attributes-2.2/compiler/src/test/ 40755 0 0 0 10464315316 15631 5 ustar 0 0 commons-attributes-2.2/compiler/src/test/org/ 40755 0 0 0 10464315316 16420 5 ustar 0 0 commons-attributes-2.2/compiler/src/test/org/apache/ 40755 0 0 0 10464315316 17641 5 ustar 0 0 commons-attributes-2.2/compiler/src/test/org/apache/commons/ 40755 0 0 0 10464315316 21314 5 ustar 0 0 commons-attributes-2.2/compiler/src/test/org/apache/commons/attributes/ 40755 0 0 0 10464315316 23502 5 ustar 0 0 commons-attributes-2.2/compiler/src/test/org/apache/commons/attributes/compiler/ 40755 0 0 0 10464315316 25314 5 ustar 0 0 commons-attributes-2.2/compiler/src/test/org/apache/commons/attributes/compiler/test/ 40755 0 0 0 10464315316 26273 5 ustar 0 0 commons-attributes-2.2/compiler/target/ 40755 0 0 0 10464315317 15352 5 ustar 0 0 commons-attributes-2.2/site/ 40755 0 0 0 10464315316 13215 5 ustar 0 0 commons-attributes-2.2/site/xdocs/ 40755 0 0 0 10464315317 14336 5 ustar 0 0 commons-attributes-2.2/site/xdocs/images/ 40755 0 0 0 10464315317 15603 5 ustar 0 0 commons-attributes-2.2/site/xdocs/style/ 40755 0 0 0 10464315317 15476 5 ustar 0 0 commons-attributes-2.2/site/etc/ 40755 0 0 0 10464315317 13771 5 ustar 0 0 commons-attributes-2.2/site/etc/ant_demo/ 40755 0 0 0 10464315316 15556 5 ustar 0 0 commons-attributes-2.2/site/etc/maven_demo/ 40755 0 0 0 10464315317 16103 5 ustar 0 0 commons-attributes-2.2/site/etc/maven_demo/src/ 40755 0 0 0 10464315317 16672 5 ustar 0 0 commons-attributes-2.2/api/ 40755 0 0 0 10464315317 13023 5 ustar 0 0 commons-attributes-2.2/api/src/ 40755 0 0 0 10464315316 13611 5 ustar 0 0 commons-attributes-2.2/api/src/java/ 40755 0 0 0 10464315317 14533 5 ustar 0 0 commons-attributes-2.2/api/src/java/org/ 40755 0 0 0 10464315316 15321 5 ustar 0 0 commons-attributes-2.2/api/src/java/org/apache/ 40755 0 0 0 10464315316 16542 5 ustar 0 0 commons-attributes-2.2/api/src/java/org/apache/commons/ 40755 0 0 0 10464315316 20215 5 ustar 0 0 commons-attributes-2.2/api/src/java/org/apache/commons/attributes/ 40755 0 0 0 10464315317 22404 5 ustar 0 0 commons-attributes-2.2/plugin/ 40755 0 0 0 10464315317 13550 5 ustar 0 0 commons-attributes-2.2/plugin/target/ 40755 0 0 0 10464315317 15036 5 ustar 0 0 commons-attributes-2.2/NOTICE.txt 100644 0 0 145 10464315316 14050 0 ustar 0 0 This product includes software developed by
The Apache Software Foundation (http://www.apache.org/).
commons-attributes-2.2/unittest/src/cl2/TestClass.java 100644 0 0 2441 10464315316 20245 0 ustar 0 0 /*
* Copyright 2003-2004 The Apache Software Foundation
*
* Licensed 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.
*/
/**
* @@TestAttribute ("TestClass")
*/
public class TestClass {
/**
* @@TestAttribute ("TestClass.ctor")
* @@.parameter TestAttribute ("TestClass.ctor.parameter")
*/
public TestClass (int parameter) {
}
/**
* @@TestAttribute ("TestClass.Inner")
*/
public static class Inner {}
/**
* @@TestAttribute ("TestClass.field")
*/
public Object field = null;
/**
* @@TestAttribute ("TestClass.method")
* @@.parameter TestAttribute ("TestClass.method.parameter")
* @@.return TestAttribute ("TestClass.method.return")
*/
public Object method (int parameter) {
return null;
}
} commons-attributes-2.2/unittest/src/cl2/TestAttribute.java 100644 0 0 1707 10464315317 21150 0 ustar 0 0 /*
* Copyright 2003-2004 The Apache Software Foundation
*
* Licensed 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.
*/
/**
* @@org.apache.commons.attributes.Indexed ()
*/
public class TestAttribute {
private final String key;
public TestAttribute (String key) {
this.key = key;
}
public String getKey () {
return key;
}
public String toString () {
return "[TestAttribute " + key + "]";
}
} commons-attributes-2.2/unittest/src/test/org/apache/commons/attributes/test/SealableTestCase.java 100644 0 0 5361 10464315316 30637 0 ustar 0 0 /*
* Copyright 2003-2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.attributes.test;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Constructor;
import java.io.File;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.Collection;
import java.util.Iterator;
import org.apache.commons.attributes.Attributes;
import org.apache.commons.attributes.AttributeIndex;
import org.apache.commons.attributes.DefaultSealable;
import org.apache.commons.attributes.SealedAttributeException;
import junit.framework.TestCase;
public class SealableTestCase extends TestCase {
/**
* A sample attribute with bean-like properties. Used to test the
* named parameter syntax.
*/
public static class SampleSealableAttribute extends DefaultSealable {
private int number;
public SampleSealableAttribute () {
}
public int getNumber () {
return number;
}
public void setNumber (int number) {
checkSealed ();
this.number = number;
}
}
/** @@SealableTestCase.SampleSealableAttribute (number=1) */
public static class ClassWithSealable {}
public void testSealable () throws Exception {
SampleSealableAttribute attribute = (SampleSealableAttribute) Attributes.getAttribute (ClassWithSealable.class, SampleSealableAttribute.class);
try {
attribute.setNumber (11);
fail ("Attribute should be sealed!");
} catch (IllegalStateException ise) {
// -- OK, attribute should be sealed.
}
assertEquals (1, attribute.getNumber ());
}
public void testSealableExceptionType () throws Exception {
SampleSealableAttribute attribute = (SampleSealableAttribute) Attributes.getAttribute (ClassWithSealable.class, SampleSealableAttribute.class);
try {
attribute.setNumber (11);
fail ("Attribute should be sealed!");
} catch (SealedAttributeException ise) {
// -- OK, attribute should be sealed and throw a SealedAttributeException.
}
}
} commons-attributes-2.2/unittest/src/test/org/apache/commons/attributes/test/OverrideTestCase.java 100644 0 0 3773 10464315316 30713 0 ustar 0 0 /*
* Copyright 2003-2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.attributes.test;
import junit.framework.TestCase;
import org.apache.commons.attributes.Attributes;
import org.apache.commons.attributes.Inheritable;
public class OverrideTestCase extends TestCase {
/**
* @@OverrideTestCase.OverrideAttribute(1)
*/
public static class OverrideSuper {
}
/**
* @@Inheritable()
*/
public static class OverrideAttribute {
private final int value;
public OverrideAttribute (int value) {
this.value = value;
}
public int getValue () {
return value;
}
public int hashCode () {
return 1;
}
public boolean equals (Object o) {
return o instanceof OverrideAttribute;
}
public String toString () {
return "OverrideAttribute: " + value;
}
}
/**
* @@OverrideTestCase.OverrideAttribute(2)
*/
public static class OverrideDerived extends OverrideSuper {
}
public void testOverride () throws Exception {
System.out.println (Attributes.getAttributes (OverrideDerived.class));
OverrideAttribute attr = (OverrideAttribute)
Attributes.getAttribute (OverrideDerived.class, OverrideAttribute.class);
assertEquals (2, attr.getValue ());
}
}
commons-attributes-2.2/unittest/src/test/org/apache/commons/attributes/test/TargetTestCase.java 100644 0 0 33730 10464315316 30376 0 ustar 0 0 /*
* Copyright 2003-2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.attributes.test;
import junit.framework.TestCase;
import org.apache.commons.attributes.Attributes;
import org.apache.commons.attributes.Target;
import org.apache.commons.attributes.InvalidAttributeTargetError;
public class TargetTestCase extends TestCase {
/**
* @@Target(Target.METHOD)
*/
public static class AttributeWithTargetMethod {}
/**
* @@Target(Target.CLASS)
*/
public static class AttributeWithTargetClass {}
/**
* @@Target(Target.FIELD)
*/
public static class AttributeWithTargetField {}
/**
* @@Target(Target.CONSTRUCTOR)
*/
public static class AttributeWithTargetConstructor {}
/**
* @@Target(Target.METHOD_PARAMETER)
*/
public static class AttributeWithTargetMethodParameter {}
/**
* @@Target(Target.CONSTRUCTOR_PARAMETER)
*/
public static class AttributeWithTargetConstructorParameter {}
/**
* @@Target(Target.RETURN)
*/
public static class AttributeWithTargetReturn {}
/*
*
-------------------------------------------------------------------
*
*/
private void expectSuccess (Class[] classes) {
for (int i = 0; i < classes.length; i++) {
Attributes.getAttributes (classes[i]);
}
}
private void expectFail (Class[] classes) {
for (int i = 0; i < classes.length; i++) {
try {
Attributes.getAttributes (classes[i]);
fail (classes[i].getName () + " should throw an InvalidAttributeTargetError");
} catch (InvalidAttributeTargetError iate) {
// OK.
}
}
}
/*
*
-------------------------------------------------------------------
*
*/
/**
* @@TargetTestCase.AttributeWithTargetMethod()
*/
public static class ClassWithInvalidDeclarations {}
public void testErrorMessage () throws Exception {
Class clazz1 = ClassWithInvalidDeclarations.class;
try {
Attributes.getAttributes (clazz1);
fail ();
} catch (InvalidAttributeTargetError iate) {
assertEquals ("Attributes of type org.apache.commons.attributes.test.TargetTestCase$AttributeWithTargetMethod " +
"can't be applied to org.apache.commons.attributes.test.TargetTestCase$ClassWithInvalidDeclarations. " +
"They can only be applied to: METHOD",
iate.getMessage ());
// OK.
}
}
/** @@TargetTestCase.AttributeWithTargetClass() */
public static class ClassAttributes0 {}
/** @@TargetTestCase.AttributeWithTargetMethod() */
public static class ClassAttributes1 {}
/** @@TargetTestCase.AttributeWithTargetField() */
public static class ClassAttributes2 {}
/** @@TargetTestCase.AttributeWithTargetMethodParameter() */
public static class ClassAttributes3 {}
/** @@TargetTestCase.AttributeWithTargetConstructorParameter() */
public static class ClassAttributes4 {}
/** @@TargetTestCase.AttributeWithTargetReturn() */
public static class ClassAttributes5 {}
/** @@TargetTestCase.AttributeWithTargetConstructor() */
public static class ClassAttributes6 {}
public void testClassAttributes () throws Exception {
expectSuccess (new Class[]{ ClassAttributes0.class });
expectFail (new Class[]{
ClassAttributes1.class,
ClassAttributes2.class,
ClassAttributes3.class,
ClassAttributes4.class,
ClassAttributes5.class,
ClassAttributes6.class
});
}
public static class FieldAttributes0 {
/** @@TargetTestCase.AttributeWithTargetClass() */
private Object o;
}
public static class FieldAttributes1 {
/** @@TargetTestCase.AttributeWithTargetMethod() */
private Object o;
}
public static class FieldAttributes2 {
/** @@TargetTestCase.AttributeWithTargetField() */
private Object o;
}
public static class FieldAttributes3 {
/** @@TargetTestCase.AttributeWithTargetMethodParameter() */
private Object o;
}
public static class FieldAttributes4 {
/** @@TargetTestCase.AttributeWithTargetConstructorParameter() */
private Object o;
}
public static class FieldAttributes5 {
/** @@TargetTestCase.AttributeWithTargetReturn() */
private Object o;
}
public static class FieldAttributes6 {
/** @@TargetTestCase.AttributeWithTargetConstructor() */
private Object o;
}
public void testFieldAttributes () throws Exception {
expectSuccess (new Class[]{ FieldAttributes2.class });
expectFail (new Class[]{
FieldAttributes0.class,
FieldAttributes1.class,
FieldAttributes3.class,
FieldAttributes4.class,
FieldAttributes5.class,
FieldAttributes6.class
});
}
public static class MethodAttributes0 {
/** @@TargetTestCase.AttributeWithTargetClass() */
private void method () {};
}
public static class MethodAttributes1 {
/** @@TargetTestCase.AttributeWithTargetMethod() */
private void method () {};
}
public static class MethodAttributes2 {
/** @@TargetTestCase.AttributeWithTargetField() */
private void method () {};
}
public static class MethodAttributes3 {
/** @@TargetTestCase.AttributeWithTargetMethodParameter() */
private void method () {};
}
public static class MethodAttributes4 {
/** @@TargetTestCase.AttributeWithTargetConstructorParameter() */
private void method () {};
}
public static class MethodAttributes5 {
/** @@TargetTestCase.AttributeWithTargetReturn() */
private void method () {};
}
public static class MethodAttributes6 {
/** @@TargetTestCase.AttributeWithTargetConstructor() */
private void method () {};
}
public void testMethodAttributes () throws Exception {
expectSuccess (new Class[]{ MethodAttributes1.class });
expectFail (new Class[]{
MethodAttributes0.class,
MethodAttributes2.class,
MethodAttributes3.class,
MethodAttributes4.class,
MethodAttributes5.class,
MethodAttributes6.class
});
}
public static class ConstructorAttributes0 {
/** @@TargetTestCase.AttributeWithTargetClass() */
public ConstructorAttributes0 () {};
}
public static class ConstructorAttributes1 {
/** @@TargetTestCase.AttributeWithTargetMethod() */
public ConstructorAttributes1 () {};
}
public static class ConstructorAttributes2 {
/** @@TargetTestCase.AttributeWithTargetField() */
public ConstructorAttributes2 () {};
}
public static class ConstructorAttributes3 {
/** @@TargetTestCase.AttributeWithTargetMethodParameter() */
public ConstructorAttributes3 () {};
}
public static class ConstructorAttributes4 {
/** @@TargetTestCase.AttributeWithTargetConstructorParameter() */
public ConstructorAttributes4 () {};
}
public static class ConstructorAttributes5 {
/** @@TargetTestCase.AttributeWithTargetReturn() */
public ConstructorAttributes5 () {};
}
public static class ConstructorAttributes6 {
/** @@TargetTestCase.AttributeWithTargetConstructor() */
public ConstructorAttributes6 () {};
}
public void testConstructorAttributes () throws Exception {
expectSuccess (new Class[]{ ConstructorAttributes6.class });
expectFail (new Class[]{
ConstructorAttributes0.class,
ConstructorAttributes1.class,
ConstructorAttributes2.class,
ConstructorAttributes3.class,
ConstructorAttributes4.class,
ConstructorAttributes5.class
});
}
public static class ConstructorParameterAttributes0 {
/** @@.param TargetTestCase.AttributeWithTargetClass() */
public ConstructorParameterAttributes0 (int param) {};
}
public static class ConstructorParameterAttributes1 {
/** @@.param TargetTestCase.AttributeWithTargetMethod() */
public ConstructorParameterAttributes1 (int param) {};
}
public static class ConstructorParameterAttributes2 {
/** @@.param TargetTestCase.AttributeWithTargetField() */
public ConstructorParameterAttributes2 (int param) {};
}
public static class ConstructorParameterAttributes3 {
/** @@.param TargetTestCase.AttributeWithTargetMethodParameter() */
public ConstructorParameterAttributes3 (int param) {};
}
public static class ConstructorParameterAttributes4 {
/** @@.param TargetTestCase.AttributeWithTargetConstructorParameter() */
public ConstructorParameterAttributes4 (int param) {};
}
public static class ConstructorParameterAttributes5 {
/** @@.param TargetTestCase.AttributeWithTargetReturn() */
public ConstructorParameterAttributes5 (int param) {};
}
public static class ConstructorParameterAttributes6 {
/** @@.param TargetTestCase.AttributeWithTargetConstructor() */
public ConstructorParameterAttributes6 (int param) {};
}
public void testConstructorParameterAttributes () throws Exception {
expectSuccess (new Class[]{ ConstructorParameterAttributes4.class });
expectFail (new Class[]{
ConstructorParameterAttributes0.class,
ConstructorParameterAttributes1.class,
ConstructorParameterAttributes2.class,
ConstructorParameterAttributes3.class,
ConstructorParameterAttributes5.class,
ConstructorParameterAttributes6.class
});
}
public static class MethodParameterAttributes0 {
/** @@.param TargetTestCase.AttributeWithTargetClass() */
private void method (int param) {};
}
public static class MethodParameterAttributes1 {
/** @@.param TargetTestCase.AttributeWithTargetMethod() */
private void method (int param) {};
}
public static class MethodParameterAttributes2 {
/** @@.param TargetTestCase.AttributeWithTargetField() */
private void method (int param) {};
}
public static class MethodParameterAttributes3 {
/** @@.param TargetTestCase.AttributeWithTargetMethodParameter() */
private void method (int param) {};
}
public static class MethodParameterAttributes4 {
/** @@.param TargetTestCase.AttributeWithTargetConstructorParameter() */
private void method (int param) {};
}
public static class MethodParameterAttributes5 {
/** @@.param TargetTestCase.AttributeWithTargetReturn() */
private void method (int param) {};
}
public static class MethodParameterAttributes6 {
/** @@.param TargetTestCase.AttributeWithTargetConstructor() */
private void method (int param) {};
}
public void testMethodParameterAttributes () throws Exception {
expectSuccess (new Class[]{ MethodParameterAttributes3.class });
expectFail (new Class[]{
MethodParameterAttributes0.class,
MethodParameterAttributes1.class,
MethodParameterAttributes2.class,
MethodParameterAttributes4.class,
MethodParameterAttributes5.class,
MethodParameterAttributes6.class
});
}
public static class ReturnAttributes0 {
/** @@.return TargetTestCase.AttributeWithTargetClass() */
private int method (int param) { return 0; };
}
public static class ReturnAttributes1 {
/** @@.return TargetTestCase.AttributeWithTargetMethod() */
private int method (int param) { return 0; };
}
public static class ReturnAttributes2 {
/** @@.return TargetTestCase.AttributeWithTargetField() */
private int method (int param) { return 0; };
}
public static class ReturnAttributes3 {
/** @@.return TargetTestCase.AttributeWithTargetMethodParameter() */
private int method (int param) { return 0; };
}
public static class ReturnAttributes4 {
/** @@.return TargetTestCase.AttributeWithTargetConstructorParameter() */
private int method (int param) { return 0; };
}
public static class ReturnAttributes5 {
/** @@.return TargetTestCase.AttributeWithTargetReturn() */
private int method (int param) { return 0; };
}
public static class ReturnAttributes6 {
/** @@.return TargetTestCase.AttributeWithTargetConstructor() */
private int method (int param) { return 0; };
}
public void testReturnAttributes () throws Exception {
expectSuccess (new Class[]{ ReturnAttributes5.class });
expectFail (new Class[]{
ReturnAttributes0.class,
ReturnAttributes1.class,
ReturnAttributes2.class,
ReturnAttributes3.class,
ReturnAttributes4.class,
ReturnAttributes6.class
});
}
} ././@LongLink 100644 0 0 153 10464315317 10256 L ustar 0 0 commons-attributes-2.2/unittest/src/test/org/apache/commons/attributes/test/RuntimeAttributesTestCase.java commons-attributes-2.2/unittest/src/test/org/apache/commons/attributes/test/RuntimeAttributesTestCas100644 0 0 7326 10464315316 31537 0 ustar 0 0 /*
* Copyright 2003-2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.attributes.test;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Constructor;
import java.io.File;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.Collection;
import java.util.Iterator;
import org.apache.commons.attributes.Attributes;
import org.apache.commons.attributes.AttributeIndex;
import org.apache.commons.attributes.test.samples.RuntimeSample;
import org.apache.commons.attributes.test.samples.Sample;
import junit.framework.TestCase;
public class RuntimeAttributesTestCase extends TestCase {
protected void collectionsEquals (Collection a, Collection b) {
if (a.size () != b.size ()) {
fail ("A=" + a + " B=" + b);
}
Iterator iter = a.iterator ();
while (iter.hasNext ()) {
Object o = iter.next ();
if (!b.contains (o)) {
fail ("B does not contain " + o);
}
}
iter = b.iterator ();
while (iter.hasNext ()) {
Object o = iter.next ();
if (!a.contains (o)) {
fail ("A does not contain " + o);
}
}
}
public void testRuntimeAttributesEqual () throws Exception {
Class clazz1 = Sample.class;
Class clazz2 = RuntimeSample.class;
collectionsEquals (Attributes.getAttributes (clazz1), Attributes.getAttributes (clazz2));
Method[] methods1 = clazz1.getDeclaredMethods ();
for (int i = 0; i < methods1.length; i++) {
Method m1 = methods1[i];
Method m2 = clazz2.getDeclaredMethod (m1.getName (), m1.getParameterTypes ());
collectionsEquals (Attributes.getAttributes (m1), Attributes.getAttributes (m2));
int numParameters = m1.getParameterTypes().length;
for (int j = 0; j < numParameters; j++) {
collectionsEquals (Attributes.getParameterAttributes (m1, j), Attributes.getParameterAttributes (m2, j));
}
collectionsEquals (Attributes.getReturnAttributes (m1), Attributes.getReturnAttributes (m2));
}
Constructor[] ctors1 = clazz1.getDeclaredConstructors ();
for (int i = 0; i < ctors1.length; i++) {
Constructor c1 = ctors1[i];
Constructor c2 = clazz2.getDeclaredConstructor (c1.getParameterTypes ());
collectionsEquals (Attributes.getAttributes (c1), Attributes.getAttributes (c2));
int numParameters = c1.getParameterTypes().length;
for (int j = 0; j < numParameters; j++) {
collectionsEquals (Attributes.getParameterAttributes (c1, j), Attributes.getParameterAttributes (c2, j));
}
}
Field[] fields1 = clazz1.getDeclaredFields ();
for (int i = 0; i < fields1.length; i++) {
Field f1 = fields1[i];
Field f2 = clazz2.getField (f1.getName ());
collectionsEquals (Attributes.getAttributes (f1), Attributes.getAttributes (f2));
}
}
} ././@LongLink 100644 0 0 150 10464315317 10253 L ustar 0 0 commons-attributes-2.2/unittest/src/test/org/apache/commons/attributes/test/AttributeIndexTestCase.java commons-attributes-2.2/unittest/src/test/org/apache/commons/attributes/test/AttributeIndexTestCase.j100644 0 0 10107 10464315316 31404 0 ustar 0 0 /*
* Copyright 2003-2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.attributes.test;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Constructor;
import java.io.File;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.Collection;
import java.util.Iterator;
import org.apache.commons.attributes.Attributes;
import org.apache.commons.attributes.AttributeIndex;
import junit.framework.TestCase;
public class AttributeIndexTestCase extends TestCase {
private URLClassLoader cl = null;
private AttributeIndex index = null;
private Class TESTCLASS = null;
private Class TESTCLASS_INNER = null;
private Class TESTATTRIBUTE = null;
public void setUp () throws Exception {
cl = new URLClassLoader (new URL[]{new File ("target/cl2/cl2.jar").toURL ()}, getClass().getClassLoader ());
index = new AttributeIndex (cl);
TESTCLASS = cl.loadClass ("TestClass");
TESTCLASS_INNER = cl.loadClass ("TestClass$Inner");
TESTATTRIBUTE = cl.loadClass ("TestAttribute");
}
public void testAttributeIndexCompatible () throws Exception {
Collection classes = index.getClassesWithAttribute ("TestAttribute");
System.out.println (classes);
assertEquals (2, classes.size ());
assertTrue (classes.contains ("TestClass"));
assertTrue (classes.contains ("TestClass.Inner"));
}
public void testClasses () throws Exception {
Collection classes = index.getClasses (TESTATTRIBUTE);
System.out.println (classes);
assertEquals (2, classes.size ());
assertTrue (classes.contains (TESTCLASS));
assertTrue (classes.contains (TESTCLASS_INNER));
}
public void testMethods () throws Exception {
Collection methods = index.getMethods (TESTATTRIBUTE);
System.out.println (methods);
assertEquals (1, methods.size ());
assertTrue (methods.contains (TESTCLASS.getDeclaredMethods()[0]));
}
public void testConstructors () throws Exception {
Collection ctors = index.getConstructors (TESTATTRIBUTE);
System.out.println (ctors);
assertEquals (1, ctors.size ());
assertTrue (ctors.contains (TESTCLASS.getDeclaredConstructors()[0]));
}
public void testConstructorParameters () throws Exception {
Collection ctors = index.getConstructorParameters (TESTATTRIBUTE);
System.out.println (ctors);
assertEquals (1, ctors.size ());
assertTrue (ctors.contains (new AttributeIndex.ConstructorParameter (TESTCLASS.getDeclaredConstructors()[0], 0)));
}
public void testMethodParameters () throws Exception {
Collection methods = index.getMethodParameters (TESTATTRIBUTE);
System.out.println (methods);
assertEquals (1, methods.size ());
assertTrue (methods.contains (new AttributeIndex.MethodParameter (TESTCLASS.getDeclaredMethods()[0], 0)));
}
public void testMethodsReturning () throws Exception {
Collection methods = index.getMethodsReturning (TESTATTRIBUTE);
System.out.println (methods);
assertEquals (1, methods.size ());
assertTrue (methods.contains (TESTCLASS.getDeclaredMethods()[0]));
}
public void testFields () throws Exception {
Collection fields = index.getFields (TESTATTRIBUTE);
System.out.println (fields);
assertEquals (1, fields.size ());
assertTrue (fields.contains (TESTCLASS.getDeclaredFields()[0]));
}
} commons-attributes-2.2/unittest/src/test/org/apache/commons/attributes/test/samples/SampleIF1.java 100644 0 0 2175 10464315316 30660 0 ustar 0 0 /*
* Copyright 2003-2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.attributes.test.samples;
/**
* @@Dependency ( SampleService.class, "sample-if-1-c" )
*/
public interface SampleIF1 {
/**
* @@Dependency ( SampleService.class, "sample-if-1" )
* @@ThreadSafe ()
*/
public void someMethod (int parameter);
/**
* @@.return Dependency ( SampleService.class, "sample-if-return" )
* @@.param2 Dependency ( SampleService.class, "sample-if-param-2" )
*/
public Integer methodWithAttributes (int param1, int param2);
} commons-attributes-2.2/unittest/src/test/org/apache/commons/attributes/test/samples/Dependency.java 100644 0 0 2770 10464315317 31217 0 ustar 0 0 /*
* Copyright 2003-2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.attributes.test.samples;
/**
* Declares a dependency.
*
* @@org.apache.commons.attributes.Inheritable()
*/
public class Dependency {
private final Class clazz;
private final String name;
public Dependency (Class clazz, String name) {
this.clazz = clazz;
this.name = name;
}
public Class getDependencyClass () {
return clazz;
}
public String getDependencyName () {
return name;
}
public boolean equals (Object o) {
return o instanceof Dependency &&
((Dependency) o).clazz == clazz &&
((Dependency) o).name.equals (name);
}
public int hashCode () {
return clazz.hashCode () ^ name.hashCode ();
}
public String toString () {
return "[Dependency on " + clazz.getName () + " via name \"" + name + "\"]";
}
} ././@LongLink 100644 0 0 145 10464315317 10257 L ustar 0 0 commons-attributes-2.2/unittest/src/test/org/apache/commons/attributes/test/samples/SuperSample.java commons-attributes-2.2/unittest/src/test/org/apache/commons/attributes/test/samples/SuperSample.java100644 0 0 3156 10464315317 31400 0 ustar 0 0 /*
* Copyright 2003-2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.attributes.test.samples;
/**
* @@Dependency ( SampleService.class, "super-sample" )
*/
public class SuperSample {
/**
* @@ThreadSafe ()
* @@Dependency ( SampleService.class, "super-field" )
*/
public Object field;
/**
* @@Dependency ( SampleService.class, "super-noattrs" )
*/
public Object noAttributesInSubClass;
/**
* @@Dependency ( SampleService.class, "sample-ctor1" )
*/
public SuperSample () {
}
/**
* @@Dependency ( SampleService.class, "sample-ctor2" )
* @@.array ThreadSafe()
*/
public SuperSample (String input, String[][] array) {
}
/**
* @@Dependency ( SampleService.class, "super-some-method-sample" )
* @@ThreadSafe ()
*/
public void someMethod (int parameter) {
}
/**
* @@Dependency ( SampleService.class, "super-privateMethod" )
*/
private void privateMethod () {
}
} commons-attributes-2.2/unittest/src/test/org/apache/commons/attributes/test/samples/SampleIF2.java 100644 0 0 1625 10464315317 30661 0 ustar 0 0 /*
* Copyright 2003-2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.attributes.test.samples;
/**
* @@Dependency ( SampleService.class, "sample-if-2-c" )
*/
public interface SampleIF2 {
/**
* @@Dependency ( SampleService.class, "sample-if-2" )
* @@ThreadSafe ()
*/
public void someMethod (int parameter);
} ././@LongLink 100644 0 0 146 10464315317 10260 L ustar 0 0 commons-attributes-2.2/unittest/src/test/org/apache/commons/attributes/test/samples/SampleIFJoin.java commons-attributes-2.2/unittest/src/test/org/apache/commons/attributes/test/samples/SampleIFJoin.jav100644 0 0 1341 10464315317 31251 0 ustar 0 0 /*
* Copyright 2003-2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.attributes.test.samples;
public interface SampleIFJoin extends SampleIF1, SampleIF2 {
} commons-attributes-2.2/unittest/src/test/org/apache/commons/attributes/test/samples/ThreadSafe.java 100644 0 0 1702 10464315317 31141 0 ustar 0 0 /*
* Copyright 2003-2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.attributes.test.samples;
public class ThreadSafe {
public ThreadSafe () {
}
public boolean equals (Object o) {
return o instanceof ThreadSafe;
}
public int hashCode () {
return 0;
}
public String toString () {
return "[ThreadSafe]";
}
} ././@LongLink 100644 0 0 147 10464315317 10261 L ustar 0 0 commons-attributes-2.2/unittest/src/test/org/apache/commons/attributes/test/samples/SampleService.java commons-attributes-2.2/unittest/src/test/org/apache/commons/attributes/test/samples/SampleService.ja100644 0 0 1304 10464315317 31344 0 ustar 0 0 /*
* Copyright 2003-2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.attributes.test.samples;
public interface SampleService {} ././@LongLink 100644 0 0 147 10464315317 10261 L ustar 0 0 commons-attributes-2.2/unittest/src/test/org/apache/commons/attributes/test/samples/BeanAttribute.java commons-attributes-2.2/unittest/src/test/org/apache/commons/attributes/test/samples/BeanAttribute.ja100644 0 0 4273 10464315317 31343 0 ustar 0 0 /*
* Copyright 2003-2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.attributes.test.samples;
import org.apache.commons.attributes.DefaultSealable;
import org.apache.commons.attributes.Sealable;
/**
* A sample attribute with bean-like properties. Used to test the
* named parameter syntax.
*/
public class BeanAttribute extends DefaultSealable {
private final int number;
private final String string;
private String name;
private int anotherNumber;
public BeanAttribute (int number, String string) {
this.number = number;
this.string = string;
}
public int getNumber () {
return number;
}
public String getString () {
return string;
}
public String getName () {
return name;
}
public int getAnotherNumber () {
return anotherNumber;
}
public void setAnotherNumber (int anotherNumber) {
checkSealed ();
this.anotherNumber = anotherNumber;
}
public void setName (String name) {
checkSealed ();
this.name = name;
}
public boolean equals (Object o) {
return o instanceof BeanAttribute &&
((BeanAttribute) o).string.equals (string) &&
((BeanAttribute) o).anotherNumber == anotherNumber &&
((BeanAttribute) o).number == number &&
((BeanAttribute) o).name.equals (name);
}
public int hashCode () {
return string.hashCode ();
}
public String toString () {
return "[BeanAttribute " + number + ", " + string + "; " + name + ", " + anotherNumber + "\"]";
}
} ././@LongLink 100644 0 0 147 10464315317 10261 L ustar 0 0 commons-attributes-2.2/unittest/src/test/org/apache/commons/attributes/test/samples/RuntimeSample.java commons-attributes-2.2/unittest/src/test/org/apache/commons/attributes/test/samples/RuntimeSample.ja100644 0 0 6432 10464315317 31376 0 ustar 0 0 /*
* Copyright 2003-2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.attributes.test.samples;
import org.apache.commons.attributes.Attributes;
import org.apache.commons.attributes.RuntimeAttributeRepository;
public class RuntimeSample extends SuperSample implements SampleIFJoin {
static {
try {
RuntimeAttributeRepository rar = new RuntimeAttributeRepository (RuntimeSample.class);
rar.addClassAttribute (new ThreadSafe ());
rar.addClassAttribute (new Dependency ( SampleService.class, "sample" ));
rar.addFieldAttribute ("field", new ThreadSafe ());
rar.addMethodAttribute ("someMethod", new Class[]{}, new Dependency ( SampleService.class, "sample-some-method1" ));
rar.addParameterAttribute ("methodWithAttributes", new Class[]{ Integer.TYPE, Integer.TYPE }, 1, new ThreadSafe ());
rar.addReturnAttribute ("methodWithAttributes", new Class[]{ Integer.TYPE, Integer.TYPE }, new Dependency ( SampleService.class, "sample-return" ));
rar.addMethodAttribute ("someMethod", new Class[]{ Integer.TYPE }, new Dependency ( SampleService.class, "sample-some-method2" ));
BeanAttribute ba = new BeanAttribute (1, "a");
ba.setAnotherNumber (56 - 14);
ba.setName ("Smith, John \"Agent\"");
rar.addMethodAttribute ("methodWithNamedParameters", new Class[]{}, ba);
rar.addMethodAttribute ("privateMethod", new Class[]{}, new Dependency ( SampleService.class, "sample-privateMethod" ));
Attributes.setAttributes (rar);
} catch (Exception e) {
throw new Error ("Unable to set attribute information: " + e.toString ());
}
}
public Object field;
public Object noAttributesInSubClass;
public void someMethod () {
}
public Integer methodWithAttributes (int param1, int param2) {
return null;
}
public void someMethod (int parameter) {
}
public void methodWithNamedParameters () {
}
public void methodWithNoAttributes () {
}
private void privateMethod () {
}
public static class InnerSample {
static {
try {
RuntimeAttributeRepository rar = new RuntimeAttributeRepository (RuntimeSample.InnerSample.class);
rar.addClassAttribute (new Dependency ( SampleService.class, "inner-sample" ));
Attributes.setAttributes (rar);
} catch (Exception e) {
throw new Error ("Unable to set attribute information: " + e.toString ());
}
}
}
} commons-attributes-2.2/unittest/src/test/org/apache/commons/attributes/test/samples/Sample.java 100644 0 0 3605 10464315317 30360 0 ustar 0 0 /*
* Copyright 2003-2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.attributes.test.samples;
/**
* @@ThreadSafe ()
* @@Dependency ( SampleService.class, "sample" )
*/
public class Sample extends SuperSample implements SampleIFJoin {
/**
* @@ThreadSafe ()
*/
public Object field;
public Object noAttributesInSubClass;
/**
* @@Dependency ( SampleService.class, "sample-some-method1" )
*/
public void someMethod () {
}
/**
* @@.param2 ThreadSafe ()
* @@.return Dependency ( SampleService.class, "sample-return" )
*/
public Integer methodWithAttributes (int param1, int param2) {
return null;
}
/**
* @@Dependency ( SampleService.class, "sample-some-method2" )
*/
public void someMethod (int parameter) {
}
/**
* @@BeanAttribute ( 1, "a", anotherNumber = (56 - 14), name = "Smith, John \"Agent\"" )
*/
public void methodWithNamedParameters () {
}
public void methodWithNoAttributes () {
}
/**
* @@Dependency ( SampleService.class, "inner-sample" )
*/
public static class InnerSample {
}
/**
* @@Dependency ( SampleService.class, "sample-privateMethod" )
*/
private void privateMethod () {
}
} commons-attributes-2.2/unittest/src/test/org/apache/commons/attributes/test/samples/Sample2.java 100644 0 0 1656 10464315317 30446 0 ustar 0 0 /*
* Copyright 2003-2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.attributes.test.samples;
public class Sample2 {
public Object aaaa;
public Sample2 () {
}
public Sample2 (String input) {
}
public void someMethod () {
}
public void someMethod (int parameter) {
}
} commons-attributes-2.2/unittest/src/test/org/apache/commons/attributes/test/AttributesTestCase.java 100644 0 0 17146 10464315317 31302 0 ustar 0 0 /*
* Copyright 2003-2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.attributes.test;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Constructor;
import java.io.File;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.Collection;
import java.util.Iterator;
import org.apache.commons.attributes.Attributes;
import org.apache.commons.attributes.AttributeIndex;
import org.apache.commons.attributes.test.samples.*;
import junit.framework.TestCase;
public class AttributesTestCase extends TestCase {
public void testClassAttributes () throws Exception {
/**
* @Dependency ( SampleService.class, "super-sample" )
*/
Class c = SuperSample.class;
assertEquals (1, Attributes.getAttributes (c).size ());
assertEquals (1, Attributes.getAttributes (c, Dependency.class).size ());
assertTrue (Attributes.hasAttributeType (c, Dependency.class));
assertTrue (Attributes.hasAttribute (c, new Dependency ( SampleService.class, "super-sample" )));
}
public void testMethodAttributes () throws Exception {
/**
* @Dependency ( SampleService.class, "super-some-method-sample" )
* @ThreadSafe ()
*/
Method m = SuperSample.class.getMethod ("someMethod", new Class[]{ Integer.TYPE });
assertEquals (2, Attributes.getAttributes (m).size ());
assertEquals (1, Attributes.getAttributes (m, Dependency.class).size ());
assertEquals (1, Attributes.getAttributes (m, ThreadSafe.class).size ());
assertTrue (Attributes.hasAttributeType (m, Dependency.class));
assertTrue (Attributes.hasAttributeType (m, ThreadSafe.class));
assertTrue (Attributes.hasAttribute (m, new Dependency ( SampleService.class, "super-some-method-sample" )));
assertTrue (Attributes.hasAttribute (m, new ThreadSafe ()));
}
public void testFieldAttributes () throws Exception {
/**
* @ThreadSafe ()
* @Dependency ( SampleService.class, "super-field" )
*/
Field f = SuperSample.class.getField ("field");
assertEquals (2, Attributes.getAttributes (f).size ());
assertEquals (1, Attributes.getAttributes (f, ThreadSafe.class).size ());
assertEquals (1, Attributes.getAttributes (f, Dependency.class).size ());
assertTrue (Attributes.hasAttribute (f, new ThreadSafe ()));
assertTrue (Attributes.hasAttribute (f, new Dependency ( SampleService.class, "super-field" ) ));
assertTrue (Attributes.hasAttributeType (f, ThreadSafe.class));
assertTrue (Attributes.hasAttributeType (f, Dependency.class));
}
public void testDefaultConstructorAttributes () throws Exception {
/**
* @Dependency ( SampleService.class, "sample-ctor1" )
*/
Constructor c = SuperSample.class.getDeclaredConstructor (new Class[0]);
assertEquals (1, Attributes.getAttributes (c).size ());
assertEquals (1, Attributes.getAttributes (c, Dependency.class).size ());
assertTrue (Attributes.hasAttributeType (c, Dependency.class));
assertTrue (Attributes.hasAttribute (c, new Dependency ( SampleService.class, "sample-ctor1" )));
}
public void testConstructorAttributes () throws Exception {
/**
* @Dependency ( SampleService.class, "sample-ctor2" )
*/
Constructor c = SuperSample.class.getDeclaredConstructor (new Class[]{ String.class, (new String[0][0]).getClass () } );
assertEquals (1, Attributes.getAttributes (c).size ());
assertEquals (1, Attributes.getAttributes (c, Dependency.class).size ());
assertTrue (Attributes.hasAttributeType (c, Dependency.class));
assertTrue (Attributes.hasAttribute (c, new Dependency ( SampleService.class, "sample-ctor2" )));
assertEquals (1, Attributes.getParameterAttributes (c, 1).size ());
assertEquals (1, Attributes.getParameterAttributes (c, 1, ThreadSafe.class).size ());
assertTrue (Attributes.hasParameterAttributeType (c, 1, ThreadSafe.class));
assertTrue (Attributes.hasParameterAttribute (c, 1, new ThreadSafe ()));
}
public void testParameterAndReturnAttributes () throws Exception {
Method m = Sample.class.getMethod ("methodWithAttributes", new Class[]{ Integer.TYPE, Integer.TYPE });
assertEquals (0, Attributes.getAttributes (m).size ());
assertEquals (2, Attributes.getReturnAttributes (m).size ());
assertTrue (Attributes.hasReturnAttribute (m, new Dependency ( SampleService.class, "sample-return" ) ));
assertTrue (Attributes.hasReturnAttribute (m, new Dependency ( SampleService.class, "sample-if-return" ) ));
assertEquals (0, Attributes.getParameterAttributes (m, 0).size ());
assertEquals (2, Attributes.getParameterAttributes (m, 1).size ());
assertTrue (Attributes.hasParameterAttribute (m, 1, new Dependency ( SampleService.class, "sample-if-param-2" ) ));
assertTrue (Attributes.hasParameterAttribute (m, 1, new ThreadSafe () ));
}
public void testNoAttributes () throws Exception {
Method m = Sample.class.getMethod ("methodWithNoAttributes", new Class[0]);
assertEquals (0, Attributes.getAttributes (m).size ());
}
/**
* Ensure that loading a class with the same name from two different class loaders
* won't mess up the attribute cache.
*/
public void testClassLoaderKeying () throws Exception {
URLClassLoader cl1 = new URLClassLoader (new URL[]{new File ("target/cl1/").toURL ()}, getClass().getClassLoader ());
URLClassLoader cl2 = new URLClassLoader (new URL[]{new File ("target/cl2/").toURL ()}, getClass().getClassLoader ());
Class cl1Class = cl1.loadClass ("TestClass");
Class cl2Class = cl2.loadClass ("TestClass");
assertEquals ("[[TestAttribute 1]]", Attributes.getAttributes (cl1Class).toString ());
assertEquals ("[[TestAttribute TestClass]]", Attributes.getAttributes (cl2Class).toString ());
}
public void testInnerClasses () throws Exception {
Class c = Sample.InnerSample.class;
assertEquals (1, Attributes.getAttributes (c).size ());
assertEquals (1, Attributes.getAttributes (c, Dependency.class).size ());
assertTrue (Attributes.hasAttributeType (c, Dependency.class));
assertTrue (Attributes.hasAttribute (c, new Dependency ( SampleService.class, "inner-sample" )));
}
public void testNamedParameters () throws Exception {
Method m = Sample.class.getMethod ("methodWithNamedParameters", new Class[]{ });
assertEquals (1, Attributes.getAttributes (m).size ());
assertEquals (1, Attributes.getAttributes (m, BeanAttribute.class).size ());
assertTrue (Attributes.hasAttributeType (m, BeanAttribute.class));
BeanAttribute ba = new BeanAttribute (1, "a");
ba.setName ("Smith, John \"Agent\"");
ba.setAnotherNumber (42);
assertTrue (Attributes.hasAttribute (m, ba));
}
} ././@LongLink 100644 0 0 163 10464315317 10257 L ustar 0 0 commons-attributes-2.2/unittest/src/test/org/apache/commons/attributes/test/ParameterIndexOutOfBoundsTestCase.java commons-attributes-2.2/unittest/src/test/org/apache/commons/attributes/test/ParameterIndexOutOfBound100644 0 0 5734 10464315317 31435 0 ustar 0 0 /*
* Copyright 2003-2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.attributes.test;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import junit.framework.TestCase;
import org.apache.commons.attributes.Attributes;
import org.apache.commons.attributes.ParameterIndexOutOfBoundsException;
public class ParameterIndexOutOfBoundsTestCase extends TestCase {
public static class Attr {}
public static class Inner {
/**
* @@ParameterIndexOutOfBoundsTestCase.Attr()
*/
public Inner (int arg1) {}
public void method (int arg1, int arg2) {}
}
private Method m;
private Constructor c;
public void setUp () throws Exception {
m = Inner.class.getMethod ("method", new Class[]{ Integer.TYPE, Integer.TYPE });
c = Inner.class.getConstructor (new Class[]{ Integer.TYPE });
}
public void testMethodInRange () throws Exception {
Attributes.getParameterAttributes (m, 0);
Attributes.getParameterAttributes (m, 1);
}
public void testConstructorInRange () throws Exception {
Attributes.getParameterAttributes (c, 0);
}
public void testMethodOutOfRange () throws Exception {
try {
Attributes.getParameterAttributes (m, -1);
fail ();
} catch (ParameterIndexOutOfBoundsException e) {
assertEquals ("-1", e.getMessage ());
}
try {
Attributes.getParameterAttributes (m, 2);
fail ();
} catch (ParameterIndexOutOfBoundsException e) {
assertEquals ("2. public void org.apache.commons.attributes.test.ParameterIndexOutOfBoundsTestCase$Inner.method(int,int) has 2 parameters.", e.getMessage ());
}
}
public void testConstructorOutOfRange () throws Exception {
try {
Attributes.getParameterAttributes (c, -1);
fail ();
} catch (ParameterIndexOutOfBoundsException e) {
assertEquals ("-1", e.getMessage ());
}
try {
Attributes.getParameterAttributes (c, 1);
fail ();
} catch (ParameterIndexOutOfBoundsException e) {
assertEquals ("1. public org.apache.commons.attributes.test.ParameterIndexOutOfBoundsTestCase$Inner(int) has 1 parameters.", e.getMessage ());
}
}
} ././@LongLink 100644 0 0 154 10464315317 10257 L ustar 0 0 commons-attributes-2.2/unittest/src/test/org/apache/commons/attributes/test/CircularDependencyTestCase.java commons-attributes-2.2/unittest/src/test/org/apache/commons/attributes/test/CircularDependencyTestCa100644 0 0 3730 10464315317 31421 0 ustar 0 0 /*
* Copyright 2003-2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.attributes.test;
import junit.framework.TestCase;
import org.apache.commons.attributes.Attributes;
import org.apache.commons.attributes.CircularDependencyError;
public class CircularDependencyTestCase extends TestCase {
/**
* @@CircularDependencyTestCase.AttributeTwo()
*/
public static class AttributeOne {}
public static class AttributeTwo extends AttributeOne {}
public void testCircularDependencies () throws Exception {
try {
// This should fail, because when loading attributes for Two,
// the runtime has to get inheritable attributes from One.
// This means it has to check if Two is Inheritable. But it
// is already loading Two -> Circular dependency.
Attributes.getAttributes (AttributeTwo.class);
fail ();
} catch (CircularDependencyError cde) {
// OK.
assertEquals ("org.apache.commons.attributes.test.CircularDependencyTestCase$AttributeTwo:" +
"org.apache.commons.attributes.test.CircularDependencyTestCase$AttributeTwo -> " +
"org.apache.commons.attributes.test.CircularDependencyTestCase$AttributeOne -> " +
"org.apache.commons.attributes.test.CircularDependencyTestCase$AttributeTwo", cde.getMessage ());
}
}
} ././@LongLink 100644 0 0 145 10464315317 10257 L ustar 0 0 commons-attributes-2.2/unittest/src/test/org/apache/commons/attributes/test/InheritableTestCase.java commons-attributes-2.2/unittest/src/test/org/apache/commons/attributes/test/InheritableTestCase.java100644 0 0 23667 10464315317 31407 0 ustar 0 0 /*
* Copyright 2003-2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.attributes.test;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Constructor;
import java.io.File;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.Collection;
import java.util.Iterator;
import org.apache.commons.attributes.Attributes;
import org.apache.commons.attributes.AttributeIndex;
import junit.framework.TestCase;
public class InheritableTestCase extends TestCase {
public static interface SampleService {}
/**
* @@InheritableTestCase.InheritableAttribute ("super-sample")
*/
public static class SuperClass {
/**
* @@InheritableTestCase.NonInheritableAttribute ()
* @@InheritableTestCase.InheritableAttribute ( "super-field" )
*/
public Object field;
/**
* @@InheritableTestCase.InheritableAttribute ( "super-noattrs" )
*/
public Object noAttributesInSubClass;
/**
* @@InheritableTestCase.InheritableAttribute ( "sample-ctor1" )
*/
public SuperClass () {
}
/**
* @@InheritableTestCase.InheritableAttribute( "sample-ctor2" )
* @@.array InheritableTestCase.NonInheritableAttribute()
*/
public SuperClass (String input, String[][] array) {
}
/**
* @@InheritableTestCase.InheritableAttribute( "super-some-method-sample" )
* @@InheritableTestCase.NonInheritableAttribute()
*/
public void someMethod (int parameter) {
}
/**
* @@InheritableTestCase.InheritableAttribute( "super-privateMethod" )
*/
private void privateMethod () {
}
}
public static interface JoinedInterface extends InterfaceOne, InterfaceTwo {
}
/**
* @@InheritableTestCase.InheritableAttribute( "sample-if-2-c" )
*/
public static interface InterfaceTwo {
/**
* @@InheritableTestCase.InheritableAttribute( "sample-if-2" )
* @@InheritableTestCase.NonInheritableAttribute()
*/
public void someMethod (int parameter);
}
/**
* @@InheritableTestCase.InheritableAttribute( "sample-if-1-c" )
*/
public static interface InterfaceOne {
/**
* @@InheritableTestCase.InheritableAttribute( "sample-if-1" )
* @@InheritableTestCase.NonInheritableAttribute()
*/
public void someMethod (int parameter);
/**
* @@.return InheritableTestCase.InheritableAttribute("sample-if-return" )
* @@.param2 InheritableTestCase.InheritableAttribute("sample-if-param-2" )
*/
public Integer methodWithAttributes (int param1, int param2);
}
/**
* @@org.apache.commons.attributes.Inheritable()
*/
public static class InheritableAttribute {
private final String name;
public InheritableAttribute(String name) { this.name = name; }
public String getInheritableAttributeName () { return name; }
public boolean equals (Object o) {
return o instanceof InheritableAttribute &&
((InheritableAttribute) o).name.equals (name);
}
public int hashCode () { return name.hashCode (); }
public String toString () { return "[InheritableAttribute \"" + name + "\"]"; }
}
public static class NonInheritableAttribute {
public NonInheritableAttribute() {}
public boolean equals (Object o) { return o instanceof NonInheritableAttribute; }
public int hashCode () { return 0; }
public String toString () { return "[NonInheritableAttribute]"; }
}
/** @@InheritableTestCase.NonInheritableAttribute()
* @@InheritableTestCase.InheritableAttribute( "sample" ) */
public static class Sample extends InheritableTestCase.SuperClass implements JoinedInterface {
/** @@InheritableTestCase.NonInheritableAttribute() */
public Object field;
public Object noAttributesInSubClass;
/** @@InheritableTestCase.InheritableAttribute( "sample-some-method1" ) */
public void someMethod () {}
/** @@InheritableTestCase.InheritableAttribute( "sample-some-method2" ) */
public void someMethod (int parameter) {}
/** @@.param2 InheritableTestCase.NonInheritableAttribute ()
* @@.return InheritableTestCase.InheritableAttribute("sample-return") */
public Integer methodWithAttributes (int param1, int param2) { return null; }
public void methodWithNoAttributes () {}
/** @@InheritableTestCase.InheritableAttribute( "inner-sample" ) */
public static class InnerSample {}
/** @@InheritableTestCase.InheritableAttribute( "sample-privateMethod" ) */
private void privateMethod () {}
}
public void testClassInheritance () throws Exception {
Class c = Sample.class;
assertEquals (5, Attributes.getAttributes (c).size ());
assertEquals (4, Attributes.getAttributes (c, InheritableAttribute.class).size ());
assertTrue (Attributes.hasAttributeType (c, InheritableAttribute.class));
assertTrue (Attributes.hasAttributeType (c, NonInheritableAttribute.class));
assertTrue (Attributes.hasAttribute (c, new InheritableAttribute( "sample" )));
assertTrue (Attributes.hasAttribute (c, new InheritableAttribute( "super-sample" )));
assertTrue (Attributes.hasAttribute (c, new InheritableAttribute( "sample-if-1-c" )));
assertTrue (Attributes.hasAttribute (c, new InheritableAttribute( "sample-if-2-c" )));
assertTrue (Attributes.hasAttribute (c, new NonInheritableAttribute()));
}
public void testMethodInheritance () throws Exception {
Method m = Sample.class.getMethod ("someMethod", new Class[]{ Integer.TYPE });
assertEquals (4, Attributes.getAttributes (m).size ());
assertEquals (4, Attributes.getAttributes (m, InheritableAttribute.class).size ());
assertTrue (Attributes.hasAttributeType (m, InheritableAttribute.class));
assertTrue (Attributes.hasAttribute (m, new InheritableAttribute( "super-some-method-sample" )));
assertTrue (Attributes.hasAttribute (m, new InheritableAttribute( "sample-some-method2" ) ));
assertTrue (Attributes.hasAttribute (m, new InheritableAttribute( "sample-if-1" ) ));
assertTrue (Attributes.hasAttribute (m, new InheritableAttribute( "sample-if-2" ) ));
}
public void testPrivateMethodNonInheritance () throws Exception {
Method m = Sample.class.getDeclaredMethod ("privateMethod", new Class[]{});
assertEquals (1, Attributes.getAttributes (m).size ());
assertEquals (1, Attributes.getAttributes (m, InheritableAttribute.class).size ());
assertTrue (Attributes.hasAttributeType (m, InheritableAttribute.class));
assertTrue (Attributes.hasAttribute (m, new InheritableAttribute( "sample-privateMethod" ) ));
m = SuperClass.class.getDeclaredMethod ("privateMethod", new Class[]{});
assertEquals (1, Attributes.getAttributes (m).size ());
assertEquals (1, Attributes.getAttributes (m, InheritableAttribute.class).size ());
assertTrue (Attributes.hasAttributeType (m, InheritableAttribute.class));
assertTrue (Attributes.hasAttribute (m, new InheritableAttribute( "super-privateMethod" ) ));
}
public void testFieldNonInheritance () throws Exception {
Field f = SuperClass.class.getField ("field");
assertEquals (2, Attributes.getAttributes (f).size ());
assertEquals (1, Attributes.getAttributes (f, NonInheritableAttribute.class).size ());
assertEquals (1, Attributes.getAttributes (f, InheritableAttribute.class).size ());
assertTrue (Attributes.hasAttributeType (f, NonInheritableAttribute.class));
assertTrue (Attributes.hasAttributeType (f, InheritableAttribute.class));
assertTrue (Attributes.hasAttribute (f, new NonInheritableAttribute()));
assertTrue (Attributes.hasAttribute (f, new InheritableAttribute( "super-field" )));
f = Sample.class.getField ("field");
assertEquals (1, Attributes.getAttributes (f).size ());
assertEquals (1, Attributes.getAttributes (f, NonInheritableAttribute.class).size ());
assertTrue (Attributes.hasAttributeType (f, NonInheritableAttribute.class));
assertTrue (Attributes.hasAttribute (f, new NonInheritableAttribute()));
f = SuperClass.class.getField ("noAttributesInSubClass");
assertEquals (1, Attributes.getAttributes (f).size ());
assertEquals (1, Attributes.getAttributes (f, InheritableAttribute.class).size ());
assertTrue (Attributes.hasAttribute (f, new InheritableAttribute( "super-noattrs" )));
assertTrue (Attributes.hasAttributeType (f, InheritableAttribute.class));
f = Sample.class.getField ("noAttributesInSubClass");
assertEquals (0, Attributes.getAttributes (f).size ());
assertEquals (0, Attributes.getAttributes (f, InheritableAttribute.class).size ());
assertTrue (!Attributes.hasAttribute (f, new InheritableAttribute( "super-noattrs" )));
assertTrue (!Attributes.hasAttributeType (f, InheritableAttribute.class));
}
} commons-attributes-2.2/unittest/src/test/org/apache/commons/attributes/test/InnerClassTestCase.java 100644 0 0 5407 10464315317 31172 0 ustar 0 0 /*
* Copyright 2003-2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.attributes.test;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import junit.framework.TestCase;
import org.apache.commons.attributes.Attributes;
import org.apache.commons.attributes.InvalidAttributeTargetError;
public class InnerClassTestCase extends TestCase {
public static class AnAttribute {}
public static class Internal {
}
public static class InnerClassSample {
public static class InternalOfSample {
}
/**
* @@InnerClassTestCase.AnAttribute()
*/
public void method (Internal i) {
}
/**
* @@InnerClassTestCase.AnAttribute()
*/
public void method2 (InternalOfSample i) {
}
/**
* @@InnerClassTestCase.AnAttribute()
*/
public Internal field;
/**
* @@InnerClassTestCase.AnAttribute()
*/
public InternalOfSample field2;
}
public void testInnerClassAttributesOnMethod () throws Exception {
Class sample = InnerClassSample.class;
Method method = sample.getMethod ("method", new Class[]{ Internal.class });
assertTrue (Attributes.getAttributes (method, AnAttribute.class).size () > 0);
}
public void testInnerClassAttributesOnMethod2 () throws Exception {
Class sample = InnerClassSample.class;
Method method2 = sample.getMethod ("method2", new Class[]{ InnerClassSample.InternalOfSample.class });
assertTrue (Attributes.getAttributes (method2, AnAttribute.class).size () > 0);
}
public void testInnerClassAttributesOnField () throws Exception {
Class sample = InnerClassSample.class;
Field field = sample.getField ("field");
assertTrue (Attributes.getAttributes (field, AnAttribute.class).size () > 0);
}
public void testInnerClassAttributesOnField2 () throws Exception {
Class sample = InnerClassSample.class;
Field field2 = sample.getField ("field2");
assertTrue (Attributes.getAttributes (field2, AnAttribute.class).size () > 0);
}
} commons-attributes-2.2/unittest/src/cl1/TestClass.java 100644 0 0 1257 10464315316 20250 0 ustar 0 0 /*
* Copyright 2003-2004 The Apache Software Foundation
*
* Licensed 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.
*/
/**
* @@TestAttribute ("1")
*/
public class TestClass {
} commons-attributes-2.2/unittest/src/cl1/TestAttribute.java 100644 0 0 1621 10464315317 21142 0 ustar 0 0 /*
* Copyright 2003-2004 The Apache Software Foundation
*
* Licensed 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.
*/
public class TestAttribute {
private final String key;
public TestAttribute (String key) {
this.key = key;
}
public String getKey () {
return key;
}
public String toString () {
return "[TestAttribute " + key + "]";
}
} commons-attributes-2.2/unittest/src/java/dummy.txt 100644 0 0 224 10464315317 17610 0 ustar 0 0 Maven requires a src/java/ directory, and CVS keeps deleting empty directories.
So this file is here just to keep this directory from being pruned. commons-attributes-2.2/unittest/project.properties 100644 0 0 1560 10464315316 20013 0 ustar 0 0 # Copyright 2003-2004 The Apache Software Foundation
#
# Licensed 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.
######################################################################
# Commons-Attributes
######################################################################
org.apache.commons.attributes.enable=true
org.apache.commons.attributes.index.enable=true
commons-attributes-2.2/unittest/maven.xml 100644 0 0 5777 10464315317 16076 0 ustar 0 0
* <taskdef resource="org/apache/commons/attributes/anttasks.properties"/>
*
* <attribute-compiler destDir="temp/"> attributepackages="my.attributes;my.otherattributes"
* <fileset dir="src/" includes="*.java"/>
* </attribute-compiler>
*
*
* Provides an Ant task that preprocesses Java files. The resulting files should then be compiled with the originals in order to enable attributes. ././@LongLink 100644 0 0 146 10464315317 10260 L ustar 0 0 commons-attributes-2.2/compiler/src/java/org/apache/commons/attributes/compiler/AttributeIndexer.java commons-attributes-2.2/compiler/src/java/org/apache/commons/attributes/compiler/AttributeIndexer.jav100644 0 0 15072 10464315317 31365 0 ustar 0 0 /* * Copyright 2003-2005 The Apache Software Foundation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.attributes.compiler; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.File; import java.io.FileOutputStream; import java.io.InputStream; import java.io.PrintWriter; import java.io.PrintStream; import java.net.URL; import java.net.URLClassLoader; import java.util.ArrayList; import java.util.Collection; import java.util.Enumeration; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.jar.JarFile; import java.util.jar.JarEntry; import java.util.jar.JarOutputStream; import org.apache.commons.attributes.AttributeRepositoryClass; import org.apache.commons.attributes.Attributes; import org.apache.commons.attributes.AttributeUtil; import org.apache.commons.attributes.Indexed; import org.apache.tools.ant.AntClassLoader; import org.apache.tools.ant.BuildException; import org.apache.tools.ant.Task; import org.apache.tools.ant.types.FileSet; import org.apache.tools.ant.types.Path; /** * Ant task to compile attribute indexes. Usage: * *
* <taskdef resource="org/apache/commons/attributes/anttasks.properties"/>
*
* <attribute-indexer jarFile="myclasses.jar">
* <classpath>
* ...
* </classpath>
* </attribute-indexer>
*
*
* The task will inspect the classes in the given jar and add a META-INF/attrs.index
* file to it, which contains the index information. The classpath element is required and
* must contain all dependencies for the attributes used.
*/
public class AttributeIndexer extends Task {
private File jarFile;
private List classes = new ArrayList ();
private Path classPath;
private File baseName;
private boolean inMaven = false;
private final static String INDEX_FILENAME = "META-INF/attrs.index";
public AttributeIndexer () {
}
public void setJarfile (File jarFile) {
this.jarFile = jarFile;
}
public void setBaseName (File baseName) {
inMaven = true;
this.baseName = baseName;
}
public Path createClasspath () {
this.classPath = new Path(project);
return classPath;
}
private static final String SUFFIX = "$__attributeRepository.class";
protected void copyEntry (JarFile jar, JarEntry entry, JarOutputStream outputStream) throws Exception {
outputStream.putNextEntry (entry);
if (!entry.isDirectory ()) {
InputStream is = new BufferedInputStream (jar.getInputStream (entry));
try {
byte[] buffer = new byte[16384];
while (true) {
int numRead = is.read (buffer, 0, 16384);
if (numRead == 0 || numRead == -1) {
break;
}
outputStream.write (buffer, 0, numRead);
}
} finally {
is.close ();
}
}
}
protected void findJarFile () throws BuildException {
File[] allFiles = baseName.getParentFile ().listFiles ();
if (allFiles == null) {
throw new BuildException ("Unable to find any file with base name " + baseName.getName ()
+ " in " + baseName.getParentFile ().getPath ());
}
long newestDate = 0;
for (int i = 0; i < allFiles.length; i++) {
String name = allFiles[i].getName ();
if (name.startsWith (baseName.getName ()) && name.endsWith (".jar") &&
allFiles[i].lastModified () > newestDate) {
jarFile = allFiles[i];
newestDate = allFiles[i].lastModified ();
}
}
if (jarFile == null) {
throw new BuildException ("Unable to find any file with base name " + baseName.getName ()
+ " in " + baseName.getParentFile ().getPath ());
}
}
public void execute () throws BuildException {
if (inMaven) {
findJarFile ();
}
if (!jarFile.exists ()) {
log ("Can't find " + jarFile.getPath ());
return;
}
try {
log ("Creating attribute index for " + jarFile.getPath ());
JarFile jar = new JarFile (jarFile);
File newJarFile = new File (jarFile.getPath () + ".new");
JarOutputStream output = new JarOutputStream (new FileOutputStream (newJarFile));
try {
Enumeration e = jar.entries ();
while (e.hasMoreElements ()) {
JarEntry entry = (JarEntry) e.nextElement ();
if (!entry.isDirectory ()) {
String className = entry.getName ();
if (className.endsWith (SUFFIX)) {
className = className.replace ('/', '.').replace ('\\', '.').substring (0, className.length () - SUFFIX.length ());
classes.add (className);
}
}
if (!entry.getName ().equals (INDEX_FILENAME)) {
copyEntry (jar, entry, output);
}
}
output.putNextEntry (new JarEntry (INDEX_FILENAME));
Iterator attrs = classes.iterator ();
while (attrs.hasNext ()) {
String className = (String) attrs.next ();
output.write (("Class: " + className + "\n").getBytes ());
}
} finally {
output.close ();
jar.close ();
}
jarFile.delete ();
newJarFile.renameTo (jarFile);
} catch (Exception e) {
e.printStackTrace ();
throw new BuildException (e.toString ());
}
}
} commons-attributes-2.2/compiler/src/java/org/apache/commons/attributes/anttasks.properties 100644 0 0 1507 10464315316 27512 0 ustar 0 0 #
# Copyright 2003-2004 The Apache Software Foundation
#
# Licensed 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.
#
attribute-compiler=org.apache.commons.attributes.compiler.AttributeCompiler
attribute-indexer=org.apache.commons.attributes.compiler.AttributeIndexer
attribute-validator=org.apache.commons.attributes.validation.AttributeValidatorTask ././@LongLink 100644 0 0 152 10464315317 10255 L ustar 0 0 commons-attributes-2.2/compiler/src/java/org/apache/commons/attributes/validation/AttributeValidator.java commons-attributes-2.2/compiler/src/java/org/apache/commons/attributes/validation/AttributeValidator100644 0 0 2346 10464315317 31435 0 ustar 0 0 /*
* Copyright 2003-2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.attributes.validation;
import java.util.Set;
/**
* Validates that a set of classes have the correct attributes
* attached to them. This interface must be implemented by the
* validation rules given to the {@link AttributeValidatorTask}.
*
* @since 2.1
*/
public interface AttributeValidator {
/**
* Validates a set of classes.
*
* @param classes the classes to validate.
* @throws ValidationException if one or more classes have
* an invalid set of attributes.
* @since 2.1
*/
public void validate (Set classes) throws ValidationException;
} ././@LongLink 100644 0 0 156 10464315317 10261 L ustar 0 0 commons-attributes-2.2/compiler/src/java/org/apache/commons/attributes/validation/AttributeValidatorTask.java commons-attributes-2.2/compiler/src/java/org/apache/commons/attributes/validation/AttributeValidator100644 0 0 15350 10464315317 31454 0 ustar 0 0 /*
* Copyright 2003-2005 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.attributes.validation;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.PrintStream;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.jar.JarFile;
import java.util.jar.JarEntry;
import java.util.jar.JarOutputStream;
import org.apache.commons.attributes.AttributeRepositoryClass;
import org.apache.commons.attributes.Attributes;
import org.apache.commons.attributes.AttributeUtil;
import org.apache.commons.attributes.Indexed;
import org.apache.tools.ant.AntClassLoader;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Task;
import org.apache.tools.ant.types.FileSet;
import org.apache.tools.ant.types.Path;
/**
* Ant task that validates attributes. Usage:
*
*
* <taskdef resource="org/apache/commons/attributes/anttasks.properties"/>
*
* <attribute-validator jarFile="myclasses.jar">
* <classpath>
* ...
* </classpath>
* <validator class="my.Validator"/>
* <validator class="my.other.Validator"/>
* </attribute-validator>
*
*
* The task will run the validator(s) with the classes the given jar file.
*/
public class AttributeValidatorTask extends Task {
private File jarFile;
private List classes = new ArrayList ();
private List validators = new ArrayList ();
private Path classPath;
private File baseName;
private boolean inMaven = false;
public static class Validator {
private String className;
public void setClass (String className) {
this.className = className;
}
public String getClassName () {
return className;
}
}
public void setJarfile (File jarFile) {
this.jarFile = jarFile;
}
public void setBaseName (File baseName) {
inMaven = true;
this.baseName = baseName;
}
public Path createClasspath () {
this.classPath = new Path(project);
return classPath;
}
public Validator createValidator () {
Validator validator = new Validator ();
validators.add (validator);
return validator;
}
private static final String SUFFIX = "$__attributeRepository.class";
protected void findJarFile () throws BuildException {
File[] allFiles = baseName.getParentFile ().listFiles ();
if (allFiles == null) {
throw new BuildException ("Unable to find any file with base name " + baseName.getName ()
+ " in " + baseName.getParentFile ().getPath ());
}
long newestDate = 0;
for (int i = 0; i < allFiles.length; i++) {
String name = allFiles[i].getName ();
if (name.startsWith (baseName.getName ()) && name.endsWith (".jar") &&
allFiles[i].lastModified () > newestDate) {
jarFile = allFiles[i];
newestDate = allFiles[i].lastModified ();
}
}
if (jarFile == null) {
throw new BuildException ("Unable to find any file with base name " + baseName.getName ()
+ " in " + baseName.getParentFile ().getPath ());
}
}
public void execute () throws BuildException {
if (inMaven) {
findJarFile ();
}
if (!jarFile.exists ()) {
log ("Can't find " + jarFile.getPath ());
return;
}
try {
log ("Validating attributes in " + jarFile.getPath ());
JarFile jar = new JarFile (jarFile);
try {
Enumeration e = jar.entries ();
while (e.hasMoreElements ()) {
JarEntry entry = (JarEntry) e.nextElement ();
if (!entry.isDirectory ()) {
String className = entry.getName ();
if (className.endsWith (SUFFIX)) {
className = className.replace ('/', '.').replace ('\\', '.').substring (0, className.length () - SUFFIX.length ());
classes.add (className);
}
}
}
} finally {
jar.close ();
}
AntClassLoader cl = new AntClassLoader (this.getClass ().getClassLoader (), project, classPath, true);
try {
cl.addPathElement (jarFile.getPath ());
HashSet classesToValidate = new HashSet ();
Iterator attrs = classes.iterator ();
while (attrs.hasNext ()) {
String className = (String) attrs.next ();
Class clazz = cl.loadClass (className);
classesToValidate.add (clazz);
}
Iterator iter = validators.iterator ();
while (iter.hasNext ()) {
Validator validator = (Validator) iter.next ();
Class validatorClass = cl.loadClass (validator.getClassName ());
AttributeValidator attrValidator = (AttributeValidator) validatorClass.newInstance ();
try {
attrValidator.validate (classesToValidate);
} catch (ValidationException ve) {
throw new BuildException (ve.getInvalidClass () + " failed to validate: " + ve.getMessage ());
}
}
} finally {
cl.cleanup ();
}
} catch (BuildException be) {
throw be;
} catch (Exception e) {
e.printStackTrace ();
throw new BuildException (e.toString ());
}
}
} ././@LongLink 100644 0 0 153 10464315317 10256 L ustar 0 0 commons-attributes-2.2/compiler/src/java/org/apache/commons/attributes/validation/ValidationException.java commons-attributes-2.2/compiler/src/java/org/apache/commons/attributes/validation/ValidationExceptio100644 0 0 2703 10464315317 31414 0 ustar 0 0 /*
* Copyright 2003-2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.attributes.validation;
/**
* Thrown by {@link AttributeValidator}s when an invalid set of
* attributes are detected.
*
* @since 2.1
*/
public class ValidationException extends Exception {
private final Class invalidClass;
/**
* Creates a new ValidationException.
*
* @param invalidClass the class whose attributes are
* invalid.
* @param message a message describing why the attributes are invalid.
* @since 2.1
*/
public ValidationException (Class invalidClass, String message) {
super (message);
this.invalidClass = invalidClass;
}
/**
* Returns the class that triggered the ValidationExeption to
* be thrown.
* @since 2.1
*/
public Class getInvalidClass () {
return invalidClass;
}
} commons-attributes-2.2/compiler/src/java/org/apache/commons/attributes/validation/package.html 100644 0 0 1061 10464315317 30153 0 ustar 0 0
Provides an API for validating internal consistency among attributes.
Many times, an attribute will only make sense in some context. For example, you may have one attribute that must either be applied to no methods, or to all methods in a class. An attribute may require the presence of another attribute.
The AttributeValidatorTask Ant task and its API enables you to define those rules
and run them as part of your regular build.
commons-attributes-2.2/compiler/src/java/org/apache/commons/attributes/javadoc/CATaglet.java 100644 0 0 23202 10464315317 27457 0 ustar 0 0 /*
* Copyright 2003-2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.attributes.javadoc;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.lang.reflect.Constructor;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.TreeMap;
import com.sun.javadoc.Tag;
import com.sun.tools.doclets.Taglet;
public class CATaglet implements Taglet {
public static class AttributeTaglet extends CATaglet {
private final String name;
private final CATaglet caTaglet;
public AttributeTaglet(String name, CATaglet caTaglet) {
this.name = name;
this.caTaglet = caTaglet;
}
public String getName() {
return name;
}
public String toString(Tag[] tags) {
caTaglet.addTags(tags);
return null;
}
}
/**
* Name of custom tag.
*/
public static final String NAME
= "org.apache.commons.attributes.CATaglet";
/**
* Fully qualified class name of the legacy taglet class of JDK1.5.
*/
public static final String LEGACY_TAGLET_CLASS_NAME
= "com.sun.tools.doclets.internal.toolkit.taglets.LegacyTaglet";
/**
* List of tags.
*/
private List tagList = new ArrayList();
/**
* Jdk1.5 legacy taglet class constructor.
*/
private Constructor legacyTagletClassConstructor = null;
/**
* Default constructor.
*/
public CATaglet() {
try {
Class legacyTagletClass = Class.forName(LEGACY_TAGLET_CLASS_NAME);
legacyTagletClassConstructor
= legacyTagletClass.getConstructor(new Class[] {Taglet.class});
//System.err.println("CATaglet will be wrapped.");
} catch (Exception e) {
/**
* Legacy taglet class not available. Seams that JDK1.4 is used to
* generate javadoc. No wrapping of taglets necessary.
*/
//System.err.println("CATaglet will not be wrapped. See stack trace.");
//e.printStackTrace();
}
}
public void addTags(Tag[] tags) {
for (int i = 0; i < tags.length; i++) {
tagList.add(tags[i].name() + " " + tags[i].text());
}
}
/**
* Return the name of this custom tag.
*/
public String getName() {
return NAME;
}
public boolean inField() {
return true;
}
public boolean inConstructor() {
return true;
}
public boolean inMethod() {
return true;
}
public boolean inOverview() {
return false;
}
public boolean inPackage() {
return false;
}
public boolean inType() {
return true;
}
public boolean isInlineTag() {
return false;
}
public static void register(Map tagletMap) {
CATaglet caTaglet = new CATaglet();
caTaglet.registerTags(tagletMap);
}
public void registerTags(Map tagletMap) {
Set tagNames = new HashSet();
StringTokenizer tok = new StringTokenizer(
System.getProperty(
"org.apache.commons.attributes.javadoc.CATaglet.sources"),
File.pathSeparator);
while (tok.hasMoreTokens()) {
try {
scanFiles(new File(tok.nextToken()), tagNames);
} catch (Exception e) {
System.err.println("Caught " + e.toString() + " trying to scan "
+ "Java sources. Javadoc of attributes may be incomplete.");
}
}
if (tagNames.size() > 0) {
Iterator iter = tagNames.iterator();
while (iter.hasNext()) {
String name = (String) iter.next();
register(name, tagletMap);
}
if (tagletMap.containsKey(NAME)) {
tagletMap.remove(NAME);
}
tagletMap.put(NAME, wrapTaglet(this));
}
}
private void scanFiles(File directory, Collection tagNames)
throws Exception {
File[] files = directory.listFiles();
if (files == null) {
return;
}
for (int i = 0; i < files.length; i++) {
if (files[i].isDirectory()) {
scanFiles(files[i], tagNames);
} else {
scanFile(files[i], tagNames);
}
}
}
private void scanFile(File file, Collection tagNames) throws Exception {
BufferedReader br = new BufferedReader(new FileReader(file));
try {
String line = null;
while ((line = br.readLine()) != null) {
scanLine(line, tagNames);
}
} finally {
br.close();
}
}
private void scanLine(String line, Collection tagNames) throws Exception {
int start = line.indexOf("@@");
while (start != -1) {
int end = line.indexOf(" ", start);
if (end == -1) {
end = line.length();
}
tagNames.add(line.substring(start + 1, end));
start = line.indexOf("@@", end);
}
}
private void register(String name, Map tagletMap) {
Taglet tag = new AttributeTaglet("@" + name, this);
if (tagletMap.containsKey(name)) {
tagletMap.remove(name);
}
tagletMap.put(name, wrapTaglet(tag));
}
/**
* Wraps a JDK1.4 taglet with a JDK1.5 legacy taglet. This is only done if
* class com.sun.tools.doclets.internal.toolkit.taglets.LegacyTaglet
* exists, what means that JDK1.5 is used to generate Javadoc.
*
* @param tag Is the taglet to wrap.
* @return Returns the wrapped taglet.
*/
private Object wrapTaglet(Taglet taglet) {
Object wrappedTaglet = taglet;
if (legacyTagletClassConstructor != null) {
try {
wrappedTaglet = legacyTagletClassConstructor.newInstance(
new Object[] {taglet});
} catch (Exception e) {
System.err.println("Wrapping of CATaglet failed.");
e.printStackTrace();
}
}
return wrappedTaglet;
}
public String toString(Tag tag) {
return null;
}
public String toString(Tag[] _t) {
String[] tags = (String[]) tagList.toArray(new String[0]);
if (tags.length == 0) {
return null;
}
// Sort by target
Map targets = new TreeMap();
for (int i = 0; i < tags.length; i++) {
String target = "";
String attribute = tags[i];
if (tags[i].startsWith("@@.")) {
int targetEnd = tags[i].indexOf(" ", 3);
if (targetEnd != -1) {
target = tags[i].substring(3, targetEnd);
attribute = "@@" + tags[i].substring(targetEnd).trim();
}
}
if (!targets.containsKey(target)) {
targets.put(target, new ArrayList());
}
List tagsForTarget = (List) targets.get(target);
tagsForTarget.add(attribute);
}
StringBuffer result = new StringBuffer();
result.append("
");
Iterator iter = attrs.iterator();
while (iter.hasNext()) {
result.append(iter.next());
if (iter.hasNext()) {
result.append("
");
}
}
result.append("
");
}
List returnAttrs = (List) targets.remove("return");
if (targets.size() > 0) {
result.append("" + target + "
- ");
Iterator iter = attrs.iterator();
while (iter.hasNext()) {
result.append(" " + iter.next());
if (iter.hasNext()) {
result.append("
");
}
}
result.append("
");
}
}
if (returnAttrs != null) {
result.append("");
Iterator iter = returnAttrs.iterator();
while (iter.hasNext()) {
result.append(iter.next());
if (iter.hasNext()) {
result.append("
");
}
}
result.append("
");
}
tagList.clear();
return result.toString();
}
}
commons-attributes-2.2/compiler/src/java/org/apache/commons/attributes/javadoc/package.html 100644 0 0 201 10464315317 27403 0 ustar 0 0
Provides a Javadoc Taglet for documenting attributes.
././@LongLink 100644 0 0 174 10464315317 10261 L ustar 0 0 commons-attributes-2.2/compiler/src/test/org/apache/commons/attributes/compiler/test/AttributeExpressionParserTestCase.java commons-attributes-2.2/compiler/src/test/org/apache/commons/attributes/compiler/test/AttributeExpres100644 0 0 10463 10464315316 31471 0 ustar 0 0 /* * Copyright 2003-2004 The Apache Software Foundation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.attributes.compiler.test; import java.lang.reflect.Field; import java.lang.reflect.Method; import java.lang.reflect.Constructor; import java.io.File; import java.net.URL; import java.net.URLClassLoader; import java.util.Collection; import java.util.Iterator; import org.apache.commons.attributes.compiler.AttributeExpressionParser; import junit.framework.TestCase; public class AttributeExpressionParserTestCase extends TestCase { private void singleTest (String expression, String className, AttributeExpressionParser.Argument[] args) { AttributeExpressionParser.ParseResult result = AttributeExpressionParser.parse (expression, "noFile", 1); AttributeExpressionParser.ParseResult expected = new AttributeExpressionParser.ParseResult (className); for (int i = 0; i < args.length; i++) { expected.arguments.add (args[i]); } assertEquals (expected, result); } public void testExpressions () throws Exception { singleTest ("Inherited()", "Inherited", new AttributeExpressionParser.Argument[] {}); singleTest ("AnAttribute(1,2)", "AnAttribute", new AttributeExpressionParser.Argument[] { new AttributeExpressionParser.Argument(null, "1", 0), new AttributeExpressionParser.Argument(null, "2", 0) }); singleTest ("AnAttribute(\"sometext,1,2\",'a',',')", "AnAttribute", new AttributeExpressionParser.Argument[] { new AttributeExpressionParser.Argument(null, "\"sometext,1,2\"", 0), new AttributeExpressionParser.Argument(null, "'a'", 0), new AttributeExpressionParser.Argument(null, "','", 0) }); singleTest ("AnAttribute(\"sometext,1,2\",'a',',',alpha='\"',beta=\"\\\'\")", "AnAttribute", new AttributeExpressionParser.Argument[] { new AttributeExpressionParser.Argument(null, "\"sometext,1,2\"", 0), new AttributeExpressionParser.Argument(null, "'a'", 0), new AttributeExpressionParser.Argument(null, "','", 0), new AttributeExpressionParser.Argument("alpha", "'\"'", 0), new AttributeExpressionParser.Argument("beta", "\"\\\'\"", 0) }); singleTest ("my.package. AnAttribute(\"sometext,1,2\",'a',',',alpha='\"',beta=\"\\\'\")", "my.package. AnAttribute", new AttributeExpressionParser.Argument[] { new AttributeExpressionParser.Argument(null, "\"sometext,1,2\"", 0), new AttributeExpressionParser.Argument(null, "'a'", 0), new AttributeExpressionParser.Argument(null, "','", 0), new AttributeExpressionParser.Argument("alpha", "'\"'", 0), new AttributeExpressionParser.Argument("beta", "\"\\\'\"", 0) }); /* singleTest ("my.package.AnAttribute( \"sometext,1,2\" , 'a' , ',' , alpha='\"', beta=\"\\\'\")", "my.package.AnAttribute", new AttributeExpressionParser.Argument[] { new AttributeExpressionParser.Argument(null, "\"sometext,1,2\" ", 0), new AttributeExpressionParser.Argument(null, "'a'", 0), new AttributeExpressionParser.Argument(null, "','", 0), new AttributeExpressionParser.Argument("alpha", "'\"'", 0), new AttributeExpressionParser.Argument("beta", "\"\\\'\"", 0) }); */ singleTest ("AnAttribute( \"sometext,1,2\" )", "AnAttribute", new AttributeExpressionParser.Argument[] { new AttributeExpressionParser.Argument(null, " \"sometext,1,2\" ", 0) }); } } commons-attributes-2.2/compiler/project.xml 100644 0 0 3566 10464315316 16362 0 ustar 0 0This is a quick demo that shows how to use attributes together with Maven. Don't worry about 90% here seemingly being pure unexplainable magic - the purpose of this part of the tutorial is to show you what steps you must do to make the Commons Attributes package work. In the reference we'll focus more on just what happens, and how the all features work.
All files required for this demo can be found in maven_demo.zip.
In order to get attributes working in your project you need to do three things: (1) declare dependencies, (2) install the commons-attributes plugin and (3) set project properties that will enable the plugin for your project.
Dependencies are declared as you would expect in your project.xml:
You can install the plugin by checking out the sources and doing:
Alternatively, you can download the plugin and put it in your Maven plugin directory.
Since Maven will unconditionally apply all plugins to every project being compiled it is neccessary to explicitly enable the attribute compiler and/or indexer. This is simply to keep them from being run on projects that do not want anything to do with Commons-Attributes. The compiler and/or indexer are enabled by two project properties that you can set in your project.properties file or in your maven.xml file:
The first property will enable the attribute precompilation step. The second will enable the attribute indexing step that takes place after the jar:jar target. Both properties can be set independently of each other, although it makes little sense to enable indexing if compilation isn't enables as well.
You should be able to unzip the demo files, cd into the directory and execute "maven run", like this: