001: package com.sun.portal.wsrp.producer.portletmanagement.test;
002:
003: import java.util.Properties;
004: import java.util.Set;
005: import java.util.HashSet;
006:
007: import java.io.InputStream;
008: import java.io.FileInputStream;
009:
010: import com.sun.portal.wsrp.common.stubs.WSRP_v1_PortletManagement_PortType;
011: import com.sun.portal.wsrp.common.stubs.PortletDescriptionResponse;
012: import com.sun.portal.wsrp.common.stubs.PortletDescription;
013: import com.sun.portal.wsrp.common.stubs.GetPortletDescription;
014: import com.sun.portal.wsrp.common.stubs.RegistrationContext;
015: import com.sun.portal.wsrp.common.stubs.PortletContext;
016: import com.sun.portal.wsrp.common.stubs.UserContext;
017: import com.sun.portal.wsrp.common.stubs.ClonePortlet;
018: import com.sun.portal.wsrp.common.stubs.DestroyPortlets;
019: import com.sun.portal.wsrp.common.stubs.DestroyPortletsResponse;
020:
021: import com.sun.portal.wsrp.consumer.common.RemoteServiceStubManager;
022: import com.sun.portal.wsrp.consumer.common.impl.PropertiesRemoteServiceStubManagerImpl;
023:
024: import com.sun.portal.wsrp.common.WSRPFactory; //PM
025: import com.sun.portal.wsrp.common.stubs.PropertyList;
026: import com.sun.portal.wsrp.common.stubs.GetPortletProperties;
027: import com.sun.portal.wsrp.common.stubs.SetPortletProperties;
028: import com.sun.portal.wsrp.common.stubs.Property;
029: import com.sun.portal.wsrp.common.stubs.PropertyList;
030: import com.sun.portal.wsrp.common.stubs.PortletPropertyDescriptionResponse;
031: import com.sun.portal.wsrp.common.stubs.GetPortletPropertyDescription;
032:
033: //--PM
034:
035: public class Test {
036: private Properties config = null;
037: private WSRP_v1_PortletManagement_PortType portType = null;
038: private String[] args = null;
039:
040: public static void main(String[] args) {
041: try {
042: new Test(args).execute();
043: } catch (Exception e) {
044: e.printStackTrace();
045: }
046: }
047:
048: public Test(String[] args) throws Exception {
049: config = new Properties();
050: InputStream is = new FileInputStream("./config.properties");
051: config.load(is);
052: this .args = args;
053:
054: RemoteServiceStubManager stubMgr = new PropertiesRemoteServiceStubManagerImpl(
055: "./config.properties");
056: portType = stubMgr
057: .getPortletManagementPortType(RemoteServiceStubManager.PORTLET_MANAGEMENT_PORT_BINDING);
058: }
059:
060: void execute() throws Exception {
061: String op = args[0];
062:
063: if (op.equalsIgnoreCase("getportletdescription")) {
064: PortletDescriptionResponse pdr = getPortletDescription();
065: PortletDescription pd = pdr.getPortletDescription();
066: System.out.println(WSRPFactory.getInstance()
067: .getPortletDescriptionXML(pd, true));
068: } else if (op.equalsIgnoreCase("cloneportlet")) {
069: PortletContext pc = clonePortlet();
070: System.out.println(WSRPFactory.getInstance()
071: .getPortletContextXML(pc, true));
072: } else if (op.equalsIgnoreCase("destroyportlets")) {
073: DestroyPortletsResponse dpr = destroyPortlets();
074: System.out.println(WSRPFactory.getInstance()
075: .getDestroyPortletsResponseXML(dpr, true));
076: } else if (op.equalsIgnoreCase("getportletproperties")) {
077: PropertyList pl = getPortletProperties();
078: System.out.println(WSRPFactory.getInstance()
079: .getPropertyListXML(pl, true));
080: } else if (op.equalsIgnoreCase("setportletproperties")) {
081: PortletContext pc = setPortletProperties();
082: System.out.println(WSRPFactory.getInstance()
083: .getPortletContextXML(pc, true));
084: } else if (op.equalsIgnoreCase("getportletpropertydescription")) {
085: PortletPropertyDescriptionResponse ppdr = getPortletPropertyDescription();
086: System.out.println(WSRPFactory.getInstance()
087: .getPortletPropertyDescriptionResponseXML(ppdr,
088: true));
089: } else {
090: throw new Exception("unknown operation: " + op);
091: }
092: }
093:
094: private PortletContext clonePortlet() throws Exception {
095: ClonePortlet cp = getClonePortlet();
096: PortletContext pc = (PortletContext) portType.clonePortlet(cp);
097:
098: return pc;
099: }
100:
101: private DestroyPortletsResponse destroyPortlets() throws Exception {
102: DestroyPortlets dp = getDestroyPortlets();
103: DestroyPortletsResponse dpr = (DestroyPortletsResponse) portType
104: .destroyPortlets(dp);
105:
106: return dpr;
107: }
108:
109: private DestroyPortlets getDestroyPortlets() {
110: RegistrationContext rc = getRegistrationContext();
111: String[] phs = getPortletHandles();
112:
113: return new DestroyPortlets(rc, phs);
114: }
115:
116: private String[] getPortletHandles() {
117: Set handles = new HashSet();
118: for (int i = 2; i < args.length; i++) {
119: handles.add(args[i]);
120: }
121:
122: return (String[]) handles.toArray(new String[0]);
123: }
124:
125: private ClonePortlet getClonePortlet() {
126: RegistrationContext rc = getRegistrationContext();
127: PortletContext pc = getPortletContext();
128: UserContext uc = getUserContext();
129:
130: ClonePortlet cp = new ClonePortlet(rc, pc, uc);
131: return cp;
132: }
133:
134: private PortletDescriptionResponse getPortletDescription()
135: throws Exception {
136: GetPortletDescription gpd = getGetPortletDescription();
137: PortletDescriptionResponse pdr = (PortletDescriptionResponse) portType
138: .getPortletDescription(gpd);
139:
140: return pdr;
141: }
142:
143: private GetPortletDescription getGetPortletDescription() {
144: RegistrationContext rc = getRegistrationContext();
145: PortletContext pc = getPortletContext();
146: UserContext uc = getUserContext();
147:
148: GetPortletDescription gpd = new GetPortletDescription(rc, pc,
149: uc, null);
150:
151: return gpd;
152: }
153:
154: private RegistrationContext getRegistrationContext() {
155: System.out.println("Registration Context :" + args[1]);
156: return new RegistrationContext(args[1], null, null);
157: }
158:
159: private PortletContext getPortletContext() {
160: System.out.println("Portlet Context :" + args[3]);
161: return new PortletContext(args[3], null, null);
162: }
163:
164: private UserContext getUserContext() {
165: System.out.println("User Context :" + args[2]);
166: return new UserContext(args[2], null, null, null);
167: }
168:
169: //PM
170: private PortletPropertyDescriptionResponse getPortletPropertyDescription()
171: throws Exception {
172: GetPortletPropertyDescription gppd = getGetPortletPropertyDescription();
173: PortletPropertyDescriptionResponse ppdr = (PortletPropertyDescriptionResponse) portType
174: .getPortletPropertyDescription(gppd);
175:
176: return ppdr;
177: }
178:
179: private GetPortletPropertyDescription getGetPortletPropertyDescription()
180: throws Exception {
181: RegistrationContext rc = getRegistrationContext();
182: PortletContext pc = getPortletContext();
183: UserContext uc = getUserContext();
184: String[] dls = null;
185: dls = new String[1];
186: dls[0] = args[4];
187: System.out.println("Locales :" + dls[0]);
188: GetPortletPropertyDescription gppd = new GetPortletPropertyDescription(
189: rc, pc, uc, dls);
190: return gppd;
191: }
192:
193: private PortletContext setPortletProperties() throws Exception {
194: SetPortletProperties spp = getSetPortletProperties();
195: PortletContext pc = (PortletContext) portType
196: .setPortletProperties(spp);
197:
198: return pc;
199: }
200:
201: private SetPortletProperties getSetPortletProperties()
202: throws Exception {
203: RegistrationContext rc = getRegistrationContext();
204: PortletContext pc = getPortletContext();
205: UserContext uc = getUserContext();
206: PropertyList pl = getPropertyList();
207:
208: SetPortletProperties spp = new SetPortletProperties(rc, pc, uc,
209: pl);
210:
211: return spp;
212: }
213:
214: private PropertyList getPortletProperties() throws Exception {
215: GetPortletProperties gpp = getGetPortletProperties();
216: PropertyList pl = (PropertyList) portType
217: .getPortletProperties(gpp);
218:
219: return pl;
220: }
221:
222: private GetPortletProperties getGetPortletProperties()
223: throws Exception {
224: RegistrationContext rc = getRegistrationContext();
225: PortletContext pc = getPortletContext();
226: UserContext uc = getUserContext();
227: // TBD, test this
228: String[] names = null;
229:
230: GetPortletProperties gpp = new GetPortletProperties(rc, pc, uc,
231: names);
232: return gpp;
233: }
234:
235: private PropertyList getPropertyList() {
236: String key = args[4];
237: String val = args[5];
238:
239: Property p = new Property(key, "en-US", val, null);
240: PropertyList pl = new PropertyList(new Property[] { p }, null,
241: null);
242:
243: return pl;
244: }
245: //--PM
246: }
|