Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
This bundle wraps Pi4j (http://pi4j.com) that wraps the native code Wiring Pi (http://wiringpi.com). It wraps these libraries to make them OSGi friendly and allow them to work together with the OSGi enRoute IoT circuit library (osgi.enroute.iot.circuit). The bundle will first use Pi4J to detect on what hardware it runs. If it runs on an appropriate type, it will register a component that can be configured with Metatype. The Metatype defines a full blown configuration template for all the Pi's functions. The GPIO's are registered as components for the circuit. Regardless of the success of the configuration, this bundle will also register a GpioController service, which is the main Pi4J class.
package aQute.lib.converter;
import java.lang.reflect.Array;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.GenericArrayType;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Proxy;
import java.lang.reflect.Type;
import java.lang.reflect.TypeVariable;
import java.lang.reflect.WildcardType;
import java.net.URI;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Dictionary;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Stack;
import java.util.TreeMap;
import java.util.TreeSet;
import java.util.UUID;
import java.util.Vector;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.regex.Pattern;
import aQute.lib.base64.Base64;
/**
* General Java type converter from an object to any type. Supports number
* conversion
*/
@SuppressWarnings({
"unchecked", "rawtypes"
})
public class Converter {
public interface Hook {
Object convert(Type dest, Object o) throws Exception;
}
boolean fatal = true;
Map hooks;
List allHooks;
public T convert(Class type, Object o) throws Exception {
// Is it a compatible type?
if (o != null && type.isAssignableFrom(o.getClass()))
return (T) o;
return (T) convert((Type) type, o);
}
public T convert(TypeReference type, Object o) throws Exception {
return (T) convert(type.getType(), o);
}
public Object convert(Type type, Object o) throws Exception {
Class resultType = getRawClass(type);
if (o == null) {
if (resultType.isPrimitive() || Number.class.isAssignableFrom(resultType))
return convert(type, 0);
return null; // compatible with any
}
if (allHooks != null) {
for (Hook hook : allHooks) {
Object r = hook.convert(type, o);
if (r != null)
return r;
}
}
if (hooks != null) {
Hook hook = hooks.get(type);
if (hook != null) {
Object value = hook.convert(type, o);
if (value != null)
return value;
}
}
Class< ? > actualType = o.getClass();
// We can always make a string
if (resultType == String.class) {
if (actualType.isArray()) {
if (actualType == char[].class)
return new String((char[]) o);
if (actualType == byte[].class)
return Base64.encodeBase64((byte[]) o);
int l = Array.getLength(o);
StringBuilder sb = new StringBuilder("[");
String del = "";
for (int i = 0; i < l; i++) {
sb.append(del);
del = ",";
sb.append(convert(String.class, Array.get(o, i)));
}
sb.append("]");
return sb.toString();
}
return o.toString();
}
// or make a UUID
if (resultType == UUID.class) {
return UUID.fromString(o.toString());
}
//
// In case we have a Dictionary that is not also a map
// this is kind of opportune in OSGi because of the silly
// dictionaries we're still having
//
if ( o instanceof Dictionary && !(o instanceof Map)) {
Dictionary,?> dict = (Dictionary< ? , ? >) o;
Map