001: // Copyright 2006, 2007 The Apache Software Foundation
002: //
003: // Licensed under the Apache License, Version 2.0 (the "License");
004: // you may not use this file except in compliance with the License.
005: // You may obtain a copy of the License at
006: //
007: // http://www.apache.org/licenses/LICENSE-2.0
008: //
009: // Unless required by applicable law or agreed to in writing, software
010: // distributed under the License is distributed on an "AS IS" BASIS,
011: // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012: // See the License for the specific language governing permissions and
013: // limitations under the License.
014:
015: package org.apache.tapestry.ioc.internal;
016:
017: import static org.apache.tapestry.ioc.internal.util.InternalUtils.asString;
018: import static org.apache.tapestry.ioc.services.ClassFabUtils.toJavaClassName;
019:
020: import java.lang.reflect.Constructor;
021: import java.lang.reflect.Method;
022: import java.lang.reflect.Type;
023: import java.util.Collection;
024: import java.util.List;
025: import java.util.Map;
026:
027: import org.apache.tapestry.ioc.Messages;
028: import org.apache.tapestry.ioc.def.ContributionDef;
029: import org.apache.tapestry.ioc.def.ServiceDef;
030: import org.apache.tapestry.ioc.internal.util.InternalUtils;
031: import org.apache.tapestry.ioc.internal.util.MessagesImpl;
032:
033: final class IOCMessages {
034: private static final Messages MESSAGES = MessagesImpl
035: .forClass(IOCMessages.class);
036:
037: static String buildMethodConflict(String conflict, String existing) {
038: return MESSAGES.format("build-method-conflict", conflict,
039: existing);
040: }
041:
042: static String buildMethodWrongReturnType(Method method) {
043: return MESSAGES.format("build-method-wrong-return-type",
044: asString(method), method.getReturnType()
045: .getCanonicalName());
046: }
047:
048: static String decoratorMethodWrongReturnType(Method method) {
049: return MESSAGES.format("decorator-method-wrong-return-type",
050: asString(method), method.getReturnType()
051: .getCanonicalName());
052: }
053:
054: public static String builderLocked() {
055: return MESSAGES.get("builder-locked");
056: }
057:
058: static String serviceWrongInterface(String serviceId,
059: Class actualInterface, Class requestedInterface) {
060: return MESSAGES
061: .format("service-wrong-interface", serviceId,
062: actualInterface.getName(), requestedInterface
063: .getName());
064: }
065:
066: static String instantiateBuilderError(Class builderClass,
067: Throwable cause) {
068: return MESSAGES.format("instantiate-builder-error",
069: builderClass.getName(), cause);
070: }
071:
072: static String builderMethodError(String methodId, String serviceId,
073: Throwable cause) {
074: return MESSAGES.format("builder-method-error", methodId,
075: serviceId, cause);
076: }
077:
078: static String constructorError(String creatorDescription,
079: String serviceId, Throwable cause) {
080: return MESSAGES.format("constructor-error", creatorDescription,
081: serviceId, cause);
082: }
083:
084: static String decoratorMethodError(Method method, String serviceId,
085: Throwable cause) {
086: return MESSAGES.format("decorator-method-error",
087: asString(method), serviceId, cause);
088: }
089:
090: static String builderMethodReturnedNull(String methodId,
091: String serviceId) {
092: return MESSAGES.format("builder-method-returned-null",
093: methodId, serviceId);
094: }
095:
096: static String noServiceMatchesType(Class serviceInterface) {
097: return MESSAGES.format("no-service-matches-type",
098: serviceInterface.getName());
099: }
100:
101: static String manyServiceMatches(Class serviceInterface,
102: List<String> ids) {
103: StringBuilder buffer = new StringBuilder();
104:
105: for (int i = 0; i < ids.size(); i++) {
106: if (i > 0)
107: buffer.append(", ");
108:
109: buffer.append(ids.get(i));
110: }
111:
112: return MESSAGES.format("many-service-matches", serviceInterface
113: .getName(), ids.size(), buffer.toString());
114: }
115:
116: static String unknownScope(String name) {
117: return MESSAGES.format("unknown-scope", name);
118: }
119:
120: static String decoratorMethodNeedsDelegateParameter(Method method) {
121: return MESSAGES.format(
122: "decorator-method-needs-delegate-parameter",
123: asString(method));
124: }
125:
126: static String decoratorReturnedWrongType(Method method,
127: String serviceId, Object returned, Class serviceInterface) {
128: return MESSAGES.format("decorator-returned-wrong-type",
129: asString(method), serviceId, returned, serviceInterface
130: .getName());
131: }
132:
133: static String creatingService(String serviceId) {
134: return MESSAGES.format("creating-service", serviceId);
135: }
136:
137: static String invokingMethod(String methodId) {
138: return MESSAGES.format("invoking-method", methodId);
139: }
140:
141: static String invokingConstructor(String creatorDescription) {
142: return MESSAGES.format("invoking-constructor",
143: creatorDescription);
144: }
145:
146: static String invokingMethod(ContributionDef def) {
147: // The toString() of a contribution def is the name of the method.
148: return MESSAGES.format("invoking-method", def);
149: }
150:
151: static String recursiveServiceBuild(ServiceDef def) {
152: return MESSAGES.format("recursive-service-build", def
153: .getServiceId(), def.toString());
154: }
155:
156: static String contributionWrongReturnType(Method method) {
157: return MESSAGES.format("contribution-wrong-return-type",
158: asString(method), toJavaClassName(method
159: .getReturnType()));
160: }
161:
162: static String tooManyContributionParameters(Method method) {
163: return MESSAGES.format("too-many-contribution-parameters",
164: asString(method));
165: }
166:
167: static String noContributionParameter(Method method) {
168: return MESSAGES.format("no-contribution-parameter",
169: asString(method));
170: }
171:
172: static String contributionMethodError(Method method, Throwable cause) {
173: return MESSAGES.format("contribution-method-error",
174: asString(method), cause);
175: }
176:
177: static String contributionWasNull(String serviceId,
178: ContributionDef def) {
179: return MESSAGES.format("contribution-was-null", serviceId, def);
180: }
181:
182: static String contributionKeyWasNull(String serviceId,
183: ContributionDef def) {
184: return MESSAGES.format("contribution-key-was-null", serviceId,
185: def);
186: }
187:
188: static String contributionWrongValueType(String serviceId,
189: ContributionDef def, Class actualClass, Class expectedClass) {
190: return MESSAGES.format("contribution-wrong-value-type",
191: serviceId, def, actualClass.getName(), expectedClass
192: .getName());
193: }
194:
195: static String contributionWrongKeyType(String serviceId,
196: ContributionDef def, Class actualClass, Class expectedClass) {
197: return MESSAGES.format("contribution-wrong-key-type",
198: serviceId, def, actualClass.getName(), expectedClass
199: .getName());
200: }
201:
202: static String tooManyConfigurationParameters(String methodId) {
203: return MESSAGES.format("too-many-configuration-parameters",
204: methodId);
205: }
206:
207: static String genericTypeNotSupported(Type type) {
208: return MESSAGES.format("generic-type-not-supported", type);
209: }
210:
211: static String contributionDuplicateKey(String serviceId,
212: ContributionDef contributionDef, ContributionDef existingDef) {
213: return MESSAGES.format("contribution-duplicate-key", serviceId,
214: contributionDef, existingDef);
215: }
216:
217: static String errorBuildingService(String serviceId,
218: ServiceDef serviceDef, Throwable cause) {
219: return MESSAGES.format("error-building-service", serviceId,
220: serviceDef, cause);
221: }
222:
223: static String noPublicConstructors(Class moduleBuilderClass) {
224: return MESSAGES.format("no-public-constructors",
225: moduleBuilderClass.getName());
226: }
227:
228: static String tooManyPublicConstructors(Class moduleBuilderClass,
229: Constructor constructor) {
230: return MESSAGES.format("too-many-public-constructors",
231: moduleBuilderClass.getName(), constructor);
232: }
233:
234: static String recursiveModuleConstructor(Class builderClass,
235: Constructor constructor) {
236: return MESSAGES.format("recursive-module-constructor",
237: builderClass.getName(), constructor);
238: }
239:
240: static String constructedConfiguration(Collection result) {
241: return MESSAGES.format("constructed-configuration", result);
242: }
243:
244: static String constructedConfiguration(Map result) {
245: return MESSAGES.format("constructed-configuration", result);
246: }
247:
248: static String serviceConstructionFailed(ServiceDef serviceDef,
249: Throwable cause) {
250: return MESSAGES.format("service-construction-failed",
251: serviceDef.getServiceId(), cause);
252: }
253:
254: static String noSuchService(String serviceId,
255: Collection<String> serviceIds) {
256: return MESSAGES.format("no-such-service", serviceId,
257: InternalUtils.joinSorted(serviceIds));
258: }
259:
260: static String serviceIdConflict(String serviceId,
261: ServiceDef existing, ServiceDef conflicting) {
262: return MESSAGES.format("service-id-conflict", serviceId,
263: existing, conflicting);
264: }
265:
266: static String noConstructor(Class implementationClass,
267: String serviceId) {
268: return MESSAGES.format("no-constructor", implementationClass
269: .getName(), serviceId);
270: }
271:
272: static String bindMethodMustBeStatic(String methodId) {
273: return MESSAGES.format("bind-method-must-be-static", methodId);
274: }
275:
276: static String errorInBindMethod(String methodId, Throwable cause) {
277: return MESSAGES.format("error-in-bind-method", methodId, cause);
278: }
279:
280: static String noAutobuildConstructor(Class clazz) {
281: return MESSAGES.format("no-autobuild-constructor", clazz
282: .getName());
283: }
284:
285: static String autobuildConstructorError(
286: String constructorDescription, Throwable cause) {
287: return MESSAGES.format("autobuild-constructor-error",
288: constructorDescription, cause);
289: }
290: }
|