1 /***************************************************************************************
2 * Copyright (c) Jonas Bonér, Alexandre Vasseur. All rights reserved. *
3 * http://aspectwerkz.codehaus.org *
4 * ---------------------------------------------------------------------------------- *
5 * The software in this package is published under the terms of the LGPL license *
6 * a copy of which has been included with this distribution in the license.txt file. *
7 **************************************************************************************/
8 package org.codehaus.aspectwerkz.definition;
9
10 import org.codehaus.aspectwerkz.expression.ExpressionInfo;
11
12 import java.util.ArrayList;
13 import java.util.List;
14
15 /***
16 * Holds the meta-data for the interface introductions. <p/>This definition holds only pure interface introduction.
17 * <p/>It is extended in IntroductionDefinition for interface+implementation introductions
18 *
19 * @author <a href="mailto:jboner@codehaus.org">Jonas Bonér </a>
20 * @author <a href="mailto:alex@gnilux.com">Alexandre Vasseur </a>
21 */
22 public class InterfaceIntroductionDefinition {
23 /***
24 * The name of the interface introduction.
25 */
26 protected final String m_name;
27
28 /***
29 * The introduction expressions.
30 */
31 protected ExpressionInfo[] m_expressionInfos;
32
33 /***
34 * The attribute for the introduction.
35 */
36 protected String m_attribute = "";
37
38 /***
39 * The interface classes name.
40 */
41 protected List m_interfaceClassNames = new ArrayList();
42
43 /***
44 * Creates a new introduction meta-data instance.
45 *
46 * @param name the name of the expressionInfo
47 * @param expressionInfo the expressionInfo
48 * @param interfaceClassName the class name of the interface
49 */
50 public InterfaceIntroductionDefinition(final String name,
51 final ExpressionInfo expressionInfo,
52 final String interfaceClassName) {
53 if (name == null) {
54 throw new IllegalArgumentException("name can not be null");
55 }
56 if (expressionInfo == null) {
57 throw new IllegalArgumentException("expressionInfo can not be null");
58 }
59 if (interfaceClassName == null) {
60 throw new IllegalArgumentException("interface class name can not be null");
61 }
62 m_name = name;
63 m_interfaceClassNames.add(interfaceClassName);
64 m_expressionInfos = new ExpressionInfo[1];
65 m_expressionInfos[0] = expressionInfo;
66 }
67
68 /***
69 * Returns the name of the introduction.
70 *
71 * @return the name
72 */
73 public String getName() {
74 return m_name;
75 }
76
77 /***
78 * Returns the expressions.
79 *
80 * @return the expressions array
81 */
82 public ExpressionInfo[] getExpressionInfos() {
83 return m_expressionInfos;
84 }
85
86 /***
87 * Returns the class name of the interface.
88 *
89 * @return the class name of the interface
90 */
91 public String getInterfaceClassName() {
92 return (String) m_interfaceClassNames.get(0);
93 }
94
95 /***
96 * Returns the class name of the interface.
97 *
98 * @return the class name of the interface
99 */
100 public List getInterfaceClassNames() {
101 return m_interfaceClassNames;
102 }
103
104 /***
105 * Returns the attribute.
106 *
107 * @return the attribute
108 */
109 public String getAttribute() {
110 return m_attribute;
111 }
112
113 /***
114 * Sets the attribute.
115 *
116 * @param attribute the attribute
117 */
118 public void setAttribute(final String attribute) {
119 m_attribute = attribute;
120 }
121
122 /***
123 * Adds a new expression info.
124 *
125 * @param expression a new expression info
126 */
127 public void addExpressionInfo(final ExpressionInfo expression) {
128 final ExpressionInfo[] tmpExpressions = new ExpressionInfo[m_expressionInfos.length + 1];
129 java.lang.System.arraycopy(m_expressionInfos, 0, tmpExpressions, 0, m_expressionInfos.length);
130 tmpExpressions[m_expressionInfos.length] = expression;
131 m_expressionInfos = new ExpressionInfo[m_expressionInfos.length + 1];
132 java.lang.System.arraycopy(tmpExpressions, 0, m_expressionInfos, 0, tmpExpressions.length);
133 }
134
135 /***
136 * Adds an array with new expression infos.
137 *
138 * @param expressions an array with new expression infos
139 */
140 public void addExpressionInfos(final ExpressionInfo[] expressions) {
141 final ExpressionInfo[] tmpExpressions = new ExpressionInfo[m_expressionInfos.length + expressions.length];
142 java.lang.System.arraycopy(m_expressionInfos, 0, tmpExpressions, 0, m_expressionInfos.length);
143 java.lang.System.arraycopy(expressions, 0, tmpExpressions, m_expressionInfos.length, expressions.length);
144 m_expressionInfos = new ExpressionInfo[m_expressionInfos.length + expressions.length];
145 java.lang.System.arraycopy(tmpExpressions, 0, m_expressionInfos, 0, tmpExpressions.length);
146 }
147 }