1 // SECTION-START[License Header] 2 // <editor-fold defaultstate="collapsed" desc=" Generated License "> 3 /* 4 * Copyright (c) 2010 The JOMC Project 5 * Copyright (c) 2005 Christian Schulte <schulte2005@users.sourceforge.net> 6 * All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 12 * o Redistributions of source code must retain the above copyright 13 * notice, this list of conditions and the following disclaimer. 14 * 15 * o Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in 17 * the documentation and/or other materials provided with the 18 * distribution. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE JOMC PROJECT AND CONTRIBUTORS "AS IS" 21 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 22 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE JOMC PROJECT OR 24 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 25 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 26 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 27 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 28 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 29 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 30 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 * 32 * $Id: javaURLContextFactory.java 2270 2010-06-29 13:25:34Z schulte2005 $ 33 * 34 */ 35 // </editor-fold> 36 // SECTION-END 37 package org.jomc.standalone.ri.naming.java; 38 39 import java.util.Hashtable; 40 import javax.naming.CompositeName; 41 import javax.naming.Context; 42 import javax.naming.Name; 43 import javax.naming.spi.ObjectFactory; 44 import org.jomc.standalone.ri.naming.StandaloneContext; 45 46 // SECTION-START[Documentation] 47 // <editor-fold defaultstate="collapsed" desc=" Generated Documentation "> 48 /** 49 * Standalone context factory for the ''java'' URL scheme. 50 * <p><b>Specifications</b><ul> 51 * <li>{@code 'javax.naming.spi.ObjectFactory'} {@code (javax.naming.spi.ObjectFactory)} {@code Multiton}</li> 52 * </ul></p> 53 * 54 * @author <a href="mailto:schulte2005@users.sourceforge.net">Christian Schulte</a> 1.0 55 * @version $Id: javaURLContextFactory.java 2270 2010-06-29 13:25:34Z schulte2005 $ 56 */ 57 // </editor-fold> 58 // SECTION-END 59 // SECTION-START[Annotations] 60 // <editor-fold defaultstate="collapsed" desc=" Generated Annotations "> 61 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.0", comments = "See http://jomc.sourceforge.net/jomc/1.0/jomc-tools" ) 62 // </editor-fold> 63 // SECTION-END 64 public class javaURLContextFactory implements ObjectFactory 65 { 66 // SECTION-START[ObjectFactory] 67 68 private static Context javaContext; 69 70 public Object getObjectInstance( final Object obj, final Name name, final Context nameCtx, 71 final Hashtable environment ) throws Exception 72 { 73 synchronized ( javaURLContextFactory.class ) 74 { 75 if ( javaContext == null ) 76 { 77 javaContext = new StandaloneContext(); 78 javaContext.getEnvironment().putAll( environment ); 79 } 80 81 if ( obj == null ) 82 { 83 return javaContext; 84 } 85 if ( obj instanceof String && ( (String) obj ).startsWith( "java:" ) ) 86 { 87 return javaContext.lookup( new CompositeName( obj.toString() ) ); 88 } 89 if ( obj instanceof String[] && ( (String[]) obj ).length > 0 ) 90 { 91 final String url = ( (String[]) obj )[0]; 92 if ( url.startsWith( "java:" ) ) 93 { 94 return javaContext.lookup( new CompositeName( ( (String[]) obj )[0] ) ); 95 } 96 } 97 98 return null; 99 } 100 } 101 102 // SECTION-END 103 // SECTION-START[javaURLContextFactory] 104 // SECTION-END 105 // SECTION-START[Constructors] 106 // <editor-fold defaultstate="collapsed" desc=" Generated Constructors "> 107 108 /** Creates a new {@code javaURLContextFactory} instance. */ 109 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.0", comments = "See http://jomc.sourceforge.net/jomc/1.0/jomc-tools" ) 110 public javaURLContextFactory() 111 { 112 // SECTION-START[Default Constructor] 113 super(); 114 // SECTION-END 115 } 116 // </editor-fold> 117 // SECTION-END 118 // SECTION-START[Dependencies] 119 // SECTION-END 120 // SECTION-START[Properties] 121 // SECTION-END 122 // SECTION-START[Messages] 123 // SECTION-END 124 }