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

Commons Attributes example source code file (InvalidAttributeTargetError.java)

This example Commons Attributes source code file (InvalidAttributeTargetError.java) 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

arraylist, constructor_parameter, error, invalidattributetargeterror, invalidattributetargeterror, list, method, method_parameter, string, string, stringbuffer, stringbuffer, they, they, util

The Commons Attributes InvalidAttributeTargetError.java source code

/*
 * 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;

import java.util.ArrayList;
import java.util.List;

/**
 * Thrown when an attribute has a {@link Target} declaration that forbids
 * it being applied to the program element it has been applied to.
 *
 * <p>For example:
 *
 * <pre>
 * /**
 *  * This attribute can only be applied to Classes.
 *  * Target(Target.CLASS)
 *  */
 * public class MyAttribute {}
 *
 * public class MyClass {
 *     /** 
 *       * Error: Can't apply MyAttribute to a field!
 *       * @@MyAttribute() 
 *       */
 *     private String myField;
 * }
 * </code>
* * @since 2.1 */ public class InvalidAttributeTargetError extends Error { /** * Creates a new InvalidAttributeTargetError. * * @param attributeClass name of the type of the attribute that was applied to the wrong target. * @param element the element that the user tried to apply the attribute to. * @param targetFlags the targets (bitwise OR of the {@link Target}.XXX flags that the attributeClass * can be applied to. * @since 2.1 */ public InvalidAttributeTargetError (String attributeClass, String element, int targetFlags) { super ("Attributes of type " + attributeClass + " can't be applied to " + element + ". " + "They can only be applied to: " + flagsToString (targetFlags)); } private final static String flagsToString (int flags) { List targetNames = new ArrayList (); if ((flags & Target.CLASS) > 0) { targetNames.add ("CLASS"); } if ((flags & Target.FIELD) > 0) { targetNames.add ("FIELD"); } if ((flags & Target.METHOD) > 0) { targetNames.add ("METHOD"); } if ((flags & Target.CONSTRUCTOR) > 0) { targetNames.add ("CONSTRUCTOR"); } if ((flags & Target.METHOD_PARAMETER) > 0) { targetNames.add ("METHOD_PARAMETER"); } if ((flags & Target.CONSTRUCTOR_PARAMETER) > 0) { targetNames.add ("CONSTRUCTOR_PARAMETER"); } if ((flags & Target.RETURN) > 0) { targetNames.add ("RETURN"); } StringBuffer sb = new StringBuffer (); for (int i = 0; i < targetNames.size (); i++) { sb.append (targetNames.get (i)); if (i < targetNames.size () - 1) { sb.append (" | "); } } return sb.toString (); } }

Other Commons Attributes examples (source code examples)

Here is a short list of links related to this Commons Attributes InvalidAttributeTargetError.java 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.