001: package org.andromda.core.namespace;
002:
003: import java.util.Arrays;
004: import java.util.Collection;
005: import java.util.LinkedHashSet;
006:
007: import org.andromda.core.common.ClassUtils;
008:
009: /**
010: * Stores information about a namespace component.
011: *
012: * @author Chad Brandon
013: */
014: public class Component {
015: /**
016: * The name of the component
017: */
018: private String name;
019:
020: /**
021: * Gets the name of the component.
022: *
023: * @return the component name.
024: */
025: public String getName() {
026: return name;
027: }
028:
029: /**
030: * Sets the name of the component.
031: *
032: * @param name the component's name.
033: */
034: public void setName(final String name) {
035: this .name = name;
036: }
037:
038: /**
039: * The path to the compoment's descriptor.
040: */
041: private final Collection paths = new LinkedHashSet();
042:
043: /**
044: * Gets the component's descriptor paths (these are the paths
045: * where the component's descriptor may be found).
046: *
047: * @return the path to the component's descriptor.
048: */
049: public String[] getPaths() {
050: return (String[]) paths.toArray(new String[0]);
051: }
052:
053: /**
054: * Adds a path to the component's descriptor.
055: *
056: * @param path that path to the component's descriptor.
057: */
058: public void addPath(final String path) {
059: this .paths.add(path);
060: }
061:
062: /**
063: * Adds the given <code>paths</code> to the existing paths
064: * contained within this component.
065: *
066: * @param paths the paths to add.
067: */
068: final void addPaths(final String[] paths) {
069: if (paths != null && paths.length > 0) {
070: this .paths.addAll(Arrays.asList(paths));
071: }
072: }
073:
074: /**
075: * Stores the interface name that defines this component.
076: */
077: private Class type;
078:
079: /**
080: * Sets the type class that defines this component.
081: *
082: * @param typeClass the name of the type.
083: */
084: public void setTypeClass(final String typeClass) {
085: final Class type = ClassUtils.loadClass(typeClass);
086: if (!NamespaceComponent.class.isAssignableFrom(type)) {
087: throw new NamespaceComponentsException(
088: "namespace component '" + type
089: + "' must implement --> '"
090: + NamespaceComponent.class.getName() + "'");
091: }
092: this .type = type;
093: }
094:
095: /**
096: * Gets the class that defines this component.
097: *
098: * @return the class that defines this component.
099: */
100: public Class getType() {
101: return this.type;
102: }
103: }
|