All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.sf.eBusx.monitor.ApplicationInfo Maven / Gradle / Ivy

//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later
// version.
//
// This library is distributed in the hope that it will be
// useful, but WITHOUT ANY WARRANTY; without even the implied
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
// PURPOSE. See the GNU Lesser General Public License for more
// details.
//
// You should have received a copy of the GNU Lesser General
// Public License along with this library; if not, write to the
//
// Free Software Foundation, Inc.,
// 59 Temple Place, Suite 330,
// Boston, MA
// 02111-1307 USA
//
// The Initial Developer of the Original Code is Charles W. Rapp.
// Portions created by Charles W. Rapp are
// Copyright 2012, 2013, 2016, 2019, 2020. Charles W. Rapp
// All Rights Reserved.
//

package net.sf.eBusx.monitor;

import com.google.common.base.Strings;
import java.io.Serializable;
import java.util.Formatter;
import net.sf.eBus.messages.EField;
import net.sf.eBus.messages.ENotificationMessage;

/**
 * Reports the application information. This includes the
 * application name, version, copyright, description and
 * user-defined attributes. These attributes are defined by
 * creating an {@link EField} sub-class. See the
 * {@code net.sf.eBus.messages} package documentation for more
 * information about sub-classing {@code EField}.
 * 

* In order to receive this message, subscribe to: * {@code net.sf.eBusx.monitor.ApplicationInfo}:{@link Monitor#MONITOR_UPDATE_SUBJECT}. * * @see MonitorUpdate * @see Monitor * * @author Charles Rapp */ public final class ApplicationInfo extends ENotificationMessage implements Serializable { //--------------------------------------------------------------- // Member data. // //----------------------------------------------------------- // Constants. // /** * Serialization version identifier. */ private static final long serialVersionUID = 0x050200L; //----------------------------------------------------------- // Locals. // /** * The application name. */ public final String appName; /** * The application version. */ public final String appVersion; /** * The application copyright information. */ public final String copyright; /** * Optional human-readable description of this application. */ public final String description; /** * The application-specific attributes. */ public final EField attributes; //--------------------------------------------------------------- // Member methods. // //----------------------------------------------------------- // Constructors. // /** * Creates a new ApplicationInfo instance. * @param name application name. May not be {@code null} or * empty. * @param version application version. May not be * {@code null} or empty. * @param copyrt application copyright. May be {@code null} * or empty. * @param desc application description. May be {@code null} * or empty. * @param attr application-specific attributes. May be * {@code null}. * @exception IllegalArgumentException * if either {@code name} or {@code version} is {@code null} * or empty. */ @Deprecated public ApplicationInfo(final String name, final String version, final String copyrt, final String desc, final EField attr) throws IllegalArgumentException { this (Monitor.MONITOR_UPDATE_SUBJECT, System.currentTimeMillis(), name, version, copyrt, desc, attr); } // end of ApplicationInfo(...) /** * Creates a new ApplicationInfo instance from the given * deserialized header and fields. * @param subject the notification subject. * @param timestamp the message timestamp. * @param name application name. * @param version application version. * @param copyrt application copyright. * @param desc application description. * @param attr application-specific attributes. May be * {@code null}. * @throws IllegalArgumentException * if either {@code name} or {@code version} is {@code null} * or empty. */ @Deprecated public ApplicationInfo(final String subject, final long timestamp, final String name, final String version, final String copyrt, final String desc, final EField attr) throws IllegalArgumentException { super (subject, timestamp); if (name == null || name.isEmpty() == true) { throw ( new IllegalArgumentException( "null or empty name")); } else if (version == null || version.isEmpty() == true) { throw ( new IllegalArgumentException( "null or empty version")); } appName = name; appVersion = version; copyright = copyrt; description = desc; attributes = attr; } // end of ApplicationInfo(...) private ApplicationInfo(final Builder builder) { super (builder); this.appName = builder.mAppName; this.appVersion = builder.mAppVersion; this.copyright = builder.mCopyright; this.description = builder.mDescription; this.attributes = builder.mAttributes; } // end of ApplicationInfo(Builder) // // end of Constructors. //----------------------------------------------------------- //----------------------------------------------------------- // Object Method Overrides. // /** * Returns the application information message as text. * @return textual representation of application information. */ @Override public String toString() { final Formatter retval = new Formatter(); retval.format("%s%n app name: %s%n", super.toString(), appName); retval.format(" app version: %s%n", appVersion); retval.format(" copyright: %s%n", copyright); retval.format(" description: %s%n", description); retval.format(" attributes: "); if (attributes == null) { retval.format(" (none)"); } else { retval.format("%n%s", attributes); } return (retval.toString()); } // end of toString() // // end of Object Method Overrides. //----------------------------------------------------------- /** * Returns the {@code ApplicationInfo} message builder. * @return message builder. */ public static Builder builder() { return (new Builder()); } // end of builder() //--------------------------------------------------------------- // Inner classes. // public static final class Builder extends ENotificationMessage.Builder { //----------------------------------------------------------- // Member data. // //------------------------------------------------------- // Locals. // private String mAppName; private String mAppVersion; private String mCopyright; private String mDescription; private EField mAttributes; //----------------------------------------------------------- // Member methods. // //------------------------------------------------------- // Constructors. // private Builder() { super (ApplicationInfo.class); this.subject(Monitor.MONITOR_UPDATE_SUBJECT); } // end of Builder() // // end of Constructors. //------------------------------------------------------- //------------------------------------------------------- // Builder Method Overrides. // @Override protected ApplicationInfo buildImpl() { return (new ApplicationInfo(this)); } // end of buildImpl() @Override protected Validator validate(final Validator problems) { return (super.validate(problems) .requireNotNull(mAppName, "appName") .requireNotNull(mAppVersion, "appVersion")); } // end of validate(Validator) // // end of Builder Method Overrides. //------------------------------------------------------- //------------------------------------------------------- // Set Methods. // public Builder appName(final String name) { if (Strings.isNullOrEmpty(name)) { throw ( new IllegalArgumentException( "name is null or empty")); } mAppName = name; return (this); } // end of appName(String) public Builder appVersion(final String version) { if (Strings.isNullOrEmpty(version)) { throw ( new IllegalArgumentException( "version is null or empty")); } mAppVersion = version; return (this); } // end of appVersion(String) public Builder copyright(final String copyright) { mCopyright = copyright; return (this); } // end of copyright(String) public Builder description(final String description) { mDescription = description; return (this); } // end of description(String) public Builder attributes(final EField attributes) { mAttributes = attributes; return (this); } // end of attributes(EFoield) // // end of Set Methods. //------------------------------------------------------- } // end of class Builder } // end of class ApplicationInfo





© 2015 - 2024 Weber Informatics LLC | Privacy Policy