Java 类org.springframework.core.JdkVersion 实例源码

项目:class-guard    文件:ResourceBundleMessageSource.java   
/**
 * Obtain the resource bundle for the given basename and Locale.
 * @param basename the basename to look for
 * @param locale the Locale to look for
 * @return the corresponding ResourceBundle
 * @throws MissingResourceException if no matching bundle could be found
 * @see java.util.ResourceBundle#getBundle(String, java.util.Locale, ClassLoader)
 * @see #getBundleClassLoader()
 */
protected ResourceBundle doGetBundle(String basename, Locale locale) throws MissingResourceException {
    if ((this.defaultEncoding != null && !"ISO-8859-1".equals(this.defaultEncoding)) ||
            !this.fallbackToSystemLocale || this.cacheMillis >= 0) {
        // Custom Control required...
        if (JdkVersion.getMajorJavaVersion() < JdkVersion.JAVA_16) {
            throw new IllegalStateException("Cannot use 'defaultEncoding', 'fallbackToSystemLocale' and " +
                    "'cacheSeconds' on the standard ResourceBundleMessageSource when running on Java 5. " +
                    "Consider using ReloadableResourceBundleMessageSource instead.");
        }
        return new ControlBasedResourceBundleFactory().getBundle(basename, locale);
    }
    else {
        // Good old standard call...
        return ResourceBundle.getBundle(basename, locale, getBundleClassLoader());
    }
}
项目:class-guard    文件:ResourceBundleMessageSourceTests.java   
public void testResourceBundleMessageSourceWithInappropriateDefaultCharset() {
    if (JdkVersion.getMajorJavaVersion() < JdkVersion.JAVA_16) {
        return;
    }
    ResourceBundleMessageSource ms = new ResourceBundleMessageSource();
    ms.setBasename("org/springframework/context/support/messages");
    ms.setDefaultEncoding("argh");
    ms.setFallbackToSystemLocale(false);
    try {
        ms.getMessage("code1", null, Locale.ENGLISH);
        fail("Should have thrown NoSuchMessageException");
    }
    catch (NoSuchMessageException ex) {
        // expected
    }
}
项目:class-guard    文件:XsltViewTests.java   
private void assertHtmlOutput(String output) throws Exception {
    if (JdkVersion.getMajorJavaVersion() < JdkVersion.JAVA_15) {
        // TODO: find out why the SAXReader.read call fails on JDK 1.4 and 1.3
        return;
    }

    SAXReader reader = new SAXReader();
    Document document = reader.read(new StringReader(output));
    List nodes = document.getRootElement().selectNodes("/html/body/table/tr");

    Element tr1 = (Element) nodes.get(0);
    assertRowElement(tr1, "1", "Whatsit", "12.99");
    Element tr2 = (Element) nodes.get(1);
    assertRowElement(tr2, "2", "Thingy", "13.99");
    Element tr3 = (Element) nodes.get(2);
    assertRowElement(tr3, "3", "Gizmo", "14.99");
    Element tr4 = (Element) nodes.get(3);
    assertRowElement(tr4, "4", "Cranktoggle", "11.99");
}
项目:spring-rich-client    文件:DefaultMemberPropertyAccessor.java   
private Object getMapValue(Map map, Object key) {
    if (map.containsKey(key)) {
        return map.get(key);
    }
    else {
        if (!JdkVersion.isAtLeastJava15()) {
            // we don't know the type of the keys, so we fall back to
            // comparing toString()
            for (Iterator i = map.entrySet().iterator(); i.hasNext();) {
                Map.Entry entry = (Map.Entry) i.next();
                if (entry.getKey() == key
                        || (entry.getKey() != null && key != null && entry.getKey().toString().equals(
                                key.toString()))) {
                    return entry.getValue();
                }
            }
        }
        return null;
    }
}
项目:spring-rich-client    文件:AbstractMemberPropertyAccessor.java   
protected NotReadablePropertyException createNotReadablePropertyException(String propertyName, Exception e) {
    if (JdkVersion.isAtLeastJava14()) {
        NotReadablePropertyException beanException = new NotReadablePropertyException(getTargetClass(),
                propertyName);
        beanException.initCause(e);
        return beanException;
    }
    else {
        ByteArrayOutputStream stackTrace = new ByteArrayOutputStream();
        PrintWriter stackTraceWriter = new PrintWriter(stackTrace);
        e.printStackTrace(stackTraceWriter);
        stackTraceWriter.close();
        return new NotReadablePropertyException(getTargetClass(), propertyName,
                new String(stackTrace.toByteArray()));
    }
}
项目:spring-richclient    文件:DefaultMemberPropertyAccessor.java   
private Object getMapValue(Map map, Object key) {
    if (map.containsKey(key)) {
        return map.get(key);
    }
    else {
        if (!JdkVersion.isAtLeastJava15()) {
            // we don't know the type of the keys, so we fall back to
            // comparing toString()
            for (Iterator i = map.entrySet().iterator(); i.hasNext();) {
                Map.Entry entry = (Map.Entry) i.next();
                if (entry.getKey() == key
                        || (entry.getKey() != null && key != null && entry.getKey().toString().equals(
                                key.toString()))) {
                    return entry.getValue();
                }
            }
        }
        return null;
    }
}
项目:spring-richclient    文件:AbstractMemberPropertyAccessor.java   
protected NotReadablePropertyException createNotReadablePropertyException(String propertyName, Exception e) {
    if (JdkVersion.isAtLeastJava14()) {
        NotReadablePropertyException beanException = new NotReadablePropertyException(getTargetClass(),
                propertyName);
        beanException.initCause(e);
        return beanException;
    }
    else {
        ByteArrayOutputStream stackTrace = new ByteArrayOutputStream();
        PrintWriter stackTraceWriter = new PrintWriter(stackTrace);
        e.printStackTrace(stackTraceWriter);
        stackTraceWriter.close();
        return new NotReadablePropertyException(getTargetClass(), propertyName,
                new String(stackTrace.toByteArray()));
    }
}
项目:Equella    文件:SecurityAttributeSource.java   
private SecurityAttribute computeSecurityAttribute(Method method, Class<?> targetClass)
{
    // The method may be on an interface, but we need attributes from the
    // target class.
    // If the target class is null, the method will be unchanged.
    Method specificMethod = ClassUtils.getMostSpecificMethod(method, targetClass);
    // If we are dealing with method with generic parameters, find the
    // original method.
    if( JdkVersion.isAtLeastJava15() )
    {
        specificMethod = BridgeMethodResolver.findBridgedMethod(specificMethod);
    }

    // First try is the method in the target class.
    SecurityAttribute txAtt = findSecurityAttribute(specificMethod, targetClass);
    if( txAtt != null )
    {
        return txAtt;
    }

    if( !specificMethod.equals(method) )
    {
        // Fallback is to look at the original method.
        txAtt = findSecurityAttribute(method, targetClass);
        if( txAtt != null )
        {
            return txAtt;
        }
    }
    return null;
}
项目:proarc    文件:Z3950ClientTest.java   
@Before
public void setUp() throws Exception {
    host = System.getProperty("Z3950ClientTest.host");
    port = System.getProperty("Z3950ClientTest.port");
    base = System.getProperty("Z3950ClientTest.base");
    Assume.assumeNotNull(host, port, base);
    assertEquals(JdkVersion.JAVA_17, JdkVersion.getMajorJavaVersion());
}
项目:class-guard    文件:JmxUtilsTests.java   
public void testLocatePlatformMBeanServer() {
    if(JdkVersion.getMajorJavaVersion() < JdkVersion.JAVA_15) {
        return;
    }

    MBeanServer server = null;
    try {
        server = JmxUtils.locateMBeanServer();
    }
    finally {
        if (server != null) {
            MBeanServerFactory.releaseMBeanServer(server);
        }
    }
}
项目:class-guard    文件:JmxUtilsAnnotationTests.java   
public void testNotMXBean() throws Exception {
    if (JdkVersion.getMajorJavaVersion() < JdkVersion.JAVA_16) {
        return;
    }
    FooNotX foo = new FooNotX();
    assertFalse("MXBean annotation not detected correctly", JmxUtils.isMBean(foo.getClass()));
}
项目:class-guard    文件:JmxUtilsAnnotationTests.java   
public void testAnnotatedMXBean() throws Exception {
    if (JdkVersion.getMajorJavaVersion() < JdkVersion.JAVA_16) {
        return;
    }
    FooX foo = new FooX();
    assertTrue("MXBean annotation not detected correctly", JmxUtils.isMBean(foo.getClass()));
}
项目:class-guard    文件:NumberUtilsTests.java   
public void testParseLocalizedBigDecimalNumber1() {
    if (JdkVersion.getMajorJavaVersion() < JdkVersion.JAVA_15) {
        return;
    }
    String bigDecimalAsString = "0.10";
    NumberFormat numberFormat = NumberFormat.getInstance(Locale.ENGLISH);
    Number bigDecimal = NumberUtils.parseNumber(bigDecimalAsString, BigDecimal.class, numberFormat);
    assertEquals(new BigDecimal(bigDecimalAsString), bigDecimal);
}
项目:class-guard    文件:NumberUtilsTests.java   
public void testParseLocalizedBigDecimalNumber2() {
    if (JdkVersion.getMajorJavaVersion() < JdkVersion.JAVA_15) {
        return;
    }
    String bigDecimalAsString = "0.001";
    NumberFormat numberFormat = NumberFormat.getInstance(Locale.ENGLISH);
    Number bigDecimal = NumberUtils.parseNumber(bigDecimalAsString, BigDecimal.class, numberFormat);
    assertEquals(new BigDecimal(bigDecimalAsString), bigDecimal);
}
项目:class-guard    文件:NumberUtilsTests.java   
public void testParseLocalizedBigDecimalNumber3() {
    if (JdkVersion.getMajorJavaVersion() < JdkVersion.JAVA_15) {
        return;
    }
    String bigDecimalAsString = "3.14159265358979323846";
    NumberFormat numberFormat = NumberFormat.getInstance(Locale.ENGLISH);
    Number bigDecimal = NumberUtils.parseNumber(bigDecimalAsString, BigDecimal.class, numberFormat);
    assertEquals(new BigDecimal(bigDecimalAsString), bigDecimal);
}
项目:class-guard    文件:SQLErrorCodeSQLExceptionTranslator.java   
/**
 * Constructor for use as a JavaBean.
 * The SqlErrorCodes or DataSource property must be set.
 */
