
net.sf.eBus.messages.EStringInfo Maven / Gradle / Ivy
//
// Copyright 2019, 2023 Charles W. Rapp
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
package net.sf.eBus.messages;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.nio.charset.Charset;
import net.sf.eBus.messages.type.DataType;
/**
* This field-level, run-time annotation is used to defines
* two attributes:
*
* -
* {@code charset}: defines {@link Charset}
* used to serialize/de-serialize associated {@code String}
* field. If this attribute is not defined for a
* {@code String} type, then {@link DataType#DEFAULT_CHARSET}
* is used.
*
* -
* {@code lineCount}: defines number of line separators
* expected (but not required) in {@code String}
* value. This value
* defaults to one if not specified. The message string does
* not necessarily need to match this line count expect by an
* application to enforce message correctness. This attribute
* may be used in a GUI application to decide whether to use
* a JavaFX {@code TextField} to input a single line string
* or a {@code TextArea} for a multi-line string. If
* multi-line then the line count may be used to define a
* {@code TextArea} size.
*
* -
* {@code maximumAllowedSize}: defines maximum allowed
* serialized string length. This attribute is used when
* serializing text fields to determine if there is a buffer
* overflow.
*
*
*
*
* Supported Field Types and Default Settings
*
*
* Field Type
* Default Value
*
*
*
*
* {@link java.lang.Class Class}
* {@link net.sf.eBus.messages.type.DataType#MAX_CLASS_NAME_LENGTH MAX_CLASS_NAME_LENGTH}
*
*
* {@link java.io.File File}
* {@link net.sf.eBus.messages.type.DataType#MAX_FILE_NAME_LENGTH MAX_FILE_NAME_LENGTH}
*
*
* {@link java.lang.String String}
* {@link net.sf.eBus.messages.type.DataType#MAX_STRING_LENGTH MAX_STRING_LENGTH}
*
*
* {@link java.net.URI URI}
* {@link net.sf.eBus.messages.type.DataType#MAX_STRING_LENGTH MAX_STRING_LENGTH}
*
*
* {@link java.time.ZoneId ZoneId}
* {@link net.sf.eBus.messages.type.DataType#MAX_ZONE_ID_LENGTH MAX_ZONE_ID_LENGTH}
*
*
*
*
* This annotation is ignored if applied to all other data types.
*
*
* @author Charles W. Rapp
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
@Documented
public @interface EStringInfo
{
/**
* Returns the name of the character set used to
* serialize/de-serialize the {@code String} field. This
* name must satisfy {@link Charset#forName(String)} and
* return a character set instance. If this does not happen,
* then
* {@link net.sf.eBus.messages.type.DataType#DEFAULT_CHARSET}
* is used.
* @return character set name.
*/
String charset() default "UTF-8";
/**
* Returns the expected number of lines in this message text
* field. If not specified, then defaults to one.
* @return text field line expected line count.
*/
int lineCount() default 1;
/**
* Returns string's maximum allowed size in bytes. If
* encoded string exceeds this size, then serialization
* results in a {@code BufferOverflowException}.
*
* This attribute is ignored for all other field types.
* Defaults to value < zero which means that default field
* size is used.
*
* @return maximum allowed field size.
*/
int maximumAllowedSize() default -1;
} // end of annotation EStringInfo
© 2015 - 2025 Weber Informatics LLC | Privacy Policy