List of usage examples for org.apache.commons.lang ArrayUtils EMPTY_CLASS_ARRAY
Class EMPTY_CLASS_ARRAY
To view the source code for org.apache.commons.lang ArrayUtils EMPTY_CLASS_ARRAY.
Click Source Link
Class
array. From source file:org.polymap.core.runtime.recordstore.RecordModel.java
/** * Allows to access the properties of the model (name, type(?)) in a static way. * * @param <M> The state model type. * @param cl The state model class.// w w w. j a va 2 s . c om * @return A new type instance with null state. */ public static <M extends RecordModel> M type(Class<M> cl) { IRecordState nullState = new IRecordState() { public IRecordState add(String key, Object value) { throw new RuntimeException("Not allowed for TYPE state."); } public <T> T get(String key) { throw new RuntimeException("Not allowed for TYPE state."); } public <T> List<T> getList(String key) { throw new RuntimeException("Not allowed for TYPE state."); } public Object id() { throw new RuntimeException("Not allowed for TYPE state."); } public Iterator<Entry<String, Object>> iterator() { throw new RuntimeException("Not allowed for TYPE state."); } public <T> IRecordState put(String key, T value) { throw new RuntimeException("Not allowed for TYPE state."); } public IRecordState remove(String key) { throw new RuntimeException("Not allowed for TYPE state."); } }; try { Constructor<M> ctor = cl.getDeclaredConstructor(new Class[] { IRecordState.class }); return ctor.newInstance(new Object[] { nullState }); } catch (Exception e) { // try no-arg ctor try { Constructor<M> ctor = cl.getDeclaredConstructor(ArrayUtils.EMPTY_CLASS_ARRAY); return ctor.newInstance(ArrayUtils.EMPTY_OBJECT_ARRAY); } catch (Exception e2) { throw new RuntimeException(e); } } }
From source file:org.polymap.kaps.importer.AnnotatedCompositeImporter.java
public void fillEntity(Composite composite, Map<String, Object> row) { for (Map.Entry<String, Object> rowEntry : row.entrySet()) { String propName = nameMap.get(rowEntry.getKey()); if (propName != null && rowEntry.getValue() != null) { try { Method m = type.getDeclaredMethod(propName, ArrayUtils.EMPTY_CLASS_ARRAY); Property p = (Property) m.invoke(composite, ArrayUtils.EMPTY_OBJECT_ARRAY); // String if (String.class.equals(p.type())) { p.set(rowEntry.getValue().toString()); }//from w w w .ja v a 2s .c o m // Integer else if (Integer.class.equals(p.type())) { p.set(((Number) rowEntry.getValue()).intValue()); } // Long else if (Long.class.equals(p.type())) { p.set(((Number) rowEntry.getValue()).longValue()); } // Float else if (Float.class.equals(p.type())) { p.set(((Number) rowEntry.getValue()).floatValue()); } // Double else if (Double.class.equals(p.type())) { p.set(((Number) rowEntry.getValue()).doubleValue()); } // Boolean else if (Boolean.class.equals(p.type())) { p.set(rowEntry.getValue()); } // Date else if (java.util.Date.class.equals(p.type())) { p.set(rowEntry.getValue()); } else { throw new RuntimeException("Unhandled property type: " + p.type()); } // log.info( " property: " + p.qualifiedName().name() + " = " // + rowEntry.getValue() ); } catch (Exception e) { throw new RuntimeException("Property: " + propName, e); } } else { // log.info( " skipping column value: " + rowEntry.getKey() ); } } }
From source file:reconf.client.constructors.CollectionConstructor.java
public Object construct(MethodData data) throws Throwable { if (data.hasAdapter()) { return data.getAdapter().adapt(data.getValue()); }/*from ww w.jav a 2 s. com*/ Class<?> returnClass = null; Type innerClass = null; if (data.getReturnType() instanceof ParameterizedType) { ParameterizedType parameterized = (ParameterizedType) data.getReturnType(); returnClass = (Class<?>) parameterized.getRawType(); if (parameterized.getActualTypeArguments()[0] instanceof ParameterizedType) { innerClass = parameterized.getActualTypeArguments()[0]; } else if (parameterized.getActualTypeArguments()[0] instanceof Class<?>) { innerClass = parameterized.getActualTypeArguments()[0]; } } else if (data.getReturnType() instanceof Class) { returnClass = (Class<?>) data.getReturnType(); if (returnClass.getGenericSuperclass() != null && returnClass.getGenericSuperclass() instanceof ParameterizedType) { ParameterizedType parameterized = (ParameterizedType) returnClass.getGenericSuperclass(); if (parameterized.getActualTypeArguments().length != 1) { throw new IllegalArgumentException( msg.format("error.cant.build.type", data.getReturnType(), data.getMethod())); } if (parameterized.getActualTypeArguments()[0] instanceof TypeVariable) { throw new IllegalArgumentException( msg.format("error.cant.build.type", data.getReturnType(), data.getMethod())); } else { innerClass = parameterized.getActualTypeArguments()[0]; } } else { innerClass = Object.class; } } else { throw new IllegalArgumentException(msg.format("error.return", data.getMethod())); } if (returnClass.isInterface()) { returnClass = getDefaultImplementation(data, returnClass); } Constructor<?> constructor = returnClass.getConstructor(ArrayUtils.EMPTY_CLASS_ARRAY); Collection<Object> collectionInstance = (Collection<Object>) constructor .newInstance(ArrayUtils.EMPTY_OBJECT_ARRAY); if (null == data.getValue()) { return collectionInstance; } for (String s : new StringParser(data).getTokens()) { Object o = ObjectConstructorFactory.get(innerClass) .construct(new MethodData(data.getMethod(), innerClass, s)); if (o != null) { collectionInstance.add(o); } } return collectionInstance; }
From source file:reconf.client.constructors.complex.StringParserTest.java
private MethodData methodDataOf(String arg) { try {//from ww w. j a v a 2s .co m return new MethodData(Object.class.getMethod("toString", ArrayUtils.EMPTY_CLASS_ARRAY), String.class, arg); } catch (Exception e) { throw new RuntimeException(e); } }
From source file:reconf.client.constructors.MapConstructor.java
public Object construct(MethodData data) throws Throwable { if (data.hasAdapter()) { return data.getAdapter().adapt(data.getValue()); }//from w w w. j a v a 2 s . c o m Class<?> returnClass = null; Type keyType = null; Type valueType = null; if (data.getReturnType() instanceof ParameterizedType) { ParameterizedType parameterized = (ParameterizedType) data.getReturnType(); returnClass = (Class<?>) parameterized.getRawType(); if (parameterized.getActualTypeArguments().length == 1) { Type first = parameterized.getActualTypeArguments()[0]; if (returnClass.getGenericSuperclass() != null && returnClass.getGenericSuperclass() instanceof ParameterizedType) { parameterized = (ParameterizedType) returnClass.getGenericSuperclass(); if (parameterized.getActualTypeArguments().length != 2) { throw new IllegalArgumentException( msg.format("error.cant.build.type", data.getReturnType(), data.getMethod())); } if (parameterized.getActualTypeArguments()[0] instanceof TypeVariable) { keyType = first; valueType = parameterized.getActualTypeArguments()[1]; } else if (parameterized.getActualTypeArguments()[1] instanceof TypeVariable) { valueType = first; keyType = parameterized.getActualTypeArguments()[0]; } else { throw new IllegalArgumentException( msg.format("error.cant.build.type", data.getReturnType(), data.getMethod())); } } } else { keyType = parameterized.getActualTypeArguments()[0]; valueType = parameterized.getActualTypeArguments()[1]; } } else if (data.getReturnType() instanceof Class) { returnClass = (Class<?>) data.getReturnType(); if (returnClass.getGenericSuperclass() != null && returnClass.getGenericSuperclass() instanceof ParameterizedType) { ParameterizedType parameterized = (ParameterizedType) returnClass.getGenericSuperclass(); if (parameterized.getActualTypeArguments().length != 2) { throw new IllegalArgumentException( msg.format("error.cant.build.type", data.getReturnType(), data.getMethod())); } keyType = parameterized.getActualTypeArguments()[0]; valueType = parameterized.getActualTypeArguments()[1]; } else { keyType = Object.class; valueType = Object.class; } } else { throw new IllegalArgumentException(msg.format("error.return", data.getMethod())); } if (returnClass.isInterface()) { returnClass = getDefaultImplementation(data, returnClass); } Constructor<?> constructor = returnClass.getConstructor(ArrayUtils.EMPTY_CLASS_ARRAY); Map<Object, Object> mapInstance = (Map<Object, Object>) constructor .newInstance(ArrayUtils.EMPTY_OBJECT_ARRAY); if (null == data.getValue() || StringUtils.isEmpty(data.getValue())) { return mapInstance; } if ((!(keyType instanceof Class)) || (!StringUtils.startsWith(data.getValue(), "[") || !StringUtils.endsWith(data.getValue(), "]"))) { throw new IllegalArgumentException(msg.format("error.build", data.getValue(), data.getMethod())); } StringParser parser = new StringParser(data); for (Entry<String, String> each : parser.getTokensAsMap().entrySet()) { Object value = ObjectConstructorFactory.get(valueType) .construct(new MethodData(data.getMethod(), valueType, each.getValue())); mapInstance.put(ObjectConstructorFactory.get(keyType) .construct(new MethodData(data.getMethod(), keyType, each.getKey())), value); } return mapInstance; }
From source file:reconf.client.proxy.MethodConfiguration.java
private ConfigurationAdapter getRemoteAdapter() { if (null == remoteItem || remoteItem.getAdapter() == null) { return null; }/*from www . j av a 2 s . c o m*/ try { Constructor<? extends ConfigurationAdapter> constructor = remoteItem.getAdapter() .getConstructor(ArrayUtils.EMPTY_CLASS_ARRAY); return constructor.newInstance(ArrayUtils.EMPTY_OBJECT_ARRAY); } catch (Throwable t) { throw new IllegalArgumentException(msg.get("error.adapter"), t); } }