/**
   * Update the calculated person data. This method and updateCalculatedPersonOnDeleteOfSor need to
   * be generalized to handle recalculations.
   *
   * @param toPerson
   * @param fromPerson
   * @param sorPerson Adjust calculated roles... Point prc_role to prc_person receiving role Add the
   *     role to the set of roles in receiving prc_person Remove role from prc person losing role
   */
  protected void updateCalculatedPersonsOnMoveOfSor(
      final Person toPerson, final Person fromPerson, final SorPerson sorPerson) {
    Assert.notNull(toPerson, "toPerson cannot be null");
    Assert.notNull(fromPerson, "fromPerson cannot be null");
    logger.info("UpdateCalculated: recalculating person data for move.");

    final List<Role> rolesToDelete = new ArrayList<Role>();

    final List<SorRole> sorRoles = new ArrayList<SorRole>(sorPerson.getRoles());
    for (final SorRole sorRole : sorRoles) {
      for (final Role role : fromPerson.getRoles()) {
        if (sorRole.getId().equals(role.getSorRoleId())) {
          sorRoleElector.addSorRole(sorRole, toPerson);
          rolesToDelete.add(role);
        }
      }
    }
    for (final Role role : rolesToDelete) {
      sorRoleElector.removeCalculatedRole(
          fromPerson, role, this.personRepository.getSoRRecordsForPerson(fromPerson));
      fromPerson.getRoles().remove(role);
    }

    // TODO recalculate names for person receiving role? Anything else?
    // TODO recalculate names for person losing role? Anything else?
    //        this.personRepository.savePerson(fromPerson);
    //        this.personRepository.savePerson(toPerson);
  }
  public ServiceExecutionResult<SorRole> updateSorRole(
      final SorPerson sorPerson, final SorRole sorRole) {
    Assert.notNull(sorPerson, "sorPerson cannot be null.");
    Assert.notNull(sorRole, "sorRole cannot be null.");

    final Set validationErrors = this.validator.validate(sorRole);

    if (!validationErrors.isEmpty()) {
      // since because of existing design we cannot raise exception, we can only rollback the
      // transaction through code
      // OR-384
      if (TransactionAspectSupport.currentTransactionStatus() != null) {
        TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
      }

      return new GeneralServiceExecutionResult<SorRole>(validationErrors);
    }

    final SorRole savedSorRole = this.personRepository.saveSorRole(sorRole);

    final Person person = this.personRepository.findByInternalId(sorPerson.getPersonId());
    final Role role = person.findRoleBySoRRoleId(savedSorRole.getId());
    if (role != null) {
      // update calculated role only if that role was previously converted to calculated one by
      // sorRoleElector
      role.recalculate(savedSorRole);
      this.personRepository.savePerson(person);
    }
    // else //do nothing i.e. don't update the calculated role if SorRoleElector Previously decided
    // not to convert this sor role to calculated role

    return new GeneralServiceExecutionResult<SorRole>(savedSorRole);
  }
  @PreAuthorize("hasPermission(#sorRole, 'admin')")
  public ServiceExecutionResult<SorRole> validateAndSaveRoleForSorPerson(
      final SorPerson sorPerson, final SorRole sorRole) {
    logger.info(" validateAndSaveRoleForSorPerson start");
    Assert.notNull(sorPerson, "SorPerson cannot be null.");
    Assert.notNull(sorRole, "SorRole cannot be null.");

    // check if the SoR Role has an ID assigned to it already and assign source sor
    setRoleIdAndSource(sorRole, sorPerson.getSourceSor());

    final Set validationErrors = this.validator.validate(sorRole);

    if (!validationErrors.isEmpty()) {
      // since because of existing design we cannot raise exception, we can only rollback the
      // transaction through code
      // OR-384
      if (TransactionAspectSupport.currentTransactionStatus() != null) {
        TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
      }

      return new GeneralServiceExecutionResult<SorRole>(validationErrors);
    }

    final SorPerson newSorPerson = this.personRepository.saveSorPerson(sorPerson);
    Person person = this.personRepository.findByInternalId(newSorPerson.getPersonId());
    final SorRole newSorRole = newSorPerson.findSorRoleBySorRoleId(sorRole.getSorId());
    // let sor role elector decide if this new role can be converted to calculated one
    sorRoleElector.addSorRole(newSorRole, person);
    person = recalculatePersonBiodemInfo(person, newSorPerson, RecalculationType.UPDATE, false);
    this.personRepository.savePerson(person);
    logger.info("validateAndSaveRoleForSorPerson end");
    return new GeneralServiceExecutionResult<SorRole>(newSorRole);
  }
 /**
  * Copy the contents of the given byte array to the given output File.
  *
  * @param in the byte array to copy from
  * @param out the file to copy to
  * @throws IOException in case of I/O errors
  */
 public static void copy(byte[] in, File out) throws IOException {
   Assert.notNull(in, "No input byte array specified");
   Assert.notNull(out, "No output File specified");
   ByteArrayInputStream inStream = new ByteArrayInputStream(in);
   OutputStream outStream = new BufferedOutputStream(new FileOutputStream(out));
   copy(inStream, outStream);
 }
 /**
  * Copy the contents of the given input File to the given output File.
  *
  * @param in the file to copy from
  * @param out the file to copy to
  * @return the number of bytes copied
  * @throws IOException in case of I/O errors
  */
 public static int copy(File in, File out) throws IOException {
   Assert.notNull(in, "No input File specified");
   Assert.notNull(out, "No output File specified");
   return copy(
       new BufferedInputStream(new FileInputStream(in)),
       new BufferedOutputStream(new FileOutputStream(out)));
 }
