/** * {@inheritDoc} * * @see org.teiid.designer.core.properties.PropertyDefinition#isValidValue(java.lang.String) */ @Override public String isValidValue(String newValue) { // if empty must have a value or a default value if required if (StringUtilities.isEmpty(newValue)) { // invalid if required and no default value if (isRequired() && StringUtilities.isEmpty(getDefaultValue())) { return Util.getString("invalidNullPropertyValue", getDisplayName()); // $NON-NLS-1$ } // OK to be null/empty return null; } if (Boolean.class.getName().equals(this.className) || Boolean.TYPE.getName().equals(this.className)) { if (!newValue.equalsIgnoreCase(Boolean.TRUE.toString()) && !newValue.equalsIgnoreCase(Boolean.FALSE.toString())) { return Util.getString( "invalidPropertyValueForType", newValue, Boolean.TYPE.getName()); // $NON-NLS-1$ } } else if (Character.class.getName().equals(this.className) || Character.TYPE.getName().equals(this.className)) { if (newValue.length() != 1) { return Util.getString( "invalidPropertyValueForType", newValue, Character.TYPE.getName()); // $NON-NLS-1$ } } else if (Byte.class.getName().equals(this.className) || Byte.TYPE.getName().equals(this.className)) { try { Byte.parseByte(newValue); } catch (Exception e) { return Util.getString( "invalidPropertyValueForType", newValue, Byte.TYPE.getName()); // $NON-NLS-1$ } } else if (Short.class.getName().equals(this.className) || Short.TYPE.getName().equals(this.className)) { try { Short.parseShort(newValue); } catch (Exception e) { return Util.getString( "invalidPropertyValueForType", newValue, Short.TYPE.getName()); // $NON-NLS-1$ } } else if (Integer.class.getName().equals(this.className) || Integer.TYPE.getName().equals(this.className)) { try { Integer.parseInt(newValue); } catch (Exception e) { return Util.getString( "invalidPropertyValueForType", newValue, Integer.TYPE.getName()); // $NON-NLS-1$ } } else if (Long.class.getName().equals(this.className) || Long.TYPE.getName().equals(this.className)) { try { Long.parseLong(newValue); } catch (Exception e) { return Util.getString( "invalidPropertyValueForType", newValue, Long.TYPE.getName()); // $NON-NLS-1$ } } else if (Float.class.getName().equals(this.className) || Float.TYPE.getName().equals(this.className)) { try { Float.parseFloat(newValue); } catch (Exception e) { return Util.getString( "invalidPropertyValueForType", newValue, Float.TYPE.getName()); // $NON-NLS-1$ } } else if (Double.class.getName().equals(this.className) || Double.TYPE.getName().equals(this.className)) { try { Double.parseDouble(newValue); } catch (Exception e) { return Util.getString( "invalidPropertyValueForType", newValue, Double.TYPE.getName()); // $NON-NLS-1$ } } else if (!String.class.getName().equals(this.className)) { return Util.getString( "unknownPropertyType", this.displayName, this.className); // $NON-NLS-1$ } // valid value return null; }
/** * {@inheritDoc} * * @see * org.teiid.designer.vdb.connections.SourceHandler#getTranslatorDefinitions(java.lang.String) */ @Override public PropertyDefinition[] getTranslatorDefinitions(String translatorName) { if (StringUtilities.isEmpty(translatorName)) { throw new IllegalArgumentException(); } Server defaultServer = getDefaultServer(); if ((defaultServer != null) && defaultServer.isConnected()) { try { TeiidTranslator translator = defaultServer.getAdmin().getTranslator(translatorName); if (translator != null) { Collection<PropertyDefinition> props = new ArrayList<PropertyDefinition>(); for (org.teiid.adminapi.PropertyDefinition propDefn : translator.getPropertyDefinitions()) { TranslatorProperty prop = new TranslatorProperty(propDefn.getPropertyTypeClassName()); prop.advanced = propDefn.isAdvanced(); prop.description = propDefn.getDescription(); prop.displayName = propDefn.getDisplayName(); prop.id = propDefn.getName(); prop.masked = propDefn.isMasked(); prop.modifiable = propDefn.isModifiable(); prop.required = propDefn.isRequired(); prop.defaultValue = (propDefn.getDefaultValue() == null) ? StringUtilities.EMPTY_STRING : propDefn.getDefaultValue().toString(); if (propDefn.isConstrainedToAllowedValues()) { Collection values = propDefn.getAllowedValues(); prop.allowedValues = new String[values.size()]; int i = 0; for (Object value : values) { prop.allowedValues[i++] = value.toString(); } } else { // if boolean type turn into allowed values String type = propDefn.getPropertyTypeClassName(); if (Boolean.class.getName().equals(type) || Boolean.TYPE.getName().equals(type)) { prop.allowedValues = new String[] {Boolean.TRUE.toString(), Boolean.FALSE.toString()}; } } props.add(prop); } return props.toArray(new PropertyDefinition[props.size()]); } } catch (Exception e) { UTIL.log( IStatus.ERROR, e, UTIL.getString( "VdbSourceConnectionHandler.errorObtainingTranslatorProperties", //$NON-NLS-1$ translatorName, defaultServer.getHost())); } } return null; }