List of usage examples for java.util Hashtable containsKey
public synchronized boolean containsKey(Object key)
From source file:ca.queensu.cs.sail.mailboxmina2.main.modules.ThreadsModule.java
/** This method calculates all roots for the given messages in messageData * and stores this information in the database * @param messages a list of Messages//from www.j av a2 s . c o m * @throws SQLException if there was an error with the database */ private void calculateRoots(List<MM2Message> messages, Connection connection) throws SQLException { // Needed Data Structures Hashtable<String, String> parentsTable = new Hashtable<String, String>(); Hashtable<String, String> rootsTable = new Hashtable<String, String>(); // Build up parents table form database String query = "SELECT * FROM parent"; Statement stmt = connection.createStatement(); ResultSet results = stmt.executeQuery(query); while (results.next()) { parentsTable.put(results.getString("msg_id"), results.getString("parent_id")); } Main.getLogger().debug(3, parentsTable.keySet().size() + " parent relations are known!"); // Calculate all roots for (MM2Message msg : messages) { String msgUID = msg.getHeaderEntry("msg_id"); String rootUID = msgUID; if (parentsTable.containsKey(msgUID)) { Set<String> seenParents = new HashSet<String>(); String myParent = parentsTable.get(msgUID); seenParents.add(myParent); while (myParent != null) { rootUID = myParent; myParent = parentsTable.get(myParent); if (seenParents.contains(myParent)) { Main.getLogger().log("Parents Cycle: " + rootUID + " " + myParent); break; } else { seenParents.add(myParent); } } } rootsTable.put(msgUID, rootUID); } Main.getLogger().log("Storing " + rootsTable.keySet().size() + " roots in database..."); storeRoots(rootsTable, connection); }
From source file:org.jboss.dashboard.workspace.CopyManagerImpl.java
public Section copy(final Section section, final WorkspaceImpl workspace, final SectionCopyOption sco) throws Exception { final Section[] results = new Section[] { null }; HibernateTxFragment txFragment = new HibernateTxFragment() { protected void txFragment(Session session) throws Exception { SectionCopyOption copyOption = sco; log.debug("Copying section " + section.getId() + " to Workspace " + workspace.getId()); if (copyOption == null) { if (workspace.getId().equals(section.getWorkspace().getId())) copyOption = CopyOption.DEFAULT_SECTION_COPY_OPTION_SAME_WORKSPACE; else copyOption = CopyOption.DEFAULT_SECTION_COPY_OPTION_OTHER_WORKSPACE; }/* w ww . j a va 2 s. c o m*/ Section sectionCopy = (Section) section.clone(); sectionCopy.setPosition(-1); //Let the workspace decide the position later sectionCopy.setWorkspace(workspace); boolean copyingToSameWorkspace = workspace.getId().equals(section.getWorkspace().getId()); if (copyingToSameWorkspace) {//Section in same workspace-> can't reuse the id sectionCopy.setId(null); } else {//Section in different workspace-> can reuse the url sectionCopy.setFriendlyUrl(section.getFriendlyUrl()); } if (log.isDebugEnabled()) log.debug("Storing basic section copy to workspace " + workspace.getId()); UIServices.lookup().getSectionsManager().store(sectionCopy); // Add to destination workspace if (log.isDebugEnabled()) log.debug("Adding cloned section (" + sectionCopy.getId() + ") to workspace " + workspace.getId()); workspace.addSection(sectionCopy); UIServices.lookup().getWorkspacesManager().store(workspace); //Resources copyResources(section, sectionCopy); // Panels inside section LayoutRegion[] regions = section.getLayout().getRegions(); log.debug("Regions in section are " + Arrays.asList(regions)); Hashtable panelInstanceMappings = new Hashtable(); for (int i = 0; i < regions.length; i++) { LayoutRegion region = regions[i]; Panel[] panels = section.getPanels(region); if (log.isDebugEnabled()) log.debug("Copying " + panels.length + " panels in region " + region); for (int j = 0; panels != null && j < panels.length; j++) { Panel panelClone = null; PanelInstance instanceClone = panels[j].getInstance(); String panelInstanceId = panels[j].getInstanceId().toString(); if (copyOption.isDuplicatePanelInstance(panelInstanceId)) { //Duplicate Panel instance for this panel. if (panelInstanceMappings.containsKey(panelInstanceId)) { instanceClone = (PanelInstance) panelInstanceMappings.get(panelInstanceId); } else { instanceClone = copy(panels[j].getInstance(), workspace); panelInstanceMappings.put(panelInstanceId, instanceClone); } } panelClone = copy(panels[j], sectionCopy, null, instanceClone); if (panelClone == null) log.error("Panel " + panels[j].getPanelId() + " failed to copy itself to Section " + sectionCopy.getId()); } } copyPermissions(section, sectionCopy); session.flush(); session.refresh(sectionCopy); // To fix bug 2011 results[0] = sectionCopy; } }; synchronized (("workspace_" + workspace.getDbid()).intern()) { txFragment.execute(); } return results[0]; }
From source file:org.hdiv.filter.ValidatorHelperRequest.java
/** * Check if all required parameters are received in <code>request</code>. * /*from www .j ava 2 s . c o m*/ * @param request * HttpServletRequest to validate * @param state * IState The restored state for this url * @param target * Part of the url that represents the target action * @return valid result if all required parameters are received. False in otherwise. */ private ValidatorHelperResult allRequiredParametersReceived(HttpServletRequest request, IState state, String target) { Hashtable receivedParameters = new Hashtable(state.getRequiredParams()); String currentParameter = null; Enumeration requestParameters = request.getParameterNames(); while (requestParameters.hasMoreElements()) { currentParameter = (String) requestParameters.nextElement(); if (receivedParameters.containsKey(currentParameter)) { receivedParameters.remove(currentParameter); } // If multiple parameters are received, it is possible to pass this // verification without checking all the request parameters. if (receivedParameters.size() == 0) { return ValidatorHelperResult.VALID; } } if (receivedParameters.size() > 0) { this.logger.log(HDIVErrorCodes.REQUIRED_PARAMETERS, target, receivedParameters.keySet().toString(), null); return new ValidatorHelperResult(HDIVErrorCodes.REQUIRED_PARAMETERS); } return ValidatorHelperResult.VALID; }
From source file:org.apache.pig.impl.logicalLayer.LOJoin.java
@Override public Schema getSchema() throws FrontendException { List<LogicalOperator> inputs = mPlan.getPredecessors(this); mType = DataType.BAG;//mType is from the super class Hashtable<String, Integer> nonDuplicates = new Hashtable<String, Integer>(); if (!mIsSchemaComputed) { List<Schema.FieldSchema> fss = new ArrayList<Schema.FieldSchema>(); mSchemaInputMapping = new ArrayList<LogicalOperator>(); int i = -1; boolean seeUnknown = false; for (LogicalOperator op : inputs) { try { Schema cSchema = op.getSchema(); if (cSchema != null) { for (FieldSchema schema : cSchema.getFields()) { ++i;/* www. ja v a2 s .c o m*/ FieldSchema newFS = null; if (schema.alias != null) { if (nonDuplicates.containsKey(schema.alias)) { if (nonDuplicates.get(schema.alias) != -1) { nonDuplicates.remove(schema.alias); nonDuplicates.put(schema.alias, -1); } } else { nonDuplicates.put(schema.alias, i); } newFS = new FieldSchema(op.getAlias() + "::" + schema.alias, schema.schema, schema.type); } else { newFS = new Schema.FieldSchema(null, schema.type); } newFS.setParent(schema.canonicalName, op); fss.add(newFS); mSchemaInputMapping.add(op); } } else { seeUnknown = true; } } catch (FrontendException ioe) { mIsSchemaComputed = false; mSchema = null; throw ioe; } } mIsSchemaComputed = true; mSchema = null; if (!seeUnknown) { mSchema = new Schema(fss); for (Entry<String, Integer> ent : nonDuplicates.entrySet()) { int ind = ent.getValue(); if (ind == -1) continue; FieldSchema prevSch = fss.get(ind); // this is a non duplicate and hence can be referred to // with just the field schema alias or outeralias::field schema alias // In mSchema we have outeralias::fieldschemaalias. To allow // using just the field schema alias, add it to mSchemas // as an alias for this field. mSchema.addAlias(ent.getKey(), prevSch); } } } return mSchema; }
From source file:com.eleybourn.bookcatalogue.utils.Utils.java
/** * Passed a parent view, add it and all children view (if any) to the passed collection * /*w w w. j a v a 2 s . c o m*/ * @param p Parent View * @param vh Collection */ private static void getViews(View p, Hashtable<Integer, View> vh) { // Get the view ID and add it to collection if not already present. final int id = p.getId(); if (id != View.NO_ID && !vh.containsKey(id)) { vh.put(id, p); } // If it's a ViewGroup, then process children recursively. if (p instanceof ViewGroup) { final ViewGroup g = (ViewGroup) p; final int nChildren = g.getChildCount(); for (int i = 0; i < nChildren; i++) { getViews(g.getChildAt(i), vh); } } }
From source file:org.kepler.dataproxy.metadata.ADN.ADNMetadataSpecification.java
/** * This method will transfer ResultsetType java object to array of * ResultRecord java object. The ResultRecord object can be shown in kepler. * If the results is null or there is no record in the result, null will be * return/* w w w . j ava 2 s . c o m*/ * * @param ResultsetType * results the result need to be transform * @param String * endpoints the search end point * @return ResultRecord[] the resultrecord need be returned. */ public boolean transformResultset(ResultsetType results, String endpoint, CompositeEntity container, Vector aResultList) throws SAXException, IOException, EcoGridException, NameDuplicationException, IllegalActionException { if (results == null) { return false; // ??? } ResultsetTypeResultsetMetadata metaData = results.getResultsetMetadata(); if (metaData != null) { populateFieldMap(metaData); } // transfer ResultType to a vector of sorted titles containing // (title,ids,returnFieldsVector) Vector resultsetItemList = transformResultsetType(results); // transfer the sored vector (contains eml2resultsetitem object to an // array // of ResultRecord int numResults = resultsetItemList.size(); aResultList = new Vector(); Hashtable titleList = new Hashtable();// This hashtable is for keeping // track // if there is a duplicate title for (int i = 0; i < numResults; i++) { try { SortableResultRecord source = (SortableResultRecord) resultsetItemList.elementAt(i); String title = source.getTitle(); log.debug("The title is " + title); String id = source.getId(); log.debug("The id is " + id); Vector returnFieldList = source.getEntityList(); // if couldn't find id, skip this record if (id == null || id.trim().equals("")) { continue; } // if couldn't find title, assign a one to it -- <j> if (title == null || title.trim().equals("")) { title = "<" + i + ">"; } if (titleList.containsKey(title)) { title = title + " " + i; } titleList.put(title, title); String format = null; String description = ""; for (int j = 0; j < returnFieldList.size(); j++) { ResultsetTypeRecordReturnField returnField = (ResultsetTypeRecordReturnField) returnFieldList .elementAt(j); if (returnField == null) { continue; } String returnFieldId = returnField.getId(); String returnFieldValue = returnField.get_value(); String returnFieldName = (String) fieldIdtoNameMap.get(returnFieldId); if (returnFieldName != null && !returnFieldName.trim().equals("")) { if (returnFieldName.equals("description")) { log.debug("The description after parsing is " + returnFieldValue); description = returnFieldValue; } else if (returnFieldName.equals("format")) { format = returnFieldValue; } } } TypedAtomicActor newRecord = null; if (format.trim().toLowerCase().indexOf("database") > -1) { // VERIFY!!!! log.debug("The entiy is a database resource"); newRecord = new GEONDatabaseResource(container, title); ((GEONDatabaseResource) newRecord)._idAtt.setExpression(id); ((GEONDatabaseResource) newRecord)._endpointAtt.setExpression(endpoint); ((GEONDatabaseResource) newRecord)._namespaceAtt.setExpression(namespace); ((GEONDatabaseResource) newRecord)._descriptionAtt .setExpression(restyleDescription(description)); } else if (format.equals("shapefile")) { log.debug("The entiy is a shapefile resource"); newRecord = new GEONShpResource(container, title); ((GEONShpResource) newRecord)._idAtt.setExpression(id); ((GEONShpResource) newRecord)._endpointAtt.setExpression(endpoint); ((GEONShpResource) newRecord)._namespaceAtt.setExpression(namespace); ((GEONShpResource) newRecord)._descriptionAtt.setExpression(restyleDescription(description)); } else continue; aResultList.add(newRecord); } catch (Exception e) { continue; } } // for _numResults = aResultList.size(); return _numResults > 0; }
From source file:com.cyberway.issue.crawler.Heritrix.java
protected static ObjectName addGuiPort(ObjectName name) throws MalformedObjectNameException, NullPointerException { @SuppressWarnings("unchecked") Hashtable<String, String> ht = name.getKeyPropertyList(); if (!ht.containsKey(JmxUtils.GUI_PORT)) { // Add gui port if this instance was started with a gui. if (Heritrix.gui) { ht.put(JmxUtils.GUI_PORT, Integer.toString(Heritrix.guiPort)); name = new ObjectName(name.getDomain(), ht); }/*www . j a v a 2 s. c om*/ } return name; }
From source file:com.cyberway.issue.crawler.Heritrix.java
/** * Add vital stats to passed in ObjectName. * @param name ObjectName to add to.//from ww w. j av a 2 s . c o m * @return name with host, guiport, and jmxport added. * @throws UnknownHostException * @throws MalformedObjectNameException * @throws NullPointerException */ protected static ObjectName addVitals(ObjectName name) throws UnknownHostException, MalformedObjectNameException, NullPointerException { @SuppressWarnings("unchecked") Hashtable<String, String> ht = name.getKeyPropertyList(); if (!ht.containsKey(JmxUtils.HOST)) { ht.put(JmxUtils.HOST, InetAddress.getLocalHost().getHostName()); name = new ObjectName(name.getDomain(), ht); } if (!ht.containsKey(JmxUtils.JMX_PORT)) { // Add jdk jmx-port. This will be present if we've attached // ourselves to the jdk jmx agent. Otherwise, we've been // deployed in a j2ee container with its own jmx agent. In // this case we won't know how to get jmx port. String p = System.getProperty("com.sun.management.jmxremote.port"); if (p != null && p.length() > 0) { ht.put(JmxUtils.JMX_PORT, p); name = new ObjectName(name.getDomain(), ht); } } return name; }
From source file:org.hdiv.filter.AbstractValidatorHelper.java
/** * Checks if repeated or no valid values have been received for the * parameter <code>parameter</code>. * /*from www. j a v a2s. co m*/ * @param target Part of the url that represents the target action * @param parameter parameter name * @param values Parameter <code>parameter</code> values * @param tempStateValues values stored in state for <code>parameter</code> * @return True If repeated or no valid values have been received for the * parameter <code>parameter</code>. */ private boolean hasNonConfidentialIncorrectValues(String target, String parameter, String[] values, List tempStateValues) { Hashtable receivedValues = new Hashtable(); for (int i = 0; i < values.length; i++) { boolean exists = false; for (int j = 0; j < tempStateValues.size() && !exists; j++) { String tempValue = (String) tempStateValues.get(j); if (tempValue.equalsIgnoreCase(values[i])) { tempStateValues.remove(j); exists = true; } } if (!exists) { if (receivedValues.containsKey(values[i])) { this.logger.log(HDIVErrorCodes.REPEATED_VALUES, target, parameter, values[i]); return true; } this.logger.log(HDIVErrorCodes.PARAMETER_VALUE_INCORRECT, target, parameter, values[i]); return true; } receivedValues.put(values[i], values[i]); } return false; }
From source file:com.fiorano.openesb.application.aps.ApplicationHeader.java
/** * Sets all the fieldValues of this <code>ApplicationHeader</code> object * from the XML using STAX parser./*from w ww .j a v a 2s .com*/ */ public void populate(FioranoStaxParser cursor) throws XMLStreamException, FioranoException { //Set cursor to the current DMI element. You can use either markCursor/getNextElement(<element>) API. if (cursor.markCursor(APSConstants.APPLICATION_HEADER)) { // Get Attributes. This MUST be done before accessing any data of element. Hashtable attributes = cursor.getAttributes(); if (attributes != null && attributes.containsKey(APSConstants.ATTR_IS_SUBGRAPHABLE)) { boolean canSub = XMLUtils .getStringAsBoolean((String) attributes.get(APSConstants.ATTR_IS_SUBGRAPHABLE)); setCanBeSubGraphed(canSub); } if (attributes != null && attributes.containsKey(APSConstants.ATTR_SCOPE)) { String scope = (String) attributes.get(APSConstants.ATTR_SCOPE); setScope(scope); } //Get associated Data //String nodeVal = cursor.getText(); // Get Child Elements while (cursor.nextElement()) { String nodeName = cursor.getLocalName(); // Get Attributes attributes = cursor.getAttributes(); //String nodeValue = cursor.getText(); //if (nodeValue == null) // continue; if (nodeName.equalsIgnoreCase("Name")) { String nodeValue = cursor.getText(); setApplicationName(nodeValue); } else if (nodeName.equalsIgnoreCase("ApplicationGUID")) { String nodeValue = cursor.getText(); setApplicationGUID(nodeValue); } else if (nodeName.equalsIgnoreCase("Author")) { String nodeValue = cursor.getText(); addAuthor(nodeValue); } else if (nodeName.equalsIgnoreCase("CreationDate")) { String nodeValue = cursor.getText(); setCreationDate(nodeValue); } else if (nodeName.equalsIgnoreCase("Icon")) { String nodeValue = cursor.getText(); setIcon(nodeValue); } else if (nodeName.equalsIgnoreCase("Version")) { String nodeValue = cursor.getText(); if (attributes != null) { boolean isLocked = XMLUtils.getStringAsBoolean((String) attributes.get("isLocked")); setIsVersionLocked(isLocked); setVersionNumber(nodeValue); } } else if (nodeName.equalsIgnoreCase("Label")) { m_strProfile = cursor.getText(); } else if (nodeName.equalsIgnoreCase("CompatibleWith")) { String nodeValue = cursor.getText(); addCompatibleWith(nodeValue); } else if (nodeName.equalsIgnoreCase("Category")) { String nodeValue = cursor.getText(); setCategoryIn(nodeValue); } else if (nodeName.equalsIgnoreCase("LongDescription")) { String nodeValue = cursor.getText(); setLongDescription(nodeValue); } else if (nodeName.equalsIgnoreCase("ShortDescription")) { String nodeValue = cursor.getText(); setShortDescription(nodeValue); } // LOOK AT THIS. SHOULD PASS THIS TO BE HANDLED BY PARAM DMI else if (nodeName.equalsIgnoreCase("Param")) { String nodeValue = cursor.getText(); Param param = new Param(); param.setParamName((String) attributes.get(APSConstants.PARAM_NAME)); param.setParamValue(nodeValue); //changed by Sandeep M /* param.setFieldValues(cursor); */ /* String name = (String)attributes.get("name"); param.setParamValue(nodeValue); param.populate(cursor); */ m_params.add(param); } else if (nodeName.equalsIgnoreCase("ApplicationContext")) { m_appContext = new ApplicationContext(); m_appContext.setFieldValues(cursor); } } validate(); } else throw new FioranoException(DmiErrorCodes.ERR_INVALID_ARGUMENT_ERROR); }