public SQLErrorCodeSQLExceptionTranslator() {
    if (JdkVersion.getMajorJavaVersion() >= JdkVersion.JAVA_16) {
        setFallbackTranslator(new SQLExceptionSubclassTranslator());
    }
    else {
        setFallbackTranslator(new SQLStateSQLExceptionTranslator());
    }
}
项目:class-guard    文件:Jaxb2Marshaller.java   
public boolean supports(Type genericType) {
    if (genericType instanceof ParameterizedType) {
        ParameterizedType parameterizedType = (ParameterizedType) genericType;
        if (JAXBElement.class.equals(parameterizedType.getRawType()) &&
                parameterizedType.getActualTypeArguments().length == 1) {
            Type typeArgument = parameterizedType.getActualTypeArguments()[0];
            if (typeArgument instanceof Class) {
                Class<?> classArgument = (Class<?>) typeArgument;
                if (JdkVersion.getMajorJavaVersion() >= JdkVersion.JAVA_17 && classArgument.isArray()) {
                    return classArgument.getComponentType().equals(Byte.TYPE);
                }
                else {
                    return (isPrimitiveWrapper(classArgument) || isStandardClass(classArgument) ||
                            supportsInternal(classArgument, false));
                }
            }
            else if (JdkVersion.getMajorJavaVersion() <= JdkVersion.JAVA_16 &&
                    typeArgument instanceof GenericArrayType) {
                // see http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5041784
                GenericArrayType arrayType = (GenericArrayType) typeArgument;
                return arrayType.getGenericComponentType().equals(Byte.TYPE);
            }
        }
    }
    else if (genericType instanceof Class) {
        Class<?> clazz = (Class<?>) genericType;
        return supportsInternal(clazz, this.checkForXmlRootElement);
    }
    return false;
}
项目:class-guard    文件:BeanInfoTests.java   
@Override
public void setAsText(String text) throws IllegalArgumentException {
    if (JdkVersion.getMajorJavaVersion() >= JdkVersion.JAVA_15) {
        Assert.isTrue(this.target instanceof ValueBean, "Target must be available on JDK 1.5+");
    }
    super.setAsText(text);
}
项目:class-guard    文件:ServiceLoaderTests.java   
@Test
public void testServiceLoaderFactoryBean() {
    if (JdkVersion.getMajorJavaVersion() < JdkVersion.JAVA_16 ||
            !ServiceLoader.load(DocumentBuilderFactory.class).iterator().hasNext()){
        return;
    }

    DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
    RootBeanDefinition bd = new RootBeanDefinition(ServiceLoaderFactoryBean.class);
    bd.getPropertyValues().add("serviceType", DocumentBuilderFactory.class.getName());
    bf.registerBeanDefinition("service", bd);
    ServiceLoader<?> serviceLoader = (ServiceLoader<?>) bf.getBean("service");
    assertTrue(serviceLoader.iterator().next() instanceof DocumentBuilderFactory);
}
项目:class-guard    文件:ServiceLoaderTests.java   
@Test
public void testServiceFactoryBean() {
    if (JdkVersion.getMajorJavaVersion() < JdkVersion.JAVA_16 ||
            !ServiceLoader.load(DocumentBuilderFactory.class).iterator().hasNext()){
        return;
    }

    DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
    RootBeanDefinition bd = new RootBeanDefinition(ServiceFactoryBean.class);
    bd.getPropertyValues().add("serviceType", DocumentBuilderFactory.class.getName());
    bf.registerBeanDefinition("service", bd);
    assertTrue(bf.getBean("service") instanceof DocumentBuilderFactory);
}
项目:class-guard    文件:ServiceLoaderTests.java   
@Test
public void testServiceListFactoryBean() {
    if (JdkVersion.getMajorJavaVersion() < JdkVersion.JAVA_16 ||
            !ServiceLoader.load(DocumentBuilderFactory.class).iterator().hasNext()){
        return;
    }

    DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
    RootBeanDefinition bd = new RootBeanDefinition(ServiceListFactoryBean.class);
    bd.getPropertyValues().add("serviceType", DocumentBuilderFactory.class.getName());
    bf.registerBeanDefinition("service", bd);
    List<?> serviceList = (List<?>) bf.getBean("service");
    assertTrue(serviceList.get(0) instanceof DocumentBuilderFactory);
}
项目:spring-osgi    文件:OsgiHttpIntegrationTest.java   
/**
 * {@inheritDoc}
 * 
 * <p/>Installs the required web bundles (such as Apache Tomcat) before
 * running the integration test.
 */
