001: /*
002: * Copyright 2005 Sun Microsystems, Inc. All
003: * rights reserved. Use of this product is subject
004: * to license terms. Federal Acquisitions:
005: * Commercial Software -- Government Users
006: * Subject to Standard License Terms and
007: * Conditions.
008: *
009: * Sun, Sun Microsystems, the Sun logo, and Sun ONE
010: * are trademarks or registered trademarks of Sun Microsystems,
011: * Inc. in the United States and other countries.
012: */
013:
014: package com.sun.portal.wsrp.common.registry.ebxml;
015:
016: import com.sun.portal.wsrp.common.registry.RegistryManager;
017: import com.sun.portal.wsrp.common.registry.RegistryConfiguration;
018: import com.sun.portal.wsrp.common.registry.RegistryQueryManager;
019: import com.sun.portal.wsrp.common.registry.RegistryLifeCycleManager;
020: import com.sun.portal.wsrp.common.registry.RegistryObjectManager;
021: import com.sun.portal.wsrp.WSRPException;
022:
023: import java.util.Properties;
024: import java.util.HashSet;
025:
026: import javax.xml.registry.BusinessQueryManager;
027: import javax.xml.registry.BusinessLifeCycleManager;
028: import javax.xml.registry.ConnectionFactory;
029: import javax.xml.registry.RegistryService;
030: import javax.xml.registry.JAXRException;
031:
032: import org.freebxml.omar.client.xml.registry.util.SecurityUtil;
033: import org.freebxml.omar.client.xml.registry.ConnectionImpl;
034: import org.freebxml.omar.client.xml.registry.util.JAXRUtility;
035: import org.freebxml.omar.client.xml.registry.util.ProviderProperties;
036: import org.freebxml.omar.common.AbstractProperties;
037:
038: public class RegistryManagerImpl implements RegistryManager {
039:
040: private Properties connProps = new Properties();
041: private String alias = null;
042: private String keyPass = null;
043: private BusinessQueryManager bqm = null;
044: private BusinessLifeCycleManager blcm = null;
045: private RegistryConfiguration rc = null;
046:
047: public RegistryManagerImpl(RegistryConfiguration config)
048: throws WSRPException {
049:
050: try {
051: assignConnectionProperties(config);
052: fetchUserProperties(config);
053:
054: SecurityUtil su = SecurityUtil.getInstance();
055: HashSet creds = new HashSet();
056:
057: creds.add(su.aliasToX500PrivateCredential(alias, keyPass));
058: ConnectionFactory connFactory = JAXRUtility
059: .getConnectionFactory();
060: connFactory.setProperties(connProps);
061: ConnectionImpl conn = (ConnectionImpl) connFactory
062: .createConnection();
063:
064: conn.setCredentials(creds);
065: RegistryService rs = conn.getRegistryService();
066: bqm = rs.getBusinessQueryManager();
067: blcm = rs.getBusinessLifeCycleManager();
068: rc = config;
069: } catch (JAXRException je) {
070: throw new WSRPException("Connection failed "
071: + je.getMessage());
072: }
073: }
074:
075: public RegistryLifeCycleManager getRegistryCycleManager()
076: throws WSRPException {
077: return new RegistryLifeCycleManagerImpl(bqm, blcm, rc);
078: }
079:
080: public RegistryQueryManager getRegistryQueryManager()
081: throws WSRPException {
082: return new RegistryQueryManagerImpl(bqm, blcm);
083: }
084:
085: public RegistryObjectManager getRegistryObjectManager()
086: throws WSRPException {
087: return new RegistryObjectManagerImpl();
088: }
089:
090: private void fetchUserProperties(RegistryConfiguration props) {
091: alias = props.get(JESRegistryConstants.KEY_STORE_ALIAS)
092: .toString();
093: keyPass = props.get(JESRegistryConstants.KEY_PASSWD).toString();
094: }
095:
096: private void assignConnectionProperties(RegistryConfiguration props) {
097:
098: Object temp;
099: ProviderProperties providerProps = ProviderProperties
100: .getInstance();
101: temp = props.get(JESRegistryConstants.QUERY_URL);
102: if (temp != null) {
103: connProps.setProperty(
104: JESRegistryConstants.JAXR_QUERY_URL_STRING, temp
105: .toString().trim());
106: providerProps.put(new String(
107: JESRegistryConstants.JAXR_QUERY_URL_STRING),
108: new String(temp.toString().trim()));
109: }
110: temp = props.get(JESRegistryConstants.PUBLISH_URL);
111: if (temp != null) {
112: connProps.setProperty(
113: JESRegistryConstants.JAXR_PUBLISH_URL_STRING, temp
114: .toString().trim());
115: providerProps.put(
116: JESRegistryConstants.JAXR_PUBLISH_URL_STRING, temp
117: .toString().trim());
118: }
119:
120: temp = props.get(JESRegistryConstants.PROXY_HOST);
121: if (temp != null)
122: connProps.setProperty(JESRegistryConstants.PROXY_HOST, temp
123: .toString().trim());
124:
125: temp = props.get(JESRegistryConstants.PROXY_PORT);
126: if (temp != null)
127: connProps.setProperty(JESRegistryConstants.PROXY_PORT, temp
128: .toString().trim());
129:
130: temp = props.get(JESRegistryConstants.PROXY_USER);
131: if (temp != null)
132: connProps.setProperty(JESRegistryConstants.PROXY_USER, temp
133: .toString().trim());
134:
135: temp = props.get(JESRegistryConstants.PROXY_PASSWD);
136: if (temp != null)
137: connProps.setProperty(JESRegistryConstants.PROXY_PASSWD,
138: temp.toString().trim());
139:
140: temp = props.get(JESRegistryConstants.KEY_STORE_LOCATION);
141: if (temp != null) {
142: connProps.setProperty(
143: JESRegistryConstants.JAXR_EBXML_KEYSTORE_LOCATION,
144: temp.toString().trim());
145: providerProps.put(
146: JESRegistryConstants.JAXR_EBXML_KEYSTORE_LOCATION,
147: temp.toString().trim());
148: }
149:
150: temp = props.get(JESRegistryConstants.KEY_STORE_PASSWD);
151: if (temp != null) {
152: connProps.setProperty(
153: JESRegistryConstants.JAXR_EBXML_KEYSTORE_PASSWD,
154: temp.toString().trim());
155: providerProps.put(
156: JESRegistryConstants.JAXR_EBXML_KEYSTORE_PASSWD,
157: temp.toString().trim());
158: }
159:
160: }
161:
162: }
|