/** * Returns the given parameter as an instance of {@code ServiceParameter}. * * @param parameter the parameter (may be {@code null}). * @return the service parameter, or {@code null} if the given argument was null. */ public static ServiceParameter castOrCopy(final ParameterDescriptor<?> parameter) { if (parameter == null || parameter instanceof ServiceParameter) { return (ServiceParameter) parameter; } return new ServiceParameter(parameter); }
/** * Gets the parameter name as an instance of {@code MemberName}. * This method performs the following checks: * * <ul> * <li>If the {@linkplain DefaultParameterDescriptor#getName() primary name} is an instance of {@code MemberName}, * returns that primary name.</li> * <li>Otherwise this method searches for the first {@linkplain DefaultParameterDescriptor#getAlias() alias} * which is an instance of {@code MemberName}. If found, that alias is returned.</li> * <li>If no alias is found, then this method tries to build a member name from the primary name and the * {@linkplain DefaultParameterDescriptor#getValueClass() value class}, using the mapping defined in * {@link org.apache.sis.util.iso.DefaultTypeName} javadoc.</li> * </ul> * * This method can be used as a bridge between the parameter object * defined by ISO 19111 (namely {@code CC_OperationParameter}) and the one * defined by ISO 19115 (namely {@code SV_Parameter}). * * @param parameter the parameter from which to get the name (may be {@code null}). * @return the member name, or {@code null} if none. * * @see org.apache.sis.util.iso.Names#createMemberName(CharSequence, String, CharSequence, Class) * * @since 0.5 */ public static MemberName getMemberName(final ParameterDescriptor<?> parameter) { return ServiceParameter.getMemberName(parameter); }
/** * Invoked by JAXB at marshalling time for getting the actual metadata to write * inside the {@code <srv:SV_Parameter>} XML element. * This is the value or a copy of the value given in argument to the {@code wrap} method. * * @return the metadata to be marshalled. */ @XmlElementRef public ServiceParameter getElement() { return ServiceParameter.castOrCopy(metadata); }
if (that.getUnit() == null && that.getDefaultValue() == null && that.getValueClass() == getValueClass()) return Objects.equals(toString(getName()), toString(that.getName())); return that.getMinimumOccurs() == getMinimumOccurs() && that.getMaximumOccurs() == getMaximumOccurs() && that.getValidValues() == null && that.getMinimumValue() == null &&
/** * Tests {@link ServiceParameter#getName()}. */ @Test public void testGetName() { final ServiceParameter param = create(); assertEquals("name", "Version", String.valueOf(param.getName())); assertEquals("valueClass", String.class, param.getValueClass()); }
/** * Tests {@link ServiceParameter#getValueType()} and {@link ServiceParameter#getValueClass()}. */ @Test public void testGetValueType() { final ServiceParameter param = create(); assertEquals("valueType", "OGC:CharacterString", param.getValueType().toFullyQualifiedName().toString()); assertEquals("valueClass", String.class, param.getValueClass()); }
/** * Tests {@link ServiceParameter#getOptionalityLabel()} and {@link ServiceParameter#setOptionalityLabel(String)}. */ @Test public void testOptionalityLabel() { final ServiceParameter param = create(); assertEquals("Optional", param.getOptionalityLabel()); param.optionality = false; assertEquals("Mandatory", param.getOptionalityLabel()); param.setOptionalityLabel("Optional"); assertTrue(param.optionality); param.setOptionalityLabel("Mandatory"); assertFalse(param.optionality); }
/** * Sets the value from the {@code <gco:aName>} (legacy ISO 19139:2007 format). * This method is called at unmarshalling-time by JAXB. * * @param value the new name. * @throws IllegalStateException if a name is already defined. */ @SuppressWarnings("unused") private void setLegacyName(final DefaultMemberName value) { ensureUndefined(); memberName = value; }
if (that.getUnit() == null && that.getDefaultValue() == null && that.getValueClass() == getValueClass()) return Objects.equals(toString(getName()), toString(that.getName())); return that.getMinimumOccurs() == getMinimumOccurs() && that.getMaximumOccurs() == getMaximumOccurs() && that.getValidValues() == null && that.getMinimumValue() == null &&
/** * Gets the parameter name as an instance of {@code MemberName}. * This method performs the following checks: * * <ul> * <li>If the {@linkplain DefaultParameterDescriptor#getName() primary name} is an instance of {@code MemberName}, * returns that primary name.</li> * <li>Otherwise this method searches for the first {@linkplain DefaultParameterDescriptor#getAlias() alias} * which is an instance of {@code MemberName}. If found, that alias is returned.</li> * <li>If no alias is found, then this method tries to build a member name from the primary name and the * {@linkplain DefaultParameterDescriptor#getValueClass() value class}, using the mapping defined in * {@link org.apache.sis.util.iso.DefaultTypeName} javadoc.</li> * </ul> * * This method can be used as a bridge between the parameter object * defined by ISO 19111 (namely {@code CC_OperationParameter}) and the one * defined by ISO 19115 (namely {@code SV_Parameter}). * * @param parameter the parameter from which to get the name (may be {@code null}). * @return the member name, or {@code null} if none. * * @see org.apache.sis.util.iso.Names#createMemberName(CharSequence, String, CharSequence, Class) * * @since 0.5 */ public static MemberName getMemberName(final ParameterDescriptor<?> parameter) { return ServiceParameter.getMemberName(parameter); }
/** * Returns the given parameter as an instance of {@code ServiceParameter}. * * @param parameter the parameter (may be {@code null}). * @return the service parameter, or {@code null} if the given argument was null. */ public static ServiceParameter castOrCopy(final ParameterDescriptor<?> parameter) { if (parameter == null || parameter instanceof ServiceParameter) { return (ServiceParameter) parameter; } return new ServiceParameter(parameter); }
/** * Invoked by JAXB at marshalling time for getting the actual metadata to write * inside the {@code <srv:SV_Parameter>} XML element. * This is the value or a copy of the value given in argument to the {@code wrap} method. * * @return the metadata to be marshalled. */ @XmlElementRef public ServiceParameter getElement() { return ServiceParameter.castOrCopy(metadata); }
/** * Creates a parameter initialized to the values of the given one. */ private ServiceParameter(final ParameterDescriptor<?> parameter) { super(parameter); memberName = getMemberName(parameter); optionality = parameter.getMinimumOccurs() > 0; repeatability = parameter.getMaximumOccurs() > 1; }
/** * Creates the parameter to use for testing purpose. * * @return the test parameter. */ public static ServiceParameter create() { final MemberName paramName = Names.createMemberName(null, null, "Version", String.class); final ServiceParameter param = new ServiceParameter(); param.memberName = paramName; param.optionality = true; param.repeatability = false; return param; }
/** * Creates a parameter initialized to the values of the given one. */ private ServiceParameter(final ParameterDescriptor<?> parameter) { super(parameter); memberName = getMemberName(parameter); optionality = parameter.getMinimumOccurs() > 0; repeatability = parameter.getMaximumOccurs() > 1; }
/** * Tests marshalling of an almost empty parameter (except for default mandatory values). * The main purpose is to ensure that the XML does not contains spurious elements like * empty enumeration wrapper. For testing a complete marshalling, * see {@link org.apache.sis.metadata.iso.identification.DefaultServiceIdentificationTest}. * * @throws JAXBException if an error occurred during marshalling. */ @Test public void testMarshalEmpty() throws JAXBException { final String xml = marshal(new ServiceParameter()); assertXmlEquals( "<srv:SV_Parameter xmlns:srv=\"" + Namespaces.SRV + '"' + " xmlns:gco=\"" + Namespaces.GCO + "\">\n" + " <srv:optionality>\n" + " <gco:Boolean>false</gco:Boolean>\n" + " </srv:optionality>\n" + " <srv:repeatability>\n" + " <gco:Boolean>false</gco:Boolean>\n" + " </srv:repeatability>\n" + "</srv:SV_Parameter>\n", xml, "xmlns:*"); } }