protected String[] getTestBundlesNames() {
    List col = new ArrayList();

    // Servlet/JSP artifacts
    col.add("javax.servlet, com.springsource.javax.servlet, 2.4.0");
    col.add(SPRING_OSGI_GROUP + ", jsp-api.osgi, 2.0-SNAPSHOT");

    // JSP compiler
    col.add(SPRING_OSGI_GROUP + ", jasper.osgi, 5.5.23-SNAPSHOT");
    col.add(SPRING_OSGI_GROUP + ", commons-el.osgi, 1.0-SNAPSHOT");

    // standard tag library
    col.add("org.springframework.osgi, jstl.osgi, 1.1.2-SNAPSHOT");

    // add MX4J for 1.4
    // if < jdk 1.5, add an JMX implementation
    if (!JdkVersion.isAtLeastJava15())
        col.add("net.sourceforge.mx4j, com.springsource.mx4j, 3.0.2");

    col.add(SPRING_OSGI_GROUP + ", catalina.osgi, 5.5.23-SNAPSHOT");
    col.add(SPRING_OSGI_GROUP + ", catalina.start.osgi, 1.0.0");

    // Spring DM web extender
    col.add(SPRING_OSGI_GROUP + ", spring-osgi-web," + getSpringDMVersion());
    col.add(SPRING_OSGI_GROUP + ", spring-osgi-web-extender," + getSpringDMVersion());
    col.add("net.sourceforge.cglib, com.springsource.net.sf.cglib, 2.1.3");

    // the war
    col.add(SPRING_OSGI_GROUP + ".samples.simple-web-app, war, " + getSpringDMVersion() + ",war");
    return (String[]) col.toArray(new String[col.size()]);
}
项目:spring-rich-client    文件:SwingDockingApplicationPageFactory.java   
public ApplicationPage createApplicationPage(ApplicationWindow window, PageDescriptor descriptor) {
    if (JdkVersion.isAtLeastJava16()) {
        return new TabbedSwingDockingApplicationPage(window, descriptor);
    } else if (JdkVersion.isAtLeastJava15()) {
        return new SwingDockingApplicationPage(window, descriptor);
    } else {
        return new DesktopApplicationPage(window, descriptor, JDesktopPane.OUTLINE_DRAG_MODE, new DefaultDesktopCommandGroupFactory());
    }
}
项目:spring-rich-client    文件:AbstractMemberPropertyAccessor.java   
/**
 * Determine the type of the key used to index the collection/map. When jdk
 * is at least 1.5, maps can be specified with generics and their key type
 * can be resolved.
 *
 * @param propertyName name of the property.
 * @return the type of the key. An integer if it's not a map, {@link String}
 * if the jdk is less than 1.5, a specific type if the map was generified.
 */
