001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */package org.apache.geronimo.connector.deployment;
017:
018: import java.lang.reflect.Field;
019: import java.lang.reflect.Method;
020: import java.util.HashMap;
021: import java.util.List;
022: import java.util.Map;
023:
024: import javax.annotation.Resource;
025: import javax.naming.Reference;
026: import javax.xml.namespace.QName;
027:
028: import org.apache.commons.logging.Log;
029: import org.apache.commons.logging.LogFactory;
030: import org.apache.geronimo.common.DeploymentException;
031: import org.apache.geronimo.common.UnresolvedReferenceException;
032: import org.apache.geronimo.gbean.AbstractNameQuery;
033: import org.apache.geronimo.gbean.GBeanInfo;
034: import org.apache.geronimo.gbean.GBeanInfoBuilder;
035: import org.apache.geronimo.j2ee.deployment.EARContext;
036: import org.apache.geronimo.j2ee.deployment.Module;
037: import org.apache.geronimo.j2ee.deployment.annotation.AnnotatedApp;
038: import org.apache.geronimo.j2ee.deployment.annotation.ResourceAnnotationHelper;
039: import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
040: import org.apache.geronimo.kernel.GBeanNotFoundException;
041: import org.apache.geronimo.kernel.config.Configuration;
042: import org.apache.geronimo.kernel.repository.Environment;
043: import org.apache.geronimo.naming.deployment.AbstractNamingBuilder;
044: import org.apache.geronimo.naming.reference.ResourceReferenceFactory;
045: import org.apache.geronimo.naming.reference.UserTransactionReference;
046: import org.apache.geronimo.xbeans.geronimo.naming.GerMessageDestinationDocument;
047: import org.apache.geronimo.xbeans.geronimo.naming.GerMessageDestinationType;
048: import org.apache.geronimo.xbeans.geronimo.naming.GerPatternType;
049: import org.apache.geronimo.xbeans.geronimo.naming.GerResourceEnvRefDocument;
050: import org.apache.geronimo.xbeans.geronimo.naming.GerResourceEnvRefType;
051: import org.apache.geronimo.xbeans.javaee.DescriptionType;
052: import org.apache.geronimo.xbeans.javaee.FullyQualifiedClassType;
053: import org.apache.geronimo.xbeans.javaee.InjectionTargetType;
054: import org.apache.geronimo.xbeans.javaee.JndiNameType;
055: import org.apache.geronimo.xbeans.javaee.MessageDestinationRefType;
056: import org.apache.geronimo.xbeans.javaee.MessageDestinationType;
057: import org.apache.geronimo.xbeans.javaee.MessageDestinationTypeType;
058: import org.apache.geronimo.xbeans.javaee.ResourceEnvRefType;
059: import org.apache.geronimo.xbeans.javaee.XsdStringType;
060: import org.apache.xmlbeans.QNameSet;
061: import org.apache.xmlbeans.XmlObject;
062:
063: /**
064: * @version $Rev: 608311 $ $Date: 2008-01-02 18:44:54 -0800 (Wed, 02 Jan 2008) $
065: */
066: public class AdminObjectRefBuilder extends AbstractNamingBuilder {
067: private final static Log log = LogFactory
068: .getLog(AdminObjectRefBuilder.class);
069: private final QNameSet adminOjbectRefQNameSet;
070: private final QNameSet messageDestinationQNameSet;
071: private final QNameSet messageDestinationRefQNameSet;
072:
073: private static final QName GER_ADMIN_OBJECT_REF_QNAME = GerResourceEnvRefDocument.type
074: .getDocumentElementName();
075: private static final QNameSet GER_ADMIN_OBJECT_REF_QNAME_SET = QNameSet
076: .singleton(GER_ADMIN_OBJECT_REF_QNAME);
077: private static final QName GER_MESSAGE_DESTINATION_QNAME = GerMessageDestinationDocument.type
078: .getDocumentElementName();
079: private static final QNameSet GER_MESSAGE_DESTINATION_QNAME_SET = QNameSet
080: .singleton(GER_MESSAGE_DESTINATION_QNAME);
081:
082: public AdminObjectRefBuilder(Environment defaultEnvironment,
083: String[] eeNamespaces) {
084: super (defaultEnvironment);
085: adminOjbectRefQNameSet = buildQNameSet(eeNamespaces,
086: "resource-env-ref");
087: messageDestinationQNameSet = buildQNameSet(eeNamespaces,
088: "message-destination");
089: messageDestinationRefQNameSet = buildQNameSet(eeNamespaces,
090: "message-destination-ref");
091: }
092:
093: protected boolean willMergeEnvironment(XmlObject specDD,
094: XmlObject plan) {
095: return specDD.selectChildren(adminOjbectRefQNameSet).length > 0
096: || specDD.selectChildren(messageDestinationRefQNameSet).length > 0;
097: }
098:
099: public void initContext(XmlObject specDD, XmlObject plan,
100: Module module) throws DeploymentException {
101: List<MessageDestinationType> specDestinations = convert(specDD
102: .selectChildren(messageDestinationQNameSet),
103: JEE_CONVERTER, MessageDestinationType.class,
104: MessageDestinationType.type);
105: XmlObject[] gerDestinations = plan
106: .selectChildren(GER_MESSAGE_DESTINATION_QNAME_SET);
107: Map<String, GerMessageDestinationType> nameMap = new HashMap<String, GerMessageDestinationType>();
108: for (XmlObject gerDestination : gerDestinations) {
109: GerMessageDestinationType destination = (GerMessageDestinationType) gerDestination
110: .copy().changeType(GerMessageDestinationType.type);
111: String name = destination.getMessageDestinationName()
112: .trim();
113: nameMap.put(name, destination);
114: boolean found = false;
115: for (MessageDestinationType specDestination : specDestinations) {
116: if (specDestination.getMessageDestinationName()
117: .getStringValue().trim().equals(name)) {
118: found = true;
119: break;
120: }
121: }
122: if (!found) {
123: throw new DeploymentException(
124: "No spec DD message-destination for " + name);
125: }
126: }
127: module.getRootEarContext().registerMessageDestionations(
128: module.getName(), nameMap);
129: }
130:
131: public void buildNaming(XmlObject specDD, XmlObject plan,
132: Module module, Map componentContext)
133: throws DeploymentException {
134: XmlObject[] gerResourceEnvRefsUntyped = plan == null ? NO_REFS
135: : plan.selectChildren(GER_ADMIN_OBJECT_REF_QNAME_SET);
136: Map<String, GerResourceEnvRefType> refMap = mapResourceEnvRefs(gerResourceEnvRefsUntyped);
137: int initialGerRefSize = refMap.size();
138: Map<String, Map<String, GerMessageDestinationType>> messageDestinations = module
139: .getRootEarContext().getMessageDestinations();
140:
141: // Discover and process any @Resource annotations (if !metadata-complete)
142: if (module.getClassFinder() != null) {
143:
144: // Process all the annotations for this naming builder type
145: try {
146: ResourceAnnotationHelper.processAnnotations(module
147: .getAnnotatedApp(), module.getClassFinder(),
148: new AdminObjectRefProcessor(refMap,
149: messageDestinations, module
150: .getEarContext()));
151: } catch (Exception e) {
152: log.warn(
153: "Unable to process @Resource annotations for module"
154: + module.getName(), e);
155: }
156: }
157:
158: List<ResourceEnvRefType> resourceEnvRefsUntyped = convert(
159: specDD.selectChildren(adminOjbectRefQNameSet),
160: JEE_CONVERTER, ResourceEnvRefType.class,
161: ResourceEnvRefType.type);
162: int unresolvedRefSize = resourceEnvRefsUntyped.size();
163: ClassLoader cl = module.getEarContext().getClassLoader();
164: for (ResourceEnvRefType resourceEnvRef : resourceEnvRefsUntyped) {
165: String name = resourceEnvRef.getResourceEnvRefName()
166: .getStringValue().trim();
167: addInjections(name, resourceEnvRef
168: .getInjectionTargetArray(), componentContext);
169: String type = resourceEnvRef.getResourceEnvRefType()
170: .getStringValue().trim();
171: Class iface;
172: try {
173: iface = cl.loadClass(type);
174: } catch (ClassNotFoundException e) {
175: throw new DeploymentException("could not load class "
176: + type, e);
177: }
178: GerResourceEnvRefType gerResourceEnvRef = refMap.get(name);
179: refMap.remove(name);
180: try {
181: String refType = getStringValue(resourceEnvRef
182: .getResourceEnvRefType());
183: if (refType.equals("javax.transaction.UserTransaction")) {
184: Reference ref = new UserTransactionReference();
185: getJndiContextMap(componentContext).put(ENV + name,
186: ref);
187: } else {
188: AbstractNameQuery containerId = getAdminObjectContainerId(
189: name, gerResourceEnvRef);
190: ResourceReferenceFactory<RuntimeException> ref = buildAdminObjectReference(
191: module, containerId, iface);
192: getJndiContextMap(componentContext).put(ENV + name,
193: ref);
194: }
195: } catch (UnresolvedReferenceException e) {
196: throw new DeploymentException(
197: "Unable to resolve resource env reference '"
198: + name
199: + "' ("
200: + (e.isMultiple() ? "found multiple matching resources"
201: : "no matching resources found")
202: + ")", e);
203: }
204: }
205:
206: if ((initialGerRefSize - unresolvedRefSize) != refMap.size()) {
207: log
208: .warn("Failed to build reference to Admin object reference "
209: + refMap.keySet()
210: + " defined in plan file, reason - corresponding entry in deployment descriptor missing.");
211: }
212:
213: //message-destination-refs
214: List<MessageDestinationRefType> messageDestinationRefsUntyped = convert(
215: specDD.selectChildren(messageDestinationRefQNameSet),
216: JEE_CONVERTER, MessageDestinationRefType.class,
217: MessageDestinationRefType.type);
218:
219: for (MessageDestinationRefType messageDestinationRef : messageDestinationRefsUntyped) {
220: String name = getStringValue(messageDestinationRef
221: .getMessageDestinationRefName());
222: addInjections(name, messageDestinationRef
223: .getInjectionTargetArray(), componentContext);
224: String linkName = getStringValue(messageDestinationRef
225: .getMessageDestinationLink());
226: //TODO figure out something better to do here!
227: if (linkName == null) {
228: linkName = name;
229: }
230: String type = getStringValue(messageDestinationRef
231: .getMessageDestinationType());
232: if (type == null) {
233: //must have an injection target to determine type EE5.8.1.3
234: InjectionTargetType[] targets = messageDestinationRef
235: .getInjectionTargetArray();
236: if (targets.length == 0) {
237: throw new DeploymentException(
238: "No type for message-destination-ref can be determined from explicit specification or injection target: "
239: + messageDestinationRef);
240: }
241: type = getStringValue(targets[0]
242: .getInjectionTargetClass());
243: if (type == null) {
244: throw new DeploymentException(
245: "no type for message destination ref in injection target: "
246: + targets[0]);
247: }
248: }
249: Class iface;
250: try {
251: iface = cl.loadClass(type);
252: } catch (ClassNotFoundException e) {
253: throw new DeploymentException("could not load class "
254: + type, e);
255: }
256: String moduleURI = null;
257: GerMessageDestinationType destination = getMessageDestination(
258: linkName, messageDestinations);
259: if (destination != null) {
260: if (destination.isSetAdminObjectLink()) {
261: if (destination.isSetAdminObjectModule()) {
262: moduleURI = destination.getAdminObjectModule()
263: .trim();
264: }
265: linkName = destination.getAdminObjectLink().trim();
266: }
267: } else {
268: //well, we know for sure an admin object is not going to be defined in a modules that can have a message-destination
269: int pos = linkName.indexOf('#');
270: if (pos > -1) {
271: //AMM -- the following line causes blowups; e.g. to look in DayTrader EJB module for a RA -- why is that?!?
272: //moduleURI = linkName.substring(0, pos);
273: linkName = linkName.substring(pos + 1);
274: }
275: }
276:
277: //try to resolve ref based only matching resource-ref-name
278: //throws exception if it can't locate ref.
279: AbstractNameQuery containerId = buildAbstractNameQuery(
280: null, moduleURI, linkName,
281: NameFactory.JCA_ADMIN_OBJECT,
282: NameFactory.RESOURCE_ADAPTER_MODULE);
283: ResourceReferenceFactory<RuntimeException> ref = buildAdminObjectReference(
284: module, containerId, iface);
285: getJndiContextMap(componentContext).put(ENV + name, ref);
286:
287: }
288:
289: }
290:
291: public static GerMessageDestinationType getMessageDestination(
292: String messageDestinationLink,
293: Map<String, Map<String, GerMessageDestinationType>> messageDestinations)
294: throws DeploymentException {
295: GerMessageDestinationType destination = null;
296: int pos = messageDestinationLink.indexOf('#');
297: if (pos > -1) {
298: String targetModule = messageDestinationLink.substring(0,
299: pos);
300: Map<String, GerMessageDestinationType> destinations = messageDestinations
301: .get(targetModule);
302: // Hmmm...if we don't find the module then something is wrong in the deployment.
303: if (destinations == null) {
304: StringBuffer sb = new StringBuffer();
305: for (Object o : messageDestinations.keySet()) {
306: sb.append(o).append("\n");
307: }
308: throw new DeploymentException("Unknown module "
309: + targetModule
310: + " when processing message destination "
311: + messageDestinationLink
312: + "\nKnown modules in deployable unit are:\n"
313: + sb.toString());
314: }
315: messageDestinationLink = messageDestinationLink
316: .substring(pos + 1);
317: destination = destinations.get(messageDestinationLink);
318: } else {
319: for (Map<String, GerMessageDestinationType> destinations : messageDestinations
320: .values()) {
321: GerMessageDestinationType destinationTest = destinations
322: .get(messageDestinationLink);
323: if (destinationTest != null) {
324: if (destination != null) {
325: throw new DeploymentException(
326: "Duplicate message destination "
327: + messageDestinationLink
328: + " accessed from a message-destination-link without a module");
329: }
330: destination = destinationTest;
331: }
332: }
333: }
334: return destination;
335: }
336:
337: private ResourceReferenceFactory<RuntimeException> buildAdminObjectReference(
338: Module module, AbstractNameQuery containerId, Class iface)
339: throws DeploymentException {
340: Configuration localConfiguration = module.getEarContext()
341: .getConfiguration();
342: try {
343: localConfiguration.findGBean(containerId);
344: } catch (GBeanNotFoundException e) {
345: throw new DeploymentException(
346: "Can not resolve admin object ref " + containerId
347: + " in configuration "
348: + localConfiguration.getId(), e);
349: }
350: return new ResourceReferenceFactory<RuntimeException>(module
351: .getConfigId(), containerId, iface);
352: }
353:
354: private static AbstractNameQuery getAdminObjectContainerId(
355: String name, GerResourceEnvRefType gerResourceEnvRef) {
356: AbstractNameQuery containerId;
357: if (gerResourceEnvRef == null) {
358: containerId = buildAbstractNameQuery(null, null, name,
359: NameFactory.JCA_ADMIN_OBJECT,
360: NameFactory.RESOURCE_ADAPTER_MODULE);
361: } else if (gerResourceEnvRef.isSetMessageDestinationLink()) {
362: containerId = buildAbstractNameQuery(null, null,
363: gerResourceEnvRef.getMessageDestinationLink()
364: .trim(), NameFactory.JCA_ADMIN_OBJECT,
365: NameFactory.RESOURCE_ADAPTER_MODULE);
366: } else if (gerResourceEnvRef.isSetAdminObjectLink()) {
367: String moduleURI = null;
368: if (gerResourceEnvRef.isSetAdminObjectModule()) {
369: moduleURI = gerResourceEnvRef.getAdminObjectModule()
370: .trim();
371: }
372: containerId = buildAbstractNameQuery(null, moduleURI,
373: gerResourceEnvRef.getAdminObjectLink().trim(),
374: NameFactory.JCA_ADMIN_OBJECT,
375: NameFactory.RESOURCE_ADAPTER_MODULE);
376: } else {
377: //construct name from components
378: GerPatternType patternType = gerResourceEnvRef.getPattern();
379: containerId = buildAbstractNameQuery(patternType,
380: NameFactory.JCA_ADMIN_OBJECT,
381: NameFactory.RESOURCE_ADAPTER_MODULE, null);
382: }
383: return containerId;
384: }
385:
386: private static Map<String, GerResourceEnvRefType> mapResourceEnvRefs(
387: XmlObject[] refs) {
388: Map<String, GerResourceEnvRefType> refMap = new HashMap<String, GerResourceEnvRefType>();
389: if (refs != null) {
390: for (XmlObject ref1 : refs) {
391: GerResourceEnvRefType ref = (GerResourceEnvRefType) ref1
392: .copy().changeType(GerResourceEnvRefType.type);
393: refMap.put(ref.getRefName().trim(), ref);
394: }
395: }
396: return refMap;
397: }
398:
399: public QNameSet getSpecQNameSet() {
400: return adminOjbectRefQNameSet;
401: }
402:
403: public QNameSet getPlanQNameSet() {
404: return GER_ADMIN_OBJECT_REF_QNAME_SET;
405: }
406:
407: public static class AdminObjectRefProcessor extends
408: ResourceAnnotationHelper.ResourceProcessor {
409: public static final AdminObjectRefProcessor INSTANCE = new AdminObjectRefProcessor(
410: null, null, null);
411:
412: private final EARContext earContext;
413: private final Map<String, GerResourceEnvRefType> refMap;
414: private final Map<String, Map<String, GerMessageDestinationType>> messageDestinations;
415:
416: public AdminObjectRefProcessor(
417: Map<String, GerResourceEnvRefType> refMap,
418: Map<String, Map<String, GerMessageDestinationType>> messageDestinations,
419: EARContext earContext) {
420: this .refMap = refMap;
421: this .messageDestinations = messageDestinations;
422: this .earContext = earContext;
423: }
424:
425: public boolean processResource(AnnotatedApp annotatedApp,
426: Resource annotation, Class cls, Method method,
427: Field field) throws DeploymentException {
428: String resourceName = getResourceName(annotation, method,
429: field);
430: String resourceType = getResourceType(annotation, method,
431: field);
432:
433: if (resourceType.equals("javax.ejb.SessionContext"))
434: return true;
435: if (resourceType.equals("javax.ejb.MessageDrivenContext"))
436: return true;
437: if (resourceType.equals("javax.ejb.EntityContext"))
438: return true;
439: if (resourceType.equals("javax.ejb.TimerService"))
440: return true;
441:
442: //If it already exists in xml as a message-destination-ref or resource-env-ref, we are done.
443: MessageDestinationRefType[] messageDestinationRefs = annotatedApp
444: .getMessageDestinationRefArray();
445: for (MessageDestinationRefType messageDestinationRef : messageDestinationRefs) {
446: if (messageDestinationRef
447: .getMessageDestinationRefName()
448: .getStringValue().trim().equals(resourceName)) {
449: if (method != null || field != null) {
450: InjectionTargetType[] targets = messageDestinationRef
451: .getInjectionTargetArray();
452: if (!hasTarget(method, field, targets)) {
453: configureInjectionTarget(
454: messageDestinationRef
455: .addNewInjectionTarget(),
456: method, field);
457: }
458: }
459: return true;
460: }
461: }
462: ResourceEnvRefType[] ResourceEnvRefs = annotatedApp
463: .getResourceEnvRefArray();
464: for (ResourceEnvRefType resourceEnvRefType : ResourceEnvRefs) {
465: if (resourceEnvRefType.getResourceEnvRefName()
466: .getStringValue().trim().equals(resourceName)) {
467: if (method != null || field != null) {
468: InjectionTargetType[] targets = resourceEnvRefType
469: .getInjectionTargetArray();
470: if (!hasTarget(method, field, targets)) {
471: configureInjectionTarget(resourceEnvRefType
472: .addNewInjectionTarget(), method,
473: field);
474: }
475: }
476: return true;
477: }
478: }
479:
480: //if it maps to a message-destination in the geronimo plan, it's a message-destination.
481: GerMessageDestinationType gerMessageDestinationType = null;
482: if (messageDestinations != null) {
483: gerMessageDestinationType = getMessageDestination(
484: resourceName, messageDestinations);
485: }
486: if (gerMessageDestinationType != null) {
487: addMethodDestinationRef(annotatedApp, resourceName,
488: resourceType, method, field, annotation);
489: return true;
490: } else {
491: //if it maps to a resource-env-ref in the geronimo plan, it's a resource-ref
492: GerResourceEnvRefType resourceEnvRefType = null;
493: if (refMap != null) {
494: resourceEnvRefType = refMap.get(resourceName);
495: }
496: if (resourceEnvRefType != null
497: || resourceType
498: .equals("javax.transaction.UserTransaction")) {
499: //mapped resource-env-ref
500: addResourceEnvRef(annotatedApp, resourceName,
501: resourceType, method, field, annotation);
502: return true;
503: } else {
504: if (earContext != null) {
505: // look for an JCAAdminObject gbean with the right name
506: AbstractNameQuery containerId = buildAbstractNameQuery(
507: null, null, resourceName,
508: NameFactory.JCA_ADMIN_OBJECT,
509: NameFactory.RESOURCE_ADAPTER_MODULE);
510: try {
511: earContext.findGBean(containerId);
512: } catch (GBeanNotFoundException e) {
513: // not identifiable as an admin object ref
514: return false;
515: }
516: } else {
517: if (!("javax.jms.Queue".equals(resourceType)
518: || "javax.jms.Topic"
519: .equals(resourceType) || "javax.jms.Destination"
520: .equals(resourceType))) {
521: // not identifiable as an admin object ref
522: return false;
523: }
524: }
525: addResourceEnvRef(annotatedApp, resourceName,
526: resourceType, method, field, annotation);
527: return true;
528: }
529: }
530: }
531:
532: private void addResourceEnvRef(AnnotatedApp annotatedApp,
533: String resourceName, String resourceType,
534: Method method, Field field, Resource annotation) {
535: ResourceEnvRefType resourceEnvRef = annotatedApp
536: .addNewResourceEnvRef();
537:
538: //------------------------------------------------------------------------------
539: // <resource-env-ref> required elements:
540: //------------------------------------------------------------------------------
541:
542: // resource-env-ref-name
543: JndiNameType resourceEnvRefName = resourceEnvRef
544: .addNewResourceEnvRefName();
545: resourceEnvRefName.setStringValue(resourceName);
546: resourceEnvRef.setResourceEnvRefName(resourceEnvRefName);
547:
548: if (!resourceType.equals("")) {
549: // resource-env-ref-type
550: FullyQualifiedClassType qualifiedClass = resourceEnvRef
551: .addNewResourceEnvRefType();
552: qualifiedClass.setStringValue(resourceType);
553: resourceEnvRef.setResourceEnvRefType(qualifiedClass);
554: }
555: if (method != null || field != null) {
556: // injectionTarget
557: InjectionTargetType injectionTarget = resourceEnvRef
558: .addNewInjectionTarget();
559: configureInjectionTarget(injectionTarget, method, field);
560: }
561:
562: //------------------------------------------------------------------------------
563: // <resource-env-ref> optional elements:
564: //------------------------------------------------------------------------------
565:
566: // description
567: String descriptionAnnotation = annotation.description();
568: if (!descriptionAnnotation.equals("")) {
569: DescriptionType description = resourceEnvRef
570: .addNewDescription();
571: description.setStringValue(descriptionAnnotation);
572: }
573:
574: // mappedName
575: String mappdedNameAnnotation = annotation.mappedName();
576: if (!mappdedNameAnnotation.equals("")) {
577: XsdStringType mappedName = resourceEnvRef
578: .addNewMappedName();
579: mappedName.setStringValue(mappdedNameAnnotation);
580: resourceEnvRef.setMappedName(mappedName);
581: }
582: }
583:
584: private void addMethodDestinationRef(AnnotatedApp annotatedApp,
585: String resourceName, String resourceType,
586: Method method, Field field, Resource annotation) {
587: MessageDestinationRefType messageDestinationRef = annotatedApp
588: .addNewMessageDestinationRef();
589:
590: //------------------------------------------------------------------------------
591: // <message-destination-ref> required elements:
592: //------------------------------------------------------------------------------
593:
594: // message-destination-ref-name
595: JndiNameType messageDestinationRefName = messageDestinationRef
596: .addNewMessageDestinationRefName();
597: messageDestinationRefName.setStringValue(resourceName);
598: messageDestinationRef
599: .setMessageDestinationRefName(messageDestinationRefName);
600:
601: if (!resourceType.equals("")) {
602: // message-destination-ref-type
603: MessageDestinationTypeType msgDestType = messageDestinationRef
604: .addNewMessageDestinationType();
605: msgDestType.setStringValue(resourceType);
606: messageDestinationRef
607: .setMessageDestinationType(msgDestType);
608: }
609: if (method != null || field != null) {
610: // injectionTarget
611: InjectionTargetType injectionTarget = messageDestinationRef
612: .addNewInjectionTarget();
613: configureInjectionTarget(injectionTarget, method, field);
614: }
615:
616: //------------------------------------------------------------------------------
617: // <message-destination-ref> optional elements:
618: //------------------------------------------------------------------------------
619:
620: // description
621: String descriptionAnnotation = annotation.description();
622: if (!descriptionAnnotation.equals("")) {
623: DescriptionType description = messageDestinationRef
624: .addNewDescription();
625: description.setStringValue(descriptionAnnotation);
626: }
627:
628: // mappedName
629: String mappdedNameAnnotation = annotation.mappedName();
630: if (!mappdedNameAnnotation.equals("")) {
631: XsdStringType mappedName = messageDestinationRef
632: .addNewMappedName();
633: mappedName.setStringValue(mappdedNameAnnotation);
634: messageDestinationRef.setMappedName(mappedName);
635: }
636: }
637: }
638:
639: public static final GBeanInfo GBEAN_INFO;
640:
641: static {
642: GBeanInfoBuilder infoBuilder = GBeanInfoBuilder
643: .createStatic(AdminObjectRefBuilder.class,
644: NameFactory.MODULE_BUILDER);
645: infoBuilder.addAttribute("eeNamespaces", String[].class, true,
646: true);
647: infoBuilder.addAttribute("defaultEnvironment",
648: Environment.class, true, true);
649:
650: infoBuilder.setConstructor(new String[] { "defaultEnvironment",
651: "eeNamespaces" });
652:
653: GBEAN_INFO = infoBuilder.getBeanInfo();
654: }
655:
656: public static GBeanInfo getGBeanInfo() {
657: return GBEAN_INFO;
658: }
659:
660: }
|