01: /*
02: * $Id: CollaborationHandler.java 562 2005-10-24 19:03:40Z hengels $
03: * (c) Copyright 2004 con:cern development team.
04: *
05: * This file is part of con:cern (http://concern.org).
06: *
07: * con:cern is free software; you can redistribute it and/or modify
08: * it under the terms of the GNU Lesser General Public License
09: * as published by the Free Software Foundation; either version 2.1
10: * of the License, or (at your option) any later version.
11: *
12: * Please see COPYING for the complete licence.
13: */
14: package org.concern.model.cpd;
15:
16: import org.xml.sax.Attributes;
17: import org.xml.sax.SAXException;
18: import org.concern.model.*;
19:
20: public class CollaborationHandler extends ScopeHandler {
21: private Collaborator collaborator;
22: private TextHandler descriptionHandler = new TextHandler();
23: private EnvironmentEntryHandler environmentEntryHandler = new EnvironmentEntryHandler();
24:
25: public CollaborationHandler() {
26: }
27:
28: public Collaborator getCollaboration() {
29: return collaborator;
30: }
31:
32: public void startElement(String uri, String localName,
33: String qName, Attributes attributes) throws SAXException {
34: collaborator = new Collaborator(attributes.getValue("name"));
35: String cardinality = attributes.getValue("cardinality");
36: if ("one to one".equals(cardinality))
37: collaborator.setCardinality(Collaborator.ONE_TO_ONE);
38: else if ("one to many".equals(cardinality))
39: collaborator.setCardinality(Collaborator.ONE_TO_MANY);
40: else if ("many to one".equals(cardinality))
41: collaborator.setCardinality(Collaborator.MANY_TO_ONE);
42: else if ("many to many".equals(cardinality))
43: collaborator.setCardinality(Collaborator.MANY_TO_MANY);
44: }
45:
46: public void characters(char ch[], int start, int length)
47: throws SAXException {
48: }
49:
50: public void endElement(String uri, String localName, String qName)
51: throws SAXException {
52: }
53:
54: public ScopeHandler getHandler(String localName, String qName) {
55: if ("description".equals(qName))
56: return descriptionHandler;
57: else if ("env-entry".equals(qName))
58: return environmentEntryHandler;
59: else
60: throw new RuntimeException("unexpected tag " + localName
61: + " " + qName);
62: }
63:
64: public void fetchChild(ScopeHandler handler) {
65: if (handler == descriptionHandler)
66: collaborator.setDescription(descriptionHandler.getText());
67: else if (handler == environmentEntryHandler)
68: collaborator.getEnvironment().add(
69: environmentEntryHandler.getEnvironmentEntry());
70: }
71: }
|