11package com .genexus .util ;
22
33import java .io .File ;
4- import java .io .IOException ;
54import java .util .Hashtable ;
65
7- import com .fasterxml .jackson .core .JsonParseException ;
8- import com .fasterxml .jackson .databind .JsonMappingException ;
9- import com .fasterxml .jackson .dataformat .xml .XmlMapper ;
10- import com .fasterxml .jackson .dataformat .xml .ser .ToXmlGenerator ;
6+ import com .genexus .ApplicationContext ;
117import com .genexus .ModelContext ;
128import com .genexus .internet .HttpContext ;
13- import com .genexus .util .cloudservice .Property ;
14- import com .genexus .util .cloudservice .Service ;
15- import com .genexus .util .cloudservice .Services ;
169import com .genexus .webpanels .HttpContextWeb ;
17- import com .genexus .diagnostics .core .ILogger ;
18- import com .genexus .diagnostics .core .LogManager ;
10+ import com .genexus .xml .XMLReader ;
1911
2012public class GXServices {
21-
22- public static final ILogger logger = LogManager .getLogger (GXServices .class );
23-
2413 private static final boolean DEBUG = com .genexus .DebugFlag .DEBUG ;
2514 public static final String WEBNOTIFICATIONS_SERVICE = "WebNotifications" ;
2615 public static final String STORAGE_SERVICE = "Storage" ;
@@ -55,46 +44,29 @@ public static void endGXServices() {
5544 instance = null ;
5645 }
5746
58- public static void loadFromFile (String basePath , String fileName , GXServices services ) {
47+ public static void loadFromFile (String basePath , String fileName , GXServices services ){
5948 if (basePath .equals ("" )) {
6049 basePath = services .configBaseDirectory ();
6150 }
6251 String fullPath = basePath + fileName ;
63- XmlMapper xmlMapper = new XmlMapper ();
64- xmlMapper .configure (ToXmlGenerator .Feature .WRITE_XML_DECLARATION , true );
65- Services xmlServices = null ;
66- try {
67- xmlServices = xmlMapper .readValue (new File (fullPath ), Services .class );
68- } catch (JsonParseException e ) {
69- logger .error (e .getMessage (), e );
70- e .printStackTrace ();
71- } catch (JsonMappingException e ) {
72- logger .error (e .getMessage (), e );
73- e .printStackTrace ();
74- } catch (IOException e ) {
75- logger .error (e .getMessage (), e );
76- e .printStackTrace ();
77- }
78-
79- if (services == null )
80- services = new GXServices ();
81-
82- for (Service xmlService : xmlServices .getService ()) {
83- GXService service = new GXService ();
84- service .setName (xmlService .getName ());
85- service .setType (xmlService .getType ());
86- service .setClassName (xmlService .getClassName ());
87- service .setAllowMultiple (xmlService .getAllowMultiple ());
88- GXProperties ptys = new GXProperties ();
89- for (Property xmlPty : xmlService .getProperties ().getProperty ()) {
90- ptys .add (xmlPty .getName (), xmlPty .getValue ());
52+ XMLReader reader = new XMLReader ();
53+ reader .open (fullPath );
54+ reader .readType (1 , "Services" );
55+ reader .read ();
56+ if (reader .getErrCode () == 0 ) {
57+ while (!reader .getName ().equals ("Services" )) {
58+ services .processService (reader );
59+ reader .read ();
60+ if (reader .getName ().equals ("Service" ) && reader .getNodeType () == 2 ) //</Service>
61+ reader .read ();
9162 }
92- service .setProperties (ptys );
93-
94- if (service .getAllowMultiple ()) {
95- services .services .put (service .getType () + ":" + service .getName (), service );
96- } else {
97- services .services .put (service .getType (), service );
63+ reader .close ();
64+ }
65+ else
66+ {
67+ if (!ApplicationContext .getInstance ().getReorganization () && DEBUG )
68+ {
69+ System .out .println ("GXServices - Could not load Services Config: " + fullPath + " - " + reader .getErrDescription ());
9870 }
9971 }
10072 }
@@ -108,13 +80,15 @@ private String configBaseDirectory() {
10880 if (ModelContext .getModelContext () != null ) {
10981 HttpContext webContext = (HttpContext ) ModelContext .getModelContext ().getHttpContext ();
11082 if ((webContext != null ) && (webContext instanceof HttpContextWeb )) {
111- baseDir = com .genexus .ModelContext .getModelContext ().getHttpContext ().getDefaultPath () + File .separator
112- + "WEB-INF" + File .separatorChar ;
83+ baseDir = com .genexus .ModelContext .getModelContext ()
84+ .getHttpContext ().getDefaultPath ()
85+ + File .separator + "WEB-INF" + File .separatorChar ;
11386 }
11487 }
11588 if (baseDir .equals ("" )) {
11689 String servletPath = com .genexus .ApplicationContext .getInstance ().getServletEngineDefaultPath ();
117- if (servletPath != null && !servletPath .equals ("" )) {
90+ if (servletPath != null && !servletPath .equals ("" ))
91+ {
11892 baseDir = servletPath + File .separator + "WEB-INF" + File .separatorChar ;
11993 }
12094 }
@@ -125,15 +99,66 @@ private void readServices(String basePath) {
12599
126100 if (basePath .equals ("" ))
127101 basePath = configBaseDirectory ();
128- if (new File (basePath + SERVICES_DEV_FILE ).exists ()) {
102+ if (new File (basePath + SERVICES_DEV_FILE ).exists ()){
129103 loadFromFile (basePath , SERVICES_DEV_FILE , this );
130104 }
131- if (new File (basePath + SERVICES_FILE ).exists ()) {
105+ if (new File (basePath + SERVICES_FILE ).exists ()){
132106 loadFromFile (basePath , SERVICES_FILE , this );
133107 }
134108 }
135109
110+ private void processService (XMLReader reader ) {
111+ short result ;
112+ result = reader .readType (1 , "Name" );
113+ String name = new String (reader .getValue ());
114+
115+ result = reader .readType (1 , "Type" );
116+ String type = new String (reader .getValue ());
117+
118+ result = reader .readType (1 , "ClassName" );
119+ String className = new String (reader .getValue ());
120+
121+ boolean allowMultiple = false ;
122+ reader .read ();
123+ if (reader .getName () == "AllowMultiple" )
124+ {
125+ allowMultiple = Boolean .parseBoolean (reader .getValue ());
126+ reader .read ();
127+ }
128+ GXProperties properties = processProperties (reader );
129+
130+ GXService service = new GXService ();
131+ service .setName (name );
132+ service .setType (type );
133+ service .setClassName (className );
134+ service .setAllowMultiple (allowMultiple );
135+ service .setProperties (properties );
136+ if (service .getAllowMultiple ()){
137+ services .put (service .getType () + ":" + service .getName (), service );
138+ }
139+ else {
140+ services .put (type , service );
141+ }
142+ }
143+
144+ private GXProperties processProperties (XMLReader reader ) {
145+ short result ;
146+ GXProperties properties = new GXProperties ();
147+ reader .read ();
148+ while (reader .getName ().equals ("Property" )) {
149+ result = reader .readType (1 , "Name" );
150+ String name = new String (reader .getValue ());
151+ result = reader .readType (1 , "Value" );
152+ String value = new String (reader .getValue ());
153+ properties .add (name , value );
154+ reader .read ();
155+ reader .read ();
156+ }
157+ return properties ;
158+ }
159+
136160 public GXService get (String name ) {
137161 return services .get (name );
138162 }
163+
139164}
0 commit comments