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: */package org.apache.cxf.tools.common.model;
19:
20: import java.util.*;
21:
22: import org.apache.cxf.common.util.StringUtils;
23:
24: public class JavaAnnotation {
25: private static final String DEFAULT_QUOTE = "\"";
26:
27: private String tagName;
28: private final Map<String, String> arguments = new HashMap<String, String>();
29:
30: public JavaAnnotation() {
31: }
32:
33: public JavaAnnotation(String tn) {
34: this .tagName = tn;
35: }
36:
37: public void addArgument(String key, String value, String quote) {
38: if (!StringUtils.isEmpty(value)) {
39: arguments.put(key, quote + value + quote);
40: }
41: }
42:
43: public void addArgIgnoreEmtpy(String key, String value, String quote) {
44: if (value != null) {
45: arguments.put(key, quote + value + quote);
46: }
47: }
48:
49: public void addArgument(String key, String value) {
50: addArgument(key, value, DEFAULT_QUOTE);
51: }
52:
53: public Map<String, String> getArguments() {
54: return arguments;
55: }
56:
57: public String toString() {
58: StringBuffer sb = new StringBuffer();
59: sb.append("@");
60: sb.append(this .tagName);
61: Object[] keys = arguments.keySet().toArray();
62: if (keys.length > 0) {
63: sb.append("(");
64: for (int i = 0; i < keys.length; i++) {
65: sb.append((String) keys[i]);
66: String value = this .arguments.get((String) keys[i]);
67: if ("null".equals(value)) {
68: continue;
69: }
70: sb.append(" = ");
71: if ("".equals(value)) {
72: sb.append("\"\"");
73: } else {
74: sb.append(value);
75: }
76: if (i != (keys.length - 1)) {
77: sb.append(", ");
78: }
79: }
80: sb.append(")");
81: }
82: return sb.toString();
83: }
84: }
|