KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jorm > mapper > rdb > mi2xml > RdbDomtreeBuilder


1 /**
2  * JORM: an implementation of a generic mapping system for persistent Java
3  * objects. Two mapping are supported: to RDBMS and to binary files.
4  * Copyright (C) 2001-2004 France Telecom R&D - INRIA
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  *
20  * Contact: jorm@objectweb.org
21  *
22  */

23
24 package org.objectweb.jorm.mapper.rdb.mi2xml;
25
26 import org.objectweb.jorm.api.PException;
27 import org.objectweb.jorm.mapper.rdb.metainfo.RdbClassMultiMapping;
28 import org.objectweb.jorm.mapper.rdb.metainfo.RdbExternalTable;
29 import org.objectweb.jorm.mapper.rdb.metainfo.RdbFilter;
30 import org.objectweb.jorm.mapper.rdb.metainfo.RdbGenClassMapping;
31 import org.objectweb.jorm.mapper.rdb.metainfo.RdbJoin;
32 import org.objectweb.jorm.mapper.rdb.metainfo.RdbPrimitiveElementMapping;
33 import org.objectweb.jorm.mapper.rdb.metainfo.RdbTable;
34 import org.objectweb.jorm.metainfo.api.Class;
35 import org.objectweb.jorm.metainfo.api.ClassMapping;
36 import org.objectweb.jorm.metainfo.api.ClassRef;
37 import org.objectweb.jorm.metainfo.api.GenClassMapping;
38 import org.objectweb.jorm.metainfo.api.GenClassRef;
39 import org.objectweb.jorm.metainfo.api.IdentifierMapping;
40 import org.objectweb.jorm.metainfo.api.MetaObject;
41 import org.objectweb.jorm.metainfo.api.NameDef;
42 import org.objectweb.jorm.metainfo.api.ParentClassMapping;
43 import org.objectweb.jorm.metainfo.api.PrimitiveElement;
44 import org.objectweb.jorm.metainfo.api.Reference;
45 import org.objectweb.jorm.metainfo.api.ReferenceMapping;
46 import org.objectweb.jorm.mi2xml.lib.BasicMappingDomtreeBuilder;
47 import org.objectweb.util.monolog.api.BasicLevel;
48 import org.w3c.dom.Document JavaDoc;
49 import org.w3c.dom.Element JavaDoc;
50
51 import java.util.Collection JavaDoc;
52 import java.util.Iterator JavaDoc;
53 import java.util.Map JavaDoc;
54
55 /**
56  * BasicRdbMappingDomTreeGenerator extends the BasicMappingDomTreeGenerator class.
57  *
58  * BasicRdbMappingDomTreeGenerator generates an org.w3c.dom.Document object for
59  * a ClassMapping object or a GenClassMapping object.
60  */

