|
Java example source code file (CorbalocURL.java)
The CorbalocURL.java Java example source code/* * Copyright (c) 2002, 2003, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package com.sun.corba.se.impl.naming.namingutil; import java.util.*; import com.sun.corba.se.spi.logging.CORBALogDomains ; import com.sun.corba.se.impl.logging.NamingSystemException ; /** * The corbaloc: URL definitions from the -ORBInitDef and -ORBDefaultInitDef's * will be parsed and converted to this object. This object is capable of * storing multiple Host profiles as defined in the CorbaLoc grammer. * * @author Hemanth */ public class CorbalocURL extends INSURLBase { static NamingSystemException wrapper = NamingSystemException.get( CORBALogDomains.NAMING_READ ) ; /** * This constructor parses the URL and initializes all the variables. Once * the URL Object is constructed it is immutable. URL parameter is a * corbaloc: URL string with 'corbaloc:' prefix stripped. */ public CorbalocURL( String aURL ) { String url = aURL; if( url != null ) { try { // First Clean the URL Escapes if there are any url = Utility.cleanEscapes( url ); } catch( Exception e ) { // There is something wrong with the URL escapes used // so throw an exception badAddress( e ); } int endIndex = url.indexOf( '/' ); if( endIndex == -1 ) { // If there is no '/' then the endIndex is at the end of the URL endIndex = url.length(); } // _REVISIT_: Add a testcase to check 'corbaloc:/' if( endIndex == 0 ) { // The url starts with a '/', it's an error badAddress( null ); } // Anything between corbaloc: and / is the host,port information // of the server where the Service Object is located StringTokenizer endpoints = new StringTokenizer( url.substring( 0, endIndex ), "," ); // NOTE: // There should be atleast one token, because there are checks // to make sure that there is host information before the // delimiter '/'. So no need to explicitly check for number of // tokens != 0 while( endpoints.hasMoreTokens( ) ) { String endpointInfo = endpoints.nextToken(); IIOPEndpointInfo iiopEndpointInfo = null; if( endpointInfo.startsWith( "iiop:" ) ) { iiopEndpointInfo = handleIIOPColon( endpointInfo ); } else if( endpointInfo.startsWith( "rir:" ) ) { handleRIRColon( endpointInfo ); rirFlag = true; } else if( endpointInfo.startsWith( ":" ) ) { iiopEndpointInfo = handleColon( endpointInfo ); } else { // Right now we are not allowing any other protocol // other than iiop:, rir: so raise exception indicating // that the URL is malformed badAddress( null ); } if ( rirFlag == false ) { // Add the Host information if RIR flag is set, // If RIR is set then it means use the internal Boot // Strap protocol for Key String resolution if( theEndpointInfo == null ) { theEndpointInfo = new java.util.ArrayList( ); } theEndpointInfo.add( iiopEndpointInfo ); } } // If there is something after corbaloc:endpointInfo/ // then that is the keyString if( url.length() > (endIndex + 1) ) { theKeyString = url.substring( endIndex + 1 ); } } } /** * A Utility method to throw BAD_PARAM exception to signal malformed * INS URL. */ private void badAddress( java.lang.Throwable e ) { throw wrapper.insBadAddress( e ) ; } /** * If there is 'iiop:' token in the URL, this method will parses * and validates that host and port information. */ private IIOPEndpointInfo handleIIOPColon( String iiopInfo ) { // Check the iiop syntax iiopInfo = iiopInfo.substring( NamingConstants.IIOP_LENGTH ); return handleColon( iiopInfo ); } /** * This is to handle the case of host information with no 'iiop:' prefix. * instead if ':' is specified then iiop is assumed. */ private IIOPEndpointInfo handleColon( String iiopInfo ) { // String after ":" iiopInfo = iiopInfo.substring( 1 ); String hostandport = iiopInfo; // The format can be 1.2@<host>: Other Java examples (source code examples)Here is a short list of links related to this Java CorbalocURL.java source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.