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