01: package org.andromda.cartridges.ejb;
02:
03: import org.andromda.metafacades.uml.AttributeFacade;
04: import org.andromda.metafacades.uml.ModelElementFacade;
05:
06: import java.util.ArrayList;
07: import java.util.Collection;
08: import java.util.Iterator;
09:
10: /**
11: * Transform class for the EJB cartridge.
12: *
13: * @author Richard Kunze
14: * @author Chad Brandon
15: */
16: public class EJBScriptHelper {
17:
18: /**
19: * Create a comma seperated list of attributes.
20: * <p/>
21: * This method can be used to generated e.g. argument lists for constructors, method calls etc.
22: *
23: * @param attributes a collection of {@link Attribute} objects
24: * @param includeTypes if <code>true</code>, the type names of the attributes are included.
25: * @param includeNames if <code>true</code>, the names of the attributes are included
26: */
27: public String getAttributesAsList(Collection attributes,
28: boolean includeTypes, boolean includeNames) {
29: if (!includeNames && !includeTypes || attributes == null) {
30: return "";
31: }
32:
33: StringBuffer sb = new StringBuffer();
34: String separator = "";
35:
36: for (final Iterator it = attributes.iterator(); it.hasNext();) {
37: AttributeFacade attr = (AttributeFacade) it.next();
38: sb.append(separator);
39: separator = ", ";
40: if (includeTypes) {
41: sb.append(attr.getType().getFullyQualifiedName());
42: sb.append(" ");
43: }
44: if (includeNames) {
45: sb.append(attr.getName());
46: }
47: }
48: return sb.toString();
49: }
50:
51: /**
52: * Filter a list of model elements by visibility.
53: *
54: * @param list the original list
55: * @param visibility the visibility - "public" "protected", "private" or the empty string (for package visibility)
56: * @return a list with all elements from the original list that have a matching visibility.
57: */
58: public Collection filterByVisibility(Collection list,
59: String visibility) {
60: Collection retval = new ArrayList(list.size());
61: for (final Iterator iter = list.iterator(); iter.hasNext();) {
62: ModelElementFacade elem = (ModelElementFacade) iter.next();
63: if (visibility.equals(elem.getVisibility().toString())) {
64: retval.add(elem);
65: }
66: }
67: return retval;
68: }
69:
70: }
|