61 public class RdbDomtreeBuilder extends BasicMappingDomtreeBuilder {
62     // TODO: create a separate class
63
public final static String JavaDoc RDB_CLASS_MAPPING = "rdb-class-mapping";
64     public final static String JavaDoc COLOCATED_CLASS = "colocated-class";
65     public final static String JavaDoc RDB_TABLE_SPEC = "rdb-table-spec";
66     public final static String JavaDoc ID_MAPPING = "id-mapping";
67     public final static String JavaDoc RDB_CLASS_REF_MAPPING = "rdb-class-ref-mapping";
68     public final static String JavaDoc RDB_GEN_CLASS_REF_MAPPING = "rdb-gen-class-ref-mapping";
69     public final static String JavaDoc RDB_REF_MAPPING = "rdb-ref-mapping";
70     public final static String JavaDoc RDB_EXTERNAL_TABLE_SPEC = "rdb-external-table-spec";
71     public final static String JavaDoc RDB_JOIN = "rdb-join";
72     public final static String JavaDoc RDB_FILTER_SPEC = "rdb-filter-spec";
73     public final static String JavaDoc RDB_FILTER = "rdb-filter";
74     public final static String JavaDoc RDB_COLUMN_SPEC = "rdb-column-spec";
75     public final static String JavaDoc RDB_COLUMN_MATCH = "rdb-column-match";
76     public final static String JavaDoc RDB_GEN_CLASS_MAPPING = "rdb-gen-class-mapping";
77     public final static String JavaDoc RDB_EXTENSION_REF_MAPPING = "rdb-extension-ref-mapping";
78     public final static String JavaDoc PARENT_CLASS_MAPPING = "parent-class-mapping";
79
80     public final static String JavaDoc LINKEND_SEP = "/";
81
82     /**
83      * Builds a new rdb domtree generator.
84      * This class is loaded by a classloader.
85      */

86     public RdbDomtreeBuilder() {
87         // keep empty
88
}
89
90     /**
91      * Adds a rdb-class-mapping element to a mapping element.
92      * @param document an org.w3c.dom.Document object,
93      * mappingElement a mapping element,
94      * classMapping a <tt>ClassMapping</tt> object.
95      */

96     public void processClassMapping(Document JavaDoc document, Element mappingElement,
97                                     ClassMapping classMapping) throws PException {
98         Element cmElement = document.createElement(RDB_CLASS_MAPPING);
99         //cmElement.setAttribute("link-end", currentClass.getName());
100
mappingElement.appendChild(cmElement);
101         // Processes the dependencies among classes.
102
if (!(classMapping.getDependencies().isEmpty())) {
103             Iterator JavaDoc classNameIterator = classMapping.getDependencies().iterator();
104             while (classNameIterator.hasNext()) {
105                 String JavaDoc jormClassName = (String JavaDoc) classNameIterator.next();
106                 Element ccElement = document.createElement(COLOCATED_CLASS);
107                 ccElement.setAttribute("class-name", jormClassName);
108                 if (logger.isLoggable(BasicLevel.DEBUG)) {
109                     logger.log(BasicLevel.DEBUG,
110                                "begin =<" + ccElement.getTagName() + ">");
111                     logger.log(BasicLevel.DEBUG,
112                                " colocated class =<" + jormClassName + ">");
113                 }
114                 cmElement.appendChild(ccElement);
115                 if (logger.isLoggable(BasicLevel.DEBUG)) {
116                     logger.log(BasicLevel.DEBUG,
117                                "end =<" + ccElement.getTagName() + ">");
118                 }
119             }
120         }
121         // Processes the RdbTable object.
122
RdbTable table = ((RdbClassMultiMapping) classMapping).getRdbTable();
123         if (table != null) {
124             String JavaDoc colocated = (table.isColocated() ? "TRUE" : "FALSE");
125             String JavaDoc colocatedMaster = (table.isColocatedMaster() ? "TRUE" : "FALSE");
126             Element tableElement = document.createElement(RDB_TABLE_SPEC);
127             tableElement.setAttribute("table-name", table.getName());
128             tableElement.setAttribute("colocated", colocated);
129             tableElement.setAttribute("colocated-master", colocatedMaster);
130             cmElement.appendChild(tableElement);
131             processRdbTableSpec(document, tableElement, table);
132         }
133         // Processes the RdbExternalTable objects.
134
if (!((RdbClassMultiMapping) classMapping).getRdbExternalTables().isEmpty()) {
135             Iterator JavaDoc etIterator = ((RdbClassMultiMapping) classMapping).getRdbExternalTables().iterator();
136             while (etIterator.hasNext()) {
137                 RdbExternalTable externalTable = (RdbExternalTable) etIterator.next();
138                 String JavaDoc etcolocated = (externalTable.isColocated() ? "TRUE" : "FALSE");
139                 String JavaDoc etcolocatedMaster = (externalTable.isColocatedMaster() ? "TRUE" : "FALSE");
140                 Element etElement = document.createElement(RDB_EXTERNAL_TABLE_SPEC);
141                 if (logger.isLoggable(BasicLevel.DEBUG)) {
142                     logger.log(BasicLevel.DEBUG,
143                                "begin =<" + etElement.getTagName() + ">");
144                 }
145                 etElement.setAttribute("table-name", externalTable.getName());
146                 etElement.setAttribute("colocated", etcolocated);
147                 etElement.setAttribute("colocated-master", etcolocatedMaster);
148                 //etElement.setAttribute("read-only", readOnly);
149
cmElement.appendChild(etElement);
150                 processRdbExternalTableSpec(document, etElement, externalTable);
151                 if (logger.isLoggable(BasicLevel.DEBUG)) {
152                     logger.log(BasicLevel.DEBUG,
153                                "end =<" + etElement.getTagName() + ">");
154                 }
155             }
156         }
157         // Processes the RdbFilter object.
158
RdbFilter filter = ((RdbClassMultiMapping) classMapping).getRdbFilter();
159         if (filter != null) {
160             Element filterElement = document.createElement(RDB_FILTER_SPEC);
161             if (logger.isLoggable(BasicLevel.DEBUG)) {
162                 logger.log(BasicLevel.DEBUG,
163                            "begin =<" + filterElement.getTagName() + ">");
164             }
165             cmElement.appendChild(filterElement);
166             Element rdbFilterElement = document.createElement(RDB_FILTER);
167             String JavaDoc filterStr = filter.getStringExpression();
168             rdbFilterElement.setAttribute("value", filterStr);
169             filterElement.appendChild(rdbFilterElement);
170             if (logger.isLoggable(BasicLevel.DEBUG)) {
171                 logger.log(BasicLevel.DEBUG,
172                    "rdf-filter <" + filterStr + ">");
173             }
174
175             if (logger.isLoggable(BasicLevel.DEBUG)) {
176                 logger.log(BasicLevel.DEBUG,
177                            "end =<" + filterElement.getTagName() + ">");
178             }
179         }
180
181         // Processes the ParentClassMapping objects.
182
if (logger.isLoggable(BasicLevel.DEBUG)) {
183                 logger.log(BasicLevel.DEBUG,
184                            "rdb-class-mapping.linkedMO = " + ((Class JavaDoc) classMapping.getLinkedMO()).getFQName());
185             }
186         Collection JavaDoc pcm = classMapping.getParentClassMappings();
187             if (logger.isLoggable(BasicLevel.DEBUG)) {
188                 logger.log(BasicLevel.DEBUG,
189                            "pcm = " + pcm);
190             }
191         if (!pcm.isEmpty()) {
192             if (logger.isLoggable(BasicLevel.DEBUG)) {
193                 logger.log(BasicLevel.DEBUG,
194                            "begin =<parent-class-mapping>");
195             }
196             Iterator JavaDoc pcmIterator = pcm.iterator();
197             while (pcmIterator.hasNext()) {
198                 ParentClassMapping parentClassMapping = (ParentClassMapping) pcmIterator.next();
199                 Element pcmElem = document.createElement(PARENT_CLASS_MAPPING);
200                 pcmElem.setAttribute("link-end", parentClassMapping.getFQName());
201                 pcmElem.setAttribute("rule-name", parentClassMapping.getRuleName());
202                 cmElement.appendChild(pcmElem);
203             }
204         }
205
206
207         // Processes the IdentifierMapping object.
208
IdentifierMapping identifierMapping = classMapping.getIdentifierMapping();
209         if ( identifierMapping != null) {
210             // Gets the referenced NameDef object
211
NameDef idNameDef = (NameDef) identifierMapping.getLinkedMO();
212             // Gets the parent of the NameDef object
213
Class JavaDoc parent = (Class JavaDoc) idNameDef.getParent();
214             String JavaDoc linkend = null;
215             //TODO: simplify code - see JormPathHelper
216
if (parent == currentClass) {
217                 linkend = idNameDef.getName();
218             } else {
219                 linkend = LINKEND_SEP + parent.getFQName() + LINKEND_SEP + idNameDef.getName();
220             }
221             Element idNameDefElement = document.createElement(ID_MAPPING);
222             //idNameDefElement.setAttribute("link-end", (String) metaobject2idvalue.get(idNameDef));
223
idNameDefElement.setAttribute("link-end", linkend);
224             cmElement.appendChild(idNameDefElement);
225         }
226
227         // Processes the ReferenceMapping objects.
228
if (!(classMapping.getReferenceMappings().isEmpty())) {
229             Iterator JavaDoc rmIterator = classMapping.getReferenceMappings().iterator();
230             while (rmIterator.hasNext()) {
231                 ReferenceMapping referenceMapping = (ReferenceMapping) rmIterator.next();
232                 NameDef refNameDef = (NameDef) referenceMapping.getLinkedMO();
233                 String JavaDoc ruleName = referenceMapping.getRuleName();
234                 // Gets the parent of the Reference object that contains this NameDef object.
235
Reference reference = (Reference) refNameDef.getParent();
236                 String JavaDoc linkend = null;
237                 Class JavaDoc clazz = (Class JavaDoc) reference.getParent();
238                 if (clazz == currentClass) {
239                     linkend = (refNameDef.getName().equals("")
240                         ? reference.getName()
241                         : reference.getName() + LINKEND_SEP + refNameDef.getName());
242                 } else {
243                     linkend = LINKEND_SEP + clazz.getFQName() + LINKEND_SEP + reference.getName() + LINKEND_SEP + refNameDef.getName();
244                 }
245                 Element refElement = null;
246                 if (refNameDef.getParent() instanceof ClassRef) {
247                     refElement = document.createElement(RDB_CLASS_REF_MAPPING);
248                 } else if (refNameDef.getParent() instanceof GenClassRef) {
249                     refElement = document.createElement(RDB_GEN_CLASS_REF_MAPPING);
250                 }
251                 //refElement.setAttribute("link-end", (String) metaobject2idvalue.get(refNameDef));
252
refElement.setAttribute("link-end", linkend);
253                 refElement.setAttribute("rule-name", ruleName);
254                 cmElement.appendChild(refElement);
255             }
256         }
257     }
258
259     /**
260      * Adds rdb-column-spec elements to a rdb-table-spec element.
261      * @param document an org.w3c.dom.Document object,
262      * tableElement a rdb-table-spec element,
263      * table an <tt>RdbTable</tt> object.
264      */

265     private void processRdbTableSpec(Document JavaDoc document, Element tableElement, RdbTable table) {
266         // Processes the PrimitiveElementMapping objects.
267
if (!(table.getPrimitiveElementMappings().isEmpty())) {
268             Iterator JavaDoc pemIterator = table.getPrimitiveElementMappings().iterator();
269             while (pemIterator.hasNext()) {
270                 RdbPrimitiveElementMapping pem = (RdbPrimitiveElementMapping) pemIterator.next();
271                 String JavaDoc notNull = (pem.isNotNull() ? "TRUE" : "FALSE");
272                 PrimitiveElement pe = (PrimitiveElement) pem.getLinkedMO();
273                 Element csElement = document.createElement(RDB_COLUMN_SPEC);
274                 //csElement.setAttribute("link-end", (String) metaobject2idvalue.get(pe));
275
// if pe is a field or a scalarfield, link-end is set with the corresponding field name.
276
// if pe defines the primitive type of a generic class, link-end is set with the
277
// corresponding gen-class name.
278
MetaObject parent = pe.getParent();
279                 String JavaDoc linkend = pe.getName();
280                 if (parent instanceof Class JavaDoc) {
281                     boolean isInherited = (parent != currentClass);
282                     if (isInherited) {
283                         linkend = LINKEND_SEP + ((Class JavaDoc) parent).getFQName() + LINKEND_SEP + pe.getName();
284                     }
285                 }
286                 logger.log(BasicLevel.DEBUG,
287                                " rdb-column-spec link-end =<" + linkend + ">");
288                 csElement.setAttribute("link-end", linkend);
289                 csElement.setAttribute("column-name", pem.getName());
290                 csElement.setAttribute("sql-type", pem.getType());
291                 csElement.setAttribute("not-null", notNull);
292                 csElement.setAttribute("join-name", "");
293                 tableElement.appendChild(csElement);
294             }
295         }
296     }
297
298     /**
299      * Adds rdb-join and rdb-column-spec elements to a rdb-external-table-spec element.
300      * @param document an org.w3c.dom.Document object,
301      * etElement a rdb-external-table-spec element,
302      * externalTable a <tt>RdbExternalTable</tt> object.
303      */

304     private void processRdbExternalTableSpec(Document JavaDoc document, Element etElement,
305                                              RdbExternalTable externalTable) throws PException {
306         // Processes the Join objects.
307
Iterator JavaDoc joinIterator = externalTable.getRdbJoins().iterator();
308         while (joinIterator.hasNext()) {
309             RdbJoin join = (RdbJoin) joinIterator.next();
310             Element joinElement = document.createElement(RDB_JOIN);
311             joinElement.setAttribute("name", join.getName());
312             etElement.appendChild(joinElement);
313             processRdbJoin(document, joinElement, join);
314         }
315         // Processes the PrimitiveElement objects.
316
if (!(externalTable.getPrimitiveElementMappings().isEmpty())) {
317             Iterator JavaDoc peIterator = externalTable.getPrimitiveElementMappings().iterator();
318             Element csElement = null;
319             while (peIterator.hasNext()) {
320                 RdbPrimitiveElementMapping pem = (RdbPrimitiveElementMapping) peIterator.next();
321                 String JavaDoc notNull = (pem.isNotNull() ? "TRUE" : "FALSE");
322                 PrimitiveElement pe = null;
323                 RdbJoin join = null;
324                 Map JavaDoc join2pe = pem.getPrimitiveElementByRdbJoin();
325                 if (join2pe != null) {
326                     // the column is associated with several PrimitiveElement objects
327
joinIterator = join2pe.keySet().iterator();
328                     while (joinIterator.hasNext()) {
329                         join = (RdbJoin) joinIterator.next();
330                         pe = (PrimitiveElement) join2pe.get(join);
331                         csElement = document.createElement(RDB_COLUMN_SPEC);
332                         csElement.setAttribute("link-end", pe.getName());
333                         csElement.setAttribute("column-name", pem.getName());
334                         csElement.setAttribute("sql-type", pem.getType());
335                         csElement.setAttribute("not-null", notNull);
336                         csElement.setAttribute("join-name", join.getName());
337                         etElement.appendChild(csElement);
338                     }
339                 } else {
340                     pe = (PrimitiveElement) pem.getLinkedMO();
341                     join = pem.getJoinByPrimitiveElement(pe);
342                     if (join == null) {
343                         throw new PException("No join defined in the external table for the field: "
344                                              + pe.getName());
345                     }
346                     csElement = document.createElement(RDB_COLUMN_SPEC);
347                     csElement.setAttribute("link-end", pe.getName());
348                     csElement.setAttribute("column-name", pem.getName());
349                     csElement.setAttribute("sql-type", pem.getType());
350                     csElement.setAttribute("not-null", notNull);
351                     csElement.setAttribute("join-name", join.getName());
352                     etElement.appendChild(csElement);
353                 }
354                 if (logger.isLoggable(BasicLevel.DEBUG)) {
355                     logger.log(BasicLevel.DEBUG,
356                                "begin =<" + csElement.getTagName() + ">");
357                 }
358                 //csElement.setAttribute("link-end", (String) metaobject2idvalue.get(pe));
359
if (logger.isLoggable(BasicLevel.DEBUG)) {
360                     logger.log(BasicLevel.DEBUG,
361                                "end =<" + csElement.getTagName() + ">");
362                 }
363             }
364         }
365     }
366
367     /**
368      * Adds rdb-column-match elements to a rdb-join element.
369      * @param document an org.w3c.dom.Document object,
370      * joinElement a rdb-join element,
371      * RdbJoin a <tt>RdbJoin</tt> object.
372      */

373     private void processRdbJoin(Document JavaDoc document, Element joinElement, RdbJoin join) {
374         // Processes the join columns.
375
Iterator JavaDoc column1Iterator = join.getPTJoinColumnNames().iterator();
376         Iterator JavaDoc column2Iterator = join.getETJoinColumnNames().iterator();
377         while (column1Iterator.hasNext()) {
378             String JavaDoc column1 = (String JavaDoc) column1Iterator.next();
379             String JavaDoc column2 = (String JavaDoc) column2Iterator.next();
380             Element cmElement = document.createElement(RDB_COLUMN_MATCH);
381             cmElement.setAttribute("column1", column1);
382             cmElement.setAttribute("column2", column2);
383             ;
384             joinElement.appendChild(cmElement);
385         }
386     }
387
388     /**
389      * Adds a rdb-gen-class-mapping element to a mapping element.
390      * @param document an org.w3c.dom.Document object,
391      * mappingElement a mapping element,
392      * genClassMapping a <tt>GenClassMapping</tt> object.
393      */

394     public void processGenClassMapping(Document JavaDoc document, Element mappingElement,
395                                        GenClassMapping genClassMapping) throws PException {
396         GenClassRef genClassRef = (GenClassRef) genClassMapping.getLinkedMO();
397         Element gcmElement = document.createElement(RDB_GEN_CLASS_MAPPING);
398         gcmElement.setAttribute("link-end", (String JavaDoc) metaobject2idvalue.get(genClassRef));
399         mappingElement.appendChild(gcmElement);
400         // Processes the RdbTable object.
401
RdbTable table = ((RdbGenClassMapping) genClassMapping).getRdbTable();
402         String JavaDoc colocated = (table.isColocated() ? "TRUE" : "FALSE");
403         String JavaDoc colocatedMaster = (table.isColocatedMaster() ? "TRUE" : "FALSE");
404         Element tableElement = document.createElement(RDB_TABLE_SPEC);
405         tableElement.setAttribute("table-name", table.getName());
406         tableElement.setAttribute("colocated", colocated);
407         tableElement.setAttribute("colocated-master", colocatedMaster);
408         gcmElement.appendChild(tableElement);
409         processRdbTableSpec(document, tableElement, table);
410         // Processes the RdbExternalTable objects.
411
if (((RdbGenClassMapping) genClassMapping).getRdbExternalTables() != null) {
412             Iterator JavaDoc etIterator = ((RdbClassMultiMapping) genClassMapping).getRdbExternalTables().iterator();
413             while (etIterator.hasNext()) {
414                 RdbExternalTable externalTable = (RdbExternalTable) etIterator.next();
415                 String JavaDoc etcolocated = (externalTable.isColocated() ? "TRUE" : "FALSE");
416                 String JavaDoc etcolocatedMaster = (externalTable.isColocatedMaster() ? "TRUE" : "FALSE");
417                 Element etElement = document.createElement(RDB_EXTERNAL_TABLE_SPEC);
418                 if (logger.isLoggable(BasicLevel.DEBUG)) {
419                     logger.log(BasicLevel.DEBUG,
420                                "begin =<" + etElement.getTagName() + ">");
421                 }
422                 etElement.setAttribute("table-name", externalTable.getName());
423                 etElement.setAttribute("colocated", etcolocated);
424                 etElement.setAttribute("colocated-master", etcolocatedMaster);
425                 //etElement.setAttribute("read-only", readOnly);
426
gcmElement.appendChild(etElement);
427                 processRdbExternalTableSpec(document, etElement, externalTable);
428                 if (logger.isLoggable(BasicLevel.DEBUG)) {
429                     logger.log(BasicLevel.DEBUG,
430                                "end =<" + etElement.getTagName() + ">");
431                 }
432             }
433         }
434         // Processes the IdentifierMapping object.
435
IdentifierMapping identifierMapping = genClassMapping.getIdentifierMapping();
436         NameDef idNameDef = (NameDef) identifierMapping.getLinkedMO();
437         Element idNameDefElement = document.createElement(ID_MAPPING);
438         //idNameDefElement.setAttribute("link-end", (String) metaobject2idvalue.get(idNameDef));
439
idNameDefElement.setAttribute("link-end", idNameDef.getName());
440         gcmElement.appendChild(idNameDefElement);
441         // Processes the ReferenceMapping object.
442
if (genClassMapping.getReferenceMapping() != null) {
443             ReferenceMapping referenceMapping = genClassMapping.getReferenceMapping();
444             NameDef refNameDef = (NameDef) referenceMapping.getLinkedMO();
445             Element refElement = document.createElement(RDB_REF_MAPPING);
446             //refElement.setAttribute("link-end", (String) metaobject2idvalue.get(refNameDef));
447
refElement.setAttribute("link-end", refNameDef.getName());
448             refElement.setAttribute("rule-name", referenceMapping.getRuleName());
449             gcmElement.appendChild(refElement);
450         }
451     }
452 }
453
454
Popular Tags