List of usage examples for java.util Hashtable isEmpty
public synchronized boolean isEmpty()
From source file:org.mybatisorm.annotation.handler.JoinHandler.java
private String getImplicitJoin(List<Field> fields) { Hashtable<Set<Class<?>>, LinkedList<Field[]>> refMap = getRefMap(fields); if (refMap.isEmpty()) throw new InvalidAnnotationException("References for join not found"); Field field = fields.get(0);/*from w w w. ja va 2 s .co m*/ Class<?> clazz = field.getType(), clazz2; LinkedList<Field[]> refs = null; StringBuilder sb = new StringBuilder(); TableHandler handler = HandlerFactory.getHandler(clazz); String table = handler.getName(), alias = field.getName() + "_"; Map<String, String> aliases = new HashMap<String, String>(); aliases.put(table, alias); sb.append(table).append(" ").append(alias); List<String> cnames = new LinkedList<String>(); for (int i = 1; i < fields.size(); i++) { field = fields.get(i); clazz = field.getType(); table = HandlerFactory.getHandler(clazz).getName(); alias = field.getName() + "_"; aliases.put(table, alias); int j; for (j = i - 1; j >= 0; j--) { clazz2 = fields.get(j).getType(); cnames.add(0, clazz2.getSimpleName()); refs = refMap.get(pair(clazz, clazz2)); if (refs == null) continue; sb.append(" INNER JOIN ").append(table).append(" ").append(alias).append(" ON ("); Iterator<Field[]> it = refs.iterator(); while (it.hasNext()) { Field[] fs = it.next(); table = HandlerFactory.getHandler(fs[0].getDeclaringClass()).getName(); alias = aliases.get(table); sb.append(alias).append(".").append(ColumnAnnotation.getName(fs[0])).append(" = "); table = HandlerFactory.getHandler(fs[1].getDeclaringClass()).getName(); alias = aliases.get(table); sb.append(alias).append(".").append(ColumnAnnotation.getName(fs[1])); if (it.hasNext()) sb.append(" AND "); } sb.append(")"); break; } if (j < 0) throw new InvalidJoinException("The class " + clazz.getSimpleName() + " doesn't refer to the former classes. (" + StringUtil.join(cnames, ",") + ")"); cnames.clear(); } return sb.toString(); }
From source file:org.wso2.carbon.context.CarbonContext.java
/** * Create filter from the bundle context adding class name and properties * * @param bundleContext BundleContext//ww w. ja v a2s. c o m * @param clazz The type of the OSGi service * @param props attribute list that filter the service list * @return Filter * @throws InvalidSyntaxException */ protected Filter createFilter(BundleContext bundleContext, Class clazz, Hashtable<String, String> props) throws InvalidSyntaxException { StringBuilder buf = new StringBuilder(); buf.append("(objectClass=" + clazz.getName() + ")"); if (props != null && !props.isEmpty()) { buf.insert(0, "(&"); for (Map.Entry<String, String> entry : props.entrySet()) { buf.append("(" + entry.getKey() + "=" + entry.getValue() + ")"); } buf.append(")"); } return bundleContext.createFilter(buf.toString()); }
From source file:org.unitime.timetable.solver.curricula.CurriculaCourseDemands.java
public Set<WeightedStudentId> getDemands(CourseOffering course) { if (iDemands.isEmpty()) return iFallback.getDemands(course); Set<WeightedStudentId> demands = iDemands.get(course.getUniqueId()); if (!iIncludeOtherStudents) return demands; if (demands == null) { demands = new HashSet<WeightedStudentId>(); iDemands.put(course.getUniqueId(), demands); }// w w w .j av a 2 s .co m if (iCheckedCourses.add(course.getUniqueId())) { int was = demands.size(); Hashtable<String, Set<String>> curricula = iLoadedCurricula.get(course.getUniqueId()); Set<WeightedStudentId> other = iFallback.getDemands(course); if (curricula == null || curricula.isEmpty()) { demands.addAll(other); } else { other: for (WeightedStudentId student : other) { // if (student.getAreas().isEmpty()) continue; // ignore students w/o academic area for (AreaCode area : student.getAreas()) { Set<String> majors = curricula.get(area.getArea()); if (majors != null && (majors.contains("") || student.match(area.getArea(), majors))) continue other; // all majors or match } demands.add(student); } } if (demands.size() > was) sLog.info(course.getCourseName() + " has " + (demands.size() - was) + " other students (besides of the " + was + " curriculum students)."); } return demands; }
From source file:hu.sztaki.lpds.storage.service.carmen.server.upload.UploadServlet.java
/** * Processes requests for <code>GET</code> methods. * * @param request/*from w w w . ja v a2s . co m*/ * servlet request * @param response * servlet response * @throws IOException channel handling error * @throws ServletException Servlet error */ protected void getProcessRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // System.out.println(""); // System.out.println("UploadServlet getProcessRequest begin..."); ServletOutputStream out = response.getOutputStream(); String getSID = null; String getendSID = null; String retStr = new String(""); try { getSID = request.getParameter("sid"); // System.out.println("getSID: " + getSID); } catch (Exception e) { e.printStackTrace(); } try { getendSID = request.getParameter("endsid"); // System.out.println("getendSID: " + getendSID); } catch (Exception e) { e.printStackTrace(); } // if ((getSID != null) && (getendSID == null)) { // get type "sid" // System.out.println("get type SID : " + getSID); if (!getSID.trim().equals("")) { retStr = UploadUtils.getInstance().getGenerateRetHTMLString(getSID); } else { retStr = new String("Error in parameter: sid"); } } else if ((getSID == null) && (getendSID != null)) { // get type "endsid" // System.out.println("get type endSID : " + getendSID); if (!getendSID.trim().equals("")) { // check error uploads boolean haveError = false; // get file list (fileHash) Hashtable fileHash = UploadItemsList.getInstance().getFileHash(getendSID); // parse if ((fileHash != null) && (!fileHash.isEmpty())) { Enumeration enumeration = fileHash.keys(); StringBuffer sb = new StringBuffer(); while (enumeration.hasMoreElements()) { String fileName = (String) enumeration.nextElement(); if ((fileName != null) && (!fileName.equals(""))) { UploadItemBean uploadItemBean = (UploadItemBean) fileHash.get(fileName); Integer filePerCent = uploadItemBean.getPerCent(); String fileErrorStr = uploadItemBean.getErrorStr(); // System.out.println("fileName - fileErrorStr : " + fileName + " - " + fileErrorStr); if (fileErrorStr.startsWith("Error")) { haveError = true; // System.out.println("have error in : "); // retStr = new String(fileErrorStr + "</ br>"); sb.append(new String(fileErrorStr + "</ br>")); // System.out.println("fileName : " + fileName); } } } retStr = sb.toString(); // System.out.println("Storage Upload Servlet haveError : " + haveError); if (haveError) { retStr = new String("Error in upload process ! </ br>\n" + retStr); } else { // System.out.println("no have error in : "); retStr = new String("Upload is succesfull !" + "</ br>"); } } else { retStr = new String("Error getFileHash is null !"); } } else { retStr = new String("Error in parameter: endsid"); } } else if ((getSID == null) && (getendSID == null)) { // getSID == null and getendSID == null // System.out.println("getSID : " + getSID + " - getendSID : " + getendSID); retStr = new String("Error in parameter: sid and endsid !"); } else { retStr = new String("Error in parameters !"); } out.print(retStr); // System.out.println("UploadServlet getProcessRequest retString: " + retStr); // System.out.println("UploadServlet getProcessRequest end..."); }
From source file:org.mybatisorm.annotation.handler.JoinHandler.java
private String getExplicitJoin(String joinHint, List<Field> fields) { StringBuilder sb = new StringBuilder(); TableHandler handler;//from ww w. j a v a2 s. c om List<Field> fieldList = new ArrayList<Field>(); Class<?> clazz; Field field; Hashtable<Set<Class<?>>, LinkedList<Field[]>> refMap = null; if (!Pattern.compile(Pattern.quote(" ON "), Pattern.CASE_INSENSITIVE).matcher(joinHint).find()) { refMap = getRefMap(fields); if (refMap.isEmpty()) throw new InvalidAnnotationException("The references for join has not been found"); } QueryTokenizer tokenizer = new QueryTokenizer(joinHint); QueryTokenizer.TokenType type; String text; boolean onRequired = false; // processing the first class type = tokenizer.next(); if (type != QueryTokenizer.TokenType.IDENTIFIER) throw new InvalidJoinException("The join hint must start with the property name."); text = tokenizer.getText(); field = getField(text); fieldList.add(field); clazz = field.getType(); handler = HandlerFactory.getHandler(clazz); sb.append(handler.getName()).append(" ").append(text).append("_"); while ((type = tokenizer.next()) != QueryTokenizer.TokenType.EOS) { text = tokenizer.getText(); switch (type) { case IDENTIFIER: field = getField(text); fieldList.add(field); clazz = field.getType(); handler = HandlerFactory.getHandler(clazz); sb.append(handler.getName()).append(" ").append(text).append("_"); onRequired = true; break; case CLASS_FIELD: String[] s = text.split("\\."); sb.append(s[0]).append("_."); field = getField(getField(s[0]).getType(), s[1]); sb.append(ColumnAnnotation.getName(field)); break; case ON: onRequired = false; sb.append(text); break; case WS: sb.append(text); break; case ETC: if (onRequired) { sb.append(getOnPhrase(fieldList, refMap)); onRequired = false; } sb.append(text); break; } } if (onRequired) { sb.append(getOnPhrase(fieldList, refMap)); } return sb.toString(); }
From source file:net.sf.joost.plugins.traxfilter.THResolver.java
/** * Prepare TH instance for work/*from w w w . j a va 2 s . c o m*/ * * This involves setting TrAX parameters and all other stuff if needed * * @param th * @param params */ protected void prepareTh(TransformerHandler th, Hashtable params) { if (DEBUG) log.debug("prepareTh()"); Transformer tr = th.getTransformer(); // make sure old parameters are cleaned tr.clearParameters(); // set transformation parameters if (!params.isEmpty()) { for (Enumeration e = params.keys(); e.hasMoreElements();) { String key = (String) e.nextElement(); if (DEBUG) log.debug("prepareTh(): set parameter " + key + "=" + params.get(key)); if (!key.startsWith(tmp_TRAX_ATTR_NS) && !key.startsWith(tmp_FILTER_ATTR_NS)) { // ordinary parameter, set it to the TrAX object tr.setParameter(key, params.get(key)); } } } }
From source file:eionet.cr.api.xmlrpc.XmlRpcServices.java
@Override public Vector getEntries(Hashtable criteria) throws CRException { if (logger.isInfoEnabled()) { logger.info("Entered " + Thread.currentThread().getStackTrace()[1].getMethodName()); }/* w w w . j a v a2 s. c o m*/ Vector result = new Vector(); try { SearchResultDTO<SubjectDTO> searchResult = DAOFactory.get().getDao(SearchDAO.class) .searchByFilters(criteria, false, PagingRequest.create(1, MAX_RESULTS), null, null, true); Collection<SubjectDTO> subjects = searchResult.getItems(); if (subjects != null) { for (Iterator<SubjectDTO> iter = subjects.iterator(); iter.hasNext();) { SubjectDTO subjectDTO = iter.next(); Hashtable<String, Vector<String>> predicatesTable = new Hashtable<String, Vector<String>>(); for (Iterator<String> predicatesIter = subjectDTO.getPredicates().keySet() .iterator(); predicatesIter.hasNext();) { String predicate = predicatesIter.next(); predicatesTable.put(predicate, new Vector<String>(getLiteralValues(subjectDTO, predicate))); } if (!predicatesTable.isEmpty()) { Hashtable<String, Hashtable> subjectTable = new Hashtable<String, Hashtable>(); subjectTable.put(subjectDTO.getUri(), predicatesTable); result.add(subjectTable); } } } } catch (Throwable t) { t.printStackTrace(); if (t instanceof CRException) { throw (CRException) t; } else { throw new CRException(t.toString(), t); } } return result; }
From source file:info.magnolia.cms.module.ModuleUtil.java
/** * Register a servlet in the web.xml including init parameters. The code checks if the servlet already exists * @param name//from www . j av a 2s .c om * @param className * @param urlPatterns * @param comment * @param initParams * @throws JDOMException * @throws IOException */ public static boolean registerServlet(String name, String className, String[] urlPatterns, String comment, Hashtable initParams) throws JDOMException, IOException { boolean changed = false; // get the web.xml File source = new File(Path.getAppRootDir() + "/WEB-INF/web.xml"); if (!source.exists()) { throw new FileNotFoundException("Failed to locate web.xml " //$NON-NLS-1$ + source.getAbsolutePath()); } SAXBuilder builder = new SAXBuilder(); Document doc = builder.build(source); // check if there already registered XPath xpath = XPath.newInstance("/webxml:web-app/webxml:servlet[webxml:servlet-name='" + name + "']"); // must add the namespace and use it: there is no default namespace elsewise xpath.addNamespace("webxml", doc.getRootElement().getNamespace().getURI()); Element node = (Element) xpath.selectSingleNode(doc); if (node == null) { log.info("register servlet " + name); // make a nice comment doc.getRootElement().addContent(new Comment(comment)); // the same name space must be used Namespace ns = doc.getRootElement().getNamespace(); node = new Element("servlet", ns); node.addContent(new Element("servlet-name", ns).addContent(name)); node.addContent(new Element("servlet-class", ns).addContent(className)); if (initParams != null && !(initParams.isEmpty())) { Enumeration params = initParams.keys(); while (params.hasMoreElements()) { String paramName = params.nextElement().toString(); String paramValue = (String) initParams.get(paramName); Element initParam = new Element("init-param", ns); initParam.addContent(new Element("param-name", ns).addContent(paramName)); initParam.addContent(new Element("param-value", ns).addContent(paramValue)); node.addContent(initParam); } } doc.getRootElement().addContent(node); changed = true; } else { log.info("servlet {} already registered", name); } for (int i = 0; i < urlPatterns.length; i++) { String urlPattern = urlPatterns[i]; changed = changed | registerServletMapping(doc, name, urlPattern, comment); } if (changed) { XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat()); outputter.output(doc, new FileWriter(source)); } return changed; }
From source file:com.hs.mail.mailet.RemoteDelivery.java
/** * For this message, we take the list of recipients, organize these into * distinct servers, and deliver the message for each of these servers. *//*w w w. j av a 2s . c o m*/ public void service(Set<Recipient> recipients, SmtpMessage message) throws MessagingException { // Organize the recipients into distinct servers (name made case insensitive) Hashtable<String, Collection<Recipient>> targets = new Hashtable<String, Collection<Recipient>>(); for (Recipient recipient : recipients) { String targetServer = recipient.getHost().toLowerCase(Locale.US); if (!Config.isLocal(targetServer)) { String key = (null == gateway) ? targetServer : gateway; Collection<Recipient> temp = targets.get(key); if (temp == null) { temp = new ArrayList<Recipient>(); targets.put(key, temp); } temp.add(recipient); } } if (targets.isEmpty()) { return; } // We have the recipients organized into distinct servers List<Recipient> undelivered = new ArrayList<Recipient>(); MimeMessage mimemsg = message.getMimeMessage(); boolean deleteMessage = true; for (String targetServer : targets.keySet()) { Collection<Recipient> temp = targets.get(targetServer); if (!deliver(targetServer, temp, message, mimemsg)) { // Retry this message later deleteMessage = false; if (!temp.isEmpty()) { undelivered.addAll(temp); } } } if (!deleteMessage) { try { message.setRetryCount(message.getRetryCount() + 1); message.setLastUpdate(new Date()); recipients.clear(); recipients.addAll(undelivered); message.store(); } catch (IOException e) { } } }
From source file:org.wandora.application.gui.OccurrenceTableSingleType.java
@Override public void duplicateType() { try {//from w ww .ja v a 2 s.c o m Point p = getTableModelPoint(); if (p != null) { Topic selectedScope = langs[p.y]; if (type != null && !type.isRemoved()) { Topic newType = wandora.showTopicFinder("Select new occurrence type"); if (newType != null && !newType.isRemoved()) { Hashtable<Topic, String> os = topic.getData(type); if (os != null && !os.isEmpty()) { for (Topic scope : os.keySet()) { if (scope != null && !scope.isRemoved()) { if (selectedScope == null) { String occurrenceText = os.get(scope); topic.setData(newType, scope, occurrenceText); } else if (selectedScope.mergesWithTopic(scope)) { String occurrenceText = os.get(scope); topic.setData(newType, scope, occurrenceText); } } } } } } } } catch (Exception e) { if (wandora != null) wandora.handleError(e); } }