public Class getIndexedPropertyKeyType(String propertyName) {
    if (!PropertyAccessorUtils.isIndexedProperty(propertyName)) {
        throw new IllegalArgumentException("'" + propertyName + "' is no indexed property");
    }
    Class type = getPropertyType(getParentPropertyName(propertyName));
    if (!Map.class.isAssignableFrom(type)) {
        return Integer.class;
    }
    if (JdkVersion.isAtLeastJava15()) {
        int nestingLevel = PropertyAccessorUtils.getNestingLevel(propertyName) - 1;
        Member accessor = getPropertyAccessor(getRootPropertyName(propertyName));
        if (accessor instanceof Field) {
            return GenericCollectionTypeResolver.getMapKeyFieldType((Field) accessor, nestingLevel);
        }
        else if (accessor instanceof Method) {
            MethodParameter parameter = new MethodParameter((Method) accessor, ((Method) accessor)
                    .getParameterTypes().length - 1, nestingLevel);
            return GenericCollectionTypeResolver.getMapKeyParameterType(parameter);
        }
        else {
            throw new InvalidPropertyException(getTargetClass(), propertyName, "property not accessable");
        }
    }
    else {
        return String.class; // the default for Java 1.4
    }
}
项目:spring-richclient    文件:SwingDockingApplicationPageFactory.java   
public ApplicationPage createApplicationPage(ApplicationWindow window, PageDescriptor descriptor) {
    if (JdkVersion.isAtLeastJava16()) {
        return new TabbedSwingDockingApplicationPage(window, descriptor);
    } else if (JdkVersion.isAtLeastJava15()) {
        return new SwingDockingApplicationPage(window, descriptor);
    } else {
        return new DesktopApplicationPage(window, descriptor, JDesktopPane.OUTLINE_DRAG_MODE, new DefaultDesktopCommandGroupFactory());
    }
}
项目:spring-richclient    文件:AbstractMemberPropertyAccessor.java   
/**
 * Determine the type of the key used to index the collection/map. When jdk
 * is at least 1.5, maps can be specified with generics and their key type
 * can be resolved.
 *
 * @param propertyName name of the property.
 * @return the type of the key. An integer if it's not a map, {@link String}
 * if the jdk is less than 1.5, a specific type if the map was generified.
 */
