public CSSValueList(
      @Nonnull final ECSSProperty eProperty,
      @Nonnull final ICSSProperty[] aProperties,
      @Nonnull final String[] aValues,
      final boolean bIsImportant) {
    ValueEnforcer.notNull(eProperty, "Property");
    ValueEnforcer.notEmptyNoNullValue(aProperties, "Properties");
    ValueEnforcer.notEmptyNoNullValue(aValues, "Values");
    if (aProperties.length != aValues.length)
      throw new IllegalArgumentException("Different number of properties and values passed");

    boolean bFound = false;
    for (final ICSSProperty aProperty : aProperties)
      if (aProperty.getProp() == eProperty) {
        bFound = true;
        break;
      }
    if (!bFound)
      throw new IllegalArgumentException(
          "The property " + eProperty + " is not contained in an ICSSProperty instance!");

    m_eProperty = eProperty;
    m_aValues = new ArrayList<CSSValue>(aProperties.length);
    for (int i = 0; i < aProperties.length; ++i)
      m_aValues.add(new CSSValue(aProperties[i], aValues[i], bIsImportant));
  }
 public DataTablesOrderColumn(
     @Nonnegative final int nIndex, @Nonnull final ESortOrder eSortOrder) {
   ValueEnforcer.isGE0(nIndex, "Index");
   ValueEnforcer.notNull(eSortOrder, "SortOrder");
   m_nIndex = nIndex;
   m_eSortOrder = eSortOrder;
 }
 public ThreadDeadlockInfo(
     @Nonnull final ThreadInfo aThreadInfo,
     @Nonnull final Thread aThread,
     @Nullable final StackTraceElement[] aStackTrace) {
   m_aThreadInfo = ValueEnforcer.notNull(aThreadInfo, "ThreadInfo");
   m_aThread = ValueEnforcer.notNull(aThread, "Thread");
   m_aStackTrace = ArrayHelper.getCopy(aStackTrace);
 }
    void setUser(@Nonnull final LoggedInUserManager aOwningMgr, @Nonnull final IUser aUser) {
      ValueEnforcer.notNull(aOwningMgr, "OwningMgr");
      ValueEnforcer.notNull(aUser, "User");
      if (m_aUser != null) throw new IllegalStateException("Session already has a user!");

      m_aOwningMgr = aOwningMgr;
      m_aUser = aUser;
      m_sUserID = aUser.getID();
    }
  void internalSessionActivateUser(
      @Nonnull final IUser aUser, @Nonnull final ISessionScope aSessionScope) {
    ValueEnforcer.notNull(aUser, "User");
    ValueEnforcer.notNull(aSessionScope, "SessionScope");

    m_aRWLock.writeLock().lock();
    try {
      final LoginInfo aInfo = new LoginInfo(aUser, aSessionScope);
      m_aLoggedInUsers.put(aUser.getID(), aInfo);
    } finally {
      m_aRWLock.writeLock().unlock();
    }
  }
