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.wsrf.bootstrap; 36 37 import java.io.File; 38 import java.io.InputStream; 39 import java.net.URL; 40 41 import org.apache.muse.core.AbstractEnvironment; 42 import org.apache.muse.ws.addressing.EndpointReference; 43 import org.apache.muse.ws.addressing.MessageHeaders; 44 45 /** 46 * The bootstrap environment implements a {@link AbstractEnvironment} in order to start up the WSRF layer 47 * before the initial invocation of the web service interface. 48 * 49 * @author Oliver Waeldrich 50 * 51 */ 52 public class BootstrapEnvironment extends AbstractEnvironment 53 { 54 55 private String realPath = null; 56 57 /** 58 * Creates a {@link BootstrapEnvironment} with a given application path (path of the expanded web 59 * application) and the external URI of the application. 60 * 61 * @param realPath 62 * the real path on the file system used for this environment 63 * 64 * @param defaultDeploymentUri 65 * the default WSRF deployment URI 66 */ 67 public BootstrapEnvironment( String realPath, String defaultDeploymentUri ) 68 { 69 this.realPath = realPath; 70 setDefaultURI( defaultDeploymentUri ); 71 } 72 73 /** 74 * @return the deployment EPR 75 */ 76 public EndpointReference getDeploymentEPR() 77 { 78 return getDefaultEPR(); 79 } 80 81 /** 82 * @return the real path on the file system used for this environment 83 */ 84 public File getRealDirectory() 85 { 86 return new File( realPath, "WEB-INF/classes" ); 87 } 88 89 /** 90 * registers a new addressing context 91 * 92 * @param context 93 * the addressing context 94 */ 95 public synchronized void addAddressingContext( MessageHeaders context ) 96 { 97 BootstrapRegistry.registerAddressingContext( context ); 98 } 99 100 /** 101 * @return the registered addressing context 102 */ 103 public synchronized MessageHeaders getAddressingContext() 104 { 105 return BootstrapRegistry.getAddressingContext(); 106 } 107 108 /** 109 * looks up a data resource at the given path 110 * 111 * @param path 112 * the name of the data resource 113 * 114 * @return the data resource URL 115 */ 116 public URL getDataResource( String path ) 117 { 118 return super.getDataResource( resolveName( path ) ); 119 } 120 121 /** 122 * Returns the data resource at the given path as an {@link InputStream}. 123 * 124 * @param path 125 * the name of the data resource 126 * 127 * @return the data resource input stream 128 */ 129 public InputStream getDataResourceStream( String path ) 130 { 131 String resource = resolveName( path ); 132 try 133 { 134 return super.getDataResourceStream( resource ); 135 } 136 catch ( RuntimeException e ) 137 { 138 throw new RuntimeException( "Could not reolve data resource: " + resource, e ); 139 } 140 } 141 142 /** 143 * Remove leading "/" if name is absolute 144 */ 145 private String resolveName( String name ) 146 { 147 if ( name == null ) 148 { 149 return name; 150 } 151 152 if ( name.startsWith( "/" ) ) 153 { 154 name = name.substring( 1 ); 155 } 156 return name; 157 } 158 159 }