/* 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.named.NamedArray; import xbn.array.VWString; import xbn.array.primitive.ListPA; /**
Manage a set of unique PackageTypes. See PackageType.
Source code: PTArray.java.
Create a PTArray.
@param a_packageType The array of PackageTypes. Must be valid according to the super constructor, and must contain at least one PackageType that is local. **/ public PTArray(PackageType[] a_packageType) { super(a_packageType); boolean bLocal = false; for(int i = 0; i < getLength() && !bLocal; i++) { bLocal = isLocal(i); } if(!bLocal) { throwAX("constructor: At least one element in a_packageType must be local (meaning isLocal() equals true). All elements are currently external or primitive."); } } /**Get the PackageType for the requested prefix.
@param s_prefix The prefix of the requested PackageType. May not be null or zero characters in length. IfdoesExist(s_prefix)
equals false, then this prefix is considered primitive, and must contain only lowercase letters.
@return The PackageType that has a prefix of s_prefix if doesExist(s_prefix)
equals true.
doesExist(s_prefix)
equals false.
**/
public final PackageType getPackageType(String s_prefix) {
if(doesExist(s_prefix)) {
return (PackageType)getNamed(s_prefix);
}
//The prefix doesn't exist. It must be primitive.
for(int i = 0; i < s_prefix.length(); i++) {
if(s_prefix.charAt(i) < 'a' || s_prefix.charAt(i) > 'z') {
throwAX("getPackageType: s_prefix ('" + s_prefix + "') is not equal to any existing prefix, but contains characters other than a-z (lowercase), meaning it is also not of primitive type.");
}
}
//It is primitive.
return null;
}
/**
Get the PackageType at the requested array index.
@return(PackageType)getNamed(i_dx)
**/
public PackageType getPackageType(int i_dx) {
return (PackageType)getNamed(i_dx);
}
/**
Is the PackageType having the requested prefix local?
@returngetPackageType(s_prefix).isLocal()
**/
public final boolean isLocal(String s_prefix) {
return getPackageType(s_prefix).isLocal();
}
/**
Is the PackageType at the requested array index local?
@returngetPackageType(i_dx).isLocal()
**/
public boolean isLocal(int i_dx) {
return getPackageType(i_dx).isLocal();
}
/**
Is the PackageType having the requested prefix external?
@returngetPackageType(s_prefix).isExternal()
**/
public boolean isExternal(String s_prefix) {
return getPackageType(s_prefix).isExternal();
}
/**
Is the PackageType at the requested array index external?
@returngetPackageType(i_dx).isExternal()
**/
public boolean isExternal(int i_dx) {
return getPackageType(i_dx).isExternal();
}
/**
Get the external url for the requested prefix.
@returngetPackageType(s_prefix).getExternalUrl()
**/
public String getExternalUrl(String s_prefix) {
return getPackageType(s_prefix).getExternalUrl();
}
/**
Get the external url for the requested array index.
@returngetPackageType(i_dx).getExternalUrl()
**/
public String getExternalUrl(int i_dx) {
return getPackageType(i_dx).getExternalUrl();
}
String getNotFoundPrefixList() {
VWString vws = null;
for(int i = 0; i < getLength(); i++) {
if(!getPackageType(i).isFound()) {
if(vws == null) {
vws = new VWString();
}
vws.add(getPackageType(i).getPrefix());
}
}
if(vws == null) {
return null;
}
return (new ListPA("'", "', '", "'")).get(vws.getAOString());
}
}