@Override public Schema getSchema() { SchemaFactory sm = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); try { File sFx = StreamUtil.copyStreamToTempFile(getSchemaInputStream()); Schema schema = sm.newSchema(sFx); return schema; } catch (Exception e) { NeptusLog.pub().warn(ReflectionUtil.getCallerStamp() + e.getMessage()); } return null; }
@SuppressWarnings("unchecked") private <T> PluginProperty extractPluginProperty(Field f, T class1) { NeptusProperty neptusProperty = f.getAnnotation(NeptusProperty.class); Object fieldValue = null; try { fieldValue = f.get(class1); } catch (Exception e) { e.printStackTrace(); return null; } // Name String nameRaw = neptusProperty.name(); String displayName; if (nameRaw == null || nameRaw.length() == 0) { nameRaw = f.getName(); char firstLetter = Character.toUpperCase(nameRaw.charAt(0)); displayName = firstLetter + nameRaw.substring(1); } else { displayName = nameRaw; } // Type Class<?> type = f.getType(); PluginProperty pp = new PluginProperty(nameRaw, type, fieldValue); pp.setValue(fieldValue); // Editable if (neptusProperty.editable() == false) { pp.setEditable(false); } else { pp.setEditable(true); } // Display name // signal the scope is the whole Neptus if (class1.getClass().equals(GeneralPreferences.class)) displayName = "* " + I18n.text(displayName); else displayName = I18n.text(displayName); pp.setDisplayName(displayName); // Category if (neptusProperty.category() != null) { pp.setCategory(I18n.text(neptusProperty.category())); } // Short description Map<String, PluginProperty> hashMap = PluginUtils.getDefaultsValues(class1); StringBuilder description = new StringBuilder(); description.append(I18n.text(neptusProperty.description())); String defaultValue; if (hashMap == null) { // no value! defaultValue = I18n.textf("No default found for class %className", class1.getClass().getSimpleName()); } else { PluginProperty pluginProperty = hashMap.get(f.getName()); if (pluginProperty == null) { // no value! defaultValue = I18n.textf("No default found for field %fieldName", f.getName()); } else { Object defaultPropValue = pluginProperty.getValue(); defaultValue = (defaultPropValue == null ? I18n.text("Absence of value") : ((f.getType().getEnumConstants() != null ? I18n.text(defaultPropValue.toString()) : defaultPropValue.toString()))); } } description.append(" ("); description.append(I18n.text("Default value")); description.append(": "); description.append(defaultValue); description.append(")"); pp.setShortDescription(description.toString()); // Editor class - ATTENTION must be the last or wont work! Class<? extends PropertyEditor> editClass = null; if (neptusProperty.editorClass() != PropertyEditor.class) { editClass = neptusProperty.editorClass(); } if (editClass != null) { pEditorRegistry.registerEditor(pp, editClass); } else { if (ReflectionUtil.hasInterface(f.getType(), PropertyType.class)) { PropertyType pt = (PropertyType) fieldValue; pEditorRegistry.registerEditor(pp, pt.getPropertyEditor()); } if (f.getType().getEnumConstants() != null) { if (fieldValue != null) { pEditorRegistry.registerEditor( pp, new EnumEditor((Class<? extends Enum<?>>) fieldValue.getClass())); } } } return pp; }