Java Code Examples for org.fourthline.cling.model.ModelUtil#isStringConvertibleType()
The following examples show how to use
org.fourthline.cling.model.ModelUtil#isStringConvertibleType() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AnnotationActionBinder.java From TVRemoteIME with GNU General Public License v2.0 | 5 votes |
protected void validateType(StateVariable stateVariable, Class type) throws LocalServiceBindingException { // Validate datatype as good as we can // (for enums and other convertible types, the state variable type should be STRING) Datatype.Default expectedDefaultMapping = ModelUtil.isStringConvertibleType(getStringConvertibleTypes(), type) ? Datatype.Default.STRING : Datatype.Default.getByJavaType(type); log.finer("Expecting '" + stateVariable + "' to match default mapping: " + expectedDefaultMapping); if (expectedDefaultMapping != null && !stateVariable.getTypeDetails().getDatatype().isHandlingJavaType(expectedDefaultMapping.getJavaType())) { // TODO: Consider custom types?! throw new LocalServiceBindingException( "State variable '" + stateVariable + "' datatype can't handle action " + "argument's Java type (change one): " + expectedDefaultMapping.getJavaType() ); } else if (expectedDefaultMapping == null && stateVariable.getTypeDetails().getDatatype().getBuiltin() != null) { throw new LocalServiceBindingException( "State variable '" + stateVariable + "' should be custom datatype " + "(action argument type is unknown Java type): " + type.getSimpleName() ); } log.finer("State variable matches required argument datatype (or can't be validated because it is custom)"); }
Example 2
Source File: AnnotationActionBinder.java From DroidDLNA with GNU General Public License v3.0 | 5 votes |
protected void validateType(StateVariable stateVariable, Class type) throws LocalServiceBindingException { // Validate datatype as good as we can // (for enums and other convertible types, the state variable type should be STRING) Datatype.Default expectedDefaultMapping = ModelUtil.isStringConvertibleType(getStringConvertibleTypes(), type) ? Datatype.Default.STRING : Datatype.Default.getByJavaType(type); log.finer("Expecting '" + stateVariable + "' to match default mapping: " + expectedDefaultMapping); if (expectedDefaultMapping != null && !stateVariable.getTypeDetails().getDatatype().isHandlingJavaType(expectedDefaultMapping.getJavaType())) { // TODO: Consider custom types?! throw new LocalServiceBindingException( "State variable '" + stateVariable + "' datatype can't handle action " + "argument's Java type (change one): " + expectedDefaultMapping.getJavaType() ); } else if (expectedDefaultMapping == null && stateVariable.getTypeDetails().getDatatype().getBuiltin() != null) { throw new LocalServiceBindingException( "State variable '" + stateVariable + "' should be custom datatype " + "(action argument type is unknown Java type): " + type.getSimpleName() ); } log.finer("State variable matches required argument datatype (or can't be validated because it is custom)"); }
Example 3
Source File: AnnotationStateVariableBinder.java From TVRemoteIME with GNU General Public License v2.0 | 4 votes |
protected Datatype createDatatype() throws LocalServiceBindingException { String declaredDatatype = getAnnotation().datatype(); if (declaredDatatype.length() == 0 && getAccessor() != null) { Class returnType = getAccessor().getReturnType(); log.finer("Using accessor return type as state variable type: " + returnType); if (ModelUtil.isStringConvertibleType(getStringConvertibleTypes(), returnType)) { // Enums and toString() convertible types are always state variables with type STRING log.finer("Return type is string-convertible, using string datatype"); return Datatype.Default.STRING.getBuiltinType().getDatatype(); } else { Datatype.Default defaultDatatype = Datatype.Default.getByJavaType(returnType); if (defaultDatatype != null) { log.finer("Return type has default UPnP datatype: " + defaultDatatype); return defaultDatatype.getBuiltinType().getDatatype(); } } } // We can also guess that if the allowed values are set then it's a string if ((declaredDatatype == null || declaredDatatype.length() == 0) && (getAnnotation().allowedValues().length > 0 || getAnnotation().allowedValuesEnum() != void.class)) { log.finer("State variable has restricted allowed values, hence using 'string' datatype"); declaredDatatype = "string"; } // If we still don't have it, there is nothing more we can do if (declaredDatatype == null || declaredDatatype.length() == 0) { throw new LocalServiceBindingException("Could not detect datatype of state variable: " + getName()); } log.finer("Trying to find built-in UPnP datatype for detected name: " + declaredDatatype); // Now try to find the actual UPnP datatype by mapping the Default to Builtin Datatype.Builtin builtin = Datatype.Builtin.getByDescriptorName(declaredDatatype); if (builtin != null) { log.finer("Found built-in UPnP datatype: " + builtin); return builtin.getDatatype(); } else { // TODO throw new LocalServiceBindingException("No built-in UPnP datatype found, using CustomDataType (TODO: NOT IMPLEMENTED)"); } }
Example 4
Source File: LocalService.java From TVRemoteIME with GNU General Public License v2.0 | 4 votes |
public boolean isStringConvertibleType(Class clazz) { return ModelUtil.isStringConvertibleType(getStringConvertibleTypes(), clazz); }
Example 5
Source File: AnnotationStateVariableBinder.java From DroidDLNA with GNU General Public License v3.0 | 4 votes |
protected Datatype createDatatype() throws LocalServiceBindingException { String declaredDatatype = getAnnotation().datatype(); if (declaredDatatype.length() == 0 && getAccessor() != null) { Class returnType = getAccessor().getReturnType(); log.finer("Using accessor return type as state variable type: " + returnType); if (ModelUtil.isStringConvertibleType(getStringConvertibleTypes(), returnType)) { // Enums and toString() convertible types are always state variables with type STRING log.finer("Return type is string-convertible, using string datatype"); return Datatype.Default.STRING.getBuiltinType().getDatatype(); } else { Datatype.Default defaultDatatype = Datatype.Default.getByJavaType(returnType); if (defaultDatatype != null) { log.finer("Return type has default UPnP datatype: " + defaultDatatype); return defaultDatatype.getBuiltinType().getDatatype(); } } } // We can also guess that if the allowed values are set then it's a string if ((declaredDatatype == null || declaredDatatype.length() == 0) && (getAnnotation().allowedValues().length > 0 || getAnnotation().allowedValuesEnum() != void.class)) { log.finer("State variable has restricted allowed values, hence using 'string' datatype"); declaredDatatype = "string"; } // If we still don't have it, there is nothing more we can do if (declaredDatatype == null || declaredDatatype.length() == 0) { throw new LocalServiceBindingException("Could not detect datatype of state variable: " + getName()); } log.finer("Trying to find built-in UPnP datatype for detected name: " + declaredDatatype); // Now try to find the actual UPnP datatype by mapping the Default to Builtin Datatype.Builtin builtin = Datatype.Builtin.getByDescriptorName(declaredDatatype); if (builtin != null) { log.finer("Found built-in UPnP datatype: " + builtin); return builtin.getDatatype(); } else { // TODO throw new LocalServiceBindingException("No built-in UPnP datatype found, using CustomDataType (TODO: NOT IMPLEMENTED)"); } }
Example 6
Source File: LocalService.java From DroidDLNA with GNU General Public License v3.0 | 4 votes |
public boolean isStringConvertibleType(Class clazz) { return ModelUtil.isStringConvertibleType(getStringConvertibleTypes(), clazz); }