|
Commons Attributes example source code file (declaring.xml)
The Commons Attributes declaring.xml source code
<?xml version="1.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.
=
-->
<document>
<properties>
<author email="commons-dev@jakarta.apache.org">Jakarta Commons Development Team
<title>Reference - Declaring and Using
</properties>
<body>
<section name="What are Attributes?">
<p>Attributes are value objects that can be added to language elements such as
classes, methods and fields.</p>
<subsection name="Value Objects">
<p>What is a value object? Simply stated, a value object is an object that is
read-only, constant and can be replaced with another object of the same value
without it making any difference. For example, instances of the class
<code>java.lang.Integer are value objects. You can replace any instance
of that class with any other instance, provided that they are equal. An
<code>java.io.Socket is not a value object, as you can't replace an
instance of a socket with another - it corresponds to a real resource, in
this case a connection.</p>
<p>You should therefore not allow your attribute classes to be mutable, and not
use Sockets or similar classes as attributes.</p>
</subsection>
</section>
<section name="How Are They Added?">
<p>Let's look at the way attributes are added to the code. The general form of the
attribute expression is (optional parts are in [brackets]):</p>
<source>
<subsection name="target">
<p>This name indicates what sub-element the attribute is to be applied to.
Classes and fields have no sub-elements, but methods do. The sub-elements
of a method are (1) the arguments and (2) the return value. In order to
apply an element to a method argument, you let the target be <code>.argument name.
For example:</p>
<source>
<p>Will attach MyAttribute to the first argument of the method - not to
the method itself. The attribute can be retrieved via
<code>Attributes.getParameterAttributes(Method,int).
<p>Adding an attribute to the return value is done by the reserved target
name <code>.return:
<source>
<p>The attribute can then be retrieved via
Other Commons Attributes examples (source code examples)Here is a short list of links related to this Commons Attributes declaring.xml source code file: |
| ... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.