List of usage examples for org.apache.commons.lang.reflect FieldUtils readField
public static Object readField(Object target, String fieldName, boolean forceAccess) throws IllegalAccessException
From source file:org.jfree.chart.plot.StackedXYPlot.java
/** * Adds a subplot with the specified weight * @param subplot the subplot (<code>null</code> not permitted). * @param weight the weight (must be >= 1). *///www . j a va 2 s . c o m @Override public void add(XYPlot subplot, int weight) { Objects.requireNonNull(subplot, "subplot must not be null"); if (weight <= 0) { throw new IllegalArgumentException("weight must be >= 1."); } subplot.setParent(this); subplot.setWeight(weight); subplot.addChangeListener(this); subplot.setRangeZeroBaselineVisible(false); subplot.setInsets(new RectangleInsets(0.0, 0.0, 0.0, 0.0), false); List subplots = Collections.EMPTY_LIST; try { subplots = (List) FieldUtils.readField(this, "subplots", true); } catch (IllegalAccessException ex) { Logger.getLogger(StackedXYPlot.class.getName()).log(Level.SEVERE, ex.getMessage(), ex); } subplots.add(subplot); ValueAxis axis = getDomainAxis(); if (axis != null) { axis.configure(); } fireChangeEvent(); }
From source file:org.jfree.chart.plot.StackedXYPlot.java
/** * Draws the plot./*from www. jav a 2 s. c o m*/ * @param graphics2d the graphics device. * @param plotArea the plot plotArea (in Java2D space). * @param anchor an anchor point in Java2D space (<code>null</code> permitted). * @param parentState the state from the parent plot (<code>null</code> permitted). * @param plotRenderingInfo chart drawing information (<code>null</code> permitted). */ @Override public void draw(Graphics2D graphics2d, Rectangle2D plotArea, Point2D anchor, PlotState parentState, PlotRenderingInfo plotRenderingInfo) { if (plotRenderingInfo != null) { plotRenderingInfo.setPlotArea(plotArea); } RectangleInsets insets = getInsets(); insets.trim(plotArea); setFixedRangeAxisSpaceForSubplots(null); //calculateAxisSpace will also calculate sub-plot plotArea AxisSpace space = calculateAxisSpace(graphics2d, plotArea); Rectangle2D dataArea = space.shrink(plotArea, null); Rectangle2D[] calculatedSubPlotAreas = null; //get subplotsAreas from parent class try { calculatedSubPlotAreas = (Rectangle2D[]) FieldUtils.readField(this, "subplotAreas", true); } catch (IllegalAccessException ex) { Logger.getLogger(StackedXYPlot.class.getName()).log(Level.SEVERE, ex.getMessage(), ex); } setFixedRangeAxisSpaceForSubplots(space); // draw all the subplots for (int i = 0; i < getSubplots().size(); i++) { XYPlot plot = (XYPlot) getSubplots().get(i); PlotRenderingInfo subplotInfo = null; if (plotRenderingInfo != null) { subplotInfo = new PlotRenderingInfo(plotRenderingInfo.getOwner()); plotRenderingInfo.addSubplotInfo(subplotInfo); } plot.draw(graphics2d, calculatedSubPlotAreas[i], anchor, parentState, subplotInfo); } if (plotRenderingInfo != null) { plotRenderingInfo.setDataArea(dataArea); } }
From source file:org.jodconverter.filter.DefaultFilterChainTest.java
/** Tests that a DefaultFilterChain is created empty by default. */ @Test//from ww w.j a v a2 s .com public void create_WithoutFilters_ShouldBeEmpty() throws IllegalAccessException { final DefaultFilterChain chain = new DefaultFilterChain(); final List<Filter> filters = (List<Filter>) FieldUtils.readField(chain, "filters", true); assertThat(filters).hasSize(0); }
From source file:org.jodconverter.filter.DefaultFilterChainTest.java
/** Tests that a DefaultFilterChain.addFilter works as expected. */ @Test// ww w. j a v a 2 s . c o m public void create_ShouldBeEditable() throws IllegalAccessException { final Filter filter = new RefreshFilter(); final DefaultFilterChain chain = new DefaultFilterChain(); chain.addFilter(filter); final List<Filter> filters = (List<Filter>) FieldUtils.readField(chain, "filters", true); assertThat(filters).hasSize(1); assertThat(filters).containsExactly(filter); }
From source file:org.jodconverter.office.AbstractOfficeManagerPoolTest.java
@Test public void create_WithCustomConfig_ShouldUseCustomConfig() throws Exception { final SimpleOfficeManagerPoolConfig config = new SimpleOfficeManagerPoolConfig( new File(System.getProperty("java.io.tmpdir"))); config.setWorkingDir(testFolder.getRoot()); config.setTaskExecutionTimeout(5000L); config.setTaskQueueTimeout(9000L);/*from w w w.j a v a 2 s.c o m*/ final AbstractOfficeManagerPool pool = new AbstractOfficeManagerPool(1, config) { @Override protected OfficeManager[] createPoolEntries() { return new OfficeManager[1]; } }; final SimpleOfficeManagerPoolConfig setupConfig = (SimpleOfficeManagerPoolConfig) FieldUtils.readField(pool, "config", true); assertThat(setupConfig.getWorkingDir().getPath()).isEqualTo(testFolder.getRoot().getPath()); assertThat(setupConfig.getTaskExecutionTimeout()).isEqualTo(5000L); assertThat(setupConfig.getTaskQueueTimeout()).isEqualTo(9000L); }
From source file:org.jodconverter.office.LocalOfficeManagerBuilderITest.java
@Test public void build_WithDefaultValues_ShouldInitializedOfficeManagerWithDefaultValues() throws Exception { final OfficeManager manager = new DefaultOfficeManagerBuilder().build(); assertThat(manager).isInstanceOf(AbstractOfficeManagerPool.class); final OfficeProcessManagerPoolConfig config = (OfficeProcessManagerPoolConfig) FieldUtils.readField(manager, "config", true); assertThat(config.getOfficeHome().getPath()).isEqualTo(LocalOfficeUtils.getDefaultOfficeHome().getPath()); assertThat(config.getWorkingDir().getPath()) .isEqualTo(new File(System.getProperty("java.io.tmpdir")).getPath()); assertThat(config.getProcessManager()).isEqualTo(LocalOfficeUtils.findBestProcessManager()); assertThat(config.getRunAsArgs()).isNull(); assertThat(config.getTemplateProfileDir()).isNull(); assertThat(config.isKillExistingProcess()).isTrue(); assertThat(config.getProcessTimeout()).isEqualTo(120000L); assertThat(config.getProcessRetryInterval()).isEqualTo(250L); assertThat(config.getMaxTasksPerProcess()).isEqualTo(200); assertThat(config.getTaskExecutionTimeout()).isEqualTo(120000L); assertThat(config.getTaskQueueTimeout()).isEqualTo(30000L); final OfficeUrl[] officeUrls = (OfficeUrl[]) FieldUtils.readField(manager, "officeUrls", true); assertThat(officeUrls).hasSize(1);/*from w w w .j a va 2 s. c om*/ assertThat(officeUrls[0].getConnectionAndParametersAsString()) .isEqualTo("socket,host=127.0.0.1,port=2002,tcpNoDelay=1"); }
From source file:org.jodconverter.office.LocalOfficeManagerBuilderITest.java
@Test public void build_WithCustomValues_ShouldInitializedOfficeManagerWithCustomValues() throws Exception { final OfficeManager manager = new DefaultOfficeManagerBuilder() .setConnectionProtocol(OfficeConnectionProtocol.PIPE).setPipeNames("test").setPortNumbers(2003) .setOfficeHome(LocalOfficeUtils.getDefaultOfficeHome()) .setWorkingDir(System.getProperty("java.io.tmpdir")) .setTemplateProfileDir("src/integTest/resources/templateProfileDir") .setProcessManager(LocalOfficeUtils.findBestProcessManager()).setRunAsArgs("sudo") .setKillExistingProcess(false).setRetryTimeout(5000).setRetryInterval(1000) .setMaxTasksPerProcess(10).setTaskExecutionTimeout(20000).setTaskQueueTimeout(1000).build(); assertThat(manager).isInstanceOf(AbstractOfficeManagerPool.class); final OfficeProcessManagerPoolConfig config = (OfficeProcessManagerPoolConfig) FieldUtils.readField(manager, "config", true); assertThat(config.getOfficeHome().getPath()).isEqualTo(LocalOfficeUtils.getDefaultOfficeHome().getPath()); assertThat(config.getWorkingDir().getPath()) .isEqualTo(new File(System.getProperty("java.io.tmpdir")).getPath()); assertThat(config.getTemplateProfileDir().getPath()) .isEqualTo(new File("src/integTest/resources/templateProfileDir").getPath()); assertThat(config.getProcessManager()).isEqualTo(LocalOfficeUtils.findBestProcessManager()); assertThat(config.getRunAsArgs()).isEqualTo(new String[] { "sudo" }); assertThat(config.isKillExistingProcess()).isEqualTo(false); assertThat(config.getProcessTimeout()).isEqualTo(5000L); assertThat(config.getProcessRetryInterval()).isEqualTo(1000L); assertThat(config.getMaxTasksPerProcess()).isEqualTo(10); assertThat(config.getTaskExecutionTimeout()).isEqualTo(20000L); assertThat(config.getTaskQueueTimeout()).isEqualTo(1000L); final OfficeUrl[] officeUrls = (OfficeUrl[]) FieldUtils.readField(manager, "officeUrls", true); assertThat(officeUrls).hasSize(1);//w w w . ja v a 2 s . c om assertThat(officeUrls[0].getConnectionAndParametersAsString()).isEqualTo("pipe,name=test"); }
From source file:org.jodconverter.office.LocalOfficeManagerBuilderITest.java
@Test public void build_WithValuesAsString_ShouldInitializedOfficeManagerWithCustomValues() throws Exception { final OfficeManager manager = new DefaultOfficeManagerBuilder() .setOfficeHome(LocalOfficeUtils.getDefaultOfficeHome().getPath()) .setWorkingDir(new File(System.getProperty("java.io.tmpdir")).getPath()) .setProcessManager(LocalOfficeUtils.findBestProcessManager().getClass().getName()).build(); assertThat(manager).isInstanceOf(AbstractOfficeManagerPool.class); final OfficeProcessManagerPoolConfig config = (OfficeProcessManagerPoolConfig) FieldUtils.readField(manager, "config", true); assertThat(config.getOfficeHome().getPath()).isEqualTo(LocalOfficeUtils.getDefaultOfficeHome().getPath()); assertThat(config.getWorkingDir().getPath()) .isEqualTo(new File(System.getProperty("java.io.tmpdir")).getPath()); assertThat(config.getProcessManager().getClass().getName()) .isEqualTo(LocalOfficeUtils.findBestProcessManager().getClass().getName()); }
From source file:org.jodconverter.office.LocalOfficeManagerBuilderITest.java
@Test public void build_WithEmptyValuesAsString_ShouldInitializedOfficeManagerWithDefaultValues() throws Exception { final OfficeManager manager = new DefaultOfficeManagerBuilder().setOfficeHome(" ").setWorkingDir(" ") .setProcessManager(" ").setTemplateProfileDir(" ").build(); assertThat(manager).isInstanceOf(AbstractOfficeManagerPool.class); final OfficeProcessManagerPoolConfig config = (OfficeProcessManagerPoolConfig) FieldUtils.readField(manager, "config", true); assertThat(config.getOfficeHome().getPath()).isEqualTo(LocalOfficeUtils.getDefaultOfficeHome().getPath()); assertThat(config.getWorkingDir().getPath()) .isEqualTo(new File(System.getProperty("java.io.tmpdir")).getPath()); assertThat(config.getProcessManager()).isEqualTo(LocalOfficeUtils.findBestProcessManager()); }
From source file:org.jodconverter.office.LocalOfficeManagerBuilderITest.java
@Test public void build_WithPipeDefaultConfiguration_ShouldInitializedOfficeManagerWithDefaultPipe() throws Exception { final OfficeManager manager = new DefaultOfficeManagerBuilder() .setConnectionProtocol(OfficeConnectionProtocol.PIPE).build(); final OfficeUrl[] officeUrls = (OfficeUrl[]) FieldUtils.readField(manager, "officeUrls", true); assertThat(officeUrls).hasSize(1);//from www. j a v a 2s . co m assertThat(officeUrls[0]).isInstanceOf(OfficeUrl.class); assertThat(officeUrls[0].getConnectionAndParametersAsString()).isEqualTo("pipe,name=office"); }