KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.util.Hashtable JavaDoc;
20 import java.util.Vector JavaDoc;
21
22 import javax.naming.Context JavaDoc;
23
24 import org.apache.tools.ant.Task;
25
26 /**
27  * Task to set up JNDI properties ( the hashtable that is passed to InitialContext )
28  * It has explicit attributes for common properties, and supports generic name/value
29  * elements.
30  *
31  * @author Costin Manolache
32  */

33 public class JndiEnv extends Task {
34  
35     Hashtable JavaDoc env = new Hashtable JavaDoc();
36     String JavaDoc url;
37     boolean topLevel=true;
38     
39     public JndiEnv() {
40     }
41     
42     public JndiEnv(boolean child) {
43         topLevel=false;
44     }
45     
46     public String JavaDoc getProviderUrl() {
47         return (String JavaDoc) env.get(Context.PROVIDER_URL);
48     }
49     
50     public void setProviderUrl(String JavaDoc providerUrl) {
51         env.put(Context.PROVIDER_URL, providerUrl);
52     }
53
54     public String JavaDoc getUrl() {
55         return url;
56     }
57
58     public void setUrl(String JavaDoc url) {
59         this.url = url;
60     }
61
62     public String JavaDoc getInitialFactory() {
63         return (String JavaDoc) env.get(Context.INITIAL_CONTEXT_FACTORY);
64     }
65
66     public void setInitialFactory(String JavaDoc initialFactory) {
67         env.put(Context.INITIAL_CONTEXT_FACTORY, initialFactory);
68     }
69
70     public String JavaDoc getAuthoritative() {
71         return (String JavaDoc) env.get(Context.AUTHORITATIVE);
72     }
73
74     public void setAuthoritative(String JavaDoc authoritative) {
75         env.put(Context.AUTHORITATIVE, authoritative);
76     }
77
78     public String JavaDoc getObjectFactories() {
79         return (String JavaDoc) env.get(Context.OBJECT_FACTORIES);
80     }
81
82     public void setObjectFactories(String JavaDoc objectFactories) {
83         env.put(Context.OBJECT_FACTORIES, objectFactories);
84     }
85
86     public String JavaDoc getUrlPkgPrefixes() {
87         return (String JavaDoc) env.get(Context.URL_PKG_PREFIXES);
88     }
89
90     public void setUrlPkgPrefixes(String JavaDoc urlPkgPrefixes) {
91         env.put(Context.URL_PKG_PREFIXES, urlPkgPrefixes);
92     }
93
94     public void execute() {
95         if( nvEntries!=null ) {
96             for( int i=0; i<nvEntries.size(); i++ ) {
97                 NameValue nv=(NameValue)nvEntries.elementAt(i);
98                 env.put( nv.name, nv.value);
99             }
100         }
101         // If this is a standalone task - add a ref in the project.
102
if(topLevel)
103             project.addReference( "globalJndiEnv", this );
104     }
105
106     Vector JavaDoc nvEntries;
107     
108     public NameValue addEnv() {
109         if( nvEntries==null ) nvEntries=new Vector JavaDoc();
110         NameValue nv=new NameValue();
111         nvEntries.addElement( nv );
112         return nv;
113     }
114     
115     public static class NameValue {
116         String JavaDoc name;
117         String JavaDoc value;
118         
119         public void setName(String JavaDoc name) {
120             this.name=name;
121         }
122         public void setValue(String JavaDoc value) {
123             this.value=value;
124         }
125     }
126 }
127
Popular Tags