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();
    }
  }
 public DataTablesOrderColumn(
     @Nonnegative final int nIndex, @Nonnull final ESortOrder eSortOrder) {
   ValueEnforcer.isGE0(nIndex, "Index");
   ValueEnforcer.notNull(eSortOrder, "SortOrder");
   m_nIndex = nIndex;
   m_eSortOrder = eSortOrder;
 }
  @Nullable
  public final String getText(@Nonnull final Locale aContentLocale) {
    ValueEnforcer.notNull(aContentLocale, "ContentLocale");

    final Locale aLocaleToUse = internalGetLocaleToUseWithFallback(aContentLocale);
    return aLocaleToUse == null ? null : internalGetText(aLocaleToUse);
  }
示例#6
0
  @Nonnull
  @CheckReturnValue
  public SizeDouble getAdded(@Nonnull final IHasDimensionDouble aToAdd) {
    ValueEnforcer.notNull(aToAdd, "ToAdd");

    return new SizeDouble(m_dWidth + aToAdd.getWidth(), m_dHeight + aToAdd.getHeight());
  }
示例#7
0
  @Nonnull
  @CheckReturnValue
  public SizeDouble getSubtracted(@Nonnull final IHasDimensionDouble aToSubtract) {
    ValueEnforcer.notNull(aToSubtract, "ToSubtract");

    return new SizeDouble(m_dWidth - aToSubtract.getWidth(), m_dHeight - aToSubtract.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);
    }
  }
