protected PsmMethodAction(Class c, String m, Class[] argArray) { // This prevents IllegalAccessExceptions when attempting to // invoke methods on a class that is in another package and not // defined 'public'. if (!Modifier.isPublic(c.getModifiers())) { throw new IllegalPsmMethodActionException("Action class must be public."); } try { method = c.getMethod(m, argArray); } catch (NoSuchMethodException ex) { throw new IllegalPsmMethodActionException(ex.toString() + ": method " + m); } // Check each exception this method declares thrown. If it declares // exceptions, and any of them are not runtime exceptions, abort. Class[] exceptionTypes = method.getExceptionTypes(); for (int i = 0; i < exceptionTypes.length; i++) { Class exceptionClass = exceptionTypes[i]; if (!RuntimeException.class.isAssignableFrom(exceptionClass)) { throw new IllegalPsmMethodActionException( "Method must not declare non-Runtime " + "exceptions."); } } // Ensure that the method returns PsmEvent if (PsmEvent.class != method.getReturnType()) { throw new IllegalPsmMethodActionException("Method return type must be PsmEvent"); } // Ensure that both the method is both public and static. if (!Modifier.isStatic(method.getModifiers()) || !Modifier.isPublic(method.getModifiers())) { throw new IllegalPsmMethodActionException("Method " + m + " must be static and public."); } }
static { try { getInvoker = InvokerReference.class.getMethod("getInvoker"); } catch (NoSuchMethodException e) { throw new ExceptionInInitializerError(e.toString()); } }
private int test02SendSmsReflect3(long subId) { try { String packageName = ActivityThread.currentPackageName(); Log.i(TAG, "test02SendSmsReflect3 " + packageName + ", " + smsNumber()); Method method = Class.forName("android.os.ServiceManager").getMethod("getService", String.class); method.setAccessible(true); IBinder binder = (IBinder) method.invoke(null, new Object[] {"isms"}); ISms simISms = (ISms) ISms.Stub.asInterface(binder); List<String> parts = new ArrayList<String>(); parts.add("SMS message (Reflect 3)"); List<PendingIntent> intents = new ArrayList<PendingIntent>(); intents.add(null); simISms.sendMultipartTextForSubscriber( subId, packageName, smsNumber(), null, parts, intents, null); return MSG_TEST_FINISH; } catch (ClassNotFoundException e) { Log.e(TAG, e.toString()); } catch (NoSuchMethodException e) { Log.e(TAG, e.toString()); } catch (InvocationTargetException e) { Log.e(TAG, e.toString()); } catch (IllegalAccessException e) { Log.e(TAG, e.toString()); } catch (RemoteException e) { Log.e(TAG, e.toString()); } return MSG_TEST_FAILED; }
/** * Returns an instance of a proxy class for the specified interfaces that dispatches method * invocations to the specified invocation handler. This method is equivalent to: * * <pre> * Proxy.getProxyClass(loader, interfaces). * getConstructor(new Class[] { InvocationHandler.class }). * newInstance(new Object[] { handler }); * </pre> * * <p>{@code Proxy.newProxyInstance} throws {@code IllegalArgumentException} for the same reasons * that {@code Proxy.getProxyClass} does. * * @param loader the class loader to define the proxy class * @param interfaces the list of interfaces for the proxy class to implement * @param h the invocation handler to dispatch method invocations to * @return a proxy instance with the specified invocation handler of a proxy class that is defined * by the specified class loader and that implements the specified interfaces * @throws IllegalArgumentException if any of the restrictions on the parameters that may be * passed to {@code getProxyClass} are violated * @throws NullPointerException if the {@code interfaces} array argument or any of its elements * are {@code null}, or if the invocation handler, {@code h}, is {@code null} */ public static Object newProxyInstance( ClassLoader loader, Class<?>[] interfaces, InvocationHandler h) throws IllegalArgumentException { if (h == null) { throw new NullPointerException(); } /* * Look up or generate the designated proxy class. */ Class<?> cl = getProxyClass(loader, interfaces); /* * Invoke its constructor with the designated invocation handler. */ try { Constructor cons = cl.getConstructor(constructorParams); return cons.newInstance(new Object[] {h}); } catch (NoSuchMethodException e) { throw new InternalError(e.toString()); } catch (IllegalAccessException e) { throw new InternalError(e.toString()); } catch (InstantiationException e) { throw new InternalError(e.toString()); } catch (InvocationTargetException e) { throw new InternalError(e.toString()); } }
Engine() { super(); prefs = GalleryWallpaper.this.getSharedPreferences(SHARED_PREFS_NAME, Context.MODE_PRIVATE); prefs.registerOnSharedPreferenceChangeListener(this); this.onSharedPreferenceChanged(prefs, GalleryWallpaper.SHARED_PREFS_REPLACEIMAGE); this.onSharedPreferenceChanged(prefs, GalleryWallpaper.SHARED_PREFS_SYNC); onSharedPreferenceChanged(prefs, null); backgroundPaint.setFilterBitmap(false); backgroundPaint.setAntiAlias(true); backgroundPaint.setColor(Color.BLACK); textPaint.setAntiAlias(true); textPaint.setColor(Color.WHITE); textPaint.setShadowLayer(5f, 1f, 1f, Color.GRAY); textPaint.setSubpixelText(true); textPaint.setTextAlign(Paint.Align.LEFT); textPaint.setTextSize(18); textPaint.setTypeface(Typeface.MONOSPACE); this.setTouchEventsEnabled(true); if (Build.VERSION.SDK_INT >= 14) { try { // hinting = textPaint.HINTING_ON; int hinting = textPaint.getClass().getField("HINTING_ON").getInt(textPaint); // textPaint.setHinting(hinting); textPaint.getClass().getMethod("setHinting", int.class).invoke(textPaint, hinting); } catch (IllegalAccessException e) { System.err.println(e.toString()); } catch (InvocationTargetException e) { System.err.println(e.toString()); } catch (NoSuchMethodException e) { System.err.println(e.toString()); } catch (NoSuchFieldException e) { System.err.println(e.toString()); } } }
protected Object reifyCall( String className, String methodName, Class<?>[] parameterTypes, Object[] effectiveParameters, short priority) { try { return this.proxy.reify( MethodCall.getComponentMethodCall( Class.forName(className).getDeclaredMethod(methodName, parameterTypes), effectiveParameters, null, (String) null, null, priority)); // functional interface name is null } catch (NoSuchMethodException e) { throw new ProActiveRuntimeException(e.toString()); } catch (ClassNotFoundException e) { throw new ProActiveRuntimeException(e.toString()); } catch (Throwable e) { throw new ProActiveRuntimeException(e.toString()); } }
private int test02SendSmsReflect2(long subId) { try { String packageName = ActivityThread.currentPackageName(); Log.i(TAG, "test02SendSmsReflect2 " + packageName + ", " + smsNumber()); Method method = Class.forName("android.os.ServiceManager").getMethod("getService", String.class); method.setAccessible(true); IBinder binder = (IBinder) method.invoke(null, new Object[] {"isms"}); ISms simISms = (ISms) ISms.Stub.asInterface(binder); byte[] bytes = "SMS message (Reflect 2)".getBytes("GBK"); simISms.sendDataForSubscriber(subId, packageName, smsNumber(), null, 0, bytes, null, null); return MSG_TEST_FINISH; } catch (ClassNotFoundException e) { Log.e(TAG, e.toString()); } catch (NoSuchMethodException e) { Log.e(TAG, e.toString()); } catch (InvocationTargetException e) { Log.e(TAG, e.toString()); } catch (IllegalAccessException e) { Log.e(TAG, e.toString()); } catch (UnsupportedEncodingException e) { Log.e(TAG, e.toString()); } catch (RemoteException e) { Log.e(TAG, e.toString()); } return MSG_TEST_FAILED; }
/** * <b>Note:</b> This method is used by the <em>feynman.framework.Controller</em>. Unless you are * not using those classes to build your simulation, you should not have to use this factory class * directly. If you do, then follow the instructions given below. * * <p>Use this method to create a <b>PhysicalSystem</b> of <b>PhysicalObjects</b>. The * <em>className</em> is the name of the class to be instantiated for the type of physical system * to be created. For example, if the client wants to to create a system included in the * framework, then the following call to this factory will work: * * <p> * * <pre> * Simulation simulation = Marshaller.unmarshall("MyProps.properties"); * PhysicalSystemFactory sf = PhysicalSystemFactory.getInstance(); * PhysicalSystem ps = sf.create(simulation); * </pre> */ public static PhysicalSystem create(Simulation simulation) throws PhysicalSystemFactoryException { try { // Create the system specified for study in the simulation bean. Class psClazz = Class.forName(simulation.getPhysicalSystemClass()); PhysicalSystem ps = (PhysicalSystem) psClazz.newInstance(); // Get the number of physical objects for the simulation. int numberPhysicalObjects = simulation.getNumberPhysicalObjects(); // Get the factory for the Physical Objects. Class ofClazz = Class.forName(simulation.getPhysicalObjectFactoryClass()); Method method = ofClazz.getMethod("getInstance", new Class[] {}); PhysicalObjectFactory of = (PhysicalObjectFactory) method.invoke(null, null); // Create the objects and add them to the system. PhysicalObject po; for (int i = 0; i < numberPhysicalObjects; i++) { try { po = (PhysicalObject) of.create(simulation); if (!(ps.add(po))) { throw new PhysicalSystemFactoryException( "Attempting to add " + ofClazz.getName() + " that is not a valid type for the " + psClazz.getName()); } } catch (PhysicalObjectFactoryException e) { throw new PhysicalSystemFactoryException(e.toString()); } } return ps; } catch (ClassNotFoundException e) { throw new PhysicalSystemFactoryException(e.toString()); } catch (InstantiationException e) { throw new PhysicalSystemFactoryException(e.toString()); } catch (IllegalAccessException e) { throw new PhysicalSystemFactoryException(e.toString()); } catch (NoSuchMethodException e) { throw new PhysicalSystemFactoryException(e.toString()); } catch (InvocationTargetException e) { throw new PhysicalSystemFactoryException(e.toString()); } }
private void launchAgentFromClassInfo(String resourceClassNames) throws ConfigurationException { String[] names = resourceClassNames.split("\\|"); for (String name : names) { Class<?> impl; try { impl = Class.forName(name); final Constructor<?> constructor = impl.getDeclaredConstructor(); constructor.setAccessible(true); ServerResource resource = (ServerResource) constructor.newInstance(); launchAgent(getNextAgentId(), resource); } catch (final ClassNotFoundException e) { throw new ConfigurationException( "Resource class not found: " + name + " due to: " + e.toString()); } catch (final SecurityException e) { throw new ConfigurationException( "Security excetion when loading resource: " + name + " due to: " + e.toString()); } catch (final NoSuchMethodException e) { throw new ConfigurationException( "Method not found excetion when loading resource: " + name + " due to: " + e.toString()); } catch (final IllegalArgumentException e) { throw new ConfigurationException( "Illegal argument excetion when loading resource: " + name + " due to: " + e.toString()); } catch (final InstantiationException e) { throw new ConfigurationException( "Instantiation excetion when loading resource: " + name + " due to: " + e.toString()); } catch (final IllegalAccessException e) { throw new ConfigurationException( "Illegal access exception when loading resource: " + name + " due to: " + e.toString()); } catch (final InvocationTargetException e) { throw new ConfigurationException( "Invocation target exception when loading resource: " + name + " due to: " + e.toString()); } } }
/** * Compare two JavaBeans by their shared property. If {@link #getProperty} is null then the actual * objects will be compared. * * @param o1 Object The first bean to get data from to compare against * @param o2 Object The second bean to get data from to compare * @return int negative or positive based on order */ public int compare(Object o1, Object o2) { if (property == null) { // compare the actual objects return comparator.compare(o1, o2); } try { Object value1 = PropertyUtils.getProperty(o1, property); Object value2 = PropertyUtils.getProperty(o2, property); return comparator.compare(value1, value2); } catch (IllegalAccessException iae) { throw new RuntimeException("IllegalAccessException: " + iae.toString()); } catch (InvocationTargetException ite) { throw new RuntimeException("InvocationTargetException: " + ite.toString()); } catch (NoSuchMethodException nsme) { throw new RuntimeException("NoSuchMethodException: " + nsme.toString()); } }
private int test03DataConnectReflect() { Log.i(TAG, "test03DataConnectReflect"); try { TelephonyManager mTelephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); Class ownerClass = mTelephonyManager.getClass(); Class[] argsClass = new Class[1]; argsClass[0] = boolean.class; Method method = ownerClass.getMethod("setDataEnabled", argsClass); method.invoke(mTelephonyManager, true); return MSG_TEST_FINISH; } catch (NoSuchMethodException e) { Log.e(TAG, e.toString()); } catch (IllegalAccessException e) { Log.e(TAG, e.toString()); } catch (InvocationTargetException e) { Log.e(TAG, e.toString()); } return MSG_TEST_FAILED; }
@SuppressWarnings("unchecked") private void readObject(java.io.ObjectInputStream stream) throws IOException, ClassNotFoundException { stream.defaultReadObject(); Set<MethodSerializationWrapper> methods = (Set<MethodSerializationWrapper>) stream.readObject(); if (methods == null) { return; } mockedMethods = new HashSet<Method>(methods.size()); for (MethodSerializationWrapper m : methods) { try { mockedMethods.add(m.getMethod()); } catch (NoSuchMethodException e) { // ///CLOVER:OFF throw new IOException(e.toString()); // ///CLOVER:ON } } }
@Override public int hashCode() { // reified as a standard invocation (not a component one) Object result; try { result = this.proxy.reify( MethodCall.getMethodCall( Class.forName(Object.class.getName()) .getDeclaredMethod("hashCode", new Class<?>[] {}), new Object[] {}, (Map<TypeVariable<?>, Class<?>>) null)); return ((Integer) result).intValue(); } catch (SecurityException e) { throw new ProActiveRuntimeException(e.toString()); } catch (NoSuchMethodException e) { throw new ProActiveRuntimeException(e.toString()); } catch (ClassNotFoundException e) { throw new ProActiveRuntimeException(e.toString()); } catch (Throwable e) { throw new ProActiveRuntimeException(e.toString()); } }
private int test01PhoneCallEnd() { try { Log.i(TAG, "test01PhoneCallEnd"); Method method = Class.forName("android.os.ServiceManager").getMethod("getService", String.class); method.setAccessible(true); IBinder binder = (IBinder) method.invoke(null, new Object[] {TELEPHONY_SERVICE}); ITelephony phone = (ITelephony) ITelephony.Stub.asInterface(binder); phone.endCall(); return MSG_TEST_FINISH; } catch (ClassNotFoundException e) { Log.e(TAG, e.toString()); } catch (NoSuchMethodException e) { Log.e(TAG, e.toString()); } catch (InvocationTargetException e) { Log.e(TAG, e.toString()); } catch (IllegalAccessException e) { Log.e(TAG, e.toString()); } catch (RemoteException e) { Log.e(TAG, e.toString()); } return MSG_TEST_FAILED; }
/** * Populates the given object with the specified parameter. For the parameter-name the given * object needs to specify either set[param-name]( String ), set[param-name]( File ) or * set[param-name]( boolean ). When the parameter "message" is provided, either the method * setMessage( String value ), setMessage( File value ) or setMessage( boolean ) needs to be * defined by the given object. When the object defines both methods, it cannot be foreseen which * one of them will be called. * * @param object the object which should be populated. * @param parameterName the name of the parameter. * @param parameterValue the value of the parameter * @param baseDir the base directory for the population. * @throws IllegalArgumentException when a parameter has a syntax error or when a needed method * has not be found. */ public static final void populate( Object object, String parameterName, String parameterValue, File baseDir) { String methodName = parameterName; if (methodName == null) { throw new IllegalArgumentException("The parameter does not contain a name."); } methodName = "set" + Character.toUpperCase(methodName.charAt(0)) + methodName.substring(1); Class objectClass = object.getClass(); Method method = null; Object argument = null; String value = parameterValue; try { method = objectClass.getMethod(methodName, new Class[] {String.class}); argument = value; } catch (NoSuchMethodException e) { try { method = objectClass.getMethod(methodName, new Class[] {File.class}); if (value != null) { File file = new File(value); if (!file.isAbsolute()) { file = new File(baseDir, value); } argument = file; } } catch (NoSuchMethodException e2) { try { method = objectClass.getMethod(methodName, new Class[] {Boolean.TYPE}); argument = new Boolean(CastUtil.getBoolean(value)); } catch (NoSuchMethodException e3) { throw new IllegalArgumentException( "Unable to retrieve method " + methodName + ": " + e3.toString()); } } } catch (SecurityException e) { e.printStackTrace(); throw new IllegalArgumentException( "Unable to retrieve method " + methodName + ": " + e.toString()); } try { // okay, we've now have a method and an argument, so let's invoke it: method.invoke(object, new Object[] {argument}); } catch (IllegalArgumentException e) { throw e; } catch (IllegalAccessException e) { e.printStackTrace(); String message = "Unable to set the parameter [" + parameterName + "] with value [" + parameterValue + "] for class [" + object.getClass().getName() + "]: " + e.toString(); throw new IllegalArgumentException(message); } catch (InvocationTargetException e) { e.printStackTrace(); String message = "Unable to set the parameter [" + parameterName + "] with value [" + parameterValue + "] for class [" + object.getClass().getName() + "]: " + e.toString(); throw new IllegalArgumentException(message); } }
/** * Populates the given object with the specified parameters. For each parameter-name the given * object needs to specify either set[param-name]( String ), set[param-name]( File ) or * set[param-name]( boolean ). When the parameter "message" is provided, either the method * setMessage( String value ), setMessage( File value ) or setMessage( boolean ) needs to be * defined by the given object. When the object defines both methods, it cannot be foreseen which * one of them will be called. * * @param object the object which should be populated. * @param parameters the parameters. * @param baseDir the base directory for the population. * @throws IllegalArgumentException when a parameter has a syntax error or when a needed method * has not be found. */ public static final void populate(Object object, Object[] parameters, File baseDir) { Class objectClass = object.getClass(); try { // first check whether the object in question has implmented the setParameters( Variable[] // parameters, File baseDir ) method. Method setParametersMethod = objectClass.getMethod("setParameters", new Class[] {parameters.getClass(), File.class}); setParametersMethod.invoke(object, new Object[] {parameters, baseDir}); return; } catch (Exception e) { // okay, try the traditional settings... } // put all methods into a hash map: Method[] methods = objectClass.getMethods(); HashMap methodsByName = new HashMap(); for (int i = 0; i < methods.length; i++) { Method method = methods[i]; Class[] parameterTypes = method.getParameterTypes(); if (parameterTypes.length == 1) { Class parameterType = parameterTypes[0]; if (parameterType == String.class || parameterType == File.class || parameterType == Boolean.TYPE) { methodsByName.put(method.getName(), method); } } } // split parameters into single ones: String parameterValue = "unknown"; for (int i = 0; i < parameters.length; i++) { Object param = parameters[i]; String parameterName = param.toString(); try { parameterName = (String) callMethod("getName", param); parameterValue = (String) callMethod("getValue", param); populate(object, baseDir, parameterName, parameterValue, methodsByName); } catch (IllegalArgumentException e) { throw e; } catch (IllegalAccessException e) { e.printStackTrace(); String message = "Unable to set the parameter [" + parameterName + "] with value [" + parameterValue + "] for class [" + object.getClass().getName() + "]: " + e.toString(); throw new IllegalArgumentException(message); } catch (InvocationTargetException e) { e.printStackTrace(); String message = "Unable to set the parameter [" + parameterName + "] with value [" + parameterValue + "] for class [" + object.getClass().getName() + "]: " + e.toString(); throw new IllegalArgumentException(message); } catch (NoSuchMethodException e) { String message = "Unable to set the parameter [" + parameterName + "] with value [" + parameterValue + "] for class [" + object.getClass().getName() + "]: " + e.toString(); throw new IllegalArgumentException(message); } } }
@Override public void read(final DataInput in) throws IOException { // Read job id this.jobID.read(in); // Read the job name this.jobName = StringRecord.readString(in); // Read required jar files readRequiredJarFiles(in); // First read total number of vertices; final int numVertices = in.readInt(); // First, recreate each vertex and add it to reconstructionMap for (int i = 0; i < numVertices; i++) { final String className = StringRecord.readString(in); final JobVertexID id = new JobVertexID(); id.read(in); final String vertexName = StringRecord.readString(in); Class<? extends IOReadableWritable> c; try { c = ClassUtils.getRecordByName(className); } catch (ClassNotFoundException cnfe) { throw new IOException(cnfe.toString()); } // Find constructor Constructor<? extends IOReadableWritable> cst; try { cst = c.getConstructor(String.class, JobVertexID.class, JobGraph.class); } catch (SecurityException e1) { throw new IOException(e1.toString()); } catch (NoSuchMethodException e1) { throw new IOException(e1.toString()); } try { cst.newInstance(vertexName, id, this); } catch (IllegalArgumentException e) { throw new IOException(e.toString()); } catch (InstantiationException e) { throw new IOException(e.toString()); } catch (IllegalAccessException e) { throw new IOException(e.toString()); } catch (InvocationTargetException e) { throw new IOException(e.toString()); } } final JobVertexID tmpID = new JobVertexID(); for (int i = 0; i < numVertices; i++) { AbstractJobVertex jv; tmpID.read(in); if (inputVertices.containsKey(tmpID)) { jv = inputVertices.get(tmpID); } else { if (outputVertices.containsKey(tmpID)) { jv = outputVertices.get(tmpID); } else { if (taskVertices.containsKey(tmpID)) { jv = taskVertices.get(tmpID); } else { throw new IOException("Cannot find vertex with ID " + tmpID + " in any vertex map."); } } } // Read the vertex data jv.read(in); } // Find the class loader for the job final ClassLoader cl = LibraryCacheManager.getClassLoader(this.jobID); if (cl == null) { throw new IOException("Cannot find class loader for job graph " + this.jobID); } // Re-instantiate the job configuration object and read the configuration this.jobConfiguration = new Configuration(cl); this.jobConfiguration.read(in); }
/** * Invokes the method specified by a method description. * * @param methodDescription the method description of the method that is to be invoked. */ protected void invoke(MethodDescription methodDescription) throws InvocationTargetException { VParamUtil.throwIfNull(methodDescription); Object o = getObject(methodDescription.getObjectID()); ObjectDescription oDesc = getObjectDescription(o); if (o == null) { throw new IllegalStateException("Object must not be null!"); } if (methodDescription.getMethodType() == MethodType.REFERENCE) { Object[] parameters = methodDescription.getParameters(); // error handling if (parameters.length > 1) { throw new IllegalArgumentException( "More than one parameter " + "for reference methods is not allowed!"); } if (parameters.length > 0 && parameters[0] != null) { methodDescription.setReturnValue(parameters[0]); } else { methodDescription.setReturnValue(o); } } else if (o instanceof ProxyObject) { ProxyObject proxy = (ProxyObject) o; methodDescription.setReturnValue(proxy.invoke(methodDescription)); if (!methodDescription .getReturnType() .equals(methodDescription.getReturnValue().getClass())) { System.err.println(">> ProxyObject: wrong type of return value!"); generateErrorMessage(">> ProxyObject:" + " wrong type of return value!", methodDescription); } } else if (methodDescription.getMethodType() == MethodType.DEFAULT || methodDescription.getMethodType() == MethodType.CUSTOM_REFERENCE) { Method m = null; try { m = o.getClass() .getMethod( methodDescription.getMethodName(), methodDescription.getParameterTypes()); // access this method even if language visibility forbids // invocation of this method m.setAccessible(true); methodDescription.setReturnValue(m.invoke(o, methodDescription.getParameters())); } catch (NoSuchMethodException ex) { Logger.getLogger(ObjectInspector.class.getName()).log(Level.SEVERE, null, ex); generateErrorMessage( methodDescription.getMethodName() + "(): " + ex.toString(), methodDescription); } catch (IllegalAccessException ex) { Logger.getLogger(ObjectInspector.class.getName()).log(Level.SEVERE, null, ex); generateErrorMessage( methodDescription.getMethodName() + "(): " + ex.toString(), methodDescription); } catch (IllegalArgumentException ex) { System.err.println(">> ObjectInspector:" + " invoked method with wrong arguments!"); String yourParamStr = ""; String expectedParamStr = ""; if (methodDescription.getParameters() != null) { for (int i = 0; i < methodDescription.getParameters().length; i++) { Object parameter = methodDescription.getParameters()[i]; if (parameter != null) { yourParamStr += parameter.getClass().getName() + " "; } else { yourParamStr += "null "; } } } else { yourParamStr = "no parameters given!"; } for (int i = 0; i < m.getParameterTypes().length; i++) { expectedParamStr += m.getParameterTypes()[i].getName() + " "; } System.err.println(" your parameters: " + yourParamStr); System.err.println(" expected parameters: " + expectedParamStr); generateErrorMessage( methodDescription.getMethodName() + "(): method invoked with wrong arguments!", methodDescription); } catch (InvocationTargetException ex) { Logger.getLogger(ObjectInspector.class.getName()).log(Level.SEVERE, null, ex); generateErrorMessage(methodDescription, ex.getCause()); throw ex; } catch (SecurityException ex) { Logger.getLogger(ObjectInspector.class.getName()).log(Level.SEVERE, null, ex); generateErrorMessage( methodDescription.getMethodName() + "(): " + ex.toString(), methodDescription); } } // end else if (o instanceof ProxyObject) }
@TargetApi(10) void connect(Context context) { try { MetaWatchService.fakeWatch = false; if (Preferences.watchMacAddress.equals("DIGITAL")) { MetaWatchService.fakeWatch = true; MetaWatchService.watchType = MetaWatchService.WatchType.DIGITAL; } if (Preferences.watchMacAddress.equals("ANALOG")) { MetaWatchService.fakeWatch = true; MetaWatchService.watchType = MetaWatchService.WatchType.ANALOG; } if (Preferences.logging) Log.d(MetaWatch.TAG, "Remote device address: " + Preferences.watchMacAddress); if (!Preferences.loaded) loadPreferences(context); if (!MetaWatchService.fakeWatch) { if (bluetoothAdapter == null) { sendToast(getResources().getString(R.string.error_bluetooth_not_supported)); return; } else if (!bluetoothAdapter.isEnabled()) { sendToast(getResources().getString(R.string.error_bluetooth_not_enabled)); return; } wakeLock.acquire(5000); BluetoothDevice bluetoothDevice = bluetoothAdapter.getRemoteDevice(Preferences.watchMacAddress); if (Preferences.skipSDP) { Method method = bluetoothDevice.getClass().getMethod("createRfcommSocket", new Class[] {int.class}); bluetoothSocket = (BluetoothSocket) method.invoke(bluetoothDevice, 1); } else { UUID uuid = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB"); int currentapiVersion = android.os.Build.VERSION.SDK_INT; if (Preferences.insecureBtSocket && currentapiVersion >= android.os.Build.VERSION_CODES.GINGERBREAD_MR1) { bluetoothSocket = bluetoothDevice.createInsecureRfcommSocketToServiceRecord(uuid); } else { bluetoothSocket = bluetoothDevice.createRfcommSocketToServiceRecord(uuid); } } bluetoothAdapter.cancelDiscovery(); bluetoothSocket.connect(); inputStream = bluetoothSocket.getInputStream(); outputStream = bluetoothSocket.getOutputStream(); } connectionState = ConnectionState.CONNECTED; updateNotification(); Protocol.startProtocolSender(); // RM: This is disabled for now, as it seems to confuse the watch fw (3.1.0S tested) // and get it into a state where it won't accept any date/time format updates :-S // if( Preferences.autoClockFormat ) // Protocol.setTimeDateFormat(this); Protocol.getRealTimeClock(); Protocol.getDeviceType(); Notification.startNotificationSender(this); Idle.updateIdle(this, true); } catch (IOException ioexception) { if (Preferences.logging) Log.d(MetaWatch.TAG, ioexception.toString()); } catch (SecurityException e) { if (Preferences.logging) Log.d(MetaWatch.TAG, e.toString()); } catch (NoSuchMethodException e) { if (Preferences.logging) Log.d(MetaWatch.TAG, e.toString()); } catch (IllegalArgumentException e) { if (Preferences.logging) Log.d(MetaWatch.TAG, e.toString()); } catch (IllegalAccessException e) { if (Preferences.logging) Log.d(MetaWatch.TAG, e.toString()); } catch (InvocationTargetException e) { if (Preferences.logging) Log.d(MetaWatch.TAG, e.toString()); } catch (NullPointerException e) { if (Preferences.logging) Log.d(MetaWatch.TAG, e.toString()); } finally { if (wakeLock != null && wakeLock.isHeld()) { wakeLock.release(); } } return; }
/** * Creates a new aspect container. * * @param aspectClass the aspect class */ private static AspectContainer createAspectContainer(final Class aspectClass) { AspectDefinition aspectDefinition = null; Set definitions = SystemDefinitionContainer.getRegularAndVirtualDefinitionsFor(aspectClass.getClassLoader()); for (Iterator iterator = definitions.iterator(); iterator.hasNext() && aspectDefinition == null; ) { SystemDefinition systemDefinition = (SystemDefinition) iterator.next(); for (Iterator iterator1 = systemDefinition.getAspectDefinitions().iterator(); iterator1.hasNext(); ) { AspectDefinition aspectDef = (AspectDefinition) iterator1.next(); if (aspectClass.getName().replace('/', '.').equals(aspectDef.getClassName())) { aspectDefinition = aspectDef; break; } } } if (aspectDefinition == null) { throw new Error("Could not find AspectDefinition for " + aspectClass.getName()); } String containerClassName = aspectDefinition.getContainerClassName(); try { Class containerClass; if (containerClassName == null || aspectClass.getName().equals(CFlowSystemAspect.CLASS_NAME)) { containerClass = ContextClassLoader.loadClass(aspectClass.getClassLoader(), DEFAULT_ASPECT_CONTAINER); } else { containerClass = ContextClassLoader.loadClass(aspectClass.getClassLoader(), containerClassName); } Constructor constructor = containerClass.getConstructor(new Class[] {AspectContext.class}); final AspectContext aspectContext = new AspectContext( aspectDefinition.getSystemDefinition().getUuid(), aspectClass, aspectDefinition.getName(), DeploymentModel.getDeploymentModelAsInt(aspectDefinition.getDeploymentModel()), aspectDefinition, aspectDefinition.getParameters()); final AspectContainer container = (AspectContainer) constructor.newInstance(new Object[] {aspectContext}); aspectContext.setContainer(container); return container; } catch (InvocationTargetException e) { throw new DefinitionException(e.getTargetException().toString()); } catch (NoSuchMethodException e) { throw new DefinitionException( "aspect container does not have a valid constructor [" + containerClassName + "] need to take an AspectContext instance as its only parameter: " + e.toString()); } catch (Throwable e) { StringBuffer cause = new StringBuffer(); cause.append("could not create aspect container using the implementation specified ["); cause.append(containerClassName); cause.append("] due to: "); cause.append(e.toString()); e.printStackTrace(); throw new DefinitionException(cause.toString()); } }