public Class getIndexedPropertyKeyType(String propertyName) {
    if (!PropertyAccessorUtils.isIndexedProperty(propertyName)) {
        throw new IllegalArgumentException("'" + propertyName + "' is no indexed property");
    }
    Class type = getPropertyType(getParentPropertyName(propertyName));
    if (!Map.class.isAssignableFrom(type)) {
        return Integer.class;
    }
    if (JdkVersion.isAtLeastJava15()) {
        int nestingLevel = PropertyAccessorUtils.getNestingLevel(propertyName) - 1;
        Member accessor = getPropertyAccessor(getRootPropertyName(propertyName));
        if (accessor instanceof Field) {
            return GenericCollectionTypeResolver.getMapKeyFieldType((Field) accessor, nestingLevel);
        }
        else if (accessor instanceof Method) {
            MethodParameter parameter = new MethodParameter((Method) accessor, ((Method) accessor)
                    .getParameterTypes().length - 1, nestingLevel);
            return GenericCollectionTypeResolver.getMapKeyParameterType(parameter);
        }
        else {
            throw new InvalidPropertyException(getTargetClass(), propertyName, "property not accessable");
        }
    }
    else {
        return String.class; // the default for Java 1.4
    }
}
项目:class-guard    文件:TaskExecutorFactoryBean.java   
private boolean shouldUseBackport() {
    return (StringUtils.hasText(this.poolSize) && this.poolSize.startsWith("0") &&
            JdkVersion.getMajorJavaVersion() < JdkVersion.JAVA_16);
}
项目:class-guard    文件:ResourceBundleMessageSourceTests.java   
public void testMessageAccessWithDefaultMessageSourceAndFallbackTurnedOff() {
    if (JdkVersion.getMajorJavaVersion() < JdkVersion.JAVA_16) {
        return;
    }
    doTestMessageAccess(false, false, false, false, false);
}
项目:class-guard    文件:ResourceBundleMessageSourceTests.java   
public void testMessageAccessWithDefaultMessageSourceAndFallbackTurnedOffAndFallbackToGerman() {
    if (JdkVersion.getMajorJavaVersion() < JdkVersion.JAVA_16) {
        return;
    }
    doTestMessageAccess(false, false, true, true, false);
}
项目:class-guard    文件:ResourceBundleMessageSourceTests.java   
@Override
protected void tearDown() throws Exception {
    if (JdkVersion.getMajorJavaVersion() >= JdkVersion.JAVA_16) {
        ResourceBundle.clearCache();
    }
}
项目:class-guard    文件:SQLExceptionSubclassTranslatorTests.java   
public void testErrorCodeTranslation() {
    if (JdkVersion.getMajorJavaVersion() < JdkVersion.JAVA_16) {
        return;
    }

    SQLExceptionTranslator sext = new SQLErrorCodeSQLExceptionTranslator(ERROR_CODES);

    SQLException dataIntegrityViolationEx = SQLExceptionSubclassFactory.newSQLDataException("", "", 0);
    DataIntegrityViolationException divex = (DataIntegrityViolationException) sext.translate("task", "SQL", dataIntegrityViolationEx);
    assertEquals(dataIntegrityViolationEx, divex.getCause());

    SQLException featureNotSupEx = SQLExceptionSubclassFactory.newSQLFeatureNotSupportedException("", "", 0);
    InvalidDataAccessApiUsageException idaex = (InvalidDataAccessApiUsageException) sext.translate("task", "SQL", featureNotSupEx);
    assertEquals(featureNotSupEx, idaex.getCause());

    SQLException dataIntegrityViolationEx2 = SQLExceptionSubclassFactory.newSQLIntegrityConstraintViolationException("", "", 0);
    DataIntegrityViolationException divex2 = (DataIntegrityViolationException) sext.translate("task", "SQL", dataIntegrityViolationEx2);
    assertEquals(dataIntegrityViolationEx2, divex2.getCause());

    SQLException permissionDeniedEx = SQLExceptionSubclassFactory.newSQLInvalidAuthorizationSpecException("", "", 0);
    PermissionDeniedDataAccessException pdaex = (PermissionDeniedDataAccessException) sext.translate("task", "SQL", permissionDeniedEx);
    assertEquals(permissionDeniedEx, pdaex.getCause());

    SQLException dataAccessResourceEx = SQLExceptionSubclassFactory.newSQLNonTransientConnectionException("", "", 0);
    DataAccessResourceFailureException darex = (DataAccessResourceFailureException) sext.translate("task", "SQL", dataAccessResourceEx);
    assertEquals(dataAccessResourceEx, darex.getCause());

    SQLException badSqlEx2 = SQLExceptionSubclassFactory.newSQLSyntaxErrorException("", "", 0);
    BadSqlGrammarException bsgex2 = (BadSqlGrammarException) sext.translate("task", "SQL2", badSqlEx2);
    assertEquals("SQL2", bsgex2.getSql());
    assertEquals(badSqlEx2, bsgex2.getSQLException());

    SQLException tranRollbackEx = SQLExceptionSubclassFactory.newSQLTransactionRollbackException("", "", 0);
    ConcurrencyFailureException cfex = (ConcurrencyFailureException) sext.translate("task", "SQL", tranRollbackEx);
    assertEquals(tranRollbackEx, cfex.getCause());

    SQLException transientConnEx = SQLExceptionSubclassFactory.newSQLTransientConnectionException("", "", 0);
    TransientDataAccessResourceException tdarex = (TransientDataAccessResourceException) sext.translate("task", "SQL", transientConnEx);
    assertEquals(transientConnEx, tdarex.getCause());

    SQLException transientConnEx2 = SQLExceptionSubclassFactory.newSQLTimeoutException("", "", 0);
    QueryTimeoutException tdarex2 = (QueryTimeoutException) sext.translate("task", "SQL", transientConnEx2);
    assertEquals(transientConnEx2, tdarex2.getCause());

    SQLException recoverableEx = SQLExceptionSubclassFactory.newSQLRecoverableException("", "", 0);
    RecoverableDataAccessException rdaex2 = (RecoverableDataAccessException) sext.translate("task", "SQL", recoverableEx);
    assertEquals(recoverableEx, rdaex2.getCause());

    // Test classic error code translation. We should move there next if the exception we pass in is not one
    // of the new sub-classes.
    SQLException sexEct = new SQLException("", "", 1);
    BadSqlGrammarException bsgEct = (BadSqlGrammarException) sext.translate("task", "SQL-ECT", sexEct);
    assertEquals("SQL-ECT", bsgEct.getSql());
    assertEquals(sexEct, bsgEct.getSQLException());

    // Test fallback. We assume that no database will ever return this error code,
    // but 07xxx will be bad grammar picked up by the fallback SQLState translator
    SQLException sexFbt = new SQLException("", "07xxx", 666666666);
    BadSqlGrammarException bsgFbt = (BadSqlGrammarException) sext.translate("task", "SQL-FBT", sexFbt);
    assertEquals("SQL-FBT", bsgFbt.getSql());
    assertEquals(sexFbt, bsgFbt.getSQLException());
    // and 08xxx will be data resource failure (non-transient) picked up by the fallback SQLState translator
    SQLException sexFbt2 = new SQLException("", "08xxx", 666666666);
    DataAccessResourceFailureException darfFbt = (DataAccessResourceFailureException) sext.translate("task", "SQL-FBT2", sexFbt2);
    assertEquals(sexFbt2, darfFbt.getCause());
}
项目:class-guard    文件:ExtendedBeanInfoTests.java   
private boolean trueUntilJdk17() {
    return JdkVersion.getMajorJavaVersion() < JdkVersion.JAVA_17;
}
项目:spring-osgi    文件:BaseWebIntegrationTest.java   
protected String[] getTestFrameworkBundlesNames() {
    String[] def = super.getTestFrameworkBundlesNames();
    List col = new ArrayList();
    CollectionUtils.mergeArrayIntoCollection(def, col);

    System.setProperty("DEBUG", "false");
    // set this property (to whatever value) to get logging in Jetty
    //System.setProperty("VERBOSE", "false");

    // Servlet/JSP artifacts
    col.add("javax.servlet, com.springsource.javax.servlet, 2.4.0");
    col.add("org.springframework.osgi, jsp-api.osgi, 2.0-SNAPSHOT");

    // JSP compiler
    col.add("org.springframework.osgi, jasper.osgi, 5.5.23-SNAPSHOT");
    col.add("org.springframework.osgi, commons-el.osgi, 1.0-SNAPSHOT");

    // standard tag library
    col.add("org.springframework.osgi, jstl.osgi, 1.1.2-SNAPSHOT");

    // add MX4J for 1.4
    // if < jdk 1.5, add an JMX implementation
    if (!(JdkVersion.getMajorJavaVersion()>=JdkVersion.JAVA_15))
        col.add("net.sourceforge.mx4j, com.springsource.mx4j, 3.0.2");

    col.add("org.springframework.osgi, catalina.osgi, 5.5.23-SNAPSHOT");
    col.add("org.springframework.osgi, catalina.start.osgi, 1.0.0");

    // jetty starter
    //      col.add("org.springframework.osgi, jetty.start.osgi, 1.0.0");
    //      col.add("org.springframework.osgi, jetty.web.extender.fragment.osgi, 1.0.0");
    //      col.add("org.mortbay.jetty, jetty-util, 6.1.9");
    //      col.add("org.mortbay.jetty, jetty, 6.1.9");

    // Spring DM web extender
    col.add("org.springframework.osgi, spring-osgi-web," + getSpringDMVersion());
    col.add("org.springframework.osgi, spring-osgi-web-extender," + getSpringDMVersion());
    col.add("net.sourceforge.cglib, com.springsource.net.sf.cglib, 2.1.3");

    return (String[]) col.toArray(new String[col.size()]);
}
项目:spring-osgi    文件:ExtenderConfiguration.java   
private void addDefaultDependencyFactories() {
    boolean debug = log.isDebugEnabled();

    // default JDK 1.4 processor
    dependencyFactories.add(0, new MandatoryImporterDependencyFactory());

    // load through reflection the dependency and injection processors if running on JDK 1.5 and annotation processing is enabled
    if (processAnnotation) {
        if (JdkVersion.getMajorJavaVersion()>=JdkVersion.JAVA_15) {
            // dependency processor
            Class annotationProcessor = null;
            try {
                annotationProcessor = Class.forName(ANNOTATION_DEPENDENCY_FACTORY, false,
                    ExtenderConfiguration.class.getClassLoader());
            }
            catch (ClassNotFoundException cnfe) {
                log.warn("Spring DM annotation package not found, annotation processing disabled.", cnfe);
                return;
            }
            Object processor = BeanUtils.instantiateClass(annotationProcessor);
            Assert.isInstanceOf(OsgiServiceDependencyFactory.class, processor);
            dependencyFactories.add(1, (OsgiServiceDependencyFactory) processor);

            if (debug)
                log.debug("Succesfully loaded annotation dependency processor [" + ANNOTATION_DEPENDENCY_FACTORY
                        + "]");

            // add injection processor (first in line)
            postProcessors.add(0, new OsgiAnnotationPostProcessor());
            log.info("Spring-DM annotation processing enabled");
        }
        else {
            if (debug)
                log.debug("JDK 5 not available [" + ANNOTATION_DEPENDENCY_FACTORY + "] not loaded");
            log.warn("Spring-DM annotation processing enabled but JDK 5 is n/a; disabling annotation processing...");
        }
    }
    else {
        if (debug) {
            log.debug("Spring-DM annotation processing disabled; [" + ANNOTATION_DEPENDENCY_FACTORY
                    + "] not loaded");
        }
    }

}
项目:spring-osgi    文件:AbstractDependencyManagerTests.java   
/**
 * Returns the bundles that have to be installed as part of the test setup.
 * This method is preferred as the bundles are by their names rather then as
 * {@link Resource}s. It allows for a <em>declarative</em> approach for
 * specifying bundles as opposed to {@link #getTestBundles()} which provides
 * a programmatic one.
 * 
 * <p/>This implementation reads a predefined properties file to determine
 * the bundles needed. If the configuration needs to be changed, consider
 * changing the configuration location.
 * 
 * @return an array of testing framework bundle identifiers
 * @see #getTestingFrameworkBundlesConfiguration()
 * @see #locateBundle(String)
 * 
 */
