001: /*
002: * DPRootSpecifier.java
003: *
004: * Created on November 15, 2001, 3:45 PM
005: */
006:
007: package com.sun.portal.desktop.deployment;
008:
009: import org.w3c.dom.Document;
010:
011: import java.util.Properties;
012: import java.io.FileInputStream;
013: import java.io.IOException;
014: import java.io.FileNotFoundException;
015:
016: import com.sun.portal.desktop.dp.DPRoot;
017: import com.sun.portal.desktop.dp.DPFactory;
018: import com.sun.portal.desktop.dp.DPProvider;
019: import com.sun.portal.desktop.dp.DPChannel;
020: import com.sun.portal.desktop.dp.DPReference;
021:
022: import com.sun.portal.desktop.dp.xml.XMLDPFactory;
023: import com.sun.portal.desktop.dp.xml.XMLDPRoot;
024:
025: import com.sun.portal.desktop.context.AdminDPContext;
026: import com.sun.portal.desktop.context.DSAMEAdminDPContext;
027: import com.sun.portal.desktop.context.DPContext;
028: import com.sun.portal.util.ResourceLoader;
029: import com.iplanet.sso.SSOToken;
030:
031: /**
032: *
033: * @author yabob
034: * @version
035: */
036: public class DPRootSpecifier {
037:
038: private DPRootSpecifier(String user, String pwd)
039: throws ParFileException {
040: String sysprop = System.getProperty(DTPROPFILE);
041: if (sysprop == null) {
042: Object tok[] = { DTPROPFILE };
043: throw new ParFileException("errorSystemProp", tok);
044: }
045:
046: try {
047: //m_ADPCtxObj = getAdminDPContextObject(sysprop);
048: m_ADPCtxObj = new DSAMEAdminDPContext();
049: ((AdminDPContext) m_ADPCtxObj).init(user, pwd, null,
050: ResourceLoader.getInstance(System.getProperties())
051: .getPortalId());
052:
053: m_Factory = XMLDPFactory.getInstance();
054: } catch (Exception ex) {
055: throw new ParFileException("errorAuthenticate", ex);
056: }
057: }
058:
059: private DPRootSpecifier(SSOToken ssoToken, String portalId)
060: throws ParFileException {
061: String sysprop = System.getProperty(DTPROPFILE);
062: if (sysprop == null) {
063: Object tok[] = { DTPROPFILE };
064: throw new ParFileException("errorSystemProp", tok);
065: }
066:
067: try {
068: //m_ADPCtxObj = getAdminDPContextObject(sysprop);
069: m_ADPCtxObj = new DSAMEAdminDPContext();
070: //need to change the logfile
071: ((AdminDPContext) m_ADPCtxObj).init(ssoToken, null,
072: portalId);
073: m_Factory = XMLDPFactory.getInstance();
074: } catch (Exception ex) {
075: throw new ParFileException("errorAuthenticate", ex);
076: }
077: }
078:
079: // Use static method so we don't have a public constructor throwing exceptions.
080:
081: public static DPRootSpecifier makeSpecifier(String user, String pwd)
082: throws ParFileException {
083: return new DPRootSpecifier(user, pwd);
084: }
085:
086: public static DPRootSpecifier makeSpecifier(SSOToken ssoToken,
087: String portalId) throws ParFileException {
088: return new DPRootSpecifier(ssoToken, portalId);
089: }
090:
091: // setDN must be written so as to not cause unneccesary revalidation when
092: // recalled with the same string.
093:
094: public void setDN(String dn) {
095: if (dn != null && m_DN != null && dn.equals(m_DN)) {
096: return;
097: }
098: m_DN = dn;
099: m_IsGlobal = dn.equalsIgnoreCase(GLOBAL);
100: m_DRoot = null; // invalidate, so we perform lookup at next getRoot().
101: }
102:
103: public DPRoot getRoot() throws ParFileException {
104: if (m_DRoot != null) {
105: return m_DRoot;
106: }
107: if (m_DN == null) {
108: throw new ParFileException("errorNoDirName");
109: }
110:
111: try {
112: String buf = m_IsGlobal ? ((AdminDPContext) m_ADPCtxObj)
113: .getGlobalDPDocument()
114: : ((AdminDPContext) m_ADPCtxObj)
115: .getDPDocument(m_DN);
116: m_DRoot = m_Factory
117: .createRoot((DPContext) m_ADPCtxObj, buf);
118: } catch (Exception ex) {
119: throw new ParFileException("errorDPFetch", ex);
120: }
121:
122: return m_DRoot;
123: }
124:
125: public String getDN() {
126: return m_DN;
127: }
128:
129: public DPProvider createProvider(String name, String classname,
130: int providerVersion) throws ParFileException {
131:
132: // FIXME - we shouldn't be coercing to implementation classes.
133:
134: try {
135: Document doc = ((XMLDPRoot) m_DRoot).getDocument();
136: return m_Factory.createProvider((DPContext) m_ADPCtxObj,
137: m_DRoot, doc, name, classname, providerVersion);
138: } catch (Exception ex) {
139: throw new ParFileException("errorDPCreate", ex);
140: }
141: }
142:
143: public DPChannel createChannel(String name, String provider)
144: throws ParFileException {
145:
146: // FIXME - XMLDPFactory methods aren't public yet, and we
147: // shouldn't be coercing to implementation classes.
148:
149: try {
150: Document doc = ((XMLDPRoot) m_DRoot).getDocument();
151: return m_Factory.createChannel((DPContext) m_ADPCtxObj,
152: m_DRoot, doc, name, provider);
153: } catch (Exception ex) {
154: throw new ParFileException("errorDPCreate", ex);
155: }
156: }
157:
158: public DPReference createReference(String name)
159: throws ParFileException {
160:
161: // FIXME - we shouldn't be coercing to implementation classes.
162:
163: try {
164: Document doc = ((XMLDPRoot) m_DRoot).getDocument();
165: return m_Factory.createReference((DPContext) m_ADPCtxObj,
166: m_DRoot, doc, name);
167: } catch (Exception ex) {
168: throw new ParFileException("errorDPCreate", ex);
169: }
170: }
171:
172: public void flush() throws ParFileException {
173: try {
174: m_DRoot.setDirty(false);
175: StringBuffer buf = new StringBuffer(256);
176: m_DRoot.toXML(buf, 0);
177: if (m_IsGlobal) {
178: ((AdminDPContext) m_ADPCtxObj)
179: .storeGlobalDPDocument(buf.toString());
180: } else {
181: ((AdminDPContext) m_ADPCtxObj).storeDPDocument(m_DN,
182: buf.toString());
183: }
184: } catch (Exception ex) {
185: throw new ParFileException("errorDPFlush", ex);
186: }
187: }
188:
189: private Object getAdminDPContextObject(String propsFileName)
190: throws ParFileException {
191: Properties desktopProps = new Properties();
192: try {
193: desktopProps.load(new FileInputStream(propsFileName));
194: } catch (FileNotFoundException fnfe) {
195: throw new ParFileException(
196: "DPRootSpecifier.getAdminDPContext() ", fnfe);
197: } catch (IOException ioe) {
198: throw new ParFileException(
199: "DPRootSpecifier.getAdminDPContext() ", ioe);
200: }
201:
202: String adminDPContextClassName = desktopProps
203: .getProperty(AdminDPContext.ADMINDPCONTEXTCLASSNAME_KEY);
204: Object adcObj = null;
205:
206: try {
207: adcObj = (Class.forName(adminDPContextClassName)
208: .newInstance());
209: } catch (ClassNotFoundException cnfe) {
210: throw new ParFileException(
211: "DPRootSpecifier.getAdminDPContext()", cnfe);
212: } catch (NoClassDefFoundError ncdfe) {
213: throw new ParFileException(
214: "DPRootSpecifier.getAdminDPContext()", ncdfe);
215: } catch (IllegalAccessException iae) {
216: throw new ParFileException(
217: "DPRootSpecifier.getAdminDPContext()", iae);
218: } catch (ClassCastException cce) {
219: throw new ParFileException(
220: "DPRootSpecifier.getAdminDPContext()", cce);
221: } catch (InstantiationException ie) {
222: throw new ParFileException(
223: "DPRootSpecifier.getAdminDPContext()", ie);
224: } catch (SecurityException se) {
225: throw new ParFileException(
226: "DPRootSpecifier.getAdminDPContext()", se);
227: }
228:
229: return adcObj;
230: }
231:
232: private String DTPROPFILE = "desktop.propertiesFile";
233:
234: private boolean m_IsGlobal;
235: private String m_DN = null;
236: private DPRoot m_DRoot = null;
237: private Object m_ADPCtxObj;
238: private XMLDPFactory m_Factory;
239: private static String GLOBAL = "global";
240: }
|