001: /**
002: * $Id: DPConnection.java,v 1.6 2005/04/08 10:11:00 rt130506 Exp $
003: * Copyright 2003 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.wsrp.producer;
014:
015: import java.util.Map;
016: import java.util.HashMap;
017: import java.util.Set;
018: import java.util.HashSet;
019: import java.util.Collections;
020: import java.util.Iterator;
021:
022: import javax.servlet.http.HttpServletRequest;
023:
024: import com.sun.portal.desktop.context.DPContext;
025: import com.sun.portal.desktop.context.DSAMEDPContext;
026:
027: import com.sun.portal.desktop.dp.DPRoot;
028: import com.sun.portal.desktop.dp.xml.XMLDPFactory;
029:
030: public class DPConnection {
031: //
032: // this class does not cache the dp objects. this means
033: // each request for a SD rebuilds the DP entirely.
034: //
035: // this may not be so bad considering the request for the
036: // producer's SD will be infrequent.
037: //
038: // if needed, this class can cache the dp roots map
039: // and watch for DP updates via the modified
040: // timestamp. for now, we leave this as is.
041: //
042:
043: private Map dpRoots = Collections.synchronizedMap(new HashMap());
044: private DSAMEDPContext dpContext = new DSAMEDPContext();
045: private boolean dpContextInitialized = false;
046:
047: private HttpServletRequest req = null;
048:
049: public DPConnection(HttpServletRequest req) {
050: this .req = req;
051:
052: synchronized (this .getClass()) {
053: if (!dpContextInitialized) {
054: dpContext.init(req);
055: }
056: }
057: }
058:
059: public DPConnection(String portalId) {
060: this .req = req;
061:
062: synchronized (this .getClass()) {
063: if (!dpContextInitialized) {
064: dpContext.init(portalId);
065: }
066: }
067: }
068:
069: private void resetModified() {
070: synchronized (dpRoots) {
071: boolean clear = false;
072:
073: for (Iterator i = dpRoots.keySet().iterator(); i.hasNext();) {
074: String name = (String) i.next();
075: long lastRead = dpContext.getDPDocumentLastRead(name);
076: long lastModified = dpContext
077: .getDPDocumentLastModified(name);
078:
079: //ISConnection.debug.error("DPConnection.resetModified(): name=" + name);
080: //ISConnection.debug.error("DPConnection.resetModified(): lastRead=" + lastRead);
081: //ISConnection.debug.error("DPConnection.resetModified(): lastModified=" + lastModified);
082:
083: if (lastModified != -1 && lastRead != -1
084: && lastModified > lastRead) {
085: //ISConnection.debug.error("DPConnection.resetModified(): was modified, clearing cachey");
086: clear = true;
087: break;
088: }
089: }
090:
091: if (clear) {
092: dpRoots.clear();
093: }
094: }
095: }
096:
097: public DPRoot getDPRoot(String org) {
098: resetModified();
099: DPRoot dpRoot = XMLDPFactory.getInstance().createRoot(
100: dpContext, org, dpRoots);
101: return dpRoot;
102: }
103: }
|