001: package com.bm.ejb3metadata.annotations.metadata;
002:
003: import java.util.Arrays;
004:
005: import com.bm.ejb3metadata.annotations.impl.JAnnotationResource;
006: import com.bm.ejb3metadata.annotations.impl.JEjbEJB;
007: import com.bm.ejb3metadata.annotations.impl.JavaxPersistenceContext;
008: import com.bm.ejb3metadata.annotations.impl.JavaxPersistenceUnit;
009: import com.bm.ejb3metadata.annotations.metadata.interfaces.ISharedMetadata;
010:
011: /**
012: * Defines Metadata shared by Field, Method and Classes. For example
013: * @javax.annotation.EJB, @javax.annotation.Resource, etc.
014: * @author Daniel Wiese
015: */
016: public class CommonAnnotationMetadata implements ISharedMetadata {
017:
018: /**
019: * This field is used as a PersistenceContext.
020: */
021: private JavaxPersistenceContext javaxPersistenceContext = null;
022:
023: /**
024: * This field is used as a PersistenceUnit.
025: */
026: private JavaxPersistenceUnit javaxPersistenceUnit = null;
027:
028: /**
029: * Object representing @{@link javax.ejb.EJB} annotation.
030: */
031: private JEjbEJB jEjbEJB = null;
032:
033: /**
034: * Object representing @{@link javax.annotation.Resource} annotation.
035: */
036: private JAnnotationResource jAnnotationResource = null;
037:
038: /**
039: * @return JEjbEJB object representing javax.ejb.EJB annotation.
040: */
041: public JEjbEJB getJEjbEJB() {
042: return jEjbEJB;
043: }
044:
045: /**
046: * Set JAnnotationEJB object.
047: * @param jEjbEJB object representing javax.annotation.EJB annotation.
048: */
049: public void setJEjbEJB(final JEjbEJB jEjbEJB) {
050: this .jEjbEJB = jEjbEJB;
051: }
052:
053: /**
054: * @return JAnnotationResource object representing javax.annotation.Resource
055: * annotation.
056: */
057: public JAnnotationResource getJAnnotationResource() {
058: return jAnnotationResource;
059: }
060:
061: /**
062: * Set JAnnotationResource object.
063: * @param jAnnotationResource object representing javax.annotation.Resource
064: * annotation.
065: */
066: public void setJAnnotationResource(
067: final JAnnotationResource jAnnotationResource) {
068: this .jAnnotationResource = jAnnotationResource;
069: }
070:
071: /**
072: * @return true if this field is used as a persistence context.
073: */
074: public boolean isPersistenceContext() {
075: return javaxPersistenceContext != null;
076: }
077:
078: /**
079: * @return the persistence context infos.
080: */
081: public JavaxPersistenceContext getJavaxPersistenceContext() {
082: return javaxPersistenceContext;
083: }
084:
085: /**
086: * Sets the persistence context info on this field.
087: * @param javaxPersistenceContext information on persistence context.
088: */
089: public void setJavaxPersistenceContext(
090: final JavaxPersistenceContext javaxPersistenceContext) {
091: this .javaxPersistenceContext = javaxPersistenceContext;
092: }
093:
094: /**
095: * @return true if this field is used as a persistence unit.
096: */
097: public boolean isPersistenceUnit() {
098: return javaxPersistenceUnit != null;
099: }
100:
101: /**
102: * @return the persistence unit infos.
103: */
104: public JavaxPersistenceUnit getJavaxPersistenceUnit() {
105: return javaxPersistenceUnit;
106: }
107:
108: /**
109: * Sets the persistence unit info on this field.
110: * @param javaxPersistenceUnit information on persistence unit.
111: */
112: public void setJavaxPersistenceUnit(
113: final JavaxPersistenceUnit javaxPersistenceUnit) {
114: this .javaxPersistenceUnit = javaxPersistenceUnit;
115: }
116:
117: /**
118: * @return string representation
119: */
120: @Override
121: public String toString() {
122: StringBuilder sb = new StringBuilder();
123: String titleIndent = " ";
124: // classname
125: sb.append(titleIndent);
126: sb.append(this .getClass().getName().substring(
127: this .getClass().getPackage().getName().length() + 1));
128: sb.append("[\n");
129:
130: // jEjbEJB
131: concatStringBuilder("jEjbEJB", jEjbEJB, sb);
132:
133: // jAnnotationResource
134: concatStringBuilder("jAnnotationResource", jAnnotationResource,
135: sb);
136:
137: // javaxPersistenceContext
138: concatStringBuilder("javaxPersistenceContext",
139: javaxPersistenceContext, sb);
140:
141: // javaxPersistenceUnit
142: concatStringBuilder("javaxPersistenceUnit",
143: javaxPersistenceUnit, sb);
144:
145: sb.append(titleIndent);
146: sb.append("]\n");
147: return sb.toString();
148: }
149:
150: /**
151: * Adds an entry to the given StringBuilder.
152: * @param name the name of the entry.
153: * @param object object to add.
154: * @param sb the string builder object on which add the given element.
155: * @param indent the indent to add at each line.
156: */
157: protected static void concatStringBuilder(final String name,
158: final Object object, final StringBuilder sb,
159: final String indent) {
160: if (object != null) {
161: sb.append(indent);
162: sb.append(name);
163: sb.append("=");
164: // For arrays, use asList
165: if (object instanceof Object[]) {
166: sb.append(Arrays.asList((Object[]) object));
167: } else {
168: sb.append(object);
169: }
170: sb.append("\n");
171: }
172: }
173:
174: /**
175: * Adds an entry to the given StringBuilder.
176: * @param name the name of the entry.
177: * @param object object to add.
178: * @param sb the string builder object on which add the given element.
179: */
180: protected static void concatStringBuilder(final String name,
181: final Object object, final StringBuilder sb) {
182: concatStringBuilder(name, object, sb, " ");
183: }
184:
185: }
|