|
|||||||||||||||||||
| 30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover | |||||||||||||||||||
| Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
| XTagFactory.java | 75% | 72% | 83.3% | 74.4% |
|
||||||||||||||
| 1 |
/*
|
|
| 2 |
* Copyright (c) 2001-2003 The XDoclet team
|
|
| 3 |
* All rights reserved.
|
|
| 4 |
*/
|
|
| 5 |
package xjavadoc;
|
|
| 6 |
|
|
| 7 |
import java.util.HashMap;
|
|
| 8 |
import java.util.Map;
|
|
| 9 |
import java.util.StringTokenizer;
|
|
| 10 |
|
|
| 11 |
/**
|
|
| 12 |
* Creates XTag instances.
|
|
| 13 |
*
|
|
| 14 |
* @author Aslak Hellesøy
|
|
| 15 |
* @created 10. februar 2002
|
|
| 16 |
*/
|
|
| 17 |
public final class XTagFactory |
|
| 18 |
{
|
|
| 19 |
|
|
| 20 |
/**
|
|
| 21 |
* Maps tag name to XTag class.
|
|
| 22 |
*/
|
|
| 23 |
private final Map _tagClasses = new HashMap(); |
|
| 24 |
private boolean _isValidating = false; |
|
| 25 |
|
|
| 26 | 146 |
public XTagFactory() {
|
| 27 |
// ignore standard tags. See:
|
|
| 28 |
// http://java.sun.com/j2se/1.4.1/docs/tooldocs/windows/javadoc.html#javadoctags
|
|
| 29 | 146 |
setIgnoredTags( "author,deprecated,exception,param,return,see,serial,serialData,serialField,since,throws,version" );
|
| 30 |
} |
|
| 31 |
|
|
| 32 | 672 |
public boolean isValidating() |
| 33 |
{
|
|
| 34 | 672 |
return _isValidating;
|
| 35 |
} |
|
| 36 |
|
|
| 37 | 0 |
public void setValidating( boolean isValidating ) |
| 38 |
{
|
|
| 39 | 0 |
_isValidating = isValidating; |
| 40 |
} |
|
| 41 |
|
|
| 42 |
/**
|
|
| 43 |
* Set the name of the tags that shouldn't be validated against.
|
|
| 44 |
*
|
|
| 45 |
* @param tags
|
|
| 46 |
*/
|
|
| 47 | 146 |
public void setIgnoredTags( String tags ) |
| 48 |
{
|
|
| 49 | 146 |
StringTokenizer st = new StringTokenizer( tags, "," ); |
| 50 |
|
|
| 51 | 146 |
while( st.hasMoreTokens() )
|
| 52 |
{
|
|
| 53 | 1752 |
registerTagClass( st.nextToken(), DefaultXTag.class );
|
| 54 |
} |
|
| 55 |
} |
|
| 56 |
|
|
| 57 |
/**
|
|
| 58 |
* Creates a new XTag. If a special tag class has been previously registeres,
|
|
| 59 |
* an instance of the corresponding class will be returned. This allows for
|
|
| 60 |
* special tag implementations.
|
|
| 61 |
*
|
|
| 62 |
* @param tagName name of the tag, without the '@'
|
|
| 63 |
* @param text content of the tag. Will be parsed into
|
|
| 64 |
* attributes.
|
|
| 65 |
* @param doc
|
|
| 66 |
* @param lineNumber
|
|
| 67 |
* @return an instance of XTag
|
|
| 68 |
* @exception UnknownTagException
|
|
| 69 |
* @throws TagValidationException if validation is activated and an unknown
|
|
| 70 |
* tag was encountered.
|
|
| 71 |
*/
|
|
| 72 | 712 |
public XTag createTag( String tagName, String text, XDoc doc, int lineNumber ) throws UnknownTagException |
| 73 |
{
|
|
| 74 | 712 |
tagName = XDoc.dotted( tagName ); |
| 75 |
|
|
| 76 |
// Let's see if there is a custom class for that tag
|
|
| 77 | 712 |
Class tagClass = ( Class ) _tagClasses.get( tagName ); |
| 78 | 712 |
DefaultXTag tag; |
| 79 |
|
|
| 80 | 712 |
if( tagClass != null ) |
| 81 |
{
|
|
| 82 | 662 |
try
|
| 83 |
{
|
|
| 84 | 662 |
tag = ( DefaultXTag ) tagClass.newInstance(); |
| 85 |
} |
|
| 86 |
catch( InstantiationException e )
|
|
| 87 |
{
|
|
| 88 | 0 |
e.printStackTrace(); |
| 89 | 0 |
throw new IllegalStateException( e.getMessage() ); |
| 90 |
} |
|
| 91 |
catch( IllegalAccessException e )
|
|
| 92 |
{
|
|
| 93 | 0 |
e.printStackTrace(); |
| 94 | 0 |
throw new IllegalStateException( e.getMessage() ); |
| 95 |
} |
|
| 96 |
} |
|
| 97 |
else
|
|
| 98 |
{
|
|
| 99 | 50 |
tag = new DefaultXTag();
|
| 100 |
} |
|
| 101 | 712 |
tag.init( tagName, text, doc, lineNumber ); |
| 102 |
|
|
| 103 |
// Throw validation ex if validation is on and the tag is unknown
|
|
| 104 | 712 |
if( _isValidating && ( tagClass == null ) ) |
| 105 |
{
|
|
| 106 | 0 |
throw new UnknownTagException( tag ); |
| 107 |
} |
|
| 108 | 712 |
return tag;
|
| 109 |
} |
|
| 110 |
|
|
| 111 | 1752 |
public void registerTagClass( String tagName, Class tagClass ) |
| 112 |
{
|
|
| 113 | 1752 |
Class old = (Class) _tagClasses.get( XDoc.dotted(tagName) ); |
| 114 | 1752 |
if( old != null ) { |
| 115 | 0 |
throw new IllegalStateException( "The tag @" + XDoc.dotted(tagName) + |
| 116 |
" has already been mapped to " + old.getName() +
|
|
| 117 |
". Can't reregister it to " + tagClass.getName());
|
|
| 118 |
} |
|
| 119 | 1752 |
_tagClasses.put( XDoc.dotted( tagName ), tagClass ); |
| 120 |
} |
|
| 121 |
} |
|
| 122 |
|
|
||||||||||