如何为List创建ConstraintValidator

我有一个简单的validation器来validationString值是预定义列表的一部分: public class CoBoundedStringConstraints implements ConstraintValidator { private List m_boundedTo; @Override public void initialize(CoBoundedString annotation) { m_boundedTo = FunctorUtils.transform(annotation.value(), new ToLowerCase()); } @Override public boolean isValid(String value, ConstraintValidatorContext context) { if (value == null ) { return true; } context.disableDefaultConstraintViolation(); context.buildConstraintViolationWithTemplate(“should be one of ” + m_boundedTo).addConstraintViolation(); return m_boundedTo.contains(value.toLowerCase()); } } 例如,它将validation: @CoBoundedString({“a”,”b” }) public […]

使用nodeList创建XML文档

我需要使用NodeList创建一个XML Document对象。 有人可以帮我做这件事。 我已经向您展示了下面的代码和xml import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.xpath.*; import org.w3c.dom.*; public class ReadFile { public static void main(String[] args) { String exp = “/configs/markets”; String path = “testConfig.xml”; try { Document xmlDocument = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(path); XPath xPath = XPathFactory.newInstance().newXPath(); XPathExpression xPathExpression = xPath.compile(exp); NodeList nodes = (NodeList) xPathExpression.evaluate(xmlDocument, XPathConstants.NODESET); } catch (Exception ex) { ex.printStackTrace(); } […]

AspectJ切入点表达式匹配任何位置的参数注释

我正在尝试定义切入点表达式以匹配包含用特定注释注释的参数的方法,无论参数位于何处。在我的情况下,我正在寻找@Constraint注释。 例如: 匹配方法: public void method1(@Constraint Car car) public void method2(String id, @Constraint Plane plane) public void method3(Wheel wheel, @Constraint List trains, @Constraint Plane plane) public void method4(Motor motor, @Constraint Set trains, Bicycle bike, Wheel wheel) public void method5(Wing wing, Motorcycle moto, @Constraint Truck truck, Bicycle bike, Wheel wheel) 到目前为止,我已经尝试了以下表达式而没有运气: @Before(“execution(public * *.*(..)) and @args(com.example.Constraint)”) […]

Javamail NTLM身份validation失败

尝试在JavaMail中使用NTLM连接到Exchange服务器。 我可以连接到SMTP,但不能连接到IMAP。 我还可以使用相同的主机/用户名/密码,帐户类型=“IMAP”,端口143,ssl = false,身份validation= NTLM,域名=“”通过OS X Mail.app应用程序进行身份validation。 连接代码: import javax.mail.Session; import javax.mail.Transport; import javax.mail.Store; import java.util.Properties; public class NTLMTest { public static void main(String[] args) throws Exception { final String host = “example.com”; final String user = “bob”; final String password = “password”; final Properties properties = new Properties(); Session session = Session.getDefaultInstance(properties); session.setDebug(true); […]

如何在Java中混合两个数组?

我有一些String []数组,例如: [‘a1’, ‘a2’] [‘b1’, ‘b2’, ‘b3’, ‘b4’] [‘c1’] 我如何混合它们,以便得到[‘a1’, ‘b1’, ‘c1’, ‘a2’, ‘b2’, ‘b3’, ‘b4’] (a的0个元素,然后是b,c, a,b,c等1个元素)? 谢谢 更准确地说,结果数组必须包含第一个数组的第一个值,然后是第二个数组的第一个值,…,最后一个数组的第一个值,第一个数组的第二个值,……,最后一个数组的第二个值,…,最大数组的最后一个值。 如果数组的大小不同,那么较小的数组就不会被考虑在内。 这是一个例子: a1 a2 a3 a4 b1 b2 b3 b4 b5 b6 b7 c1 c2 d1 d2 d3 d4 d5 Combines into (brackets are just to highlight steps, so they really mean nothing): (a1 b1 […]

Tomcat Valve设置

我认为我遇到了一些配置问题。 我需要保护我的实际tomcat应用程序中的文件夹不受某个IP范围的访问。 我以为这是服务器故障 ,所以我在那里发布了问题。 现在我不确定这是SO还是SF呢…… 尽管如此,我还是继续尝试自己去做,并认为我需要设置它 org.apache.catalina.valves.RemoteAddrValve 对于我的那个文件夹。 可悲的是,我无法得到我需要的地方。 web.xml,server.xml? 试过两次,成功无效。 任何人都可以帮我解决这个问题。 TIA ķ

如何使用Webdriver Selenium获取“style”元素的值

我想检查样式元素的值是否大于特定值(即,是> 666px?),但我无法得到该值。 以下是我要捕获的样式的HTML代码: 我正在使用此代码尝试打印其值,但它不打印: System.out.print(driver.findElement(By.id(“da1c”)).findElement(By.cssSelector(“span”)).getAttribute(“style”)); 我想要这样的东西: if ((driver.findElement(By.id(“da1c”)).findElement(By.cssSelector(“span”)).getAttribute(“style”)).value> 700) { System.out.println(“value exceeding”) }

Applet – 服务器通信,我该怎么办呢?

我有一个applet,我必须向Web应用程序发送请求,以从数据库中的服务器获取数据。 我正在使用对象,服务器响应对象非常有用!! applet如何与服务器通信? 我认为Web服务方法,RMI和……让我开心,但哪个最好又可靠?

ExecutorService.invokeAll不支持可运行任务的收集

想通过ExecutorService的 invokeAll(..)方法运行Runnable任务的集合。 但是现在不支持( 仅支持可调用任务的集合 ) 有什么具体的原因吗? 做类似事情的替代方案是什么。

关闭子框架(Java + iReport)时如何防止父框架关闭?

基本上我想从我的主应用程序上的按钮调用JasperViewer 。 我用这个 private void btnExportActionPerformed(java.awt.event.ActionEvent evt) { try { JasperPrint printer = JasperFillManager.fillReport(getClass().getResourceAsStream(“reportRecharge.jasper”), params, new JREmptyDataSource()); JasperViewer jv = new JasperViewer(printer); jv.setVisible(true); } catch (JRException ex) { ex.printStackTrace(); } } 当JasperViewer出现并关闭它时, main frame / parent main frame也关闭。 我尝试添加jv.setDefaultCloseOperation(HIDE_ON_CLOSE); 但它也没有用。 怎么弄呢? 任何帮助,将不胜感激。