protected String[] getTestFrameworkBundlesNames() {
    // load properties file
    Properties props = PropertiesUtil.loadAndExpand(getTestingFrameworkBundlesConfiguration());

    if (props == null)
        throw new IllegalArgumentException("cannot load default configuration from "
                + getTestingFrameworkBundlesConfiguration());

    boolean trace = logger.isTraceEnabled();

    if (trace)
        logger.trace("Loaded properties " + props);

    // pass properties to test instance running inside OSGi space
    System.getProperties().put(SPRING_OSGI_VERSION_PROP_KEY, props.get(SPRING_OSGI_VERSION_PROP_KEY));
    System.getProperties().put(SPRING_VERSION_PROP_KEY, props.get(SPRING_VERSION_PROP_KEY));

    Properties excluded = PropertiesUtil.filterKeysStartingWith(props, IGNORE);

    if (trace) {
        logger.trace("Excluded ignored properties " + excluded);
    }

    // filter bundles which are Tiger/JDK 1.5 specific
    String sign = null;
    if (JdkVersion.getMajorJavaVersion()>=JdkVersion.JAVA_15) {
        sign = "-15";
    }
    else {
        sign = "+15";
    }

    excluded = PropertiesUtil.filterValuesStartingWith(props, sign);
    if (trace)
        logger.trace("JDK " + JdkVersion.getJavaVersion() + " excluded bundles " + excluded);

    String[] bundles = (String[]) props.keySet().toArray(new String[props.size()]);
    // sort the array (as the Properties file doesn't respect the order)
    bundles = StringUtils.sortStringArray(bundles);

    if (logger.isDebugEnabled())
        logger.debug("Default framework bundles :" + ObjectUtils.nullSafeToString(bundles));

    return bundles;
}
项目:spring-rich-client    文件:SwingDockingApplicationPage.java   
protected JDesktopPane createDesktopPane() {
    if (!JdkVersion.isAtLeastJava15()) {
        throw new IllegalStateException("At least Java Version 5 is needed for Swing-Docking.");
    }
    return new DockingDesktopPane();
}
项目:spring-rich-client    文件:TabbedSwingDockingApplicationPage.java   
protected JDesktopPane createDesktopPane() {
    if (!JdkVersion.isAtLeastJava16()) {
        throw new IllegalStateException("At least Java Version 6 is needed for tabbed Swing-Docking.");
    }
    return new TabbingDesktopPane();
}
项目:spring-rich-client    文件:AbstractMemberPropertyAccessor.java   
/**
 * {@inheritDoc}
 */
