/* XBN Java: Generically useful, non-GUI Java code. http://sourceforge.net/projects/xbnjava Copyright (C) 1997-2003, Jeff Epstein All rights reserved. Modifications: No Redistribution in binary form, with or without modifications, are permitted provided that the following conditions are met: * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * If modifications are made to source code then this license should indicate that fact in the "Modifications" section above. * Neither the author, nor the contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. [NOTE: This license contains NO advertising clause.] */ package xbn.jdlcode; import xbn.AssertException; import xbn.named.Named; import xbn.string.UtilString; import xbn.string.padchop.PadChopString; import xbn.string.padchop.ConfigPad; /**

A JDFile that is explicitely defined it the jdlcode doclet class map configuration file. See getJDCAFromFLR.

Manage a set of JDClasses with JDCArray

Source code:  JDClass.java.

@version 0.9b @author Jeff Epstein, http://sourceforge.net/projects/xbnjava. **/ public class JDClass extends JDFile implements Named { private UtilString uStr = new UtilString(); private String sAbbreviation = null; private PackageType pType = null; private boolean bNameIsAbbrevOrFQCN = false; private PadChopString pcsPad = new PadChopString(new ConfigPad(20)); /**

Create a JDClass.

@param s_abbreviation The abbreviation assigned to this class. For example, you might assign "s" to java.lang.String. Must contain only letters, digits and underscores. See getAbbreviation. @param s_fullyQualifiedClassName Must conform to the following restrictions: @param pt_array The PTArray defining all PackageTypes. **/ public JDClass(String s_abbreviation, String s_fullyQualifiedClassName, PTArray pt_array) { super(s_fullyQualifiedClassName); throwAXIfBadStr(s_abbreviation, "s_abbreviation", sCNSTR); throwAXIfNull(pt_array, "pt_array", sCNSTR); if(!uStr.isLetterDigitUnderscore(s_abbreviation)) { throwAX("constructor: s_abbreviation ('" + s_abbreviation + "') may only contain letters, digits and underscores."); } if(s_abbreviation.length() > 20) { throwAX("constructor: The length of the abbreviation must range 1..20. Currently " + s_abbreviation.length() + ". s_abbreviation='" + s_abbreviation + "'."); } for(int i = 0; i < getPartCount(); i++) { boolean bLDU = uStr.isLetterDigitUnderscore(getPart(i)); if(!bLDU) { if(i < (getPartCount() - 1) || (!getPart(i).equals("package-summary") && !getPart(i).equals("overview-summary"))) { throwAX("constructor: The fully qualified class name '" + s_fullyQualifiedClassName + "' may only contain letters, digits, underscores and periods. Part at array index " + i + " contains illegal characters. Note the only exception to this rule is when the file name (the last part) is 'overview-summary' or 'package-summary'."); } } } sAbbreviation = s_abbreviation; try { pType = pt_array.getPackageType(getPart(0)); } catch(AssertException ax) { throwAX("constructor: Attempting to get the PackageType of this JDClass: " + ax.toString()); } if(pType != null) { pType.setFound(); } else { if(getPartCount() > 1) { throwAX("contructor: The prefix of this class name (prefix='" + getPart(0) + "', s_fullyQualifiedClassName='" + s_fullyQualifiedClassName + "') is not equal to any existing PackageType. Primitive types may only contain lowercase letters."); } } bNameIsAbbrevOrFQCN = true; } /**

Get the abbreviation assigned to this JDClass.

@return s_abbreviation, exactly as provided to the constructor. **/ public String getAbbreviation() { return sAbbreviation; } /**

Determine what the name of this JDClass should be.

Get with isNameAbbrevOrFQCN

@param b_abbrevOrFQCN If true, then name should be the abbreviation. If false, the name should be the fully qualified class name. **/ public void setNameAbbrevOrFQCN(boolean b_abbrevOrFQCN) { bNameIsAbbrevOrFQCN = b_abbrevOrFQCN; } /**

What is the name of this JDClass?. The abbreviation or the fully qualified class name?

Set with setNameAbbrevOrFQCN

@return true If the name is the abbreviation.
false If the name is the fully qualified class name. **/ public boolean isNameAbbrevOrFQCN() { return bNameIsAbbrevOrFQCN; } /**

Get theh name of this JDClass.

@return getAbbreviation() if isNameAbbrevOrFQCN is true.
getList(".") if isNameAbbrevOrFQCN is false. **/ public String getName() { if(isNameAbbrevOrFQCN()) { return getAbbreviation(); } return getList("."); } /**

Get the PackageType of this JDClass.

@return null If this JDClass is primitive.
a PackageType object If this JDClass is local or external. **/ public PackageType getPackageType() { return pType; } /**

Get the PackageType prefix of this JDClass.

@return "primitive" If this JDClass is primitive.
getPackageType().getPrefix() If this JDClass is local or external. **/ public String getPackageTypePrefix() { if(isPrimitive()) { return "primitive"; } return getPackageType().getPrefix(); } /**

Is this JDClass primitive?

@return (getPackageType() == null) **/ public boolean isPrimitive() { return (getPackageType() == null); } /**

Is this JDClass local?

@return true If both isPrimitive and getPackageType().isExternal() equal false. **/ public boolean isLocal() { if(isPrimitive()) { return false; } return !getPackageType().isExternal(); } /**

Is this JDClass external?

@return true If isPrimitive equals false and getPackageType().isExternal() equals true. **/ public boolean isExternal() { if(isPrimitive()) { return false; } return getPackageType().isExternal(); } /**

Get the external url for this JDClass.

@return getPackageType().getExternalUrl() @exception AssertException if isExternal equals false. **/ public String getExternalUrl() { if(!isExternal()) { throwAX("getExternalUrl: isExternal() equals false. The package type of this JDClass is either primitive or local."); } return getPackageType().getExternalUrl(); } /**

Get some information about this JDClass.

**/ public String toString() { return pcsPad.get(getAbbreviation()) + super.toString(); } }