Exemple #6
0
 Favorite(
     @Nonnull @Nonempty final String sID,
     @Nonnull @Nonempty final String sUserID,
     @Nonnull @Nonempty final String sApplicationID,
     @Nonnull @Nonempty final String sMenuItemID,
     @Nonnull @Nonempty final String sDisplayName,
     @Nullable final Map<String, String> aAdditionalParams) {
   m_sID = ValueEnforcer.notEmpty(sID, "ID");
   m_sUserID = ValueEnforcer.notEmpty(sUserID, "User ID");
   m_sMenuItemID = ValueEnforcer.notEmpty(sMenuItemID, "menu item ID");
   m_sApplicationID = ValueEnforcer.notEmpty(sApplicationID, "application ID");
   setDisplayName(sDisplayName);
   m_aAdditionalParams = CollectionHelper.newMap(aAdditionalParams);
 }
  @Nonnull
  @CheckReturnValue
  public SizeDouble getSubtracted(@Nonnull final IHasDimensionDouble aToSubtract) {
    ValueEnforcer.notNull(aToSubtract, "ToSubtract");

    return new SizeDouble(m_dWidth - aToSubtract.getWidth(), m_dHeight - aToSubtract.getHeight());
  }
  /**
   * Return the scaled width and height relative to a maximum size.
   *
   * @param dMaxWidth Maximum width. Must be &gt; 0.
   * @param dMaxHeight Maximum height. Must be &gt; 0.
   * @return An array with 2 elements, where the first element is the width, and the second is the
   *     height.
   */
  @Nonnull
  @CheckReturnValue
  public SizeDouble getBestMatchingSize(
      @Nonnegative final double dMaxWidth, @Nonnegative final double dMaxHeight) {
    ValueEnforcer.isGT0(dMaxWidth, "MaxWidth");
    ValueEnforcer.isGT0(dMaxHeight, "MaxHeight");

    final double dRelWidth = m_dWidth / dMaxWidth;
    final double dRelHeight = m_dHeight / dMaxHeight;
    if (dRelWidth > dRelHeight) {
      if (m_dWidth > dMaxWidth) return new SizeDouble(dMaxWidth, m_dHeight / dRelWidth);
    } else {
      if (m_dHeight > dMaxHeight) return new SizeDouble(m_dWidth / dRelHeight, dMaxHeight);
    }
    return this;
  }
  /**
   * Marks the present position in the stream. Subsequent calls to reset() will reposition the
   * stream to this point.
   *
   * @param nReadAheadLimit Limit on the number of characters that may be read while still
   *     preserving the mark. Because the stream's input comes from a string, there is no actual
   *     limit, so this argument must not be negative, but is otherwise ignored.
   * @exception IllegalArgumentException If readAheadLimit is &lt; 0
   * @exception IOException If an I/O error occurs
   */
  @Override
  public void mark(final int nReadAheadLimit) throws IOException {
    ValueEnforcer.isGE0(nReadAheadLimit, "ReadAheadLimit");

    _ensureOpen();
    m_nMark = m_nNext;
  }
  @Nonnull
  @CheckReturnValue
  public SizeDouble getAdded(@Nonnull final IHasDimensionDouble aToAdd) {
    ValueEnforcer.notNull(aToAdd, "ToAdd");

    return new SizeDouble(m_dWidth + aToAdd.getWidth(), m_dHeight + aToAdd.getHeight());
  }
  /**
   * Get the {@link JAXBContext} from an existing {@link Class} object. If the class's owning
   * package is a valid JAXB package, this method redirects to {@link #getFromCache(Package)}
   * otherwise a new JAXB context is created and NOT cached.
   *
   * @param aClass The class for which the JAXB context is to be created. May not be <code>null
   *     </code>.
   * @param aClassLoader Class loader to use. May be <code>null</code> in which case the default
   *     class loader is used.
   * @return Never <code>null</code>.
   */
  @Nonnull
  public JAXBContext getFromCache(
      @Nonnull final Class<?> aClass, @Nullable final ClassLoader aClassLoader) {
    ValueEnforcer.notNull(aClass, "Class");

    final Package aPackage = aClass.getPackage();
    if (aPackage.getAnnotation(XmlSchema.class) != null) {
      // Redirect to cached version
      return getFromCache(aPackage, aClassLoader);
    }

    // E.g. an internal class - try anyway!
    if (GlobalDebug.isDebugMode())
      s_aLogger.info("Creating JAXB context for class " + aClass.getName());

    if (aClassLoader != null)
      s_aLogger.warn(
          "Package "
              + aPackage.getName()
              + " does not seem to be JAXB generated. Therefore a new JAXBContext is created and the provided ClassLoader is ignored!");

    try {
      return JAXBContext.newInstance(aClass);
    } catch (final JAXBException ex) {
      final String sMsg = "Failed to create JAXB context for class '" + aClass.getName() + "'";
      s_aLogger.error(sMsg + ": " + ex.getMessage());
      throw new IllegalArgumentException(sMsg, ex);
    }
  }
  @Nullable
  public final String getText(@Nonnull final Locale aContentLocale) {
    ValueEnforcer.notNull(aContentLocale, "ContentLocale");

    final Locale aLocaleToUse = internalGetLocaleToUseWithFallback(aContentLocale);
    return aLocaleToUse == null ? null : internalGetText(aLocaleToUse);
  }
  @Nonnull
  @CheckReturnValue
  public SizeDouble getScaledToHeight(@Nonnegative final double dNewHeight) {
    ValueEnforcer.isGT0(dNewHeight, "NewHeight");

    if (m_dHeight == dNewHeight) return this;
    final double dMultFactory = dNewHeight / m_dHeight;
    return new SizeDouble(m_dWidth * dMultFactory, dNewHeight);
  }
  @Nonnull
  @CheckReturnValue
  public SizeDouble getScaledToWidth(@Nonnegative final double dNewWidth) {
    ValueEnforcer.isGT0(dNewWidth, "NewWidth");

    if (m_dWidth == dNewWidth) return this;
    final double dMultFactory = dNewWidth / m_dWidth;
    return new SizeDouble(dNewWidth, m_dHeight * dMultFactory);
  }