public Class getPropertyType(String propertyName) {
    if (PropertyAccessorUtils.isIndexedProperty(propertyName)) {
        int nestingLevel = PropertyAccessorUtils.getNestingLevel(propertyName);
        if (JdkVersion.isAtLeastJava15()) {
            Member accessor = getPropertyAccessor(getRootPropertyName(propertyName));
            if (accessor instanceof Field) {
                return GenericCollectionTypeResolver.getIndexedValueFieldType((Field) accessor, nestingLevel);
            }
            else {
                Method accessorMethod = (Method) accessor;
                MethodParameter parameter = new MethodParameter(accessorMethod,
                        accessorMethod.getParameterTypes().length - 1);
                return GenericCollectionTypeResolver.getIndexedValueMethodType(parameter, nestingLevel);
            }
        }
        else {
            // we can only resolve array types in Java 1.4
            Class type = getPropertyType(getRootPropertyName(propertyName));
            for (int i = 0; i < nestingLevel; i++) {
                if (type.isArray()) {
                    type = type.getComponentType();
                }
                else {
                    return Object.class; // cannot resolve type
                }
            }
            return type;
        }
    }
    else {
        Member readAccessor = (Member) readAccessors.get(propertyName);
        if (readAccessor instanceof Field) {
            return ((Field) readAccessor).getType();
        }
        else if (readAccessor instanceof Method) {
            return ((Method) readAccessor).getReturnType();
        }
        Member writeAccessor = (Member) writeAccessors.get(propertyName);
        if (writeAccessor instanceof Field) {
            return ((Field) writeAccessor).getType();
        }
        else if (writeAccessor instanceof Method) {
            return ((Method) writeAccessor).getParameterTypes()[0];
        }
    }
    return null;
}
项目:spring-richclient    文件:SwingDockingApplicationPage.java   
protected JDesktopPane createDesktopPane() {
    if (!JdkVersion.isAtLeastJava15()) {
        throw new IllegalStateException("At least Java Version 5 is needed for Swing-Docking.");
    }
    return new DockingDesktopPane();
}
项目:spring-richclient    文件:TabbedSwingDockingApplicationPage.java   
protected JDesktopPane createDesktopPane() {
    if (!JdkVersion.isAtLeastJava16()) {
        throw new IllegalStateException("At least Java Version 6 is needed for tabbed Swing-Docking.");
    }
    return new TabbingDesktopPane();
}