List of usage examples for java.util Stack peek
public synchronized E peek()
From source file:org.sakaiproject.basiclti.impl.BasicLTISecurityServiceImpl.java
@SuppressWarnings("unchecked") public String archive(String siteId, Document doc, Stack stack, String archivePath, List attachments) { logger.info("-------basic-lti-------- archive('" + StringUtils.join(new Object[] { siteId, doc, stack, archivePath, attachments }, "','") + "')"); StringBuilder results = new StringBuilder("archiving basiclti " + siteId + "\n"); int count = 0; try {//w w w . j a v a 2 s. c o m Site site = SiteService.getSite(siteId); logger.info("SITE: " + site.getId() + " : " + site.getTitle()); Element basicLtiList = doc.createElement("org.sakaiproject.basiclti.service.BasicLTISecurityService"); for (SitePage sitePage : site.getPages()) { for (ToolConfiguration toolConfiguration : sitePage.getTools()) { if (toolConfiguration.getTool() == null) continue; if (toolConfiguration.getTool().getId().equals(TOOL_REGISTRATION)) { // results.append(" tool=" + toolConfiguration.getId() + "\n"); count++; BasicLTIArchiveBean basicLTIArchiveBean = new BasicLTIArchiveBean(); basicLTIArchiveBean.setPageTitle(sitePage.getTitle()); basicLTIArchiveBean.setToolTitle(toolConfiguration.getTitle()); basicLTIArchiveBean.setSiteToolProperties(toolConfiguration.getConfig()); Node newNode = basicLTIArchiveBean.toNode(doc); basicLtiList.appendChild(newNode); } } } ((Element) stack.peek()).appendChild(basicLtiList); stack.push(basicLtiList); stack.pop(); } catch (IdUnusedException iue) { logger.info("SITE ID " + siteId + " DOES NOT EXIST."); results.append("Basic LTI Site does not exist\n"); } // Something we did not expect catch (Exception e) { e.printStackTrace(); results.append("basiclti exception:" + e.getClass().getName() + "\n"); } results.append("archiving basiclti (" + count + ") tools archived\n"); return results.toString(); }
From source file:de.betterform.agent.web.event.EventQueue.java
public List<XMLEvent> aggregateEventList() { // Stack is used to "navigate" through the event list LinkedList<XMLEvent> aggregatedFocusList = new LinkedList<XMLEvent>(); Stack<XMLEvent> aggregatedInsertEventsStack = new Stack(); Stack<XMLEvent> aggregatedEmbedEventsStack = new Stack(); ArrayList<XMLEvent> aggregatedEventList = new ArrayList<XMLEvent>(eventList.size()); for (XMLEvent xmlEvent : this.loadEmbedEventList) { aggregatedEventList.add(xmlEvent); }/*from www . j a v a 2 s .co m*/ this.loadEmbedEventList.clear(); for (int i = 0; i < eventList.size(); i++) { XercesXMLEvent xmlEvent = (XercesXMLEvent) eventList.get(i); XercesXMLEvent xmlEventToAdd = new XercesXMLEvent(); // Map PROTOTYPE_CLONED event to betterform-insert-repeatitem or betterform-insert-itemset event // and copy event properties to new created XMLEvent if (xmlEvent.getType().equals(BetterFormEventNames.PROTOTYPE_CLONED)) { if (xmlEvent.getContextInfo("targetName").equals(XFormsConstants.ITEMSET)) { xmlEventToAdd.initXMLEvent("betterform-insert-itemset", xmlEvent.getBubbles(), xmlEvent.getCancelable(), xmlEvent.getContextInfo()); } else { xmlEventToAdd.initXMLEvent("betterform-insert-repeatitem", xmlEvent.getBubbles(), xmlEvent.getCancelable(), xmlEvent.getContextInfo()); } xmlEventToAdd.target = xmlEvent.target; xmlEvent.addProperty("generatedIds", new HashMap()); aggregatedEventList.add(xmlEventToAdd); // push XMLEvent to Stack for further processing aggregatedInsertEventsStack.push(xmlEventToAdd); } // add all generated ids to surrounding betterform-insert-repeatitem or betterform-insert-itemset event else if (xmlEvent.getType().equals(BetterFormEventNames.ID_GENERATED) && aggregatedInsertEventsStack.size() > 0) { XMLEvent aggregatingInsertEvent = aggregatedInsertEventsStack.peek(); ((HashMap) aggregatingInsertEvent.getContextInfo("generatedIds")) .put(xmlEvent.getContextInfo("originalId"), xmlEvent.getContextInfo("targetId")); } // add insert position to surrounding betterform-insert-repeatitem or betterform-insert-itemset event else if (xmlEvent.getType().equals(BetterFormEventNames.ITEM_INSERTED)) { XMLEvent tmpEvent = aggregatedInsertEventsStack.pop(); tmpEvent.addProperty("position", xmlEvent.getContextInfo("position")); tmpEvent.addProperty("label", xmlEvent.getContextInfo("label")); tmpEvent.addProperty("value", xmlEvent.getContextInfo("value")); } else if (xmlEvent.getType().equals(BetterFormEventNames.EMBED)) { aggregatedEventList.add(xmlEvent); aggregatedEmbedEventsStack.push(xmlEvent); } else if (xmlEvent.getType().equals(BetterFormEventNames.EMBED_DONE)) { aggregatedEmbedEventsStack.pop().addProperty("targetElement", xmlEvent.getContextInfo("targetElement")); aggregatedEventList.add(xmlEvent); } else if (xmlEvent.getType().equals(XFormsEventNames.FOCUS)) { aggregatedFocusList.push(xmlEvent); } /* else if(xmlEvent.getType().equals(BetterFormEventNames.INDEX_CHANGED)){ aggregatedFocusList.push(xmlEvent); }*/ // all other events within eventList are simply copied to the new eventlist else { aggregatedEventList.add(xmlEvent); } } while (!aggregatedFocusList.isEmpty()) { aggregatedEventList.add(aggregatedFocusList.pollLast()); } return aggregatedEventList; }
From source file:aula1.Aula1.java
public static String calculaPolonesaINversa(String entrada, String info) { Stack<String> pilha = new Stack<>(); Stack<Op> operadores = new Stack<>(); String[] operadoresSuportados = { "+", "-", "*", "/", "^", "(", ")", "sen" }; for (int i = 0; i < entrada.length(); i++) { String s = ""; if (entrada.charAt(i) == 's') { if (entrada.contains("sen")) { int ind = entrada.indexOf("sen"); ind += 2;/*w ww . jav a 2 s .c om*/ i = 0; entrada = entrada.substring(ind + 1); s = "sen"; } } else s = String.valueOf(entrada.charAt(i)); if (Character.isDigit(entrada.charAt(i)) || entrada.charAt(i) == 'x') { if (Character.isDigit(entrada.charAt(i))) { s = String.valueOf(entrada.charAt(i)); while (Character.isDigit(entrada.charAt(i + 1))) { s += String.valueOf(entrada.charAt(i + 1)); i++; } } pilha.push(s); } else if (Arrays.asList(operadoresSuportados).contains(s)) { String n1 = ""; String n2 = ""; if (s.equals("sen")) n1 = pilha.pop(); else { n1 = pilha.pop(); n2 = pilha.pop(); } String resultado; if (n1.equals("x")) n1 = info; else if (n2.equals("x")) n2 = info; try { switch (s) { case "+": resultado = Operadores.soma(n2, n1); pilha.push(resultado); break; case "-": resultado = Operadores.sub(n2, n1); pilha.push(resultado); break; case "*": resultado = Operadores.M(n2, n1); pilha.push(resultado); break; case "/": resultado = Operadores.D(n2, n1); pilha.push(resultado); break; case "^": resultado = Operadores.pow(n2, n1); pilha.push(resultado); break; case "sen": resultado = Operadores.sen(n1); pilha.push(resultado); break; } } catch (Exception e) { System.out.println("Erro: " + e.getMessage()); } } } return pilha.peek(); }
From source file:uk.ac.cam.caret.sakai.rwiki.component.service.impl.RWikiObjectServiceImpl.java
/** * {@inheritDoc} Archive all the wiki pages in the site as a single * collection/* w w w . j a v a2s . com*/ */ public String archive(String siteId, Document doc, Stack stack, String archivePath, List attachments) { // TODO Permissions ? // prepare the buffer for the results log StringBuffer results = new StringBuffer(); results.append(Messages.getString("RWikiObjectServiceImpl.32")).append(siteId).append("\n"); //$NON-NLS-1$ //$NON-NLS-2$ log.debug("archiving Wiki Pages for " + siteId); //$NON-NLS-1$ int npages = 0; int nversions = 0; try { String defaultRealm = siteService.getSite(siteId).getReference(); wikiSecurityService.checkAdminPermission(RWikiObjectService.REFERENCE_ROOT + defaultRealm); // start with an element with our very own name Element element = doc.createElement(APPLICATION_ID); ((Element) stack.peek()).appendChild(element); stack.push(element); try { List l = cdao.findRWikiSubPages("/site/" + siteId); //$NON-NLS-1$ for (Iterator i = l.iterator(); i.hasNext();) { RWikiObject rwo = (RWikiObject) i.next(); RWikiEntity rwe = (RWikiEntity) getEntity(rwo); log.debug("Archiving " + rwo.getName()); //$NON-NLS-1$ rwe.toXml(doc, stack); npages++; List lh = this.findRWikiHistoryObjects(rwo); if (lh != null) { for (Iterator ih = lh.iterator(); ih.hasNext();) { RWikiObject rwoh = (RWikiObject) ih.next(); RWikiEntity rwoeh = (RWikiEntity) getEntity(rwoh); log.debug("Archiving " + rwoh.getName() //$NON-NLS-1$ + " version " + rwoh.getVersion()); //$NON-NLS-1$ rwoeh.toXml(doc, stack); nversions++; } } } } catch (Exception any) { any.printStackTrace(); results.append(Messages.getString("RWikiObjectServiceImpl.31") + siteId //$NON-NLS-1$ + " " + any.toString() + "\n"); //$NON-NLS-1$ //$NON-NLS-2$ } results.append(Messages.getString("RWikiObjectServiceImpl.30")).append(npages).append( //$NON-NLS-1$ Messages.getString("RWikiObjectServiceImpl.43")).append(nversions) //$NON-NLS-1$ .append(Messages.getString("RWikiObjectServiceImpl.44")); //$NON-NLS-1$ stack.pop(); } catch (IdUnusedException ex) { } return results.toString(); }
From source file:org.eclipse.ice.item.utilities.moose.MOOSEFileHandler.java
/** * This operations loads a MOOSE YAML file at the specified path and returns * a fully-configured set of ICE TreeComposites. * //from ww w. j ava2s . co m * @param filePath * The file path from which the MOOSE blocks written in YAML * should be read. If the path is null or empty, the operation * returns without doing any work. * @return The MOOSE input file specification as read from the YAML input * and stored in TreeComposites. Each TreeComposite contains both * parameters and exemplar children. Any parameters in a * TreeComposite are contained in a DataComponent. The id of the * data component is 1. * @throws IOException */ public ArrayList<TreeComposite> loadYAML(String filePath) throws IOException { // Local Declarations InputStream input = null; String syntaxFilePath, treeName; ArrayList<String> hardPathsList = null; ArrayList<TreeComposite> trees = new ArrayList<TreeComposite>(); Map<String, TreeComposite> treeMap = null; TreeComposite oneUpTree = null; // Quit if the path is boned if (filePath == null || filePath.isEmpty()) { return null; } // Get a handle on the YAML file File yamlFile = new File(filePath); input = new FileInputStream(yamlFile); // Get the project space directory string String projectDir = new File(yamlFile.getParent()).getParent(); // Load the YAML tree if (debugFlag) { logger.info("MOOSEFileHandler Message: Loading YAML file " + filePath.toString()); } Yaml yaml = new Yaml(); ArrayList<?> list = (ArrayList<?>) yaml.load(input); if (debugFlag) { logger.info("MOOSEFileHandler Message: File loaded."); } // Check we got a valid YAML file if (list == null || list.isEmpty()) { logger.error("Invalid YAML at " + yamlFile.getAbsolutePath()); return trees; } // Load the block list. Use YAMLBlocks so that they can be converted to // TreeComposites appropriately. for (int i = 0; i < list.size(); i++) { Block block = new YAMLBlock(); block.loadFromMap((Map<String, Object>) list.get(i)); // Recursively add Files to any File Entries in // this block setFileEntries(block, projectDir); block.active = true; trees.add(block.toTreeComposite()); } // Close the files try { input.close(); } catch (IOException e) { // Complain logger.error(getClass().getName() + " Exception!", e); } // Put all the names of top-level nodes into a list (we use this later) ArrayList<String> topLevelNodes = new ArrayList<String>(); for (TreeComposite node : trees) { topLevelNodes.add(node.getName()); } // Instantiate a HashMap that all TreeComposites and their exemplar // children trees can be added to, keyed by absolute path name treeMap = new HashMap<String, TreeComposite>(); // Create empty stack for TreeComposites Stack<TreeComposite> treeStack = new Stack<TreeComposite>(); treeStack.push(null); // Push the top level TreeComposites from the ArrayList first on first for (TreeComposite tree : trees) { treeStack.push(tree); } // Pop one of the top-level trees off to start. TreeComposite tree = treeStack.pop(); ArrayList<TreeComposite> childExemplars; treeName = ""; int prevNameIndex; while (tree != null) { // Append to the tree name treeName += "/" + tree.getName(); // Put the tree in the Map, keyed on path name treeMap.put((treeName.startsWith("/") ? treeName.substring(1) : treeName), tree); // Push child exemplars to the top of the tree stack childExemplars = tree.getChildExemplars(); for (int i = (childExemplars.size() - 1); i >= 0; i--) { treeStack.push(childExemplars.get(i)); } // If the next tree in the stack is a top-level tree, clear the // path name if (trees.contains(treeStack.peek())) { treeName = ""; } // Otherwise, if the current tree didn't have child exemplars to // push onto the stack, remove the last "part" of the path name, as // we'll be going back up one level else if (childExemplars.isEmpty()) { // Get the name of the tree one level up prevNameIndex = treeName.lastIndexOf("/" + tree.getName()); treeName = treeName.substring(0, prevNameIndex); // Go up another level if the next tree in the stack isn't // a child exemplar of the current tree referenced by treeName oneUpTree = treeMap.get(treeName.substring(1)); if (oneUpTree != null && !oneUpTree.getChildExemplars().contains(treeStack.peek())) { prevNameIndex = treeName.lastIndexOf("/"); treeName = ((prevNameIndex == 0 || prevNameIndex == -1) ? treeName : treeName.substring(0, prevNameIndex)); } } // Pop the next tree off the stack tree = treeStack.pop(); } // Define the file path of the action syntax file int yamlIndex = filePath.indexOf(".yaml"); syntaxFilePath = filePath.substring(0, yamlIndex) + ".syntax"; // Load the list of all "hard" paths from the action syntax file try { hardPathsList = loadActionSyntax(syntaxFilePath); } catch (IOException e) { logger.error(getClass().getName() + " Exception!", e); } // Begin looking through the TreeComposites for matches to the list of // "hard" paths from the action syntax file TreeComposite currTree; boolean hasType = false; int typeIndex = -1; String cleanPath; ArrayList<TreeComposite> types, currChildExemplars; DataComponent typeParameters = null, treeParameters = null; for (String path : hardPathsList) { // Clean the path of the excess return carriage at the end cleanPath = (path.endsWith("\r") ? path.substring(0, path.length() - 1) : path); // Get the tree with the corresponding hard path currTree = treeMap.get(cleanPath); // Check if there is a corresponding tree at all (depends on the // user's YAML file), and if so, if it has child exemplars if (currTree != null && !(currTree.getChildExemplars().isEmpty())) { // Iterate through the child exemplars, look for one named // "<type>" currChildExemplars = currTree.getChildExemplars(); for (int i = 0; i < currChildExemplars.size(); i++) { hasType = "<type>".equals(currChildExemplars.get(i).getName()); if (hasType) { typeIndex = i; break; } } if (hasType) { // Get the exemplars of <type>, these will become // the list of types to chose from types = currTree.getChildExemplars().get(typeIndex).getChildExemplars(); // Remove the <type> child exemplar from currTree currChildExemplars.remove(typeIndex); currTree.setChildExemplars(currChildExemplars); // Copy all the parameters from currTree into all to the // childExemplars before we instantiate an // AdaptiveTreeComposite Map<String, IEntry> parameterMap = new HashMap<String, IEntry>(); for (TreeComposite currType : types) { // Get the current type's data node typeParameters = (DataComponent) currType.getDataNodes().get(0); // Get the current tree's data node treeParameters = (DataComponent) currTree.getDataNodes().get(0); // Put all the typeParameters in a HashMap, keyed on // name parameterMap.clear(); for (IEntry parameter : typeParameters.retrieveAllEntries()) { parameterMap.put(parameter.getName(), parameter); } // Loop through the current tree's parameters, appending // them all onto the type's parameters list for (IEntry currEntry : treeParameters.retrieveAllEntries()) { // Check that the HashMap doesn't already have an // entry with the same name if (!parameterMap.containsKey(currEntry.getName())) { // Append the parameter from one list onto the // other typeParameters.addEntry(currEntry); } } } // Create a new AdaptiveTreeComposite with the list of types AdaptiveTreeComposite adapTree = new AdaptiveTreeComposite(types); // Copy all the TreeComposite data (data node, exemplars, // etc.) from currTree adapTree.copy(currTree); currTree = adapTree; // Overwrite the tree in the map treeMap.put(cleanPath, adapTree); // Since we allocated the AdaptiveTreeComposite with new, // the reference to the original object is lost, so we must // wire it back in // Check if this tree is a child exemplar of something (ie. // isn't a top-level node) if (!topLevelNodes.contains(currTree.getName())) { // Get the name of the tree that this // AdaptiveTreeComposite is a child exemplar of prevNameIndex = cleanPath.indexOf("/" + currTree.getName()); treeName = cleanPath.substring(0, prevNameIndex); // Re-set the AdaptiveTreeComposite as a child exemplar // of whatever tree it belongs to TreeComposite exemplarParent = treeMap.get(treeName); if (exemplarParent != null) { exemplarParent.addChildExemplar(currTree); } } } } // Reset flags, indices hasType = false; typeIndex = -1; } // Reconstruct the top level nodes into an ArrayList ArrayList<TreeComposite> newTrees = new ArrayList<TreeComposite>(); for (String nodeName : topLevelNodes) { newTrees.add(treeMap.get(nodeName)); } return newTrees; }
From source file:EditorPaneTest.java
public EditorPaneFrame() { setTitle("EditorPaneTest"); setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT); final Stack<String> urlStack = new Stack<String>(); final JEditorPane editorPane = new JEditorPane(); final JTextField url = new JTextField(30); // set up hyperlink listener editorPane.setEditable(false);//from www . ja v a 2 s . c o m editorPane.addHyperlinkListener(new HyperlinkListener() { public void hyperlinkUpdate(HyperlinkEvent event) { if (event.getEventType() == HyperlinkEvent.EventType.ACTIVATED) { try { // remember URL for back button urlStack.push(event.getURL().toString()); // show URL in text field url.setText(event.getURL().toString()); editorPane.setPage(event.getURL()); } catch (IOException e) { editorPane.setText("Exception: " + e); } } } }); // set up checkbox for toggling edit mode final JCheckBox editable = new JCheckBox(); editable.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { editorPane.setEditable(editable.isSelected()); } }); // set up load button for loading URL ActionListener listener = new ActionListener() { public void actionPerformed(ActionEvent event) { try { // remember URL for back button urlStack.push(url.getText()); editorPane.setPage(url.getText()); } catch (IOException e) { editorPane.setText("Exception: " + e); } } }; JButton loadButton = new JButton("Load"); loadButton.addActionListener(listener); url.addActionListener(listener); // set up back button and button action JButton backButton = new JButton("Back"); backButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { if (urlStack.size() <= 1) return; try { // get URL from back button urlStack.pop(); // show URL in text field String urlString = urlStack.peek(); url.setText(urlString); editorPane.setPage(urlString); } catch (IOException e) { editorPane.setText("Exception: " + e); } } }); add(new JScrollPane(editorPane), BorderLayout.CENTER); // put all control components in a panel JPanel panel = new JPanel(); panel.add(new JLabel("URL")); panel.add(url); panel.add(loadButton); panel.add(backButton); panel.add(new JLabel("Editable")); panel.add(editable); add(panel, BorderLayout.SOUTH); }
From source file:org.apache.tajo.engine.planner.LogicalPlanner.java
private List<String> getNewlyEvaluatedExprsForJoin(PlanContext context, JoinNode joinNode, Stack<Expr> stack) { QueryBlock block = context.queryBlock; EvalNode evalNode;/*w ww. ja v a 2s.c o m*/ List<String> newlyEvaluatedExprs = TUtil.newList(); for (Iterator<NamedExpr> it = block.namedExprsMgr.getIteratorForUnevaluatedExprs(); it.hasNext();) { NamedExpr namedExpr = it.next(); try { evalNode = exprAnnotator.createEvalNode(context, namedExpr.getExpr(), NameResolvingMode.LEGACY); if (LogicalPlanner.checkIfBeEvaluatedAtJoin(block, evalNode, joinNode, stack.peek().getType() != OpType.Join)) { block.namedExprsMgr.markAsEvaluated(namedExpr.getAlias(), evalNode); newlyEvaluatedExprs.add(namedExpr.getAlias()); } } catch (VerifyException ve) { } catch (PlanningException e) { } } return newlyEvaluatedExprs; }
From source file:com.udojava.evalex.Expression.java
/** * Evaluates the expression./*from w w w .j a va 2 s .c o m*/ * * @return The result of the expression. */ public MyComplex eval() { Stack<LazyNumber> stack = new Stack<>(); for (final String token : getRPN()) { if (operators.containsKey(token)) { final LazyNumber v1 = stack.pop(); final LazyNumber v2 = stack.pop(); LazyNumber number = () -> operators.get(token).eval(v2.eval(), v1.eval()); stack.push(number); } else if (mainVars.getMap().containsKey(token)) { MyComplex v = mainVars.get(token); if (v.type == ValueType.ARRAY) { stack.push(() -> v); } else { PitDecimal bd = new PitDecimal(v.real, v.imaginary); bd.type = v.type; bd.setVarToken(token); stack.push(() -> bd); } } else if (functions.containsKey(token.toUpperCase(Locale.ROOT))) { LazyFunction f = functions.get(token.toUpperCase(Locale.ROOT)); ArrayList<LazyNumber> p = new ArrayList<>(!f.numParamsVaries() ? f.getNumParams() : 0); // pop parameters off the stack until we hit the start of // this function's parameter list while (!stack.isEmpty() && stack.peek() != PARAMS_START) { p.add(0, stack.pop()); } if (stack.peek() == PARAMS_START) { stack.pop(); } LazyNumber fResult = f.lazyEval(p); stack.push(fResult); } else if ("(".equals(token)) { stack.push(PARAMS_START); } else { MyComplex bd; if (token.endsWith("i")) { String str = token.substring(0, token.length() - 1); if (str.isEmpty()) str = "1"; bd = new MyComplex("0", str); } else { bd = new MyComplex(token); } MyComplex finalBd = bd; stack.push(() -> finalBd); // blank constant } } return stack.pop().eval(); }
From source file:org.sakaiproject.lessonbuildertool.service.LessonBuilderEntityProducer.java
/** * {@inheritDoc}/*from ww w . j ava2s .co m*/ */ public String archive(String siteId, Document doc, Stack stack, String archivePath, List attachments) { //prepare the buffer for the results log StringBuilder results = new StringBuilder(); try { Site site = siteService.getSite(siteId); // start with an element with our very own (service) name Element element = doc.createElement(serviceName()); element.setAttribute(VERSION_ATTR, ARCHIVE_VERSION); ((Element) stack.peek()).appendChild(element); stack.push(element); Element lessonbuilder = doc.createElement(LESSONBUILDER); List<SimplePage> sitePages = simplePageToolDao.getSitePages(siteId); if (sitePages != null && !sitePages.isEmpty()) { for (SimplePage page : sitePages) addPage(doc, lessonbuilder, page, site); } Collection<ToolConfiguration> tools = site.getTools(myToolIds()); int count = 0; if (tools != null && !tools.isEmpty()) { for (ToolConfiguration config : tools) { element = doc.createElement(LESSONBUILDER); addAttr(doc, element, "toolid", config.getPageId()); addAttr(doc, element, "name", config.getContainingPage().getTitle()); Properties props = config.getPlacementConfig(); String roleList = props.getProperty("functions.require"); if (roleList == null) roleList = ""; addAttr(doc, element, "functions.require", roleList); // should be impossible for these nulls, but we've seen it if (simplePageToolDao.getTopLevelPageId(config.getPageId()) != null) addAttr(doc, element, "pageId", Long.toString(simplePageToolDao.getTopLevelPageId(config.getPageId()))); else logger.warn("archive site " + siteId + " tool page " + config.getPageId() + " null lesson"); // addPage(doc, element, simplePageToolDao.getTopLevelPageId(config.getPageId())); lessonbuilder.appendChild(element); count++; } results.append("archiving " + count + " LessonBuilder instances.\n"); } else { results.append("archiving no LessonBuilder instances.\n"); } ((Element) stack.peek()).appendChild(lessonbuilder); stack.push(lessonbuilder); stack.pop(); } catch (Exception any) { any.printStackTrace(); logger.warn("archive: exception archiving service: " + any + " " + serviceName()); } stack.pop(); return results.toString(); }
From source file:com.sqewd.open.dal.core.persistence.db.EntityHelper.java
@SuppressWarnings({ "rawtypes", "unchecked" }) public static Object getColumnValue(final ResultSet rs, final StructAttributeReflect attr, final AbstractEntity entity, final AbstractJoinGraph gr, final Stack<KeyValuePair<Class<?>>> path) throws Exception { Object value = null;/* w w w .java 2 s .com*/ KeyValuePair<String> alias = gr.getAliasFor(path, attr.Column, 0); String tabprefix = alias.getKey(); if (EnumPrimitives.isPrimitiveType(attr.Field.getType())) { EnumPrimitives prim = EnumPrimitives.type(attr.Field.getType()); switch (prim) { case ECharacter: String sv = rs.getString(tabprefix + "." + attr.Column); if (!rs.wasNull()) { PropertyUtils.setSimpleProperty(entity, attr.Field.getName(), sv.charAt(0)); } break; case EShort: short shv = rs.getShort(tabprefix + "." + attr.Column); if (!rs.wasNull()) { PropertyUtils.setSimpleProperty(entity, attr.Field.getName(), shv); } break; case EInteger: int iv = rs.getInt(tabprefix + "." + attr.Column); if (!rs.wasNull()) { PropertyUtils.setSimpleProperty(entity, attr.Field.getName(), iv); } break; case ELong: long lv = rs.getLong(tabprefix + "." + attr.Column); if (!rs.wasNull()) { PropertyUtils.setSimpleProperty(entity, attr.Field.getName(), lv); } break; case EFloat: float fv = rs.getFloat(tabprefix + "." + attr.Column); if (!rs.wasNull()) { PropertyUtils.setSimpleProperty(entity, attr.Field.getName(), fv); } break; case EDouble: double dv = rs.getDouble(tabprefix + "." + attr.Column); if (!rs.wasNull()) { PropertyUtils.setSimpleProperty(entity, attr.Field.getName(), dv); } break; default: throw new Exception("Unsupported Data type [" + prim.name() + "]"); } } else if (attr.Convertor != null) { // TODO : Not supported at this time. value = rs.getString(tabprefix + "." + attr.Column); } else if (attr.Field.getType().equals(String.class)) { value = rs.getString(tabprefix + "." + attr.Column); if (rs.wasNull()) { value = null; } } else if (attr.Field.getType().equals(Date.class)) { long lvalue = rs.getLong(tabprefix + "." + attr.Column); if (!rs.wasNull()) { Date dt = new Date(lvalue); value = dt; } } else if (attr.Field.getType().isEnum()) { String svalue = rs.getString(tabprefix + "." + attr.Column); if (!rs.wasNull()) { Class ecls = attr.Field.getType(); value = Enum.valueOf(ecls, svalue); } } else if (attr.Reference != null) { Class<?> rt = Class.forName(attr.Reference.Class); Object obj = rt.newInstance(); if (!(obj instanceof AbstractEntity)) throw new Exception("Unsupported Entity type [" + rt.getCanonicalName() + "]"); AbstractEntity rentity = (AbstractEntity) obj; if (path.size() > 0) { path.peek().setKey(attr.Column); } KeyValuePair<Class<?>> cls = new KeyValuePair<Class<?>>(); cls.setValue(rentity.getClass()); path.push(cls); setEntity(rentity, rs, gr, path); value = rentity; path.pop(); } return value; }