001: /**
002: * $Id: DSAMEMultiPortalConstants.java,v 1.6 2005/10/20 17:01:50 jtb Exp $
003: * Copyright 2004 Sun Microsystems, Inc. All
004: * rights reserved. Use of this product is subject
005: * to license terms. Federal Acquisitions:
006: * Commercial Software -- Government Users
007: * Subject to Standard License Terms and
008: * Conditions.
009: *
010: * Sun, Sun Microsystems, the Sun logo, and Sun ONE
011: * are trademarks or registered trademarks of Sun Microsystems,
012: * Inc. in the United States and other countries.
013: */package com.sun.portal.desktop.context;
014:
015: import java.util.Map;
016: import java.util.HashMap;
017: import com.sun.portal.admin.common.util.AdminUtil;
018:
019: public class DSAMEMultiPortalConstants implements DSAMEConstants {
020:
021: private static Map instances = new HashMap(2);
022:
023: /**
024: * Always holds the id of the first instance created.
025: * This is used only during the getInstance with no args.
026: * The only use this has, is to avoid the cost of getting the
027: * key set from the map and then iterating thru the set to
028: * get the poralId when only one entry exists.
029: */
030: private static String loneId = null;
031:
032: private DSAMEMultiPortalConstants(String id) {
033: //Every portal MUST have a valid portal id.
034: validateId(id);
035: //In case of an upgraded portal, the service and attrs do
036: //not have a portal id in their names
037: if (!id.equals(AdminUtil.UPGRADED_PORTAL)) {
038: id = id.trim();
039: MP_ATTR_PREFIX = "sunPortal" + id + "Desktop";
040: MP_SUN_DESKTOP_SERVICE = "SunPortal" + id
041: + "DesktopService";
042: MP_SUN_DESKTOP_OBJECT_CLASS = "SunPortal" + id
043: + "DesktopPerson";
044: MP_ATTR_DEFAULTCHANNELNAME = MP_ATTR_PREFIX
045: + "DefaultChannelName";
046: MP_ATTR_EDITPROVIDERCONTAINERNAME = MP_ATTR_PREFIX
047: + "EditProviderContainerName";
048: MP_ATTR_COMMUNITY_PARENT_CONTAINER_URL_PARAMETER = MP_ATTR_PREFIX
049: + "CommunityParentContainerURLParameter";
050: MP_ATTR_COMMUNITY_HOME_CONTAINER_NAME = MP_ATTR_PREFIX
051: + "CommunityHomeContainerName";
052: MP_ATTR_COMMUNITY_CREATE_CONTAINER_NAME = MP_ATTR_PREFIX
053: + "CommunityCreateContainerName";
054:
055: MP_ATTR_DESKTOP_TYPE = MP_ATTR_PREFIX + "Type";
056: MP_ATTR_DP_DOCUMENT_USER = MP_ATTR_PREFIX
057: + "DpDocumentUser";
058: MP_ATTR_DP_LAST_MODIFIED_USER = MP_ATTR_PREFIX
059: + "DpLastModifiedUser";
060: }
061: }
062:
063: /**
064: * portalId may contain only letters, digits and hyphen.
065: *
066: * @throws ContextError if the identifier is invalid
067: */
068: private void validateId(String id) {
069: if (id == null || id.length() == 0) {
070: throw new ContextError("Invalid portal identifier");
071: } else if (id.matches(".*[^a-zA-Z0-9-].*")) {
072: throw new ContextError("Invalid portal identifier");
073: }
074: }
075:
076: /**
077: * The prefix MP indicates MULTI_PORTAL
078: * Conventionally, the identifiers should be lower case as they are not
079: * being set in the static initilizers. But practically these are
080: * constants for a portal server instance, hence the capitalization.
081: */
082:
083: // Attribute Prefix
084: public String MP_ATTR_PREFIX = ATTR_PREFIX;
085:
086: //
087: // Service Names
088: //
089: public String MP_SUN_DESKTOP_SERVICE = "SunPortalDesktopService";
090:
091: public String MP_SUN_DESKTOP_OBJECT_CLASS = "SunPortalDesktopPerson";
092:
093: //
094: // Dynamic Attributes
095: //
096: public String MP_ATTR_DEFAULTCHANNELNAME = ATTR_PREFIX
097: + "DefaultChannelName";
098:
099: public String MP_ATTR_EDITPROVIDERCONTAINERNAME = ATTR_PREFIX
100: + "EditProviderContainerName";
101:
102: public String MP_ATTR_COMMUNITY_PARENT_CONTAINER_URL_PARAMETER = ATTR_PREFIX
103: + "CommunityParentContainerURLParameter";
104:
105: public String MP_ATTR_COMMUNITY_HOME_CONTAINER_NAME = ATTR_PREFIX
106: + "CommunityHomeContainerName";
107:
108: public String MP_ATTR_COMMUNITY_CREATE_CONTAINER_NAME = ATTR_PREFIX
109: + "CommunityCreateContainerName";
110:
111: public String MP_ATTR_DESKTOP_TYPE = ATTR_PREFIX + "Type";
112:
113: //
114: // User Attributes
115: //
116: public String MP_ATTR_DP_DOCUMENT_USER = ATTR_PREFIX
117: + "DpDocumentUser";
118:
119: public String MP_ATTR_DP_LAST_MODIFIED_USER = ATTR_PREFIX
120: + "DpLastModifiedUser";
121:
122: //
123: // instance management
124: //
125:
126: public static synchronized void createInstance(String id) {
127: if (!instances.containsKey(id)) {
128: instances.put(id, new DSAMEMultiPortalConstants(id));
129: if (instances.size() == 1) {
130: loneId = id;
131: }
132: }
133: }
134:
135: /**
136: * For the desktop code, there is always only one instance of this class
137: * since each portal runs in its own JVM. This method returns such
138: * instance which has been created using createInstance. It throws a
139: * ContextError if no instance exists or if more than one instances
140: * exist. So ideally, there will be only one instance in existance
141: * if this class is being properly used in the desktop code.
142: */
143: public static DSAMEMultiPortalConstants getInstance() {
144: int n = instances.size();
145: if (n == 0) {
146: throw new ContextError("Instance does not exist");
147: } else if (n > 1) {
148: throw new ContextError("Invalid use of getInstance: "
149: + " More than one instance exists");
150: }
151: return (DSAMEMultiPortalConstants) instances.get(loneId);
152: }
153:
154: /**
155: * The desktop code executes in VM in which there is only one
156: * portal. Thus there is a single instance of this
157: * class which gets initialized at the servlet init time.
158: * Once initialized, this never changes during the lifetime of that VM.
159: * But in case of admin mbeans, the situation is different. Different
160: * mbeans belonging to different portals run in the same JVM of the cacao
161: * server. Each mbean knows which portal it belongs to and hence can
162: * request an instance of this class initialized for a specific portal.
163: * So this method is used by the mbeans to get a specific instance. The rule
164: * to use this method still remains same, that is, one MUST first create
165: * an instance before trying to get it, otherwise a ContextError is
166: * thrown.
167: */
168: public static DSAMEMultiPortalConstants getInstance(String id) {
169: if (!instances.containsKey(id)) {
170: throw new ContextError("Instance does not exist");
171: }
172: return (DSAMEMultiPortalConstants) instances.get(id);
173: }
174: }
|