예제 #6
0
 /**
  * Determine whether the given class has a method with the given signature, and return it if
  * available (else return <code>null</code>).
  *
  * <p>Essentially translates <code>NoSuchMethodException</code> to <code>null</code>.
  *
  * @param clazz the clazz to analyze
  * @param methodName the name of the method
  * @param paramTypes the parameter types of the method
  * @return the method, or <code>null</code> if not found
  * @see java.lang.Class#getMethod
  */
 public static Method getMethodIfAvailable(Class clazz, String methodName, Class[] paramTypes) {
   Assert.notNull(clazz, "Class must not be null");
   Assert.notNull(methodName, "Method name must not be null");
   try {
     return clazz.getMethod(methodName, paramTypes);
   } catch (NoSuchMethodException ex) {
     return null;
   }
 }
  /**
   * This does not explicitly delete the names because its assumed the recalculation will clean it
   * up.
   */
  public boolean deleteSystemOfRecordPerson(
      final SorPerson sorPerson, final boolean mistake, final String terminationTypes) {
    Assert.notNull(sorPerson, "sorPerson cannot be null.");
    final String terminationTypeToUse =
        terminationTypes != null ? terminationTypes : Type.TerminationTypes.UNSPECIFIED.name();

    final Person person = this.personRepository.findByInternalId(sorPerson.getPersonId());
    Assert.notNull(person, "person cannot be null.");

    if (mistake) {
      Set<Role> rolesToDelete = new HashSet<Role>();

      for (final SorRole sorRole : sorPerson.getRoles()) {
        for (final Role role : person.getRoles()) {
          if (sorRole.getId().equals(role.getSorRoleId())) {
            rolesToDelete.add(role);
          }
        }
      }

      for (final Role role : rolesToDelete) {
        // let sorRoleElector delete the role and add another role if required
        sorRoleElector.removeCalculatedRole(
            person, role, this.personRepository.getSoRRecordsForPerson(person));
      }

      final Number number = this.personRepository.getCountOfSoRRecordsForPerson(person);

      if (number.intValue() == 1) {
        this.personRepository.deletePerson(person);
      }

      this.personRepository.deleteSorPerson(sorPerson);
      return true;
    }

    // we do this explicitly here because once they're gone we can't re-calculate?  We might move to
    // this to the recalculateCalculatedPerson method.
    final Type terminationReason =
        this.referenceRepository.findType(Type.DataTypes.TERMINATION, terminationTypeToUse);

    for (final SorRole sorRole : sorPerson.getRoles()) {
      for (final Role role : person.getRoles()) {
        if (!role.isTerminated() && sorRole.getId().equals(role.getSorRoleId())) {
          role.expireNow(terminationReason, true);
        }
      }
    }

    this.personRepository.deleteSorPerson(sorPerson);
    this.personRepository.savePerson(person);

    Person p = recalculatePersonBiodemInfo(person, sorPerson, RecalculationType.DELETE, mistake);
    this.personRepository.savePerson(p);
    return true;
  }
 /**
  * Copy the contents of the given byte array to the given OutputStream. Closes the stream when
  * done.
  *
  * @param in the byte array to copy from
  * @param out the OutputStream to copy to
  * @throws IOException in case of I/O errors
  */
 public static void copy(byte[] in, OutputStream out) throws IOException {
   Assert.notNull(in, "No input byte array specified");
   Assert.notNull(out, "No OutputStream specified");
   try {
     out.write(in);
   } finally {
     try {
       out.close();
     } catch (IOException ex) {
     }
   }
 }
