001: /*
002: * BEGIN_HEADER - DO NOT EDIT
003: *
004: * The contents of this file are subject to the terms
005: * of the Common Development and Distribution License
006: * (the "License"). You may not use this file except
007: * in compliance with the License.
008: *
009: * You can obtain a copy of the license at
010: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
011: * See the License for the specific language governing
012: * permissions and limitations under the License.
013: *
014: * When distributing Covered Code, include this CDDL
015: * HEADER in each file and include the License file at
016: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
017: * If applicable add the following below this CDDL HEADER,
018: * with the fields enclosed by brackets "[]" replaced with
019: * your own identifying information: Portions Copyright
020: * [year] [name of copyright owner]
021: */
022:
023: /*
024: * @(#)ContextImpl.java
025: * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
026: *
027: * END_HEADER - DO NOT EDIT
028: */
029: package com.sun.jbi.internal.security;
030:
031: import com.sun.jbi.StringTranslator;
032: import com.sun.jbi.binding.security.Context;
033: import java.util.HashMap;
034:
035: /**
036: * Implementation of the Context.
037: *
038: * @author Sun Microsystems, Inc.
039: */
040: public class ContextImpl implements Context {
041: /**
042: * The Context.
043: */
044: private HashMap mContext;
045:
046: /**
047: * The String Translator.
048: */
049: private StringTranslator mTranslator;
050:
051: /**
052: * Creates a new instance of ContextImpl.
053: *
054: * @param translator is the StringTranslator.
055: */
056: public ContextImpl(StringTranslator translator) {
057: mTranslator = translator;
058: mContext = new HashMap();
059: }
060:
061: /* ------------------------------------------------------------------------------- *\
062: * Context Impl. *
063: \* ------------------------------------------------------------------------------- */
064:
065: /**
066: * @param key is the key to look for in the context.
067: * @return true if the Context contains a particular Key
068: */
069: public boolean containsKey(String key) {
070: return mContext.containsKey(key);
071: };
072:
073: /**
074: * @param key whose associated value is to be returned.
075: * @return the Object value associated with a particular Key
076: */
077: public Object getValue(String key) {
078: return mContext.get(key);
079: }
080:
081: /**
082: * @param key is the Key whose value is to be set.
083: * @param value is the value for the Key.
084: */
085: public void setValue(String key, Object value) {
086: mContext.put(key, value);
087: };
088:
089: /**
090: * Enumerate all the Keys in the Context.
091: *
092: * @return the List of Keys (Strings) in the Context.
093: */
094: public java.util.Set enumerateKeys() {
095: return mContext.keySet();
096: };
097:
098: /**
099: * Remove a entry.
100: *
101: * @param key is the Key identifying the entry to be deleted.
102: */
103: public void removeValue(String key)
104:
105: {
106: mContext.remove(key);
107: }
108:
109: /**
110: * Print the Contents of the Context to the Logger.
111: *
112: * @param logger is the java.util.Logger to use for printing out the contents.
113: * @param level is the logging level
114: */
115: public void print(java.util.logging.Logger logger,
116: java.util.logging.Level level) {
117: StringBuffer buffer = new StringBuffer();
118:
119: buffer.append(mTranslator
120: .getString(LocalStringConstants.CONST_CONTEXT)
121: + "\n");
122:
123: java.util.Iterator itr = enumerateKeys().iterator();
124:
125: while (itr.hasNext()) {
126: String param = (String) itr.next();
127:
128: buffer
129: .append("\t"
130: + mTranslator
131: .getString(LocalStringConstants.CONST_PARAM)
132: + " " + param + "\n");
133: buffer
134: .append("\t"
135: + mTranslator
136: .getString(LocalStringConstants.CONST_VALUE)
137: + " " + getValue(param) + "\n");
138: }
139:
140: logger.log(level, buffer.toString());
141: }
142: }
|