1 package org.andromda.cartridges.ejb;
2
3 import java.util.ArrayList;
4 import java.util.Collection;
5 import java.util.Iterator;
6 import org.andromda.metafacades.uml.AttributeFacade;
7 import org.andromda.metafacades.uml.ModelElementFacade;
8
9
10
11
12
13
14
15 public class EJBScriptHelper
16 {
17
18
19
20
21
22
23
24
25
26
27 public String getAttributesAsList(Collection attributes, boolean includeTypes, boolean includeNames)
28 {
29 if (!includeNames && !includeTypes || attributes == null)
30 {
31 return "";
32 }
33
34 StringBuilder sb = new StringBuilder();
35 String separator = "";
36
37 for (final Iterator it = attributes.iterator(); it.hasNext();)
38 {
39 AttributeFacade attr = (AttributeFacade)it.next();
40 sb.append(separator);
41 separator = ", ";
42 if (includeTypes)
43 {
44 sb.append(attr.getType().getFullyQualifiedName());
45 sb.append(' ');
46 }
47 if (includeNames)
48 {
49 sb.append(attr.getName());
50 }
51 }
52 return sb.toString();
53 }
54
55
56
57
58
59
60
61
62 public Collection filterByVisibility(Collection list, String visibility)
63 {
64 Collection<ModelElementFacade> result = new ArrayList<ModelElementFacade>(list.size());
65 for (ModelElementFacade elem : (Iterable<ModelElementFacade>) list)
66 {
67 if (visibility.equals(elem.getVisibility()))
68 {
69 result.add(elem);
70 }
71 }
72 return result;
73 }
74
75 }