Conceivably, this makes it unnecessary to copy and paste the Apache
Copyright at the top of every java source files.
Instead, simply annotate:
@CopyRightApache
public class Foo {...}
This copyright info then becomes available both at source, class and
runtime level, plus the compiler will verify it for you in case of
typo.
H
On Fri, 21 Jan 2005 16:17:43 +1100, Hanson Char <[EMAIL PROTECTED]> wrote:
> An idea on preserving copyright on objects via jdk1.5 annotation and enum.
>
> 1) Creates a enum CopyRightType with one value APACHE, which has the
> toString method to return the Apache software license.
> 2) Creates an annotation CopyRightApache that has a value that returns
> the above CopyRightType, with the default set to CopyRightType.APACHE.
> 3) Annotates every class with @CopyRightApache.
>
> Now the copyright of any object can be accessed in the JVM during runtime by:
>
> object.getClass().getAnnotation(CopyRightApache.class).toString()
>
> Sample code:
>
> // Enum Definition for the Apache Copyright
> @CopyRightApache
> public enum CopyRightType {
> APACHE {
> @Override public String toString() {
> return "\n"
> + "/*
> ========================================================================\n"
> + " * Copyright 2004 The Apache Software Foundation\n"
> + " *\n"
> + " * Licensed under the Apache License, Version 2.0 (the
> \"License\");\n"
> + " * you may not use this file except in compliance with
> the License.\n"
> + " * You may obtain a copy of the License at\n"
> + " *\n"
> + " * http://www.apache.org/licenses/LICENSE-2.0\n"
> + " *\n"
> + " * Unless required by applicable law or agreed to in
> writing, software\n"
> + " * distributed under the License is distributed on an
> \"AS IS\" BASIS,\n"
> + " * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
> express or implied.\n"
> + " * See the License for the specific language governing
> permissions and\n"
> + " * limitations under the License.\n"
> + " *
> ========================================================================\n"
> + " */\n"
> ;
> }
> };
> }
>
> // Annotation Type Definition for the Apache Copyright
> @CopyRightApache
> @Documented
> @Retention(RetentionPolicy.RUNTIME)
> public @interface CopyRightApache {
> CopyRightType value() default CopyRightType.APACHE;
> }
>
> // JUnit test case for the Apache Copyright artifacts.
> import junit.framework.TestCase;
> import org.apache.commons.logging.Log;
> import org.apache.commons.logging.LogFactory;
>
> @CopyRightApache
> @TestOnly
> public class CopyRightApacheTest extends TestCase {
> private Log log = LogFactory.getLog(this.getClass());
>
> public void test() {
> log.debug(this.getClass().getAnnotation(CopyRightApache.class));
> }
> }
>
> An interesting result is that the enum and annotation are themselves
> recursively annotated by the same copyright they define.
>
> H
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]