001: /*
002: * Hammurapi
003: * Automated Java code review system.
004: * Copyright (C) 2004 Johannes Bellert
005: *
006: * This program is free software; you can redistribute it and/or modify
007: * it under the terms of the GNU General Public License as published by
008: * the Free Software Foundation; either version 2 of the License, or
009: * (at your option) any later version.
010: *
011: * This program is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014: * GNU General Public License for more details.
015: *
016: * You should have received a copy of the GNU General Public License
017: * along with this program; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
019: *
020: * URL: http://www.pavelvlasov.com/pv/content/menu.show?id=products.jtaste
021: * e-Mail: Johannes.Bellert@ercgroup.com
022: *
023: * * Created on Apr 9, 2004
024: *
025: */
026: package org.hammurapi.inspectors.metrics;
027:
028: import java.io.InputStream;
029: import java.util.Collection;
030: import java.util.Enumeration;
031: import java.util.Hashtable;
032:
033: import org.apache.xpath.CachedXPathAPI;
034: import org.hammurapi.HammurapiException;
035: import org.w3c.dom.Document;
036: import org.w3c.dom.Element;
037: import org.w3c.dom.Node;
038: import org.w3c.dom.traversal.NodeIterator;
039:
040: import com.pavelvlasov.xml.dom.AbstractDomObject;
041:
042: /**
043: * @author Johannes Bellert
044: *
045: */
046: public class ArchitecturalLayerMapping extends AbstractDomObject
047: implements ArchitecturalLayerConstants {
048:
049: private String name = "<undefined>";
050:
051: public ArchitecturalLayerMapping() {
052: super ();
053: }
054:
055: public ArchitecturalLayerMapping(Element holder)
056: throws HammurapiException {
057: super ();
058: try {
059: CachedXPathAPI cxpa = new CachedXPathAPI();
060:
061: this .name = holder.getAttribute("name");
062: NodeIterator it = cxpa.selectNodeIterator(holder,
063: "TechStackEntity");
064: Node teNode;
065: while ((teNode = it.nextNode()) != null) {
066: if (teNode instanceof Element) {
067:
068: TechStackEntity tse = new TechStackEntity(
069: (Element) teNode);
070: this .mappings.put(tse.getName(), this .name);
071: //!! check for configuration bugs: if the list contains this key, thrown a exception.
072: this .techStackEntityList.put(tse.getName(), tse);
073: }
074: }
075: //init();
076: } catch (Exception e) {
077: throw new HammurapiException(e);
078: }
079: }
080:
081: //!! job: missing Hibernate, XStream, ..
082: private Hashtable mappings = new Hashtable();
083: /*
084: {
085: mappings.put(FILE_PROPERTY, HELPER_LAYER);
086: mappings.put(PDF_GEN_ITEXT, HELPER_LAYER);
087: mappings.put(JCE, HELPER_LAYER);
088: mappings.put(TIB_INCONCERT, INTEGRATION_LAYER);
089: mappings.put(TIB_INCONCERT_WEB, PRESENTATION_LAYER );
090: mappings.put(TIB_CORE, INTEGRATION_LAYER);
091: mappings.put(FILENET_ERC_PROXY, INTEGRATION_LAYER);
092: mappings.put(ACTIVATION_FRAMEWORK, INTEGRATION_LAYER);
093: mappings.put(MAIL, INTEGRATION_LAYER);
094: mappings.put(STRUTS_PLUGIN, MVC_LAYER);
095: mappings.put(STRUTS_MENU, MVC_LAYER);
096: mappings.put(STRUTS_FORM, MVC_LAYER);
097: mappings.put(STRUTS_MVC, MVC_LAYER);
098: mappings.put(STRUTS_UPLOAD, HELPER_LAYER);
099:
100: mappings.put(QUARTZ, CONTROLLER_LAYER);
101: mappings.put(EJB_ENTITYBEAN, INTEGRATION_LAYER);
102: mappings.put(EJB_SESSIONBEAN, BUSINESS_LAYER);
103: mappings.put(EJB, BUSINESS_LAYER);
104: mappings.put(HTTPSERVLET, MVC_LAYER);
105: mappings.put(JTA, INTEGRATION_LAYER);
106: mappings.put(VELOCITY, MVC_LAYER);
107:
108: mappings.put(GETTERSETTER, BUSINESS_LAYER);
109: mappings.put(IO_FILE, INTEGRATION_LAYER);
110: mappings.put(XML_W3C_DOM, HELPER_LAYER);
111: mappings.put(XML_SAX, HELPER_LAYER);
112: mappings.put(XML_PARSER, HELPER_LAYER);
113: mappings.put(APACHE_COMMONS_VALIDATOR, PRESENTATION_LAYER);
114: mappings.put(SSL, PRESENTATION_LAYER);
115: mappings.put(SECURITY_CERTIFICATE, HELPER_LAYER);
116:
117: mappings.put(JXL, INTEGRATION_LAYER);
118: mappings.put(LOGGING, HELPER_LAYER);
119: mappings.put(LOGGING_DEPRECIATED, HELPER_LAYER);
120: mappings.put(EXCEPTION, HELPER_LAYER);
121: mappings.put(SQL_DEPRECIATED, INTEGRATION_LAYER);
122: mappings.put(JSP, PRESENTATION_LAYER);
123: mappings.put(JUNIT_TEST, TEST_LAYER);
124: mappings.put(LOGGER_LOG4J, HELPER_LAYER);
125: mappings.put(SQL_COMMON, INTEGRATION_LAYER);
126: mappings.put(SQL_PREPARED, INTEGRATION_LAYER);
127: mappings.put(SQL_LOB, INTEGRATION_LAYER);
128: mappings.put(SQL_DATASOURCE, INTEGRATION_LAYER);
129:
130: mappings.put(PL_SQL, INTEGRATION_LAYER);
131: mappings.put(NETWORK, INTEGRATION_LAYER);
132: mappings.put(JMS, INTEGRATION_LAYER);
133: mappings.put(RMI, INTEGRATION_LAYER);
134: mappings.put(JNDI, HELPER_LAYER);
135: mappings.put(PL_SQL, INTEGRATION_LAYER);
136: mappings.put(JAKARTA_DBUTIL, HELPER_LAYER);
137: mappings.put(JAKARTA_BEANUTIL, BUSINESS_LAYER);
138: mappings.put(JAKARTA_DIGESTER, HELPER_LAYER);
139: mappings.put(VALUE_OBJECT, BUSINESS_LAYER);
140: mappings.put(HIBERNATE, INTEGRATION_LAYER);
141: mappings.put(SPRING_TX, INTEGRATION_LAYER);
142: mappings.put(CASTOR, HELPER_LAYER);
143: mappings.put(HTTPUNIT, TEST_LAYER );
144: }
145:
146: */
147: private Hashtable techStackEntityList = new Hashtable();
148:
149: /*
150: {
151: techStackAppreciation.put(FILE_PROPERTY, new TechStackEntity(FILE_PROPERTY, OK ));
152: techStackAppreciation.put(PDF_GEN_ITEXT, new TechStackEntity(PDF_GEN_ITEXT, OK ));
153:
154: techStackAppreciation.put(TIB_INCONCERT, new TechStackEntity(TIB_INCONCERT , OK));
155: techStackAppreciation.put(TIB_INCONCERT_WEB, new TechStackEntity(TIB_INCONCERT_WEB, OK));
156: techStackAppreciation.put(TIB_CORE, new TechStackEntity(TIB_CORE , OK));
157: techStackAppreciation.put(FILENET_ERC_PROXY, new TechStackEntity( FILENET_ERC_PROXY, OK));
158: techStackAppreciation.put(ACTIVATION_FRAMEWORK, new TechStackEntity(ACTIVATION_FRAMEWORK , OK));
159: techStackAppreciation.put(MAIL, new TechStackEntity( MAIL, OK));
160: techStackAppreciation.put(STRUTS_PLUGIN, new TechStackEntity( STRUTS_PLUGIN, OK));
161: techStackAppreciation.put(STRUTS_MENU, new TechStackEntity( STRUTS_MENU, EVALUATION));
162: techStackAppreciation.put(STRUTS_FORM, new TechStackEntity( STRUTS_FORM, OK));
163: techStackAppreciation.put(STRUTS_MVC, new TechStackEntity( STRUTS_MVC, OK));
164: techStackAppreciation.put(STRUTS_UPLOAD, new TechStackEntity( STRUTS_UPLOAD, OK));
165: techStackAppreciation.put(VELOCITY, new TechStackEntity( VELOCITY, OK));
166:
167: techStackAppreciation.put(QUARTZ, new TechStackEntity(QUARTZ , RESTRICTEDUSE));
168: techStackAppreciation.put(EJB_ENTITYBEAN, new TechStackEntity( EJB_ENTITYBEAN, OK));
169: techStackAppreciation.put(EJB_SESSIONBEAN, new TechStackEntity(EJB_SESSIONBEAN , OK));
170: techStackAppreciation.put(EJB, new TechStackEntity(EJB , OK));
171: techStackAppreciation.put(HTTPSERVLET, new TechStackEntity( HTTPSERVLET, OK));
172: techStackAppreciation.put(JTA, new TechStackEntity( JTA, OK));
173: techStackAppreciation.put(GETTERSETTER, new TechStackEntity( GETTERSETTER, OK));
174: techStackAppreciation.put(IO_FILE, new TechStackEntity(IO_FILE , OK));
175: techStackAppreciation.put(XML_W3C_DOM, new TechStackEntity( XML_W3C_DOM, OK));
176: techStackAppreciation.put(XML_SAX, new TechStackEntity( XML_SAX, OK));
177: techStackAppreciation.put(XML_PARSER, new TechStackEntity( XML_PARSER, OK));
178: techStackAppreciation.put(APACHE_COMMONS_VALIDATOR, new TechStackEntity( APACHE_COMMONS_VALIDATOR, OK));
179:
180: techStackAppreciation.put(JXL, new TechStackEntity( JXL, OK));
181: techStackAppreciation.put(SQL_DEPRECIATED, new TechStackEntity( SQL_DEPRECIATED, DEPRECIATED));
182: techStackAppreciation.put(JSP, new TechStackEntity( JSP, OK));
183: techStackAppreciation.put(SERVLET, new TechStackEntity( SERVLET, OK));
184:
185: techStackAppreciation.put(JUNIT_TEST, new TechStackEntity( JUNIT_TEST, OK));
186: techStackAppreciation.put(LOGGER_LOG4J, new TechStackEntity( LOGGER_LOG4J, OK));
187: techStackAppreciation.put(SQL_COMMON, new TechStackEntity( SQL_COMMON, OK));
188: techStackAppreciation.put(SQL_PREPARED, new TechStackEntity(SQL_PREPARED , OK));
189: techStackAppreciation.put(SQL_LOB, new TechStackEntity( SQL_LOB, OK));
190: techStackAppreciation.put(SQL_DATASOURCE, new TechStackEntity( SQL_DATASOURCE, OK));
191: techStackAppreciation.put(PL_SQL, new TechStackEntity(PL_SQL , RESTRICTEDUSE));
192: techStackAppreciation.put(VALUE_OBJECT, new TechStackEntity( VALUE_OBJECT, OK));
193: techStackAppreciation.put(EXCEPTION, new TechStackEntity( EXCEPTION, OK));
194: techStackAppreciation.put(JAKARTA_DBUTIL, new TechStackEntity( JAKARTA_DBUTIL, RESTRICTEDUSE));
195: techStackAppreciation.put(JAKARTA_BEANUTIL, new TechStackEntity( JAKARTA_BEANUTIL, OK));
196: techStackAppreciation.put(JAKARTA_DIGESTER, new TechStackEntity( JAKARTA_DIGESTER, OK));
197: techStackAppreciation.put(LOGGING, new TechStackEntity( LOGGING, OK));
198: techStackAppreciation.put(LOGGING_DEPRECIATED, new TechStackEntity( LOGGING_DEPRECIATED, DEPRECIATED));
199: techStackAppreciation.put(NETWORK, new TechStackEntity( NETWORK, OK));
200: techStackAppreciation.put(JMS, new TechStackEntity( JMS, OK));
201: techStackAppreciation.put(RMI, new TechStackEntity( RMI, OK));
202: techStackAppreciation.put(JNDI, new TechStackEntity( JNDI, OK));
203: techStackAppreciation.put(JCE, new TechStackEntity( JCE, OK));
204:
205: techStackAppreciation.put(HIBERNATE, new TechStackEntity( HIBERNATE, EVALUATION));
206: techStackAppreciation.put(CASTOR, new TechStackEntity( CASTOR, OK));
207: techStackAppreciation.put(SPRING_TX, new TechStackEntity( SPRING_TX, EVALUATION));
208: techStackAppreciation.put(HTTPUNIT, new TechStackEntity( HTTPUNIT, OK));
209: techStackAppreciation.put(SSL, new TechStackEntity( SSL, OK));
210: techStackAppreciation.put(SECURITY_CERTIFICATE, new TechStackEntity( SECURITY_CERTIFICATE, OK));
211: }
212: */
213:
214: /**
215: * @return Returns the mappings.
216: */
217: public Hashtable getMappings() {
218: return mappings;
219: }
220:
221: /**
222: * @param mappings The mappings to set.
223: */
224: public void setMappings(Hashtable mappings) {
225: this .mappings = mappings;
226: }
227:
228: public Element toDom(Document document){
229:
230: Element ret=document.createElement("LayerMappings");
231: ret.setAttribute("tier", String.valueOf(this .name));
232: ret.setAttribute("size", String.valueOf(this .mappings.size()));
233:
234: Enumeration enum = this .mappings.keys();
235: while (enum.hasMoreElements()) {
236: String layerKey = (String) enum.nextElement();
237: Element layer=document.createElement("Mapping");
238: String tier = (String)mappings.get(layerKey);
239: layer.setAttribute("identificator", layerKey );
240: layer.setAttribute("tier", tier );
241: ret.appendChild(layer);
242:
243: /* Enumeration enumTe = this.techStackEntityList.elements();
244: while (enumTe.hasMoreElements()) {
245: TechStackEntity te = (TechStackEntity) enumTe.nextElement();
246: layer.appendChild( te.toDom(document)) ;
247: }
248: */
249: }
250: return ret;
251:
252: }
253:
254: /**
255: * @return Returns the techStackAppreciation.
256: */
257: public Hashtable getTechStackEntityList() {
258: return techStackEntityList;
259: }
260:
261: /**
262: * @return Returns the techStackAppreciation.
263: */
264: public Collection getTechStackEntityListValues() {
265: return techStackEntityList.values();
266: }
267:
268: /**
269: * @param techStackAppreciation The techStackAppreciation to set.
270: */
271: public void setTechStackEntityList(Hashtable techStackAppreciation) {
272: this .techStackEntityList = techStackAppreciation;
273: }
274:
275: //!! test purpose only
276: public static void main(String[] args) {
277:
278: System.out.println("ArchitecturalLayerMapping load");
279:
280: try {
281: InputStream inspectorStream = ArchitecturalLayerMapping.class
282: .getResourceAsStream("ArchitecturalLayerMapping.xml");
283:
284: DomArchitecturalMappingSource source = new DomArchitecturalMappingSource(
285: inspectorStream);
286: source.loadLayerMappings();
287: } catch (HammurapiException e) {
288: // TODO Auto-generated catch block
289: e.printStackTrace();
290: }
291: }
292:
293: /**
294: * @return Returns the name.
295: */
296: public String getName() {
297: return name;
298: }
299:
300: /**
301: * @param name The name to set.
302: */
303: public void setName(String name) {
304: this .name = name;
305: }
306:
307: public String toString() {
308: return this .name + " " + this.getMappings().size();
309: }
310: }
|