Exemple #15
0
  @Nonnull
  public EChange setDisplayName(@Nonnull @Nonempty final String sDisplayName) {
    ValueEnforcer.notEmpty(sDisplayName, "display name");

    if (sDisplayName.equals(m_sDisplayName)) return EChange.UNCHANGED;

    m_sDisplayName = sDisplayName;
    return EChange.CHANGED;
  }
  /**
   * This constructor requires a class name, because in case a class has no instance variables the
   * hash code may be the same for different instances of different classes.
   *
   * @param aClass The class this instance is about to create a hash code for. May not be <code>null
   *     </code>.
   */
  public HashCodeGenerator(@Nonnull final Class<?> aClass) {
    ValueEnforcer.notNull(aClass, "Class");

    // Use the class name
    append(aClass.getName());

    // Is it an array class? If so add the component class name.
    final Class<?> aComponentType = aClass.getComponentType();
    if (aComponentType != null) append(aComponentType.getName());
  }
  /**
   * Applies an RFC 1522 compliant decoding scheme to the given string of text.
   *
   * <p>This method processes the "encoded-word" header common to all the RFC 1522 codecs and then
   * invokes {@link #getDecoded(byte [])} method of a concrete class to perform the specific
   * decoding.
   *
   * @param sEncodedText a string to decode
   * @return A new decoded String or {@code null} if the input is {@code null}.
   * @throws DecodeException thrown if there is an error condition during the decoding process.
   */
  @Nullable
  public String getDecodedText(@Nullable final String sEncodedText) throws DecodeException {
    if (sEncodedText == null) return null;

    ValueEnforcer.isTrue(
        sEncodedText.startsWith(PREFIX),
        "RFC 1522 violation: malformed encoded content. Prefix missing.");
    ValueEnforcer.isTrue(
        sEncodedText.endsWith(POSTFIX),
        "RFC 1522 violation: malformed encoded content. Postfix missing.");

    int nFrom = PREFIX.length();
    final int nTerminator = sEncodedText.length() - POSTFIX.length();

    // Read charset
    int nTo = sEncodedText.indexOf(SEP, nFrom);
    if (nTo == nTerminator)
      throw new DecodeException("RFC 1522 violation: charset token not found");
    final String sDestCharset = sEncodedText.substring(nFrom, nTo);
    if (StringHelper.hasNoText(sDestCharset))
      throw new DecodeException("RFC 1522 violation: charset not specified");
    final Charset aDestCharset = CharsetManager.getCharsetFromNameOrNull(sDestCharset);
    if (aDestCharset == null)
      throw new DecodeException("Failed to resolve charset '" + sDestCharset + "'");

    // Read encoding
    nFrom = nTo + 1;
    nTo = sEncodedText.indexOf(SEP, nFrom);
    if (nTo == nTerminator)
      throw new DecodeException("RFC 1522 violation: encoding token not found");
    final String sEncoding = sEncodedText.substring(nFrom, nTo);
    if (!getRFC1522Encoding().equalsIgnoreCase(sEncoding))
      throw new DecodeException("This codec cannot decode '" + sEncoding + "' encoded content");

    // Read encoded data
    nFrom = nTo + 1;
    nTo = sEncodedText.indexOf(SEP, nFrom);
    final byte[] aEncodedBytes =
        CharsetManager.getAsBytes(
            sEncodedText.substring(nFrom, nTo), CCharset.CHARSET_US_ASCII_OBJ);
    final byte[] aDecodedBytes = getDecoded(aEncodedBytes);
    return CharsetManager.getAsString(aDecodedBytes, aDestCharset);
  }
  public void addPrivateKey(
      @Nonnull @Nonempty final String sAlias,
      @Nonnull final Key aKey,
      @Nonnull final String sPassword)
      throws OpenAS2Exception {
    ValueEnforcer.notEmpty(sAlias, "Alias");
    ValueEnforcer.notNull(aKey, "Key");
    ValueEnforcer.notNull(sPassword, "Password");

    final KeyStore aKeyStore = getKeyStore();
    try {
      if (!aKeyStore.containsAlias(sAlias)) throw new CertificateNotFoundException(null, sAlias);

      final Certificate[] aCertChain = aKeyStore.getCertificateChain(sAlias);
      aKeyStore.setKeyEntry(sAlias, aKey, sPassword.toCharArray(), aCertChain);
      save(getFilename(), getPassword());
    } catch (final GeneralSecurityException ex) {
      throw WrappedOpenAS2Exception.wrap(ex);
    }
  }
  public void removeCertificate(@Nonnull final X509Certificate aCert) throws OpenAS2Exception {
    ValueEnforcer.notNull(aCert, "Cert");
    final KeyStore aKeyStore = getKeyStore();

    try {
      final String sAlias = aKeyStore.getCertificateAlias(aCert);
      if (sAlias == null) throw new CertificateNotFoundException(aCert);
      removeCertificate(sAlias);
    } catch (final GeneralSecurityException ex) {
      throw WrappedOpenAS2Exception.wrap(ex);
    }
  }
  public void addCertificate(
      @Nonnull @Nonempty final String sAlias,
      @Nonnull final X509Certificate aCert,
      final boolean bOverwrite)
      throws OpenAS2Exception {
    ValueEnforcer.notEmpty(sAlias, "Alias");
    ValueEnforcer.notNull(aCert, "Cert");

    final KeyStore aKeyStore = getKeyStore();

    try {
      if (aKeyStore.containsAlias(sAlias) && !bOverwrite)
        throw new CertificateExistsException(sAlias);

      aKeyStore.setCertificateEntry(sAlias, aCert);
      save(getFilename(), getPassword());
      s_aLogger.info(
          "Added certificate alias '" + sAlias + "' of certificate '" + aCert.getSubjectDN());
    } catch (final GeneralSecurityException ex) {
      throw WrappedOpenAS2Exception.wrap(ex);
    }
  }
  @Override
  @Nonnull
  public String getAlias(
      @Nonnull final Partnership aPartnership,
      @Nonnull final ECertificatePartnershipType ePartnershipType)
      throws OpenAS2Exception {
    ValueEnforcer.notNull(aPartnership, "Partnership");
    ValueEnforcer.notNull(ePartnershipType, "PartnershipType");

    String sAlias = null;
    switch (ePartnershipType) {
      case RECEIVER:
        sAlias = aPartnership.getReceiverX509Alias();
        break;
      case SENDER:
        sAlias = aPartnership.getSenderX509Alias();
        break;
    }

    if (sAlias == null) throw new CertificateNotFoundException(ePartnershipType, aPartnership);
    return sAlias;
  }
