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.sg.impl; 36 37 import javax.xml.namespace.QName; 38 39 import org.w3.x2005.x08.addressing.EndpointReferenceType; 40 41 /** 42 * MembershipContentRuleContext 43 * 44 * A MembershipContentRule may lookup the QName of the port type for resources that are created locally via 45 * the MembershipContentRuleContext. 46 * 47 * The port type QName is set by the @see ServiceGroup resourceAdded method, and is unset after invocation. 48 * 49 * @author Oliver Waeldrich 50 * 51 */ 52 public class MembershipContentRuleContext 53 { 54 55 private static ThreadLocal<RuleContextContainer> context = null; 56 57 /** 58 * Initializes the {@link ThreadLocal} during the initialization of the 59 * {@link org.ogf.graap.wsag.wsrf.impl.WSAG4JResourceRouter}. 60 * 61 * @see org.ogf.graap.wsag.wsrf.impl.WSAG4JResourceRouter#initialize() 62 * @see org.ogf.graap.wsag.wsrf.bootstrap.WSAG4JContextListener#contextInitialized(javax.servlet.ServletContextEvent) 63 */ 64 public static synchronized void initializeContext() 65 { 66 if ( context != null ) 67 { 68 return; 69 } 70 71 context = new ThreadLocal<RuleContextContainer>() 72 { 73 74 protected RuleContextContainer initialValue() 75 { 76 return new RuleContextContainer(); 77 } 78 }; 79 } 80 81 /** 82 * Unsets the {@link ThreadLocal} during the shutdown process of the 83 * {@link org.ogf.graap.wsag.wsrf.impl.WSAG4JResourceRouter} in order to prevent memory leaks. 84 * 85 * @see org.ogf.graap.wsag.wsrf.impl.WSAG4JResourceRouter#shutdown() 86 * @see org.ogf.graap.wsag.wsrf.bootstrap.WSAG4JContextListener#contextDestroyed(javax.servlet.ServletContextEvent) 87 */ 88 public static synchronized void finalizeContext() 89 { 90 // 91 // prevent memory leak 92 // 93 if ( context != null ) 94 { 95 context.set( null ); 96 context = null; 97 } 98 } 99 100 /** 101 * 102 * @return the QName of the implemented port type 103 */ 104 public static QName getPortTypeQName() 105 { 106 return context.get().getPortTypeQName(); 107 } 108 109 /** 110 * 111 * @param porttype 112 * the QName of the implemented port type 113 */ 114 public static void setPortTypeQName( QName porttype ) 115 { 116 context.get().setPortTypeQName( porttype ); 117 } 118 119 /** 120 * 121 * @return the agreement factory EPR 122 */ 123 public static EndpointReferenceType getFactoryEPR() 124 { 125 return context.get().getFactoryEPR(); 126 } 127 128 /** 129 * 130 * @param epr 131 * the agreement factory EPR 132 */ 133 public static void setFactoryEPR( EndpointReferenceType epr ) 134 { 135 ( (RuleContextContainer) context.get() ).setFactoryEPR( epr ); 136 } 137 138 /** 139 * 140 * @return the agreement registry EPR 141 */ 142 public static EndpointReferenceType getRegistryEPR() 143 { 144 return ( (RuleContextContainer) context.get() ).getRegistryEPR(); 145 } 146 147 /** 148 * 149 * @param epr 150 * the agreement registry EPR 151 */ 152 public static void setRegistryEPR( EndpointReferenceType epr ) 153 { 154 ( (RuleContextContainer) context.get() ).setRegistryEPR( epr ); 155 } 156 }