Index: topia/src/java/org/codelutin/topia/generators/Util.java diff -u /dev/null topia/src/java/org/codelutin/topia/generators/Util.java:1.1 --- /dev/null Mon Jun 21 09:51:22 2004 +++ topia/src/java/org/codelutin/topia/generators/Util.java Mon Jun 21 09:51:17 2004 @@ -0,0 +1,205 @@ +/* *##% + * Copyright (C) 2002, 2003 Code Lutin + * + * 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. + *##%*/ + +/* * + * Util.java + * + * Created: 19 juin 2004 + * + * @author Benjamin Poussin + * Copyright Code Lutin + * @version $Revision: 1.1 $ + * + * Mise a jour: $Date: 2004/06/21 09:51:17 $ + * par : $Author: bpoussin $ + */ + +package org.codelutin.topia.generators; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Iterator; + +import org.codelutin.generator.models.object.ObjectModelParameter; +import org.codelutin.generator.models.object.ObjectModelAttribute; +import org.codelutin.generator.models.object.ObjectModelClass; +import org.codelutin.generator.models.object.ObjectModelClassifier; +import org.codelutin.generator.models.object.ObjectModelOperation; + +/** +* Classe contenant des methodes utiles pour la generation +*/ +public class Util extends org.codelutin.generator.Util { // Util + + /** + * Returns all attributes that are part of the primary key for this class. + * @see ObjectModelAttribute + * + * @return a Collection containing all ObjectModelAttribute for this class. + */ + public static Collection getPrimaryKeyAttributes(ObjectModelClass clazz) { + ArrayList primaryKeyAttributes = new ArrayList(); + for (Iterator i = clazz.getAttributes().iterator(); i.hasNext();) { + ObjectModelAttribute attribute = (ObjectModelAttribute) i.next(); + if (isPrimaryKey(attribute)) { + primaryKeyAttributes.add(attribute); + } + } + return primaryKeyAttributes; + } + + /** + * Returns whether this classifier is an entity or not. + * + * @return a boolean indicating whether this classifier is an entity or not. + */ + public static boolean isEntity(ObjectModelClassifier classifier) { + return classifier.hasStereotype("entity"); + } + + /** + * Returns whether this classifier is a service or not. + * + * @return a boolean indicating whether this classifier is a service or not. + */ + public static boolean isService(ObjectModelClassifier classifier) { + return classifier.hasStereotype("service"); + } + + /** + * Returns whether this classifier is a controller or not. + * + * @return a boolean indicating whether this classifier is a controller or not. + */ + public static boolean isController(ObjectModelClassifier classifier) { + return classifier.hasStereotype("controller"); + } + + /** + * Returns whether this classifier is a utility or not. + * + * @return a boolean indicating whether this classifier is a utility or not. + */ + public static boolean isUtility(ObjectModelClassifier classifier) { + return classifier.hasStereotype("utility"); + } + + /** + * Returns the needed transaction level of this operation. + * Possible values includes required, requiresNew, mandatory, supports, notSupported and never. + * + * @return the the needed transaction level of this operation. + */ + public static String getTransactionLevel(ObjectModelOperation operation) { + return operation.getTagValue("transactionLevel"); + } + + public static boolean isReadOnly(ObjectModelAttribute attribute) { + String value = attribute.getTagValue("readOnly"); + return "true".equals(value); + } + + public static boolean isPrimaryKey(ObjectModelAttribute attribute) { + String value = attribute.getTagValue("primaryKey"); + return "true".equals(value); + } + + public static boolean isMandatory(ObjectModelAttribute attribute) { + String value = attribute.getTagValue("mandatory"); + return "true".equals(value); + } + + /** + * Returns whether this attribute is derived (calculated) or not. + * + * @return a boolean indicating whether this attribute is derived or not. + */ + public static boolean isDerived(ObjectModelAttribute attribute) { + String value = attribute.getTagValue("derived"); + return "true".equals(value); + } + + public static boolean isDerived(ObjectModelClass clazz){ + for (Iterator i = clazz.getAttributes().iterator(); i.hasNext();) { + ObjectModelAttribute attribute = (ObjectModelAttribute) i.next(); + if (isDerived(attribute)) { + return true; + } + } + return false; + } + + /** + * Returns the creation pattern for this auto valued attribute. + * + * @return the creation pattern for this auto valued attribute. + */ + public static String getDefaultValue(ObjectModelAttribute attribute) { + return attribute.getTagValue("defaultValue"); + } + + /** + * Returns the rendering pattern for this attribute. + * + * @return the rendering pattern for this attribute. + */ + public static String getMask(ObjectModelAttribute attribute) { + return attribute.getTagValue("mask"); + } + + /** + * Returns the enumeration name of values for this attribute. + * + * @return the the enumeration name of values for this attribute. + */ + public static String getEnumName(ObjectModelAttribute attribute) { + return attribute.getTagValue("enumName"); + } + /** + * Returns whether this attribute is to be internationalized or not. + * + * @return a boolean indicating whether this attribute is to be internationalized or not. + */ + public static boolean isI18n(ObjectModelAttribute attribute) { + String value = attribute.getTagValue("i18n"); + return "true".equals(value); + } + + /** + * Returns whether this attribute is to be versioned or not. + * + * @return a boolean indicating whether this attribute is to be versioned or not. + */ + public static boolean isVersioned(ObjectModelAttribute attribute) { + String value = attribute.getTagValue("versioned"); + return "true".equals(value); + } + + public static String getAttributeTypeForDO(ObjectModelParameter attribute) { + String result; + if (attribute instanceof ObjectModelAttribute + && isNMultiplicity((ObjectModelAttribute)attribute)){ + result = "java.util.List"; + }else{ + result = attribute.getType(); + } + return result; + } + +} // Util +