예제 #9
0
 /**
  * Return a static method of a class.
  *
  * @param methodName the static method name
  * @param clazz the class which defines the method
  * @param args the parameter types to the method
  * @return the static method, or <code>null</code> if no static method was found
  * @throws IllegalArgumentException if the method name is blank or the clazz is null
  */
 public static Method getStaticMethod(Class clazz, String methodName, Class[] args) {
   Assert.notNull(clazz, "Class must not be null");
   Assert.notNull(methodName, "Method name must not be null");
   try {
     Method method = clazz.getDeclaredMethod(methodName, args);
     if ((method.getModifiers() & Modifier.STATIC) != 0) {
       return method;
     }
   } catch (NoSuchMethodException ex) {
   }
   return null;
 }
 /**
  * Copy the contents of the given String to the given output Writer. Closes the write when done.
  *
  * @param in the String to copy from
  * @param out the Writer to copy to
  * @throws IOException in case of I/O errors
  */
 public static void copy(String in, Writer out) throws IOException {
   Assert.notNull(in, "No input String specified");
   Assert.notNull(out, "No Writer specified");
   try {
     out.write(in);
   } finally {
     try {
       out.close();
     } catch (IOException ex) {
     }
   }
 }
  public boolean deleteSystemOfRecordPerson(
      final String sorSource,
      final String sorId,
      final boolean mistake,
      final String terminationTypes) {
    Assert.notNull(sorSource, "sorSource cannot be null.");
    Assert.notNull(sorId, "sorId cannot be null.");
    final SorPerson sorPerson =
        this.personRepository.findBySorIdentifierAndSource(sorSource, sorId);

    return sorPerson != null && deleteSystemOfRecordPerson(sorPerson, mistake, terminationTypes);
  }
