View Javadoc
1 /* 2 * ==================================================================== 3 * 4 * This code is subject to the freebxml License, Version 1.1 5 * 6 * Copyright (c) 2001 - 2003 freebxml.org. All rights reserved. 7 * 8 * ==================================================================== 9 10 * $Header: /cvsroot/ebxmlrr/ebxmlrr/src/share/com/sun/ebxml/registry/lcm/ContentIndexingManager.java,v 1.17 2003/05/19 22:21:42 farrukh_najmi Exp $ 11 * 12 */ 13 14 package com.sun.ebxml.registry.lcm; 15 16 import com.sun.ebxml.registry.RegistryException; 17 import java.io.StringWriter; 18 import javax.xml.transform.stream.StreamSource; 19 import org.oasis.ebxml.registry.bindings.rim.AssociationType1; 20 import org.oasis.ebxml.registry.bindings.rim.ExtrinsicObjectType; 21 import org.oasis.ebxml.registry.bindings.rim.LeafRegistryObjectList; 22 import org.oasis.ebxml.registry.bindings.rim.ServiceType; 23 24 /*** 25 * 26 * Manages cataloging of RepositoryItems when they are submitted to the registry. 27 * Maintains an association between an objectType and its corresponding 28 * Content Cataloging Service and Invocation Control File. 29 * <p> 30 * Content Cataloging is specified by the "Content Management Services" chapter 31 * of ebRS V2.4 or later. 32 * 33 * @author Farrukh S. Najmi 34 * 35 */ 36 37 public class ContentIndexingManager { 38 39 static com.sun.ebxml.registry.util.Utility util = com.sun.ebxml.registry.util.Utility.getInstance(); 40 static com.sun.ebxml.registry.util.BindingUtility bu = com.sun.ebxml.registry.util.BindingUtility.getInstance(); 41 static com.sun.ebxml.registry.repository.RepositoryManager rm = com.sun.ebxml.registry.repository.RepositoryManagerFactory.getInstance().getRepositoryManager(); 42 43 public static final String DEFAULT_XML_CATALOGING_SERVICE_ID="urn:uuid:4bcfc370-7a71-4c50-a6ed-ade41d836613"; 44 45 java.util.HashMap objectTypeToServiceMap = new java.util.HashMap(); 46 java.util.HashMap objectTypeToInvocationControlFileMap = new java.util.HashMap(); 47 48 private org.apache.commons.logging.Log log = org.apache.commons.logging.LogFactory.getLog(this.getClass()); 49 50 /*** 51 * 52 * @link 53 * 54 * @shapeType PatternLink 55 * 56 * @pattern Singleton 57 * 58 * @supplierRole Singleton factory 59 * 60 */ 61 62 /*# private ContentIndexingManager _objectManagerImpl; */ 63 64 private static ContentIndexingManager instance = null; 65 66 /*** 67 * 68 * @associates <{com.sun.ebxml.registry.persistence.PersistenceManagerImpl}> 69 * 70 */ 71 com.sun.ebxml.registry.persistence.PersistenceManagerImpl pm = com.sun.ebxml.registry.persistence.PersistenceManagerImpl.getInstance(); 72 73 protected ContentIndexingManager() { 74 } 75 76 public static ContentIndexingManager getInstance(){ 77 if (instance == null) { 78 synchronized(ContentIndexingManager.class) { 79 if (instance == null) { 80 instance = new ContentIndexingManager(); 81 } 82 } 83 } 84 85 return instance; 86 } 87 88 /*** 89 * 90 * Catalogs the content as described by ebXMl Registry V3 Content Cataloging feature. 91 * 92 * Implemented in V2 as a special feature because it does not require interface changes in V2. 93 * 94 * 95 * 96 * This method may convert RepositoryItem content to metadata which will be committed as the same User 97 * 98 * as original submit synchronously following the original submit but in a different database transaction. 99 * 100 * Any error will not be returned to the client and will simply be logged by the registry in a registry specific manner. 101 * 102 */ 103 104 public LeafRegistryObjectList catalogContent(ExtrinsicObjectType eo, com.sun.ebxml.registry.repository.RepositoryItem originalContent) throws RegistryException { 105 106 LeafRegistryObjectList catalogedMetadata = null; 107 108 log.debug("catalogContent entered for eo.id " + eo.getId() + " eo.type " + eo.getObjectType()); 109 110 String objectType = eo.getObjectType(); 111 ServiceType catalogingService = getCatalogingService(objectType); 112 113 114 if (catalogingService != null) { 115 //Only default XML Cataloging Service supported for now 116 if (!(catalogingService.getId().equals(DEFAULT_XML_CATALOGING_SERVICE_ID))) { 117 catalogingService = null; 118 } 119 } 120 121 if (catalogingService == null) { 122 log.debug("Cataloging service not found for objectType=" + objectType); 123 return catalogedMetadata; 124 } 125 else { 126 log.debug("Cataloging service = " + catalogingService.getId()); 127 } 128 129 ExtrinsicObjectType invocationControlFile = getInvocationControlFile(objectType); 130 131 if (invocationControlFile != null) { 132 log.debug("InvocationControlFile = " + invocationControlFile.getId()); 133 } 134 else { 135 log.debug("InvocationControlFile not found for objectType=" + objectType); 136 } 137 138 if (originalContent != null) { 139 log.debug("originalContent = " + originalContent.getId()); 140 } 141 else { 142 log.debug("originalContent not found"); 143 } 144 145 if ((invocationControlFile != null) && (catalogingService != null) && (originalContent != null)) { 146 catalogedMetadata = catalogContent(eo, originalContent, invocationControlFile, catalogingService); 147 } 148 149 return catalogedMetadata; 150 } 151 152 private LeafRegistryObjectList catalogContent(ExtrinsicObjectType eo, com.sun.ebxml.registry.repository.RepositoryItem originalContent, ExtrinsicObjectType invocationControlFile, ServiceType catalogingService) throws RegistryException { 153 log.debug("catalogContent 2 entered"); 154 155 LeafRegistryObjectList catalogedMetadata = null; 156 java.io.File outputFile = null; 157 158 try { 159 StreamSource inputSrc = getAsStreamSource(eo); 160 //??Make this be stream based since file system impl of RM is not always the case 161 162 java.io.File xslFile = new java.io.File(rm.getRepositoryItemPath(invocationControlFile.getId())); 163 StreamSource invocationControlFileSrc = new StreamSource(xslFile); 164 javax.xml.transform.TransformerFactory tFactory = javax.xml.transform.TransformerFactory.newInstance(); 165 javax.xml.transform.Transformer transformer = tFactory.newTransformer(invocationControlFileSrc); 166 167 //Set respository item as second parameter 168 transformer.setParameter("repositoryItem", rm.getRepositoryItemPath(originalContent.getId() )); 169 170 //Create the output file with catalogedMetadata 171 outputFile = java.io.File.createTempFile("ContentCatalogingManager_OutputFile", ".xml"); 172 173 log.debug("Tempfile= " + outputFile.getAbsolutePath()); 174 javax.xml.transform.stream.StreamResult sr = new javax.xml.transform.stream.StreamResult(outputFile); 175 transformer.transform(inputSrc, sr); 176 177 java.io.FileReader fr = new java.io.FileReader(outputFile); 178 catalogedMetadata = LeafRegistryObjectList.unmarshal(fr); 179 } 180 181 // these Exceptions should already be caught by Binding 182 catch (RegistryException e) { 183 throw new RegistryException(e); 184 } 185 catch (javax.xml.transform.TransformerConfigurationException e) { 186 throw new RegistryException(e); 187 } 188 catch (javax.xml.transform.TransformerException e) { 189 throw new RegistryException(e); 190 } 191 catch (org.exolab.castor.xml.MarshalException e) { 192 throw new RegistryException(e); 193 } 194 catch (org.exolab.castor.xml.ValidationException e) { 195 throw new RegistryException(e); 196 } 197 catch (java.io.IOException e) { 198 throw new RegistryException(e); 199 } 200 201 return catalogedMetadata; 202 } 203 204 private StreamSource getAsStreamSource(ExtrinsicObjectType eo) throws RegistryException { 205 log.debug("getAsStreamSource(ExtrinsicObjectType ) enetered"); 206 207 StreamSource src = null; 208 209 try { 210 //Add MetaData (ExtrinsicObject) first 211 StringWriter sw = new StringWriter(); 212 org.exolab.castor.xml.Marshaller marshaller = new org.exolab.castor.xml.Marshaller(sw); 213 marshaller.setMarshalAsDocument(true); 214 marshaller.marshal(eo, sw); 215 216 java.io.StringReader reader = new java.io.StringReader(sw.toString()); 217 src = new StreamSource(reader); 218 } 219 220 // these Exceptions should already be caught by Binding 221 catch (org.exolab.castor.xml.MarshalException e) { 222 throw new RegistryException(e); 223 } 224 catch (org.exolab.castor.xml.ValidationException e) { 225 throw new RegistryException(e); 226 } 227 catch (java.io.IOException e) { 228 throw new RegistryException(e); 229 } 230 231 return src; 232 233 } 234 235 236 237 /*** 238 * 239 * Gets the Cataloging Service for the specified objectType. 240 * 241 * Returns the cataloging service that is the sourceObject of an Association that has associationType = "ContentManagementServiceFor" 242 * 243 * and the targetObject is the ClassificationNode pointed to by objectType or an ancestor of the ClassificationNode pointed to by objectType. 244 * 245 */ 246 private ServiceType getCatalogingService(String objectType) throws RegistryException { 247 ServiceType catalogingService = null; 248 249 catalogingService = (ServiceType) objectTypeToServiceMap.get(objectType); 250 251 if ((catalogingService == null) && (!(objectTypeToServiceMap.containsKey(objectType)))) { 252 //Lookup failed in map so look dynamically 253 254 AssociationType1 ass = getAssociation(objectType, "ContentManagementServiceFor"); 255 256 if (ass != null) { 257 Object src = ass.getSourceObject(); 258 catalogingService = (ServiceType)pm.getRegistryObject(bu.getObjectId(src), "Service"); 259 } 260 261 //Update the map to avoid dynamic resolution in future for this objectType 262 objectTypeToServiceMap.put(objectType, (Object)catalogingService); 263 } 264 265 return catalogingService; 266 } 267 268 /*** 269 * 270 * Gets the Invocation Control file for a specified objectType. 271 * 272 */ 273 private ExtrinsicObjectType getInvocationControlFile(String objectType) throws RegistryException { 274 ExtrinsicObjectType invocationControlFile = null; 275 276 invocationControlFile = (ExtrinsicObjectType) objectTypeToInvocationControlFileMap.get(objectType); 277 278 if ((invocationControlFile == null) && (!(objectTypeToInvocationControlFileMap.containsKey(objectType)))) { 279 //Lookup failed in map so look dynamically 280 AssociationType1 ass = getAssociation(objectType, "urn:uuid:261ab741-57f4-4fd5-86ee-a15311ec3213"); //InvocationControlFileFor 281 282 if (ass != null) { 283 Object src = ass.getSourceObject(); 284 invocationControlFile = (ExtrinsicObjectType)pm.getRegistryObject(bu.getObjectId(src), "ExtrinsicObject"); 285 } 286 287 //Update the map to avoid dynamic resolution in future for this objectType 288 objectTypeToInvocationControlFileMap.put(objectType, (Object)invocationControlFile); 289 } 290 return invocationControlFile; 291 } 292 293 294 295 /*** 296 * 297 * Gets the Association that has the specified assocType and has as targetObject 298 * 299 * the ClassificationNode pointed to by objectType or an ancestor of the ClassificationNode pointed to by objectType. 300 * 301 */ 302 private AssociationType1 getAssociation(String objectType, String assocType) throws RegistryException { 303 AssociationType1 ass=null; 304 org.oasis.ebxml.registry.bindings.rim.RegistryObjectType ro = pm.getRegistryObject(objectType, "ClassificationNode"); 305 org.oasis.ebxml.registry.bindings.query.ResponseOption responseOption = new org.oasis.ebxml.registry.bindings.query.ResponseOption(); 306 responseOption.setReturnType(org.oasis.ebxml.registry.bindings.query.types.ReturnTypeType.LEAFCLASS); 307 responseOption.setReturnComposedObjects(false); 308 309 java.util.ArrayList objectRefs = new java.util.ArrayList(); 310 311 if ((ro != null) && (ro instanceof org.oasis.ebxml.registry.bindings.rim.ClassificationNodeType)) { 312 org.oasis.ebxml.registry.bindings.rim.ClassificationNodeType node = (org.oasis.ebxml.registry.bindings.rim.ClassificationNodeType)ro; 313 314 String query = "SELECT * from " + pm.mapTableName("Association") + " ass " + 315 316 // " WHERE ass.associationType = '" + assocType + "' AND ass.targetObject = '" + node.getId() + "'"; 317 318 " WHERE ass.targetObject = '" + node.getId() + "' AND ass.associationType = '" + assocType + "' "; 319 320 objectRefs.clear(); 321 java.util.ArrayList al = pm.executeSQLQuery( query, responseOption, "Association", objectRefs); 322 323 if (al.size() >= 1) { 324 ass = (AssociationType1)al.get(0); 325 } 326 else { 327 //Check if an Association exists for the parent node 328 Object parent = node.getParent(); 329 330 if ((parent != null) ) { 331 String parentId = bu.getObjectId(parent); 332 ass = getAssociation(parentId, assocType); 333 } 334 } 335 } 336 return ass; 337 } 338 339 public static void main(String[] args) throws Exception { 340 341 try { 342 if (args.length == 0) { 343 System.out.println("Usage: ContentIndexManager <objectType>"); 344 System.exit(-1); 345 } 346 347 String objectType = args[0]; 348 ContentIndexingManager cim = ContentIndexingManager.getInstance(); 349 ServiceType service = cim.getCatalogingService(objectType); 350 351 StringWriter sw = null; 352 if (service != null) { 353 sw = new StringWriter(); 354 service.marshal(sw); 355 356 System.err.println(sw); 357 } 358 359 ExtrinsicObjectType eo = cim.getInvocationControlFile(objectType); 360 361 if (eo != null) { 362 sw = new StringWriter(); 363 eo.marshal(sw); 364 365 System.err.println(sw); 366 } 367 } catch (Exception e) { 368 e.printStackTrace(); 369 } 370 } 371 372 } 373

This page was automatically generated by Maven