Exemple #22
0
  /**
   * Constructs {@link CSVReader} with supplied {@link CSVParser}.
   *
   * @param aReader the reader to an underlying CSV source.
   * @param aParser the parser to use to parse input
   * @param bKeepCR <code>true</code> to keep carriage returns in data read, <code>false</code>
   *     otherwise
   */
  public CSVReader(
      @Nonnull final Reader aReader, @Nonnull final CSVParser aParser, final boolean bKeepCR) {
    ValueEnforcer.notNull(aReader, "Reader");
    ValueEnforcer.notNull(aParser, "Parser");

    Reader aInternallyBufferedReader = StreamHelper.getBuffered(aReader);
    if (bKeepCR) m_aLineReader = new CSVLineReaderKeepCR(aInternallyBufferedReader);
    else if (aInternallyBufferedReader instanceof BufferedReader)
      m_aLineReader = new CSVLineReaderBufferedReader((BufferedReader) aInternallyBufferedReader);
    else {
      if (!(aInternallyBufferedReader instanceof NonBlockingBufferedReader)) {
        // It is buffered, but we need it to support readLine
        aInternallyBufferedReader = new NonBlockingBufferedReader(aInternallyBufferedReader);
      }
      m_aLineReader =
          new CSVLineReaderNonBlockingBufferedReader(
              (NonBlockingBufferedReader) aInternallyBufferedReader);
    }
    m_aReader = aInternallyBufferedReader;
    m_aParser = aParser;
    m_bKeepCR = bKeepCR;
  }
  public void saveFormState(@Nonnull final FormState aFormState) {
    ValueEnforcer.notNull(aFormState, "FormState");

    m_aRWLock.writeLock().lock();
    try {
      m_aMap.put(aFormState.getFlowID(), aFormState);
      m_bAtLeastOnceAFormState = true;
    } finally {
      m_aRWLock.writeLock().unlock();
    }

    if (GlobalDebug.isDebugMode()) s_aLogger.info("Saved form state: " + aFormState.toString());
    else s_aLogger.info("Saved form state for page " + aFormState.getPageID());
  }
  @Nonnull
  @ReturnsMutableCopy
  public static MultilingualText createMultilingualTextFromMap(
      @Nonnull final Map<String, String> aMap) {
    ValueEnforcer.notNull(aMap, "Map");

    final MultilingualText ret = new MultilingualText();
    final LocaleCache aLC = LocaleCache.getInstance();
    for (final Entry<String, String> aEntry : aMap.entrySet()) {
      final String sText = aEntry.getValue();
      if (sText != null) ret.setText(aLC.getLocale(aEntry.getKey()), sText);
    }
    return ret;
  }
  /**
   * Set the global password constraint list.
   *
   * @param aPasswordConstraintList The list to be set. May not be <code>null</code>.
   */
  public static void setPasswordConstraintList(
      @Nonnull final IPasswordConstraintList aPasswordConstraintList) {
    ValueEnforcer.notNull(aPasswordConstraintList, "PasswordConstraintList");

    // Create a copy
    final IPasswordConstraintList aRealPasswordConstraints = aPasswordConstraintList.getClone();
    s_aRWLock.writeLock().lock();
    try {
      s_aPasswordConstraintList = aRealPasswordConstraints;
    } finally {
      s_aRWLock.writeLock().unlock();
    }
    s_aLogger.info("Set global password constraints to " + aRealPasswordConstraints);
  }
  /**
   * Reads characters into a portion of an array.
   *
   * @param aBuf Destination buffer
   * @param nOfs Offset at which to start writing characters
   * @param nLen Maximum number of characters to read
   * @return The number of characters read, or -1 if the end of the stream has been reached
   * @exception IOException If an I/O error occurs
   */
  @Override
  @CheckForSigned
  public int read(
      @Nonnull final char[] aBuf, @Nonnegative final int nOfs, @Nonnegative final int nLen)
      throws IOException {
    _ensureOpen();
    ValueEnforcer.isArrayOfsLen(aBuf, nOfs, nLen);

    if (nLen == 0) return 0;
    if (m_nNext >= m_nLength) return -1;
    final int nChars = Math.min(m_nLength - m_nNext, nLen);
    m_sStr.getChars(m_nNext, m_nNext + nChars, aBuf, nOfs);
    m_nNext += nChars;
    return nChars;
  }
  /**
   * Applies an RFC 1522 compliant encoding scheme to the given string of text with the given
   * charset.
   *
   * <p>This method constructs the "encoded-word" header common to all the RFC 1522 codecs and then
   * invokes {@link #getEncoded(byte [])} method of a concrete class to perform the specific
   * encoding.
   *
   * @param sText a string to encode
   * @param aSourceCharset a charset to be used
   * @return RFC 1522 compliant "encoded-word"
   * @throws EncodeException thrown if there is an error condition during the Encoding process.
   * @see <a
   *     href="http://download.oracle.com/javase/6/docs/api/java/nio/charset/Charset.html">Standard
   *     charsets</a>
   */
  @Nullable
  protected String getEncodedText(
      @Nullable final String sText, @Nonnull final Charset aSourceCharset) throws EncodeException {
    ValueEnforcer.notNull(aSourceCharset, "SourceCharset");
    if (sText == null) return null;

    final byte[] aEncodedData = getEncoded(CharsetManager.getAsBytes(sText, aSourceCharset));

    final StringBuilder aSB = new StringBuilder();
    aSB.append(PREFIX)
        .append(aSourceCharset.name())
        .append(SEP)
        .append(getRFC1522Encoding())
        .append(SEP)
        .append(CharsetManager.getAsString(aEncodedData, CCharset.CHARSET_US_ASCII_OBJ))
        .append(POSTFIX);
    return aSB.toString();
  }
  @Nullable
  public static String getFormattedText(
      @Nonnull final Locale aDisplayLocale,
      @Nullable final String sText,
      @Nullable final Object... aArgs) {
    ValueEnforcer.notNull(aDisplayLocale, "DisplayLocale");

    if (sText == null) {
      // Avoid NPE in MessageFormat
      return null;
    }

    if (aArgs == null || aArgs.length == 0) {
      // Return text unchanged
      return sText;
    }

    final MessageFormat aMF = new MessageFormat(sText, aDisplayLocale);
    return aMF.format(aArgs);
  }
Exemple #29
0
 /**
  * Sets the line number to skip for start reading.
  *
  * @param nSkipLines the line number to skip for start reading.
  * @return this
  */
 @Nonnull
 public CSVReader setSkipLines(@Nonnegative final int nSkipLines) {
   ValueEnforcer.isGE0(nSkipLines, "SkipLines");
   m_nSkipLines = nSkipLines;
   return this;
 }
 /**
  * Constructor to use a custom map for the attribute container
  *
  * @param bDummy Dummy parameter to be used to uniquely specify the constructor
  * @param aAttrMap The attribute map to be used.
  */
 protected MapBasedReadOnlyAttributeContainer(
     final boolean bDummy, @Nonnull final Map<KEYTYPE, VALUETYPE> aAttrMap) {
   m_aAttrs = ValueEnforcer.notNull(aAttrMap, "AttrMap");
 }