View Javadoc
1 /* 2 * $Header: /cvsroot/ebxmlrr/ebxmlrr/src/share/com/sun/ebxml/registry/query/QueryManagerImpl.java,v 1.17 2003/06/20 14:30:31 farrukh_najmi Exp $ 3 * 4 * ==================================================================== 5 * 6 * This code is subject to the freebxml License, Version 1.1 7 * 8 * Copyright (c) 2003 freebxml.org. All rights reserved. 9 * 10 * ==================================================================== 11 */ 12 package com.sun.ebxml.registry.query; 13 14 import com.sun.ebxml.registry.RegistryException; 15 import java.util.ArrayList; 16 import org.oasis.ebxml.registry.bindings.rs.RegistryResponse; 17 18 /*** 19 * Implements the QueryManager interface for ebXML Registry as defined by ebRS spec. 20 * 21 * @author <a href="mailto:Farrukh.Najmi@Sun.COM">Farrukh S. Najmi</a> 22 */ 23 public class QueryManagerImpl implements com.sun.ebxml.registry.QueryManager { //implements QueryManager { 24 protected QueryManagerImpl() {} 25 26 27 public static QueryManagerImpl getInstance() { 28 if (instance == null) { 29 synchronized(QueryManagerImpl.class) { 30 if (instance == null) { 31 instance = new QueryManagerImpl(); 32 } 33 } 34 } 35 return instance; 36 } 37 38 /*** 39 * submitAdhocQuery 40 */ 41 public RegistryResponse submitAdhocQuery(org.oasis.ebxml.registry.bindings.rim.User user, org.oasis.ebxml.registry.bindings.query.AdhocQueryRequest req) throws RegistryException { 42 RegistryResponse resp = null; 43 44 try { 45 org.oasis.ebxml.registry.bindings.query.AdhocQueryRequestChoice ch = req.getAdhocQueryRequestChoice(); 46 org.oasis.ebxml.registry.bindings.query.ResponseOption responseOption = req.getResponseOption(); 47 48 String sqlQuery = ch.getSQLQuery(); 49 org.oasis.ebxml.registry.bindings.query.FilterQuery fq = ch.getFilterQuery(); 50 51 org.oasis.ebxml.registry.bindings.query.AdhocQueryResponse ahqr = null; 52 if (sqlQuery != null) { 53 ahqr = sqlQueryProcessor.executeQuery(user, sqlQuery, responseOption); 54 } 55 else if (fq != null) { 56 ahqr = filterQueryProcessor.executeQuery(user, fq, responseOption); 57 } 58 else { 59 throw new RegistryException("Invalid request: no query specified"); 60 } 61 62 org.oasis.ebxml.registry.bindings.rs.RegistryResponseChoice rrch = new org.oasis.ebxml.registry.bindings.rs.RegistryResponseChoice(); 63 rrch.setAdhocQueryResponse(ahqr); 64 65 resp = new RegistryResponse(); 66 resp.setRegistryResponseChoice(rrch); 67 68 resp.setStatus(org.oasis.ebxml.registry.bindings.rs.types.StatusType.SUCCESS); 69 } catch (RegistryException e) { 70 e.printStackTrace(); 71 resp = com.sun.ebxml.registry.util.Utility.getInstance().createRegistryResponseFromThrowable(e, "QueryManagerImpl", "Unknown"); 72 } 73 74 return resp; 75 } 76 77 /*** 78 * getContent 79 */ 80 public RegistryResponse getContent(org.oasis.ebxml.registry.bindings.query.GetContentRequest req) throws RegistryException { 81 RegistryResponse resp = new RegistryResponse(); 82 org.oasis.ebxml.registry.bindings.rs.RegistryResponseChoice rrch = new org.oasis.ebxml.registry.bindings.rs.RegistryResponseChoice(); 83 rrch.setGetContentResponse(new org.oasis.ebxml.registry.bindings.query.GetContentResponse()); 84 resp.setRegistryResponseChoice(rrch); 85 86 org.oasis.ebxml.registry.bindings.rim.ObjectRefListItem[] items = req.getObjectRefList().getObjectRefListItem(); 87 ArrayList ids = new ArrayList(); 88 for (int i=0 ; i<items.length ; i++) { 89 String id = items[i].getObjectRef().getId(); 90 ids.add(id); 91 } 92 93 com.sun.ebxml.registry.repository.RepositoryManager repositoryMgr = 94 com.sun.ebxml.registry.repository.RepositoryManagerFactory.getInstance().getRepositoryManager(); 95 ids = repositoryMgr.itemsExist(ids); 96 97 if (ids.size() > 0) { 98 org.oasis.ebxml.registry.bindings.rs.RegistryErrorList el = new org.oasis.ebxml.registry.bindings.rs.RegistryErrorList(); 99 for (int i=0 ; i<ids.size() ; i++) { 100 org.oasis.ebxml.registry.bindings.rs.RegistryError re = new org.oasis.ebxml.registry.bindings.rs.RegistryError(); 101 re.setContent("Repository item id=\"" + (String) ids.get(i) + "\" does not exist!"); 102 re.setErrorCode("unknown"); 103 re.setCodeContext("QueryManagerImpl.getContent"); 104 el.addRegistryError(re); 105 } 106 resp.setRegistryErrorList(el); 107 resp.setStatus(org.oasis.ebxml.registry.bindings.rs.types.StatusType.FAILURE); 108 } 109 else { 110 resp.setStatus(org.oasis.ebxml.registry.bindings.rs.types.StatusType.SUCCESS); 111 } 112 113 return resp; 114 } 115 116 /*** 117 * This method used by RegistryAttributeFinderModule 118 * 119 */ 120 public static org.oasis.ebxml.registry.bindings.rim.ClassificationNodeType getClassificationNode(String pathPattern) throws RegistryException { 121 org.oasis.ebxml.registry.bindings.rim.ClassificationNodeType ro=null; 122 String sqlQuery = "Select * from ClassificationNode WHERE path LIKE '"+ pathPattern + "' "; 123 org.oasis.ebxml.registry.bindings.query.ResponseOption responseOption = new org.oasis.ebxml.registry.bindings.query.ResponseOption(); 124 responseOption.setReturnComposedObjects(true); 125 responseOption.setReturnType(org.oasis.ebxml.registry.bindings.query.types.ReturnTypeType.LEAFCLASS); 126 String tableName = com.sun.ebxml.registry.persistence.rdb.ClassificationNodeDAO.getTableNameStatic(); 127 ArrayList objectRefs = new ArrayList(); 128 ArrayList results= com.sun.ebxml.registry.persistence.rdb.SQLPersistenceManagerImpl.getInstance().executeSQLQuery(sqlQuery, responseOption, tableName, objectRefs); 129 if (results.size() == 1) { 130 ro = (org.oasis.ebxml.registry.bindings.rim.ClassificationNodeType)results.get(0); 131 } 132 133 return ro; 134 } 135 136 /*** 137 * This method is added for the REST 138 * 139 */ 140 public org.oasis.ebxml.registry.bindings.rim.RegistryObjectType getRegistryObject(String id) throws RegistryException { 141 org.oasis.ebxml.registry.bindings.rim.RegistryObjectType ro=null; 142 String sqlQuery = "Select * from RegistryObject WHERE id = '"+ id + "' "; 143 org.oasis.ebxml.registry.bindings.query.ResponseOption responseOption = new org.oasis.ebxml.registry.bindings.query.ResponseOption(); 144 responseOption.setReturnComposedObjects(true); 145 responseOption.setReturnType(org.oasis.ebxml.registry.bindings.query.types.ReturnTypeType.LEAFCLASS); 146 String tableName = (new com.sun.ebxml.registry.persistence.rdb.RegistryObjectDAO()).getTableName(); 147 ArrayList objectRefs = new ArrayList(); 148 ArrayList results= com.sun.ebxml.registry.persistence.rdb.SQLPersistenceManagerImpl.getInstance().executeSQLQuery(sqlQuery, responseOption, tableName, objectRefs); 149 if (results.size() == 1) { 150 ro = (org.oasis.ebxml.registry.bindings.rim.RegistryObjectType)results.get(0); 151 } 152 153 return ro; 154 } 155 156 /*** 157 * This method is added for the REST 158 * It returns the RepositroyItem give a UUID 159 */ 160 public com.sun.ebxml.registry.repository.RepositoryItem getRepositoryItem(String id) throws RegistryException{ 161 162 com.sun.ebxml.registry.repository.RepositoryItem ri=null; 163 com.sun.ebxml.registry.repository.RepositoryManager rm = com.sun.ebxml.registry.repository.RepositoryManagerFactory.getInstance().getRepositoryManager(); 164 165 String path = rm.getRepositoryItemPath(id); 166 java.io.File itemFile = new java.io.File(path); 167 if(itemFile.exists()){ 168 javax.activation.FileDataSource fs =new javax.activation.FileDataSource(itemFile); 169 javax.activation.DataHandler dh=new javax.activation.DataHandler(fs); 170 String nullTemp = null; 171 ri = new com.sun.ebxml.registry.repository.RepositoryItem(id,nullTemp,dh); 172 }else{ 173 System.out.println("File NOT Exists!"); 174 } 175 return ri; 176 } 177 178 179 public static void main(String[] args) throws Exception { 180 try { 181 String command = args[0]; 182 java.io.File file = new java.io.File(args[1]); 183 184 QueryManagerImpl qm = QueryManagerImpl.getInstance(); 185 186 if (command.equalsIgnoreCase("-submitAdhocQuery")) { 187 java.io.FileReader fr = new java.io.FileReader(file); 188 189 org.oasis.ebxml.registry.bindings.query.AdhocQueryRequest req = org.oasis.ebxml.registry.bindings.query.AdhocQueryRequest.unmarshal(fr); 190 191 long t1 = System.currentTimeMillis(); 192 RegistryResponse rr = qm.submitAdhocQuery(null, req); 193 long t2 = System.currentTimeMillis(); 194 195 System.err.println("Elapsed time in seconds: " + (t2-t1)/1000); 196 197 java.io.FileWriter fw = new java.io.FileWriter("c:/tmp/qmResponse.xml"); 198 rr.marshal(fw); 199 } 200 } catch (Exception e) { 201 e.printStackTrace(); 202 } 203 } 204 205 206 207 208 /*** 209 * @link 210 * @shapeType PatternLink 211 * @pattern Singleton 212 * @supplierRole Singleton factory 213 */ 214 /*# private QueryManagerImpl _registryServiceImpl; */ 215 private static QueryManagerImpl instance = null; 216 217 /*** 218 * @directed 219 */ 220 private com.sun.ebxml.registry.query.filter.FilterQueryProcessor filterQueryProcessor = com.sun.ebxml.registry.query.filter.FilterQueryProcessor.getInstance();; 221 222 /*** 223 * @directed 224 */ 225 private com.sun.ebxml.registry.query.sql.SQLQueryProcessor sqlQueryProcessor = com.sun.ebxml.registry.query.sql.SQLQueryProcessor.getInstance(); 226 227 228 }

This page was automatically generated by Maven