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.config.core;
031:
032: import com.caucho.naming.Jndi;
033: import com.caucho.util.L10N;
034:
035: import com.caucho.webbeans.manager.WebBeansContainer;
036: import javax.annotation.PostConstruct;
037:
038: /**
039: * Sets an EL value.
040: */
041: public class ResinSet {
042: private static L10N L = new L10N(ResinSet.class);
043:
044: private String _jndiName;
045: private String _var;
046:
047: private Object _value;
048: private boolean _hasValue;
049:
050: private Object _default;
051:
052: /**
053: * The EL name to be set.
054: */
055: public void setVar(String name) {
056: _var = name;
057: }
058:
059: /**
060: * The JNDI name to be set.
061: */
062: public void setJndiName(String name) {
063: _jndiName = name;
064: }
065:
066: /**
067: * The EL value to be set.
068: */
069: public void setValue(Object value) {
070: _hasValue = true;
071: _value = value;
072: }
073:
074: /**
075: * The EL default value to be set.
076: */
077: public void setDefault(Object value) {
078: _default = value;
079: }
080:
081: /**
082: * The EL value to be set.
083: */
084: public void setProperty(String name, Object value) {
085: WebBeansContainer.create().addSingletonByName(value, name);
086: }
087:
088: @PostConstruct
089: public void init() throws Exception {
090: if (_jndiName != null)
091: Jndi.rebindDeepShort(_jndiName, _value);
092:
093: if (_var != null) {
094: WebBeansContainer webBeans = WebBeansContainer.create();
095:
096: if (_value != null)
097: webBeans.addSingletonByName(_value, _var);
098: else if (_default != null
099: && webBeans.findByName(_var) == null)
100: webBeans.addSingletonByName(_default, _var);
101: }
102: }
103: }
|