org.nuiton.eugene.PackageValidator Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of eugene Show documentation
Show all versions of eugene Show documentation
Efficient Universal Generator.
/*
* #%L
* EUGene :: EUGene
*
* $Id: PackageValidator.java 1012 2010-11-28 11:24:27Z tchemit $
* $HeadURL: https://svn.nuiton.org/eugene/tags/eugene-2.10/eugene/src/main/java/org/nuiton/eugene/PackageValidator.java $
* %%
* Copyright (C) 2004 - 2010 CodeLutin
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* .
* #L%
*/
package org.nuiton.eugene;
/**
* The PackageValidator class is used by the xmi1.2ToObjectModel.xsl
* stylesheet and Xalan-Java to extend the stylesheet functionnalities.
* Allows to include external classes and interfaces to the generated
* ObjectModel.
*
* Created: 21 avr. 2005
*
* @author Arnaud Thimel
* @version $Revision: 1012 $
*/
public class PackageValidator {
/**
* The toContinue
method indicates if the package
* localPackageNameDot
has to be iterated by the stylesheet.
* @param fullPackagePath the full package path
* @param localPackageNameDot the current package to evaluate
* @param extraPackages the list of extra packages
* @return true if there is to iterate on localPackageNameDot
*/
public static boolean toContinue(String fullPackagePath,
String localPackageNameDot, String extraPackages) {
if (fullPackagePath.startsWith(localPackageNameDot)) {
return true;
}
String[] packages = extraPackages.split(",");
for (int i = 0; i < packages.length; i++) {
packages[i] = packages[i].trim();
if (packages[i].startsWith(localPackageNameDot)) {
return localPackageNameDot.length() < packages[i]
.lastIndexOf(".") + 1;
}
}
return false;
}
/**
* isValid
indicates if the current package
* (localPackageNameDot
) is valid according to the extra
* packages list (extraPackages
).
* @param fullPackagePath
* @param localPackageName the current package to evaluate
* @param extraPackages the list of extra packages
* @return true is the current package is valid
*/
public static boolean isValid(String fullPackagePath,
String localPackageName, String extraPackages) {
if (localPackageName.startsWith(fullPackagePath)) {
return true;
}
if (localPackageName.length() == 0) {
return false;
}
String[] packages = extraPackages.split(",");
for (int i = 0; i < packages.length; i++) {
packages[i] = packages[i].trim();
if (localPackageName.matches(packages[i])
|| packages[i].startsWith(localPackageName)) {
return true;
}
}
return false;
}
}