예제 #12
0
 public static JComponent getDeepest(JComponent outermostContainer, MouseEvent mouseEvent) {
   JComponent result;
   Assert.notNull(outermostContainer);
   Assert.notNull(mouseEvent);
   MouseEvent localizedMouseEvent =
       SwingUtilities.convertMouseEvent(mouseEvent.getComponent(), mouseEvent, outermostContainer);
   result =
       (JComponent)
           SwingUtilities.getDeepestComponentAt(
               outermostContainer,
               localizedMouseEvent.getPoint().x,
               localizedMouseEvent.getPoint().y);
   return result;
 }
  public ServiceExecutionResult<ReconciliationResult> reconcile(
      final ReconciliationCriteria reconciliationCriteria) throws IllegalArgumentException {
    Assert.notNull(reconciliationCriteria, "reconciliationCriteria cannot be null");
    logger.info("reconcile start");
    final Set validationErrors = this.validator.validate(reconciliationCriteria);

    if (!validationErrors.isEmpty()) {
      Iterator iter = validationErrors.iterator();
      while (iter.hasNext()) {
        logger.info("validation errors: " + iter.next());
      }
      logger.info("reconcile start");
      // since because of existing design we cannot raise exception, we can only rollback the
      // transaction through code
      // OR-384
      if (TransactionAspectSupport.currentTransactionStatus() != null) {
        TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
      }

      return new GeneralServiceExecutionResult<ReconciliationResult>(validationErrors);
    }

    final ReconciliationResult result = this.reconciler.reconcile(reconciliationCriteria);
    // (reconciliationCriteria, result);
    return new GeneralServiceExecutionResult<ReconciliationResult>(result);
  }
  public void load() throws IOException {
    Assert.notNull(m_configFile, "The configuration file must not be null");

    if (!m_configFile.exists()) {
      throw new FileNotFoundException("file " + m_configFile + " does not exist.");
    }
  }
  /**
   * Persists an SorPerson on update.
   *
   * @param sorPerson the person to update.
   * @return serviceExecutionResult.
   */
  public ServiceExecutionResult<SorPerson> updateSorPerson(final SorPerson sorPerson) {
    final Set validationErrors = this.validator.validate(sorPerson);

    if (!validationErrors.isEmpty()) {
      Iterator iter = validationErrors.iterator();
      while (iter.hasNext()) {
        logger.info("validation errors: " + iter.next());
      }
      // since because of existing design we cannot raise exception, we can only rollback the
      // transaction through code
      // OR-384
      if (TransactionAspectSupport.currentTransactionStatus() != null) {
        TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
      }

      return new GeneralServiceExecutionResult<SorPerson>(validationErrors);
    }

    // do reconciliationCheck to make sure that modifications do not cause person to reconcile to a
    // different person
    if (!this.reconciler.reconcilesToSamePerson(sorPerson)) {
      throw new IllegalStateException();
    }

    // Iterate over any sorRoles setting sorid and source id if not specified by SoR.
    for (final SorRole sorRole : sorPerson.getRoles()) {
      setRoleIdAndSource(sorRole, sorPerson.getSourceSor());
    }

    // Save Sor Person
    final SorPerson savedSorPerson = this.personRepository.saveSorPerson(sorPerson);

    Person person = this.findPersonById(savedSorPerson.getPersonId());

    Assert.notNull(person, "person cannot be null.");

    logger.info(
        "Verifying Number of calculated Roles before the calculate: " + person.getRoles().size());

    // Iterate over sorRoles. SorRoles may be new or updated.
    for (final SorRole savedSorRole : savedSorPerson.getRoles()) {
      logger.info(
          "DefaultPersonService: savedSorPersonRole Found, savedSorRoleID: "
              + savedSorRole.getId());
      logger.info("DefaultPersonService: savedSorPersonRole Found, Role Must be newly added.");
      // let sor role elector decide if this new role can be converted to calculated one
      sorRoleElector.addSorRole(savedSorRole, person);
      logger.info(
          "Verifying Number of calculated Roles after calculate: " + person.getRoles().size());
    }

    for (final IdentifierAssigner ia : this.identifierAssigners) {
      ia.addIdentifierTo(sorPerson, person);
    }

    person = recalculatePersonBiodemInfo(person, savedSorPerson, RecalculationType.UPDATE, false);
    person = this.personRepository.savePerson(person);

    return new GeneralServiceExecutionResult<SorPerson>(savedSorPerson);
  }
예제 #16
0
 /**
  * Resolve the given resource location to a <code>java.net.URL</code>.
  *
  * <p>Does not check whether the URL actually exists; simply returns the URL that the given
  * location would correspond to.
  *
  * @param resourceLocation the resource location to resolve: either a "classpath:" pseudo URL, a
  *     "file:" URL, or a plain file path
  * @return a corresponding URL object
  * @throws FileNotFoundException if the resource cannot be resolved to a URL
  */
 public static URL getURL(String resourceLocation) throws FileNotFoundException {
   Assert.notNull(resourceLocation, "Resource location must not be null");
   if (resourceLocation.startsWith(CLASSPATH_URL_PREFIX)) {
     String path = resourceLocation.substring(CLASSPATH_URL_PREFIX.length());
     URL url = ClassUtils.getDefaultClassLoader().getResource(path);
     if (url == null) {
       String description = "class path resource [" + path + "]";
       throw new FileNotFoundException(
           description + " cannot be resolved to URL because it does not exist");
     }
     return url;
   }
   try {
     // try URL
     return new URL(resourceLocation);
   } catch (MalformedURLException ex) {
     // no URL -> treat as file path
     try {
       return new File(resourceLocation).toURI().toURL();
     } catch (MalformedURLException ex2) {
       throw new FileNotFoundException(
           "Resource location ["
               + resourceLocation
               + "] is neither a URL not a well-formed file path");
     }
   }
 }
