idx
int64
0
165k
question
stringlengths
73
4.15k
target
stringlengths
5
918
len_question
int64
21
890
len_target
int64
3
255
23,700
public static AGeneralOperation getOperation ( OperationType operationType ) { switch ( operationType ) { case BASIC_INSTRUCTION : return new BasicOperation ( ) ; case BASIC_CONVERSION : return new BasicConversion ( ) ; case OBJECT : return new ObjectOperation ( ) ; case ARRAY : return new ArrayOperation ( ) ; case ARRAY_LIST : return new ArrayListOperation ( ) ; case LIST_ARRAY : return new ListArrayOperation ( ) ; case ARRAY_WITH_MAPPED_ITEMS : return new MappedArrayOperation ( ) ; case ARRAY_LIST_WITH_MAPPED_ITEMS : return new MappedArrayListOperation ( ) ; case LIST_ARRAY_WITH_MAPPED_ITEMS : return new MappedListArrayOperation ( ) ; case COLLECTION : return new CollectionOperation ( ) ; case COLLECTION_WITH_MAPPED_ITEMS : return new MappedCollectionOperation ( ) ; case MAP : return new MapOperation ( ) ; case MAP_WITH_MAPPED_ITEMS : return new MappedMapOperation ( ) ; case CONVERSION : return new ConversionOperation ( ) ; case DATE_CALENDAR : return new DateCalendarOperation ( ) ; case STRING_ENUM : return new StringEnumOperation ( ) ; case STRING_STRINGBUFFER : return new StringStringBufferOperation ( ) ; case STRING_STRINGBUILDER : return new StringStringBuilderOperation ( ) ; case CALENDAR_DATE : return new CalendarDateOperation ( ) ; case ENUM_STRING : return new EnumStringOperation ( ) ; case STRINGBUILDER_STRING : return new StringBuilderStringOperation ( ) ; case STRINGBUFFER_STRING : return new StringBufferStringOperation ( ) ; case ENUM_ENUM : return new EnumEnumOperation ( ) ; default : return null ; } }
Operation factory .
418
3
23,701
public static InputStream loadResource ( String resource ) throws MalformedURLException , IOException { String content = resource . trim ( ) ; // if resource is a content and not a path if ( ! isPath ( content ) ) return new ByteArrayInputStream ( content . getBytes ( "UTF-8" ) ) ; URL url = Thread . currentThread ( ) . getContextClassLoader ( ) . getResource ( content ) ; // Could not find resource. Try with the classloader that loaded this class. if ( isNull ( url ) ) { ClassLoader classLoader = ResourceLoader . class . getClassLoader ( ) ; if ( classLoader != null ) url = classLoader . getResource ( content ) ; } // Last ditch attempt searching classpath if ( isNull ( url ) ) url = ClassLoader . getSystemResource ( content ) ; // one more time if ( isNull ( url ) && content . contains ( ":" ) ) url = new URL ( content ) ; if ( isNull ( url ) ) Error . xmlNotFound ( content ) ; return url . openStream ( ) ; }
Returns an instance of inputStream if resource exists null otherwise .
233
12
23,702
public boolean fieldsToCheck ( Field destination , Field source ) { destinationName = destination . getName ( ) ; sourceName = source . getName ( ) ; if ( ! xml . conversionsLoad ( ) . isEmpty ( ) ) { configurationType = XML ; if ( config == DESTINATION ) { if ( existsXmlConversion ( destinationClass ) ) { membership = Membership . DESTINATION ; return true ; } if ( existsXmlConversion ( sourceClass ) ) { membership = Membership . SOURCE ; return true ; } } else { if ( existsXmlConversion ( sourceClass ) ) { membership = Membership . SOURCE ; return true ; } if ( existsXmlConversion ( destinationClass ) ) { membership = Membership . DESTINATION ; return true ; } } } configurationType = ANNOTATION ; if ( config == DESTINATION ) { if ( existsAnnotatedConversion ( destinationClass ) ) { membership = Membership . DESTINATION ; return true ; } if ( existsAnnotatedConversion ( sourceClass ) ) { membership = Membership . SOURCE ; return true ; } } else { if ( existsAnnotatedConversion ( sourceClass ) ) { membership = Membership . SOURCE ; return true ; } if ( existsAnnotatedConversion ( destinationClass ) ) { membership = Membership . DESTINATION ; return true ; } } return false ; }
Checks for the existence of a conversion method .
298
10
23,703
private boolean exists ( List < ConversionMethod > conversions ) { if ( conversions . isEmpty ( ) ) return false ; return ( method = verifyConversionExistence ( conversions ) ) != null ; }
Verifies the conversion method existence returns true if exists false otherwise .
41
13
23,704
private ConversionMethod verifyConversionExistence ( List < ConversionMethod > conversions ) { for ( ConversionMethod method : conversions ) if ( isPresentIn ( method . getFrom ( ) , sourceName ) && isPresentIn ( method . getTo ( ) , destinationName ) ) return method ; return null ; }
This method finds the conversion method between those loaded .
64
10
23,705
private boolean isPresentIn ( String [ ] values , String field ) { for ( String value : values ) if ( value . equalsIgnoreCase ( JMapConversion . ALL ) || value . equals ( field ) ) return true ; return false ; }
Returns true if the field name is contained in the values array false otherwise .
53
15
23,706
public static void nestedBeanNull ( String currentField , String destinationClass , String destinationField , String sourceClass , String sourceField , boolean safeNavigationOperator ) { throw new NestedBeanNullException ( MSG . INSTANCE . message ( nestedBeanNullException , currentField , destinationClass , destinationField , sourceClass , sourceField ) , safeNavigationOperator ) ; }
Thrown when the source field is null in a mapping of nested type .
82
15
23,707
public static void bodyContainsIllegalCode ( Method method , Exception additionalInformation ) { Class < ? > clazz = method . getClazz ( ) ; if ( isNull ( clazz ) ) clazz = JMapper . class ; String originalName = method . getOriginalName ( ) ; if ( isNull ( originalName ) ) originalName = method . getName ( ) ; String message = clazz != JMapper . class ? MSG . INSTANCE . message ( conversionBodyIllegalCode , clazz . getSimpleName ( ) , originalName , "" + additionalInformation . getMessage ( ) ) : MSG . INSTANCE . message ( conversionBodyIllegalCode2 , "" + additionalInformation . getMessage ( ) ) ; throw new ConversionBodyIllegalCodeException ( message ) ; }
Thrown when the code contained in the body method is illegal .
166
13
23,708
public static void incorrectMethodDefinition ( String methodName , String className ) { throw new DynamicConversionMethodException ( MSG . INSTANCE . message ( dynamicConversionMethodException , methodName , className ) ) ; }
Thrown when the method don t respects the convetions beloging to the dynamic conversion implementation .
46
21
23,709
public static void incorrectBodyDefinition ( String methodName , String className ) { throw new DynamicConversionBodyException ( MSG . INSTANCE . message ( dynamicConversionBodyException , methodName , className ) ) ; }
Thrown when the body method don t respects the convetions beloging to the dynamic conversion implementation .
46
22
23,710
public static void attributeInexistent ( String attributeName , Class < ? > aClass ) { throw new IllegalArgumentException ( MSG . INSTANCE . message ( malformedBeanException2 , attributeName , aClass . getSimpleName ( ) ) ) ; }
Thrown if attributes isn t present in the xml file .
56
12
23,711
public static void xmlWrongMethod ( Class < ? > aClass ) { throw new WrongMethodException ( MSG . INSTANCE . message ( wrongMethodException1 , aClass . getSimpleName ( ) ) ) ; }
Thrown when the class has only one attribute .
46
10
23,712
public static void xmlClassInexistent ( String path , Class < ? > aClass ) { throw new XmlMappingClassDoesNotExistException ( MSG . INSTANCE . message ( xmlMappingClassDoesNotExistException1 , path , aClass . getSimpleName ( ) ) ) ; }
Thrown if class isn t present in xml file .
65
11
23,713
public static void xmlClassExistent ( String path , Class < ? > aClass ) { throw new XmlMappingClassExistException ( MSG . INSTANCE . message ( xmlMappingClassExistException1 , aClass . getSimpleName ( ) , path ) ) ; }
Thrown if class is present in xml file .
60
10
23,714
public static void xmlConversionNameUndefined ( String xmlPath , String className ) { throw new XmlConversionNameException ( MSG . INSTANCE . message ( xmlConversionNameException , xmlPath , className ) ) ; }
Thrown when the conversion name is undefined .
50
9
23,715
public static void xmlConversionTypeIncorrect ( String conversionName , String xmlPath , String className , String type ) { throw new XmlConversionTypeException ( MSG . INSTANCE . message ( xmlConversionTypeException , conversionName , xmlPath , className , type ) ) ; }
Thrown if conversion type is wrong .
62
8
23,716
public static void improperUseOfTheParameter ( String conversionName , String xmlPath , String className ) { throw new XmlConversionParameterException ( MSG . INSTANCE . message ( xmlConversionParameterException , conversionName , xmlPath , className ) ) ; }
Thrown if the use of the parameters is incorrect .
56
11
23,717
public static void undefinedMapping ( Field destinationField , Class < ? > destinationClass , Field sourceField , Class < ? > sourceClass ) { throw new UndefinedMappingException ( MSG . INSTANCE . message ( undefinedMappingException , destinationField . getName ( ) , destinationClass . getSimpleName ( ) , sourceField . getName ( ) , sourceClass . getSimpleName ( ) ) ) ; }
Thrown when the instruction isn t defined .
87
9
23,718
public static void badConversion ( Field destinationField , Class < ? > destinationClass , Field sourceField , Class < ? > sourceClass , String plus ) { throw new UndefinedMappingException ( MSG . INSTANCE . message ( undefinedMappingException , destinationField . getName ( ) , destinationClass . getSimpleName ( ) , sourceField . getName ( ) , sourceClass . getSimpleName ( ) ) + ". More information: " + plus ) ; }
Thrown when conversions are badly written .
98
8
23,719
public static void mapping ( String mappedFieldName , Class < ? > mappedClass , Class < ? > targetClass ) { throw new MappingErrorException ( MSG . INSTANCE . message ( mappingErrorException2 , mappedFieldName , mappedClass . getSimpleName ( ) , targetClass . getSimpleName ( ) ) ) ; }
Thrown when there is an error in the configuration .
69
11
23,720
public static void mapping ( String mappedFieldName , String mappedClassName ) { throw new MappingErrorException ( MSG . INSTANCE . message ( mappingErrorException2length , mappedFieldName , mappedClassName ) ) ; }
Thrown when the length of classes and attribute parameter isn t the same .
47
15
23,721
public static void mapping ( String mappedFieldName , String mappedClassName , String targetClassName ) { throw new MappingErrorException ( MSG . INSTANCE . message ( mappingErrorException3 , mappedFieldName , mappedClassName , targetClassName ) ) ; }
Thrown when the target class doesn t exist in classes parameter .
55
13
23,722
public static void attributeAbsent ( Class < ? > aClass , Attribute aField ) { throw new XmlMappingAttributeDoesNotExistException ( MSG . INSTANCE . message ( xmlMappingAttributeDoesNotExistException2 , aField . getName ( ) , aClass . getSimpleName ( ) , "API" ) ) ; }
Thrown if the attribute doesn t exist in aClass .
75
12
23,723
public static void configNotPresent ( Class < ? > destination , Class < ? > source , XML xml ) { throw new MappingNotFoundException ( MSG . INSTANCE . message ( Constants . mappingNotFoundException2path , destination . getSimpleName ( ) , source . getSimpleName ( ) , xml . getXmlPath ( ) ) ) ; }
Thrown when the xml configuration doesn t contains the classes configuration .
76
13
23,724
public static void configNotPresent ( Class < ? > clazz , XML xml ) { throw new MappingNotFoundException ( MSG . INSTANCE . message ( Constants . mappingNotFoundException1path , clazz . getSimpleName ( ) , xml . getXmlPath ( ) ) ) ; }
Thrown when missing the configuration belonging to clazz .
64
11
23,725
public static void classesNotConfigured ( Class < ? > destination , Class < ? > source ) { throw new MappingNotFoundException ( MSG . INSTANCE . message ( Constants . mappingNotFoundException2 , destination . getSimpleName ( ) , source . getSimpleName ( ) ) ) ; }
Thrown when the xml configuration doesn t exist .
64
10
23,726
public static void classNotConfigured ( Class < ? > clazz ) { throw new MappingNotFoundException ( MSG . INSTANCE . message ( Constants . mappingNotFoundException1 , clazz . getSimpleName ( ) ) ) ; }
Thrown when the xml configuration of the clazz doesn t exist .
52
14
23,727
public static void globalClassesAbsent ( Class < ? > aClass ) { throw new MappingErrorException ( MSG . INSTANCE . message ( mappingErrorRelationalException3 , aClass . getSimpleName ( ) ) ) ; }
Thrown if the configured class hasn t classes parameter .
50
11
23,728
public static void classesAbsent ( String fieldName , Class < ? > aClass ) { throw new MappingErrorException ( MSG . INSTANCE . message ( mappingErrorRelationalException2 , fieldName , aClass . getSimpleName ( ) ) ) ; }
Thrown if the configured field hasn t classes parameter .
55
11
23,729
public static void classNotMapped ( Class < ? > aClass ) { throw new ClassNotMappedException ( MSG . INSTANCE . message ( classNotMappedException1 , aClass . getSimpleName ( ) ) ) ; }
Thrown if the class isn t mapped .
50
9
23,730
public static void classNotMapped ( Object sourceClass , Class < ? > configuredClass ) { String sourceName = sourceClass instanceof Class ? ( ( Class < ? > ) sourceClass ) . getSimpleName ( ) : sourceClass . getClass ( ) . getSimpleName ( ) ; throw new ClassNotMappedException ( MSG . INSTANCE . message ( classNotMappedException2 , sourceName , configuredClass . getSimpleName ( ) ) ) ; }
Thrown if the sourceClass isn t mapped in configuredClass .
98
13
23,731
public static void illegalCode ( Class < ? > destination , Class < ? > source , String path , Throwable e ) { String additionalInformation = e . getMessage ( ) . split ( "," ) [ 1 ] ; throw new IllegalCodeException ( MSG . INSTANCE . message ( illegalCodePath , destination . getSimpleName ( ) , source . getSimpleName ( ) , path , additionalInformation ) ) ; }
Thrown when there is an error in mapper generated class .
87
13
23,732
public static void absentRelationship ( Class < ? > configuredClass , Class < ? > targetClass ) { throw new AbsentRelationshipException ( MSG . INSTANCE . message ( noRelationshipException , configuredClass . getSimpleName ( ) , targetClass . getSimpleName ( ) ) ) ; }
Thrown when there isn t correspondence between classes .
62
10
23,733
public static void emptyConstructorAbsent ( Class < ? > aClass ) { throw new MalformedBeanException ( MSG . INSTANCE . message ( malformedBeanException1 , aClass . getSimpleName ( ) ) ) ; }
Thrown if the class haven t an empty constructor .
51
11
23,734
protected ChooseConfig searchConfig ( ChooseConfig cc , XML xml ) { ChooseConfig config = searchXmlConfig ( cc , xml ) ; if ( isNull ( config ) ) config = searchAnnotatedConfig ( cc ) ; return config ; }
This method finds the configuration location returns null if don t finds it
51
13
23,735
private ChooseConfig searchXmlConfig ( ChooseConfig cc , XML xml ) { if ( isNull ( xml . getXmlPath ( ) ) ) return null ; if ( ( isNull ( cc ) || cc == ChooseConfig . DESTINATION ) && xml . isInheritedMapped ( destination ) ) return ChooseConfig . DESTINATION ; if ( ( isNull ( cc ) || cc == ChooseConfig . SOURCE ) && xml . isInheritedMapped ( source ) ) return ChooseConfig . SOURCE ; return null ; }
This method finds the xml configuration returns null if there are no .
116
13
23,736
private ChooseConfig searchAnnotatedConfig ( ChooseConfig cc ) { if ( ( isNull ( cc ) || cc == ChooseConfig . DESTINATION ) && Annotation . isInheritedMapped ( destination ) ) return ChooseConfig . DESTINATION ; if ( ( isNull ( cc ) || cc == ChooseConfig . SOURCE ) && Annotation . isInheritedMapped ( source ) ) return ChooseConfig . SOURCE ; return null ; }
This method finds the annotations returns null if there are no .
98
12
23,737
public static JMapAccessor getFieldAccessors ( Class < ? > clazz , Field field ) { return getFieldAccessors ( clazz , field , false , field . getName ( ) , Constants . DEFAULT_FIELD_VALUE ) ; }
Returns JMapAccessor relative to this field null if not present .
54
14
23,738
private static JMapAccessor getAccessor ( Class < ? > clazz , java . lang . annotation . Annotation [ ] annotations , String fieldName , boolean isOpposite ) { for ( java . lang . annotation . Annotation annotation : annotations ) { if ( annotation . annotationType ( ) == JMapAccessors . class ) { JMapAccessors jmapAccessors = ( JMapAccessors ) annotation ; for ( JMapAccessor jmapAccessor : jmapAccessors . value ( ) ) if ( isValid ( jmapAccessor , fieldName , clazz , isOpposite ) ) return jmapAccessor ; } if ( annotation . annotationType ( ) == JMapAccessor . class ) { JMapAccessor jmapAccessor = ( JMapAccessor ) annotation ; if ( isValid ( jmapAccessor , fieldName , clazz , isOpposite ) ) return jmapAccessor ; } } return null ; }
It finds between annotations if exists a JMapAccessor relative to the field with this name .
203
19
23,739
public static List < ConversionMethod > getConversionMethods ( Class < ? > clazz ) { List < ConversionMethod > conversions = new ArrayList < ConversionMethod > ( ) ; for ( Method method : getAnnotatedMethods ( clazz ) ) try { conversions . add ( Converter . toConversionMethod ( method ) ) ; } catch ( ConversionParameterException e ) { Error . wrongParameterNumber ( method . getName ( ) , clazz . getSimpleName ( ) ) ; } catch ( DynamicConversionParameterException e ) { Error . parametersUsageNotAllowed ( method . getName ( ) , clazz . getSimpleName ( ) ) ; } catch ( DynamicConversionMethodException e ) { Error . incorrectMethodDefinition ( method . getName ( ) , clazz . getSimpleName ( ) ) ; } catch ( DynamicConversionBodyException e ) { Error . incorrectBodyDefinition ( method . getName ( ) , clazz . getSimpleName ( ) ) ; } return conversions ; }
Returns a list of ConversionMethod that belong to the class given as input .
211
15
23,740
private static List < Method > getAnnotatedMethods ( Class < ? > clazz ) { List < Method > methods = new ArrayList < Method > ( ) ; for ( Method method : getAllMethods ( clazz ) ) if ( ! isNull ( method . getAnnotation ( JMapConversion . class ) ) ) methods . add ( method ) ; return methods ; }
Returns a list with all annotated methods .
80
9
23,741
public static boolean isInheritedMapped ( Class < ? > classToCheck ) { for ( Class < ? > clazz : getAllsuperClasses ( classToCheck ) ) if ( ! isNull ( clazz . getAnnotation ( JGlobalMap . class ) ) ) return true ; for ( Field field : getListOfFields ( classToCheck ) ) if ( ! isNull ( field . getAnnotation ( JMap . class ) ) ) return true ; return false ; }
Returns true if the class is configured in annotation false otherwise .
105
12
23,742
public static ConversionType getConversionType ( final Field destination , final Field source ) { return getConversionType ( destination . getType ( ) , source . getType ( ) ) ; }
Analyzes Fields given as input and returns the type of conversion that has to be done .
40
18
23,743
public static ConversionType getConversionType ( final Class < ? > destination , final Class < ? > source ) { if ( destination == String . class ) return toStringConversion ( source ) ; if ( destination == Byte . class ) return toByteConversion ( source ) ; if ( destination == byte . class ) return tobyteConversion ( source ) ; if ( destination == Short . class ) return toShortConversion ( source ) ; if ( destination == short . class ) return toshortConversion ( source ) ; if ( destination == Integer . class ) return toIntegerConversion ( source ) ; if ( destination == int . class ) return tointConversion ( source ) ; if ( destination == Long . class ) return toLongConversion ( source ) ; if ( destination == long . class ) return tolongConversion ( source ) ; if ( destination == Float . class ) return toFloatConversion ( source ) ; if ( destination == float . class ) return tofloatConversion ( source ) ; if ( destination == Double . class ) return toDoubleConversion ( source ) ; if ( destination == double . class ) return todoubleConversion ( source ) ; if ( destination == Character . class ) return toCharacterConversion ( source ) ; if ( destination == char . class ) return tocharConversion ( source ) ; if ( destination == Boolean . class ) return toBooleanConversion ( source ) ; if ( destination == boolean . class ) return tobooleanConversion ( source ) ; return UNDEFINED ; }
Analyzes classes given as input and returns the type of conversion that has to be done .
322
18
23,744
private Class < ? > defineStructure ( Field destination , Field source ) { Class < ? > destinationClass = destination . getType ( ) ; Class < ? > sourceClass = source . getType ( ) ; Class < ? > result = null ; // if destination is an interface if ( destinationClass . isInterface ( ) ) // if source is an interface if ( sourceClass . isInterface ( ) ) // retrieves the implementation of the destination interface result = ( Class < ? > ) implementationClass . get ( destinationClass . getName ( ) ) ; // if source is an implementation else { // retrieves source interface Class < ? > sourceInterface = sourceClass . getInterfaces ( ) [ 0 ] ; // if the destination and source interfaces are equal if ( destinationClass . equals ( sourceInterface ) ) // assigns implementation to destination result = sourceClass ; // if they are different else // destination gets the implementation of his interface result = ( Class < ? > ) implementationClass . get ( destinationClass . getName ( ) ) ; } // if destination is an implementation else result = destinationClass ; return result ; }
This method defines the destination structure for this operation . If destination class is an interface a relative implementation will be found .
230
23
23,745
public static < D , S > IJMapper < D , S > getMapper ( final Class < D > destination , final Class < S > source ) { return getMapper ( destination , source , undefinedConfig ( ) ) ; }
Returns an instance of JMapper from cache if exists in alternative a new instance .
50
16
23,746
private static String relationalMapperName ( Class < ? > configuredClass , String resource ) { String className = configuredClass . getName ( ) . replaceAll ( "\\." , "" ) ; if ( isEmpty ( resource ) ) return className ; if ( ! isPath ( resource ) ) return write ( className , String . valueOf ( resource . hashCode ( ) ) ) ; String [ ] dep = resource . split ( "\\\\" ) ; if ( dep . length <= 1 ) dep = resource . split ( "/" ) ; String xml = dep [ dep . length - 1 ] ; return write ( className , xml . replaceAll ( "\\." , "" ) . replaceAll ( " " , "" ) ) ; }
Returns a unique name that identify this relationalMapper .
155
11
23,747
public static Attribute attribute ( String name , String customGet , String customSet ) { return new Attribute ( name , customGet , customSet ) ; }
Permits to define an attribute to map .
33
9
23,748
public static TargetAttribute targetAttribute ( String name , String customGet , String customSet ) { return new TargetAttribute ( name , customGet , customSet ) ; }
Permits to define a target attribute .
34
8
23,749
public static LocalAttribute localAttribute ( String name , String customGet , String customSet ) { return new LocalAttribute ( name , customGet , customSet ) ; }
Permits to define a local attribute .
34
8
23,750
public static void error ( Throwable e ) throws JMapperException { logger . error ( "{}: {}" , e . getClass ( ) . getSimpleName ( ) , e . getMessage ( ) ) ; throw new JMapperException ( e ) ; }
This method handles error log .
54
6
23,751
protected final StringBuilder write ( StringBuilder sb , final Object ... objects ) { for ( Object string : objects ) sb . append ( string ) ; return sb ; }
This method adds to the sb the objects .
37
10
23,752
public Method loadMethod ( ) { methodToGenerate = new Method ( ) ; // the method will be created in the mapper membership = Membership . MAPPER ; // class to which it belongs methodToGenerate . setClazz ( configClass ) ; Class < ? > destinationClass = destinationField . getType ( ) ; Class < ? > sourceClass = sourceField . getType ( ) ; // Return Type definition methodToGenerate . setReturnType ( destinationClass ) ; // Parameters type definition switch ( methodDefined . getParameterNumber ( ) ) { case ZERO : methodToGenerate . setParameters ( new Class < ? > [ ] { } ) ; break ; case ONE : methodToGenerate . setParameters ( new Class < ? > [ ] { sourceClass } ) ; break ; case TWO : methodToGenerate . setParameters ( new Class < ? > [ ] { destinationClass , sourceClass } ) ; break ; } // setting of conversion method name methodToGenerate . setOriginalName ( methodDefined . getName ( ) ) ; // Method name definition switch ( methodDefined . getType ( ) ) { case STATIC : methodToGenerate . setName ( definedName ( ) ) ; break ; case DYNAMIC : methodToGenerate . setName ( dynamicName ( ) ) ; break ; } // adds the generated name in the defined method methodDefined . setName ( methodToGenerate . getName ( ) ) ; int count = 1 ; String body = "{try{" ; // Parameters type definition switch ( methodDefined . getParameterNumber ( ) ) { case TWO : String dType = placeholders . get ( destinationTypePattern ) ; String dName = placeholders . get ( destinationPattern ) ; body += dType + " " + dName + " = (" + dType + ") $" + count ++ + ";" + newLine ; case ONE : String sType = placeholders . get ( sourceTypePattern ) ; String sName = placeholders . get ( sourcePattern ) ; body += sType + " " + sName + " = (" + sType + ") $" + count + ";" + newLine ; default : break ; } // Method body definition body += methodDefined . getContent ( ) ; for ( Entry < String , String > pair : placeholders . entrySet ( ) ) // only if the placeholder is used if ( ! isNull ( pair . getValue ( ) ) ) body = body . replaceAll ( pair . getKey ( ) , Matcher . quoteReplacement ( pair . getValue ( ) ) ) ; return methodToGenerate . setBody ( body + "}catch(java.lang.Exception e){" + error ( ) + "}return " + defaultPrimitiveValue ( destinationClass ) + ";}" ) ; }
Loads the method to generate .
598
7
23,753
private String defaultPrimitiveValue ( Class < ? > clazz ) { return clazz == byte . class || clazz == short . class || clazz == int . class ? "0" : clazz == long . class ? "0L" : clazz == float . class ? "0.0f" : clazz == double . class ? "0.0d" : clazz == char . class ? "'\u0000'" : clazz == boolean . class ? "false" : "null" ; }
Returns the default values of primitive types in the form of strings .
110
13
23,754
private String error ( ) { Map < String , List < ConversionMethod > > conversions = xml . conversionsLoad ( ) ; String methodName = "illegalCode" ; String paramater = "" ; String resource = xml . getXmlPath ( ) ; if ( ! isNull ( resource ) ) { boolean isPath = isPath ( resource ) ; methodName = ! isPath ? "illegalCodeContent" : "illegalCode" ; if ( ! conversions . isEmpty ( ) && ! isNull ( conversions . get ( configClass . getName ( ) ) ) ) { // if is a content, the double quotes must be handled if ( ! isPath ) resource = doubleQuotesHandling ( resource ) ; paramater = write ( ",\"" , resource , "\"" ) ; } } return write ( "com.googlecode.jmapper.config.Error#" , methodName , "(e,\"" , methodToGenerate . getOriginalName ( ) , "\",\"" , configClass . getSimpleName ( ) , "\"" , paramater , ");" ) ; }
This method surrounds the explicit conversion defined with a try - catch to handle null pointers .
231
17
23,755
public ConversionHandler load ( ConversionAnalyzer analyzer ) { this . methodDefined = analyzer . getMethod ( ) ; this . membership = analyzer . getMembership ( ) ; this . configClass = membership == Membership . DESTINATION ? destinationClass : sourceClass ; this . configurationType = analyzer . getConfigurationType ( ) ; return this ; }
Loads analyzer configurations
77
5
23,756
public ConversionHandler from ( MappedField sourceMappedField ) { this . sourceField = sourceMappedField . getValue ( ) ; placeholders . put ( sourceTypePattern , sourceField . getType ( ) . getName ( ) ) ; placeholders . put ( sourceNamePattern , sourceField . getName ( ) ) ; placeholders . put ( sourceGetPattern , sourceMappedField . getMethod ( ) ) ; placeholders . put ( sourceSetPattern , sourceMappedField . setMethod ( ) ) ; return this ; }
Source field definition .
114
4
23,757
public ConversionHandler to ( MappedField destinationMappedField ) { this . destinationField = destinationMappedField . getValue ( ) ; placeholders . put ( destinationTypePattern , destinationField . getType ( ) . getName ( ) ) ; placeholders . put ( destinationNamePattern , destinationField . getName ( ) ) ; placeholders . put ( destinationGetPattern , destinationMappedField . getMethod ( ) ) ; placeholders . put ( destinationSetPattern , destinationMappedField . setMethod ( ) ) ; return this ; }
Destination field definition .
114
5
23,758
private static synchronized < D , S > IMapper < D , S > createMapper ( MapperBuilder mapper ) throws Throwable { Class < Mapper < D , S > > mapperClass = mapper . exist ( ) ? mapper . < D , S > get ( ) : mapper . < D , S > generate ( ) ; return mapperClass . newInstance ( ) ; }
This method is synchornized to avoid creations of the same instance
85
14
23,759
public JMapper < D , S > destinationFactory ( DestinationFactory < D > factory ) { this . mapper . setDestinationFactory ( factory ) ; return this ; }
Permits to define a destination factory this is usefull in case of immutable objects .
36
17
23,760
public static boolean isAssignableFrom ( Class < ? > destination , Class < ? > source ) { return destination . isAssignableFrom ( source ) || isBoxing ( destination , source ) || isUnBoxing ( destination , source ) ; }
Returns true if destination is assignable from source analyzing autoboxing also .
54
16
23,761
private static boolean functionsAreAllowed ( boolean isAddAllFunction , boolean isPutAllFunction , Class < ? > classD , Class < ? > classS ) { if ( isAddAllFunction ) return collectionIsAssignableFrom ( classD ) && collectionIsAssignableFrom ( classS ) ; if ( isPutAllFunction ) return mapIsAssignableFrom ( classD ) && mapIsAssignableFrom ( classS ) ; return isAssignableFrom ( classD , classS ) ; }
Returns true if the function to check is allowed .
110
10
23,762
public static String getGenericString ( Field field ) { String fieldDescription = field . toGenericString ( ) ; List < String > splitResult = new ArrayList < String > ( ) ; char [ ] charResult = fieldDescription . toCharArray ( ) ; boolean isFinished = false ; int separatorIndex = fieldDescription . indexOf ( " " ) ; int previousIndex = 0 ; while ( ! isFinished ) { // if previous character is "," don't cut the string int position = separatorIndex - 1 ; char specialChar = charResult [ position ] ; boolean isSpecialChar = true ; if ( specialChar != ' ' && specialChar != ' ' ) { if ( specialChar == ' ' ) { String specialString = null ; try { specialString = fieldDescription . substring ( position - "extends" . length ( ) , position + 1 ) ; if ( isNull ( specialString ) || ! " extends" . equals ( specialString ) ) isSpecialChar = false ; } catch ( IndexOutOfBoundsException e ) { isSpecialChar = false ; } } else isSpecialChar = false ; } if ( ! isSpecialChar ) { splitResult . add ( fieldDescription . substring ( previousIndex , separatorIndex ) ) ; previousIndex = separatorIndex + 1 ; } separatorIndex = fieldDescription . indexOf ( " " , separatorIndex + 1 ) ; if ( separatorIndex == - 1 ) isFinished = true ; } for ( String description : splitResult ) if ( ! isAccessModifier ( description ) ) return description ; return null ; }
Splits the fieldDescription to obtain his class type generics inclusive .
339
14
23,763
public static boolean areEqual ( Field destination , Field source ) { return getGenericString ( destination ) . equals ( getGenericString ( source ) ) ; }
Returns true if destination and source have the same structure .
33
11
23,764
public static String mapperClassName ( Class < ? > destination , Class < ? > source , String resource ) { String className = destination . getName ( ) . replaceAll ( "\\." , "" ) + source . getName ( ) . replaceAll ( "\\." , "" ) ; if ( isEmpty ( resource ) ) return className ; if ( ! isPath ( resource ) ) return write ( className , String . valueOf ( resource . hashCode ( ) ) ) ; String [ ] dep = resource . split ( "\\\\" ) ; if ( dep . length <= 1 ) dep = resource . split ( "/" ) ; String xml = dep [ dep . length - 1 ] ; return write ( className , xml . replaceAll ( "\\." , "" ) . replaceAll ( " " , "" ) ) ; }
Returns the name of mapper that identifies the destination and source classes .
176
14
23,765
public static boolean areMappedObjects ( Class < ? > dClass , Class < ? > sClass , XML xml ) { return isMapped ( dClass , xml ) || isMapped ( sClass , xml ) ; }
returns true if almost one class is configured false otherwise .
49
12
23,766
private static boolean isMapped ( Class < ? > aClass , XML xml ) { return xml . isInheritedMapped ( aClass ) || Annotation . isInheritedMapped ( aClass ) ; }
Returns true if the class is configured in annotation or xml false otherwise .
47
14
23,767
public static List < Class < ? > > getAllsuperClasses ( Class < ? > aClass ) { List < Class < ? > > result = new ArrayList < Class < ? > > ( ) ; result . add ( aClass ) ; Class < ? > superclass = aClass . getSuperclass ( ) ; while ( ! isNull ( superclass ) && superclass != Object . class ) { result . add ( superclass ) ; superclass = superclass . getSuperclass ( ) ; } return result ; }
Returns a list with the class passed in input plus his superclasses .
111
14
23,768
public InfoOperation getInfoOperation ( final Field destination , final Field source ) { Class < ? > dClass = destination . getType ( ) ; Class < ? > sClass = source . getType ( ) ; Class < ? > dItem = null ; Class < ? > sItem = null ; InfoOperation operation = new InfoOperation ( ) . setConversionType ( UNDEFINED ) ; // Array[] = Collection<> if ( dClass . isArray ( ) && collectionIsAssignableFrom ( sClass ) ) { dItem = dClass . getComponentType ( ) ; sItem = getCollectionItemClass ( source ) ; operation . setInstructionType ( ARRAY_LIST ) ; if ( areMappedObjects ( dItem , sItem , xml ) ) return operation . setInstructionType ( ARRAY_LIST_WITH_MAPPED_ITEMS ) . setConfigChosen ( configChosen ( dItem , sItem , xml ) ) ; } // Collection<> = Array[] if ( collectionIsAssignableFrom ( dClass ) && sClass . isArray ( ) ) { dItem = getCollectionItemClass ( destination ) ; sItem = sClass . getComponentType ( ) ; operation . setInstructionType ( LIST_ARRAY ) ; if ( areMappedObjects ( dItem , sItem , xml ) ) return operation . setInstructionType ( LIST_ARRAY_WITH_MAPPED_ITEMS ) . setConfigChosen ( configChosen ( dItem , sItem , xml ) ) ; } if ( isAssignableFrom ( dItem , sItem ) ) return operation . setConversionType ( ABSENT ) ; // if components are primitive or wrapper types, apply implicit conversion if ( areBasic ( dItem , sItem ) ) return operation . setConversionType ( getConversionType ( dItem , sItem ) ) ; return operation ; }
This method calculates and returns information relating the operation to be performed .
411
13
23,769
private MapperConstructor getMapper ( String dName ) { return new MapperConstructor ( destinationType ( ) , sourceType ( ) , dName , dName , getSName ( ) , configChosen , xml , methodsToGenerate ) ; }
Returns a new instance of MapperConstructor
56
9
23,770
public Map < String , String > getMappings ( ) { HashMap < String , String > mappings = new HashMap < String , String > ( ) ; HashMap < String , Boolean > destInstance = new HashMap < String , Boolean > ( ) ; String s = "V" ; destInstance . put ( "null" , true ) ; destInstance . put ( "v" , false ) ; HashMap < String , NullPointerControl > nullPointer = new HashMap < String , NullPointerControl > ( ) ; nullPointer . put ( "Not" , NOT_ANY ) ; nullPointer . put ( "All" , ALL ) ; nullPointer . put ( "Des" , DESTINATION ) ; nullPointer . put ( "Sou" , SOURCE ) ; HashMap < String , MappingType > mapping = new HashMap < String , MappingType > ( ) ; mapping . put ( "All" , ALL_FIELDS ) ; mapping . put ( "Valued" , ONLY_VALUED_FIELDS ) ; mapping . put ( "Null" , ONLY_NULL_FIELDS ) ; java . lang . reflect . Method [ ] methods = IMapper . class . getDeclaredMethods ( ) ; for ( Entry < String , Boolean > d : destInstance . entrySet ( ) ) for ( Entry < String , NullPointerControl > npc : nullPointer . entrySet ( ) ) for ( Entry < String , MappingType > mtd : mapping . entrySet ( ) ) for ( Entry < String , MappingType > mts : mapping . entrySet ( ) ) { String methodName = d . getKey ( ) + s + npc . getKey ( ) + mtd . getKey ( ) + mts . getKey ( ) ; for ( java . lang . reflect . Method method : methods ) if ( method . getName ( ) . equals ( methodName ) ) mappings . put ( methodName , wrappedMapping ( d . getValue ( ) , npc . getValue ( ) , mtd . getValue ( ) , mts . getValue ( ) ) ) ; } mappings . put ( "get" , "return null;" + newLine ) ; return mappings ; }
Returns a Map where the keys are the mappings names and relative values are the mappings .
488
19
23,771
private String wrappedMapping ( boolean makeDest , NullPointerControl npc , MappingType mtd , MappingType mts ) { String sClass = source . getName ( ) ; String dClass = destination . getName ( ) ; String str = ( makeDest ? " " + sClass + " " + stringOfGetSource + " = (" + sClass + ") $1;" : " " + dClass + " " + stringOfGetDestination + " = (" + dClass + ") $1;" + newLine + " " + sClass + " " + stringOfGetSource + " = (" + sClass + ") $2;" ) + newLine ; switch ( npc ) { case SOURCE : str += "if(" + stringOfGetSource + "!=null){" + newLine ; break ; case DESTINATION : str += "if(" + stringOfGetDestination + "!=null){" + newLine ; break ; case ALL : str += "if(" + stringOfGetSource + "!=null && " + stringOfGetDestination + "!=null){" + newLine ; break ; default : break ; } str += mapping ( makeDest , mtd , mts ) + newLine + " return " + stringOfSetDestination + ";" + newLine ; return ( npc != NOT_ANY ) ? str += "}" + newLine + " return null;" + newLine : str ; }
This method adds the Null Pointer Control to mapping created by the mapping method . wrapMapping is used to wrap the mapping returned by mapping method .
317
30
23,772
public StringBuilder mapping ( boolean makeDest , MappingType mtd , MappingType mts ) { StringBuilder sb = new StringBuilder ( ) ; if ( isNullSetting ( makeDest , mtd , mts , sb ) ) return sb ; if ( makeDest ) sb . append ( newInstance ( destination , stringOfSetDestination ) ) ; for ( ASimpleOperation simpleOperation : simpleOperations ) sb . append ( setOperation ( simpleOperation , mtd , mts ) . write ( ) ) ; for ( AComplexOperation complexOperation : complexOperations ) sb . append ( setOperation ( complexOperation , mtd , mts ) . write ( makeDest ) ) ; return sb ; }
This method writes the mapping based on the value of the three MappingType taken in input .
158
19
23,773
private < T extends AGeneralOperation > T setOperation ( T operation , MappingType mtd , MappingType mts ) { operation . setMtd ( mtd ) . setMts ( mts ) . initialDSetPath ( stringOfSetDestination ) . initialDGetPath ( stringOfGetDestination ) . initialSGetPath ( stringOfGetSource ) ; return operation ; }
Setting common to all operations .
85
6
23,774
private boolean isNullSetting ( boolean makeDest , MappingType mtd , MappingType mts , StringBuilder result ) { if ( makeDest && ( mtd == ALL_FIELDS || mtd == ONLY_VALUED_FIELDS ) && mts == ONLY_NULL_FIELDS ) { result . append ( " " + stringOfSetDestination + "(null);" + newLine ) ; return true ; } return false ; }
if it is a null setting returns the null mapping
98
10
23,775
private final StringBuilder genericFlow ( boolean newInstance ) { // if newInstance is true or mapping type of newField is ONLY_NULL_FIELDS // write the mapping for the new field if ( newInstance || getMtd ( ) == ONLY_NULL_FIELDS ) return sourceControl ( fieldToCreate ( ) ) ; // if is enrichment case and mapping type of destination is ALL_FIELDS if ( getMtd ( ) == ALL_FIELDS && ! destinationType ( ) . isPrimitive ( ) ) return write ( " if(" , getDestination ( ) , "!=null){" , newLine , sourceControl ( existingField ( ) ) , " }else{" , newLine , sourceControl ( fieldToCreate ( ) ) , " }" , newLine ) ; // other cases return sourceControl ( existingField ( ) ) ; }
This method specifies the general flow of the complex mapping .
184
11
23,776
private StringBuilder sourceControl ( StringBuilder mapping ) { if ( getMts ( ) == ALL_FIELDS && ! sourceType ( ) . isPrimitive ( ) ) { StringBuilder write = write ( " if(" , getSource ( ) , "!=null){" , newLine , sharedCode ( mapping ) , newLine , " }" ) ; if ( ! destinationType ( ) . isPrimitive ( ) && ! avoidSet ) write . append ( write ( "else{" , newLine , setDestination ( "null" ) , newLine , " }" , newLine ) ) ; else write . append ( newLine ) ; return write ; } else return write ( sharedCode ( mapping ) , newLine ) ; }
This method is used when the MappingType of Source is setting to ALL .
157
16
23,777
@ Deprecated public static Redirect moved ( String url , Object ... args ) { touchPayload ( ) . message ( url , args ) ; return _INSTANCE ; }
This method is deprecated
36
4
23,778
public Binder < T > attribute ( String key , Object value ) { if ( null == value ) { attributes . remove ( value ) ; } else { attributes . put ( key , value ) ; } return this ; }
Set attribute of this binder .
46
7
23,779
public Binder < T > attributes ( Map < String , Object > attributes ) { this . attributes . putAll ( attributes ) ; return this ; }
Set attributes to this binder
31
6
23,780
static boolean isPortAvailable ( int port ) { ServerSocket ss = null ; try { ss = new ServerSocket ( port ) ; ss . setReuseAddress ( true ) ; return true ; } catch ( IOException ioe ) { // NOSONAR return false ; } finally { closeQuietly ( ss ) ; } }
Find out if the provided port is available .
70
9
23,781
public RenderBinary name ( String attachmentName ) { this . name = attachmentName ; this . disposition = Disposition . of ( S . notBlank ( attachmentName ) ) ; return this ; }
Set the attachment name .
42
5
23,782
private static void addNonHeapMetrics ( Collection < Metric < ? > > result ) { MemoryUsage memoryUsage = ManagementFactory . getMemoryMXBean ( ) . getNonHeapMemoryUsage ( ) ; result . add ( newMemoryMetric ( "nonheap.committed" , memoryUsage . getCommitted ( ) ) ) ; result . add ( newMemoryMetric ( "nonheap.init" , memoryUsage . getInit ( ) ) ) ; result . add ( newMemoryMetric ( "nonheap.used" , memoryUsage . getUsed ( ) ) ) ; result . add ( newMemoryMetric ( "nonheap" , memoryUsage . getMax ( ) ) ) ; }
Add JVM non - heap metrics .
155
8
23,783
protected void addBasicMetrics ( Collection < Metric < ? > > result ) { // NOTE: ManagementFactory must not be used here since it fails on GAE Runtime runtime = Runtime . getRuntime ( ) ; result . add ( newMemoryMetric ( "mem" , runtime . totalMemory ( ) + getTotalNonHeapMemoryIfPossible ( ) ) ) ; result . add ( newMemoryMetric ( "mem.free" , runtime . freeMemory ( ) ) ) ; result . add ( new Metric <> ( "processors" , runtime . availableProcessors ( ) ) ) ; result . add ( new Metric <> ( "instance.uptime" , System . currentTimeMillis ( ) - this . timestamp ) ) ; }
Add basic system metrics .
160
5
23,784
protected void addClassLoadingMetrics ( Collection < Metric < ? > > result ) { ClassLoadingMXBean classLoadingMxBean = ManagementFactory . getClassLoadingMXBean ( ) ; result . add ( new Metric <> ( "classes" , ( long ) classLoadingMxBean . getLoadedClassCount ( ) ) ) ; result . add ( new Metric <> ( "classes.loaded" , classLoadingMxBean . getTotalLoadedClassCount ( ) ) ) ; result . add ( new Metric <> ( "classes.unloaded" , classLoadingMxBean . getUnloadedClassCount ( ) ) ) ; }
Add class loading metrics .
146
5
23,785
protected void addGarbageCollectionMetrics ( Collection < Metric < ? > > result ) { List < GarbageCollectorMXBean > garbageCollectorMxBeans = ManagementFactory . getGarbageCollectorMXBeans ( ) ; for ( GarbageCollectorMXBean garbageCollectorMXBean : garbageCollectorMxBeans ) { String name = beautifyGcName ( garbageCollectorMXBean . getName ( ) ) ; result . add ( new Metric <> ( "gc." + name + ".count" , garbageCollectorMXBean . getCollectionCount ( ) ) ) ; result . add ( new Metric <> ( "gc." + name + ".time" , garbageCollectorMXBean . getCollectionTime ( ) ) ) ; } }
Add garbage collection metrics .
171
5
23,786
protected void addHeapMetrics ( Collection < Metric < ? > > result ) { MemoryUsage memoryUsage = ManagementFactory . getMemoryMXBean ( ) . getHeapMemoryUsage ( ) ; result . add ( newMemoryMetric ( "heap.committed" , memoryUsage . getCommitted ( ) ) ) ; result . add ( newMemoryMetric ( "heap.init" , memoryUsage . getInit ( ) ) ) ; result . add ( newMemoryMetric ( "heap.used" , memoryUsage . getUsed ( ) ) ) ; result . add ( newMemoryMetric ( "heap" , memoryUsage . getMax ( ) ) ) ; }
Add JVM heap metrics .
148
6
23,787
protected void addThreadMetrics ( Collection < Metric < ? > > result ) { ThreadMXBean threadMxBean = ManagementFactory . getThreadMXBean ( ) ; result . add ( new Metric <> ( "threads.peak" , ( long ) threadMxBean . getPeakThreadCount ( ) ) ) ; result . add ( new Metric <> ( "threads.daemon" , ( long ) threadMxBean . getDaemonThreadCount ( ) ) ) ; result . add ( new Metric <> ( "threads.totalStarted" , threadMxBean . getTotalStartedThreadCount ( ) ) ) ; result . add ( new Metric <> ( "threads" , ( long ) threadMxBean . getThreadCount ( ) ) ) ; }
Add thread metrics .
181
4
23,788
private void addManagementMetrics ( Collection < Metric < ? > > result ) { try { // Add JVM up time in ms result . add ( new Metric <> ( "uptime" , ManagementFactory . getRuntimeMXBean ( ) . getUptime ( ) ) ) ; result . add ( new Metric <> ( "systemload.average" , ManagementFactory . getOperatingSystemMXBean ( ) . getSystemLoadAverage ( ) ) ) ; this . addHeapMetrics ( result ) ; addNonHeapMetrics ( result ) ; this . addThreadMetrics ( result ) ; this . addClassLoadingMetrics ( result ) ; this . addGarbageCollectionMetrics ( result ) ; } catch ( NoClassDefFoundError ex ) { // Expected on Google App Engine } }
Add metrics from ManagementFactory if possible . Note that ManagementFactory is not available on Google App Engine .
176
20
23,789
public void invoke ( StartupLifecycle lifecycle ) { this . initializeAsciiLogo ( ) ; this . printLogo ( ) ; lifecycle . willInitialize ( ) ; this . logInitializationStart ( ) ; lifecycle . willCreateSpringContext ( ) ; this . initializeApplicationContext ( ) ; lifecycle . didCreateSpringContext ( this . context ) ; this . initializeVersionProvider ( ) ; this . initializeSystemInfo ( ) ; this . initializeProfile ( ) ; this . initializeExternalProperties ( ) ; this . initializePropertyPlaceholderConfigurer ( ) ; this . initializeSpark ( ) ; lifecycle . willCreateDefaultSparkRoutes ( this . context ) ; this . initializeJsonTransformer ( ) ; this . initializeDefaultResources ( ) ; this . initializeActuators ( ) ; lifecycle . willScanForComponents ( this . context ) ; this . initializeSpringComponentScan ( ) ; lifecycle . willRefreshSpringContext ( this . context ) ; this . refreshApplicationContext ( ) ; this . completeSystemInfoInitialization ( ) ; lifecycle . didInitializeSpring ( this . context ) ; this . enableApplicationReloading ( ) ; Optional < CharSequence > statusMessages = lifecycle . didInitialize ( ) ; this . logInitializationFinished ( statusMessages ) ; }
Start the Indoqa - Boot application and hook into the startup lifecycle .
286
15
23,790
public static void save ( ) { H . Response resp = H . Response . current ( ) ; H . Session session = H . Session . current ( ) ; serialize ( session ) ; H . Flash flash = H . Flash . current ( ) ; serialize ( flash ) ; }
Persist session and flash to cookie write all cookies to http response
59
13
23,791
private Connection connect ( ) throws SQLException { if ( DefaultContentLoader . localDataSource == null ) { LOG . error ( "Data Source is null" ) ; return null ; } final Connection conn = DataSourceUtils . getConnection ( DefaultContentLoader . localDataSource ) ; if ( conn == null ) { LOG . error ( "Connection is null" ) ; } return conn ; }
Establish a connection to underlying db .
84
8
23,792
protected RequestData initializeRequestData ( final MessageContext messageContext ) { RequestData requestData = new RequestData ( ) ; requestData . setMsgContext ( messageContext ) ; // reads securementUsername first from the context then from the property String contextUsername = ( String ) messageContext . getProperty ( SECUREMENT_USER_PROPERTY_NAME ) ; if ( StringUtils . hasLength ( contextUsername ) ) { requestData . setUsername ( contextUsername ) ; } else { requestData . setUsername ( securementUsername ) ; } requestData . setAppendSignatureAfterTimestamp ( true ) ; requestData . setTimeStampTTL ( securementTimeToLive ) ; requestData . setWssConfig ( wssConfig ) ; return requestData ; }
Creates and initializes a request data for the given message context .
171
14
23,793
protected void checkResults ( final List < WSSecurityEngineResult > results , final List < Integer > validationActions ) throws Wss4jSecurityValidationException { if ( ! handler . checkReceiverResultsAnyOrder ( results , validationActions ) ) { throw new Wss4jSecurityValidationException ( "Security processing failed (actions mismatch)" ) ; } }
Checks whether the received headers match the configured validation actions . Subclasses could override this method for custom verification behavior .
79
23
23,794
@ SuppressWarnings ( "unchecked" ) private void updateContextWithResults ( final MessageContext messageContext , final WSHandlerResult result ) { List < WSHandlerResult > handlerResults ; if ( ( handlerResults = ( List < WSHandlerResult > ) messageContext . getProperty ( WSHandlerConstants . RECV_RESULTS ) ) == null ) { handlerResults = new ArrayList < WSHandlerResult > ( ) ; messageContext . setProperty ( WSHandlerConstants . RECV_RESULTS , handlerResults ) ; } handlerResults . add ( 0 , result ) ; messageContext . setProperty ( WSHandlerConstants . RECV_RESULTS , handlerResults ) ; }
Puts the results of WS - Security headers processing in the message context . Some actions like Signature Confirmation require this .
156
24
23,795
protected void verifyCertificateTrust ( WSHandlerResult result ) throws WSSecurityException { List < WSSecurityEngineResult > signResults = result . getActionResults ( ) . getOrDefault ( WSConstants . SIGN , emptyList ( ) ) ; if ( signResults . isEmpty ( ) ) { throw new Wss4jSecurityValidationException ( "No action results for 'Perform Signature' found" ) ; } else if ( signResults . size ( ) > 1 ) { throw new Wss4jSecurityValidationException ( "Multiple action results for 'Perform Signature' found. Expected only 1." ) ; } WSSecurityEngineResult signResult = signResults . get ( 0 ) ; if ( signResult != null ) { X509Certificate returnCert = ( X509Certificate ) signResult . get ( WSSecurityEngineResult . TAG_X509_CERTIFICATE ) ; Credential credential = new Credential ( ) ; credential . setCertificates ( new X509Certificate [ ] { returnCert } ) ; RequestData requestData = new RequestData ( ) ; requestData . setSigVerCrypto ( validationSignatureCrypto ) ; requestData . setEnableRevocation ( enableRevocation ) ; requestData . setSubjectCertConstraints ( OrgnummerExtractor . PATTERNS ) ; SignatureTrustValidator validator = new SignatureTrustValidator ( ) ; validator . validate ( credential , requestData ) ; } }
Verifies the trust of a certificate .
321
8
23,796
protected void verifyTimestamp ( WSHandlerResult result ) throws WSSecurityException { List < WSSecurityEngineResult > insertTimestampResults = result . getActionResults ( ) . getOrDefault ( WSConstants . TS , emptyList ( ) ) ; if ( insertTimestampResults . isEmpty ( ) ) { throw new Wss4jSecurityValidationException ( "No action results for 'Insert timestamp' found" ) ; } else if ( insertTimestampResults . size ( ) > 1 ) { throw new Wss4jSecurityValidationException ( "Multiple action results for 'Insert timestamp' found. Expected only 1." ) ; } WSSecurityEngineResult actionResult = insertTimestampResults . get ( 0 ) ; if ( actionResult != null ) { Timestamp timestamp = ( Timestamp ) actionResult . get ( WSSecurityEngineResult . TAG_TIMESTAMP ) ; if ( timestamp != null && timestampStrict ) { Credential credential = new Credential ( ) ; credential . setTimestamp ( timestamp ) ; RequestData requestData = new RequestData ( ) ; requestData . setWssConfig ( WSSConfig . getNewInstance ( ) ) ; requestData . setTimeStampTTL ( validationTimeToLive ) ; requestData . setTimeStampStrict ( timestampStrict ) ; TimestampValidator validator = new TimestampValidator ( ) ; validator . validate ( credential , requestData ) ; } } }
Verifies the timestamp .
318
5
23,797
public static void addMissingColumns ( SQLiteDatabase database , Class contractClass ) { Contract contract = new Contract ( contractClass ) ; Cursor cursor = database . rawQuery ( "PRAGMA table_info(" + contract . getTable ( ) + ")" , null ) ; for ( ContractField field : contract . getFields ( ) ) { if ( ! fieldExistAsColumn ( field . name , cursor ) ) { database . execSQL ( "ALTER TABLE " + contract . getTable ( ) + " ADD COLUMN " + field . name + " " + field . type + ";" ) ; } } }
Adds missing table columns for the given contract class .
134
10
23,798
public TableBuilder addConstraint ( String columnName , String constraintType , String constraintConflictClause ) { constraints . add ( new Constraint ( columnName , constraintType , constraintConflictClause ) ) ; return this ; }
Adds the specified constraint to the created table .
51
9
23,799
@ Deprecated public static Predicate < ColumnModel > allOf ( final Predicate < ColumnModel > ... conditions ) { return ( cM ) - > Arrays . stream ( conditions ) . allMatch ( c -> c . test ( cM ) ) ; }
A condition that returns true if all of the provided conditions return true . Equivalent to logical AND operator .
55
21