01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing,
13: * software distributed under the License is distributed on an
14: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15: * KIND, either express or implied. See the License for the
16: * specific language governing permissions and limitations
17: * under the License.
18: */
19: package org.apache.openjpa.lib.meta;
20:
21: import java.security.AccessController;
22:
23: import org.apache.openjpa.lib.util.J2DoPrivHelper;
24: import org.apache.openjpa.lib.util.Localizer;
25:
26: /**
27: * Utility class for performing common operations on {@link SourceTracker}s.
28: *
29: * @since 0.3.3.1
30: */
31: public class SourceTrackers {
32:
33: private static final Localizer _loc = Localizer
34: .forPackage(SourceTrackers.class);
35:
36: private static final String SEP = J2DoPrivHelper.getLineSeparator();
37:
38: /**
39: * Create a message appropriate for display to the user describing
40: * the location(s) that <code>trackers</code> were loaded from.
41: *
42: * @param trackers the source-trackers for which location info should
43: * be provided.
44: */
45: public static String getSourceLocationMessage(
46: SourceTracker[] trackers) {
47: StringBuffer buf = new StringBuffer(20 * (trackers.length + 1));
48: buf.append(_loc.get("source-trackers-location-header")).append(
49: SEP);
50: String sourceFilePath;
51: for (int i = 0; i < trackers.length; i++) {
52: sourceFilePath = (trackers[i].getSourceFile() == null ? _loc
53: .get("source-tracker-file-unknown").getMessage()
54: : (String) AccessController
55: .doPrivileged(J2DoPrivHelper
56: .getAbsolutePathAction(trackers[i]
57: .getSourceFile())));
58: buf.append(" ").append(
59: _loc.get("source-trackers-location-line-item",
60: trackers[i].getResourceName(),
61: sourceFilePath));
62: if (i < trackers.length - 1)
63: buf.append(SEP);
64: }
65: return buf.toString();
66: }
67: }
|