예제 #17
0
  /**
   * Replacement for <code>Class.forName()</code> that also returns Class instances for primitives
   * (like "int") and array class names (like "String[]").
   *
   * @param name the name of the Class
   * @param classLoader the class loader to use (may be <code>null</code>, which indicates the
   *     default class loader)
   * @return Class instance for the supplied name
   * @throws ClassNotFoundException if the class was not found
   * @throws LinkageError if the class file could not be loaded
   * @see Class#forName(String, boolean, ClassLoader)
   */
  public static Class forName(String name, ClassLoader classLoader)
      throws ClassNotFoundException, LinkageError {
    Assert.notNull(name, "Name must not be null");

    Class clazz = resolvePrimitiveClassName(name);
    if (clazz != null) {
      return clazz;
    }

    // "java.lang.String[]" style arrays
    if (name.endsWith(ARRAY_SUFFIX)) {
      String elementClassName = name.substring(0, name.length() - ARRAY_SUFFIX.length());
      Class elementClass = forName(elementClassName, classLoader);
      return Array.newInstance(elementClass, 0).getClass();
    }

    // "[Ljava.lang.String;" style arrays
    int internalArrayMarker = name.indexOf(INTERNAL_ARRAY_PREFIX);
    if (internalArrayMarker != -1 && name.endsWith(";")) {
      String elementClassName = null;
      if (internalArrayMarker == 0) {
        elementClassName = name.substring(INTERNAL_ARRAY_PREFIX.length(), name.length() - 1);
      } else if (name.startsWith("[")) {
        elementClassName = name.substring(1);
      }
      Class elementClass = forName(elementClassName, classLoader);
      return Array.newInstance(elementClass, 0).getClass();
    }

    ClassLoader classLoaderToUse = classLoader;
    if (classLoaderToUse == null) {
      classLoaderToUse = getDefaultClassLoader();
    }
    return classLoaderToUse.loadClass(name);
  }
예제 #18
0
  /** {@inheritDoc} */
  @Override
  public void start(BundleContext bundleContext) throws Exception {
    focusManager = ServiceUtils.getService(bundleContext, FocusManager.class);

    Assert.notNull(focusManager, "focusManager");

    versionService = ServiceUtils.getService(bundleContext, VersionService.class);

    Assert.notNull(versionService, "versionService");

    meetTools = focusManager.getOperationSet(OperationSetJitsiMeetTools.class);

    Assert.notNull(meetTools, "meetTools");

    super.start(bundleContext);
  }
예제 #19
0
    /**
     * @param name The name of the parameter. Not empty.
     * @param expression The ECMAScript expression of the parameter. Not null.
     * @return The newly created subdialogue parameter
     */
    public static Parameter createWithExpression(String name, String expression) {
      Assert.notNull(expression, "expression");

      Parameter parameter = new Parameter(name);
      parameter.mExpression = expression;
      return parameter;
    }
예제 #20
0
 /**
  * Return a path suitable for use with <code>ClassLoader.getResource</code> (also suitable for use
  * with <code>Class.getResource</code> by prepending a slash ('/') to the return value. Built by
  * taking the package of the specified class file, converting all dots ('.') to slashes ('/'),
  * adding a trailing slash if necesssary, and concatenating the specified resource name to this.
  * <br>
  * As such, this function may be used to build a path suitable for loading a resource file that is
  * in the same package as a class file, although {@link
  * org.springframework.core.io.ClassPathResource} is usually even more convenient.
  *
  * @param clazz the Class whose package will be used as the base
  * @param resourceName the resource name to append. A leading slash is optional.
  * @return the built-up resource path
  * @see java.lang.ClassLoader#getResource
  * @see java.lang.Class#getResource
  */
 public static String addResourcePathToPackagePath(Class clazz, String resourceName) {
   Assert.notNull(resourceName, "Resource name must not be null");
   if (!resourceName.startsWith("/")) {
     return classPackageAsResourcePath(clazz) + "/" + resourceName;
   }
   return classPackageAsResourcePath(clazz) + resourceName;
 }
