idx
int64
0
41.2k
question
stringlengths
74
4.21k
target
stringlengths
5
888
34,000
public void deleteProperty ( String name ) { String [ ] propName = parsePropertyName ( name ) ; Element element = doc . getRootElement ( ) ; for ( int i = 0 ; i < propName . length - 1 ; i ++ ) { element = element . getChild ( propName [ i ] ) ; if ( element == null ) { return ; } } element . removeChild ( propName [ propName . length - 1 ] ) ; }
Deletes the specified property .
34,001
private String [ ] parsePropertyName ( String name ) { int size = 1 ; for ( int i = 0 ; i < name . length ( ) ; i ++ ) { if ( name . charAt ( i ) == '.' ) { size ++ ; } } String [ ] propName = new String [ size ] ; StringTokenizer tokenizer = new StringTokenizer ( name , "." ) ; int i = 0 ; while ( tokenizer . hasMoreTokens ( ) ) { propName [ i ] = tokenizer . nextToken ( ) ; i ++ ; } return propName ; }
Returns an array representation of the given Jive property . Jive properties are always in the format prop . name . is . this which would be represented as an array of four Strings .
34,002
public static boolean isWhitespace ( String s ) { if ( isEmpty ( s ) ) return true ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { char c = s . charAt ( i ) ; if ( whitespace . indexOf ( c ) == - 1 ) return false ; } return true ; }
Returns true if string s is empty or whitespace characters only .
34,003
public static String stripCharsInBag ( String s , String bag ) { int i ; String returnString = "" ; for ( i = 0 ; i < s . length ( ) ; i ++ ) { char c = s . charAt ( i ) ; if ( bag . indexOf ( c ) == - 1 ) returnString += c ; } return returnString ; }
Removes all characters which appear in string bag from string s .
34,004
public static boolean isInteger ( String s ) { if ( isEmpty ( s ) ) return defaultEmptyOK ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { char c = s . charAt ( i ) ; if ( ! isDigit ( c ) ) return false ; } return true ; }
Returns true if all characters in string s are numbers .
34,005
public static boolean isNonnegativeInteger ( String s ) { if ( isEmpty ( s ) ) return defaultEmptyOK ; try { int temp = Integer . parseInt ( s ) ; if ( temp >= 0 ) return true ; return false ; } catch ( Exception e ) { return false ; } }
Returns true if string s is an integer > = 0 .
34,006
public static boolean isAlphabetic ( String s ) { if ( isEmpty ( s ) ) return defaultEmptyOK ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { char c = s . charAt ( i ) ; if ( ! isLetter ( c ) ) return false ; } return true ; }
Returns true if string s is letters only .
34,007
public static boolean isSSN ( String s ) { if ( isEmpty ( s ) ) return defaultEmptyOK ; String normalizedSSN = stripCharsInBag ( s , SSNDelimiters ) ; return ( isInteger ( normalizedSSN ) && normalizedSSN . length ( ) == digitsInSocialSecurityNumber ) ; }
isSSN returns true if string s is a valid U . S . Social Security Number . Must be 9 digits .
34,008
public static boolean isUSPhoneNumber ( String s ) { if ( isEmpty ( s ) ) return defaultEmptyOK ; String normalizedPhone = stripCharsInBag ( s , phoneNumberDelimiters ) ; return ( isInteger ( normalizedPhone ) && normalizedPhone . length ( ) == digitsInUSPhoneNumber ) ; }
isUSPhoneNumber returns true if string s is a valid U . S . Phone Number . Must be 10 digits .
34,009
public static boolean isUSPhoneAreaCode ( String s ) { if ( isEmpty ( s ) ) return defaultEmptyOK ; String normalizedPhone = stripCharsInBag ( s , phoneNumberDelimiters ) ; return ( isInteger ( normalizedPhone ) && normalizedPhone . length ( ) == digitsInUSPhoneAreaCode ) ; }
isUSPhoneAreaCode returns true if string s is a valid U . S . Phone Area Code . Must be 3 digits .
34,010
public static boolean isUSPhoneMainNumber ( String s ) { if ( isEmpty ( s ) ) return defaultEmptyOK ; String normalizedPhone = stripCharsInBag ( s , phoneNumberDelimiters ) ; return ( isInteger ( normalizedPhone ) && normalizedPhone . length ( ) == digitsInUSPhoneMainNumber ) ; }
isUSPhoneMainNumber returns true if string s is a valid U . S . Phone Main Number . Must be 7 digits .
34,011
public static boolean isInternationalPhoneNumber ( String s ) { if ( isEmpty ( s ) ) return defaultEmptyOK ; String normalizedPhone = stripCharsInBag ( s , phoneNumberDelimiters ) ; return isPositiveInteger ( normalizedPhone ) ; }
isInternationalPhoneNumber returns true if string s is a valid international phone number . Must be digits only ; any length OK . May be prefixed by + character .
34,012
public static boolean isZipCode ( String s ) { if ( isEmpty ( s ) ) return defaultEmptyOK ; String normalizedZip = stripCharsInBag ( s , ZipCodeDelimiters ) ; return ( isInteger ( normalizedZip ) && ( ( normalizedZip . length ( ) == digitsInZipCode1 ) || ( normalizedZip . length ( ) == digitsInZipCode2 ) ) ) ; }
isZIPCode returns true if string s is a valid U . S . ZIP code . Must be 5 or 9 digits only .
34,013
public static boolean isContiguousZipCode ( String s ) { boolean retval = false ; if ( isZipCode ( s ) ) { if ( isEmpty ( s ) ) retval = defaultEmptyOK ; else { String normalizedZip = s . substring ( 0 , 5 ) ; int iZip = Integer . parseInt ( normalizedZip ) ; if ( ( iZip >= 96701 && iZip <= 96898 ) || ( iZip >= 99501 && iZip <= 99950 ) ) retval = false ; else retval = true ; } } return retval ; }
Returns true if string s is a valid contiguous U . S . Zip code . Must be 5 or 9 digits only .
34,014
public static boolean isEmail ( String s ) { if ( isEmpty ( s ) ) return defaultEmptyOK ; if ( isWhitespace ( s ) ) return false ; int i = 1 ; int sLength = s . length ( ) ; while ( ( i < sLength ) && ( s . charAt ( i ) != '@' ) ) i ++ ; if ( ( i >= sLength - 1 ) || ( s . charAt ( i ) != '@' ) ) return false ; else return true ; }
Email address must be of form a
34,015
public static boolean isYear ( String s ) { if ( isEmpty ( s ) ) return defaultEmptyOK ; if ( ! isNonnegativeInteger ( s ) ) return false ; return ( ( s . length ( ) == 2 ) || ( s . length ( ) == 4 ) ) ; }
isYear returns true if string s is a valid Year number . Must be 2 or 4 digits only .
34,016
public static boolean isIntegerInRange ( String s , int a , int b ) { if ( isEmpty ( s ) ) return defaultEmptyOK ; if ( ! isSignedInteger ( s ) ) return false ; int num = Integer . parseInt ( s ) ; return ( ( num >= a ) && ( num <= b ) ) ; }
isIntegerInRange returns true if string s is an integer within the range of integer arguments a and b inclusive .
34,017
public static boolean isDate ( String year , String month , String day ) { if ( ! ( isYear ( year ) && isMonth ( month ) && isDay ( day ) ) ) return false ; int intYear = Integer . parseInt ( year ) ; int intMonth = Integer . parseInt ( month ) ; int intDay = Integer . parseInt ( day ) ; if ( intDay > daysInMonth [ intMonth - 1 ] ) return false ; if ( ( intMonth == 2 ) && ( intDay > daysInFebruary ( intYear ) ) ) return false ; return true ; }
isDate returns true if string arguments year month and day form a valid date .
34,018
public static boolean isDate ( String date ) { if ( isEmpty ( date ) ) return defaultEmptyOK ; String month ; String day ; String year ; int dateSlash1 = date . indexOf ( "/" ) ; int dateSlash2 = date . lastIndexOf ( "/" ) ; if ( dateSlash1 <= 0 || dateSlash1 == dateSlash2 ) return false ; month = date . substring ( 0 , dateSlash1 ) ; day = date . substring ( dateSlash1 + 1 , dateSlash2 ) ; year = date . substring ( dateSlash2 + 1 ) ; return isDate ( year , month , day ) ; }
isDate returns true if string argument date forms a valid date .
34,019
public static boolean isDateAfterToday ( String date ) { if ( isEmpty ( date ) ) return defaultEmptyOK ; int dateSlash1 = date . indexOf ( "/" ) ; int dateSlash2 = date . lastIndexOf ( "/" ) ; if ( dateSlash1 <= 0 ) return false ; java . util . Date passed = null ; if ( dateSlash1 == dateSlash2 ) { String month = date . substring ( 0 , dateSlash1 ) ; String day = "28" ; String year = date . substring ( dateSlash1 + 1 ) ; if ( ! isDate ( year , month , day ) ) return false ; try { int monthInt = Integer . parseInt ( month ) ; int yearInt = Integer . parseInt ( year ) ; Calendar calendar = Calendar . getInstance ( ) ; calendar . set ( yearInt , monthInt - 1 , 0 , 0 , 0 , 0 ) ; calendar . add ( Calendar . MONTH , 1 ) ; passed = new java . util . Date ( calendar . getTime ( ) . getTime ( ) ) ; } catch ( Exception e ) { passed = null ; } } else { String month = date . substring ( 0 , dateSlash1 ) ; String day = date . substring ( dateSlash1 + 1 , dateSlash2 ) ; String year = date . substring ( dateSlash2 + 1 ) ; if ( ! isDate ( year , month , day ) ) return false ; passed = UtilDateTime . toDate ( month , day , year , "0" , "0" , "0" ) ; } java . util . Date now = UtilDateTime . nowDate ( ) ; if ( passed != null ) { return passed . after ( now ) ; } else { return false ; } }
isDate returns true if string argument date forms a valid date and is after today .
34,020
public static boolean isTime ( String hour , String minute , String second ) { if ( isHour ( hour ) && isMinute ( minute ) && isSecond ( second ) ) return true ; else return false ; }
isTime returns true if string arguments hour minute and second form a valid time .
34,021
public static boolean isTime ( String time ) { if ( isEmpty ( time ) ) return defaultEmptyOK ; String hour ; String minute ; String second ; int timeColon1 = time . indexOf ( ":" ) ; int timeColon2 = time . lastIndexOf ( ":" ) ; if ( timeColon1 <= 0 ) return false ; hour = time . substring ( 0 , timeColon1 ) ; if ( timeColon1 == timeColon2 ) { minute = time . substring ( timeColon1 + 1 ) ; second = "0" ; } else { minute = time . substring ( timeColon1 + 1 , timeColon2 ) ; second = time . substring ( timeColon2 + 1 ) ; } return isTime ( hour , minute , second ) ; }
isTime returns true if string argument time forms a valid time .
34,022
public static boolean isCreditCard ( String stPassed ) { if ( isEmpty ( stPassed ) ) return defaultEmptyOK ; String st = stripCharsInBag ( stPassed , creditCardDelimiters ) ; int sum = 0 ; int mul = 1 ; int l = st . length ( ) ; if ( l > 19 ) return ( false ) ; for ( int i = 0 ; i < l ; i ++ ) { String digit = st . substring ( l - i - 1 , l - i ) ; int tproduct = 0 ; try { tproduct = Integer . parseInt ( digit , 10 ) * mul ; } catch ( Exception e ) { Debug . logWarning ( e . getMessage ( ) ) ; return false ; } if ( tproduct >= 10 ) sum += ( tproduct % 10 ) + 1 ; else sum += tproduct ; if ( mul == 1 ) mul ++ ; else mul -- ; } if ( ( sum % 10 ) == 0 ) return true ; else return false ; }
Checks credit card number with Luhn Mod - 10 test
34,023
public static boolean isVisa ( String cc ) { if ( ( ( cc . length ( ) == 16 ) || ( cc . length ( ) == 13 ) ) && ( cc . substring ( 0 , 1 ) . equals ( "4" ) ) ) return isCreditCard ( cc ) ; return false ; }
Checks to see if the cc number is a valid Visa number
34,024
public static boolean isMasterCard ( String cc ) { int firstdig = Integer . parseInt ( cc . substring ( 0 , 1 ) ) ; int seconddig = Integer . parseInt ( cc . substring ( 1 , 2 ) ) ; if ( ( cc . length ( ) == 16 ) && ( firstdig == 5 ) && ( ( seconddig >= 1 ) && ( seconddig <= 5 ) ) ) return isCreditCard ( cc ) ; return false ; }
Checks to see if the cc number is a valid Master Card number
34,025
public static boolean isDiscover ( String cc ) { String first4digs = cc . substring ( 0 , 4 ) ; if ( ( cc . length ( ) == 16 ) && ( first4digs . equals ( "6011" ) ) ) return isCreditCard ( cc ) ; return false ; }
Checks to see if the cc number is a valid Discover number
34,026
public static boolean isJCB ( String cc ) { String first4digs = cc . substring ( 0 , 4 ) ; if ( ( cc . length ( ) == 16 ) && ( first4digs . equals ( "3088" ) || first4digs . equals ( "3096" ) || first4digs . equals ( "3112" ) || first4digs . equals ( "3158" ) || first4digs . equals ( "3337" ) || first4digs . equals ( "3528" ) ) ) return isCreditCard ( cc ) ; return false ; }
Checks to see if the cc number is a valid JCB number
34,027
public static boolean isAnyCard ( String ccPassed ) { if ( isEmpty ( ccPassed ) ) return defaultEmptyOK ; String cc = stripCharsInBag ( ccPassed , creditCardDelimiters ) ; if ( ! isCreditCard ( cc ) ) return false ; if ( isMasterCard ( cc ) || isVisa ( cc ) || isAmericanExpress ( cc ) || isDinersClub ( cc ) || isDiscover ( cc ) || isEnRoute ( cc ) || isJCB ( cc ) ) return true ; return false ; }
Checks to see if the cc number is a valid number for any accepted credit card
34,028
public static String getCardType ( String ccPassed ) { if ( isEmpty ( ccPassed ) ) return "Unknown" ; String cc = stripCharsInBag ( ccPassed , creditCardDelimiters ) ; if ( ! isCreditCard ( cc ) ) return "Unknown" ; if ( isMasterCard ( cc ) ) return "MasterCard" ; if ( isVisa ( cc ) ) return "Visa" ; if ( isAmericanExpress ( cc ) ) return "AmericanExpress" ; if ( isDinersClub ( cc ) ) return "DinersClub" ; if ( isDiscover ( cc ) ) return "Discover" ; if ( isEnRoute ( cc ) ) return "EnRoute" ; if ( isJCB ( cc ) ) return "JCB" ; return "Unknown" ; }
Checks to see if the cc number is a valid number for any accepted credit card and return the name of that type
34,029
public static boolean isCardMatch ( String cardType , String cardNumberPassed ) { if ( isEmpty ( cardType ) ) return defaultEmptyOK ; if ( isEmpty ( cardNumberPassed ) ) return defaultEmptyOK ; String cardNumber = stripCharsInBag ( cardNumberPassed , creditCardDelimiters ) ; if ( ( cardType . equalsIgnoreCase ( "VISA" ) ) && ( isVisa ( cardNumber ) ) ) return true ; if ( ( cardType . equalsIgnoreCase ( "MASTERCARD" ) ) && ( isMasterCard ( cardNumber ) ) ) return true ; if ( ( ( cardType . equalsIgnoreCase ( "AMERICANEXPRESS" ) ) || ( cardType . equalsIgnoreCase ( "AMEX" ) ) ) && ( isAmericanExpress ( cardNumber ) ) ) return true ; if ( ( cardType . equalsIgnoreCase ( "DISCOVER" ) ) && ( isDiscover ( cardNumber ) ) ) return true ; if ( ( cardType . equalsIgnoreCase ( "JCB" ) ) && ( isJCB ( cardNumber ) ) ) return true ; if ( ( ( cardType . equalsIgnoreCase ( "DINERSCLUB" ) ) || ( cardType . equalsIgnoreCase ( "DINERS" ) ) ) && ( isDinersClub ( cardNumber ) ) ) return true ; if ( ( cardType . equalsIgnoreCase ( "CARTEBLANCHE" ) ) && ( isCarteBlanche ( cardNumber ) ) ) return true ; if ( ( cardType . equalsIgnoreCase ( "ENROUTE" ) ) && ( isEnRoute ( cardNumber ) ) ) return true ; return false ; }
Checks to see if the cc number is a valid number for the specified type
34,030
public static boolean isNotPoBox ( String s ) { if ( isEmpty ( s ) ) return defaultEmptyOK ; String sl = s . toLowerCase ( ) ; if ( sl . indexOf ( "p.o. b" ) != - 1 ) return false ; if ( sl . indexOf ( "p.o.b" ) != - 1 ) return false ; if ( sl . indexOf ( "p.o b" ) != - 1 ) return false ; if ( sl . indexOf ( "p o b" ) != - 1 ) return false ; if ( sl . indexOf ( "po b" ) != - 1 ) return false ; if ( sl . indexOf ( "pobox" ) != - 1 ) return false ; if ( sl . indexOf ( "po#" ) != - 1 ) return false ; if ( sl . indexOf ( "po #" ) != - 1 ) return false ; if ( sl . indexOf ( "p.0. b" ) != - 1 ) return false ; if ( sl . indexOf ( "p.0.b" ) != - 1 ) return false ; if ( sl . indexOf ( "p.0 b" ) != - 1 ) return false ; if ( sl . indexOf ( "p 0 b" ) != - 1 ) return false ; if ( sl . indexOf ( "p0 b" ) != - 1 ) return false ; if ( sl . indexOf ( "p0box" ) != - 1 ) return false ; if ( sl . indexOf ( "p0#" ) != - 1 ) return false ; if ( sl . indexOf ( "p0 #" ) != - 1 ) return false ; return true ; }
isNotPoBox returns true if address argument does not contain anything that looks like a a PO Box .
34,031
public void process ( final String beanName , final HttpServletRequest request , final HttpServletResponse response ) throws ServletException , IOException { InputStream is = request . getInputStream ( ) ; OutputStream os = response . getOutputStream ( ) ; Hessian2Input in = new Hessian2Input ( is ) ; AbstractHessianOutput out ; SerializerFactory serializerFactory = new SerializerFactory ( ) ; serializerFactory . setAllowNonSerializable ( true ) ; serializerFactory . addFactory ( new JdonSerializerFactory ( ) ) ; in . setSerializerFactory ( serializerFactory ) ; int code = in . read ( ) ; if ( code != 'c' ) { throw new IOException ( "expected 'c' in hessian input at " + code ) ; } int major = in . read ( ) ; in . read ( ) ; if ( major >= HESSIAN_PROTOCOL_MAJOR_VERSION ) { out = new Hessian2Output ( os ) ; } else { out = new HessianOutput ( os ) ; } out . setSerializerFactory ( serializerFactory ) ; in . skipOptionalCall ( ) ; out . startReply ( ) ; readHeaders ( in ) ; try { out . writeObject ( makeCall ( in , beanName , request ) ) ; } catch ( Exception e ) { writeException ( out , e ) ; } in . completeCall ( ) ; out . completeReply ( ) ; out . close ( ) ; }
Process servlet requests and writes bean s method result to output
34,032
public Map readHeaders ( Hessian2Input hessian2Input ) throws IOException { Map headers = new HashMap ( ) ; String header = hessian2Input . readHeader ( ) ; while ( header != null ) { headers . put ( header , hessian2Input . readObject ( ) ) ; header = hessian2Input . readHeader ( ) ; } return headers ; }
Reads headers from call .
34,033
protected void writeException ( final AbstractHessianOutput out , Exception ex ) throws IOException { OutputStream os = new ByteArrayOutputStream ( ) ; ex . printStackTrace ( new PrintStream ( os ) ) ; out . writeFault ( ex . getClass ( ) . toString ( ) , os . toString ( ) , null ) ; }
Writes Exception information to Hessian Output .
34,034
public Object getComponentNewInstance ( String name ) { Debug . logVerbose ( "[JdonFramework]getComponentNewInstance: name=" + name , module ) ; ComponentAdapter componentAdapter = container . getComponentAdapter ( name ) ; if ( componentAdapter == null ) { Debug . logWarning ( "[JdonFramework]Not find the component in container :" + name , module ) ; return null ; } return componentAdapter . getComponentInstance ( container ) ; }
This method will usually create a new instance each time it is called
34,035
public ModelHandler borrowtHandlerObject ( String formName ) { ModelHandler modelHandler = null ; try { modelHandler = handlerObjectFactory . borrowHandlerObject ( formName ) ; modelHandler . setModelMapping ( modelFactory . getModelMapping ( formName ) ) ; } catch ( Exception ex ) { Debug . logError ( "[JdonFramework]can't get the modelHandler for the formName " + formName , module ) ; returnHandlerObject ( modelHandler ) ; } return modelHandler ; }
borrow a Handler instance from Modelhandler pool
34,036
public void returnHandlerObject ( ModelHandler modelHandler ) { if ( modelHandler == null ) return ; try { handlerObjectFactory . returnHandlerObject ( modelHandler ) ; } catch ( Exception ex ) { Debug . logError ( "[JdonFramework] return modelHandler error" + ex , module ) ; } }
return the Handler instance .
34,037
private Object makeModelObject ( String formName ) { Object object = null ; Class modelClass = null ; try { modelClass = ( Class ) modelFactory . getModelClasses ( formName ) ; if ( modelClass == null ) { throw new Exception ( " not found the model in config xml, formName=" + formName ) ; } object = modelClass . newInstance ( ) ; modelProxyInjection . injectProperties ( object ) ; } catch ( Exception e ) { Debug . logError ( "[JdonFramework] + modelClass + " error:" + e , module ) ; } return object ; }
create model instance from the model class that read from the xml configure .
34,038
public boolean hasNext ( ) { if ( currentIndex == endIndex ) { return false ; } if ( nextElement == null ) { nextElement = getNextElement ( ) ; if ( nextElement == null ) { return false ; } } return true ; }
Returns true if there are more elements in the iteration .
34,039
public Object next ( ) throws java . util . NoSuchElementException { Object element = null ; if ( nextElement != null ) { element = nextElement ; nextElement = null ; } else { element = getNextElement ( ) ; if ( element == null ) { throw new java . util . NoSuchElementException ( ) ; } } return element ; }
Returns the next element of primary key collection .
34,040
public boolean hasPrevious ( ) { if ( currentIndex == startIndex ) { return false ; } if ( previousElement == null ) { previousElement = getPreviousElement ( ) ; if ( previousElement == null ) { return false ; } } return true ; }
Returns true if there are previous elements in the iteration .
34,041
private Object getPreviousElement ( ) { Object element = null ; while ( currentIndex >= startIndex && element == null ) { currentIndex -- ; element = getElement ( ) ; } return element ; }
Returns the previous element or null if there are no more elements to return .
34,042
public Object getNextElement ( ) { Object element = null ; while ( currentIndex + 1 < endIndex && element == null ) { currentIndex ++ ; element = getElement ( ) ; } return element ; }
Returns the next available element of primary key collection or null if there are no more elements to return .
34,043
protected void emitWhitespace ( ) throws SAXException { char [ ] data = new char [ whitespace . length ( ) ] ; whitespace . getChars ( 0 , data . length , data , 0 ) ; whitespace . setLength ( 0 ) ; super . characters ( data , 0 , data . length ) ; }
Passes saved whitespace down the filter chain .
34,044
public String getKey ( ) { StringBuilder buffer = new StringBuilder ( cacheType ) ; buffer . append ( dataTypeName ) ; if ( dataKey != null ) buffer . append ( dataKey . toString ( ) ) ; return buffer . toString ( ) . intern ( ) ; }
cacheType + dataTypeName + dataKey
34,045
public void startElement ( String uri , String localName ) throws SAXException { startElement ( uri , localName , "" , EMPTY_ATTS ) ; }
Start a new element without a qname or attributes .
34,046
public void emptyElement ( String uri , String localName , String qName , Attributes atts ) throws SAXException { startElement ( uri , localName , qName , atts ) ; endElement ( uri , localName , qName ) ; }
Add an empty element .
34,047
public void emptyElement ( String uri , String localName ) throws SAXException { emptyElement ( uri , localName , "" , EMPTY_ATTS ) ; }
Add an empty element without a qname or attributes .
34,048
public void dataElement ( String uri , String localName , String qName , Attributes atts , String content ) throws SAXException { startElement ( uri , localName , qName , atts ) ; characters ( content ) ; endElement ( uri , localName , qName ) ; }
Add an element with character data content .
34,049
public void dataElement ( String uri , String localName , String content ) throws SAXException { dataElement ( uri , localName , "" , EMPTY_ATTS , content ) ; }
Add an element with character data content but no qname or attributes .
34,050
public void dataElement ( String localName , Attributes atts , String content ) throws SAXException { dataElement ( "" , localName , "" , atts , content ) ; }
Add an element with character data content but no Namespace URI or qname .
34,051
public void characters ( String data ) throws SAXException { char ch [ ] = data . toCharArray ( ) ; characters ( ch , 0 , ch . length ) ; }
Add a string of character data with XML escaping .
34,052
private void installLexicalHandler ( ) { XMLReader parent = getParent ( ) ; if ( parent == null ) { throw new NullPointerException ( "No parent for filter" ) ; } for ( int i = 0 ; i < LEXICAL_HANDLER_NAMES . length ; i ++ ) { try { parent . setProperty ( LEXICAL_HANDLER_NAMES [ i ] , this ) ; break ; } catch ( SAXNotRecognizedException ex ) { } catch ( SAXNotSupportedException ex ) { } } }
Installs lexical handler before a parse .
34,053
public synchronized ContainerRegistryBuilder createContainerBuilder ( AppContextWrapper context ) { containerLoaderAnnotation . startScan ( context ) ; ContainerFactory containerFactory = new ContainerFactory ( ) ; ContainerWrapper cw = containerFactory . create ( containerLoaderAnnotation . getConfigInfo ( ) ) ; ContainerComponents configComponents = containerLoaderXML . loadAllContainerConfig ( context ) ; ContainerComponents aspectConfigComponents = containerLoaderXML . loadAllAspectConfig ( context ) ; return createContainerBuilder ( context , cw , configComponents , aspectConfigComponents ) ; }
the main method in this class read all components include interceptors from Xml configure file .
34,054
private static Class < ? > getHibernateClass ( ) { Class < ? > cl = null ; try { cl = Class . forName ( HIBERNATE_CLASS ) ; } catch ( ClassNotFoundException e ) { } return cl ; }
Return Hibernate class instance
34,055
private static Method getInitializeMethod ( Class < ? > cl ) { Method method = null ; try { method = cl . getDeclaredMethod ( IS_INITIALIZED , new Class [ ] { Object . class } ) ; } catch ( NoSuchMethodException e ) { } return method ; }
Return isInitialized Hibernate static method
34,056
private static boolean checkInitialize ( Method method , Object obj ) { boolean isInitialized = true ; try { isInitialized = ( Boolean ) method . invoke ( null , new Object [ ] { obj } ) ; } catch ( IllegalArgumentException e ) { } catch ( IllegalAccessException e ) { } catch ( InvocationTargetException e ) { } return isInitialized ; }
Check is current property was initialized
34,057
public static boolean isPropertyInitialized ( Object object ) { Class < ? > cl = getHibernateClass ( ) ; if ( cl == null ) { return true ; } Method method = getInitializeMethod ( cl ) ; return checkInitialize ( method , object ) ; }
Check is current object was initialized
34,058
public void registerAppRoot ( String configureFileName ) throws Exception { try { AppConfigureCollection existedAppConfigureFiles = ( AppConfigureCollection ) containerWrapper . lookup ( AppConfigureCollection . NAME ) ; if ( existedAppConfigureFiles == null ) { xmlcontainerRegistry . registerAppRoot ( ) ; existedAppConfigureFiles = ( AppConfigureCollection ) containerWrapper . lookup ( AppConfigureCollection . NAME ) ; } if ( ! existedAppConfigureFiles . getConfigList ( ) . contains ( configureFileName ) ) { Debug . logInfo ( "[JdonFramework]found jdonframework configuration:" + configureFileName , module ) ; existedAppConfigureFiles . addConfigList ( configureFileName ) ; } } catch ( Exception ex ) { Debug . logError ( "[JdonFramework] found jdonframework configuration error:" + ex , module ) ; throw new Exception ( ex ) ; } }
if there are xml configure then add new ones ; if not register it ;
34,059
public void registerComponents ( ) throws Exception { Debug . logVerbose ( "[JdonFramework] note: registe all basic components in container.xml size=" + basicComponents . size ( ) , module ) ; try { Iterator iter = basicComponents . iterator ( ) ; while ( iter . hasNext ( ) ) { String name = ( String ) iter . next ( ) ; ComponentMetaDef componentMetaDef = basicComponents . getComponentMetaDef ( name ) ; xmlcontainerRegistry . registerComponentMetaDef ( componentMetaDef ) ; } } catch ( Exception ex ) { Debug . logError ( "[JdonFramework] register basiceComponents error:" + ex , module ) ; throw new Exception ( ex ) ; } }
register all basic components in container . xml
34,060
public void registerAspectComponents ( ) throws Exception { Debug . logVerbose ( "[JdonFramework] note: registe aspect components " , module ) ; try { InterceptorsChain existedInterceptorsChain = ( InterceptorsChain ) containerWrapper . lookup ( ComponentKeys . INTERCEPTOR_CHAIN ) ; Iterator iter = aspectConfigComponents . iterator ( ) ; Debug . logVerbose ( "[JdonFramework] 3 aspectConfigComponents size:" + aspectConfigComponents . size ( ) , module ) ; while ( iter . hasNext ( ) ) { String name = ( String ) iter . next ( ) ; AspectComponentsMetaDef componentMetaDef = ( AspectComponentsMetaDef ) aspectConfigComponents . getComponentMetaDef ( name ) ; xmlcontainerRegistry . registerAspectComponentMetaDef ( componentMetaDef ) ; existedInterceptorsChain . addInterceptor ( componentMetaDef . getPointcut ( ) , name ) ; } } catch ( Exception ex ) { Debug . logError ( "[JdonFramework] registerAspectComponents error:" + ex , module ) ; throw new Exception ( ex ) ; } }
register all apsect components in aspect . xml
34,061
public static void createFile ( String output , String content ) throws Exception { OutputStreamWriter fw = null ; PrintWriter out = null ; try { if ( ENCODING == null ) ENCODING = PropsUtil . ENCODING ; fw = new OutputStreamWriter ( new FileOutputStream ( output ) , ENCODING ) ; out = new PrintWriter ( fw ) ; out . print ( content ) ; } catch ( Exception ex ) { throw new Exception ( ex ) ; } finally { if ( out != null ) out . close ( ) ; if ( fw != null ) fw . close ( ) ; } }
write the content to a file ;
34,062
public static String readFile ( String input ) throws Exception { char [ ] buffer = new char [ 4096 ] ; int len = 0 ; StringBuilder content = new StringBuilder ( 4096 ) ; if ( ENCODING == null ) ENCODING = PropsUtil . ENCODING ; InputStreamReader fr = null ; BufferedReader br = null ; try { fr = new InputStreamReader ( new FileInputStream ( input ) , ENCODING ) ; br = new BufferedReader ( fr ) ; while ( ( len = br . read ( buffer ) ) > - 1 ) { content . append ( buffer , 0 , len ) ; } } catch ( Exception e ) { throw new Exception ( e ) ; } finally { if ( br != null ) br . close ( ) ; if ( fr != null ) fr . close ( ) ; } return content . toString ( ) ; }
read the content from a file ;
34,063
public static void move ( String input , String output ) throws Exception { File inputFile = new File ( input ) ; File outputFile = new File ( output ) ; try { inputFile . renameTo ( outputFile ) ; } catch ( Exception ex ) { throw new Exception ( "Can not mv" + input + " to " + output + ex . getMessage ( ) ) ; } }
This class moves an input file to output file
34,064
public static boolean copy ( String input , String output ) throws Exception { int BUFSIZE = 65536 ; FileInputStream fis = new FileInputStream ( input ) ; FileOutputStream fos = new FileOutputStream ( output ) ; try { int s ; byte [ ] buf = new byte [ BUFSIZE ] ; while ( ( s = fis . read ( buf ) ) > - 1 ) { fos . write ( buf , 0 , s ) ; } } catch ( Exception ex ) { throw new Exception ( "makehome" + ex . getMessage ( ) ) ; } finally { fis . close ( ) ; fos . close ( ) ; } return true ; }
This class copies an input file to output file
34,065
public static void CopyDir ( String sourcedir , String destdir ) throws Exception { File dest = new File ( destdir ) ; File source = new File ( sourcedir ) ; String [ ] files = source . list ( ) ; try { makehome ( destdir ) ; } catch ( Exception ex ) { throw new Exception ( "CopyDir:" + ex . getMessage ( ) ) ; } for ( int i = 0 ; i < files . length ; i ++ ) { String sourcefile = source + File . separator + files [ i ] ; String destfile = dest + File . separator + files [ i ] ; File temp = new File ( sourcefile ) ; if ( temp . isFile ( ) ) { try { copy ( sourcefile , destfile ) ; } catch ( Exception ex ) { throw new Exception ( "CopyDir:" + ex . getMessage ( ) ) ; } } } }
This class copies an input files of a directory to another directory not include subdir
34,066
public static void recursiveRemoveDir ( File directory ) throws Exception { if ( ! directory . exists ( ) ) throw new IOException ( directory . toString ( ) + " do not exist!" ) ; String [ ] filelist = directory . list ( ) ; File tmpFile = null ; for ( int i = 0 ; i < filelist . length ; i ++ ) { tmpFile = new File ( directory . getAbsolutePath ( ) , filelist [ i ] ) ; if ( tmpFile . isDirectory ( ) ) { recursiveRemoveDir ( tmpFile ) ; } else if ( tmpFile . isFile ( ) ) { try { tmpFile . delete ( ) ; } catch ( Exception ex ) { throw new Exception ( tmpFile . toString ( ) + " can not be deleted " + ex . getMessage ( ) ) ; } } } try { directory . delete ( ) ; } catch ( Exception ex ) { throw new Exception ( directory . toString ( ) + " can not be deleted " + ex . getMessage ( ) ) ; } finally { filelist = null ; } }
This class del a directory recursively that means delete all files and directorys .
34,067
public void createTargetMetaRequest ( TargetMetaDef targetMetaDef , ContextHolder holder ) { ContainerWrapper containerWrapper = servletContainerFinder . findContainer ( holder . getAppContextHolder ( ) ) ; VisitorFactory visitorFactory = ( VisitorFactory ) containerWrapper . lookup ( ComponentKeys . VISITOR_FACTORY ) ; ComponentVisitor cm = visitorFactory . createtVisitor ( holder . getSessionHolder ( ) , targetMetaDef ) ; TargetMetaRequest targetMetaRequest = new TargetMetaRequest ( targetMetaDef , cm ) ; targetMetaRequestsHolder . setTargetMetaRequest ( targetMetaRequest ) ; }
create a targetMetaRequest instance .
34,068
public Object getEventResult ( ) { Object result = eventResultCache . get ( ) ; if ( result != null ) { return result ; } if ( eventResultHandler != null ) { result = eventResultHandler . get ( ) ; if ( result != null ) { if ( ! eventResultCache . compareAndSet ( null , result ) ) { result = eventResultCache . get ( ) ; } } } return result ; }
get a Event Result until time out value
34,069
public Object visit ( ) { Object o = null ; try { ContainerWrapper containerWrapper = containerCallback . getContainerWrapper ( ) ; TargetMetaRequest targetMetaRequest = targetMetaRequestsHolder . getTargetMetaRequest ( ) ; Debug . logVerbose ( "[JdonFramework] ComponentOriginalVisitor active:" + targetMetaRequest . getVisitableName ( ) , module ) ; Visitable vo = ( Visitable ) containerWrapper . lookup ( targetMetaRequest . getVisitableName ( ) ) ; o = vo . accept ( ) ; } catch ( Exception ex ) { Debug . logError ( "[JdonFramework] ComponentOriginalVisitor active error: " + ex ) ; } return o ; }
find the visitable component from container and execute it s accept method the return result is the tager service object .
34,070
public MethodMetaArgs createinitMethod ( HandlerMetaDef handlerMetaDef , EventModel em ) { String p_methodName = handlerMetaDef . getInitMethod ( ) ; if ( p_methodName == null ) return null ; return createCRUDMethodMetaArgs ( p_methodName , em ) ; }
create init method
34,071
public MethodMetaArgs createGetMethod ( HandlerMetaDef handlerMetaDef , Object keyValue ) { String p_methodName = handlerMetaDef . getFindMethod ( ) ; if ( p_methodName == null ) { Debug . logError ( "[JdonFramework] not configure the findMethod parameter: <getMethod name=XXXXX /> " , module ) ; } if ( keyValue == null ) { Debug . logError ( "[JdonFramework] not found model's key value:" + handlerMetaDef . getModelMapping ( ) . getKeyName ( ) + "=? in request parameters" , module ) ; } return createCRUDMethodMetaArgs ( p_methodName , keyValue ) ; }
create find method the service s find method parameter type must be String type
34,072
private void setSessionContext ( Object targetObject , TargetMetaRequest targetMetaRequest ) { if ( isSessionContextAcceptables . contains ( targetMetaRequest . getTargetMetaDef ( ) . getName ( ) ) ) { SessionContextAcceptable myResult = ( SessionContextAcceptable ) targetObject ; SessionContext sessionContext = targetMetaRequest . getSessionContext ( ) ; myResult . setSessionContext ( sessionContext ) ; } else if ( isSessionContextAcceptablesAnnotations . containsKey ( targetMetaRequest . getTargetMetaDef ( ) . getName ( ) ) ) { Method method = isSessionContextAcceptablesAnnotations . get ( targetMetaRequest . getTargetMetaDef ( ) . getName ( ) ) ; try { Object [ ] sessionContexts = new SessionContext [ 1 ] ; sessionContexts [ 0 ] = targetMetaRequest . getSessionContext ( ) ; method . invoke ( targetObject , sessionContexts ) ; } catch ( Exception e ) { Debug . logError ( "[JdonFramework]the target must has method setSessionContext(SessionContext sessionContext) : " + e , module ) ; } } }
WebServiceAccessorImp create sessionContext and save infomation into it
34,073
public Object invoke ( TargetMetaDef targetMetaDef , Method m , Object [ ] args ) throws Throwable { Object result = null ; getThreadLock ( ) ; int currentRequestNb = requestNb ++ ; Debug . logVerbose ( "[JdonFramework]Start remote call " + currentRequestNb + " " + m . getName ( ) , module ) ; HttpRequest request = new HttpRequest ( targetMetaDef , m . getName ( ) , m . getParameterTypes ( ) , args ) ; StringBuilder sb = new StringBuilder ( httpServerParam . getServletPath ( ) . toString ( ) ) ; if ( sessionId != null ) { sb . append ( ";jsessionid=" ) ; sb . append ( sessionId ) ; } httpServerParam . setServletPath ( sb . toString ( ) ) ; result = invokeHttp ( request , args ) ; Debug . logVerbose ( "[JdonFramework]Ending remote call " + currentRequestNb , module ) ; releaseThreadLock ( ) ; return result ; }
Invokes EJB service
34,074
public Object invokeHttp ( HttpRequest request , Object [ ] args ) throws Throwable { HttpResponse httpResponse ; try { HttpConnectionHelper httpConnectionHelper = new HttpConnectionHelper ( ) ; HttpURLConnection httpURLConnection ; if ( httpServerParam . isDebug ( ) ) { Debug . logVerbose ( "[JdonFramework]connect service.." , module ) ; httpURLConnection = httpConnectionHelper . connectService ( httpServerParam , null ) ; Debug . logVerbose ( "[JdonFramework]send request: class=" + request . getTargetMetaDef ( ) . getClassName ( ) , module ) ; Debug . logVerbose ( "[JdonFramework]method=" + request . getMethodName ( ) , module ) ; httpConnectionHelper . sendObjectRequest ( httpURLConnection , request ) ; } else { httpURLConnection = httpConnectionHelper . connectService ( httpServerParam , getUserPassword ( args ) ) ; httpConnectionHelper . sendObjectRequest ( httpURLConnection , request ) ; if ( httpURLConnection . getResponseCode ( ) == 401 ) { throw new AuthException ( " http Server authentication failed!" ) ; } } httpResponse = ( HttpResponse ) httpConnectionHelper . getObjectResponse ( httpURLConnection ) ; sessionId = httpURLConnection . getHeaderField ( "jsessionid" ) ; httpURLConnection . disconnect ( ) ; if ( httpResponse . isExceptionThrown ( ) ) throw httpResponse . getThrowable ( ) ; return httpResponse . getResult ( ) ; } catch ( ClassNotFoundException e ) { Debug . logError ( e , module ) ; throw new RemoteException ( " Class Not Found " , e ) ; } catch ( AuthException ae ) { throw new AuthException ( ae . getMessage ( ) ) ; } catch ( Exception e ) { String message = "invokeHttp error:" ; Debug . logError ( message + e , module ) ; throw new RemoteException ( message , e ) ; } }
Performs the http call .
34,075
private synchronized void getThreadLock ( ) { while ( sessionId == null && curUsedThread > 1 ) { try { Debug . logVerbose ( "No session. Only one thread is authorized. Waiting ..." , module ) ; wait ( ) ; } catch ( InterruptedException e ) { e . printStackTrace ( ) ; } } while ( curUsedThread >= maxThreadCount ) { try { Debug . logVerbose ( "[JdonFramework]Max concurent http call reached. Waiting ..." , module ) ; wait ( ) ; } catch ( InterruptedException e ) { e . printStackTrace ( ) ; } } curUsedThread ++ ; }
This method is used to limit the concurrent http call to the max fixed by maxThreadCount and to wait the end of the first call that will return the session id .
34,076
public Method createMethod ( TargetServiceFactory targetServiceFactory ) { Method method = null ; Debug . logVerbose ( "[JdonFramework] enter create the Method " , module ) ; try { TargetMetaRequest targetMetaRequest = targetMetaRequestsHolder . getTargetMetaRequest ( ) ; if ( targetMetaRequest . getTargetMetaDef ( ) . isEJB ( ) ) { Object obj = methodInvokerUtil . createTargetObject ( targetServiceFactory ) ; method = createObjectMethod ( obj , targetMetaRequest . getMethodMetaArgs ( ) ) ; } else { method = createPojoMethod ( ) ; } } catch ( Exception ex ) { Debug . logError ( "[JdonFramework] createMethod error: " + ex , module ) ; } return method ; }
ejb s method creating must at first get service s EJB Object ; pojo s method creating can only need service s class .
34,077
public Method createPojoMethod ( ) { Method method = null ; TargetMetaRequest targetMetaRequest = targetMetaRequestsHolder . getTargetMetaRequest ( ) ; TargetMetaDef targetMetaDef = targetMetaRequest . getTargetMetaDef ( ) ; MethodMetaArgs methodMetaArgs = targetMetaRequest . getMethodMetaArgs ( ) ; Debug . logVerbose ( "[JdonFramework] createPOJO Method :" + methodMetaArgs . getMethodName ( ) + " for target service: " + targetMetaDef . getName ( ) , module ) ; try { Class thisCLass = containerCallback . getContainerWrapper ( ) . getComponentClass ( targetMetaDef . getName ( ) ) ; if ( thisCLass == null ) return null ; method = thisCLass . getMethod ( methodMetaArgs . getMethodName ( ) , methodMetaArgs . getParamTypes ( ) ) ; } catch ( NoSuchMethodException ne ) { Debug . logError ( "[JdonFramework] method name:" + methodMetaArgs . getMethodName ( ) + " or method parameters type don't match with your service's method" , module ) ; Object types [ ] = methodMetaArgs . getParamTypes ( ) ; for ( int i = 0 ; i < types . length ; i ++ ) { Debug . logError ( "[JdonFramework]service's method parameter type must be:" + types [ i ] + "; " , module ) ; } } catch ( Exception ex ) { Debug . logError ( "[JdonFramework] createPojoMethod error: " + ex , module ) ; } return method ; }
create a method object by its meta definition
34,078
public Method createObjectMethod ( Object ownerClass , MethodMetaArgs methodMetaArgs ) { Method m = null ; try { m = ownerClass . getClass ( ) . getMethod ( methodMetaArgs . getMethodName ( ) , methodMetaArgs . getParamTypes ( ) ) ; } catch ( NoSuchMethodException nsme ) { String errS = " NoSuchMethod:" + methodMetaArgs . getMethodName ( ) + " in MethodMetaArgs of className:" + ownerClass . getClass ( ) . getName ( ) ; Debug . logError ( errS , module ) ; } catch ( Exception ex ) { Debug . logError ( "[JdonFramework] createMethod error:" + ex , module ) ; } return m ; }
create a method object by target Object
34,079
public Method createObjectMethod ( Object ownerClass , String methodName , Class [ ] paramTypes ) { Method m = null ; try { m = ownerClass . getClass ( ) . getMethod ( methodName , paramTypes ) ; } catch ( NoSuchMethodException nsme ) { String errS = " NoSuchMethod:" + methodName + " in className:" + ownerClass . getClass ( ) . getName ( ) + " or method's args type error" ; Debug . logError ( errS , module ) ; } catch ( Exception ex ) { Debug . logError ( "[JdonFramework] createMethod error:" + ex , module ) ; } return m ; }
create a method object
34,080
public InputStream getConfPathXmlStream ( String filePathName ) { int i = filePathName . lastIndexOf ( ".xml" ) ; String name = filePathName . substring ( 0 , i ) ; name = name . replace ( '.' , '/' ) ; name += ".xml" ; return getConfStream ( name ) ; }
same as getConfPathXmlFile
34,081
public Object put ( Object key , Object subKey , Object value ) { HashMap a = ( HashMap ) super . get ( key ) ; if ( a == null ) { a = new HashMap ( ) ; super . put ( key , a ) ; } return a . put ( subKey , value ) ; }
Associates the specified value with the specified key and subKey in this map . If the map previously contained a mapping for this key and subKey the old value is replaced .
34,082
public Object get ( Object key , Object subKey ) { HashMap a = ( HashMap ) super . get ( key ) ; if ( a != null ) { Object b = a . get ( subKey ) ; return b ; } return null ; }
Returns the value to which this map maps the specified key and subKey . Returns null if the map contains no mapping for this key and subKey . A return value of null does not necessarily indicate that the map contains no mapping for the key and subKey ; it s also possible that the map explicitly maps the key to null . The containsKey operation may be used to distinguish these two cases .
34,083
public void initialized ( AppContextWrapper context ) { ContainerRegistryBuilder cb = ( ContainerRegistryBuilder ) context . getAttribute ( ContainerRegistryBuilder . APPLICATION_CONTEXT_ATTRIBUTE_NAME ) ; if ( cb != null ) return ; try { synchronized ( context ) { cb = containerBuilderContext . createContainerBuilder ( context ) ; context . setAttribute ( ContainerRegistryBuilder . APPLICATION_CONTEXT_ATTRIBUTE_NAME , cb ) ; Debug . logVerbose ( "[JdonFramework] Initialize the container OK .." ) ; } } catch ( Exception e ) { Debug . logError ( "[JdonFramework] initialized error: " + e , module ) ; } }
Initialize application container
34,084
public synchronized void prepare ( String configureFileName , AppContextWrapper context ) { ContainerRegistryBuilder cb ; try { cb = ( ContainerRegistryBuilder ) context . getAttribute ( ContainerRegistryBuilder . APPLICATION_CONTEXT_ATTRIBUTE_NAME ) ; if ( cb == null ) { initialized ( context ) ; cb = ( ContainerRegistryBuilder ) context . getAttribute ( ContainerRegistryBuilder . APPLICATION_CONTEXT_ATTRIBUTE_NAME ) ; } ContainerDirector cd = new ContainerDirector ( cb ) ; cd . prepareAppRoot ( configureFileName ) ; } catch ( Exception ex ) { Debug . logError ( ex , module ) ; } }
prepare to the applicaition xml Configure for container ;
34,085
public synchronized void startup ( AppContextWrapper context ) { ContainerRegistryBuilder cb ; try { cb = ( ContainerRegistryBuilder ) context . getAttribute ( ContainerRegistryBuilder . APPLICATION_CONTEXT_ATTRIBUTE_NAME ) ; if ( cb == null ) { Debug . logError ( "[JdonFramework] at first call prepare method" ) ; return ; } if ( cb . isKernelStartup ( ) ) return ; ContainerDirector cd = new ContainerDirector ( cb ) ; cd . startup ( ) ; } catch ( Exception ex ) { Debug . logError ( ex , module ) ; } }
startup Application container
34,086
public synchronized void destroyed ( AppContextWrapper context ) { try { ContainerRegistryBuilder cb = ( ContainerRegistryBuilder ) context . getAttribute ( ContainerRegistryBuilder . APPLICATION_CONTEXT_ATTRIBUTE_NAME ) ; if ( cb != null ) { ContainerDirector cd = new ContainerDirector ( cb ) ; cd . shutdown ( ) ; context . removeAttribute ( ContainerRegistryBuilder . APPLICATION_CONTEXT_ATTRIBUTE_NAME ) ; containerBuilderContext = null ; Debug . logVerbose ( "[JdonFramework] stop the container .." , module ) ; } } catch ( Exception e ) { Debug . logError ( "[JdonFramework] destroyed error: " + e , module ) ; } }
desroy Application container
34,087
public static byte [ ] objectToBytes ( Object object ) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream ( ) ; ObjectOutputStream os = new ObjectOutputStream ( baos ) ; os . writeObject ( object ) ; return baos . toByteArray ( ) ; }
Converts a serializable object to a byte array .
34,088
public static Object bytesToObject ( byte [ ] bytes ) throws IOException , ClassNotFoundException { ByteArrayInputStream bais = new ByteArrayInputStream ( bytes ) ; ObjectInputStream is = new ObjectInputStream ( bais ) ; return is . readObject ( ) ; }
Converts a byte array to a serializable object .
34,089
private void parsePOJOServiceConfig ( Element pojoService , Map < String , TargetMetaDef > mps ) throws Exception { String name = pojoService . getAttributeValue ( "name" ) ; String className = pojoService . getAttributeValue ( "class" ) ; Debug . logVerbose ( "[JdonFramework] pojoService/component name=" + name + " class=" + className , module ) ; if ( ( className == null ) || ( className . equals ( "" ) ) ) throw new Exception ( "className is null " ) ; List mappings = pojoService . getChildren ( "constructor" ) ; String [ ] constructors = null ; if ( ( mappings != null ) && ( mappings . size ( ) != 0 ) ) { Debug . logVerbose ( "[JdonFramework] constructor parameters number:" + mappings . size ( ) + " for pojoservice " + name , module ) ; constructors = new String [ mappings . size ( ) ] ; int j = 0 ; Iterator i = mappings . iterator ( ) ; while ( i . hasNext ( ) ) { Element constructor = ( Element ) i . next ( ) ; String value = constructor . getAttributeValue ( "value" ) ; Debug . logVerbose ( "[JdonFramework] pojoService constructor=" + value , module ) ; constructors [ j ] = value ; j ++ ; } } POJOTargetMetaDef pojoMetaDef = null ; if ( constructors != null ) pojoMetaDef = new POJOTargetMetaDef ( name , className , constructors ) ; else pojoMetaDef = new POJOTargetMetaDef ( name , className ) ; mps . put ( name , pojoMetaDef ) ; }
parse POJOService Config
34,090
public EJBLocalHome getLocalHome ( String jndiHomeName ) throws ServiceLocatorException { Debug . logVerbose ( "[JdonFramework] -- > getLocalHome.... " , module ) ; EJBLocalHome home = null ; try { if ( cache . containsKey ( jndiHomeName ) ) { home = ( EJBLocalHome ) cache . get ( jndiHomeName ) ; } else { Debug . logVerbose ( "[JdonFramework] lookUp LocalHome.... " , module ) ; home = ( EJBLocalHome ) ic . lookup ( jndiHomeName ) ; cache . put ( jndiHomeName , home ) ; } } catch ( NamingException ne ) { throw new ServiceLocatorException ( ne ) ; } catch ( Exception e ) { throw new ServiceLocatorException ( e ) ; } return home ; }
will get the ejb Local home factory . If this ejb home factory has already been clients need to cast to the type of EJBHome they desire
34,091
public Block locate ( String sqlquery , Collection queryParams , Object locateId ) { int blockSize = getBlockLength ( ) ; Block block = null ; int index = - 1 ; int prevBlockStart = Integer . MIN_VALUE ; int nextBlockStart = Integer . MIN_VALUE ; int start = 0 ; Debug . logVerbose ( "[JdonFramework]try to locate a block locateId= " + locateId + " blockSize=" + blockSize , module ) ; try { while ( index == - 1 ) { block = getBlock ( sqlquery , queryParams , start , blockSize ) ; if ( block == null ) break ; List list = block . getList ( ) ; index = list . indexOf ( locateId ) ; if ( ( index >= 0 ) && ( index < list . size ( ) ) ) { Debug . logVerbose ( "[JdonFramework]found the locateId, index= " + index , module ) ; if ( ( index == 0 ) && ( block . getStart ( ) >= blockSize ) ) prevBlockStart = start - blockSize ; else if ( index == blockSize - 1 ) nextBlockStart = start + blockSize ; break ; } else { if ( block . getCount ( ) >= blockSize ) start = start + blockSize ; else break ; } } if ( index == - 1 ) { Debug . logVerbose ( "[JdonFramework] not locate the block that have the locateId= " + locateId , module ) ; return null ; } if ( prevBlockStart != Integer . MIN_VALUE ) { Block prevBlock = getBlock ( sqlquery , queryParams , prevBlockStart , blockSize ) ; prevBlock . getList ( ) . addAll ( block . getList ( ) ) ; prevBlock . setStart ( prevBlock . getStart ( ) + prevBlock . getCount ( ) ) ; prevBlock . setCount ( prevBlock . getCount ( ) + block . getCount ( ) ) ; return prevBlock ; } else if ( nextBlockStart != Integer . MIN_VALUE ) { Block nextBlock = getBlock ( sqlquery , queryParams , nextBlockStart , blockSize ) ; if ( nextBlock != null ) { block . getList ( ) . addAll ( nextBlock . getList ( ) ) ; block . setCount ( block . getCount ( ) + nextBlock . getCount ( ) ) ; } return block ; } else return block ; } catch ( Exception e ) { Debug . logError ( " locate Block error" + e , module ) ; } return block ; }
looking for the primary be equals to locateId in the result for the sql sentence .
34,092
private Block getBlock ( QueryConditonDatakey qcdk ) { Block clientBlock = new Block ( qcdk . getStart ( ) , qcdk . getCount ( ) ) ; if ( clientBlock . getCount ( ) > this . blockLength ) clientBlock . setCount ( this . blockLength ) ; List list = getBlockKeys ( qcdk ) ; Block dataBlock = new Block ( qcdk . getBlockStart ( ) , list . size ( ) ) ; int currentStart = clientBlock . getStart ( ) - dataBlock . getStart ( ) ; Block currentBlock = new Block ( currentStart , clientBlock . getCount ( ) ) ; currentBlock . setList ( list ) ; try { int lastCount = dataBlock . getCount ( ) + dataBlock . getStart ( ) - clientBlock . getStart ( ) ; Debug . logVerbose ( "[JdonFramework] lastCount=" + lastCount , module ) ; if ( lastCount < clientBlock . getCount ( ) ) { if ( dataBlock . getCount ( ) == this . blockLength ) { int newStartIndex = dataBlock . getStart ( ) + dataBlock . getCount ( ) ; int newCount = clientBlock . getCount ( ) - lastCount ; qcdk . setStart ( newStartIndex ) ; qcdk . setCount ( newCount ) ; Debug . logVerbose ( "[JdonFramework] newStartIndex=" + newStartIndex + " newCount=" + newCount , module ) ; Block nextBlock = getBlock ( qcdk ) ; Debug . logVerbose ( "[JdonFramework] nextBlock.getCount()=" + nextBlock . getCount ( ) , module ) ; currentBlock . setCount ( currentBlock . getCount ( ) + nextBlock . getCount ( ) ) ; } else { currentBlock . setCount ( lastCount ) ; } } } catch ( Exception e ) { Debug . logError ( " getBlock error" + e , module ) ; } return currentBlock ; }
get the current block being avaliable to the query condition
34,093
private List getBlockKeys ( QueryConditonDatakey qcdk ) { List keys = blockCacheManager . getBlockKeysFromCache ( qcdk ) ; if ( ( keys == null ) ) { keys = blockQueryJDBC . fetchDatas ( qcdk ) ; if ( keys != null && keys . size ( ) != 0 ) blockCacheManager . saveBlockKeys ( qcdk , keys ) ; } Debug . logVerbose ( "[JdonFramework] getBlockKeys, size=" + keys . size ( ) , module ) ; return keys ; }
get a Block that begin at the start
34,094
public static RequestWrapper create ( HttpServletRequest request ) { HttpSession session = request . getSession ( ) ; AppContextWrapper acw = new ServletContextWrapper ( session . getServletContext ( ) ) ; SessionWrapper sw = new HttpSessionWrapper ( session ) ; ContextHolder contextHolder = new ContextHolder ( acw , sw ) ; return new HttpServletRequestWrapper ( request , contextHolder ) ; }
create a HttpServletRequestWrapper with session supports . this method will create HttpSession .
34,095
public void setQueryParams ( Collection queryParams , PreparedStatement ps ) throws Exception { if ( ( queryParams == null ) || ( queryParams . size ( ) == 0 ) ) return ; int i = 1 ; Object key = null ; Iterator iter = queryParams . iterator ( ) ; while ( iter . hasNext ( ) ) { key = iter . next ( ) ; if ( key != null ) { convertType ( i , key , ps ) ; Debug . logVerbose ( "[JdonFramework] parameter " + i + " = " + key . toString ( ) , module ) ; } else { Debug . logWarning ( "[JdonFramework] parameter " + i + " is null" , module ) ; ps . setString ( i , "" ) ; } i ++ ; } }
queryParam type only support String Integer Float or Long Double Bye Short if you need operate other types you must use JDBC directly!
34,096
public List extract ( ResultSet rs ) throws Exception { ResultSetMetaData meta = rs . getMetaData ( ) ; int count = meta . getColumnCount ( ) ; List ret = new ArrayList ( ) ; while ( rs . next ( ) ) { Map map = new LinkedHashMap ( count ) ; for ( int i = 1 ; i <= count ; i ++ ) { map . put ( meta . getColumnName ( i ) , rs . getObject ( i ) ) ; } ret . add ( map ) ; } return ret ; }
return a List in the List every object is a map by database column name we can get the its result from map
34,097
public Object invoke ( TargetMetaRequest targetMetaRequest , Method method , Object [ ] args ) throws Throwable { targetMetaRequestsHolder . setTargetMetaRequest ( targetMetaRequest ) ; Debug . logVerbose ( "[JdonFramework] enter AOP invoker2 for:" + targetMetaRequest . getTargetMetaDef ( ) . getClassName ( ) + " method:" + method . getName ( ) , module ) ; Object result = null ; MethodInvocation methodInvocation = null ; try { List < MethodInterceptor > chain = advisorChainFactory . create ( targetMetaRequest . getTargetMetaDef ( ) ) ; methodInvocation = new ProxyMethodInvocation ( chain , targetMetaRequestsHolder , targetServiceFactory , method , args ) ; Debug . logVerbose ( "[JdonFramework] MethodInvocation will proceed ... " , module ) ; result = methodInvocation . proceed ( ) ; } catch ( Exception ex ) { Debug . logError ( ex , module ) ; throw new Exception ( ex ) ; } catch ( Throwable ex ) { throw new Throwable ( ex ) ; } finally { targetMetaRequestsHolder . clear ( ) ; } return result ; }
dynamic proxy active this method when client call userService . xxxmethod
34,098
@ Procedure ( mode = Mode . WRITE ) @ Description ( "apoc.refactor.rename.label(oldLabel, newLabel, [nodes]) | rename a label from 'oldLabel' to 'newLabel' for all nodes. If 'nodes' is provided renaming is applied to this set only" ) public Stream < BatchAndTotalResultWithInfo > label ( @ Name ( "oldLabel" ) String oldLabel , @ Name ( "newLabel" ) String newLabel , @ Name ( value = "nodes" , defaultValue = "" ) List < Node > nodes ) { String cypherIterate = nodes != null && ! nodes . isEmpty ( ) ? "UNWIND {nodes} AS n WITH n WHERE n:`" + oldLabel + "` RETURN n" : "MATCH (n:`" + oldLabel + "`) RETURN n" ; String cypherAction = "SET n:`" + newLabel + "` REMOVE n:`" + oldLabel + "`" ; Map < String , Object > parameters = MapUtil . map ( "batchSize" , 100000 , "parallel" , true , "iterateList" , true , "params" , MapUtil . map ( "nodes" , nodes ) ) ; return getResultOfBatchAndTotalWithInfo ( newPeriodic ( ) . iterate ( cypherIterate , cypherAction , parameters ) , db , oldLabel , null , null ) ; }
Rename the Label of a node by creating a new one and deleting the old .
34,099
@ Procedure ( mode = Mode . WRITE ) @ Description ( "apoc.refactor.rename.type(oldType, newType, [rels]) | rename all relationships with type 'oldType' to 'newType'. If 'rels' is provided renaming is applied to this set only" ) public Stream < BatchAndTotalResultWithInfo > type ( @ Name ( "oldType" ) String oldType , @ Name ( "newType" ) String newType , @ Name ( value = "rels" , defaultValue = "" ) List < Relationship > rels ) { String cypherIterate = rels != null && ! rels . isEmpty ( ) ? "UNWIND {rels} AS oldRel WITH oldRel WHERE type(oldRel)=\"" + oldType + "\" RETURN oldRel,startNode(oldRel) as a,endNode(oldRel) as b" : "MATCH (a)-[oldRel:`" + oldType + "`]->(b) RETURN oldRel,a,b" ; String cypherAction = "CREATE(a)-[newRel:`" + newType + "`]->(b)" + "SET newRel+=oldRel DELETE oldRel" ; Map < String , Object > parameters = MapUtil . map ( "batchSize" , 100000 , "parallel" , true , "iterateList" , true , "params" , MapUtil . map ( "rels" , rels ) ) ; return getResultOfBatchAndTotalWithInfo ( newPeriodic ( ) . iterate ( cypherIterate , cypherAction , parameters ) , db , null , oldType , null ) ; }
Rename the Relationship Type by creating a new one and deleting the old .