示例#9
0
  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));
  }
  /**
   * 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());
  }
  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);
    }
  }
示例#13
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;
  }
  @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;
  }
示例#15
0
  @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);
  }
示例#17
0
  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());
  }
  /**
   * 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();
  }
示例#19
0
  @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);
  }
  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);
    }
  }
示例#21
0
  @Nonnull
  public static byte[] readHttpPayload(
      @Nonnull final InputStream aIS,
      @Nonnull final IAS2HttpResponseHandler aResponseHandler,
      @Nonnull final IMessage aMsg)
      throws IOException {
    ValueEnforcer.notNull(aIS, "InputStream");
    ValueEnforcer.notNull(aResponseHandler, "ResponseHandler");
    ValueEnforcer.notNull(aMsg, "Msg");

    final DataInputStream aDataIS = new DataInputStream(aIS);

    // Retrieve the message content
    byte[] aData = null;
    final String sContentLength = aMsg.getHeader(CAS2Header.HEADER_CONTENT_LENGTH);
    if (sContentLength == null) {
      // No "Content-Length" header present
      final String sTransferEncoding = aMsg.getHeader(CAS2Header.HEADER_TRANSFER_ENCODING);
      if (sTransferEncoding != null) {
        // Remove all whitespaces in the value
        if (sTransferEncoding.replaceAll("\\s+", "").equalsIgnoreCase("chunked")) {
          // chunked encoding
          int nLength = 0;
          for (; ; ) {
            // First get hex chunk length; followed by CRLF
            int nBlocklen = 0;
            for (; ; ) {
              int ch = aDataIS.readByte();
              if (ch == '\n') break;
              if (ch >= 'a' && ch <= 'f') ch -= ('a' - 10);
              else if (ch >= 'A' && ch <= 'F') ch -= ('A' - 10);
              else if (ch >= '0' && ch <= '9') ch -= '0';
              else continue;
              nBlocklen = (nBlocklen * 16) + ch;
            }
            // Zero length is end of chunks
            if (nBlocklen == 0) break;
            // Ok, now read new chunk
            final int nNewlen = nLength + nBlocklen;
            final byte[] aNewData = new byte[nNewlen];
            if (nLength > 0) System.arraycopy(aData, 0, aNewData, 0, nLength);
            aDataIS.readFully(aNewData, nLength, nBlocklen);
            aData = aNewData;
            nLength = nNewlen;
            // And now the CRLF after the chunk;
            while (true) {
              final int n = aDataIS.readByte();
              if (n == '\n') break;
            }
          }
          aMsg.setHeader(CAS2Header.HEADER_CONTENT_LENGTH, Integer.toString(nLength));
        } else {
          // No "Content-Length" and unsupported "Transfer-Encoding"
          sendSimpleHTTPResponse(aResponseHandler, HttpURLConnection.HTTP_LENGTH_REQUIRED);
          throw new IOException("Transfer-Encoding unimplemented: " + sTransferEncoding);
        }
      } else {
        // No "Content-Length" and no "Transfer-Encoding"
        sendSimpleHTTPResponse(aResponseHandler, HttpURLConnection.HTTP_LENGTH_REQUIRED);
        throw new IOException("Content-Length missing");
      }
    } else {
      // "Content-Length" is present
      // Receive the transmission's data
      // XX if a value > 2GB comes in, this will fail!!
      final int nContentSize = Integer.parseInt(sContentLength);
      aData = new byte[nContentSize];
      aDataIS.readFully(aData);
    }

    return aData;
  }
 @Nonnull
 public DTPButtonsButtonKey setMetaKey(@Nonnull final ETriState eMetaKey) {
   ValueEnforcer.notNull(eMetaKey, "MetaKey");
   m_eMetaKey = eMetaKey;
   return this;
 }
 @Nonnull
 public DTPButtonsButtonKey setCtrlKey(@Nonnull final ETriState eCtrlKey) {
   ValueEnforcer.notNull(eCtrlKey, "CtrlKey");
   m_eCtrlKey = eCtrlKey;
   return this;
 }
 @Nonnull
 public DTPButtonsButtonKey setAltKey(@Nonnull final ETriState eAltKey) {
   ValueEnforcer.notNull(eAltKey, "AltKey");
   m_eAltKey = eAltKey;
   return this;
 }
示例#25
0
 public AS2ReceiverHandler(@Nonnull final AS2ReceiverModule aModule) {
   m_aReceiverModule = ValueEnforcer.notNull(aModule, "Module");
 }
 /**
  * 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");
 }
 /**
  * Creates a new string reader.
  *
  * @param sStr String providing the character stream. May not be <code>null</code>.
  */
 public NonBlockingStringReader(@Nonnull final String sStr) {
   m_sStr = ValueEnforcer.notNull(sStr, "String");
   m_nLength = sStr.length();
 }
 /**
  * Set the factory to create {@link AS2Client} objects internally. Overwrite this if you need a
  * proxy in the AS2Client object. By default a new instance of AS2Client is created so you don't
  * need to call this method.
  *
  * @param aAS2ClientFactory The factory to be used. May not be <code>null</code>.
  * @return this for chaining
  */
 @Nonnull
 public AS2ClientBuilder setAS2ClientFactory(
     @Nonnull final IFactory<AS2Client> aAS2ClientFactory) {
   m_aAS2ClientFactory = ValueEnforcer.notNull(aAS2ClientFactory, "AS2ClientFactory");
   return this;
 }
 /**
  * Set the message handler to be used by the {@link #verifyContent()} method. By default an
  * instance of {@link DefaultAS2ClientBuilderMessageHandler} is used so this method should only be
  * called if you have special auditing requirements.
  *
  * @param aMessageHandler The message handler to be used. May not be <code>null</code>.
  * @return this for chaining
  */
 @Nonnull
 public AS2ClientBuilder setMessageHandler(
     @Nonnull final IAS2ClientBuilderMessageHandler aMessageHandler) {
   m_aMessageHandler = ValueEnforcer.notNull(aMessageHandler, "MessageHandler");
   return this;
 }
示例#30
0
 public AbstractSoftMap(@Nonnull final Map<K, SoftValue<K, V>> aSrcMap) {
   m_aSrcMap = ValueEnforcer.notNull(aSrcMap, "SrcMap");
 }