예제 #21
0
    /**
     * @param name The name of the parameter. Not empty.
     * @param value The string value of the parameter. Not null.
     * @return The newly created subdialogue parameter
     */
    public static Parameter createWithValue(String name, String value) {
      Assert.notNull(value, "value");

      Parameter parameter = new Parameter(name);
      parameter.mValue = value;
      return parameter;
    }
 protected FS createFileSystem(String[] pathPatterns, String[] filterPatterns) {
   Assert.notNull(pathPatterns, "PathPatterns must not be null");
   Assert.notNull(filterPatterns, "FilterPatterns must not be null");
   FS fileSystem = new FS();
   for (String pathPattern : pathPatterns) {
     try {
       fileSystem.mount(
           new SimpleFileSystemDriver(
               new DirectoryHandle(pathPattern, this.resourceLoader, filterPatterns)));
     } catch (IOException ex) {
       throw new IllegalStateException(
           "Failed to mount file system for '" + pathPattern + "'", ex);
     }
   }
   return fileSystem;
 }
 public static void save(Properties properties, File file) throws IOException {
   Assert.notNull(properties, "存储的属性为空!");
   OutputStream outputStream = new FileOutputStream(file);
   properties.store(outputStream, "saved on " + DateHelper.getStringDate());
   outputStream.flush();
   outputStream.close();
 }
예제 #24
0
 /**
  * Determine whether the given class has a constructor with the given signature, and return it if
  * available (else return <code>null</code>).
  *
  * <p>Essentially translates <code>NoSuchMethodException</code> to <code>null</code>.
  *
  * @param clazz the clazz to analyze
  * @param paramTypes the parameter types of the method
  * @return the constructor, or <code>null</code> if not found
  * @see java.lang.Class#getConstructor
  */
 public static Constructor getConstructorIfAvailable(Class clazz, Class[] paramTypes) {
   Assert.notNull(clazz, "Class must not be null");
   try {
     return clazz.getConstructor(paramTypes);
   } catch (NoSuchMethodException ex) {
     return null;
   }
 }
예제 #25
0
 /**
  * Return the qualified name of the given class: usually simply the class name, but component type
  * class name + "[]" for arrays.
  *
  * @param clazz the class
  * @return the qualified name of the class
  */
 public static String getQualifiedName(Class clazz) {
   Assert.notNull(clazz, "Class must not be null");
   if (clazz.isArray()) {
     return getQualifiedNameForArray(clazz);
   } else {
     return clazz.getName();
   }
 }
