001: /*
002: * Copyright 2001 Sun Microsystems, Inc. All rights reserved.
003: * PROPRIETARY/CONFIDENTIAL. Use of this product is subject to license terms.
004: */
005:
006: package com.sun.portal.search.admin.model;
007:
008: import javax.servlet.http.HttpServletRequest; /*
009: import com.iplanet.sm.ServiceSchema;
010: import com.iplanet.sm.ServiceSchemaManager;
011: import com.iplanet.sm.AttributeSchema;
012: import com.iplanet.sm.SMSException;
013: */
014: import com.sun.identity.sm.ServiceSchema;
015: import com.sun.identity.sm.ServiceSchemaManager;
016: import com.sun.identity.sm.AttributeSchema;
017: import com.sun.identity.sm.SMSException;
018: import com.iplanet.sso.SSOException;
019: import com.iplanet.am.util.Locale;
020: import com.iplanet.am.console.base.model.AMModelBase;
021:
022: import java.util.ResourceBundle;
023: import java.util.Collection;
024: import java.util.Collections;
025: import java.util.List;
026: import java.util.ArrayList;
027: import java.util.Iterator;
028: import java.util.Set;
029: import java.util.Arrays;
030: import java.util.SortedSet;
031: import java.util.TreeSet;
032:
033: /*
034: * The model implementation for managing the properties of a service.
035: */
036: public class CSServiceModelImpl extends AMModelBase implements
037: CSServiceModel {
038: private boolean processed = false;
039:
040: /* The service name.*/
041: private String svcName = "";
042: /* The localized service name.*/
043: private String lSvcName = "";
044:
045: private int globalSize = 0;
046: private int orgSize = 0;
047: private int dynSize = 0;
048:
049: private ResourceBundle resBundle = null;
050:
051: private ServiceSchema globalSvcSchema = null;
052: private ServiceSchema orgSvcSchema = null;
053: private ServiceSchema dynSvcSchema = null;
054:
055: private List globalAttrs = Collections.EMPTY_LIST;
056: private List orgAttrs = Collections.EMPTY_LIST;
057: private List dynAttrs = Collections.EMPTY_LIST;
058:
059: /*
060: * @param req The HttpServletRequest object.
061: * @param rbName The name of the resource bundle.
062: */
063: public CSServiceModelImpl(HttpServletRequest req, String rbName) {
064: super (req, rbName);
065: //Get the service name stored in the token by SMNavModelImpl
066: svcName = "SunPortalSearchService";
067: }
068:
069: /*
070: * This method does the actual work of retrieving the attribute schemas and
071: * preparing a list of attributes.
072: */
073: public void process() {
074: if (svcName == null || svcName.length() == 0) {
075: //TOFIX: Preferably throw an exception.
076: debugError("CSServiceModelImpl: Invalid service name.");
077: return;
078: }
079:
080: //If this method has already executed then no op.
081: if (processed) {
082: return;
083: }
084:
085: ServiceSchemaManager schemaMgr = null;
086: String rbFileName = null;
087:
088: //Get the schema manager.
089: try {
090: schemaMgr = new ServiceSchemaManager(svcName, ssoToken);
091: } catch (SMSException sms) {
092: //TOFIX: Handle this properly
093: debugError(sms.getMessage());
094: return;
095: } catch (SSOException ssoe) {
096: //TOFIX: Handle this properly
097: debugError(ssoe.getMessage());
098: return;
099: }
100:
101: //Get the global schema
102: try {
103: globalSvcSchema = schemaMgr.getGlobalSchema();
104: } catch (SMSException sms) {
105: debugMessage(sms.getMessage());
106: }
107:
108: //Get the org schema
109: try {
110: orgSvcSchema = schemaMgr.getOrganizationSchema();
111: } catch (SMSException sms) {
112: debugMessage(sms.getMessage());
113: }
114:
115: //Get the dynamic schema.
116: try {
117: dynSvcSchema = schemaMgr.getDynamicSchema();
118: } catch (SMSException sms) {
119: debugMessage(sms.getMessage());
120: }
121:
122: /* Remember that this method has already executed and no need to
123: * repeat the same thing again.*/
124: processed = true;
125: }
126:
127: public Set getInstances() {
128: Set instances = null;
129: if (globalSvcSchema != null) {
130: AttributeSchema as = globalSvcSchema
131: .getAttributeSchema("sunPortalSearchInstances");
132: if (as != null) {
133: instances = as.getDefaultValues();
134: }
135: }
136:
137: return instances;
138:
139: }
140:
141: public String getHelpAnchorTag(String key) {
142: return super.getHelpAnchorTag(key);
143: }
144: }
|