Coverage report

  %line %branch
org.apache.jetspeed.capabilities.impl.JetspeedCapabilities
0% 
0% 

 1  
 /*
 2  
  * Licensed to the Apache Software Foundation (ASF) under one or more
 3  
  * contributor license agreements.  See the NOTICE file distributed with
 4  
  * this work for additional information regarding copyright ownership.
 5  
  * The ASF licenses this file to You under the Apache License, Version 2.0
 6  
  * (the "License"); you may not use this file except in compliance with
 7  
  * the License.  You may obtain a copy of the License at
 8  
  * 
 9  
  *      http://www.apache.org/licenses/LICENSE-2.0
 10  
  * 
 11  
  * Unless required by applicable law or agreed to in writing, software
 12  
  * distributed under the License is distributed on an "AS IS" BASIS,
 13  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14  
  * See the License for the specific language governing permissions and
 15  
  * limitations under the License.
 16  
  */
 17  
 package org.apache.jetspeed.capabilities.impl;
 18  
 
 19  
 import java.util.Collection;
 20  
 import java.util.Hashtable;
 21  
 import java.util.Iterator;
 22  
 import java.util.Properties;
 23  
 import java.util.Vector;
 24  
 
 25  
 import org.apache.commons.logging.Log;
 26  
 import org.apache.commons.logging.LogFactory;
 27  
 import org.apache.jetspeed.capabilities.Capabilities;
 28  
 import org.apache.jetspeed.capabilities.CapabilitiesException;
 29  
 import org.apache.jetspeed.capabilities.Capability;
 30  
 import org.apache.jetspeed.capabilities.CapabilityMap;
 31  
 import org.apache.jetspeed.capabilities.Client;
 32  
 import org.apache.jetspeed.capabilities.MediaType;
 33  
 import org.apache.jetspeed.capabilities.MimeType;
 34  
 import org.apache.jetspeed.capabilities.UnableToBuildCapabilityMapException;
 35  
 import org.apache.jetspeed.components.dao.InitablePersistenceBrokerDaoSupport;
 36  
 import org.apache.ojb.broker.query.Criteria;
 37  
 import org.apache.ojb.broker.query.QueryByCriteria;
 38  
 import org.apache.ojb.broker.query.QueryFactory;
 39  
 import org.springframework.beans.BeansException;
 40  
 import org.springframework.beans.factory.BeanFactory;
 41  
 import org.springframework.beans.factory.BeanFactoryAware;
 42  
 
 43  
 /**
 44  
  * Jetspeed Capabilities
 45  
  *
 46  
  * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
 47  
  * @author <a href="mailto:roger.ruttimann@earthlink.net">Roger Ruttimann</a>
 48  
  * @version $Id: JetspeedCapabilities.java 517124 2007-03-12 08:10:25Z ate $
 49  
  */
 50  
 public class JetspeedCapabilities extends InitablePersistenceBrokerDaoSupport implements Capabilities ,BeanFactoryAware 
 51  
 {
 52  0
     private static final Log log =
 53  0
         LogFactory.getLog(JetspeedCapabilities.class);
 54  
 
 55  
     public static final String DEFAULT_AGENT = "Mozilla/4.0";
 56  
 
 57  
     public static final String AGENT_XML = "agentxml/1.0";
 58  
 
 59  
     // Cache for the capability maps
 60  0
     Hashtable capabilityMapCache = new Hashtable();
 61  
 
 62  0
     private Collection clients = null;
 63  
 
 64  
     /**
 65  
      * added support for bean factory to create profile rules
 66  
      */
 67  
     private BeanFactory beanFactory;
 68  
 
 69  
     /** named bean references */
 70  
     private String clientBeanName; 
 71  
     private String capabilityBeanName; 
 72  
     private String mimeTypeBeanName; 
 73  
     private String mediaTypeBeanName; 
 74  
 
 75  
 	   private Class clientClass;
 76  
 	    private Class capabilityClass;
 77  
 	    private Class mimeTypeClass;
 78  
 	    private Class mediaTypeClass;
 79  
     
 80  
     
 81  
     public JetspeedCapabilities(String repositoryPath, String clientBeanName, String mediaTypeBeanName, String mimeTypeBeanName, String capabilityBeanName)
 82  
     {
 83  0
         super(repositoryPath);
 84  0
         this.clientBeanName =  clientBeanName;
 85  0
         this.capabilityBeanName =  capabilityBeanName;
 86  0
         this.mimeTypeBeanName =  mimeTypeBeanName;
 87  0
         this.mediaTypeBeanName =  mediaTypeBeanName;
 88  0
    }
 89  
     
 90  
     /**
 91  
      * Create a JetspeedProfiler with properties. Expected properties are:
 92  
      * 
 93  
      * 	   defaultRule   = the default profiling rule
 94  
      *     anonymousUser = the name of the anonymous user
 95  
      *     persistenceStoreName = The name of the persistence persistenceStore component to connect to  
 96  
      *     services.profiler.locator.impl = the pluggable Profile Locator impl
 97  
      *     services.profiler.principalRule.impl = the pluggable Principal Rule impl
 98  
      *     services.profiler.profilingRule.impl = the pluggable Profiling Rule impl
 99  
      *      
 100  
      * @param persistenceStore  The persistence persistenceStore 
 101  
      * @param properties  Properties for this component described above
 102  
      * @deprecated As of release 2.1, property-based class references replaced
 103  
      *             by container managed bean factory
 104  
      */
 105  
     public JetspeedCapabilities(String repositoryPath, Properties properties)
 106  
 	{
 107  0
         super(repositoryPath);
 108  0
     }
 109  
     /*
 110  
      * Method called automatically by Spring container upon initialization
 111  
      * 
 112  
      * @param beanFactory automatically provided by framework @throws
 113  
      * BeansException
 114  
      */
 115  
     public void setBeanFactory(BeanFactory beanFactory) throws BeansException
 116  
     {
 117  0
         this.beanFactory = beanFactory;
 118  0
     }
 119  
 
 120  
 
 121  
 	    private Class getClientClass() throws ClassNotFoundException
 122  
 	    {
 123  0
 	    	if (clientClass == null)
 124  
 	    	{
 125  0
 	    		clientClass = createClient(null).getClass();
 126  
 	    	}
 127  0
 	    	return clientClass;
 128  
 	    }
 129  
 	 
 130  
 	    private Class getMimeTypeClass() throws ClassNotFoundException
 131  
 	    {
 132  0
 	    	if (mimeTypeClass == null)
 133  
 	    	{
 134  0
 	    		mimeTypeClass = this.createMimeType(null).getClass();
 135  
 	    	}
 136  0
 	    	return mimeTypeClass;
 137  
 	    }
 138  
 	    private Class getCapabilityClass()throws ClassNotFoundException
 139  
 	    {
 140  0
 	    	if (capabilityClass == null)
 141  
 	    	{
 142  0
 	    		capabilityClass = this.createCapability(null).getClass();
 143  
 	    	}
 144  0
 	    	return capabilityClass;
 145  
 	    }
 146  
 
 147  
 	    private Class getMediaTypeClass()throws ClassNotFoundException
 148  
 	    {
 149  0
 	    	if (mediaTypeClass == null)
 150  
 	    	{
 151  0
 	    		mediaTypeClass = this.createMediaType(null).getClass();
 152  
 	    	}
 153  0
 	    	return mediaTypeClass;
 154  
 	    }
 155  
     
 156  
 
 157  
     /**
 158  
      * @param userAgent Agent from the request
 159  
      * @throws UnableToBuildCapabilityMapException
 160  
      * @see org.apache.jetspeed.services.capability.CapabilityService#getCapabilityMap(java.lang.String)
 161  
      */
 162  
     public CapabilityMap getCapabilityMap(String userAgent) throws UnableToBuildCapabilityMapException
 163  
     {        
 164  0
         CapabilityMap map = null;
 165  0
         boolean bClientFound = false;
 166  0
         String defaultAgent = null;
 167  
 
 168  0
         if (userAgent == null)
 169  
         {
 170  0
             userAgent = DEFAULT_AGENT;
 171  
         }
 172  
 
 173  
         // Check the cache if we have already a capability map for
 174  
         // the given Agent
 175  0
         map = (CapabilityMap) capabilityMapCache.get(userAgent);
 176  
 
 177  0
         if (map != null)
 178  
         {
 179  
             // Entry found
 180  0
             return map;
 181  
         }
 182  
 
 183  0
         while (!bClientFound)
 184  
         {
 185  0
             Client entry = findClient(userAgent);
 186  
 
 187  0
             if (entry == null)
 188  
             {
 189  0
                 if (userAgent.equals(DEFAULT_AGENT))
 190  
                 {
 191  0
                     log.error(
 192  
                         "CapabilityMap: Default agent not found in Client Registry !");
 193  
 
 194  
                     // Stop searching -- event the default userAgent can't be found
 195  0
                     bClientFound = true;
 196  
                 } else
 197  
                 {
 198  
                     // Retry with the default Agent
 199  0
                     if (log.isDebugEnabled())
 200  
                     {
 201  0
                         log.debug(
 202  
                             "CapabilityMap: useragent "
 203  
                                 + userAgent
 204  
                                 + "unknown, falling back to default");
 205  
                     }
 206  
 
 207  
                     // Use default Client
 208  0
                     defaultAgent = userAgent;
 209  0
                     userAgent = DEFAULT_AGENT;
 210  
                 }
 211  
             } else
 212  
             {
 213  
                 // Found Client entry start populating the capability map.
 214  0
                 map = new CapabilityMapImpl();
 215  
 
 216  
                 // Add client to CapabilityMap
 217  0
                 map.setClient(entry);
 218  
 
 219  
                 // Add capabilities
 220  0
                 Iterator capabilities = entry.getCapabilities().iterator();
 221  0
                 while (capabilities.hasNext())
 222  
                 {
 223  0
                     map.addCapability((Capability) capabilities.next());
 224  
                 }
 225  
 
 226  0
                 Collection mediatypes =
 227  
                     getMediaTypesForMimeTypes(entry.getMimetypes().iterator());
 228  
 
 229  
                 // Add Mimetypes to map
 230  0
                 Iterator mimetypes = entry.getMimetypes().iterator();
 231  0
                 while (mimetypes.hasNext())
 232  
                 {
 233  0
                     map.addMimetype((MimeType) mimetypes.next());
 234  
                 }
 235  
 
 236  0
                 Iterator media = mediatypes.iterator();
 237  0
                 while (media.hasNext())
 238  
                 {
 239  0
                     map.addMediaType((MediaType) media.next());
 240  
                 }
 241  
 
 242  
                 //Set preferred Mimetype
 243  0
                 MediaType mtEntry =
 244  
                     getMediaTypeForMimeType(map.getPreferredType().getName());
 245  
 
 246  0
                 map.setPreferredMediaType(mtEntry);
 247  
 
 248  
                 // Add map to cache
 249  0
                 capabilityMapCache.put(userAgent, map);
 250  0
                 if (defaultAgent != null)
 251  0
                     capabilityMapCache.put(defaultAgent, map);
 252  0
                 return map;
 253  
             }
 254  
 
 255  0
         }
 256  
         
 257  0
         if(map != null)
 258  
         {
 259  0
                return map;
 260  
         }
 261  
         else
 262  
         {
 263  0
             throw new UnableToBuildCapabilityMapException("We were unable to build a capability map for the agent, "+userAgent+
 264  
                                 ".  This might be an indiciation that the capability database has not been correctly initialized.");
 265  
         }
 266  
     }
 267  
 
 268  
     /**
 269  
      * Returns the client which matches the given useragent string.
 270  
      *
 271  
      * @param useragent     the useragent to match
 272  
      * @return the found client or null if the user-agent does not match any
 273  
      *  defined client
 274  
      * @see org.apache.jetspeed.capabilities.CapabilityService#findClient(java.lang.String)
 275  
      */
 276  
 
 277  
     public Client findClient(String userAgent)
 278  
     {
 279  0
         Client clientEntry = null;
 280  0
         Iterator clients = getClients();
 281  
 
 282  0
         if (log.isDebugEnabled())
 283  
         {
 284  0
             log.debug(
 285  
                 "ClientRegistry: Looking for client with useragent :"
 286  
                     + userAgent);
 287  
         }
 288  
 
 289  0
         while (clients.hasNext())
 290  
         {
 291  0
             Client client = (Client) clients.next();
 292  0
             if (client.getUserAgentPattern() != null)
 293  
             {
 294  
                 try
 295  
                 {
 296  
                     // Java 1.4 has regular expressions build in
 297  0
                     String exp = client.getUserAgentPattern();
 298  
                     //RE r = new RE(client.getUserAgentPattern());
 299  
                     //r.setMatchFlags(RE.MATCH_CASEINDEPENDENT);
 300  
                     //if (r.match(userAgent))
 301  0
                     if (userAgent.matches(exp))
 302  
                     {
 303  
 
 304  0
                         if (log.isDebugEnabled())
 305  
                         {
 306  0
                             log.debug(
 307  
                                 "Client: "
 308  
                                     + userAgent
 309  
                                     + " matches "
 310  
                                     + client.getUserAgentPattern());
 311  
                         }
 312  
 
 313  0
                         return client;
 314  
                     } else
 315  
                     {
 316  0
                         if (log.isDebugEnabled())
 317  
                         {
 318  0
                             log.debug(
 319  
                                 "Client: "
 320  
                                     + userAgent
 321  
                                     + " does not match "
 322  
                                     + client.getUserAgentPattern());
 323  
                         }
 324  
                     }
 325  0
                 } catch (java.util.regex.PatternSyntaxException e)
 326  
                 {
 327  0
                     String message =
 328  
                         "CapabilityServiceImpl: UserAgentPattern not valid : "
 329  
                             + client.getUserAgentPattern()
 330  
                             + " : "
 331  
                             + e.getMessage();
 332  0
                     log.error(message, e);
 333  0
                 }
 334  
             }
 335  0
         }
 336  
 
 337  0
         return clientEntry;
 338  
     }
 339  
 
 340  
     /* 
 341  
      * @see org.apache.jetspeed.capabilities.CapabilityService#getClients()
 342  
      */
 343  
     public Iterator getClients()
 344  
     {
 345  0
         if (null == clients)
 346  
         {
 347  
 			try
 348  
 			{
 349  0
 				QueryByCriteria query = QueryFactory.newQuery(getClientClass(), new Criteria());
 350  0
 	            query.addOrderByAscending("evalOrder");
 351  0
 	            this.clients = getPersistenceBrokerTemplate().getCollectionByQuery(query);
 352  
 	    	}
 353  0
 	    	catch (Exception e)
 354  
 	    	{
 355  0
 	            String message =
 356  
 	                "CapabilityServiceImpl: getClients query used invalid class ";
 357  0
 	            log.error(message, e);
 358  0
 	            return null;
 359  0
 	    	}
 360  
         }
 361  
 
 362  0
         return this.clients.iterator();
 363  
     }
 364  
 
 365  
     /* 
 366  
      * @see org.apache.jetspeed.capabilities.CapabilityService#getMediaTypesForMimeTypes(java.util.Iterator)
 367  
      */
 368  
     public Collection getMediaTypesForMimeTypes(Iterator mimetypes)
 369  
     {
 370  
         //Find the MediaType by matching the Mimetype
 371  
         
 372  0
         Criteria filter = new Criteria();
 373  
 
 374  0
         Vector temp = new Vector();
 375  
         // Add Mimetypes to map and create query
 376  0
         while (mimetypes.hasNext())
 377  
         {
 378  0
             MimeType mt = (MimeType) mimetypes.next();
 379  
 
 380  
             // Add mimetype to query
 381  
             // Note: mimetypes is a member of MediaTypeImpl
 382  
             // criteria.addEqualTo("mimetypes.name", mt.getName());
 383  
             //stuff.add(new Integer(mt.getMimetypeId()));
 384  0
             temp.add(mt.getName());
 385  0
         }
 386  
         
 387  0
         Collection co = null;
 388  0
         if (temp.size() > 0)
 389  
         {
 390  
 			try
 391  
 			{
 392  0
 				filter.addIn("mimetypes.name", temp);
 393  0
 			            QueryByCriteria query = QueryFactory.newQuery(getMediaTypeClass(), filter);
 394  0
 			            co = getPersistenceBrokerTemplate().getCollectionByQuery(query);            
 395  
 			}
 396  0
 			catch (Exception e)
 397  
 			{
 398  0
 			    String message =
 399  
 			        "CapabilityServiceImpl: getMediaTypesForMimeTypes -> getMediaTypeClass query used invalid class ";
 400  0
 			    log.error(message, e);
 401  
  
 402  0
 			}
 403  
         }
 404  0
         if (co == null || co.isEmpty())
 405  
         {
 406  0
             MediaType mt = getMediaType("html");
 407  0
             Vector v = new Vector();
 408  0
             v.add(mt);
 409  0
             return v;
 410  
         }
 411  0
         return co;
 412  
     }
 413  
 
 414  
     /* 
 415  
      * @see org.apache.jetspeed.capabilities.CapabilityService#deleteCapabilityMapCache()
 416  
      */
 417  
     public void deleteCapabilityMapCache()
 418  
     {
 419  0
         capabilityMapCache.clear();
 420  0
         clients = null;
 421  0
     }
 422  
 
 423  
     /* (non-Javadoc)
 424  
      * @see org.apache.jetspeed.capabilities.CapabilityService#getMediaType(java.lang.String)
 425  
      */
 426  
     public MediaType getMediaType(String mediaType)
 427  
     {        
 428  
     	try
 429  
     	{
 430  0
 	        Criteria filter = new Criteria();        
 431  0
 	        filter.addEqualTo("name", mediaType);
 432  0
 	        QueryByCriteria query = QueryFactory.newQuery(getMediaTypeClass(), filter);
 433  0
 	        return (MediaType) getPersistenceBrokerTemplate().getObjectByQuery(query);                   
 434  
 		}
 435  0
 		catch (Exception e)
 436  
 		{
 437  0
 	        String message =
 438  
 	            "CapabilityServiceImpl: getMediaType query used invalid class ";
 439  0
 	        log.error(message, e);
 440  0
 	        return null;
 441  
 		}
 442  
     }
 443  
 
 444  
     /**
 445  
      * getMediaTypeForMimeType
 446  
      * @param mimeType to use for lookup
 447  
      * @return MediaTypeEntry that matches the lookup in the MEDIATYPE_TO_MIMETYPE table
 448  
      */
 449  
     public MediaType getMediaTypeForMimeType(String mimeTypeName)
 450  
     {               
 451  
         //Find the MediaType by matching the Mimetype
 452  0
     	Collection mediaTypeCollection = null;
 453  
 		try
 454  
 		{
 455  0
 	        Criteria filter = new Criteria();       
 456  0
 	        filter.addEqualTo("mimetypes.name", mimeTypeName);
 457  
 	        
 458  0
 	        QueryByCriteria query = QueryFactory.newQuery(getMediaTypeClass(), filter);
 459  0
 	        mediaTypeCollection = getPersistenceBrokerTemplate().getCollectionByQuery(query);                    
 460  
 		}
 461  0
 		catch (Exception e)
 462  
 		{
 463  0
 	        String message =
 464  
 	            "CapabilityServiceImpl: getMediaTypeForMimeType query used invalid class ";
 465  0
 	        log.error(message, e);
 466  0
 	        return null;
 467  0
 		}
 468  
         
 469  0
         Iterator mtIterator = mediaTypeCollection.iterator();
 470  0
         if (mtIterator.hasNext())
 471  
         {
 472  0
             return (MediaType) mtIterator.next();
 473  
         } else
 474  
         {
 475  0
             return null;
 476  
         }
 477  
     }
 478  
 
 479  
     /**
 480  
      * Obtain an iterator of all existing capabilities.
 481  
      * @return Returns an iterator for all existing Capabilities of type <code>Capability</code>
 482  
      */
 483  
     public Iterator getCapabilities()
 484  
     {
 485  0
     	QueryByCriteria query = null;
 486  
 		try
 487  
 		{
 488  0
 			query = QueryFactory.newQuery(getCapabilityClass(), new Criteria());
 489  
 		}
 490  0
 		catch (Exception e)
 491  
 		{
 492  0
 	        String message =
 493  
 	            "CapabilityServiceImpl: getCapabilities query used invalid class ";
 494  0
 	        log.error(message, e);
 495  0
 	        return null;
 496  0
 		}
 497  0
         query.addOrderByAscending("name");
 498  0
         return getPersistenceBrokerTemplate().getCollectionByQuery(query).iterator();        
 499  
     }
 500  
     
 501  
     /**
 502  
      * Obtain an iterator of all existing mime types.
 503  
      * @return Returns an iterator for all existing Mime Types of type <code>MimeType</code>
 504  
      */
 505  
     public Iterator getMimeTypes()
 506  
     {
 507  
 		try
 508  
 		{
 509  0
 			QueryByCriteria query = QueryFactory.newQuery(getMimeTypeClass(), new Criteria());
 510  0
 	        query.addOrderByAscending("name");
 511  0
 	        return getPersistenceBrokerTemplate().getCollectionByQuery(query).iterator();                
 512  
 		}
 513  0
 		catch (Exception e)
 514  
 		{
 515  0
 	        String message =
 516  
 	            "CapabilityServiceImpl: getMimeTypes query used invalid class ";
 517  0
 	        log.error(message, e);
 518  0
 	        return null;
 519  
 		}
 520  
     }
 521  
     
 522  
     /**
 523  
      * Obtain an iterator of all existing media types.
 524  
      * @return Returns an iterator for all existing media types of type <code>MediaType</code>
 525  
      */
 526  
     public Iterator getMediaTypes()
 527  
     {
 528  
 		try
 529  
 		{
 530  0
 			QueryByCriteria query = QueryFactory.newQuery(getMediaTypeClass(), new Criteria());
 531  0
 	        query.addOrderByAscending("name");
 532  0
 	        return getPersistenceBrokerTemplate().getCollectionByQuery(query).iterator();                        
 533  
 		}
 534  0
 		catch (Exception e)
 535  
 		{
 536  0
 	        String message =
 537  
 	            "CapabilityServiceImpl: getMediaTypes query used invalid class ";
 538  0
 	        log.error(message, e);
 539  0
 	        return null;
 540  
 		}
 541  
     }
 542  
     /* 
 543  
      * @see org.apache.jetspeed.capabilities.Capabilities#getMimeTypeBeanName()
 544  
      */
 545  
 	public String getMimeTypeBeanName() {
 546  0
 		return mimeTypeBeanName;
 547  
 	}
 548  
 
 549  
 	/* 
 550  
      * @see org.apache.jetspeed.capabilities.Capabilities#setMimeTypeBeanName(String)
 551  
      */
 552  
 	public void setMimeTypeBeanName(String mimeTypeBeanName) {
 553  0
 		this.mimeTypeBeanName = mimeTypeBeanName;
 554  0
 	}
 555  
 
 556  
 	   /* 
 557  
      * @see org.apache.jetspeed.capabilities.Capabilities#getClientBeanName()
 558  
      */
 559  
 	public String getClientBeanName() {
 560  0
 		return clientBeanName;
 561  
 	}
 562  
 
 563  
 	/* 
 564  
      * @see org.apache.jetspeed.capabilities.Capabilities#setClientBeanName(String)
 565  
      */
 566  
 	public void setClientBeanName(String clientBeanName) {
 567  0
 		this.clientBeanName = clientBeanName;
 568  0
 	}
 569  
 
 570  
 	   /* 
 571  
      * @see org.apache.jetspeed.capabilities.Capabilities#getMediaTypeBeanName()
 572  
      */
 573  
 	public String getMediaTypeBeanName() {
 574  0
 		return mediaTypeBeanName;
 575  
 	}
 576  
 
 577  
 	/* 
 578  
      * @see org.apache.jetspeed.capabilities.Capabilities#setMediaTypeBeanName(String)
 579  
      */
 580  
 	public void setMediaTypeBeanName(String mediaTypeBeanName) {
 581  0
 		this.mediaTypeBeanName = mediaTypeBeanName;
 582  0
 	}
 583  
 
 584  
 	/* 
 585  
      * @see org.apache.jetspeed.capabilities.Capabilities#getCapabilityBeanName()
 586  
      */
 587  
 	public String getCapabilityBeanName() {
 588  0
 		return capabilityBeanName;
 589  
 	}
 590  
 
 591  
 	/* 
 592  
      * @see org.apache.jetspeed.capabilities.Capabilities#setCapabilityBeanName(String)
 593  
      */
 594  
 	public void setCapabilityBeanName(String capabilityBeanName) {
 595  0
 		this.capabilityBeanName = capabilityBeanName;
 596  0
 	}
 597  
     
 598  
 	/* 
 599  
      * @see org.apache.jetspeed.capabilities.Capabilities#createMimeType(String)
 600  
      */
 601  
 	public MimeType createMimeType(String mimeType)
 602  
 	 throws ClassNotFoundException
 603  
 	    {
 604  0
 		MimeType mimeTypeobj = null;
 605  0
 		if (mimeType != null)
 606  
 		{
 607  
 			//try to find it in space
 608  0
 			mimeTypeobj = this.getMimeType(mimeType);
 609  0
 			if (mimeTypeobj != null)
 610  0
 				return mimeTypeobj;
 611  
 		}
 612  
         try
 613  
         {
 614  0
         	mimeTypeobj = (MimeType) beanFactory.getBean(
 615  
                     this.mimeTypeBeanName, MimeType.class);
 616  0
         	mimeTypeobj.setName(mimeType);
 617  0
             return mimeTypeobj;
 618  0
         } catch (Exception e)
 619  
         {
 620  0
             log.error("Failed to create capability instance for " + this.mimeTypeBeanName 
 621  
                     + " error : " + e.getLocalizedMessage());
 622  0
             throw new ClassNotFoundException("Spring failed to create the " + this.mimeTypeBeanName
 623  
                     + " mimeType bean.", e);
 624  
         }
 625  
 	}
 626  
     
 627  
 
 628  
 	/* 
 629  
      * @see org.apache.jetspeed.capabilities.Capabilities#createCapability(String)
 630  
      */
 631  
 	public Capability createCapability(String capabilityName)	 throws ClassNotFoundException
 632  
 	    {
 633  0
 		Capability capability = null;
 634  0
 		if (capabilityName != null)
 635  
 		{
 636  
 			//try to find it in space
 637  0
 			capability = this.getCapability(capabilityName);
 638  0
 			if (capability != null)
 639  0
 				return capability;
 640  
 		}
 641  
         try
 642  
         {
 643  0
         	capability = (Capability) beanFactory.getBean(
 644  
                     this.capabilityBeanName, Capability.class);
 645  0
         	capability.setName(capabilityName);
 646  0
             return capability;
 647  0
         } catch (Exception e)
 648  
         {
 649  0
             log.error("Failed to create capability instance for " + this.capabilityBeanName
 650  
                     + " error : " + e.getLocalizedMessage());
 651  0
             throw new ClassNotFoundException("Spring failed to create the "
 652  
                     + " capability bean.", e);
 653  
         }
 654  
 	}
 655  
 
 656  
 	/* 
 657  
      * @see org.apache.jetspeed.capabilities.Capabilities#createMediaType(String)
 658  
      */
 659  
 	public MediaType createMediaType(String mediaTypeName)	 throws ClassNotFoundException
 660  
 	    {
 661  0
 		MediaType mediaType = null;
 662  0
 		if (mediaTypeName != null)
 663  
 		{
 664  
 			//try to find it in space
 665  0
 			mediaType = this.getMediaType(mediaTypeName);
 666  0
 			if (mediaType != null)
 667  0
 				return mediaType;
 668  
 		}
 669  
         try
 670  
         {
 671  0
         	mediaType = (MediaType) beanFactory.getBean(
 672  
                     this.mediaTypeBeanName, MediaType.class);
 673  0
         	mediaType.setName(mediaTypeName);
 674  0
             return mediaType;
 675  0
         } catch (Exception e)
 676  
         {
 677  0
             log.error("Failed to create mediaType instance for " + this.mediaTypeBeanName
 678  
                     + " error : " + e.getLocalizedMessage());
 679  0
             throw new ClassNotFoundException("Spring failed to create the "
 680  
                     + " mediaType bean.", e);
 681  
         }
 682  
 	}
 683  
 
 684  
 
 685  
 	/* 
 686  
      * @see org.apache.jetspeed.capabilities.Capabilities#createClient(String)
 687  
      */
 688  
 	public Client createClient(String clientName) throws ClassNotFoundException
 689  
 	    {
 690  0
 		Client client = null;
 691  0
 		if (clientName != null)
 692  
 		{
 693  
 			//try to find it in space
 694  0
 			client = this.getClient(clientName);
 695  0
 			if (client != null)
 696  0
 				return client;
 697  
 		}
 698  
         try
 699  
         {
 700  0
         	client = (Client) beanFactory.getBean(
 701  
                     this.clientBeanName, Client.class);
 702  0
         	client.setName(clientName);
 703  0
             return client;
 704  0
         } catch (Exception e)
 705  
         {
 706  0
             log.error("Failed to create client instance for " + this.clientBeanName
 707  
                     + " error : " + e.getLocalizedMessage());
 708  0
             throw new ClassNotFoundException("Spring failed to create the "
 709  
                     + " client bean.", e);
 710  
         }
 711  
 	}
 712  
     /* (non-Javadoc)
 713  
      * @see org.apache.jetspeed.capabilities.MimeTypeservice#getCapability(java.lang.String)
 714  
      */
 715  
     public MimeType getMimeType(String mimeType)
 716  
     {
 717  
     	try
 718  
     	{
 719  0
 	        Criteria filter = new Criteria();        
 720  0
 	        filter.addEqualTo("name", mimeType);
 721  0
 	        QueryByCriteria query = QueryFactory.newQuery(getMimeTypeClass(), filter);
 722  0
 	        return (MimeType) getPersistenceBrokerTemplate().getObjectByQuery(query);
 723  
 		}
 724  0
 		catch (Exception e)
 725  
 		{
 726  0
 	        String message =
 727  
 	            "MimeTypeserviceImpl: getCapability - query for getCapabilityClass failed ";
 728  0
 	        log.error(message, e);
 729  0
 	        return null;
 730  
 	
 731  
 		}
 732  
 
 733  
     }
 734  
 
 735  
 
 736  
     /* (non-Javadoc)
 737  
      * @see org.apache.jetspeed.capabilities.MimeTypeservice#getClientjava.lang.String)
 738  
      */
 739  
     public Client getClient(String clientName)
 740  
     {     
 741  
     	try
 742  
     	{
 743  0
 	        Criteria filter = new Criteria();        
 744  0
 	        filter.addEqualTo("name", clientName);
 745  0
 	        QueryByCriteria query = QueryFactory.newQuery(getClientClass(), filter);
 746  0
 	        return (Client) getPersistenceBrokerTemplate().getObjectByQuery(query);                   
 747  
 		}
 748  0
 		catch (Exception e)
 749  
 		{
 750  0
 	        String message =
 751  
 	            "MimeTypeserviceImpl: getClient - query for getClientClass failed ";
 752  0
 	        log.error(message, e);
 753  0
 	        return null;
 754  
 	
 755  
 		}
 756  
    }
 757  
   
 758  
 
 759  
     /* (non-Javadoc)
 760  
      * @see org.apache.jetspeed.capabilities.MimeTypeservice#getCapability(java.lang.String)
 761  
      */
 762  
     public Capability getCapability(String capability)
 763  
     {      
 764  
     	try
 765  
     	{
 766  
     	
 767  0
 	        Criteria filter = new Criteria();        
 768  0
 	        filter.addEqualTo("name", capability);
 769  0
 	        QueryByCriteria query = QueryFactory.newQuery(getCapabilityClass(), filter);
 770  0
 	        return (Capability) getPersistenceBrokerTemplate().getObjectByQuery(query);                   
 771  
 		}
 772  0
 		catch (Exception e)
 773  
 		{
 774  0
 	        String message =
 775  
 	            "MimeTypeserviceImpl: getCapability - query for getCapabilityClass failed ";
 776  0
 	        log.error(message, e);
 777  0
 	        return null;
 778  
 	
 779  
 		}
 780  
     }
 781  
 
 782  
     
 783  
 	/* 
 784  
      * (non-Javadoc)
 785  
      * 
 786  
      * @see org.apache.jetspeed.capabilities.Capabilities#storeMediaType(MediaType)
 787  
      */
 788  
     public void storeMediaType(MediaType mediaType) throws CapabilitiesException
 789  
     {
 790  
 
 791  
     	//TODO: change exception to better indicate cause
 792  0
     	getPersistenceBrokerTemplate().store(mediaType);
 793  0
     }
 794  
 
 795  
     /*
 796  
      * (non-Javadoc)
 797  
      * 
 798  
      * @see org.apache.jetspeed.capabilities.Capabilities#deleteMediaType(MediaType)
 799  
      */
 800  
     public void deleteMediaType(MediaType mediaType)
 801  
             throws CapabilitiesException
 802  
     {
 803  
     	//TODO: change exception to better indicate cause
 804  0
         getPersistenceBrokerTemplate().delete(mediaType);
 805  0
     }
 806  
 
 807  
 	
 808  
 	/* 
 809  
      * (non-Javadoc)
 810  
      * 
 811  
      * @see org.apache.jetspeed.capabilities.Capabilities#storeCapability(MediaType)
 812  
      */
 813  
     public void storeCapability(Capability capability) throws CapabilitiesException
 814  
     {
 815  
 
 816  
     	//TODO: change exception to better indicate cause
 817  0
     	getPersistenceBrokerTemplate().store(capability);
 818  0
     }
 819  
 
 820  
     /*
 821  
      * (non-Javadoc)
 822  
      * 
 823  
      * @see org.apache.jetspeed.capabilities.Capabilities#deleteCapability(Capability)
 824  
      */
 825  
     public void deleteCapability(Capability capability)
 826  
             throws CapabilitiesException
 827  
     {
 828  
     	//TODO: change exception to better indicate cause
 829  0
         getPersistenceBrokerTemplate().delete(capability);
 830  0
     }
 831  
 
 832  
 	/* 
 833  
      * (non-Javadoc)
 834  
      * 
 835  
      * @see org.apache.jetspeed.capabilities.Capabilities#storeMimeType(MimeType)
 836  
      */
 837  
     public void storeMimeType(MimeType mimeType) throws CapabilitiesException
 838  
     {
 839  
 
 840  
     	//TODO: change exception to better indicate cause
 841  0
     	getPersistenceBrokerTemplate().store(mimeType);
 842  0
     }
 843  
 
 844  
     /*
 845  
      * (non-Javadoc)
 846  
      * 
 847  
      * @see org.apache.jetspeed.capabilities.Capabilities#deleteMimeType(MimeType)
 848  
      */
 849  
     public void deleteMimeType(MimeType mimeType)
 850  
             throws CapabilitiesException
 851  
     {
 852  
     	//TODO: change exception to better indicate cause
 853  0
         getPersistenceBrokerTemplate().delete(mimeType);
 854  0
     }
 855  
 
 856  
 
 857  
 
 858  
 	
 859  
 	/* 
 860  
      * (non-Javadoc)
 861  
      * 
 862  
      * @see org.apache.jetspeed.capabilities.Capabilities#storeClient(MediaType)
 863  
      */
 864  
     public void storeClient(Client client) throws CapabilitiesException
 865  
     {
 866  
 
 867  
     	//TODO: change exception to better indicate cause
 868  0
     	getPersistenceBrokerTemplate().store(client);
 869  0
     }
 870  
 
 871  
     /*
 872  
      * (non-Javadoc)
 873  
      * 
 874  
      * @see org.apache.jetspeed.capabilities.Capabilities#deleteClient(Client)
 875  
      */
 876  
     public void deleteClient(Client client)
 877  
             throws CapabilitiesException
 878  
     {
 879  
     	//TODO: change exception to better indicate cause
 880  0
         getPersistenceBrokerTemplate().delete(client);
 881  0
     }
 882  
     
 883  
 }

This report is generated by jcoverage, Maven and Maven JCoverage Plugin.