idx
int64
0
165k
question
stringlengths
73
5.81k
target
stringlengths
5
918
4,700
public static Expression createExpression ( String expression ) { try { return INSTANCE . ctorExpression . newInstance ( expression ) ; } catch ( Exception e ) { throw new RuntimeException ( e ) ; } }
Creates a default expression instance .
4,701
public static Extractor createExtractor ( String expression ) { try { return INSTANCE . ctorExtractor . newInstance ( expression ) ; } catch ( Exception e ) { throw new RuntimeException ( e ) ; } }
Creates a default extractor instance .
4,702
public static Updater createUpdater ( String expression ) { try { return INSTANCE . ctorUpdater . newInstance ( expression ) ; } catch ( Exception e ) { throw new RuntimeException ( e ) ; } }
Creates a default updater instance .
4,703
public static Condition createCondition ( String expression ) { try { return INSTANCE . ctorCondition . newInstance ( expression ) ; } catch ( Exception e ) { throw new RuntimeException ( e ) ; } }
Creates a default condition instance .
4,704
protected Constructor getConstructor ( Class type ) { try { return type . getConstructor ( String . class ) ; } catch ( NoSuchMethodException e ) { throw new RuntimeException ( "Unable to find a constructor that accepts" + " a single String argument in the " + type . getName ( ) + " class." , e ) ; } }
Gets a constructor for the specified class that accepts a single String argument .
4,705
public static EngineeringObjectModelWrapper enhance ( AdvancedModelWrapper model ) { if ( ! model . isEngineeringObject ( ) ) { throw new IllegalArgumentException ( "The model of the AdvancedModelWrapper is no EngineeringObject" ) ; } return new EngineeringObjectModelWrapper ( model . getUnderlyingModel ( ) ) ; }
Returns the corresponding engineering object model wrapper to the given advanced model wrapper .
4,706
public List < Field > getForeignKeyFields ( ) { List < Field > fields = new ArrayList < Field > ( ) ; for ( Field field : model . getClass ( ) . getDeclaredFields ( ) ) { if ( field . isAnnotationPresent ( OpenEngSBForeignKey . class ) ) { fields . add ( field ) ; } } return fields ; }
Returns a list of foreign key fields for the Engineering Object model .
4,707
public AdvancedModelWrapper loadReferencedModel ( Field field , ModelRegistry modelRegistry , EngineeringDatabaseService edbService , EDBConverter edbConverter ) { try { ModelDescription description = getModelDescriptionFromField ( field ) ; String modelKey = ( String ) FieldUtils . readField ( field , model , true ) ; if ( modelKey == null ) { return null ; } modelKey = appendContextId ( modelKey ) ; Class < ? > sourceClass = modelRegistry . loadModel ( description ) ; Object model = edbConverter . convertEDBObjectToModel ( sourceClass , edbService . getObject ( modelKey ) ) ; return new AdvancedModelWrapper ( ( OpenEngSBModel ) model ) ; } catch ( SecurityException e ) { throw new EKBException ( generateErrorMessage ( field ) , e ) ; } catch ( IllegalArgumentException e ) { throw new EKBException ( generateErrorMessage ( field ) , e ) ; } catch ( IllegalAccessException e ) { throw new EKBException ( generateErrorMessage ( field ) , e ) ; } catch ( ClassNotFoundException e ) { throw new EKBException ( generateErrorMessage ( field ) , e ) ; } }
Loads the model referenced by the given field for the given model instance . Returns null if the field has no value set .
4,708
private ModelDescription getModelDescriptionFromField ( Field field ) { OpenEngSBForeignKey key = field . getAnnotation ( OpenEngSBForeignKey . class ) ; ModelDescription description = new ModelDescription ( key . modelType ( ) , key . modelVersion ( ) ) ; return description ; }
Generates the model description of a field which is annotated with the OpenEngSBForeignKey annotation .
4,709
public synchronized Long generateId ( ) { if ( sequenceBlock == null || ! sequenceBlock . hasNext ( ) ) { sequenceBlock = allocateSequenceBlock ( ) ; } return sequenceBlock . next ( ) ; }
Return the next number in the sequence .
4,710
private String performRemoveLeading ( String source , Integer length , Matcher matcher ) { if ( length != null && length != 0 ) { matcher . region ( 0 , length ) ; } if ( matcher . find ( ) ) { String matched = matcher . group ( ) ; return source . substring ( matched . length ( ) ) ; } return source ; }
Perform the remove leading operation . Returns the original string if the matcher does not match with the string
4,711
public void set ( float radians ) { float c = ( float ) StrictMath . cos ( radians ) ; float s = ( float ) StrictMath . sin ( radians ) ; m00 = c ; m01 = - s ; m10 = s ; m11 = c ; }
Sets this matrix to a rotation matrix with the given radians .
4,712
protected DataType put ( Class < ? > clazz , int type , String name ) { DataType dataType = new DataType ( type , name ) ; map . put ( clazz , dataType ) ; return dataType ; }
Create a new DataType instance for the given type and name and place it in the map with the given Class as key .
4,713
public static byte [ ] decrypt ( byte [ ] text , Key key ) throws DecryptionException { return decrypt ( text , key , key . getAlgorithm ( ) ) ; }
Decrypts the given data using the given key . The key holds the algorithm used for decryption . If you are decrypting data that is supposed to be a string consider that it might be Base64 - encoded .
4,714
public static byte [ ] decrypt ( byte [ ] text , Key key , String algorithm ) throws DecryptionException { Cipher cipher ; try { LOGGER . trace ( "start decrypting text using {} cipher" , algorithm ) ; cipher = Cipher . getInstance ( algorithm ) ; cipher . init ( Cipher . DECRYPT_MODE , key ) ; LOGGER . trace ( "initialized decryption with key of type {}" , key . getClass ( ) ) ; } catch ( GeneralSecurityException e ) { throw new IllegalArgumentException ( "unable to initialize cipher for algorithm " + algorithm , e ) ; } try { return cipher . doFinal ( text ) ; } catch ( GeneralSecurityException e ) { throw new DecryptionException ( "unable to decrypt data using algorithm " + algorithm , e ) ; } }
Decrypts the given data using the given key using the given algorithm . If you are decrypting data that is supposed to be a string consider that it might be Base64 - encoded .
4,715
public static byte [ ] encrypt ( byte [ ] text , Key key ) throws EncryptionException { return encrypt ( text , key , key . getAlgorithm ( ) ) ; }
Encrypts the given data using the given key . The key holds the algorithm used for encryption . If you are encrypting data that is supposed to be a string consider that it might be Base64 - encoded .
4,716
public static byte [ ] encrypt ( byte [ ] text , Key key , String algorithm ) throws EncryptionException { Cipher cipher ; try { LOGGER . trace ( "start encrypting text using {} cipher" , algorithm ) ; cipher = Cipher . getInstance ( algorithm ) ; cipher . init ( Cipher . ENCRYPT_MODE , key ) ; LOGGER . trace ( "initialized encryption with key of type {}" , key . getClass ( ) ) ; } catch ( GeneralSecurityException e ) { throw new IllegalArgumentException ( "unable to initialize cipher for algorithm " + algorithm , e ) ; } try { return cipher . doFinal ( text ) ; } catch ( GeneralSecurityException e ) { throw new EncryptionException ( "unable to encrypt data using algorithm " + algorithm , e ) ; } }
Encrypts the given data using the given key using the given algorithm . If you are encrypting data that is supposed to be a string consider encoding it in Base64 .
4,717
public static byte [ ] sign ( byte [ ] text , PrivateKey key , String algorithm ) throws SignatureException { Signature signature ; try { signature = Signature . getInstance ( algorithm ) ; signature . initSign ( key ) ; } catch ( GeneralSecurityException e ) { throw new IllegalArgumentException ( "cannot initialize signature for algorithm " + algorithm , e ) ; } signature . update ( text ) ; return signature . sign ( ) ; }
create a signature for the given text using the PrivateKey and algorithm
4,718
public static boolean verify ( byte [ ] text , byte [ ] signatureValue , PublicKey key , String algorithm ) throws SignatureException { Signature signature ; try { signature = Signature . getInstance ( algorithm ) ; signature . initVerify ( key ) ; } catch ( GeneralSecurityException e ) { throw new IllegalArgumentException ( "cannot initialize signature for algorithm " + algorithm , e ) ; } signature . update ( text ) ; return signature . verify ( signatureValue ) ; }
verifies if the given data is valid for the given signature and public key .
4,719
protected synchronized Object getCompiledExpression ( ) { if ( compiledExpression == null ) { try { compiledExpression = Ognl . parseExpression ( getExpression ( ) ) ; } catch ( OgnlException e ) { throw new IllegalArgumentException ( "[" + getExpression ( ) + "] is not a valid OGNL expression" , e ) ; } } return compiledExpression ; }
Return a compiled OGNL expression .
4,720
public static < T > T view ( Object completeObject , T viewObject ) { if ( completeObject == null ) return null ; Map < String , PropertyInterface > propertiesOfCompleteObject = FlatProperties . getProperties ( completeObject . getClass ( ) ) ; Map < String , PropertyInterface > properties = FlatProperties . getProperties ( viewObject . getClass ( ) ) ; for ( Map . Entry < String , PropertyInterface > entry : properties . entrySet ( ) ) { PropertyInterface property = propertiesOfCompleteObject . get ( entry . getKey ( ) ) ; Object value = property != null ? property . getValue ( completeObject ) : readByGetMethod ( completeObject , entry . getKey ( ) ) ; entry . getValue ( ) . setValue ( viewObject , value ) ; } return viewObject ; }
Creates a view to a complete object . Meaning all fields existing on view and the complete object are copied from the complete object to the view .
4,721
public static < T > T viewed ( View < T > viewObject ) { if ( viewObject == null ) return null ; @ SuppressWarnings ( "unchecked" ) Class < T > viewedClass = ( Class < T > ) getViewedClass ( viewObject . getClass ( ) ) ; Object id = IdUtils . getId ( viewObject ) ; if ( id == null ) { return null ; } return Backend . read ( viewedClass , id ) ; }
Resolves a view object to the real object . Of course this is only possible by asking the Backend to read the complete object . This method expects the view to have an id .
4,722
public static ModelDiff createModelDiff ( OpenEngSBModel before , OpenEngSBModel after ) { ModelDiff diff = new ModelDiff ( before , after ) ; calculateDifferences ( diff ) ; return diff ; }
Creates an instance of the ModelDiff class based on the both models which are passed to the function . It instantiate the class and calculates the differences of this two models .
4,723
public static ModelDiff createModelDiff ( OpenEngSBModel updated , String completeModelId , EngineeringDatabaseService edbService , EDBConverter edbConverter ) { EDBObject queryResult = edbService . getObject ( completeModelId ) ; OpenEngSBModel old = edbConverter . convertEDBObjectToModel ( updated . getClass ( ) , queryResult ) ; ModelDiff diff = new ModelDiff ( old , updated ) ; calculateDifferences ( diff ) ; return diff ; }
Creates an instance of the ModelDiff class based on the given model . It loads the old status of the model and calculates the differences of this two models .
4,724
private static void calculateDifferences ( ModelDiff diff ) { Class < ? > modelClass = diff . getBefore ( ) . getClass ( ) ; for ( Field field : modelClass . getDeclaredFields ( ) ) { if ( field . getName ( ) . equals ( ModelUtils . MODEL_TAIL_FIELD_NAME ) ) { continue ; } try { Object before = FieldUtils . readField ( field , diff . getBefore ( ) , true ) ; Object after = FieldUtils . readField ( field , diff . getAfter ( ) , true ) ; if ( ! Objects . equal ( before , after ) ) { diff . addDifference ( field , before , after ) ; } } catch ( IllegalAccessException e ) { LOGGER . warn ( "Skipped field '{}' because of illegal access to it" , field . getName ( ) , e ) ; } } }
Calculates the real differences between the two models of the given ModelDiff and saves them to the differences field of the ModelDiff class .
4,725
public void addDifference ( Field field , Object before , Object after ) { ModelDiffEntry entry = new ModelDiffEntry ( ) ; entry . setBefore ( before ) ; entry . setAfter ( after ) ; entry . setField ( field ) ; differences . put ( field , entry ) ; }
Adds a difference to the list of differences of this ModelDiff instance .
4,726
public boolean isForeignKeyChanged ( ) { return CollectionUtils . exists ( differences . values ( ) , new Predicate ( ) { public boolean evaluate ( Object object ) { return ( ( ModelDiffEntry ) object ) . isForeignKey ( ) ; } } ) ; }
Returns true if one of the differences of this ModelDiff instance is an OpenEngSBForeignKey . Returns false otherwise .
4,727
public boolean containsPoint ( Coordinate point ) { Point p = new GeometryFactory ( ) . createPoint ( point ) ; return this . getGeometry ( ) . contains ( p ) ; }
Check whether this polygon contains a given point .
4,728
public static < ReturnType > ReturnType executeWithSystemPermissions ( Callable < ReturnType > task ) throws ExecutionException { ContextAwareCallable < ReturnType > contextAwareCallable = new ContextAwareCallable < ReturnType > ( task ) ; Subject newsubject = new Subject . Builder ( ) . buildSubject ( ) ; newsubject . login ( new RootAuthenticationToken ( ) ) ; try { return newsubject . execute ( contextAwareCallable ) ; } finally { newsubject . logout ( ) ; } }
Executes the given task with root - permissions . Use with care .
4,729
public static void executeWithSystemPermissions ( Runnable task ) { ContextAwareRunnable contextAwaretask = new ContextAwareRunnable ( task ) ; Subject newsubject = new Subject . Builder ( ) . buildSubject ( ) ; newsubject . login ( new RootAuthenticationToken ( ) ) ; try { newsubject . execute ( contextAwaretask ) ; } finally { newsubject . logout ( ) ; } }
wraps an existing ExecutorService to handle context - and security - related threadlocal variables
4,730
public static ExecutorService getSecurityContextAwareExecutor ( ExecutorService original ) { SubjectAwareExecutorService subjectAwareExecutor = new SubjectAwareExecutorService ( original ) ; return ThreadLocalUtil . contextAwareExecutor ( subjectAwareExecutor ) ; }
Wrap the given executor so that it takes authentication - information and context are inherited to tasks when they are submitted .
4,731
public static < BeanType > BeanType createBeanFromAttributeMap ( Class < BeanType > beanType , Map < String , ? extends Object > attributeValues ) { BeanType instance ; try { instance = beanType . newInstance ( ) ; BeanUtils . populate ( instance , attributeValues ) ; } catch ( Exception e ) { ReflectionUtils . handleReflectionException ( e ) ; throw new IllegalStateException ( "Should never get here" ) ; } return instance ; }
Creates a new instance of the beanType and populates it with the property - values from the map
4,732
public synchronized void reloadRulebase ( ) throws RuleBaseException { long start = System . currentTimeMillis ( ) ; reloadDeclarations ( ) ; packageStrings . clear ( ) ; for ( RuleBaseElementId id : manager . listAll ( RuleBaseElementType . Function ) ) { String packageName = id . getPackageName ( ) ; StringBuffer packageString = getPackageString ( packageName ) ; String code = manager . get ( id ) ; packageString . append ( code ) ; } for ( RuleBaseElementId id : manager . listAll ( RuleBaseElementType . Rule ) ) { String packageName = id . getPackageName ( ) ; StringBuffer packageString = getPackageString ( packageName ) ; String code = manager . get ( id ) ; String formattedRule = String . format ( RULE_TEMPLATE , id . getName ( ) , code ) ; packageString . append ( formattedRule ) ; } for ( RuleBaseElementId id : manager . listAll ( RuleBaseElementType . Process ) ) { getPackageString ( id . getPackageName ( ) ) ; } Collection < KnowledgePackage > compiledPackages = new HashSet < KnowledgePackage > ( ) ; if ( packageStrings . isEmpty ( ) ) { Set < String > emptySet = Collections . emptySet ( ) ; compiledPackages . addAll ( compileDrlString ( "package dummy;\n" + declarations , emptySet ) ) ; } else { for ( Map . Entry < String , StringBuffer > entry : packageStrings . entrySet ( ) ) { String packageName = entry . getKey ( ) ; StringBuffer drlCode = entry . getValue ( ) ; Collection < String > flows = queryFlows ( packageName ) ; Collection < KnowledgePackage > compiledDrlPackage = compileDrlString ( drlCode . toString ( ) , flows ) ; compiledPackages . addAll ( compiledDrlPackage ) ; } } lockRuleBase ( ) ; clearRulebase ( ) ; base . addKnowledgePackages ( compiledPackages ) ; unlockRuleBase ( ) ; LOGGER . info ( "Reloading the rulebase took {}ms" , System . currentTimeMillis ( ) - start ) ; }
reloads the rulebase but keeps references intact
4,733
@ SuppressWarnings ( "unchecked" ) public < T > T convertEDBObjectToModel ( Class < T > model , EDBObject object ) { return ( T ) convertEDBObjectToUncheckedModel ( model , object ) ; }
Converts an EDBObject to a model of the given model type .
4,734
public < T > List < T > convertEDBObjectsToModelObjects ( Class < T > model , List < EDBObject > objects ) { List < T > models = new ArrayList < > ( ) ; for ( EDBObject object : objects ) { T instance = convertEDBObjectToModel ( model , object ) ; if ( instance != null ) { models . add ( instance ) ; } } return models ; }
Converts a list of EDBObjects to a list of models of the given model type .
4,735
private boolean checkEDBObjectModelType ( EDBObject object , Class < ? > model ) { String modelClass = object . getString ( EDBConstants . MODEL_TYPE ) ; if ( modelClass == null ) { LOGGER . warn ( String . format ( "The EDBObject with the oid %s has no model type information." + "The resulting model may be a different model type than expected." , object . getOID ( ) ) ) ; } if ( modelClass != null && ! modelClass . equals ( model . getName ( ) ) ) { return false ; } return true ; }
Tests if an EDBObject has the correct model class in which it should be converted . Returns false if the model type is not fitting returns true if the model type is fitting or model type is unknown .
4,736
private Object convertEDBObjectToUncheckedModel ( Class < ? > model , EDBObject object ) { if ( ! checkEDBObjectModelType ( object , model ) ) { return null ; } filterEngineeringObjectInformation ( object , model ) ; List < OpenEngSBModelEntry > entries = new ArrayList < > ( ) ; for ( PropertyDescriptor propertyDescriptor : getPropertyDescriptorsForClass ( model ) ) { if ( propertyDescriptor . getWriteMethod ( ) == null || propertyDescriptor . getName ( ) . equals ( ModelUtils . MODEL_TAIL_FIELD_NAME ) ) { continue ; } Object value = getValueForProperty ( propertyDescriptor , object ) ; Class < ? > propertyClass = propertyDescriptor . getPropertyType ( ) ; if ( propertyClass . isPrimitive ( ) ) { entries . add ( new OpenEngSBModelEntry ( propertyDescriptor . getName ( ) , value , ClassUtils . primitiveToWrapper ( propertyClass ) ) ) ; } else { entries . add ( new OpenEngSBModelEntry ( propertyDescriptor . getName ( ) , value , propertyClass ) ) ; } } for ( Map . Entry < String , EDBObjectEntry > objectEntry : object . entrySet ( ) ) { EDBObjectEntry entry = objectEntry . getValue ( ) ; Class < ? > entryType ; try { entryType = model . getClassLoader ( ) . loadClass ( entry . getType ( ) ) ; entries . add ( new OpenEngSBModelEntry ( entry . getKey ( ) , entry . getValue ( ) , entryType ) ) ; } catch ( ClassNotFoundException e ) { LOGGER . error ( "Unable to load class {} of the model tail" , entry . getType ( ) ) ; } } return ModelUtils . createModel ( model , entries ) ; }
Converts an EDBObject to a model by analyzing the object and trying to call the corresponding setters of the model .
4,737
private List < PropertyDescriptor > getPropertyDescriptorsForClass ( Class < ? > clasz ) { try { BeanInfo beanInfo = Introspector . getBeanInfo ( clasz ) ; return Arrays . asList ( beanInfo . getPropertyDescriptors ( ) ) ; } catch ( IntrospectionException e ) { LOGGER . error ( "instantiation exception while trying to create instance of class {}" , clasz . getName ( ) ) ; } return Lists . newArrayList ( ) ; }
Returns all property descriptors for a given class .
4,738
private Object getValueForProperty ( PropertyDescriptor propertyDescriptor , EDBObject object ) { Method setterMethod = propertyDescriptor . getWriteMethod ( ) ; String propertyName = propertyDescriptor . getName ( ) ; Object value = object . getObject ( propertyName ) ; Class < ? > parameterType = setterMethod . getParameterTypes ( ) [ 0 ] ; if ( Map . class . isAssignableFrom ( parameterType ) ) { List < Class < ? > > classes = getGenericMapParameterClasses ( setterMethod ) ; value = getMapValue ( classes . get ( 0 ) , classes . get ( 1 ) , propertyName , object ) ; } else if ( List . class . isAssignableFrom ( parameterType ) ) { Class < ? > clazz = getGenericListParameterClass ( setterMethod ) ; value = getListValue ( clazz , propertyName , object ) ; } else if ( parameterType . isArray ( ) ) { Class < ? > clazz = parameterType . getComponentType ( ) ; value = getArrayValue ( clazz , propertyName , object ) ; } else if ( value == null ) { return null ; } else if ( OpenEngSBModel . class . isAssignableFrom ( parameterType ) ) { Object timestamp = object . getObject ( EDBConstants . MODEL_TIMESTAMP ) ; Long time = System . currentTimeMillis ( ) ; if ( timestamp != null ) { try { time = Long . parseLong ( timestamp . toString ( ) ) ; } catch ( NumberFormatException e ) { LOGGER . warn ( "The model with the oid {} has an invalid timestamp." , object . getOID ( ) ) ; } } EDBObject obj = edbService . getObject ( ( String ) value , time ) ; value = convertEDBObjectToUncheckedModel ( parameterType , obj ) ; object . remove ( propertyName ) ; } else if ( parameterType . equals ( FileWrapper . class ) ) { FileWrapper wrapper = new FileWrapper ( ) ; String filename = object . getString ( propertyName + FILEWRAPPER_FILENAME_SUFFIX ) ; String content = ( String ) value ; wrapper . setFilename ( filename ) ; wrapper . setContent ( Base64 . decodeBase64 ( content ) ) ; value = wrapper ; object . remove ( propertyName + FILEWRAPPER_FILENAME_SUFFIX ) ; } else if ( parameterType . equals ( File . class ) ) { return null ; } else if ( object . containsKey ( propertyName ) ) { if ( parameterType . isEnum ( ) ) { value = getEnumValue ( parameterType , value ) ; } } object . remove ( propertyName ) ; return value ; }
Generate the value for a specific property of a model out of an EDBObject .
4,739
@ SuppressWarnings ( "unchecked" ) private < T > List < T > getListValue ( Class < T > type , String propertyName , EDBObject object ) { List < T > temp = new ArrayList < > ( ) ; for ( int i = 0 ; ; i ++ ) { String property = getEntryNameForList ( propertyName , i ) ; Object obj = object . getObject ( property ) ; if ( obj == null ) { break ; } if ( OpenEngSBModel . class . isAssignableFrom ( type ) ) { obj = convertEDBObjectToUncheckedModel ( type , edbService . getObject ( object . getString ( property ) ) ) ; } temp . add ( ( T ) obj ) ; object . remove ( property ) ; } return temp ; }
Gets a list object out of an EDBObject .
4,740
@ SuppressWarnings ( "unchecked" ) private < T > T [ ] getArrayValue ( Class < T > type , String propertyName , EDBObject object ) { List < T > elements = getListValue ( type , propertyName , object ) ; T [ ] ar = ( T [ ] ) Array . newInstance ( type , elements . size ( ) ) ; return elements . toArray ( ar ) ; }
Gets an array object out of an EDBObject .
4,741
private Object getMapValue ( Class < ? > keyType , Class < ? > valueType , String propertyName , EDBObject object ) { Map < Object , Object > temp = new HashMap < > ( ) ; for ( int i = 0 ; ; i ++ ) { String keyProperty = getEntryNameForMapKey ( propertyName , i ) ; String valueProperty = getEntryNameForMapValue ( propertyName , i ) ; if ( ! object . containsKey ( keyProperty ) ) { break ; } Object key = object . getObject ( keyProperty ) ; Object value = object . getObject ( valueProperty ) ; if ( OpenEngSBModel . class . isAssignableFrom ( keyType ) ) { key = convertEDBObjectToUncheckedModel ( keyType , edbService . getObject ( key . toString ( ) ) ) ; } if ( OpenEngSBModel . class . isAssignableFrom ( valueType ) ) { value = convertEDBObjectToUncheckedModel ( valueType , edbService . getObject ( value . toString ( ) ) ) ; } temp . put ( key , value ) ; object . remove ( keyProperty ) ; object . remove ( valueProperty ) ; } return temp ; }
Gets a map object out of an EDBObject .
4,742
private Object getEnumValue ( Class < ? > type , Object value ) { Object [ ] enumValues = type . getEnumConstants ( ) ; for ( Object enumValue : enumValues ) { if ( enumValue . toString ( ) . equals ( value . toString ( ) ) ) { value = enumValue ; break ; } } return value ; }
Gets an enum value out of an object .
4,743
public ConvertedCommit convertEKBCommit ( EKBCommit commit ) { ConvertedCommit result = new ConvertedCommit ( ) ; ConnectorInformation information = commit . getConnectorInformation ( ) ; result . setInserts ( convertModelsToEDBObjects ( commit . getInserts ( ) , information ) ) ; result . setUpdates ( convertModelsToEDBObjects ( commit . getUpdates ( ) , information ) ) ; result . setDeletes ( convertModelsToEDBObjects ( commit . getDeletes ( ) , information ) ) ; return result ; }
Converts the models of an EKBCommit to EDBObjects and return an object which contains the three corresponding lists
4,744
private void fillEDBObjectWithEngineeringObjectInformation ( EDBObject object , OpenEngSBModel model ) throws IllegalAccessException { if ( ! new AdvancedModelWrapper ( model ) . isEngineeringObject ( ) ) { return ; } for ( Field field : model . getClass ( ) . getDeclaredFields ( ) ) { OpenEngSBForeignKey annotation = field . getAnnotation ( OpenEngSBForeignKey . class ) ; if ( annotation == null ) { continue ; } String value = ( String ) FieldUtils . readField ( field , model , true ) ; if ( value == null ) { continue ; } value = String . format ( "%s/%s" , ContextHolder . get ( ) . getCurrentContextId ( ) , value ) ; String key = getEOReferenceStringFromAnnotation ( annotation ) ; object . put ( key , new EDBObjectEntry ( key , value , String . class ) ) ; } }
Adds to the EDBObject special entries which mark that a model is referring to other models through OpenEngSBForeignKey annotations
4,745
private void filterEngineeringObjectInformation ( EDBObject object , Class < ? > model ) { if ( ! AdvancedModelWrapper . isEngineeringObjectClass ( model ) ) { return ; } Iterator < String > keys = object . keySet ( ) . iterator ( ) ; while ( keys . hasNext ( ) ) { if ( keys . next ( ) . startsWith ( REFERENCE_PREFIX ) ) { keys . remove ( ) ; } } }
Filters the reference prefix values added in the model to EDBObject conversion out of the EDBObject
4,746
public static String getEntryNameForMapKey ( String property , Integer index ) { return getEntryNameForMap ( property , true , index ) ; }
Returns the entry name for a map key in the EDB format . E . g . the map key for the property map with the index 0 would be map . 0 . key .
4,747
public static String getEntryNameForMapValue ( String property , Integer index ) { return getEntryNameForMap ( property , false , index ) ; }
Returns the entry name for a map value in the EDB format . E . g . the map value for the property map with the index 0 would be map . 0 . value .
4,748
private static String getEntryNameForMap ( String property , Boolean key , Integer index ) { return String . format ( "%s.%d.%s" , property , index , key ? "key" : "value" ) ; }
Returns the entry name for a map element in the EDB format . The key parameter defines if the entry name should be generated for the key or the value of the map . E . g . the map key for the property map with the index 0 would be map . 0 . key .
4,749
public static String getEntryNameForList ( String property , Integer index ) { return String . format ( "%s.%d" , property , index ) ; }
Returns the entry name for a list element in the EDB format . E . g . the list element for the property list with the index 0 would be list . 0 .
4,750
public static String getEOReferenceStringFromAnnotation ( OpenEngSBForeignKey key ) { return String . format ( "%s%s:%s" , REFERENCE_PREFIX , key . modelType ( ) , key . modelVersion ( ) . toString ( ) ) ; }
Converts an OpenEngSBForeignKey annotation to the fitting format which will be added to an EDBObject .
4,751
private static Map < String , ModelDescription > assigneModelsToViews ( Map < ModelDescription , XLinkConnectorView [ ] > modelsToViews ) { HashMap < String , ModelDescription > viewsToModels = new HashMap < String , ModelDescription > ( ) ; for ( ModelDescription modelInfo : modelsToViews . keySet ( ) ) { List < XLinkConnectorView > currentViewList = Arrays . asList ( modelsToViews . get ( modelInfo ) ) ; for ( XLinkConnectorView view : currentViewList ) { if ( ! viewsToModels . containsKey ( view . getViewId ( ) ) ) { viewsToModels . put ( view . getViewId ( ) , modelInfo ) ; } } } return viewsToModels ; }
Naive model to view assignment . The current model is choosen for the first occurence of the view .
4,752
private static String getExpirationDate ( int futureDays ) { Calendar calendar = Calendar . getInstance ( ) ; calendar . add ( Calendar . DAY_OF_YEAR , futureDays ) ; Format formatter = new SimpleDateFormat ( XLinkConstants . DATEFORMAT ) ; return formatter . format ( calendar . getTime ( ) ) ; }
Returns a future Date - String in the format yyyyMMddkkmmss .
4,753
public static void setValueOfModel ( Object model , OpenEngSBModelEntry entry , Object value ) throws NoSuchFieldException , IllegalArgumentException , IllegalAccessException { Class clazz = model . getClass ( ) ; Field field = clazz . getDeclaredField ( entry . getKey ( ) ) ; field . setAccessible ( true ) ; field . set ( model , value ) ; }
Sets the value of the field defined in the OpenEngSBModelEntry the the given model with reflection .
4,754
public static Object createInstanceOfModelClass ( Class clazzObject , List < OpenEngSBModelEntry > entries ) { return ModelUtils . createModel ( clazzObject , entries ) ; }
Returns an instance to a given Classobject and a List of OpenEngSBModelEntries . Returns null if an error happens during the instantiation .
4,755
public static Calendar dateStringToCalendar ( String dateString ) { Calendar calendar = Calendar . getInstance ( ) ; SimpleDateFormat formatter = new SimpleDateFormat ( XLinkConstants . DATEFORMAT ) ; try { calendar . setTime ( formatter . parse ( dateString ) ) ; } catch ( Exception ex ) { return null ; } return calendar ; }
Returns a Calendarobject to a given dateString in the Format DATEFORMAT . If the given String is of the wrong format null is returned .
4,756
private static String urlEncodeParameter ( String parameter ) { try { return URLEncoder . encode ( parameter , "UTF-8" ) ; } catch ( UnsupportedEncodingException ex ) { Logger . getLogger ( XLinkUtils . class . getName ( ) ) . log ( Level . SEVERE , null , ex ) ; } return parameter ; }
Encodes a given Parameter in UTF - 8 .
4,757
public static XLinkConnectorView [ ] getViewsOfRegistration ( XLinkConnectorRegistration registration ) { List < XLinkConnectorView > viewsOfRegistration = new ArrayList < XLinkConnectorView > ( ) ; Map < ModelDescription , XLinkConnectorView [ ] > modelsToViews = registration . getModelsToViews ( ) ; for ( XLinkConnectorView [ ] views : modelsToViews . values ( ) ) { for ( int i = 0 ; i < views . length ; i ++ ) { XLinkConnectorView view = views [ i ] ; if ( ! viewsOfRegistration . contains ( view ) ) { viewsOfRegistration . add ( view ) ; } } } return viewsOfRegistration . toArray ( new XLinkConnectorView [ 0 ] ) ; }
Returns a distinct List of all RemoteToolViews contained in a RemoteToolRegistration .
4,758
public static XLinkConnector [ ] getLocalToolFromRegistrations ( List < XLinkConnectorRegistration > registrations ) { List < XLinkConnector > tools = new ArrayList < XLinkConnector > ( ) ; for ( XLinkConnectorRegistration registration : registrations ) { XLinkConnector newLocalTools = new XLinkConnector ( registration . getConnectorId ( ) , registration . getToolName ( ) , getViewsOfRegistration ( registration ) ) ; tools . add ( newLocalTools ) ; } return tools . toArray ( new XLinkConnector [ 0 ] ) ; }
Returns a list of RemoteTools to a list of RemoteToolRegistrations . The list of RemoteTool can be sent to a remote host . A RemoteToolRegistration is for internal usage only .
4,759
private void mergeInTransaction ( EntityManager em , Collection objects ) { EntityTransaction tx = null ; try { tx = em . getTransaction ( ) ; tx . begin ( ) ; for ( Object o : objects ) { em . merge ( o ) ; } tx . commit ( ) ; } catch ( RuntimeException e ) { if ( tx != null && tx . isActive ( ) ) { tx . rollback ( ) ; } throw e ; } }
Persist collection of objects .
4,760
public void execute ( ) { try { new JdbcTemplate ( dataSource ) . execute ( readResourceContent ( SCHEMA_FILE ) ) ; } catch ( IOException e ) { throw new RuntimeException ( "Could not create schema for EDBI Index" , e ) ; } }
Creates the necessary relations to save Index and IndexField instances .
4,761
public static void addId ( Entry entry , boolean updateRdn ) { String uuid = newUUID ( ) . toString ( ) ; try { entry . add ( SchemaConstants . OBJECT_CLASS_ATTRIBUTE , UNIQUE_OBJECT_OC ) ; entry . add ( ID_ATTRIBUTE , uuid ) ; } catch ( LdapException e ) { throw new LdapRuntimeException ( e ) ; } if ( updateRdn ) { Dn newDn = LdapUtils . concatDn ( ID_ATTRIBUTE , uuid , entry . getDn ( ) . getParent ( ) ) ; entry . setDn ( newDn ) ; } }
Adds a timebased uuid to entry . If updateRdn is true the uuid becomes the rdn . Use this to handle duplicates .
4,762
public static void addIds ( List < Entry > entries , boolean updateRdn ) { for ( Entry entry : entries ) { addId ( entry , updateRdn ) ; } }
Iterates over entries and adds a timebased uuid to each entry . If updateRdn is true the uuid becomes the rdn . Use this to handle duplicates .
4,763
protected synchronized void initialize ( ) { String invocationServiceName = this . invocationServiceName ; invocationService = ( InvocationService ) CacheFactory . getService ( invocationServiceName ) ; if ( invocationService == null ) { throw new IllegalArgumentException ( "Invocation service [" + invocationServiceName + "] is not defined." ) ; } invocationService . addMemberListener ( this ) ; serviceMembers = invocationService . getInfo ( ) . getServiceMembers ( ) ; memberIterator = serviceMembers . iterator ( ) ; }
Initialize this executor service .
4,764
public void execute ( Runnable command ) { if ( ! ( command instanceof ClusteredFutureTask ) ) { command = new ClusteredFutureTask < Object > ( command , null ) ; } command . run ( ) ; }
Executes the given command at some time in the future .
4,765
protected synchronized Member getExecutionMember ( ) { Iterator < Member > it = memberIterator ; if ( it == null || ! it . hasNext ( ) ) { memberIterator = it = serviceMembers . iterator ( ) ; } return it . next ( ) ; }
Return the member that should execute submitted command .
4,766
protected BrokerServiceAccessor getMethodAccessor ( String serviceBrokerName , CatalogService description ) { return new AnnotationBrokerServiceAccessor ( description , serviceBrokerName , getBeanClass ( serviceBrokerName ) , context . getBean ( serviceBrokerName ) ) ; }
Returns the accessor used to access the specified service of the specified broker .
4,767
protected Class < ? > getBeanClass ( String beanName ) { Class < ? > clazz = context . getType ( beanName ) ; while ( Proxy . isProxyClass ( clazz ) || Enhancer . isEnhanced ( clazz ) ) { clazz = clazz . getSuperclass ( ) ; } return clazz ; }
Returns the class of the specified bean name .
4,768
public void skipSolver ( ConstraintSolver ... solvers ) { if ( solversToSkip == null ) solversToSkip = new HashSet < ConstraintSolver > ( ) ; for ( ConstraintSolver solver : solvers ) solversToSkip . add ( solver ) ; }
Provide a list of solvers that should not process this constraint .
4,769
private void initAttributesAndElements ( String ... propertyNames ) { for ( String propertyName : propertyNames ) { Property property = new Property ( propertyName ) ; if ( property . isAttribute ( ) ) { m_attributes . add ( property ) ; } else { m_elements . add ( property ) ; } } }
Parses user - specified property names and determines which properties should be written out as attributes and which as child elements .
4,770
public void setUsed ( boolean newVal ) { if ( isUsed ( ) && newVal == false ) { Arrays . fill ( out , null ) ; } used = newVal ; }
Set whether this time point as used in the underlying temporal network .
4,771
private Character getPadCharacter ( String characterString ) { if ( characterString . length ( ) > 0 ) { getLogger ( ) . debug ( "The given character string is longer than one element. The first character is used." ) ; } return characterString . charAt ( 0 ) ; }
Returns the character which is used for the padding . If the character string is longer than one char the first char will be used .
4,772
private String getDirectionString ( String direction ) { if ( direction == null || ! ( direction . equals ( "Start" ) || direction . equals ( "End" ) ) ) { getLogger ( ) . debug ( "Unrecognized direction string. The standard value 'Start' will be used." ) ; return "Start" ; } return direction ; }
Returns the direction in which the padding will be done . If the direction string is null or invalid Start will be taken instead .
4,773
private String performPadOperation ( String source , Integer length , Character padChar , String direction ) { if ( direction . equals ( "Start" ) ) { return Strings . padStart ( source , length , padChar ) ; } else { return Strings . padEnd ( source , length , padChar ) ; } }
Perform the pad operation itself and returns the result
4,774
public List < Project > findAllProjects ( ) { List < Project > list = new ArrayList < > ( ) ; List < String > projectNames ; try { projectNames = readLines ( projectsFile ) ; } catch ( IOException e ) { throw new FileBasedRuntimeException ( e ) ; } for ( String projectName : projectNames ) { if ( StringUtils . isNotBlank ( projectName ) ) { list . add ( new Project ( projectName ) ) ; } } return list ; }
Finds all the available projects .
4,775
public static Map < String , Class < ? > > getPropertyTypeMap ( Class < ? > clazz , String ... exclude ) { PropertyDescriptor [ ] descriptors ; try { descriptors = getPropertyDescriptors ( clazz ) ; } catch ( IntrospectionException e ) { LOG . error ( "Failed to introspect " + clazz , e ) ; return Collections . emptyMap ( ) ; } HashMap < String , Class < ? > > map = new HashMap < > ( descriptors . length ) ; for ( PropertyDescriptor pd : descriptors ) { map . put ( pd . getName ( ) , pd . getPropertyType ( ) ) ; } for ( String property : exclude ) { map . remove ( property ) ; } return map ; }
Returns a create of all property names and their respective type . Any property passed via exclude are removed from the create before hand .
4,776
public static Map < String , Object > read ( Object object ) { PropertyDescriptor [ ] descriptors ; Class < ? > clazz = object . getClass ( ) ; try { descriptors = getPropertyDescriptors ( clazz ) ; } catch ( IntrospectionException e ) { LOG . error ( "Failed to introspect " + clazz , e ) ; return Collections . emptyMap ( ) ; } HashMap < String , Object > map = new HashMap < > ( descriptors . length ) ; for ( PropertyDescriptor pd : descriptors ) { try { Object value = pd . getReadMethod ( ) . invoke ( object ) ; map . put ( pd . getName ( ) , value ) ; } catch ( IllegalAccessException | InvocationTargetException | IllegalArgumentException e ) { LOG . error ( "Failed to visit property " + pd . getName ( ) , e ) ; } } map . remove ( "class" ) ; return map ; }
Returns a create of all property names and their values contained in the given object .
4,777
public static AdvancedModelWrapper wrap ( Object model ) { if ( ! ( isModel ( model . getClass ( ) ) ) ) { throw new IllegalArgumentException ( "The given object is no model" ) ; } return new AdvancedModelWrapper ( ( OpenEngSBModel ) model ) ; }
Creates an advanced model wrapper object out of the given model object . Throws IllegalArgumentException in case the given model object is no model .
4,778
public List < EDBObject > getModelsReferringToThisModel ( EngineeringDatabaseService edbService ) { return edbService . query ( QueryRequest . query ( EDBConverter . REFERENCE_PREFIX + "%" , getCompleteModelOID ( ) ) ) ; }
Returns a list of EDBObjects which are referring to this model .
4,779
public static Boolean isEngineeringObjectClass ( Class < ? > clazz ) { for ( Field field : clazz . getDeclaredFields ( ) ) { if ( field . isAnnotationPresent ( OpenEngSBForeignKey . class ) ) { return true ; } } return false ; }
Returns true if the class is the class of an engineering object returns false if not .
4,780
public static < T > T convertObject ( String json , Class < T > clazz ) throws IOException { try { if ( clazz . isAnnotationPresent ( Model . class ) ) { return MODEL_MAPPER . readValue ( json , clazz ) ; } return MAPPER . readValue ( json , clazz ) ; } catch ( IOException e ) { String error = String . format ( "Unable to parse given json '%s' into class '%s'." , json , clazz . getName ( ) ) ; LOGGER . error ( error , e ) ; throw new IOException ( error , e ) ; } }
Converts an object in JSON format to the given class . Throws an IOException if the conversion could not be performed .
4,781
public IndexCommit convert ( EKBCommit ekbCommit ) { IndexCommit commit = new IndexCommit ( ) ; commit . setCommitId ( ekbCommit . getRevisionNumber ( ) ) ; commit . setParentCommitId ( ekbCommit . getParentRevisionNumber ( ) ) ; commit . setConnectorId ( ekbCommit . getConnectorId ( ) ) ; commit . setDomainId ( ekbCommit . getDomainId ( ) ) ; commit . setInstanceId ( ekbCommit . getInstanceId ( ) ) ; commit . setTimestamp ( new Date ( ) ) ; commit . setUser ( getUser ( ) ) ; commit . setContextId ( getContextId ( ) ) ; List < OpenEngSBModel > inserts = ekbCommit . getInserts ( ) ; List < OpenEngSBModel > updates = ekbCommit . getUpdates ( ) ; List < OpenEngSBModel > deletes = ekbCommit . getDeletes ( ) ; Set < Class < ? > > modelClasses = extractTypes ( inserts , updates , deletes ) ; commit . setModelClasses ( modelClasses ) ; commit . setInserts ( mapByClass ( inserts ) ) ; commit . setUpdates ( mapByClass ( updates ) ) ; commit . setDeletes ( mapByClass ( deletes ) ) ; return commit ; }
Convert the given EKBCommit to an IndexCommit .
4,782
protected Map < Class < ? > , List < OpenEngSBModel > > mapByClass ( Collection < OpenEngSBModel > models ) { return group ( models , new Function < OpenEngSBModel , Class < ? > > ( ) { public Class < ? > apply ( OpenEngSBModel input ) { return input . getClass ( ) ; } } ) ; }
Groups all models in the given collection by their class .
4,783
public Catalog createCatalog ( ) { final List < CatalogService > services = new ArrayList < > ( ) ; for ( BrokerServiceAccessor serviceAccessor : serviceAccessors ) { services . add ( serviceAccessor . getServiceDescription ( ) ) ; } return new Catalog ( services ) ; }
Creates the catalog .
4,784
public BrokerServiceAccessor getServiceAccessor ( String serviceId ) { for ( BrokerServiceAccessor serviceAccessor : serviceAccessors ) { if ( serviceId . equals ( serviceAccessor . getServiceDescription ( ) . getId ( ) ) ) { return serviceAccessor ; } } throw new NotFoundException ( "Could not find service broker with service_id " + serviceId ) ; }
Returns the accessor associated to the specified service id .
4,785
public static void setIdFieldValue ( ODocument document , String value ) { setFieldValue ( document , OGraphDatabase . LABEL , value ) ; }
Sets the value for the id field of a graph object .
4,786
public static void setActiveFieldValue ( ODocument document , Boolean active ) { setFieldValue ( document , ACTIVE_FIELD , active . toString ( ) ) ; }
Sets the value for the active field of a graph object .
4,787
public static String getFieldValue ( ODocument document , String fieldname ) { return ( String ) document . field ( fieldname ) ; }
Gets the value for the given field of a graph object .
4,788
public static void setFieldValue ( ODocument document , String fieldname , String value ) { document . field ( fieldname , value ) ; }
Sets the value for the given field of an graph object .
4,789
public static void fillEdgeWithPropertyConnections ( ODocument edge , TransformationDescription description ) { Map < String , String > connections = convertPropertyConnectionsToSimpleForm ( description . getPropertyConnections ( ) ) ; for ( Map . Entry < String , String > entry : connections . entrySet ( ) ) { edge . field ( entry . getKey ( ) , entry . getValue ( ) ) ; } }
Adds to the given map the property connection information which result from the given transformation description .
4,790
public int [ ] [ ] getVariations ( ) { int permutations = ( int ) Math . pow ( n , r ) ; int [ ] [ ] table = new int [ permutations ] [ r ] ; for ( int x = 0 ; x < r ; x ++ ) { int t2 = ( int ) Math . pow ( n , x ) ; for ( int p1 = 0 ; p1 < permutations ; ) { for ( int al = 0 ; al < n ; al ++ ) { for ( int p2 = 0 ; p2 < t2 ; p2 ++ ) { table [ p1 ] [ x ] = al ; p1 ++ ; } } } } return table ; }
Get all r - permutations of n integers .
4,791
private List < JPAObject > checkInserts ( List < JPAObject > inserts ) { List < JPAObject > failedObjects = new ArrayList < JPAObject > ( ) ; for ( JPAObject insert : inserts ) { String oid = insert . getOID ( ) ; if ( checkIfActiveOidExisting ( oid ) ) { failedObjects . add ( insert ) ; } else { insert . addEntry ( new JPAEntry ( EDBConstants . MODEL_VERSION , "1" , Integer . class . getName ( ) , insert ) ) ; } } return failedObjects ; }
Checks if all oid s of the given JPAObjects are not existing yet . Returns a list of objects where the JPAObject already exists .
4,792
private List < String > checkDeletions ( List < String > deletes ) { List < String > failedObjects = new ArrayList < String > ( ) ; for ( String delete : deletes ) { if ( ! checkIfActiveOidExisting ( delete ) ) { failedObjects . add ( delete ) ; } } return failedObjects ; }
Checks if all oid s of the given JPAObjects are existing . Returns a list of objects where the JPAObject doesn t exist .
4,793
private List < JPAObject > checkUpdates ( List < JPAObject > updates ) throws EDBException { List < JPAObject > failedObjects = new ArrayList < JPAObject > ( ) ; for ( JPAObject update : updates ) { try { Integer modelVersion = investigateVersionAndCheckForConflict ( update ) ; modelVersion ++ ; update . removeEntry ( EDBConstants . MODEL_VERSION ) ; update . addEntry ( new JPAEntry ( EDBConstants . MODEL_VERSION , modelVersion + "" , Integer . class . getName ( ) , update ) ) ; } catch ( EDBException e ) { failedObjects . add ( update ) ; } } return failedObjects ; }
Checks every update for a potential conflict . Returns a list of objects where a conflict has been found .
4,794
private Integer investigateVersionAndCheckForConflict ( JPAObject newObject ) throws EDBException { JPAEntry entry = newObject . getEntry ( EDBConstants . MODEL_VERSION ) ; String oid = newObject . getOID ( ) ; Integer modelVersion = 0 ; if ( entry != null ) { modelVersion = Integer . parseInt ( entry . getValue ( ) ) ; Integer currentVersion = dao . getVersionOfOid ( oid ) ; if ( ! modelVersion . equals ( currentVersion ) ) { try { checkForConflict ( newObject ) ; } catch ( EDBException e ) { LOGGER . info ( "conflict detected, user get informed" ) ; throw new EDBException ( "conflict was detected. There is a newer version of the model with the oid " + oid + " saved." ) ; } modelVersion = currentVersion ; } } else { modelVersion = dao . getVersionOfOid ( oid ) ; } return modelVersion ; }
Investigates the version of an JPAObject and checks if a conflict can be found .
4,795
private void checkForConflict ( JPAObject newObject ) throws EDBException { String oid = newObject . getOID ( ) ; JPAObject object = dao . getJPAObject ( oid ) ; for ( JPAEntry entry : newObject . getEntries ( ) ) { if ( entry . getKey ( ) . equals ( EDBConstants . MODEL_VERSION ) ) { continue ; } JPAEntry rival = object . getEntry ( entry . getKey ( ) ) ; String value = rival != null ? rival . getValue ( ) : null ; if ( value == null || ! value . equals ( entry . getValue ( ) ) ) { LOGGER . debug ( "Conflict detected at key {} when comparing {} with {}" , new Object [ ] { entry . getKey ( ) , entry . getValue ( ) , value == null ? "null" : value } ) ; throw new EDBException ( "Conflict detected. Failure when comparing the values of the key " + entry . getKey ( ) ) ; } } }
Simple check mechanism if there is a conflict between a model which should be saved and the existing model based on the values which are in the EDB .
4,796
public void execute ( ) throws MojoExecutionException { checkParameters ( ) ; windowsModus = isWindows ( ) ; if ( windowsModus ) { setWindowsVariables ( ) ; } else { setLinuxVariables ( ) ; } createDllFromWsdl ( ) ; }
Find and executes the commands wsdl . exe and csc . exe
4,797
private void createDllFromWsdl ( ) throws MojoExecutionException { getLog ( ) . info ( "Execute WSDl to cs command" ) ; wsdlCommand ( ) ; getLog ( ) . info ( "Execute cs to dll command" ) ; cscCommand ( ) ; if ( generateNugetPackage ) { if ( isLinux ( ) ) { throw new MojoExecutionException ( "At this point, mono and nuget does not work so well together." + "Please execute the plugin with nuget under Windows" ) ; } nugetLib = nugetFolder + "lib" ; getLog ( ) . info ( "Create Nuget folder structure" ) ; createNugetStructure ( ) ; getLog ( ) . info ( "Copy the dlls to the nuget structure" ) ; copyFilesToNuget ( ) ; getLog ( ) . info ( "Generate " + namespace + " .nuspec" ) ; generateNugetPackedFile ( ) ; getLog ( ) . info ( "Pack .nuspec to a nuget package" ) ; nugetPackCommand ( ) ; } }
Windows mode for maven execution
4,798
private void wsdlCommand ( ) throws MojoExecutionException { String cmd = findWsdlCommand ( ) ; int i = 0 ; for ( String location : wsdlLocations ) { String outputFilename = new File ( outputDirectory , namespace + ( i ++ ) + ".cs" ) . getAbsolutePath ( ) ; String [ ] command = new String [ ] { cmd , serverParameter , "/n:" + namespace , location , "/out:" + outputFilename } ; ProcessBuilder builder = new ProcessBuilder ( ) ; builder . redirectErrorStream ( true ) ; builder . command ( command ) ; try { executeACommand ( builder . start ( ) ) ; } catch ( IOException | InterruptedException e ) { throw new MojoExecutionException ( "Error, while executing command: " + Arrays . toString ( command ) + "\n" , e ) ; } cspath . add ( outputFilename ) ; } try { FileComparer . removeSimilaritiesAndSaveFiles ( cspath , getLog ( ) , windowsModus ) ; } catch ( IOException e ) { throw new MojoExecutionException ( "It was not possible, to remove similarities form the files" , e ) ; } }
Search for the wsdl command and execute it when it is found
4,799
private void cscCommand ( ) throws MojoExecutionException { generateAssemblyInfo ( ) ; String cscPath = findCscCommand ( ) ; List < String > commandList = new LinkedList < String > ( cspath ) ; commandList . add ( 0 , cscPath ) ; commandList . add ( 1 , "/target:library" ) ; commandList . add ( 2 , "/out:" + namespace + ".dll" ) ; if ( isLinux ( ) ) { commandList . add ( 3 , "/reference:System.Web.Services" ) ; } String [ ] command = commandList . toArray ( new String [ commandList . size ( ) ] ) ; ProcessBuilder builder = new ProcessBuilder ( ) ; builder . redirectErrorStream ( true ) ; builder . directory ( outputDirectory ) ; builder . command ( command ) ; try { executeACommand ( builder . start ( ) ) ; } catch ( InterruptedException | IOException e ) { throw new MojoExecutionException ( "Error, while executing command: " + Arrays . toString ( command ) + "\n" , e ) ; } }
Search for the csc command and execute it when it is found