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; }
/** * 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()); } } }
/** * Parameter in array. * * @param name the name * @param cps the cps * @return true, if successful */ private static boolean parameterInArray(String name, ConfigurationParameter[] cps) { for (int i = 0; i < cps.length; i++) { if (name.equals(cps[i].getName())) return true; } return false; }
/** * Removes the configuration parameter. * * @param parms the parms * @param nameToRemove the name to remove * @return the configuration parameter[] */ private ConfigurationParameter[] removeConfigurationParameter(ConfigurationParameter[] parms, String nameToRemove) { ConfigurationParameter[] newParms = new ConfigurationParameter[parms.length - 1]; for (int i = 0, j = 0; i < newParms.length; i++, j++) { if (parms[j].getName().equals(nameToRemove)) j++; newParms[i] = parms[j]; } return newParms; }
/** * Gets the same named parm in group. * * @param parm the parm * @param group the group * @return the same named parm in group */ private ConfigurationParameter getSameNamedParmInGroup(ConfigurationParameter parm, ConfigGroup group) { ConfigurationParameter[] cps = group.getConfigParms(); String parmName = parm.getName(); for (int i = 0; i < cps.length; i++) { if (cps[i].getName().equals(parmName)) return cps[i]; } return null; }
/** * 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; }
/** * 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() }); } } }
/** * 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() }); } } }
/** * 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(); }
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]); paramSettings.setParameterValue(configurationParameters[i].getName(), value);
for (int i = 0; i < aParams.length; i++) { ConfigurationParameter param = aParams[i]; String qname = makeQualifiedName(aContextName, param.getName(), aGroupName);
public String[] getConfigParameterNames(String aGroup) { ConfigurationGroup[] groups = getConfigurationManager().getConfigParameterDeclarations( getQualifiedContextName()).getConfigurationGroupDeclarations(aGroup); if (groups.length == 0) { return EMPTY_STRINGS; } else { List<String> names = new ArrayList<String>(); ConfigurationParameter[] commonParams = getConfigurationManager() .getConfigParameterDeclarations(getQualifiedContextName()).getCommonParameters(); if (commonParams != null) { for (int i = 0; i < commonParams.length; i++) { names.add(commonParams[i].getName()); } } for (int i = 0; i < groups.length; i++) { ConfigurationParameter[] groupParams = groups[i].getConfigurationParameters(); for (int j = 0; j < groupParams.length; j++) { names.add(groupParams[j].getName()); } } String[] nameArray = new String[names.size()]; names.toArray(nameArray); return nameArray; } }
protected void validateConfigurationParameterDataTypeMatch( org.apache.uima.resource.metadata.ConfigurationParameter aParam, NameValuePair aNVP ) throws ResourceConfigurationException { String paramName = aParam.getName(); String paramType = aParam.getType(); Class valClass = aNVP.getValue().getClass(); if ( aParam.isMultiValued() ) { if ( !valClass.isArray() ) { throw new ResourceConfigurationException( "array_required", new Object[]{ paramName, this.getName() } ); } valClass = valClass.getComponentType(); if ( Array.getLength( aNVP.getValue() ) == 0 && valClass.equals( Object.class ) ) { aNVP.setValue( Array.newInstance( this.getClassForParameterType( paramType ), 0 ) ); return; } } if ( valClass != this.getClassForParameterType( paramType ) ) { throw new ResourceConfigurationException( "parameter_type_mismatch", new Object[]{ this.getName(), valClass.getName(), paramName, paramType } ); } }
public String[] getConfigParameterNames() { ConfigurationParameter[] params = getConfigurationManager().getConfigParameterDeclarations( getQualifiedContextName()).getConfigurationParameters(); if (params == null) { return EMPTY_STRINGS; } else { String[] names = new String[params.length]; for (int i = 0; i < params.length; i++) { names[i] = params[i].getName(); } return names; } }
/** * Removes the common parm settings from multiple groups. */ public void removeCommonParmSettingsFromMultipleGroups() { ConfigurationParameterSettings modelSettings = getModelSettings(); String[] allGroupNames = getAllGroupNames(); // TreeItem [] items = new TreeItem[0]; // done to avoid may not have been initialized msg // int offset = 0; commonParms = cpd.getCommonParameters(); for (int i = 0; i < allGroupNames.length; i++) { // if (null != settings) { // items = getSettingsGroupTreeItemByName(allGroupNames[i]).getItems(); // offset = items.length - commonParms.length; // } for (int j = 0; j < commonParms.length; j++) { modelSettings.setParameterValue(allGroupNames[i], commonParms[j].getName(), null); } } if (null != settings) { for (int j = 0; j < commonParms.length; j++) { TreeItem[] settingsParms = getSettingsParameter(null, commonParms[j].getName()); for (int k = 0; k < settingsParms.length; k++) { settingsParms[k].dispose(); } } } }
/** * 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() }); } } }
/** * Common parm update. * * @param existingTreeItem the existing tree item * @param existingCP the existing CP * @param prevName the prev name */ private void commonParmUpdate(TreeItem existingTreeItem, ConfigurationParameter existingCP, String prevName) { updateParmInSettingsGUI(existingCP, existingTreeItem, prevName); String newName = existingCP.getName(); if (!newName.equals(prevName)) { // name changed; update the settings model ConfigurationParameterSettings cps = getModelSettings(); String[] allGroupNames = new String[] { null }; if (usingGroupsButton.getSelection()) { allGroupNames = (String[]) Utility .addElementToArray(getAllGroupNames(), null, String.class); } Object value; for (int i = 0; i < allGroupNames.length; i++) { if (null != (value = cps.getParameterValue(allGroupNames[i], prevName))) { cps.setParameterValue(allGroupNames[i], newName, value); cps.setParameterValue(allGroupNames[i], prevName, null); } } } }
/** * 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()); }
/** * 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(); }