alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Commons Attributes example source code file (validator.xml)

This example Commons Attributes source code file (validator.xml) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Commons Attributes tags/keywords

apache, attributevalidator, attributevalidator, cdata, cdata, description, for, license, license, required, the, the, validationexception, validclass

The Commons Attributes validator.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 - Validating Attributes at Compile-Time
    </properties>
    
    <body>
        <section name="Why?">
            
            <p>
                In many cases an attribute can only be applied to certain elements,
                and its parameters must satisfy some set of constraints. For example,
                suppose we have an attribute that declares transaction metadata:
            </p>
            
            <source>
            
            <p>
                Now, the rule is that if a class has a <tt>TransactionDeclaration.EXPLICIT
                setting, then <b>all methods must have a @@TransactionLevel attribute.
                For example, this class is valid:
            </p>
            
            <source>
            
            <p>While this one is not, since methodTwo does not define a @@TransactionLevel.

<source> <p> The attribute-validator task enables you to check the consistency of attributes at compile-time. </p> </section> <section name="The attribute-validator Task"> <p> The attribute-validator task is run like this from your Ant file: </p> <source> <classpath> ... </classpath> <validator class="my.Validator"/> <validator class="my.other.Validator"/> </attribute-validator>]]> <table> <tr> <th> Parameter </th> <th> Required </th> <th> Description </th> </tr> <tr> <td> jarFile </td> <td> yes </td> <td> The jar file whose classes should be validated. </td> </tr> </table> <table> <tr> <th> Element </th> <th> Required </th> <th> Description </th> </tr> <tr> <td> classpath </td> <td> yes </td> <td> The classpath to use when loading classes from the jar file. </td> </tr> <tr> <td> validator </td> <td> yes </td> <td> One or more validators, which are classes implementing the <a href="api/org/apache/commons/attributes/validation/AttributeValidator.html">AttributeValidator interface. </td> </tr> </table> </section> <section name="Writing Your Own Validation Rules"> <p> Writing a validation rule simply means implementing the <a href="api/org/apache/commons/attributes/validation/AttributeValidator.html">AttributeValidator interface in a class. For example, this AttributeValidator will check that there are no more than three class attributes given to each class. </p> <source> </section> </body> </document>

Other Commons Attributes examples (source code examples)

Here is a short list of links related to this Commons Attributes validator.xml source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 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.