You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jcs-dev@jakarta.apache.org by Hanson Char <ha...@gmail.com> on 2005/01/21 06:17:43 UTC

Copyright in JDK1.5

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: turbine-jcs-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-jcs-dev-help@jakarta.apache.org


Re: Copyright in JDK1.5

Posted by Henri Yandell <ba...@generationjava.com>.
It wouldn't be available at source time would it?

If I goto CVS, grab the TestOnly.java file and copy it, I'll have never 
seen a copyright notice.

Hen

On Fri, 21 Jan 2005, Hanson Char wrote:

> Oops, the "TestOnly" annotation can be ommited.  Otherwise, here is
> the definition:
>
> @CopyRightApache
> @Documented
> @Inherited
> @Retention(RetentionPolicy.RUNTIME)
> public @interface TestOnly {
>    String value() default "";
> }
>
> H
>
> On Fri, 21 Jan 2005 16:23:03 +1100, Hanson Char <ha...@gmail.com> wrote:
>> 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 <ha...@gmail.com> 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: turbine-jcs-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: turbine-jcs-dev-help@jakarta.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-jcs-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-jcs-dev-help@jakarta.apache.org


Re: Copyright in JDK1.5

Posted by Hanson Char <ha...@gmail.com>.
Oops, the "TestOnly" annotation can be ommited.  Otherwise, here is
the definition:

@CopyRightApache
@Documented
@Inherited
@Retention(RetentionPolicy.RUNTIME)
public @interface TestOnly {
    String value() default "";
}

H

On Fri, 21 Jan 2005 16:23:03 +1100, Hanson Char <ha...@gmail.com> wrote:
> 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 <ha...@gmail.com> 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: turbine-jcs-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-jcs-dev-help@jakarta.apache.org


Re: Copyright in JDK1.5

Posted by Hanson Char <ha...@gmail.com>.
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 <ha...@gmail.com> 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: turbine-jcs-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-jcs-dev-help@jakarta.apache.org