예제 #26
0
  public static <T> T copyPropertiesFromMapToBean(Map<String, Object> source, Class<T> target) {
    Assert.notNull(source, "Source must not be null");
    Assert.notNull(target, "Target must not be null");
    T tarObj = instantiate(target);

    Map<String, Method> methodCache = ClassDescriptorCache.forClass(target).getMethodCache();

    for (Entry<String, Object> entry : source.entrySet()) {
      if (entry.getValue() instanceof Map) {
        @SuppressWarnings("unchecked")
        Map<String, Object> subMap = (Map<String, Object>) entry.getValue();
        Method writeMethod = methodCache.get(entry.getKey());
        if (writeMethod != null) {
          Class<?>[] params = writeMethod.getParameterTypes();
          if (params.length != 1) {
            throw new IllegalArgumentException(
                target.toString()
                    + " "
                    + writeMethod.getName()
                    + " 's param should only one class!");
          }
          Object o = copyPropertiesFromMapToBean(subMap, params[0]);
          entry.setValue(o);
        } else {
          throwMapTooManyAttException(target, entry.getKey());
        }
      }
      Method writeMethod = methodCache.get(entry.getKey());
      if (writeMethod != null) {
        try {
          writeMethod.invoke(tarObj, entry.getValue());
        } catch (IllegalArgumentException e) {
          throwAttributeNotMatchException(target, entry.getValue(), writeMethod);
        } catch (InvocationTargetException e) {
          throw new IllegalArgumentException(e.getMessage());
        } catch (IllegalAccessException e) {
          throw new IllegalArgumentException(e.getMessage());
        }
      } else {
        throwMapTooManyAttException(target, entry.getKey());
      }
    }

    return tarObj;
  }
  /**
   * Creates a new <code>PropertyPlaceholderHelper</code> that uses the supplied prefix and suffix.
   *
   * @param placeholderPrefix the prefix that denotes the start of a placeholder
   * @param placeholderSuffix the suffix that denotes the end of a placeholder
   * @param valueSeparator the separating character between the placeholder variable and the
   *     associated default value, if any
   * @param ignoreUnresolvablePlaceholders indicates whether unresolvable placeholders should be
   *     ignored (<code>true</code>) or cause an exception (<code>false</code>).
   */
  public PropertyPlaceholderHelper(
      String placeholderPrefix,
      String placeholderSuffix,
      String valueSeparator,
      boolean ignoreUnresolvablePlaceholders) {

    Assert.notNull(placeholderPrefix, "placeholderPrefix must not be null");
    Assert.notNull(placeholderSuffix, "placeholderSuffix must not be null");
    this.placeholderPrefix = placeholderPrefix;
    this.placeholderSuffix = placeholderSuffix;
    String simplePrefixForSuffix = wellKnownSimplePrefixes.get(this.placeholderSuffix);
    if (simplePrefixForSuffix != null && this.placeholderPrefix.endsWith(simplePrefixForSuffix)) {
      this.simplePrefix = simplePrefixForSuffix;
    } else {
      this.simplePrefix = this.placeholderPrefix;
    }
    this.valueSeparator = valueSeparator;
    this.ignoreUnresolvablePlaceholders = ignoreUnresolvablePlaceholders;
  }
예제 #28
0
 /**
  * Rollback the Session if not within a JTA transaction.
  *
  * @param session the JMS Session to rollback
  * @throws JMSException if committing failed
  */
 public static void rollbackIfNecessary(Session session) throws JMSException {
   Assert.notNull(session, "Session must not be null");
   try {
     session.rollback();
   } catch (javax.jms.TransactionInProgressException ex) {
     // Ignore -> can only happen in case of a JTA transaction.
   } catch (javax.jms.IllegalStateException ex) {
     // Ignore -> can only happen in case of a JTA transaction.
   }
 }
 /**
  * Replaces all placeholders of format <code>${name}</code> with the corresponding property from
  * the supplied {@link Properties}.
  *
  * @param value the value containing the placeholders to be replaced.
  * @param properties the <code>Properties</code> to use for replacement.
  * @return the supplied value with placeholders replaced inline.
  */
 public String replacePlaceholders(String value, final Properties properties) {
   Assert.notNull(properties, "Argument 'properties' must not be null.");
   return replacePlaceholders(
       value,
       new PlaceholderResolver() {
         public String resolvePlaceholder(String placeholderName) {
           return properties.getProperty(placeholderName);
         }
       });
 }
예제 #30
0
 /**
  * Does the given class and/or its superclasses at least have one or more methods (with any
  * argument types)? Includes non-public methods.
  *
  * @param clazz the clazz to check
  * @param methodName the name of the method
  * @return whether there is at least one method with the given name
  */
 public static boolean hasAtLeastOneMethodWithName(Class clazz, String methodName) {
   Assert.notNull(clazz, "Class must not be null");
   Assert.notNull(methodName, "Method name must not be null");
   Method[] declaredMethods = clazz.getDeclaredMethods();
   for (int i = 0; i < declaredMethods.length; i++) {
     Method method = declaredMethods[i];
     if (method.getName().equals(methodName)) {
       return true;
     }
   }
   Class[] ifcs = clazz.getInterfaces();
   for (int i = 0; i < ifcs.length; i++) {
     if (hasAtLeastOneMethodWithName(ifcs[i], methodName)) {
       return true;
     }
   }
   return (clazz.getSuperclass() != null
       && hasAtLeastOneMethodWithName(clazz.getSuperclass(), methodName));
 }