KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > naming > ant > JndiSet


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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 JavaDoc;
20
21 import org.apache.tools.ant.Task;
22 import org.apache.tools.ant.TaskAdapter;
23
24
25 /**
26  * Set a JNDI attribute or context.
27  *
28  * @author Costin Manolache
29  */

30 public class JndiSet extends Task {
31     private static org.apache.commons.logging.Log log=
32         org.apache.commons.logging.LogFactory.getLog( JndiSet.class );
33     String JavaDoc refId;
34     String JavaDoc value;
35     
36     String JavaDoc contextName;
37     String JavaDoc attributeName;
38     
39     public JndiSet() {
40     }
41
42     /** Will bind the referenced object
43      */

44     public void setRefId( String JavaDoc refId ) {
45         this.refId=refId;
46     }
47
48     /** bind/set this value
49      */

50     public void setValue( String JavaDoc val ) {
51         this.value=val;
52     }
53     
54     /** The context name that will be set.
55      */

56     public void setContext( String JavaDoc ctx ) {
57         this.contextName=ctx;
58     }
59
60     public void setAttribute( String JavaDoc att ) {
61         this.attributeName=att;
62     }
63     
64     
65     public void execute() {
66         try {
67             InitialContext JavaDoc ic=new InitialContext JavaDoc();
68             Object JavaDoc o=null;
69             
70             if( refId != null ) {
71                 o=project.getReference( refId );
72                 if( o instanceof TaskAdapter )
73                     o=((TaskAdapter)o).getProxy();
74             }
75             if( o==null )
76                 o=value;
77             // Add other cases.
78
log.info( "Binding " + contextName + " " + o );
79             ic.bind( contextName, o );
80
81         } catch( Exception JavaDoc ex ) {
82             ex.printStackTrace();
83         }
84     }
85     
86 }
87
Popular Tags