01: /*
02: * Copyright 2006 Google Inc.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License"); you may not
05: * use this file except in compliance with the License. You may obtain a copy of
06: * the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12: * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13: * License for the specific language governing permissions and limitations under
14: * the License.
15: */
16: package com.google.gwt.dev.util.msg;
17:
18: import com.google.gwt.core.ext.TreeLogger;
19: import com.google.gwt.core.ext.TreeLogger.Type;
20:
21: /**
22: * 1-arg message.
23: */
24: public abstract class Message1 extends Message {
25:
26: public Message1(Type type, String fmt) {
27: super (type, fmt, 1);
28: }
29:
30: protected TreeLogger branch1(TreeLogger logger, Object arg1,
31: Formatter fmt1, Throwable caught) {
32: return logger.branch(type, compose1(arg1, fmt1), caught);
33: }
34:
35: protected String compose1(Object arg1, Formatter fmt1) {
36: // Format the objects.
37: //
38: String stringArg1 = (arg1 != null ? fmt1.format(arg1) : "null");
39:
40: // To maintain consistency with the other impls, we use an insert var.
41: //
42: String insert1 = stringArg1;
43:
44: // Cache the length of the inserts.
45: //
46: int lenInsert1 = insert1.length();
47:
48: // Cache the length of each part.
49: //
50: int lenPart0 = fmtParts[0].length;
51: int lenPart1 = fmtParts[1].length;
52:
53: // Prep for copying.
54: //
55: int dest = 0;
56: char[] chars = new char[minChars + lenInsert1];
57:
58: // literal + insert, part 0
59: System.arraycopy(fmtParts[0], 0, chars, dest, lenPart0);
60: dest += lenPart0;
61:
62: insert1.getChars(0, lenInsert1, chars, dest);
63: dest += lenInsert1;
64:
65: // final literal
66: System.arraycopy(fmtParts[1], 0, chars, dest, lenPart1);
67:
68: return new String(chars);
69: }
70:
71: protected void log1(TreeLogger logger, Object arg1, Formatter fmt1,
72: Throwable caught) {
73: if (logger.isLoggable(type)) {
74: logger.log(type, compose1(arg1, fmt1), caught);
75: }
76: }
77: }
|