001: /*
002: * Copyright 1999-2004 The Apache Software Foundation
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016:
017: package org.apache.naming.ant;
018:
019: import java.util.Hashtable;
020: import java.util.Vector;
021:
022: import javax.naming.Context;
023:
024: import org.apache.tools.ant.Task;
025:
026: /**
027: * Task to set up JNDI properties ( the hashtable that is passed to InitialContext )
028: * It has explicit attributes for common properties, and supports generic name/value
029: * elements.
030: *
031: * @author Costin Manolache
032: */
033: public class JndiEnv extends Task {
034:
035: Hashtable env = new Hashtable();
036: String url;
037: boolean topLevel = true;
038:
039: public JndiEnv() {
040: }
041:
042: public JndiEnv(boolean child) {
043: topLevel = false;
044: }
045:
046: public String getProviderUrl() {
047: return (String) env.get(Context.PROVIDER_URL);
048: }
049:
050: public void setProviderUrl(String providerUrl) {
051: env.put(Context.PROVIDER_URL, providerUrl);
052: }
053:
054: public String getUrl() {
055: return url;
056: }
057:
058: public void setUrl(String url) {
059: this .url = url;
060: }
061:
062: public String getInitialFactory() {
063: return (String) env.get(Context.INITIAL_CONTEXT_FACTORY);
064: }
065:
066: public void setInitialFactory(String initialFactory) {
067: env.put(Context.INITIAL_CONTEXT_FACTORY, initialFactory);
068: }
069:
070: public String getAuthoritative() {
071: return (String) env.get(Context.AUTHORITATIVE);
072: }
073:
074: public void setAuthoritative(String authoritative) {
075: env.put(Context.AUTHORITATIVE, authoritative);
076: }
077:
078: public String getObjectFactories() {
079: return (String) env.get(Context.OBJECT_FACTORIES);
080: }
081:
082: public void setObjectFactories(String objectFactories) {
083: env.put(Context.OBJECT_FACTORIES, objectFactories);
084: }
085:
086: public String getUrlPkgPrefixes() {
087: return (String) env.get(Context.URL_PKG_PREFIXES);
088: }
089:
090: public void setUrlPkgPrefixes(String urlPkgPrefixes) {
091: env.put(Context.URL_PKG_PREFIXES, urlPkgPrefixes);
092: }
093:
094: public void execute() {
095: if (nvEntries != null) {
096: for (int i = 0; i < nvEntries.size(); i++) {
097: NameValue nv = (NameValue) nvEntries.elementAt(i);
098: env.put(nv.name, nv.value);
099: }
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 nvEntries;
107:
108: public NameValue addEnv() {
109: if (nvEntries == null)
110: nvEntries = new Vector();
111: NameValue nv = new NameValue();
112: nvEntries.addElement(nv);
113: return nv;
114: }
115:
116: public static class NameValue {
117: String name;
118: String value;
119:
120: public void setName(String name) {
121: this .name = name;
122: }
123:
124: public void setValue(String value) {
125: this.value = value;
126: }
127: }
128: }
|