01: /*
02: * Copyright 1999-2004 The Apache Software Foundation
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16:
17: package org.apache.naming.ant;
18:
19: import javax.naming.InitialContext;
20:
21: import org.apache.tools.ant.Task;
22: import org.apache.tools.ant.TaskAdapter;
23:
24: /**
25: * Set a JNDI attribute or context.
26: *
27: * @author Costin Manolache
28: */
29: public class JndiSet extends Task {
30: private static org.apache.commons.logging.Log log = org.apache.commons.logging.LogFactory
31: .getLog(JndiSet.class);
32: String refId;
33: String value;
34:
35: String contextName;
36: String attributeName;
37:
38: public JndiSet() {
39: }
40:
41: /** Will bind the referenced object
42: */
43: public void setRefId(String refId) {
44: this .refId = refId;
45: }
46:
47: /** bind/set this value
48: */
49: public void setValue(String val) {
50: this .value = val;
51: }
52:
53: /** The context name that will be set.
54: */
55: public void setContext(String ctx) {
56: this .contextName = ctx;
57: }
58:
59: public void setAttribute(String att) {
60: this .attributeName = att;
61: }
62:
63: public void execute() {
64: try {
65: InitialContext ic = new InitialContext();
66: Object o = null;
67:
68: if (refId != null) {
69: o = project.getReference(refId);
70: if (o instanceof TaskAdapter)
71: o = ((TaskAdapter) o).getProxy();
72: }
73: if (o == null)
74: o = value;
75: // Add other cases.
76: log.info("Binding " + contextName + " " + o);
77: ic.bind(contextName, o);
78:
79: } catch (Exception ex) {
80: ex.printStackTrace();
81: }
82: }
83:
84: }
|