예제 #1
0
 public <T> T deserialize(Class<T> type, File directory, String fileName) {
   try {
     return deserialize(
         type,
         new FileInputStream(
             new File(
                 ContractCheck.mustNotBeNull(directory, "directory"),
                 ContractCheck.mustNotBeNull(fileName, "fileName"))));
   } catch (FileNotFoundException e) {
     throw new RuntimeException("File not found " + fileName + " in directory " + directory, e);
   }
 }
예제 #2
0
 /**
  * Constructs an {@link AcceptMediaTypeRange}.
  *
  * @param mediaTypeRange The media type range (cannot be null).
  * @param qualifyFactor The qualify factor (if null 1.0 is default).
  * @param acceptParameters The accept parameters if any.
  */
 public AcceptMediaTypeRange(
     final MediaTypeRange mediaTypeRange,
     final Double qualifyFactor,
     final Pair<String, String>... acceptParameters) {
   ContractCheck.mustNotBeNull(mediaTypeRange, "mediaTypeRange");
   ContractCheck.mustBeInRangeOrNull(
       qualifyFactor, Double.valueOf(0.0d), Double.valueOf(1.0d), "qualifyFactor");
   this.mediaTypeRange = mediaTypeRange;
   this.qualifyFactor = qualifyFactor == null ? 1.0d : qualifyFactor.doubleValue();
   this.acceptParameters =
       (acceptParameters == null || acceptParameters.length == 0)
           ? RFC2616MediaTypeParser.EMPTY_KEY_VALUE_ARRAY
           : acceptParameters;
 }
 public SimpleFunctionCallExpression(
     final String functionName, final Collection<SimpleExpression> parameterExpressions) {
   this.functionName =
       ContractCheck.mustNotBeNullOrTrimmedEmpty(functionName, "functionName"); // $NON-NLS-1$
   this.parameterExpressions =
       parameterExpressions.toArray(new SimpleExpression[parameterExpressions.size()]);
 }
예제 #4
0
 public <T> T deserialize(Class<T> type, File file) {
   try {
     return deserialize(type, new FileInputStream(ContractCheck.mustNotBeNull(file, "file")));
   } catch (FileNotFoundException e) {
     throw new RuntimeException("File not found " + file, e);
   }
 }
예제 #5
0
 /**
  * Checks if the given media type matches this media range.
  *
  * @param typeToMatch The media type to match
  * @return True if the media type matches in the media range otherwise false.
  */
 public final boolean isMediaTypeMatching(final MediaType typeToMatch) {
   ContractCheck.mustNotBeNull(typeToMatch, "typeToMatch");
   if (!isAnyType() && !this.type.equalsIgnoreCase(typeToMatch.getType())) {
     return false;
   }
   if (this.subType == null) {
     if (typeToMatch.getSubType() != null) {
       return false;
     }
   } else if (!isAnySubType() && !this.subType.equalsIgnoreCase(typeToMatch.getSubType())) {
     return false;
   }
   if (this.parameters != null) {
     for (Pair<String, String> parameter : this.parameters) {
       String otherValue = typeToMatch.getParameter(parameter.left());
       if (parameter.right() == null) {
         if (otherValue != null) {
           return false;
         }
       } else if (!parameter.right().equals(otherValue)) {
         return false;
       }
     }
   }
   return true;
 }
예제 #6
0
 public JMSMessageSender(
     final MessageHandler<T, M> messageHandler,
     final Delegate<Session> sessionDelegate,
     final Delegate<Destination> destinationDelegate,
     final Delegate<Destination> defaultReplyDestinationDelegate,
     final URI defaultEndpoint,
     Pattern copyPropertyPattern) {
   this.messageHandler = ContractCheck.mustNotBeNull(messageHandler, "messageHandler");
   this.sessionDelegate = ContractCheck.mustNotBeNull(sessionDelegate, "sessionDelegate");
   this.producerDelegate = new JMSMessageProducerDelegate(sessionDelegate, destinationDelegate);
   this.defaultReplyDestinationDelegate =
       defaultReplyDestinationDelegate == null
           ? UnmodifiableDelegate.<Destination>nullDelegate()
           : defaultReplyDestinationDelegate;
   this.defaultEndpoint = defaultEndpoint;
   this.copyPropertyPattern = copyPropertyPattern;
 }
