KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > subversion > client > SvnCmdLineClientInvocationHandler


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 package org.netbeans.modules.subversion.client;
20
21 import java.io.File JavaDoc;
22 import java.lang.reflect.InvocationTargetException JavaDoc;
23 import java.lang.reflect.Method JavaDoc;
24 import java.util.*;
25 import org.netbeans.modules.subversion.client.parser.LocalSubversionException;
26 import org.netbeans.modules.subversion.client.parser.SvnWcParser;
27 import org.netbeans.modules.subversion.config.SvnConfigFiles;
28 import org.tigris.subversion.svnclientadapter.ISVNClientAdapter;
29
30 /**
31  *
32  *
33  * @author Tomas Stupka
34  */

35 public class SvnCmdLineClientInvocationHandler extends SvnClientInvocationHandler {
36
37     private static final String JavaDoc ISVNSTATUS_IMPL = System.getProperty("ISVNStatus.impl", ""); // NOI18N
38
private static final String JavaDoc GET_SINGLE_STATUS = "getSingleStatus"; // NOI18N
39
private static final String JavaDoc GET_STATUS = "getStatus"; // NOI18N
40
private static final String JavaDoc GET_INFO_FROM_WORKING_COPY = "getInfoFromWorkingCopy"; // NOI18N
41

42     
43     private SvnWcParser wcParser = new SvnWcParser();
44     
45     public SvnCmdLineClientInvocationHandler (ISVNClientAdapter adapter, SvnClientDescriptor desc, SvnProgressSupport support, int handledExceptions) {
46         super(adapter, desc, support, handledExceptions);
47     }
48    
49     protected Object JavaDoc invokeMethod(Method JavaDoc proxyMethod, Object JavaDoc[] args)
50     throws NoSuchMethodException JavaDoc, IllegalAccessException JavaDoc, InvocationTargetException JavaDoc
51     {
52         Object JavaDoc ret = null;
53         if (isHandledIntern(proxyMethod, args)) {
54             try {
55                 ret = handleIntern(proxyMethod, args);
56             } catch (LocalSubversionException ex) {
57                 //Exception thrown. Call out to the default adapter
58
}
59         } else {
60             ret = handle(proxyMethod, args);
61         }
62         return ret;
63     }
64
65     private static boolean isHandledIntern(Method JavaDoc method, Object JavaDoc[] args) {
66         boolean exec = ISVNSTATUS_IMPL.equals("exec"); // NOI18N
67
if(exec) {
68             return false;
69         }
70         
71         String JavaDoc methodName = method.getName();
72         return methodName.equals(GET_SINGLE_STATUS) ||
73                methodName.equals(GET_INFO_FROM_WORKING_COPY) ||
74                (method.getName().equals(GET_STATUS) && method.getParameterTypes().length == 3);
75     }
76
77     private Object JavaDoc handleIntern(Method JavaDoc method, Object JavaDoc[] args) throws LocalSubversionException {
78         Object JavaDoc returnValue = null;
79
80         if (GET_SINGLE_STATUS.equals(method.getName())) {
81             returnValue = wcParser.getSingleStatus((File JavaDoc) args[0]);
82         } else if (GET_INFO_FROM_WORKING_COPY.equals(method.getName())) {
83             returnValue= wcParser.getInfoFromWorkingCopy((File JavaDoc) args[0]);
84         } else if (GET_STATUS.equals(method.getName())) {
85             returnValue= wcParser.getStatus(
86                     (File JavaDoc) args[0],
87                     ((Boolean JavaDoc) args[1]).booleanValue(),
88                     ((Boolean JavaDoc) args[2]).booleanValue()
89             );
90         }
91         return returnValue;
92     }
93
94     /**
95      * @return false for methods that perform calls over network
96      */

97     protected boolean noRemoteCallinAWT(String JavaDoc methodName, Object JavaDoc[] args) {
98         boolean ret = super.noRemoteCallinAWT(methodName, args);
99         if(!ret) {
100             if ("getStatus".equals(methodName)) { // NOI18N
101
ret = args.length != 4 || (Boolean.TRUE.equals(args[3]) == false);
102             }
103         }
104         return ret;
105     }
106     
107 }
108
109
Popular Tags