KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > infoglue > deliver > taglib > content > InfoGlueWebServiceTag


1 package org.infoglue.deliver.taglib.content;
2
3 import java.util.ArrayList JavaDoc;
4 import java.util.HashMap JavaDoc;
5 import java.util.List JavaDoc;
6 import java.util.Map JavaDoc;
7
8 import javax.servlet.jsp.JspException JavaDoc;
9 import javax.servlet.jsp.JspTagException JavaDoc;
10
11 import org.infoglue.cms.security.InfoGluePrincipal;
12 import org.infoglue.cms.util.CmsPropertyHandler;
13 import org.infoglue.deliver.taglib.TemplateControllerTag;
14 import org.infoglue.deliver.util.webservices.DynamicWebservice;
15
16 /**
17  * This tag helps update a content in the cms from the delivery application.
18  */

19
20 public abstract class InfoGlueWebServiceTag extends TemplateControllerTag
21 {
22     /**
23      * The universal version identifier.
24      */

25     private static final long serialVersionUID = -1904980538720103871L;
26
27     /**
28      *
29      */

30     private String JavaDoc targetEndpointAddress = CmsPropertyHandler.getWebServicesBaseUrl() + "RemoteContentService";
31
32     /**
33      *
34      */

35     private InfoGluePrincipal principal;
36
37     /**
38      *
39      */

40     public InfoGlueWebServiceTag()
41     {
42         super();
43     }
44
45
46     /**
47      *
48      */

49     public void setTargetEndpointAddress(final String JavaDoc targetEndpointAddress) throws JspException JavaDoc
50     {
51         this.targetEndpointAddress = evaluateString("infoGlueWebService", "targetEndpointAddress", targetEndpointAddress);
52     }
53
54     /**
55      *
56      */

57     public void setPrincipal(final String JavaDoc principalString) throws JspException JavaDoc
58     {
59         this.principal = (InfoGluePrincipal) this.evaluate("infoGlueWebService", "principal", principalString, InfoGluePrincipal.class);
60     }
61
62     protected void invokeOperation(String JavaDoc name, Object JavaDoc argument) throws JspException JavaDoc
63     {
64         try
65         {
66             if (this.principal == null)
67                 this.principal = this.getController().getPrincipal();
68
69             final DynamicWebservice ws = new DynamicWebservice(principal);
70
71             ws.setTargetEndpointAddress(targetEndpointAddress);
72             ws.setOperationName(getOperationName());
73             ws.setReturnType(Boolean JavaDoc.class);
74
75             if(argument instanceof Map JavaDoc || argument instanceof HashMap JavaDoc)
76                 ws.addArgument(name, (Map JavaDoc)argument);
77             else if(argument instanceof List JavaDoc || argument instanceof ArrayList JavaDoc)
78                 ws.addArgument(name, (List JavaDoc)argument);
79             else
80                 ws.addArgument(name, argument);
81             
82             ws.callService();
83             setResultAttribute(ws.getResult());
84         }
85         catch (Exception JavaDoc e)
86         {
87             e.printStackTrace();
88             throw new JspTagException JavaDoc(e.getMessage());
89         }
90     }
91
92
93     public String JavaDoc getTargetEndpointAddress()
94     {
95         return targetEndpointAddress;
96     }
97
98     public abstract void setOperationName(final String JavaDoc operationName);
99
100     public abstract String JavaDoc getOperationName();
101     
102 }
Popular Tags