01: package org.andromda.core.cartridge.template;
02:
03: import java.util.ArrayList;
04: import java.util.Collection;
05: import java.util.Iterator;
06: import java.util.LinkedHashSet;
07: import java.util.Set;
08:
09: import org.andromda.core.common.ExceptionUtils;
10: import org.apache.commons.lang.StringUtils;
11:
12: /**
13: * Defines the <modelElements/> element within a <template/> within an XML cartridge descriptor. This allows
14: * the grouping of model elements by criteria defined within the nested {@link ModelElement}instances.
15: *
16: * @author Chad Brandon
17: * @see Template
18: * @see ModelElement
19: */
20: public class ModelElements {
21: private String variable;
22: private final Collection modelElements = new ArrayList();
23:
24: /**
25: * The variable name to make the model element available to the template engine. For example if you have the
26: * modelElement <<entity>> defined within your <<modelElements>> element you may want to
27: * define this value as <code>entity</code>. If on the other hand the outputToSingleFile flag is set to true you'd
28: * probably want to make it available as <code>entities</code>.
29: *
30: * @return Returns the variable.
31: */
32: public String getVariable() {
33: return variable;
34: }
35:
36: /**
37: * @param variable The variable to set.
38: */
39: public void setVariable(String variable) {
40: variable = StringUtils.trimToEmpty(variable);
41: ExceptionUtils.checkEmpty("variable", variable);
42: this .variable = variable;
43: }
44:
45: /**
46: * Adds a modelElement to the collection of <code>modelElements</code>.
47: *
48: * @param modelElement the new ModelElement to add.
49: */
50: public void addModelElement(final ModelElement modelElement) {
51: ExceptionUtils.checkNull("modelElement", modelElement);
52: modelElements.add(modelElement);
53: }
54:
55: /**
56: * Gets all metafacade instances from each ModelElement belonging to this ModelElements instance.
57: *
58: * @return Collection of all metafacades.
59: */
60: public Set getAllMetafacades() {
61: final Set allMetafacades = new LinkedHashSet();
62: for (final Iterator iterator = this .modelElements.iterator(); iterator
63: .hasNext();) {
64: allMetafacades.addAll(((ModelElement) iterator.next())
65: .getMetafacades());
66: }
67: return allMetafacades;
68: }
69:
70: /**
71: * Returns all model elements belonging to this model elements instance.
72: *
73: * @return Collection of all {@link ModelElement}instances.
74: */
75: public Collection getModelElements() {
76: return this .modelElements;
77: }
78:
79: /**
80: * Returns true if this instance has no <code>modelElements</code> stored within it.
81: *
82: * @return true/false
83: */
84: public boolean isEmpty() {
85: return this.modelElements.isEmpty();
86: }
87: }
|