001/**
002 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003 *
004 * Copyright (c) 2005 Sun Microsystems Inc. All Rights Reserved
005 *
006 * The contents of this file are subject to the terms
007 * of the Common Development and Distribution License
008 * (the License). You may not use this file except in
009 * compliance with the License.
010 *
011 * You can obtain a copy of the License at
012 * https://opensso.dev.java.net/public/CDDLv1.0.html or
013 * opensso/legal/CDDLv1.0.txt
014 * See the License for the specific language governing
015 * permission and limitations under the License.
016 *
017 * When distributing Covered Code, include this CDDL
018 * Header Notice in each file and include the License file
019 * at opensso/legal/CDDLv1.0.txt.
020 * If applicable, add the following below the CDDL Header,
021 * with the fields enclosed by brackets [] replaced by
022 * your own identifying information:
023 * "Portions Copyrighted [year] [name of copyright owner]"
024 *
025 * $Id: AMAttributeSchema.java,v 1.3 2008/06/25 05:41:19 qcheng Exp $
026 *
027 */
028
029package com.iplanet.am.sdk;
030
031import java.util.Set;
032
033import com.iplanet.sso.SSOException;
034import com.sun.identity.sm.AttributeSchema;
035import com.sun.identity.sm.SMSException;
036
037/**
038 * The class <code>AMAttributeSchema</code> provides the interfaces to obtain
039 * meta information about service configuration variable.
040 * 
041 * @deprecated This class has been deprecated. Please use
042 *             <code>com.sun.identity.sm.AttributeSchema</code>.
043 * @supported.all.api
044 */
045public class AMAttributeSchema extends Object {
046
047    /**
048     * The <code>TYPE_SINGLE</code> attribute type specifies that the
049     * attribute can have only a single value
050     */
051    public static final int TYPE_SINGLE = 1;
052
053    /**
054     * The <code>TYPE_LIST</code> attribute type specifies that the attribute
055     * can have multiple values, i.e., multi-valued attribute
056     */
057    public static final int TYPE_LIST = 2;
058
059    /**
060     * The <code>TYPE_SINGLE_CHOICE</code> attribute type specifies that the
061     * attribute can have value defined by the <code>getChoiceValues</code>
062     * method of <code>AMAttributeSchema</code>.
063     */
064    public static final int TYPE_SINGLE_CHOICE = 3;
065
066    /**
067     * The <code>TYPE_MULTIPLE_CHOICE</code> attribute type specifies that the
068     * attribute can have multiple values defined by the
069     * <code>getChoiceValues</code> method of <code>AMAttributeSchema</code>.
070     */
071    public static final int TYPE_MULTIPLE_CHOICE = 4;
072
073    /**
074     * The <code>TYPE_SIGNATURE</code> attribute type specifies that the
075     * attribute is a signing attribute.
076     */
077    public static final int TYPE_SIGNATURE = 20;
078
079    /**
080     * The <code>VALIDATOR</code> attribute type specifies that the attribute
081     * defines a attribute validator plugin.
082     */
083    public static final int TYPE_VALIDATOR = 21;
084
085    /**
086     * The <code>UITYPE_RADIO</code> attribute type specifies that the
087     * attribute should be display as a radio button.
088     */
089    public static final int UITYPE_RADIO = 22;
090
091    /**
092     * The <code>UITYPE_LINK</code> attribute type specifies that the
093     * attribute should be display as a link.
094     */
095    public static final int UITYPE_LINK = 23;
096
097    /**
098     * The <code>UITYPE_BUTTON</code> attribute type specifies that the
099     * attribute should be display as a button.
100     */
101    public static final int UITYPE_BUTTON = 24;
102
103    /**
104     * The <code>UITYPE_UNDEFINED</code> attribute type specifies that the UI
105     * type is not defined.
106     */
107    public static final int UITYPE_UNDEFINED = 25;
108
109    /**
110     * The <code>SYNTAX_BOOLEAN</code> attribute syntax specifies that the
111     * attribute is of boolean type, i.e., can have a value of either
112     * <code>true</code> or <code>
113     * false</code>
114     */
115    public static final int SYNTAX_BOOLEAN = 5;
116
117    /**
118     * The <code>SYNTAX_EMAIL</code> attribute syntax specifies that the
119     * attribute is a email address.
120     */
121    public static final int SYNTAX_EMAIL = 6;
122
123    /**
124     * The <code>SYNTAX_URL</code> attribute syntax specifies that the
125     * attribute is a URL.
126     */
127    public static final int SYNTAX_URL = 7;
128
129    /**
130     * The <code>SYNTAX_STRING</code> attribute syntax specifies that the
131     * attribute is of text type, i.e., can have any unicode characters
132     */
133    public static final int SYNTAX_STRING = 8;
134
135    /**
136     * The <code>SYNTAX_PASSWORD</code> attribute syntax specifies that the
137     * attribute is of password type, will be used by UI to mask the password
138     * typed.
139     */
140    public static final int SYNTAX_PASSWORD = 9;
141
142    /**
143     * The <code>SYNTAX_NUMERIC</code> attribute syntax specifies that the
144     * attribute is numeric, i.e., can have numbers only.
145     */
146    public static final int SYNTAX_NUMERIC = 10;
147
148    /**
149     * The <code>SYNTAX_NUMBER</code> attribute syntax specifies that the
150     * attribute is a number.
151     */
152    public static final int SYNTAX_NUMBER = 11;
153
154    /**
155     * The <code>SYNTAX_PERCENT</code> attribute syntax specifies that the
156     * attribute is a percentage.
157     */
158    public static final int SYNTAX_PERCENT = 12;
159
160    /**
161     * The <code>SYNTAX_NUMBER_RANGE</code> attribute syntax specifies that
162     * the attribute is a number within a range.
163     */
164    public static final int SYNTAX_NUMBER_RANGE = 13;
165
166    /**
167     * The <code>SYNTAX_DECIMAL_RANGE</code> attribute syntax specifies that
168     * the attribute is a decimal number within a range.
169     */
170    public static final int SYNTAX_DECIMAL_RANGE = 14;
171
172    /**
173     * The <code>SYNTAX_DECIMAL_NUMBER</code> attribute syntax specifies that
174     * the attribute is a floating point number, e.g., 1.5, 3.56, etc.
175     */
176    public static final int SYNTAX_DECIMAL_NUMBER = 15;
177
178    /**
179     * The <code>SYNTAX_DN</code> attribute syntax specifies that the
180     * attribute should be an LDAP distinguished name (DN).
181     */
182    public static final int SYNTAX_DN = 16;
183
184    /**
185     * The <code>SYNTAX_PARAGRAPH</code> attribute syntax specifies that the
186     * attribute should be a paragraph
187     */
188    public static final int SYNTAX_PARAGRAPH = 17;
189
190    /**
191     * The <code>SYNTAX_DATE</code> attribute syntax specifies that the
192     * attribute should be a date
193     */
194    public static final int SYNTAX_DATE = 18;
195
196    /**
197     * The <code>SYNTAX_XML</code> attribute syntax specifies that the
198     * attribute should be a XML blob
199     */
200    public static final int SYNTAX_XML = 19;
201
202    /**
203     * The <code>SYNTAX_ENCRYPTED_PASSWORD</code> attribute syntax specifies
204     * that the attribute is of password type, will be used by UI to mask the
205     * password typed.
206     */
207    public static final int SYNTAX_ENCRYPTED_PASSWORD = 20;
208
209    private AttributeSchema attrSchema;
210
211    protected AMAttributeSchema(AttributeSchema as) {
212        attrSchema = as;
213    }
214
215    /**
216     * The method returns the name of the attribute
217     * 
218     * @return name of the attribute
219     */
220    public String getName() {
221        return attrSchema.getName();
222    }
223
224    /**
225     * The method returns the type of the attribute i.e., single, list or choice
226     * 
227     * @return the type of the attribute.
228     */
229    public int getType() {
230        String type = attrSchema.getType().toString();
231
232        // Map the SMS attribute type to public attribute type
233        if (type.equals(AttributeSchema.Type.SINGLE.toString()))
234            return TYPE_SINGLE;
235        else if (type.equals(AttributeSchema.Type.LIST.toString()))
236            return TYPE_LIST;
237        else if (type.equals(AttributeSchema.Type.SINGLE_CHOICE.toString()))
238            return TYPE_SINGLE_CHOICE;
239        else if (type.equals(AttributeSchema.Type.MULTIPLE_CHOICE.toString()))
240            return TYPE_MULTIPLE_CHOICE;
241        else if (type.equals(AttributeSchema.Type.SIGNATURE.toString()))
242            return TYPE_SIGNATURE;
243        else if (type.equals(AttributeSchema.Type.VALIDATOR.toString()))
244            return TYPE_VALIDATOR;
245
246        return -1; // Should'nt occur
247    }
248
249    /**
250     * The method returns the UI type of the attribute i.e., link, button, ...
251     * 
252     * @return the UI type of the attribute; <code>UITYPE_UNDEFINED</code> if
253     *         the UI type is not defined for the attribute
254     */
255    public int getUIType() {
256        AttributeSchema.UIType uitype = attrSchema.getUIType();
257
258        // Map the SMS attribute UI type to public attribute type
259        if (uitype == null) {
260            // UI type not defined
261            return UITYPE_UNDEFINED;
262        } else if (uitype.equals(AttributeSchema.UIType.RADIO)) {
263            return UITYPE_RADIO;
264        } else if (uitype.equals(AttributeSchema.UIType.LINK)) {
265            return UITYPE_LINK;
266        } else if (uitype.equals(AttributeSchema.UIType.BUTTON)) {
267            return UITYPE_BUTTON;
268        }
269
270        return UITYPE_UNDEFINED;
271    }
272
273    /**
274     * The method returns the syntax of the attribute i.e., string, boolean,
275     * distinguished name (String), numeric.
276     * 
277     * @return syntax of the attribute
278     */
279    public int getSyntax() {
280        String syntax = attrSchema.getSyntax().toString();
281
282        // Map the SMS attribute type to public attribute type
283        if (syntax.equals(AttributeSchema.Syntax.BOOLEAN.toString()))
284            return SYNTAX_BOOLEAN;
285        else if (syntax.equals(AttributeSchema.Syntax.EMAIL.toString()))
286            return SYNTAX_EMAIL;
287        else if (syntax.equals(AttributeSchema.Syntax.URL.toString()))
288            return SYNTAX_URL;
289        else if (syntax.equals(AttributeSchema.Syntax.STRING.toString()))
290            return SYNTAX_STRING;
291        else if (syntax.equals(AttributeSchema.Syntax.ENCRYPTED_PASSWORD
292                .toString()))
293            return SYNTAX_ENCRYPTED_PASSWORD;
294        else if (syntax.equals(AttributeSchema.Syntax.PASSWORD.toString()))
295            return SYNTAX_PASSWORD;
296        else if (syntax.equals(AttributeSchema.Syntax.NUMERIC.toString()))
297            return SYNTAX_NUMERIC;
298        else if (syntax.equals(AttributeSchema.Syntax.NUMBER.toString()))
299            return SYNTAX_NUMBER;
300        else if (syntax.equals(AttributeSchema.Syntax.PERCENT.toString()))
301            return SYNTAX_PERCENT;
302        else if (syntax.equals(AttributeSchema.Syntax.NUMBER_RANGE.toString()))
303            return SYNTAX_NUMBER_RANGE;
304        else if (syntax.equals(AttributeSchema.Syntax.DECIMAL_RANGE.toString()))
305            return SYNTAX_DECIMAL_RANGE;
306        else if (syntax
307                .equals(AttributeSchema.Syntax.DECIMAL_NUMBER.toString()))
308            return SYNTAX_DECIMAL_NUMBER;
309        else if (syntax.equals(AttributeSchema.Syntax.DN.toString()))
310            return SYNTAX_DN;
311        else if (syntax.equals(AttributeSchema.Syntax.PARAGRAPH.toString()))
312            return SYNTAX_PARAGRAPH;
313        else if (syntax.equals(AttributeSchema.Syntax.XML.toString()))
314            return SYNTAX_XML;
315        else if (syntax.equals(AttributeSchema.Syntax.DATE.toString()))
316            return SYNTAX_DATE;
317
318        return -1;
319    }
320
321    /**
322     * Returns the value of the <code>cosQualifier</code> for this attribute
323     * that is default or merge-schemes.
324     * 
325     * @return String value of <code>cosQualifier</code>.
326     */
327    public String getCosQualifier() {
328        return attrSchema.getCosQualifier();
329    }
330
331    /**
332     * The method returns the default value of the attribute;
333     * 
334     * @return Set containing the default values of the attribute or
335     *         <code>Collections.EMPTY_SET<code> otherwise
336     */
337    public Set getDefaultValues() {
338        return attrSchema.getDefaultValues();
339    }
340
341    /**
342     * If the attribute is of choice type, this method returns the possible
343     * values for the attribute; <code>null</code> otherwise
344     * 
345     * @return String array of possible choice values; null otherwise
346     */
347    public String[] getChoiceValues() {
348        return attrSchema.getChoiceValues();
349    }
350
351    /**
352     * Given a choice value, this method returns the i18nKey for that choice
353     * value
354     * 
355     * @param cValue
356     *            the choice value
357     * @return the i18N key corresponding to the choice value
358     */
359    public String getChoiceValueI18NKey(String cValue) {
360        return attrSchema.getChoiceValueI18NKey(cValue);
361    }
362
363    /**
364     * Returns I18N key to describe the configuration attribute.
365     * 
366     * @return i18n index key to the resource bundle
367     */
368    public String getI18NKey() {
369        return attrSchema.getI18NKey();
370    }
371
372    /**
373     * Set I18N key to describe the configuration attribute
374     * 
375     * @param i18nKey
376     *            value of <code>i18nKey</code>.
377     * @throws AMException
378     */
379    public void setI18NKey(String i18nKey) throws AMException {
380        try {
381            attrSchema.setI18NKey(i18nKey);
382        } catch (SMSException se) {
383            AMCommonUtils.debug.message(
384                    "AMAttributeSchema.setAttributeDefaults(Map): ", se);
385            throw new AMException(AMSDKBundle.getString("916"), "916");
386        } catch (SSOException so) {
387            AMCommonUtils.debug.message(
388                    "AMAttributeSchema.setAttributeDefaults(Map): ", so);
389            throw new AMException(AMSDKBundle.getString("916"), "916");
390        }
391    }
392
393    /**
394     * Method to get starting range for possible values of the attribute
395     * 
396     * @return starting range for the attribute value
397     */
398    public String getStartRange() {
399        return attrSchema.getStartRange();
400    }
401
402    /**
403     * Method to get ending range for possible values of the attribute
404     * 
405     * @return ending range for the attribute value
406     */
407    public String getEndRange() {
408        return attrSchema.getEndRange();
409    }
410
411    /**
412     * Method to get service specific attributes. It return the value of the
413     * "any" attribute, if set in the XML schema for the service
414     * 
415     * @return value of "any" attribute
416     */
417    public String getAny() {
418        return attrSchema.getAny();
419    }
420
421    /**
422     * Returns URL of the view bean for the attribute.
423     * 
424     * @return URL for view bean
425     */
426    public String getPropertiesViewBeanURL() {
427        return attrSchema.getPropertiesViewBeanURL();
428    }
429
430    /**
431     * Method to get the string value for "TRUE"
432     * 
433     * @return String for TRUE value
434     */
435    public String getTrueValue() {
436        return attrSchema.getTrueValue();
437    }
438
439    /**
440     * Method to get the i18n Key for <code>BooleanTrueValue</code>.
441     * 
442     * @return String i18nKey for TRUE value
443     */
444    public String getTrueValueI18NKey() {
445        return attrSchema.getTrueValueI18NKey();
446    }
447
448    /**
449     * Method to get string value for "FALSE"
450     * 
451     * @return String for FALSE value
452     */
453    public String getFalseValue() {
454        return attrSchema.getFalseValue();
455    }
456
457    /**
458     * Method to get the i18n Key for <code>BooleanFalseValue</code>.
459     * 
460     * @return String i18nKey for FALSE value.
461     */
462    public String getFalseValueI18NKey() {
463        return attrSchema.getFalseValueI18NKey();
464    }
465
466    /**
467     * Method that returns the String representation of the
468     * <code>AMAttributeSchema</code>.
469     * 
470     * @return String representation of the <code>AMAttributeSchema</code>/
471     */
472    public String toString() {
473        return attrSchema.toString();
474    }
475}