예제 #7
0
 /**
  * Returns the value of the first occurrence of the parameter with the given name.
  *
  * @param name The name of the parameter.
  * @return The value of the first occurrence of the named parameter.
  */
 public final String getAcceptParameter(final String name) {
   ContractCheck.mustNotBeNull(name, "name");
   if (this.acceptParameters != null) {
     for (Pair<String, String> parameter : this.acceptParameters) {
       if (parameter.left().equals(name)) {
         return parameter.right();
       }
     }
   }
   return null;
 }
예제 #8
0
 /**
  * Compares this {@link AcceptMediaTypeRange} with the supplied one to order based on importance.
  *
  * @param otherAcceptMediaType The one to compare with.
  * @return 0 if they are equal important, -1 if this is less important and 1 if this is more
  *     important than the supplied one.
  * @see java.lang.Comparable#compareTo(java.lang.Object)
  */
 public int compareTo(final AcceptMediaTypeRange otherAcceptMediaType) {
   ContractCheck.mustNotBeNull(otherAcceptMediaType, "otherAcceptMediaType");
   int result = Double.compare(otherAcceptMediaType.qualifyFactor, this.qualifyFactor);
   if (result == 0) {
     String tempThis = createCompareString(this.mediaTypeRange);
     String tempOther = createCompareString(otherAcceptMediaType.mediaTypeRange);
     // We compare in the opposite as usually since we want the longest string to appear
     // first and the short last.
     return tempOther.compareTo(tempThis);
   }
   return result;
 }
예제 #9
0
 public VersionInformation(
     final VersionIdentifier identifier,
     final String version,
     final Long buildNumber,
     final Date buildTimestamp,
     final Boolean buildSnapshot) {
   this.identifier = ContractCheck.mustNotBeNull(identifier, "identifier"); // $NON-NLS-1$
   this.version = version == null ? VersionInformation.UNKNOWN_VERSION : version.trim();
   this.buildNumber = buildNumber;
   this.buildTimestamp = buildTimestamp;
   this.buildSnapshot =
       buildSnapshot != null ? Boolean.valueOf(buildSnapshot.booleanValue()) : null;
 }
예제 #10
0
 public <T> T deserialize(Class<T> type, InputStream in) {
   ObjectInputStream objectIn = null;
   try {
     objectIn = new ObjectInputStream(ContractCheck.mustNotBeNull(in, "in"));
     return type.cast(objectIn.readObject());
   } catch (ClassNotFoundException e) {
     throw new RuntimeException("Cannot deserialize instance of " + type, e);
   } catch (IOException e) {
     throw new RuntimeException("Cannot deserialize instance of " + type, e);
   } finally {
     if (objectIn != null) {
       try {
         objectIn.close();
       } catch (IOException e) {
         // we ignore the close
       }
     }
   }
 }
 public SimpleFunctionCallExpression(
     final String functionName, final SimpleExpression... parameterExpressions) {
   this.functionName =
       ContractCheck.mustNotBeNullOrTrimmedEmpty(functionName, "functionName"); // $NON-NLS-1$
   this.parameterExpressions = parameterExpressions;
 }
예제 #12
0
 /**
  * Overwrite this method in order to change the validation behavior of the sub type.
  *
  * @param subTypeString The sub type string to validate or pre-process.
  * @return The pre-processed sub type as it will be stored.
  */
 protected String processSubtypeString(final String subTypeString) {
   return ContractCheck.mustMatchPatternOrBeNull(
       subTypeString, TYPE_SUBTYPE_MATCHER, "subTypeString");
 }
예제 #13
0
 /**
  * Overwrite this method in order to change the validation behavior of the type.
  *
  * @param typeString The type string to validate or pre-process.
  * @return The pre-processed type as it will be stored.
  */
 protected String processTypeString(final String typeString) {
   return ContractCheck.mustMatchPattern(typeString, TYPE_SUBTYPE_MATCHER, "typeString");
 }