1 /* 2 * Copyright (c) 2007, Fraunhofer-Gesellschaft 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are 7 * met: 8 * 9 * (1) Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the disclaimer at the end. 11 * Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in 13 * the documentation and/or other materials provided with the 14 * distribution. 15 * 16 * (2) Neither the name of Fraunhofer nor the names of its 17 * contributors may be used to endorse or promote products derived 18 * from this software without specific prior written permission. 19 * 20 * DISCLAIMER 21 * 22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 25 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 26 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 27 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 28 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 32 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 * 34 */ 35 package org.ogf.graap.wsag.api.pattern; 36 37 import org.apache.xmlbeans.XmlObject; 38 import org.ggf.schemas.jsdl.x2005.x11.jsdl.ApplicationType; 39 import org.ggf.schemas.jsdl.x2005.x11.jsdl.JobDefinitionType; 40 import org.ogf.schemas.graap.wsAgreement.TermCompositorType; 41 42 /** 43 * ComputeApplicationPattern 44 * 45 * The term compositor contains an Application SDT. 46 * 47 * @author Oliver Waeldrich 48 * 49 * <pre> 50 * {@code 51 * <wsag:Template wsag:TemplateId="1" 52 * xmlns:wsag="http://schemas.ggf.org/graap/2007/03/ws-agreement"> 53 * <wsag:Name>ADAVANCE_RESERVATION_TEMPLATE</wsag:Name> 54 * <wsag:Context> 55 * <wsag:ServiceProvider>AgreementResponder</wsag:ServiceProvider> 56 * <wsag:TemplateId>1</wsag:TemplateId> 57 * <wsag:TemplateName>ADAVANCE_RESERVATION_TEMPLATE</wsag:TemplateName> 58 * </wsag:Context> 59 * <wsag:Terms> 60 * <wsag:All> 61 * <wsag:ServiceDescriptionTerm wsag:Name="SDT_1" 62 * wsag:ServiceName="SERVICE_1"> 63 * (Put your service description terms here) .... 64 * </wsag:ServiceDescriptionTerm> 65 * ... 66 * <wsag:ServiceDescriptionTerm wsag:Name="APPLICATION_SDT" 67 * wsag:ServiceName="CHANGE_ME"> 68 * <jsdl:JobDefinition xmlns:jsdl="http://schemas.ggf.org/jsdl/2005/11/jsdl"> 69 * <jsdl:JobDescription> 70 * <jsdl:Application> 71 * <jsdl:ApplicationName>ApplicationName</jsdl:ApplicationName> 72 * <jsdl:ApplicationVersion>ApplicationVersion</jsdl:ApplicationVersion> 73 * <jsdl:Description>Description</jsdl:Description> 74 * </jsdl:Application> 75 * </jsdl:JobDescription> 76 * </jsdl:JobDefinition> 77 * </wsag:ServiceDescriptionTerm> 78 * </wsag:All> 79 * </wsag:Terms> 80 * <wsag:CreationConstraints /> 81 * </wsag:Template> 82 * } 83 * </pre> 84 * 85 * 86 */ 87 public class ComputeApplicationPattern extends AbstractPattern 88 { 89 90 private JobDefinitionType jobDefinition; 91 92 private static final String APPLICATION_XPATH = 93 "declare namespace jsdl='http://schemas.ggf.org/jsdl/2005/11/jsdl';" 94 + "declare namespace wsag='http://schemas.ggf.org/graap/2007/03/ws-agreement';" 95 + "$this/wsag:ServiceDescriptionTerm[@wsag:Name = 'APPLICATION_SDT']/jsdl:JobDefinition"; 96 97 /** 98 * Instantiates the pattern for the given term compositor. 99 * 100 * @param termCompositor 101 * the term compositor 102 */ 103 public ComputeApplicationPattern( TermCompositorType termCompositor ) 104 { 105 super( termCompositor ); 106 107 initialize(); 108 } 109 110 /** 111 * initializes the quote object 112 */ 113 private void initialize() 114 { 115 XmlObject[] jobConstraints = getTermCompositor().selectPath( getApplicationxpath() ); 116 117 if ( jobConstraints.length != 1 ) 118 { 119 throw new IllegalStateException( "Invalid number of job descriptions in template." ); 120 } 121 122 jobDefinition = (JobDefinitionType) jobConstraints[0]; 123 } 124 125 /** 126 * @return the selected application 127 */ 128 public ApplicationType getSelectedApplication() 129 { 130 return jobDefinition.getJobDescription().getApplication(); 131 } 132 133 /** 134 * @return the selected job definition that contains the application 135 */ 136 public JobDefinitionType getSelectedJobDefinition() 137 { 138 return jobDefinition; 139 } 140 141 /** 142 * Subclasses may overwrite this method in order to provide a custom expression for selecting the 143 * applications. 144 * 145 * @return the XPath expression that is used to select the applications from the term compositor. 146 */ 147 public static String getApplicationxpath() 148 { 149 return APPLICATION_XPATH; 150 } 151 152 }