1
1
package com .genexus .util ;
2
2
3
3
import java .io .File ;
4
+ import java .io .FileInputStream ;
5
+ import java .io .IOException ;
6
+ import java .io .InputStream ;
4
7
import java .util .Hashtable ;
5
8
6
9
import com .genexus .ApplicationContext ;
@@ -47,32 +50,6 @@ public static void endGXServices() {
47
50
instance = null ;
48
51
}
49
52
50
- public static void loadFromFile (String basePath , String fileName , GXServices services ){
51
- if (basePath .equals ("" )) {
52
- basePath = services .configBaseDirectory ();
53
- }
54
- String fullPath = basePath + fileName ;
55
- XMLReader reader = new XMLReader ();
56
- reader .open (fullPath );
57
- reader .readType (1 , "Services" );
58
- reader .read ();
59
- if (reader .getErrCode () == 0 ) {
60
- while (!reader .getName ().equals ("Services" )) {
61
- services .processService (reader );
62
- reader .read ();
63
- if (reader .getName ().equals ("Service" ) && reader .getNodeType () == 2 ) //</Service>
64
- reader .read ();
65
- }
66
- reader .close ();
67
- }
68
- else
69
- {
70
- if (!ApplicationContext .getInstance ().getReorganization ())
71
- {
72
- logger .debug ("GXServices - Could not load Services Config: " + fullPath + " - " + reader .getErrDescription ());
73
- }
74
- }
75
- }
76
53
77
54
private String configBaseDirectory () {
78
55
String baseDir = "" ;
@@ -99,14 +76,71 @@ private String configBaseDirectory() {
99
76
}
100
77
101
78
private void readServices (String basePath ) {
102
-
103
- if (basePath .equals ("" ))
79
+ if (basePath .equals ("" )) {
104
80
basePath = configBaseDirectory ();
105
- if (new File (basePath + SERVICES_DEV_FILE ).exists ()){
106
- loadFromFile (basePath , SERVICES_DEV_FILE , this );
107
81
}
108
- if (new File (basePath + SERVICES_FILE ).exists ()){
109
- loadFromFile (basePath , SERVICES_FILE , this );
82
+
83
+ if (!readFromFileSystem (basePath , SERVICES_DEV_FILE )) {
84
+ readFromClasspath (SERVICES_DEV_FILE );
85
+ }
86
+
87
+ if (!readFromFileSystem (basePath , SERVICES_FILE )) {
88
+ readFromClasspath (SERVICES_FILE );
89
+ }
90
+ }
91
+
92
+ private boolean readFromFileSystem (String basePath , String fileName ) {
93
+ File file = new File (basePath + fileName );
94
+ if (file .exists ()) {
95
+ loadFromFile (basePath , fileName , this );
96
+ return true ;
97
+ }
98
+ return false ;
99
+ }
100
+
101
+ private boolean readFromClasspath (String fileName ) {
102
+ InputStream inputStream = getClass ().getClassLoader ().getResourceAsStream (fileName );
103
+ if (inputStream == null ) {
104
+ return false ;
105
+ }
106
+ try {
107
+ loadFromStream (inputStream , fileName , this );
108
+ return true ;
109
+ } catch (IOException e ) {
110
+ logger .debug ("GXServices - Could not load Services Config from classpath: " + fileName + " - " + e .getMessage ());
111
+ }
112
+ return false ;
113
+ }
114
+
115
+ public static void loadFromFile (String basePath , String fileName , GXServices services ) {
116
+ if (basePath .equals ("" )) {
117
+ basePath = services .configBaseDirectory ();
118
+ }
119
+ String fullPath = basePath + fileName ;
120
+ try (InputStream inputStream = new FileInputStream (fullPath )) {
121
+ loadFromStream (inputStream , fullPath , services );
122
+ } catch (IOException e ) {
123
+ logger .debug ("GXServices - Could not load Services Config from file: " + fullPath + " - " + e .getMessage ());
124
+ }
125
+ }
126
+
127
+ public static void loadFromStream (InputStream inputStream , String source , GXServices services ) throws IOException {
128
+ XMLReader reader = new XMLReader ();
129
+ reader .openFromInputStream (inputStream );
130
+ reader .readType (1 , "Services" );
131
+ reader .read ();
132
+ if (reader .getErrCode () == 0 ) {
133
+ while (!reader .getName ().equals ("Services" )) {
134
+ services .processService (reader );
135
+ reader .read ();
136
+ if (reader .getName ().equals ("Service" ) && reader .getNodeType () == 2 ) //</Service>
137
+ reader .read ();
138
+ }
139
+ reader .close ();
140
+ } else {
141
+ if (!ApplicationContext .getInstance ().getReorganization ()) {
142
+ logger .debug ("GXServices - Could not load Services Config: " + source + " - " + reader .getErrDescription ());
143
+ }
110
144
}
111
145
}
112
146
0 commit comments