KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > exceptions > web > Subcomponents


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 package org.netbeans.modules.exceptions.web;
20
21 import java.io.*;
22 import java.net.*;
23 import java.util.Iterator JavaDoc;
24 import java.util.List JavaDoc;
25 import java.util.Vector JavaDoc;
26 import javax.persistence.EntityManagerFactory;
27 import javax.persistence.Persistence;
28 import javax.persistence.Query;
29 import javax.servlet.*;
30 import javax.servlet.http.*;
31
32 /**
33  *
34  * @author Jan Horvath
35  * @version
36  */

37 public class Subcomponents extends HttpServlet {
38     
39     /** Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
40      * @param request servlet request
41      * @param response servlet response
42      */

43         EntityManagerFactory emf = Persistence.createEntityManagerFactory("StrutsExceptionsPU");
44
45     /** Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
46      * @param request servlet request
47      * @param response servlet response
48      */

49     protected void processRequest(HttpServletRequest request, HttpServletResponse response)
50             throws ServletException, IOException {
51         response.setContentType("text/plain;charset=UTF-8");
52         PrintWriter out = response.getWriter();
53         String JavaDoc component = request.getParameter("component");
54         List JavaDoc sc = getSubcomponents(component);
55         if (sc != null) {
56             for(Iterator JavaDoc<Vector JavaDoc> it = sc.iterator(); it.hasNext(); ) {
57                 Vector JavaDoc v = it.next();
58                 out.print(v.elementAt(0));
59                 if (it.hasNext()) out.print(",");
60             }
61         }
62         out.close();
63     }
64     
65     // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
66
/** Handles the HTTP <code>GET</code> method.
67      * @param request servlet request
68      * @param response servlet response
69      */

70     protected void doGet(HttpServletRequest request, HttpServletResponse response)
71             throws ServletException, IOException {
72         processRequest(request, response);
73     }
74     
75     /** Handles the HTTP <code>POST</code> method.
76      * @param request servlet request
77      * @param response servlet response
78      */

79     protected void doPost(HttpServletRequest request, HttpServletResponse response)
80             throws ServletException, IOException {
81         processRequest(request, response);
82         
83         
84     }
85     
86     /** Returns a short description of the servlet.
87      */

88     public String JavaDoc getServletInfo() {
89         return "Short description";
90     }
91     
92     public List JavaDoc getSubcomponents(String JavaDoc component) {
93         javax.persistence.EntityManager em = emf.createEntityManager();
94         try {
95 // em.getTransaction().begin();
96
// em.persist(object);
97
// em.getTransaction().commit();
98
Query q = em.createNativeQuery("SELECT DISTINCT i.subcomponent FROM Issue i WHERE i.component=#component");
99             q.setParameter("component", component);
100             return q.getResultList();
101         }
102         catch (Exception JavaDoc e) {
103             java.util.logging.Logger.getLogger(getClass().getName()).log(java.util.logging.Level.SEVERE,
104                                                                          "exception caught",
105                                                                          e);
106 // em.getTransaction().rollback();
107
}
108         finally {
109             em.close();
110         }
111         return null;
112     }
113 // </editor-fold>
114
}
115
Popular Tags