001: /*
002: * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License as published by
011: * the Free Software Foundation; either version 2 of the License, or
012: * (at your option) any later version.
013: *
014: * Resin Open Source is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017: * of NON-INFRINGEMENT. See the GNU General Public License for more
018: * details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with Resin Open Source; if not, write to the
022: *
023: * Free Software Foundation, Inc.
024: * 59 Temple Place, Suite 330
025: * Boston, MA 02111-1307 USA
026: *
027: * @author Scott Ferguson
028: */
029:
030: package com.caucho.bytecode;
031:
032: import java.util.Map;
033:
034: /**
035: * Represents an introspected annotation.
036: */
037: abstract public class JAnnotation {
038: /**
039: * Returns the class name.
040: */
041: abstract public String getType();
042:
043: /**
044: * Returns the annotation values.
045: */
046: abstract public Map<String, Object> getValueMap();
047:
048: /**
049: * Returns the annotation value.
050: */
051: public Object get(String name) {
052: return getValueMap().get(name);
053: }
054:
055: /**
056: * Returns the annotation value.
057: */
058: public String getString(String name) {
059: return (String) get(name);
060: }
061:
062: /**
063: * Returns the annotation value.
064: */
065: public JClass getClass(String name) {
066: return (JClass) get(name);
067: }
068:
069: /**
070: * Returns the annotation value.
071: */
072: public int getInt(String name) {
073: Integer value = (Integer) get(name);
074:
075: if (value != null)
076: return value.intValue();
077: else
078: return 0;
079: }
080:
081: /**
082: * Returns the annotation value.
083: */
084: public boolean getBoolean(String name) {
085: return Boolean.TRUE.equals(get(name));
086: }
087:
088: /**
089: * Returns the annotation value.
090: */
091: public JAnnotation getAnnotation(String name) {
092: return (JAnnotation) get(name);
093: }
094:
095: /**
096: * Returns true if equals.
097: */
098: public boolean equals(Object o) {
099: if (o == this )
100: return true;
101: else if (o == null || getClass() != o.getClass())
102: return false;
103:
104: JAnnotation jAnnotation = (JAnnotation) o;
105:
106: // note that the equality test doesn't include the class loader
107: return getType().equals(jAnnotation.getType());
108: }
109:
110: public String toString() {
111: return "JAnnotation[" + getType() + "]";
112: }
113: }
|