001: /**
002: * $Id: SchemaElements.java,v 1.2 2003/06/16 15:10:56 byork Exp $
003: * Copyright 2002 Sun Microsystems, Inc. All rights reserved. Use of this
004: * product is subject to license terms. Federal Acquisitions:
005: * Commercial Software -- Government Users Subject to Standard License Terms
006: * and Conditions.
007: *
008: * Sun, Sun Microsystems, the Sun logo, and Sun ONE are trademarks or
009: * registered trademarks of Sun Microsystems, Inc. in the United States
010: * and other countries.
011: */package com.sun.ssoadapter.ab.pim;
012:
013: import java.util.Map;
014: import java.util.HashMap;
015: import java.util.List;
016: import java.util.ArrayList;
017: import java.util.Enumeration;
018: import java.util.StringTokenizer;
019: import java.util.ResourceBundle;
020:
021: import java.util.MissingResourceException;
022:
023: public class SchemaElements implements JPimABConstants {
024: //
025: // Contains schema elements common to Entry & PimAddressEntryElement
026: // Key: Entry PropertyName, Value: PimAddressEntryElement PropertyName
027: //
028: private static Map caseExactCommonMap = new HashMap();
029:
030: //
031: // Stores the common PropertyNames in LowerCase.
032: //
033: private static Map caseInsensitiveCommonMap = new HashMap();
034:
035: //
036: // Utility member to store all the common PropertyNames as array
037: //
038: private static Object[] caseExactCommonArray = null;
039:
040: //
041: // Utility member to store all the AEFilterPropertyNames as array
042: // = (caseExactCommonArray - PIM_AELEMENTS_NOT_SET)
043: //
044: private static String[] aePropertyNames = null;
045:
046: //
047: // Contains elements present only in PimAddressEntryElement or only
048: // in Entry object.
049: //
050: private static Map exclusiveElementsOnlyMap = new HashMap();
051:
052: //
053: // Contains schema elements common to Group & PimAddressEntryElement
054: // Key: Group PropertyName, Value: PimAddressEntryElement PropertyName
055: //
056: private static Map caseExactCommonGroupMap = new HashMap();
057:
058: //
059: // Stores the common PropertyNames in LowerCase.
060: //
061: private static Map caseInsensitiveCommonGroupMap = new HashMap();
062:
063: //
064: // Utility member to store all the common PropertyNames as array
065: //
066: private static Object[] caseExactCommonGroupArray = null;
067:
068: //
069: // Contains elements present only in PimAddressEntryElement or only
070: // in Group object.
071: //
072: private static Map exclusiveElementsOnlyGroupMap = new HashMap();
073:
074: static {
075: ResourceBundle resource = null;
076: List removeForAEItems = new ArrayList();
077:
078: //
079: // Load the Common elements, Entry only elements & Pim only elements
080: //
081: try {
082: resource = ResourceBundle
083: .getBundle(ENTRY_PIM_ELEMENTS_FILE);
084: Enumeration keys = resource.getKeys();
085: while (keys.hasMoreElements()) {
086: String name = (String) keys.nextElement();
087: String value = (String) resource.getString(name);
088:
089: name = name.trim();
090: value = value.trim();
091:
092: if (value.equals(""))
093: continue; // dont add in empty values
094:
095: if (name.equals(ENTRY_ELEMENTS_ONLY_KEY)
096: || name.equals(PIM_ELEMENTS_ONLY_KEY)) {
097: StringTokenizer st = new StringTokenizer(value);
098: String[] arr = new String[st.countTokens()];
099: for (int i = 0; st.hasMoreTokens(); i++) {
100: arr[i] = st.nextToken();
101: }
102: exclusiveElementsOnlyMap.put(name, arr); // put an Array
103: } else if (name.equals(PIM_AELEMENTS_NOT_SET)) {
104: removeForAEItems.add(value);
105: } else {
106: caseExactCommonMap.put(name, value);
107: caseInsensitiveCommonMap.put(name.toLowerCase(),
108: value);
109: }
110: }
111:
112: if (caseExactCommonMap != null) {
113: caseExactCommonArray = caseExactCommonMap.keySet()
114: .toArray();
115:
116: // properties not settable on AEItemFilter
117: int size = caseExactCommonArray.length
118: - removeForAEItems.size();
119: aePropertyNames = new String[size];
120: for (int i = 0, j = 0; i < caseExactCommonArray.length; i++) {
121: String prop = (String) caseExactCommonArray[i];
122: if (!removeForAEItems.contains(prop))
123: aePropertyNames[j++] = prop;
124: }
125: }
126: } catch (MissingResourceException mre) {
127: caseExactCommonMap = null;
128: caseInsensitiveCommonMap = null;
129: exclusiveElementsOnlyMap = null;
130: caseExactCommonArray = null;
131: }
132:
133: //
134: // Load the Common elements, Group only elements & Pim only elements
135: //
136: try {
137: resource = ResourceBundle
138: .getBundle(GROUP_PIM_ELEMENTS_FILE);
139: Enumeration keys = resource.getKeys();
140: while (keys.hasMoreElements()) {
141: String name = (String) keys.nextElement();
142: String value = (String) resource.getString(name);
143:
144: name = name.trim();
145: value = value.trim();
146:
147: if (value.equals(""))
148: continue; // dont add in empty values
149:
150: if (name.equals(GROUP_ELEMENTS_ONLY_KEY)
151: || name.equals(PIM_ELEMENTS_ONLY_KEY)) {
152: StringTokenizer st = new StringTokenizer(value);
153: String[] arr = new String[st.countTokens()];
154: for (int i = 0; st.hasMoreTokens(); i++) {
155: arr[i] = st.nextToken();
156: }
157: exclusiveElementsOnlyGroupMap.put(name, arr); // put an Array
158: } else {
159: caseExactCommonGroupMap.put(name, value);
160: caseInsensitiveCommonGroupMap.put(name
161: .toLowerCase(), value);
162: }
163: }
164:
165: if (caseExactCommonGroupMap != null) {
166: caseExactCommonGroupArray = caseExactCommonGroupMap
167: .keySet().toArray();
168: }
169: } catch (MissingResourceException mre) {
170: caseExactCommonGroupMap = null;
171: caseInsensitiveCommonGroupMap = null;
172: exclusiveElementsOnlyGroupMap = null;
173: caseExactCommonGroupArray = null;
174: }
175: }
176:
177: /**
178: * Gets the pimElement (Alligo - Exchange/Notes) name corresponding
179: * to the Entry ElementName (JABAPI). Since the entryElementName
180: * can be in any case, use the caseInsensitive Map
181: */
182:
183: public String getPimElementName(String entryElementName) {
184: String name = entryElementName.toLowerCase();
185: String pimName = (String) caseInsensitiveCommonMap.get(name);
186:
187: return pimName;
188: }
189:
190: /**
191: * @return String Array of schema elements only in JABAPIs Entry object
192: */
193: public String[] getEntryOnlySchemaElements() {
194: String[] arr = (String[]) exclusiveElementsOnlyMap
195: .get(ENTRY_ELEMENTS_ONLY_KEY);
196: return (arr);
197: }
198:
199: /**
200: * @return String Array of schema elements only in
201: * PimAddressEntryElement object.
202: */
203: public String[] getPimOnlySchemaElements() {
204: String[] arr = (String[]) exclusiveElementsOnlyMap
205: .get(PIM_ELEMENTS_ONLY_KEY);
206: return (arr);
207: }
208:
209: /**
210: * @return the Array of property names that can be set on the
211: * PimAddressEntryItemFilter.
212: */
213: public Object[] getAEFilterPropertyNames() {
214: return aePropertyNames;
215: }
216:
217: /**
218: * @return the CaseExact property names common to Entry &
219: * PimAddressEntryElement
220: */
221: public Object[] getAllCommonPropertyNames() {
222: return caseExactCommonArray;
223: }
224:
225: /**
226: * Gets the pimElement (Alligo - Exchange/Notes) name corresponding
227: * to the Group Elementname (JABAPI). Since the entryElementName
228: * can be in any case, use the caseInsensitive Map
229: */
230:
231: public String getPimElementNameForGroup(String groupElementName) {
232: String name = groupElementName.toLowerCase();
233: String pimName = (String) caseInsensitiveCommonGroupMap
234: .get(name);
235:
236: return pimName;
237: }
238:
239: /**
240: * @return String Array of schema elements only in JABAPIs Group object
241: */
242: public String[] getGroupOnlySchemaElements() {
243: String[] arr = (String[]) exclusiveElementsOnlyGroupMap
244: .get(GROUP_ELEMENTS_ONLY_KEY);
245: return (arr);
246: }
247:
248: /**
249: * @return String Array of schema elements only in
250: * PimAddressEntryElement object.
251: */
252: public String[] getPimOnlySchemaElementsForGroup() {
253: String[] arr = (String[]) exclusiveElementsOnlyGroupMap
254: .get(PIM_ELEMENTS_ONLY_KEY);
255: return (arr);
256: }
257:
258: /**
259: * @return the CaseExact property names common to Group &
260: * PimAddressEntryElement
261: */
262: public Object[] getAllCommonPropertyNamesForGroup() {
263: return caseExactCommonGroupArray;
264: }
265: }
|