001package org.andromda.metafacades.uml14; 002 003import java.util.ArrayList; 004import java.util.Collection; 005import org.andromda.metafacades.uml.ClassifierFacade; 006import org.andromda.metafacades.uml.ModelElementFacade; 007import org.andromda.metafacades.uml.UMLMetafacadeProperties; 008import org.andromda.utils.StringUtilsHelper; 009import org.apache.commons.lang.StringUtils; 010import org.apache.commons.lang.SystemUtils; 011import org.omg.uml.foundation.core.Comment; 012import org.omg.uml.foundation.core.ModelElement; 013import org.omg.uml.foundation.core.TemplateParameter; 014 015/** 016 * MetafacadeLogic implementation for org.andromda.metafacades.uml.TemplateParameterFacade. 017 * 018 * @see org.andromda.metafacades.uml.TemplateParameterFacade 019 * @author Bob Fields 020 */ 021public class TemplateParameterFacadeLogicImpl 022 extends TemplateParameterFacadeLogic 023{ 024 private static final long serialVersionUID = 34L; 025 /** 026 * @param metaObject 027 * @param context 028 */ 029 public TemplateParameterFacadeLogicImpl (TemplateParameter metaObject, String context) 030 { 031 super (metaObject, context); 032 } 033 034 /** 035 * @see org.andromda.metafacades.uml.TemplateParameterFacade#getParameter() 036 */ 037 @Override 038 protected ModelElement handleGetParameter() 039 { 040 return metaObject.getParameter(); 041 } 042 043 /** 044 * @see org.andromda.metafacades.uml.TemplateParameterFacade#getDefaultElement 045 */ 046 @Override 047 protected ModelElement handleGetDefaultElement() 048 { 049 return metaObject.getDefaultElement(); 050 } 051 052 @Override 053 protected ClassifierFacade handleGetType() 054 { 055 final ParameterFacadeLogicImpl parameter = (ParameterFacadeLogicImpl)this.getParameter(); 056 return parameter.getType(); 057 } 058 059 @Override 060 protected String handleGetGetterSetterTypeName() 061 { 062 if (this.handleGetType()==null) 063 { 064 return ""; 065 } 066 else 067 { 068 // Multiplicity in return type is only supported in UML2 069 return this.getType().getFullyQualifiedName(); 070 } 071 } 072 073 @Override 074 protected String handleGetName() 075 { 076 return metaObject.getParameter().getName(); 077 } 078 079 @Override 080 protected String handleGetFullyQualifiedName() 081 { 082 final ModelElementFacade parameter = this.getParameter(); 083 return parameter.getFullyQualifiedName(); 084 } 085 086 @Override 087 protected String handleGetGetterName() 088 { 089 return "get" + StringUtils.capitalize(this.getName()); 090 } 091 092 @Override 093 protected String handleGetSetterName() 094 { 095 return "set" + StringUtils.capitalize(this.getName()); 096 } 097 098 /** 099 * UML2 only, UML14 has no concept of constrainingClassifier on the TemplateParameter 100 * @see org.andromda.metafacades.uml14.TemplateParameterFacadeLogic#handleGetConstrainingClassifiers() 101 */ 102 @Override 103 protected Collection<ClassifierFacade> handleGetConstrainingClassifiers() 104 { 105 return new ArrayList<ClassifierFacade>(); 106 } 107 108 @Override 109 protected ModelElementFacade handleGetOwner() 110 { 111 return (ModelElementFacade) this.shieldedElement(this.metaObject.getTemplate().getNamespace()); 112 } 113 114 @Override 115 protected String handleGetDocumentation(String indent) 116 { 117 return getDocumentation( 118 indent, 119 80 - indent.length()); 120 } 121 122 @Override 123 protected String handleGetDocumentation(String indent, int lineLength) 124 { 125 return getDocumentation( 126 indent, 127 lineLength, 128 true); 129 } 130 131 /** 132 * Duplicated from ModelElementFacade because there is no inheritance relationship 133 * @see org.andromda.metafacades.uml14.TemplateParameterFacadeLogic#handleGetDocumentation(java.lang.String, int, boolean) 134 */ 135 @Override 136 protected String handleGetDocumentation(String indent, int lineLength, boolean htmlStyle) 137 { 138 final StringBuilder documentation = new StringBuilder(); 139 140 if (lineLength < 1) 141 { 142 lineLength = Integer.MAX_VALUE; 143 } 144 145 final Collection<Comment> comments = this.metaObject.getParameter().getComment(); 146 if (comments != null && !comments.isEmpty()) 147 { 148 for (Comment comment : comments) 149 { 150 String commentString = StringUtils.trimToEmpty(comment.getBody()); 151 152 // if there isn't anything in the body, try the name 153 if (StringUtils.isBlank(commentString)) 154 { 155 commentString = StringUtils.trimToEmpty(comment.getName()); 156 } 157 documentation.append(StringUtils.trimToEmpty(commentString)); 158 documentation.append(SystemUtils.LINE_SEPARATOR); 159 } 160 } 161 162 // Add toDoTag if doc is empty: make modelers do the documentation. 163 if (StringUtils.isEmpty(documentation.toString())) 164 { 165 if (Boolean.valueOf((String)this.getConfiguredProperty(UMLMetafacadeProperties.TODO_FOR_MISSING_DOCUMENTATION))) 166 { 167 String todoTag = (String)this.getConfiguredProperty(UMLMetafacadeProperties.TODO_TAG); 168 documentation.append(todoTag).append(": Model Documentation for " + this.getFullyQualifiedName()); 169 } 170 } 171 172 // Only add paragraph tags if doc is not empty 173 String rtn = StringUtilsHelper.format( 174 StringUtils.trimToEmpty(documentation.toString()), 175 indent, 176 lineLength, 177 htmlStyle); 178 179 return rtn; 180 } 181 /** 182 * @see org.andromda.core.metafacade.MetafacadeBase#getValidationName 183 */ 184 @Override 185 public String getValidationName() 186 { 187 return metaObject.getParameter().getName(); 188 } 189 190 /** 191 * @see org.andromda.core.metafacade.MetafacadeBase#getValidationOwner 192 */ 193 @Override 194 public ModelElement getValidationOwner() 195 { 196 return metaObject.getTemplate(); 197 } 198}