KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > google > gwt > dev > util > msg > Message1


1 /*
2  * Copyright 2006 Google Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5  * use this file except in compliance with the License. You may obtain a copy of
6  * the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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 JavaDoc fmt) {
27     super(type, fmt, 1);
28   }
29
30   protected TreeLogger branch1(TreeLogger logger, Object JavaDoc arg1, Formatter fmt1,
31       Throwable JavaDoc caught) {
32     return logger.branch(type, compose1(arg1, fmt1), caught);
33   }
34
35   protected String JavaDoc compose1(Object JavaDoc arg1, Formatter fmt1) {
36     // Format the objects.
37
//
38
String JavaDoc stringArg1 = (arg1 != null ? fmt1.format(arg1) : "null");
39
40     // To maintain consistency with the other impls, we use an insert var.
41
//
42
String JavaDoc 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 JavaDoc(chars);
69   }
70
71   protected void log1(TreeLogger logger, Object JavaDoc arg1, Formatter fmt1,
72       Throwable JavaDoc caught) {
73     if (logger.isLoggable(type)) {
74       logger.log(type, compose1(arg1, fmt1), caught);
75     }
76   }
77 }
78
Popular Tags