KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > webservice > sample > WebServiceSample4


1 /*
2  * Copyright (C) 2005 Alfresco, Inc.
3  *
4  * Licensed under the Mozilla Public License version 1.1
5  * with a permitted attribution clause. You may obtain a
6  * copy of the License at
7  *
8  * http://www.alfresco.org/legal/license.txt
9  *
10  * Unless required by applicable law or agreed to in writing,
11  * software distributed under the License is distributed on an
12  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13  * either express or implied. See the License for the specific
14  * language governing permissions and limitations under the
15  * License.
16  */

17 package org.alfresco.webservice.sample;
18
19 import org.alfresco.webservice.repository.RepositoryServiceSoapBindingStub;
20 import org.alfresco.webservice.repository.UpdateResult;
21 import org.alfresco.webservice.types.CML;
22 import org.alfresco.webservice.types.CMLAddAspect;
23 import org.alfresco.webservice.types.CMLCreate;
24 import org.alfresco.webservice.types.NamedValue;
25 import org.alfresco.webservice.types.ParentReference;
26 import org.alfresco.webservice.types.Reference;
27 import org.alfresco.webservice.util.AuthenticationUtils;
28 import org.alfresco.webservice.util.Constants;
29 import org.alfresco.webservice.util.WebServiceFactory;
30
31 /**
32  * Web service sample 4
33  * <p>
34  * This sample shows how to construct and execute CML queries using the respository web service.
35  *
36  * @author Roy Wetherall
37  */

38 public class WebServiceSample4 extends WebServiceSampleBase
39 {
40     /**
41      * Main function
42      */

43     public static void main(String JavaDoc[] args)
44         throws Exception JavaDoc
45     {
46         AuthenticationUtils.startSession(USERNAME, PASSWORD);
47         try
48         {
49             // Make sure smaple data has been created
50
createSampleData();
51             
52             // Get the repository
53
RepositoryServiceSoapBindingStub repositoryService = WebServiceFactory.getRepositoryService();
54             
55             // Create the CML structure
56
// When executed this cml update query will create a new content node beneth the tutorial folder and the add the
57
// versionable aspect to the newly created node
58
ParentReference parentReference = new ParentReference(STORE, null, "/app:company_home/cm:sample_folder", Constants.ASSOC_CONTAINS, Constants.ASSOC_CONTAINS);
59             NamedValue[] properties = new NamedValue[]{new NamedValue(Constants.PROP_NAME, System.currentTimeMillis() + "_WebServiceSample4.txt")};
60             CMLCreate create = new CMLCreate("id1", parentReference, Constants.TYPE_CONTENT, properties);
61             CMLAddAspect addAspect = new CMLAddAspect(Constants.ASPECT_VERSIONABLE, null, null, "id1");
62             CML cml = new CML();
63             cml.setCreate(new CMLCreate[]{create});
64             cml.setAddAspect(new CMLAddAspect[]{addAspect});
65             
66             // Execute the update
67
UpdateResult[] updateResults = repositoryService.update(cml);
68                    
69             for (UpdateResult updateResult : updateResults)
70             {
71                 String JavaDoc sourceId = "none";
72                 Reference source = updateResult.getSource();
73                 if (source != null)
74                 {
75                     sourceId = source.getUuid();
76                 }
77                 
78                 String JavaDoc destinationId = "none";
79                 Reference destination = updateResult.getDestination();
80                 if (destination != null)
81                 {
82                     destinationId = destination.getUuid();
83                 }
84                 
85                 System.out.println(
86                         "Command = " + updateResult.getStatement() +
87                         "; Source = " + sourceId +
88                         "; Destination = " + destinationId);
89             }
90         }
91         finally
92         {
93             // End the session
94
AuthenticationUtils.endSession();
95         }
96     }
97 }
98
Popular Tags