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: * Free SoftwareFoundation, Inc.
023: * 59 Temple Place, Suite 330
024: * Boston, MA 02111-1307 USA
025: *
026: * @author Sam
027: */
028:
029: package com.caucho.ejb.cfg;
030:
031: import com.caucho.config.*;
032: import com.caucho.config.types.*;
033: import com.caucho.naming.Jndi;
034: import com.caucho.util.L10N;
035: import com.caucho.webbeans.manager.*;
036:
037: import javax.annotation.PostConstruct;
038: import javax.jms.Destination;
039: import javax.naming.NamingException;
040: import java.util.logging.Logger;
041: import java.util.logging.Level;
042:
043: public class MessageDestination extends DescriptionGroupConfig {
044: private final L10N L = new L10N(MessageDestination.class);
045: private Logger log = Logger.getLogger(MessageDestination.class
046: .getName());
047:
048: private String _messageDestinationName;
049: private String _mappedName;
050:
051: private Destination _destination;
052:
053: public MessageDestination() {
054: }
055:
056: public void setMessageDestinationName(String messageDestinationName) {
057: _messageDestinationName = messageDestinationName;
058: }
059:
060: public String getMessageDestinationName() {
061: return _messageDestinationName;
062: }
063:
064: public void setMappedName(String mappedName) {
065: _mappedName = mappedName;
066: }
067:
068: public Destination getResolvedDestination() {
069: if (_destination == null)
070: resolve();
071:
072: return _destination;
073: }
074:
075: private void resolve() {
076: Destination destination = null;
077:
078: WebBeansContainer webBeans = WebBeansContainer.create();
079:
080: String name = _mappedName;
081:
082: if (name == null)
083: name = _messageDestinationName;
084:
085: if (log.isLoggable(Level.FINEST))
086: log.finest(L.l("resolving <message-destination> '{0}'",
087: name));
088:
089: destination = (Destination) webBeans.getObjectByName(name);
090:
091: if (destination == null) {
092: throw new ConfigException(
093: L
094: .l(
095: "<message-destination> '{0}' could not be resolved",
096: name));
097: }
098:
099: _destination = destination;
100: }
101:
102: public String toString() {
103: return getClass().getSimpleName() + " ["
104: + _messageDestinationName + "]";
105: }
106: }
|