Index: lutingenerator/src/java/org/codelutin/generator/PackageValidator.java diff -u /dev/null lutingenerator/src/java/org/codelutin/generator/PackageValidator.java:1.1 --- /dev/null Fri Apr 22 17:06:34 2005 +++ lutingenerator/src/java/org/codelutin/generator/PackageValidator.java Fri Apr 22 17:06:29 2005 @@ -0,0 +1,91 @@ +/* *##% + * Copyright (C) 2002, 2003, 2004, 2005 Code Lutin, + * Cédric Pineau, Benjamin Poussin, + * + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * 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 Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + *##%*/ + +/* * + * PackageValidator.java + * + * Created: 21 avr. 2005 + * + * @author Arnaud Thimel + * @version $Revision: 1.1 $ + */ + +package org.codelutin.generator; + +/** + * 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. + */ +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)) { + if (packages[i].equals(localPackageNameDot + "*")) + return false; + return true; + } + } + return false; + } + + /** + * isValid indicates if the current package + * (localPackageNameDot) is valid according to the extra + * packages list (extraPackages). + * @param localPackageNameDot 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 fullPackageName, + String localPackageNameDot, String extraPackages) { + if (localPackageNameDot.startsWith(".")) + return false; + if (extraPackages != null && !"".equals(extraPackages)) { + extraPackages = fullPackageName + ", " + extraPackages; + } else { + extraPackages = fullPackageName; + } + String[] packages = extraPackages.split(","); + for (int i = 0; i < packages.length; i++) { + packages[i] = packages[i].trim(); + if ((localPackageNameDot).matches(packages[i]) || localPackageNameDot.equals(packages[i] + ".")) { + return true; + } + } + return false; + } +}