/** * Parm gui string. * * @param parm the parm * @return the string */ protected String parmGuiString(ConfigurationParameter parm) { return ((parm.isMultiValued()) ? MULTI_VALUE_INDICATOR : SINGLE_VALUE_INDICATOR) + ((parm.isMandatory()) ? REQUIRED_INDICATOR : OPTIONAL_INDICATOR) + typeNamesW.get(parm.getType()) + ((parm.getExternalOverrideName()==null) ? NO_EXTERNAL_OVERRIDE_INDICATOR : EXTERNAL_OVERRIDE_INDICATOR) + nameHeader + parm.getName(); }
/** * Fills in the model Configuration Parm from the Add/Edit dialog. called from * addNewConfigurationParameter, and alterExistingConfigurationParameter * * @param dialog the dialog * @param existingCP the existing CP */ private void fillModelParm(AddParameterDialog dialog, ConfigurationParameter existingCP) { valueChanged = false; existingCP.setName(setValueChanged(dialog.parmName, existingCP.getName())); existingCP.setDescription(setValueChanged(multiLineFix(dialog.description), existingCP .getDescription())); existingCP.setMandatory(setValueChangedBoolean(dialog.mandatory, existingCP.isMandatory())); existingCP .setMultiValued(setValueChangedBoolean(dialog.multiValue, existingCP.isMultiValued())); existingCP.setType(setValueChanged(dialog.parmType, existingCP.getType())); existingCP.setExternalOverrideName(setValueChanged(dialog.extParmName, existingCP.getExternalOverrideName())); if (valueChanged) setFileDirty(); }
/** * Parm spec matches. * * @param p the p * @param q the q * @return true, if successful */ private boolean parmSpecMatches(ConfigurationParameter p, ConfigurationParameter q) { if (!p.getType().equals(q.getType())) return false; if (p.isMandatory() != q.isMandatory()) return false; if (p.isMultiValued() != q.isMultiValued()) return false; return true; }
/** * Gets the overriding parm name. * * @param override the override * @param cps the cps * @return the overriding parm name */ private static String getOverridingParmName(String override, ConfigurationParameter[] cps) { if (null != cps) for (int i = 0; i < cps.length; i++) { String[] overrides = cps[i].getOverrides(); if (null != overrides) for (int j = 0; j < overrides.length; j++) { if (override.equals(overrides[j])) return cps[i].getName(); } } return null; }
boolean isMultiValued = cp.isMultiValued(); String type = cp.getType(); if ((isMultiValued != parms[i].isMultiValued())) continue; !type.equals(parms[i].getType()))) continue; String override = keyName + '/' + parms[i].getName(); if (adding && null != ParameterDelegatesSection.getOverridingParmName(override, cg)) continue; tableItem.setText(parms[i].getName()); tableItem.setData(parms[i]);
/** * Alter existing configuration parameter. * * @param dialog the dialog * @param existingTreeItem the existing tree item */ private void alterExistingConfigurationParameter(AddParameterDialog dialog, TreeItem existingTreeItem) { ConfigurationParameter existingCP = getCorrespondingModelParm(existingTreeItem); ConfigurationParameter previousCP = existingCP; previousCP = (ConfigurationParameter) previousCP.clone(); fillModelParm(dialog, existingCP); fillParmItem(existingTreeItem, existingCP); // the following may have changed in an existing param spec, that could // affect the setting: // 1) the name, 2) the type, 3) the multi-value aspect // Description or mandatory changes have no effect on the settings // If the multi-value aspect changes, drop all the settings // If the type changes, drop all the settings // If the name changes, change existing settings for that parm name in all groups if ((!previousCP.getType().equals(existingCP.getType())) || (previousCP.isMultiValued() != existingCP.isMultiValued())) { removeParmSettingFromMultipleGroups(existingTreeItem, !REMOVE_FROM_GUI); } commonParmUpdate(existingTreeItem, existingCP, previousCP.getName()); }
protected ConfigurationParameter _getConfigurationParameter(ConfigurationParameter[] aParams, String aName) { if (aParams != null) { for (int i = 0; i < aParams.length; i++) { if (aName.equals(aParams[i].getName())) return aParams[i]; } } return null; }
String paramType = aParam.getType(); if (aParam.isMultiValued()) { if (ConfigurationParameter.TYPE_STRING.equals(paramType)) { return String[].class;
private static void addParamValue(String[] nvp, ConfigurationParameter parameter, ConfigurationParameterSettings aggregateSettings) { Object value = nvp[1]; // default is String value if (parameter != null) { if (parameter.getType().equals("Integer")) { value = Integer.parseInt(nvp[1]); } else if (parameter.getType().equals("Boolean")) { value = Boolean.parseBoolean(nvp[1]); } else if (parameter.getType().equals("Float")) { value = Float.parseFloat(nvp[1]); } aggregateSettings.setParameterValue(nvp[0], value); } else { aggregateSettings.setParameterValue(nvp[0], value); } }
ConfigurationParameterDeclarations aggregateDeclarations) { ConfigurationParameter cfgParam = new ConfigurationParameter_impl(); cfgParam.setName(nvp[0]); if (parameter == null) { // component descriptor doesnt contain a cfgParam.setType("String"); // create String param as default } else { cfgParam.setType(parameter.getType()); cfgParam.addOverride(key + "/" + nvp[0]); aggregateDeclarations.addConfigurationParameter(cfgParam);
/** * A factory method for creating a ConfigurationParameter object. * * @param name * the parameter name * @param parameterType * the parameter type * @param parameterDescription * the parameter description * @param isMultiValued * whether the parameter is multi-valued * @param isMandatory * whether the parameter is mandatory * @return the configuration parameter */ public static ConfigurationParameter createPrimitiveParameter(String name, String parameterType, String parameterDescription, boolean isMultiValued, boolean isMandatory) { ConfigurationParameter param = new ConfigurationParameter_impl(); param.setName(name); param.setType(parameterType); param.setDescription(parameterDescription); param.setMultiValued(isMultiValued); param.setMandatory(isMandatory); return param; }
for (int i = 0; i < configurationParameters.length; i++) { ConfigurationParameter decl = paramDecls.getConfigurationParameter(null, configurationParameters[i].getName()); if (paramDecls != null && decl == null) { paramDecls.addConfigurationParameter(configurationParameters[i]); if ((value != null) && decl.isMultiValued() && !isMultiValue(value)) { value = Array.newInstance(value.getClass(), 1); Array.set(value, 0, configurationValues[i]); paramSettings.setParameterValue(configurationParameters[i].getName(), value);
for (int i = 0; i < aParams.length; i++) { Object val = this.getConfigParameterValue(aContext + aParams[i].getName(), aGroupName); if (val == null && aParams[i].isMandatory()) { if (aGroupName != null) { throw new ResourceConfigurationException( ResourceConfigurationException.MANDATORY_VALUE_MISSING_IN_GROUP, new Object[] { aParams[i].getName(), aGroupName, aContext }); } else { throw new ResourceConfigurationException( ResourceConfigurationException.MANDATORY_VALUE_MISSING, new Object[] { aParams[i].getName(), aContext });
/** * Checks parameter overrides and throws a ResourceInitializationException if they are invalid. * Note that since overrides are invalid in primitive components, this default implementation * throws an exception for ANY parameter override it finds. AnalysisEngineDescription_impl * overrides this method to correctly handle parameter overrides in aggregates. * * @param aParams * an array of ConfigurationParameters * @param aGroupName * name of groups in which these parameters are contained. Null if no group * @param aResourceManager used to resolve imports by name. * * @throws ResourceInitializationException * if there is an invalid parameter override declaration */ protected void checkForInvalidParameterOverrides(ConfigurationParameter[] aParams, String aGroupName, ResourceManager aResourceManager) throws ResourceInitializationException { for (int i = 0; i < aParams.length; i++) { String[] overrides = aParams[i].getOverrides(); if (overrides.length > 0) { throw new ResourceInitializationException( ResourceInitializationException.PARAM_OVERRIDE_IN_PRIMITIVE, new Object[] { aParams[i].getName(), getMetaData().getName(), aParams[i].getSourceUrlString() }); } } }
/** * Checks for duplicate parameter names and throws an exception if any are found. * * @param aParams * an array of ConfigurationParameters * * @throws ResourceInitializationException * if there is a duplicate parameter name in the arrays */ protected void checkForDuplicateParameterNames(ConfigurationParameter[] aParams) throws ResourceInitializationException { Set<String> paramNames = new HashSet<String>(); for (int i = 0; i < aParams.length; i++) { if (!paramNames.add(aParams[i].getName())) { throw new ResourceInitializationException( ResourceInitializationException.DUPLICATE_CONFIGURATION_PARAMETER_NAME, new Object[] { aParams[i].getName(), getMetaData().getName(), aParams[i].getSourceUrlString() }); } } }
if (cfgParamDecls.getConfigurationParameter(null, resultParam.getName()) != null) { throw new IllegalArgumentException(String.format( "Parameter with name = '%s' exists already")); String delegateKey = delegateAndItsParam.getKey(); String delegateParamName = delegateAndItsParam.getValue(); resultParam.addOverride(delegateKey + "/" + delegateParamName);
@Override public void enable() { boolean mvValue = (null != selectedCP) && (selectedCP.isMultiValued()); valueText.setVisible((null != selectedCP) && (!selectedCP.isMultiValued())); valueTextCombo.setVisible((null != selectedCP) && (!selectedCP.isMultiValued())); addButton.setEnabled(mvValue); int selected = valueTable.getSelectionIndex(); editButton.setEnabled(mvValue && selected > -1); removeButton.setEnabled(mvValue && selected > -1); upButton.setEnabled(mvValue && selected > 0); downButton.setEnabled(mvValue && (selected > -1) && (selected < (valueTable.getItemCount() - 1))); valueText.getParent().redraw(); }
/** * Validate that a value is of an appropriate data type for assignment to the given parameter. * * @param aParam * configuration parameter * @param aValue * candidate value * @param aContextName * name of context, used to generate error message * * @throws ResourceConfigurationException * if the data types do not match */ private void validateConfigurationParameterDataTypeMatch(ConfigurationParameter aParam, Object aValue, String aContextName) throws ResourceConfigurationException { if (aValue != null) { Class<?> valClass = aValue.getClass(); if (aParam.isMultiValued() && !valClass.isArray()) { throw new ResourceConfigurationException(ResourceConfigurationException.ARRAY_REQUIRED, new Object[] { aParam.getName(), aContextName }); } if (!valClass.equals(getParameterExpectedValueClass(aParam))) { throw new ResourceConfigurationException( ResourceConfigurationException.PARAMETER_TYPE_MISMATCH, new Object[] { aContextName, valClass.getName(), aParam.getName(), aParam.getType() }); } } }
/** * Adds the parm names. * * @param list the list * @param parms the parms */ private void addParmNames(List list, ConfigurationParameter[] parms) { if (null != parms) { for (int i = 0; i < parms.length; i++) { list.add(parms[i].getName()); } } }