List of usage examples for java.util Stack peek
public synchronized E peek()
From source file:com.bluexml.xforms.generator.forms.Renderable.java
/** * Indicates if tabs have to be shown.<br> * Done as DOJO tabs used in Chiba 2 can not be added inside a repeater * /* w w w . j ava2s .c om*/ * @param renderedParents * the rendered parents * * @return true, if tabs should be shown */ protected boolean doShowTab(Stack<Rendered> renderedParents) { Rendered parent = renderedParents.peek(); // if a parent is a tab container and tabs are not shown for it, // do no show tab too if (parent instanceof RenderedTabContainer) { if (!((RenderedTabContainer) parent).isShowTabs()) { return false; } } // search for a repeater for (Rendered rendered : renderedParents) { if (rendered instanceof RenderedRepeater) { return false; } } return true; }
From source file:com.madrobot.di.wizard.json.JSONDeserializer.java
/** * Deserialize a specific element, recursively. * /*from ww w. ja v a 2s . com*/ * @param obj * Object whose fields need to be set * @param jsonObject * JSON Parser to read data from * @param stack * Stack of {@link ClassInfo} - entity type under consideration * @throws JSONException * If an exception occurs during parsing */ private void deserialize(Object obj, JSONObject jsonObject, Stack<Class<?>> stack) throws JSONException { Iterator<?> iterator = jsonObject.keys(); Class<?> userClass = stack.peek(); while (iterator.hasNext()) { Object jsonKey = iterator.next(); if (jsonKey instanceof String) { String key = (String) jsonKey; Object jsonElement = jsonObject.get(key); try { Field field = getField(userClass, key); String fieldName = field.getName(); Class<?> classType = field.getType(); if (jsonElement instanceof JSONObject) { if (!Converter.isPseudoPrimitive(classType)) { String setMethodName = getSetMethodName(fieldName, classType); Method setMethod = userClass.getDeclaredMethod(setMethodName, classType); JSONObject fieldObject = (JSONObject) jsonElement; stack.push(classType); Object itemObj = classType.newInstance(); deserialize(itemObj, fieldObject, stack); setMethod.invoke(obj, itemObj); } else { Log.e(TAG, "Expecting composite type for " + fieldName); } } else if (jsonElement instanceof JSONArray) { if (Converter.isCollectionType(classType)) { if (field.isAnnotationPresent(ItemType.class)) { ItemType itemType = field.getAnnotation(ItemType.class); Class<?> itemValueType = itemType.value(); int size = itemType.size(); JSONArray fieldArrayObject = (JSONArray) jsonElement; if (size == JSONDeserializer.DEFAULT_ITEM_COLLECTION_SIZE || size > fieldArrayObject.length()) { size = fieldArrayObject.length(); } for (int index = 0; index < size; index++) { Object value = fieldArrayObject.get(index); if (value instanceof JSONObject) { stack.push(itemValueType); Object itemObj = itemValueType.newInstance(); deserialize(itemObj, (JSONObject) value, stack); String addMethodName = getAddMethodName(fieldName); Method addMethod = userClass.getDeclaredMethod(addMethodName, itemValueType); addMethod.invoke(obj, itemObj); } } } } else { Log.e(TAG, "Expecting collection type for " + fieldName); } } else if (Converter.isPseudoPrimitive(classType)) { Object value = Converter.convertTo(jsonObject, key, classType, field); String setMethodName = getSetMethodName(fieldName, classType); Method setMethod = userClass.getDeclaredMethod(setMethodName, classType); setMethod.invoke(obj, value); } else { Log.e(TAG, "Unknown datatype"); } } catch (NoSuchFieldException e) { Log.e(TAG, e.getMessage()); } catch (NoSuchMethodException e) { Log.e(TAG, e.getMessage()); } catch (IllegalAccessException e) { Log.e(TAG, e.getMessage()); } catch (InvocationTargetException e) { Log.e(TAG, e.getMessage()); } catch (InstantiationException e) { Log.e(TAG, e.getMessage()); } } } }
From source file:org.apache.whirr.service.DryRunModuleTest.java
/** * Simple test that tests dry run module and at the same time enforces clear * separation of script execution phases. *//* w w w . ja v a2 s . c o m*/ @Test public void testNoInitScriptsAfterConfigurationStartedAndNoConfigScriptsAfterDestroy() throws ConfigurationException, JSchException, IOException, InterruptedException { final List<String> expectedExecutionOrder = ImmutableList.of("bootstrap", "configure", "start", "destroy"); CompositeConfiguration config = new CompositeConfiguration(); config.setProperty("whirr.provider", "stub"); config.setProperty("whirr.cluster-name", "stub-test"); config.setProperty("whirr.instance-templates", "10 noop+noop3,10 noop2+noop,10 noop3+noop2"); config.setProperty("whirr.state-store", "memory"); ClusterSpec clusterSpec = ClusterSpec.withTemporaryKeys(config); ClusterController controller = new ClusterController(); DryRun dryRun = getDryRunInControllerForCluster(controller, clusterSpec); dryRun.reset(); controller.launchCluster(clusterSpec); controller.destroyCluster(clusterSpec); ListMultimap<NodeMetadata, Statement> perNodeExecutions = dryRun.getExecutions(); List<StatementOnNode> totalExecutions = dryRun.getTotallyOrderedExecutions(); // Assert that all nodes executed all three phases and in the right order for (Entry<NodeMetadata, Collection<Statement>> entry : perNodeExecutions.asMap().entrySet()) { assertSame("An incorrect number of scripts was executed in the node: " + entry.getValue(), entry.getValue().size(), expectedExecutionOrder.size()); List<Statement> asList = Lists.newArrayList(entry.getValue()); int count = 0; for (String phase : expectedExecutionOrder) { String scriptName = getScriptName(asList.get(count)); assertTrue("The '" + phase + "' script was executed in the wrong order, found: " + scriptName, scriptName.startsWith(phase)); count += 1; } } // This tests the barrier by making sure that once a configure // script is executed no more setup scripts are executed Stack<String> executedPhases = new Stack<String>(); for (StatementOnNode script : totalExecutions) { String[] parts = getScriptName(script.getStatement()).split("-"); if ((!executedPhases.empty() && !executedPhases.peek().equals(parts[0])) || executedPhases.empty()) { executedPhases.push(parts[0]); } } // Assert that all scripts executed in the right order with no overlaps assertEquals(expectedExecutionOrder.size(), executedPhases.size()); for (String phaseName : Lists.reverse(expectedExecutionOrder)) { assertEquals(executedPhases.pop(), phaseName); } }
From source file:org.sakaiproject.commons.api.datamodel.Post.java
/** * @see org.sakaiproject.entity.api.Entity#toXml() * * @return/* ww w . j av a 2 s . co m*/ */ public Element toXml(Document doc, Stack stack) { Element postElement = doc.createElement(XmlDefs.POST); if (stack.isEmpty()) { doc.appendChild(postElement); } else { ((Element) stack.peek()).appendChild(postElement); } stack.push(postElement); Element idElement = doc.createElement(XmlDefs.ID); idElement.setTextContent(id); postElement.appendChild(idElement); Element createdDateElement = doc.createElement(XmlDefs.CREATEDDATE); createdDateElement.setTextContent(Long.toString(createdDate)); postElement.appendChild(createdDateElement); Element modifiedDateElement = doc.createElement(XmlDefs.MODIFIEDDATE); modifiedDateElement.setTextContent(Long.toString(modifiedDate)); postElement.appendChild(modifiedDateElement); Element creatorIdElement = doc.createElement(XmlDefs.CREATORID); creatorIdElement.setTextContent(creatorId); postElement.appendChild(creatorIdElement); Element contentElement = doc.createElement(XmlDefs.CONTENT); contentElement.setTextContent(wrapWithCDATA(content)); postElement.appendChild(contentElement); if (comments.size() > 0) { Element commentsElement = doc.createElement(XmlDefs.COMMENTS); for (Comment comment : comments) { Element commentElement = doc.createElement(XmlDefs.COMMENT); commentElement.setAttribute(XmlDefs.ID, comment.getId()); commentElement.setAttribute(XmlDefs.CREATORID, comment.getCreatorId()); commentElement.setAttribute(XmlDefs.CREATEDDATE, Long.toString(comment.getCreatedDate())); commentElement.setAttribute(XmlDefs.MODIFIEDDATE, Long.toString(comment.getModifiedDate())); commentElement.setTextContent(wrapWithCDATA(comment.getContent())); commentsElement.appendChild(commentElement); } postElement.appendChild(commentsElement); } stack.pop(); return postElement; }
From source file:org.sakaiproject.archive.impl.SiteArchiver.java
/** * Archive the users defined in this site (internal users only). * @param site the site.//from w w w . j a v a 2 s. c o m * @param doc The document to contain the xml. * @param stack The stack of elements, the top of which will be the containing * element of the "site" element. */ protected String archiveUsers(Site site, Document doc, Stack stack) { Element element = doc.createElement(UserDirectoryService.APPLICATION_ID); ((Element) stack.peek()).appendChild(element); stack.push(element); try { // get the site's user list List users = new Vector(); String realmId = m_siteService.siteReference(site.getId()); //SWG "/site/" + site.getId(); try { AuthzGroup realm = m_authzGroupService.getAuthzGroup(realmId); users.addAll(m_userDirectoryService.getUsers(realm.getUsers())); Collections.sort(users); for (int i = 0; i < users.size(); i++) { User user = (User) users.get(i); user.toXml(doc, stack); } } catch (GroupNotDefinedException e) { M_log.warn(e, e); } catch (Exception any) { M_log.warn(any, any); } } catch (Exception any) { M_log.warn(any, any); } stack.pop(); return "archiving the users for Site: " + site.getId() + "\n"; }
From source file:com.netspective.commons.xml.template.Template.java
public TemplateApplyContext createApplyContext(TemplateContentHandler contentHandler, String elementName, Attributes attributes) throws SAXException { String exprsFlag = attributes .getValue(contentHandler.getNodeIdentifiers().getTemplateReplaceExprsAttrName()); boolean allowReplaceExpressions = exprsFlag != null && exprsFlag.length() > 0 ? TextUtils.getInstance().toBoolean(exprsFlag) : true;// w w w .j a v a 2 s. co m if (!allowReplaceExpressions) return new TemplateApplyContext(contentHandler); Map vars = new HashMap(); JexlContext jc = org.apache.commons.jexl.JexlHelper.createContext(); Stack nodeStack = contentHandler.getNodeStack(); ContentHandlerNodeStackEntry activeEntry = (ContentHandlerNodeStackEntry) nodeStack.peek(); vars.put("nodeStack", nodeStack); vars.put("ownerEntry", activeEntry); activeEntry.fillCreateApplyContextExpressionsVars(vars); Map templateParamsValues = allowReplaceExpressions ? getTemplateParamsValues(contentHandler.getNodeIdentifiers(), attributes) : null; if (templateParamsValues != null) vars.put(EXPRVARNAME_PARAMS, templateParamsValues); jc.setVars(vars); return new TemplateApplyContext(contentHandler, jc, templateParamsValues); }
From source file:org.cvasilak.jboss.mobile.app.activities.JBossServerRootActivity.java
@Override protected void onPause() { super.onPause(); // Select proper stack ActionBar.Tab tab = getSupportActionBar().getSelectedTab(); Stack<String> backStack = backStacks.get(tab.getTag()); if (!backStack.isEmpty()) { // Detach topmost fragment otherwise it will not be correctly displayed // after orientation change String tag = backStack.peek(); FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); Fragment fragment = getSupportFragmentManager().findFragmentByTag(tag); ft.detach(fragment);//from w w w . j av a 2 s. c om ft.commit(); } }
From source file:org.pgptool.gui.encryption.implpgp.KeyFilesOperationsPgpImpl.java
@Override public void exportPublicKey(Key key, String targetFilePathname) { Preconditions.checkArgument(key != null && key.getKeyData() != null && key.getKeyInfo() != null, "Key must be providedand fully described"); Preconditions.checkArgument(StringUtils.hasText(targetFilePathname), "targetFilePathname must be provided"); Stack<OutputStream> os = new Stack<>(); try {// w w w . ja v a 2 s . c om os.push(new FileOutputStream(targetFilePathname)); if ("asc".equalsIgnoreCase(FilenameUtils.getExtension(targetFilePathname))) { os.push(new ArmoredOutputStream(os.peek())); } KeyDataPgp keyDataPgp = KeyDataPgp.get(key); if (keyDataPgp.getPublicKeyRing() != null) { keyDataPgp.getPublicKeyRing().encode(os.peek()); } else { keyDataPgp.getSecretKeyRing().getPublicKey().encode(os.peek()); } } catch (Throwable t) { throw new RuntimeException( "Failed to export public key " + key.getKeyInfo().getUser() + " to " + targetFilePathname, t); } finally { while (!os.isEmpty()) { IoStreamUtils.safeClose(os.pop()); } } }
From source file:org.pgptool.gui.encryption.implpgp.KeyFilesOperationsPgpImpl.java
@Override public void exportPrivateKey(Key key, String targetFilePathname) { Preconditions.checkArgument(key != null && key.getKeyData() != null && key.getKeyInfo() != null, "Key must be providedand fully described"); KeyDataPgp keyDataPgp = KeyDataPgp.get(key); Preconditions.checkArgument(keyDataPgp.getSecretKeyRing() != null, "KeyPair key wasn't provided"); Preconditions.checkArgument(StringUtils.hasText(targetFilePathname), "targetFilePathname must be provided"); Stack<OutputStream> os = new Stack<>(); try {/*from w w w . ja v a 2s. c o m*/ os.push(new FileOutputStream(targetFilePathname)); if ("asc".equalsIgnoreCase(FilenameUtils.getExtension(targetFilePathname))) { os.push(new ArmoredOutputStream(os.peek())); } keyDataPgp.getSecretKeyRing().encode(os.peek()); if (keyDataPgp.getPublicKeyRing() != null) { keyDataPgp.getPublicKeyRing().encode(os.peek()); } } catch (Throwable t) { throw new RuntimeException( "Failed to export private key " + key.getKeyInfo().getUser() + " to " + targetFilePathname, t); } finally { while (!os.isEmpty()) { IoStreamUtils.safeClose(os.pop()); } } }
From source file:com.autentia.intra.bean.MenuBean.java
/** * Finalize an opened node and return its parent. If the given node has no * childs it is removed from the tree.// w ww. j a va 2s . c om * * @param path path of current node * @return false if the node was removed */ private boolean closeNode(Stack<TreeNode> path) { boolean closed = true; TreeNode node = path.pop(); if (node.getChildCount() == 0) { path.peek().getChildren().remove(node); closed = false; } log.debug("addLeaf - " + (closed ? "CLOSE " : "REMOVE") + ": " + node.getIdentifier()); return closed; }