Get the style color and number just once
[LibreOffice.git] / odk / examples / DevelopersGuide / OfficeDev / DesktopEnvironment / OnewayExecutor.java
blob4eb7f80a76f8c8f3aa74c9e97d2aceb588d49d76
1 /* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * The Contents of this file are made available subject to the terms of
5 * the BSD license.
7 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * All rights reserved.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
19 * contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
29 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
30 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
31 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
32 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 *************************************************************************/
36 import java.util.ArrayList;
38 // __________ Implementation __________
40 /**
41 * It's not allowed to call synchronous back inside a oneway interface call.
42 * (see IOnewayLink too). So we start a thread (implemented by this class), which
43 * gets all necessary parameters from the original called object and
44 * call it back later inside his run() method. So the execution of such oneway call
45 * will be asynchronous. It works in a generic way and can be used or any type
46 * of oneway request. Because the source and the target of this call-link knows,
47 * which method was used and which parameters must be handled.
50 class OnewayExecutor extends Thread
54 /**
55 * const
56 * We define some request for some well known oneway interface
57 * calls here too. So they mustn't be declared more than ones.
58 * Of course it's not necessary to use it ... but why not :-)
61 public static final int REQUEST_FRAMEACTION = 1 ;
65 public static final int REQUEST_DISPATCH = 5 ;
72 /**
73 * @member m_rLink the object, which wishes to be called back by this thread
74 * @member m_nRequest describes the type of the original request (means the
75 * called oneway method)
76 * @member m_lParams list of parameters of the original request
78 private final IOnewayLink m_rLink ;
79 private final int m_nRequest ;
80 private final ArrayList<Object> m_lParams ;
84 /**
85 * ctor
86 * It's initialize this thread with all necessary parameters.
87 * It gets the object, which wishes to be called back and the type
88 * and parameters of the original request.
90 * @param nRequest
91 * The two user of this callback can define a unique number,
92 * which identify the type of original interface method.
93 * So the called interface object can decide, which action will be
94 * necessary.
96 * @param lParams
97 * If the original method used parameters, they will be coded here in
98 * a generic way. Only the called interface object know (it depends
99 * from the original request - see nRequest too), how this list must
100 * be interpreted.
101 * Note: Atomic types (e.g. int, long) will be transported as objects
102 * too (Integer, Long)!
104 public OnewayExecutor( IOnewayLink rLink ,
105 int nRequest ,
106 ArrayList<Object> lParams )
108 m_rLink = rLink ;
109 m_nRequest = nRequest;
110 m_lParams = lParams ;
112 if (m_rLink==null)
113 System.out.println("ctor ... m_rLink == null");
114 if (m_lParams==null)
115 System.out.println("ctor ... m_lParams == null");
121 * implements the thread function
122 * Here we call the internal set link object back and
123 * give him all necessary parameters.
124 * After that we die by ourselves ...
126 @Override
127 public void run()
129 if (m_rLink==null)
130 System.out.println("run ... m_rLink == null");
131 if (m_lParams==null)
132 System.out.println("run ... m_lParams == null");
134 if (m_rLink!=null)
135 m_rLink.execOneway( m_nRequest, m_lParams );
141 * static helper!
142 * To make conversion of the generic parameter list to the original
143 * one easier - you can use this helper methods. They know how such list
144 * must be coded. It's not a must to use it - but you can ...
149 public static ArrayList<Object> encodeDispatch(
150 com.sun.star.util.URL[] aURL,
151 com.sun.star.beans.PropertyValue[][] lArgs)
153 int nLength = lArgs.length+1;
154 int nPos = 0;
155 ArrayList<Object> lParams = new ArrayList<Object>(nLength);
157 lParams.add( aURL[0] );
158 --nLength;
160 while (nLength>0)
162 lParams.add( lArgs[0][nPos] );
163 --nLength;
164 ++nPos ;
166 return lParams;
169 public static void decodeDispatch(
170 ArrayList<Object> lParams,
171 com.sun.star.util.URL[] aURL,
172 com.sun.star.beans.PropertyValue[][] lArgs)
174 int nLength = lParams.size()-1;
175 int nPos = 0;
177 lArgs[0] = new com.sun.star.beans.PropertyValue[nLength];
178 aURL[0] = (com.sun.star.util.URL) lParams.get(0);
180 while (nPos<nLength)
182 lArgs[0][nPos] = (com.sun.star.beans.PropertyValue)
183 (lParams.get(nPos+1));
184 ++nPos;
189 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */