List of usage examples for java.util.concurrent CancellationException CancellationException
public CancellationException()
From source file:com.amazonaws.services.simpleworkflow.flow.worker.AsyncDecider.java
private void handleWorkflowExecutionCancelRequested(HistoryEvent event) throws Throwable { workflowContext.setCancelRequested(true); workflowAsyncScope.cancel(new CancellationException()); cancelRequested = true;// w ww.java2s .c o m }
From source file:ca.sqlpower.wabit.dao.WorkspaceSAXHandler.java
/** * Throws a {@link CancellationException} if either the loading of the file * was cancelled by a method call or cancelled internally due to a problem * in the file. If there was a problem with the file this method will notify * the user and another notification does not need to be sent. * <p>//from w w w.j av a2s. co m * * @see WorkspaceXMLDAO#FILE_VERSION */ private void startElementImpl(final String uri, final String localName, final String name, Attributes attributes) throws SAXException { if (isCancelled()) { return; } xmlContext.push(name); final WabitObject createdObject; if (name.equals("wabit")) { createdObject = null; String versionString = attributes.getValue("export-format"); //NOTE: For correct versioning behaviour see WorkspaceXMLDAO.FILE_VERSION. if (versionString == null) { UserPrompter up = promptFactory.createUserPrompter( "This Wabit workspace file is very old. It may not read correctly, but I will try my best.", UserPromptType.MESSAGE, UserPromptOptions.OK, UserPromptResponse.OK, null, "OK"); up.promptUser(); } else { Version fileVersion = new Version(versionString); Version fileMajorMinorVersion = new Version(fileVersion, 2); Version currentMajorMinorVersion = new Version(WorkspaceXMLDAO.FILE_VERSION, 2); Version fileMajorVersion = new Version(fileVersion, 1); Version currentMajorVersion = new Version(WorkspaceXMLDAO.FILE_VERSION, 1); String message = null; boolean displayMessage = true; if (fileMajorVersion.compareTo(currentMajorVersion) < 0) { message = "The Wabit workspace you are opening is too old to be successfully loaded.\n" + "An older version of Wabit is required to view the saved workspace."; setCancelled(true); } else if (fileVersion.equals(new Version("1.0.0"))) { message = "The Wabit workspace you are opening is an old version that does not record\n" + "information about page orientation. All pages will default to portrait orientation."; } else if (fileVersion.compareTo(new Version("1.1.0")) < 0) { message = "The Wabit workspace you are opening contains OLAP and/or reports from an.\n" + "old version of the wabit. These items cannot be loaded and need to be updated\n" + "to the latest version."; } else if (fileVersion.compareTo(new Version("1.2.0")) < 0) { message = "The Wabit workspace you are opening was created in an older version of Wabit\n" + "which stored charts within reports rather than sharing them within the Workspace.\n" + "Your charts will appear as empty boxes; you will have to re-create them."; } else if (fileMajorMinorVersion.compareTo(currentMajorMinorVersion) > 0) { message = "The Wabit workspace you are opening was created in a newer version of Wabit.\n" + "Due to large changes in the file format this file cannot be loaded without updating " + "Wabit."; setCancelled(true); } else if (fileVersion.compareTo(WorkspaceXMLDAO.FILE_VERSION) > 0) { message = "The Wabit workspace you are opening was created in a newer version of Wabit.\n" + "I will attempt to load this workspace but it is recommended to update Wabit\n" + "to the latest version."; } else { displayMessage = false; } if (fileVersion.compareTo(new Version("1.2.5")) >= 0) { nameMandatory = true; uuidMandatory = true; } else { nameMandatory = false; uuidMandatory = false; } if (displayMessage) { UserPrompter up = promptFactory.createUserPrompter(message, UserPromptType.MESSAGE, UserPromptOptions.OK, UserPromptResponse.OK, null, "OK"); up.promptUser(); } if (isCancelled()) throw new CancellationException(); } } else if (name.equals("project")) { createdObject = session.getWorkspace(); } else if (name.equals("data-source")) { String dsName = attributes.getValue("name"); checkMandatory("name", dsName); progressMessage = session.getWorkspace().getName() + ": loading data source " + dsName; SPDataSource ds = dsCollection.getDataSource(dsName); if (ds == null) { List<Class<? extends SPDataSource>> dsTypes = new ArrayList<Class<? extends SPDataSource>>(); dsTypes.add(JDBCDataSource.class); dsTypes.add(Olap4jDataSource.class); //Note: the new prompt here is so that on the server side the user still has the //option of creating a new datasource UserPrompter prompter = promptFactory.createDatabaseUserPrompter( "The data source \"" + dsName + "\" does not exist. Please select a replacement.", dsTypes, UserPromptOptions.OK_NEW_NOTOK_CANCEL, UserPromptResponse.NOT_OK, null, dsCollection, "Select Data Source", "New...", "Skip Data Source", "Cancel Load"); UserPromptResponse response = prompter.promptUser(); if (response == UserPromptResponse.OK || response == UserPromptResponse.NEW) { ds = (SPDataSource) prompter.getUserSelectedResponse(); createdObject = new WabitDataSource(ds); if (!session.getWorkspace().dsAlreadyAdded(ds)) { session.getWorkspace().addDataSource(ds); } oldToNewDSNames.put(dsName, ds.getName()); } else if (response == UserPromptResponse.NOT_OK) { ds = null; createdObject = null; } else { setCancelled(true); createdObject = null; } } else if (!session.getWorkspace().dsAlreadyAdded(ds)) { session.getWorkspace().addDataSource(ds); createdObject = new WabitDataSource(ds); } else { createdObject = null; } } else if (name.equals("query")) { cache = new QueryCache(session.getContext(), false); createdObject = cache; String queryName = attributes.getValue("name"); cache.setName(queryName); progressMessage = session.getWorkspace().getName() + " : loading query " + queryName; for (int i = 0; i < attributes.getLength(); i++) { String aname = attributes.getQName(i); String aval = attributes.getValue(i); if (aname.equals("uuid")) { // already loaded } else if (aname.equals("name")) { // already loaded } else if (aname.equals("data-source")) { JDBCDataSource ds = session.getWorkspace().getDataSource(aval, JDBCDataSource.class); if (ds == null) { String newDSName = oldToNewDSNames.get(aval); if (newDSName != null) { ds = session.getWorkspace().getDataSource(newDSName, JDBCDataSource.class); if (ds == null) { logger.debug("Data source " + aval + " is not in the workspace. Attempted to replace with new data source " + newDSName + ". Query " + aname + " was connected to it previously."); throw new NullPointerException( "Data source " + newDSName + " was not found in the workspace."); } } logger.debug("Workspace has data sources " + session.getWorkspace().getDataSources()); } cache.setDataSourceWithoutSideEffects(ds); } else if (aname.equals("zoom")) { cache.setZoomLevel(Integer.parseInt(aval)); } else if (aname.equals("streaming-row-limit")) { cache.setStreamingRowLimit(Integer.parseInt(aval)); } else if (aname.equals("row-limit")) { cache.setRowLimit(Integer.parseInt(aval)); } else if (aname.equals("grouping-enabled")) { cache.setGroupingEnabled(Boolean.parseBoolean(aval)); } else if (aname.equals("prompt-for-cross-joins")) { cache.setPromptForCrossJoins(Boolean.parseBoolean(aval)); } else if (aname.equals("execute-queries-with-cross-joins")) { cache.setExecuteQueriesWithCrossJoins(Boolean.parseBoolean(aval)); } else if (aname.equals("automatically-executing")) { cache.setAutomaticallyExecuting(Boolean.parseBoolean(aval)); } else if (aname.equals("streaming")) { cache.setStreaming(Boolean.parseBoolean(aval)); } else { logger.warn("Unexpected attribute of <query>: " + aname + "=" + aval); } } session.getWorkspace().addQuery(cache, session); } else if (name.equals("constants")) { createdObject = null; String uuid = attributes.getValue("uuid"); checkMandatory("uuid", uuid); cache.getConstantsContainer().setUUID(uuid); Container constants = cache.getConstantsContainer(); for (int i = 0; i < attributes.getLength(); i++) { String aname = attributes.getQName(i); String aval = attributes.getValue(i); if (aname.equals("uuid")) { // already loaded } else if (aname.equals("xpos")) { constants.setPosition( new Point2D.Double(Double.parseDouble(aval), constants.getPosition().getY())); logger.debug("Constants container is at position " + constants.getPosition()); } else if (aname.equals("ypos")) { constants.setPosition( new Point2D.Double(constants.getPosition().getX(), Double.parseDouble(aval))); } else { logger.warn("Unexpected attribute of <constants>: " + aname + "=" + aval); } } } else if (name.equals("table")) { createdObject = null; String tableName = attributes.getValue("name"); String schema = attributes.getValue("schema"); String catalog = attributes.getValue("catalog"); String uuid = attributes.getValue("uuid"); checkMandatory("uuid", uuid); checkMandatory("name", tableName); TableContainer table = new TableContainer(uuid, cache.getDatabase(), tableName, schema, catalog, new ArrayList<SQLObjectItem>()); for (int i = 0; i < attributes.getLength(); i++) { String aname = attributes.getQName(i); String aval = attributes.getValue(i); if (aname.equals("name") || aname.equals("schema") || aname.equals("catalog") || aname.equals("uuid")) { // already loaded. } else if (aname.equals("xpos")) { table.setPosition(new Point2D.Double(Double.parseDouble(aval), table.getPosition().getY())); } else if (aname.equals("ypos")) { table.setPosition(new Point2D.Double(table.getPosition().getX(), Double.parseDouble(aval))); } else if (aname.equals("alias")) { table.setAlias(aval); } else { logger.warn("Unexpected attribute of <table>: " + aname + "=" + aval); } } container = table; containerItems = new ArrayList<SQLObjectItem>(); } else if (name.equals("column")) { createdObject = null; if (parentIs("constants")) { String itemName = attributes.getValue("name"); String uuid = attributes.getValue("id"); checkMandatory("name", itemName); checkMandatory("id", uuid); Item item = new StringItem(itemName, uuid); for (int i = 0; i < attributes.getLength(); i++) { String aname = attributes.getQName(i); String aval = attributes.getValue(i); if (aname.equals("name") || aname.equals("id")) { //already loaded. } else if (aname.equals("alias")) { item.setAlias(aval); } else if (aname.equals("where-text")) { item.setWhere(aval); } else if (aname.equals("group-by")) { item.setGroupBy(SQLGroupFunction.valueOf(aval)); } else if (aname.equals("having")) { item.setHaving(aval); } else if (aname.equals("order-by")) { item.setOrderBy(OrderByArgument.valueOf(aval)); } else { logger.warn("Unexpected attribute of <constant-column>: " + aname + "=" + aval); } } cache.getConstantsContainer().addItem(item); uuidToItemMap.put(uuid, item); } else if (parentIs("table")) { String itemName = attributes.getValue("name"); String uuid = attributes.getValue("id"); checkMandatory("name", itemName); checkMandatory("id", uuid); SQLObjectItem item = new SQLObjectItem(itemName, uuid); for (int i = 0; i < attributes.getLength(); i++) { String aname = attributes.getQName(i); String aval = attributes.getValue(i); if (aname.equals("name") || aname.equals("id")) { //already loaded. } else if (aname.equals("alias")) { item.setAlias(aval); } else if (aname.equals("where-text")) { item.setWhere(aval); } else if (aname.equals("group-by")) { item.setGroupBy(SQLGroupFunction.valueOf(aval)); } else if (aname.equals("having")) { item.setHaving(aval); } else if (aname.equals("order-by")) { item.setOrderBy(OrderByArgument.valueOf(aval)); } else { logger.warn("Unexpected attribute of <constant-column>: " + aname + "=" + aval); } } containerItems.add(item); uuidToItemMap.put(uuid, item); } else if (parentIs("select")) { String uuid = attributes.getValue("id"); checkMandatory("id", uuid); if (uuidToItemMap.get(uuid) == null) { throw new IllegalStateException( "Cannot find a column with id " + uuid + " to add to the select statement."); } cache.selectItem(uuidToItemMap.get(uuid)); } else { throw new IllegalStateException( "A column is being loaded that is not contained by any tables. Parent is " + xmlContext.get(xmlContext.size() - 2)); } } else if (name.equals("join")) { createdObject = null; String leftUUID = attributes.getValue("left-item-id"); String rightUUID = attributes.getValue("right-item-id"); checkMandatory("left-item-id", leftUUID); checkMandatory("right-item-id", rightUUID); Item leftItem = uuidToItemMap.get(leftUUID); Item rightItem = uuidToItemMap.get(rightUUID); if (leftItem == null) { throw new IllegalStateException( "The left side of a join was not found. Trying to match UUID " + leftUUID); } if (rightItem == null) { throw new IllegalStateException( "The right side of a join was not found. Trying to match UUID " + rightUUID); } SQLJoin join = new SQLJoin(leftItem, rightItem); for (int i = 0; i < attributes.getLength(); i++) { String aname = attributes.getQName(i); String aval = attributes.getValue(i); if (aname.equals("left-item-id") || aname.equals("right-item-id")) { // already loaded } else if (aname.equals("left-is-outer")) { join.setLeftColumnOuterJoin(Boolean.parseBoolean(aval)); } else if (aname.equals("right-is-outer")) { join.setRightColumnOuterJoin(Boolean.parseBoolean(aval)); } else if (aname.equals("comparator")) { join.setComparator(aval); } else { logger.warn("Unexpected attribute of <join>: " + aname + "=" + aval); } } cache.addJoin(join); } else if (name.equals("select")) { createdObject = null; // Select portion loaded in the "column" part above. } else if (name.equals("global-where")) { createdObject = null; cache.setGlobalWhereClause(attributes.getValue("text")); } else if (name.equals("group-by-aggregate")) { // For backwards compatibility to Wabit 0.9.6 and older createdObject = null; String uuid = attributes.getValue("column-id"); String aggregate = attributes.getValue("aggregate"); checkMandatory("column-id", uuid); checkMandatory("aggregate", aggregate); Item item = uuidToItemMap.get(uuid); if (item == null) { throw new IllegalStateException( "Could not get a column for grouping. Trying to match UUID " + uuid); } cache.setGroupingEnabled(true); item.setGroupBy(SQLGroupFunction.getGroupType(aggregate)); } else if (name.equals("having")) { // For backwards compatibility to Wabit 0.9.6 and older createdObject = null; String uuid = attributes.getValue("column-id"); String text = attributes.getValue("text"); checkMandatory("column-id", uuid); checkMandatory("text", text); Item item = uuidToItemMap.get(uuid); if (item == null) { throw new IllegalStateException( "Could not get a column to add a having filter. Trying to match UUID " + uuid); } cache.setGroupingEnabled(true); item.setHaving(text); } else if (name.equals("order-by")) { createdObject = null; String uuid = attributes.getValue("column-id"); checkMandatory("column-id", uuid); Item item = uuidToItemMap.get(uuid); if (item == null) { throw new IllegalStateException( "Could not get a column to add order by to the select statement. Trying to match UUID " + uuid); } for (int i = 0; i < attributes.getLength(); i++) { String aname = attributes.getQName(i); String aval = attributes.getValue(i); if (aname.equals("column-id")) { //already loaded. } if (aname.equals("direction")) {// For backwards compatibility to Wabit 0.9.6 and older item.setOrderBy(OrderByArgument.valueOf(aval)); } else { logger.warn("Unexpected attribute of <order-by>: " + aname + " = " + aval); } } //Reinserting the items for cases where when the items were first created they defined a sort //order and were placed in the query in an incorrect order to sort the columns in. cache.moveOrderByItemToEnd(item); } else if (name.equals("query-string")) { createdObject = null; String queryString = attributes.getValue("string"); checkMandatory("string", queryString); cache.setUserModifiedQuery(queryString); } else if (name.equals("text") && parentIs("query")) { createdObject = null; } else if (name.equals("olap-query")) { olapName = attributes.getValue("name"); olapID = attributes.getValue("uuid"); String dsName = attributes.getValue("data-source"); olapDataSource = session.getWorkspace().getDataSource(dsName, Olap4jDataSource.class); if (olapDataSource == null) { String newDSName = oldToNewDSNames.get(dsName); if (newDSName != null) { olapDataSource = session.getWorkspace().getDataSource(newDSName, Olap4jDataSource.class); if (olapDataSource == null) { logger.debug("Data source " + dsName + " is not in the workspace or was not of the correct type. Attempted to replace with new data source " + newDSName + ". Query " + "data-source" + " was connected to it previously."); throw new NullPointerException("Data source " + newDSName + " was not found in the workspace or was not an Olap4j Datasource."); } } logger.debug("Workspace has data sources " + session.getWorkspace().getDataSources()); } createdObject = null; } else if (name.equals("olap-cube")) { catalogName = attributes.getValue("catalog"); schemaName = attributes.getValue("schema"); cubeName = attributes.getValue("cube-name"); createdObject = null; } else if (name.equals("olap4j-query")) { olapQuery = new OlapQuery(olapID, session.getContext(), attributes.getValue("name"), attributes.getValue("name"), catalogName, schemaName, cubeName, attributes.getValue("modifiedOlapQuery"), !isInLayout); olapQuery.setName(olapName); olapQuery.setOlapDataSource(olapDataSource); if (cellSetRenderer == null) { session.getWorkspace().addOlapQuery(olapQuery); } else { cellSetRenderer.setModifiedOlapQuery(olapQuery); } createdObject = null; } else if (name.equals("olap4j-axis")) { olapAxis = new WabitOlapAxis( org.olap4j.Axis.Factory.forOrdinal(Integer.parseInt(attributes.getValue("ordinal")))); olapQuery.addAxis(olapAxis); createdObject = olapAxis; } else if (name.equals("olap4j-dimension")) { olapDimension = new WabitOlapDimension(attributes.getValue("dimension-name")); olapAxis.addDimension(olapDimension); createdObject = olapDimension; } else if (name.equals("olap4j-selection")) { WabitOlapInclusion olapInclusion = new WabitOlapInclusion( Operator.valueOf(attributes.getValue("operator")), attributes.getValue("unique-member-name")); olapDimension.addInclusion(olapInclusion); createdObject = olapInclusion; } else if (name.equals("olap4j-exclusion")) { WabitOlapExclusion olapExclusion = new WabitOlapExclusion( Operator.valueOf(attributes.getValue("operator")), attributes.getValue("unique-member-name")); olapDimension.addExclusion(olapExclusion); createdObject = olapExclusion; } else if (name.equals("wabit-image")) { currentWabitImage = new WabitImage(); createdObject = currentWabitImage; session.getWorkspace().addImage(currentWabitImage); for (int i = 0; i < attributes.getLength(); i++) { String aname = attributes.getQName(i); String aval = attributes.getValue(i); if (aname.equals("name")) { //already loaded } else { logger.warn("Unexpected attribute of <wabit-image>: " + aname + "=" + aval); } } } else if (name.equals("chart")) { chart = new Chart(); createdObject = chart; session.getWorkspace().addChart(chart); for (int i = 0; i < attributes.getLength(); i++) { String aname = attributes.getQName(i); String aval = attributes.getValue(i); if (aname.equals("uuid")) { //already loaded } else if (aname.equals("y-axis-name")) { chart.setYaxisName(aval); } else if (aname.equals("x-axis-name")) { chart.setXaxisName(aval); } else if (aname.equals("x-axis-label-rotation")) { chart.setXAxisLabelRotation(Double.parseDouble(aval)); } else if (aname.equals("type")) { chart.setType(ChartType.valueOf(aval)); } else if (aname.equals("legend-position")) { chart.setLegendPosition(LegendPosition.valueOf(aval)); } else if (aname.equals("gratuitous-animation")) { chart.setGratuitouslyAnimated(Boolean.parseBoolean(aval)); } else if (aname.equals("auto-x-axis")) { chart.setAutoXAxisRange(Boolean.parseBoolean(aval)); } else if (aname.equals("auto-y-axis")) { chart.setAutoXAxisRange(Boolean.parseBoolean(aval)); } else if (aname.equals("x-axis-max")) { chart.setXAxisMaxRange(Double.parseDouble(aval)); } else if (aname.equals("y-axis-max")) { chart.setYAxisMaxRange(Double.parseDouble(aval)); } else if (aname.equals("x-axis-min")) { chart.setXAxisMinRange(Double.parseDouble(aval)); } else if (aname.equals("y-axis-min")) { chart.setYAxisMinRange(Double.parseDouble(aval)); } else if (aname.equals("query-id")) { QueryCache query = null; for (QueryCache q : session.getWorkspace().getQueries()) { if (q.getUUID().equals(aval)) { query = q; break; } } if (query != null) { chart.setQuery(query); } OlapQuery olapQuery = null; for (OlapQuery q : session.getWorkspace().getOlapQueries()) { if (q.getUUID().equals(aval)) { olapQuery = q; break; } } if (olapQuery != null) { try { chart.setMagicEnabled(false); chart.setQuery(olapQuery); } finally { chart.setMagicEnabled(true); } } if (query == null && olapQuery == null) { throw new IllegalArgumentException( "The query with UUID " + aval + " is missing from this project."); } } else { logger.warn("Unexpected attribute of <chart>: " + aname + "=" + aval); } } } else if (name.equals("chart-column")) { ChartColumn colIdentifier = loadColumnIdentifier(attributes, ""); createdObject = colIdentifier; if (colIdentifier == null) { throw new IllegalStateException("The chart " + chart.getName() + " with uuid " + chart.getUUID() + " has a missing column identifier when ordering columns and cannot be loaded."); } for (int i = 0; i < attributes.getLength(); i++) { String aname = attributes.getQName(i); String aval = attributes.getValue(i); if (aname.equals("name")) { //already handled } else if (aname.equals("role")) { colIdentifier.setRoleInChart(ColumnRole.valueOf(aval)); } else if (aname.matches("x-axis-.*")) { ChartColumn xAxisIdentifier = loadColumnIdentifier(attributes, "x-axis-"); colIdentifier.setXAxisIdentifier(xAxisIdentifier); } } if (readingMissingChartCols) { chart.addMissingIdentifier(colIdentifier); } else { chart.addChartColumn(colIdentifier); } } else if (name.equals("missing-columns")) { readingMissingChartCols = true; createdObject = null; } else if (name.equals("layout")) { this.isInLayout = true; String layoutName = attributes.getValue("name"); checkMandatory("name", layoutName); if (attributes.getValue("template") == null || !Boolean.parseBoolean(attributes.getValue("template"))) { layout = new Report(layoutName); session.getWorkspace().addReport((Report) layout); } else { layout = new Template(layoutName); session.getWorkspace().addTemplate((Template) layout); } createdObject = layout; selectorContainer = layout; for (int i = 0; i < attributes.getLength(); i++) { String aname = attributes.getQName(i); String aval = attributes.getValue(i); if (aname.equals("name")) { //already loaded } else if (aname.equals("zoom")) { layout.setZoomLevel(Integer.parseInt(aval)); } else { logger.warn("Unexpected attribute of <layout>: " + aname + "=" + aval); } } } else if (name.equals("layout-page")) { Page page = layout.getPage(); createdObject = page; //Remove all guides from the page as they will be loaded in a later //part of this handler. for (WabitObject object : page.getChildren()) { if (object instanceof Guide) { page.removeGuide((Guide) object); } } //This sets the orientation before setting the width and height to prevent //a change in the orientation from switching the width and height. If the //orientation changes between portrait and landscape the width and height //values are swapped. String orientation = attributes.getValue("orientation"); if (orientation != null) { // XXX the null check is for compatibility with export-format 1.0.0 page.setOrientation(PageOrientation.valueOf(orientation)); } for (int i = 0; i < attributes.getLength(); i++) { String aname = attributes.getQName(i); String aval = attributes.getValue(i); if (aname.equals("name")) { // already loaded } else if (aname.equals("height")) { page.setHeight(Integer.parseInt(aval)); } else if (aname.equals("width")) { page.setWidth(Integer.parseInt(aval)); } else if (aname.equals("orientation")) { //already loaded } else { logger.warn("Unexpected attribute of <layout-page>: " + aname + "=" + aval); } } } else if (name.equals("content-box")) { contentBox = new ContentBox(); createdObject = contentBox; selectorContainer = contentBox; layout.getPage().addContentBox(contentBox); for (int i = 0; i < attributes.getLength(); i++) { String aname = attributes.getQName(i); String aval = attributes.getValue(i); if (aname.equals("name")) { // already loaded } else if (aname.equals("width")) { contentBox.setWidth(Double.parseDouble(aval)); } else if (aname.equals("height")) { contentBox.setHeight(Double.parseDouble(aval)); } else if (aname.equals("xpos")) { contentBox.setX(Double.parseDouble(aval)); } else if (aname.equals("ypos")) { contentBox.setY(Double.parseDouble(aval)); } else { logger.warn("Unexpected attribute of <content-box>: " + aname + "=" + aval); } } } else if (name.equals("content-label")) { WabitLabel label = new WabitLabel(); createdObject = label; contentBox.setContentRenderer(label); for (int i = 0; i < attributes.getLength(); i++) { String aname = attributes.getQName(i); String aval = attributes.getValue(i); if (aname.equals("name")) { //handled elsewhere } else if (aname.equals("text")) { label.setText(aval); } else if (aname.equals("horizontal-align")) { label.setHorizontalAlignment(HorizontalAlignment.valueOf(aval)); } else if (aname.equals("vertical-align")) { label.setVerticalAlignment(VerticalAlignment.valueOf(aval)); } else if (aname.equals("bg-colour")) { label.setBackgroundColour(new Color(Integer.parseInt(aval))); } else { logger.warn("Unexpected attribute of <content-label>: " + aname + "=" + aval); } } } else if (name.equals("text") && parentIs("content-label")) { createdObject = null; } else if (name.equals("image-renderer")) { imageRenderer = new ImageRenderer(); createdObject = imageRenderer; //Old image renderers always had the image in the top left. If //the file is new it will have the horizontal and vertical alignments //set. imageRenderer.setHAlign(HorizontalAlignment.LEFT); imageRenderer.setVAlign(VerticalAlignment.TOP); contentBox.setContentRenderer(imageRenderer); for (int i = 0; i < attributes.getLength(); i++) { String aname = attributes.getQName(i); String aval = attributes.getValue(i); if (aname.equals("name")) { //Handled elsewhere } else if (aname.equals("wabit-image-uuid")) { for (WabitImage image : session.getWorkspace().getImages()) { if (image.getUUID().equals(aval)) { imageRenderer.setImage(image); break; } } if (imageRenderer.getImage() == null) { throw new IllegalStateException("Could not load the workspace as the report " + layout.getName() + " is missing the image " + aval); } } else if (aname.equals("preserving-aspect-ratio")) { imageRenderer.setPreservingAspectRatio(Boolean.valueOf(aval)); } else if (aname.equals("h-align")) { imageRenderer.setHAlign(HorizontalAlignment.valueOf(aval)); } else if (aname.equals("v-align")) { imageRenderer.setVAlign(VerticalAlignment.valueOf(aval)); } else { logger.warn("Unexpected attribute of <image-renderer>: " + aname + "=" + aval); } } } else if (name.equals("chart-renderer")) { String chartUuid = attributes.getValue("chart-uuid"); Chart chart = session.getWorkspace().findByUuid(chartUuid, Chart.class); if (chart == null) { throw new IllegalStateException("Missing chart with UUID " + chartUuid + ", which is supposed" + " to be attached to a chart renderer"); } final ChartRenderer chartRenderer = new ChartRenderer(chart); createdObject = chartRenderer; contentBox.setContentRenderer(chartRenderer); for (int i = 0; i < attributes.getLength(); i++) { String aname = attributes.getQName(i); String aval = attributes.getValue(i); if (aname.equals("uuid")) { // handled elsewhere } else if (aname.equals("chart-uuid")) { // already handled } else if (aname.equals("name")) { // handled elsewhere } else { logger.warn("Unexpected attribute of <chart-renderer>: " + aname + "=" + aval); } } } else if (name.equals("content-result-set")) { String queryID = attributes.getValue("query-id"); checkMandatory("query-id", queryID); WabitResultSetProducer query = session.getWorkspace().findByUuid(queryID, WabitResultSetProducer.class); rsRenderer = new ResultSetRenderer(query); createdObject = rsRenderer; for (int i = 0; i < attributes.getLength(); i++) { String aname = attributes.getQName(i); String aval = attributes.getValue(i); if (aname.equals("query-id")) { // handled elsewhere } else if (aname.equals("name")) { // handled elsewhere } else if (aname.equals("null-string")) { rsRenderer.setNullString(aval); } else if (aname.equals("bg-colour")) { Color color = new Color(Integer.parseInt(aval)); logger.debug("Renderer has background " + color.getRed() + ", " + color.getBlue() + ", " + color.getGreen()); rsRenderer.setBackgroundColour(color); } else if (aname.equals("data-colour")) { Color color = new Color(Integer.parseInt(aval)); rsRenderer.setDataColour(color); } else if (aname.equals("header-colour")) { Color color = new Color(Integer.parseInt(aval)); rsRenderer.setHeaderColour(color); } else if (aname.equals("border")) { rsRenderer.setBorderType(BorderStyles.valueOf(aval)); } else if (aname.equals("grand-totals")) { rsRenderer.setPrintingGrandTotals(Boolean.parseBoolean(aval)); } else { logger.warn("Unexpected attribute of <content-result-set>: " + aname + "=" + aval); } } //columnInfoList.clear(); contentBox.setContentRenderer(rsRenderer); } else if (name.equals("header-font")) { if (parentIs("content-result-set")) { rsRenderer.setHeaderFont(loadFont(attributes)); createdObject = null; } else { throw new IllegalStateException("There are no header fonts defined for the parent " + xmlContext.get(xmlContext.size() - 2)); } } else if (name.equals("body-font")) { if (parentIs("content-result-set")) { createdObject = null; rsRenderer.setBodyFont(loadFont(attributes)); } else { throw new IllegalStateException( "There are no body fonts defined for the parent " + xmlContext.get(xmlContext.size() - 2)); } } else if (name.equals("column-info")) { colInfo = null; createdObject = null; //Not going to set name later, as this may break alias association String colInfoName = attributes.getValue("name"); String colInfoItem = attributes.getValue("column-info-item-id"); /* * XXX This retro compatibility fix forces us to violate * proper encapsulation and cannot be maintained if we want to * display OLAP queries in a RSRenderer. Imma comment it * out for now and evaluate later if we want to keep it. * It is for retrocompatibility with 0.9.1, which is a terribly * old version anyways. I'm not even sure we can load those files * now anyways. */ // //For backwards compatability with 0.9.1 // String colInfoKey = attributes.getValue("column-info-key"); // if (colInfoKey != null && colInfoItem == null) { // Query q = rsRenderer.getContent(); // for (Map.Entry<String, Item> entry : uuidToItemMap.entrySet()) { // Item item = entry.getValue(); // if (q.getSelectedColumns().contains(item) && (item.getAlias().equals(colInfoKey) || item.getName().equals(colInfoKey))) { // colInfoItem = entry.getKey(); // break; // } // } // if (colInfoItem == null) { // colInfo = new ColumnInfo(colInfoKey, colInfoName); // } // } String colAlias = attributes.getValue("column-alias"); if (colInfo == null && colAlias != null && colInfoItem == null) { colInfo = new ColumnInfo(colAlias, colInfoName); } checkMandatory("name", colInfoName); if (colInfo == null) { colInfo = new ColumnInfo(uuidToItemMap.get(colInfoItem), colInfoName); } for (int i = 0; i < attributes.getLength(); i++) { String aname = attributes.getQName(i); String aval = attributes.getValue(i); if (aname.equals("column-info-key") || aname.equals("name")) { //already loaded } else if (aname.equals("uuid")) { colInfo.setUUID(aval); } else if (aname.equals("width")) { colInfo.setWidth(Integer.parseInt(aval)); } else if (aname.equals("horizontal-align")) { colInfo.setHorizontalAlignment(HorizontalAlignment.valueOf(aval)); } else if (aname.equals("data-type")) { colInfo.setDataType(DataType.valueOf(aval)); } else if (aname.equals("break-on-column")) { if (Boolean.parseBoolean(aval)) { colInfo.setWillGroupOrBreak(GroupAndBreak.GROUP); } else { colInfo.setWillGroupOrBreak(GroupAndBreak.NONE); } } else if (aname.equals("group-or-break")) { colInfo.setWillGroupOrBreak(GroupAndBreak.valueOf(aval)); } else if (aname.equals("will-subtotal")) { colInfo.setWillSubtotal(Boolean.parseBoolean(aval)); } else { logger.warn("Unexpected attribute of <column-info>: " + aname + "=" + aval); } } rsRenderer.addChild(colInfo, rsRenderer.getChildren().size()); } else if (name.equals("date-format")) { createdObject = null; if (parentIs("column-info")) { String format = attributes.getValue("format"); checkMandatory("format", format); colInfo.setFormat(new SimpleDateFormat(format)); } else { throw new IllegalStateException( "There is no date format defined for the parent " + xmlContext.get(xmlContext.size() - 2)); } } else if (name.equals("decimal-format")) { createdObject = null; if (parentIs("column-info")) { String format = attributes.getValue("format"); checkMandatory("format", format); colInfo.setFormat(new DecimalFormat(format)); } else { throw new IllegalStateException( "There is no date format defined for the parent " + xmlContext.get(xmlContext.size() - 2)); } } else if (name.equals("selector")) { String type = attributes.getValue("type"); if (type.equals(ComboBoxSelector.class.getSimpleName())) { this.selector = new ComboBoxSelector(); } else if (type.equals(TextBoxSelector.class.getSimpleName())) { this.selector = new TextBoxSelector(); } else if (type.equals(DateSelector.class.getSimpleName())) { this.selector = new DateSelector(); } else { throw new IllegalStateException("Cannot create a selector of type " + type); } if (selectorContainer == null) { throw new AssertionError("Program error. 'selectorContainer' not set."); } else if (selectorContainer instanceof Report || selectorContainer instanceof ContentBox) { selectorContainer.addChild(selector, selectorContainer.getChildren(Selector.class).size()); } else { throw new IllegalStateException("Selectors can only be added to reports and content boxes.."); } createdObject = this.selector; } else if (name.equals("selector-config")) { if (selector instanceof ComboBoxSelector) { ((ComboBoxSelector) selector).setSourceKey(attributes.getValue("sourceKey")); ((ComboBoxSelector) selector).setStaticValues(attributes.getValue("staticValues")); ((ComboBoxSelector) selector).setDefaultValue(attributes.getValue("defaultValue")); ((ComboBoxSelector) selector).setAlwaysIncludeDefaultValue( Boolean.valueOf(attributes.getValue("alwaysIncludeDefaultValue"))); } else if (selector instanceof TextBoxSelector) { ((TextBoxSelector) selector).setDefaultValue(attributes.getValue("defaultValue")); } else if (selector instanceof DateSelector) { String defValueS = attributes.getValue("defaultValue"); final Date defValue; if (defValueS == null) { defValue = null; } else { defValue = new DateConverter().convertToComplexType(defValueS); } ((DateSelector) selector).setDefaultValue(defValue); } else { throw new IllegalStateException("Cannot configure selector."); } createdObject = null; } else if (name.equals("cell-set-renderer")) { String queryUUID = attributes.getValue("olap-query-uuid"); OlapQuery newQuery = null; for (OlapQuery query : session.getWorkspace().getOlapQueries()) { if (query.getUUID().equals(queryUUID)) { newQuery = query; break; } } if (newQuery == null) { throw new NullPointerException("Cannot load workspace due to missing olap query in report."); } cellSetRenderer = new CellSetRenderer(newQuery); createdObject = cellSetRenderer; contentBox.setContentRenderer(cellSetRenderer); for (int i = 0; i < attributes.getLength(); i++) { String aname = attributes.getQName(i); String aval = attributes.getValue(i); if (aname.equals("uuid") || aname.equals("olap-query-uuid")) { // handled elsewhere } else if (aname.equals("name")) { // handled elsewhere } else if (aname.equals("body-alignment")) { cellSetRenderer.setBodyAlignment(HorizontalAlignment.valueOf(aval)); } else if (aname.equals("body-format-pattern")) { cellSetRenderer.setBodyFormat(new DecimalFormat(aval)); } else { logger.warn("Unexpected attribute of <cell-set-renderer>: " + aname + "=" + aval); } } } else if (name.equals("olap-header-font")) { createdObject = null; cellSetRenderer.setHeaderFont(loadFont(attributes)); } else if (name.equals("olap-body-font")) { createdObject = null; cellSetRenderer.setBodyFont(loadFont(attributes)); } else if (name.equals("guide")) { String axisName = attributes.getValue("axis"); String offsetAmount = attributes.getValue("offset"); checkMandatory("axis", axisName); checkMandatory("offset", offsetAmount); Guide guide = new Guide(Axis.valueOf(axisName), Double.parseDouble(offsetAmount)); createdObject = guide; layout.getPage().addGuide(guide); } else if (name.equals("font")) { createdObject = null; Font font = loadFont(attributes); if (parentIs("layout-page")) { layout.getPage().setDefaultFont(font); } else if (parentIs("content-box")) { contentBox.setFont(font); } else if (parentIs("content-label")) { ((WabitLabel) contentBox.getContentRenderer()).setFont(font); } } else { createdObject = null; logger.warn("Unknown object type: " + name); } if (createdObject != null) { String valName = attributes.getValue("name"); String valUUID = attributes.getValue("uuid"); if (nameMandatory) { checkMandatory("name", valName); } if (uuidMandatory) { checkMandatory("uuid", valUUID); } if (valName != null) { createdObject.setName(valName); } if (valUUID != null) { createdObject.setUUID(valUUID); } progressMessage = session.getWorkspace().getName() + ": reading " + valName; } }
From source file:chat.viska.xmpp.HandshakerPipe.java
/** * Default constructor./*from w ww . ja va 2s.co m*/ * @param loginJid Required when registering. * @param authzId Authorization ID, optional. * @param saslMechanisms <a href="https://datatracker.ietf.org/doc/rfc4422">SASL</a> * Mechanisms used during handshake. Use an empty {@link Set} in order to use the default. * @param resource XMPP Resource. If empty, the server will generate a random one. * @param registering Indicates if the handshake includes in-band * registration. */ public HandshakerPipe(final StandardSession session, final Jid loginJid, final Jid authzId, @Nullable final CredentialRetriever retriever, final List<String> saslMechanisms, final String resource, final boolean registering) { if (registering) { Validate.isTrue(!Jid.isEmpty(loginJid), "\"loginJid\" must be provided when registering."); } if (!Jid.isEmpty(loginJid)) { Objects.requireNonNull(retriever, "A credential retriever must be provided when registering."); } this.session = session; this.loginJid = loginJid; this.authzId = authzId; this.retriever = retriever; if (saslMechanisms.isEmpty()) { this.saslMechanisms.add("SCRAM-SHA-1"); } else { this.saslMechanisms.addAll(saslMechanisms); } presetResource = resource; state.getStream().filter(it -> it == State.STREAM_CLOSED || it == State.COMPLETED || it == State.DISPOSED) .filter(it -> !handshakeResult.hasThrowable() && !handshakeResult.hasComplete()).firstOrError() .subscribe(state -> { if (state == State.COMPLETED) { handshakeResult.onComplete(); } else { handshakeResult.onError(new CancellationException()); } }); }
From source file:co.paralleluniverse.galaxy.core.Cache.java
/** * This one blocks!/*from ww w. j a va 2 s . com*/ * * @param op * @return */ private Object doOp(Op op) throws TimeoutException { try { if (op.txn != null) op.txn.add(op); Object result = runOp(op); if (result == PENDING) return op.getResult(timeout, TimeUnit.MILLISECONDS); else if (result == null && op.isCancelled()) throw new CancellationException(); else return result; } catch (java.util.concurrent.TimeoutException e) { throw new TimeoutException(e); } catch (InterruptedException e) { return null; } catch (ExecutionException e) { Throwable ex = e.getCause(); if (ex instanceof TimeoutException) throw (TimeoutException) ex; Throwables.propagateIfPossible(ex); throw Throwables.propagate(ex); } }
From source file:ca.sqlpower.wabit.dao.WorkspaceSAXHandler.java
@Override public void endElement(final String uri, final String localName, final String name) throws SAXException { if (isCancelled()) throw new CancellationException(); final ByteArrayOutputStream copyStream; if (byteStream != null) { logger.debug("Byte stream contains " + byteStream.size() + " bytes."); copyStream = new ByteArrayOutputStream(byteStream.size()); try {//from w w w . java 2 s .c o m byteStream.writeTo(copyStream); } catch (IOException ex) { logger.error(ex); throw new CancellationException("Could not copy the stream. See the logs for more details."); } } else { copyStream = null; } Runnable runner = new Runnable() { public void run() { try { context.startLoading(); endElementImpl(uri, localName, name, copyStream); } catch (SAXException e) { setCancelled(true); throw new RuntimeException(e); } finally { context.endLoading(); } } }; session.runInForeground(runner); }
From source file:ca.sqlpower.wabit.dao.WorkspaceSAXHandler.java
@Override public void characters(char[] ch, int start, int length) throws SAXException { if (isCancelled()) throw new CancellationException(); for (int i = start; i < start + length; i++) { byteStream.write((byte) ch[i]); }/*w w w. j av a 2s. co m*/ if (logger.isDebugEnabled()) { logger.debug("Starting characters at " + start + " and ending at " + length); logger.debug("Byte stream has " + byteStream.toString()); } }