001: package org.ontoware.rdfreactor.generator.java;
002:
003: import java.util.ArrayList;
004: import java.util.List;
005:
006: import org.apache.commons.logging.Log;
007: import org.apache.commons.logging.LogFactory;
008:
009: /**
010: * A <b>JPackage</b> represents a package in Java.
011: * Explicit modelling of packages allows the mapping of different namespaces in RDF to
012: * different Java packages.
013: *
014: * A JPackage has a name (typically with dots) and a List of JClass instances,
015: * representing the classes in the package.
016: *
017: * @author $Author: xamde $
018: * @version $Id: JPackage.java,v 1.8 2006/06/21 13:24:40 xamde Exp $
019: *
020: */
021: public class JPackage {
022:
023: public static final JPackage JAVA_LANG = new JPackage("java.lang");
024:
025: public static final JPackage JAVA_UTIL = new JPackage("java.util");
026:
027: public static final JPackage RDFSCHEMA = new JPackage(
028: "org.ontoware.rdfreactor.schema.rdfs");
029:
030: public static final JPackage OWL = new JPackage(
031: "org.ontoware.rdfreactor.schema.owl");
032:
033: private static Log log = LogFactory.getLog(JPackage.class);
034:
035: /** the name of the JPackage, usually it conforms to java package naming conventions */
036: private String name;
037:
038: /** the List of JClasses belonging to this JPackage */
039: private List<JClass> classes = new ArrayList<JClass>();
040:
041: public JPackage(String name) {
042: this .name = name;
043: }
044:
045: public String getName() {
046: return this .name;
047: }
048:
049: public void addClass(JClass someClass) {
050: classes.add(someClass);
051: }
052:
053: public List<JClass> getClasses() {
054: return this .classes;
055: }
056:
057: /**
058: * apply consistency checks to this JPackage and all instances
059: * of JClass and JProperty in it.
060: *
061: * @return true if the JPackage and all its parts are consistent
062: */
063: public boolean isConsistent() {
064: boolean result = true;
065: for (JClass jc : classes) {
066: if (!jc.isConsistent())
067: log.warn(jc.getName() + " is not consistent");
068: result &= jc.isConsistent();
069: }
070: return result;
071: }
072:
073: public String toString() {
074: StringBuffer buf = new StringBuffer();
075: buf.append(" JPackage " + name + "\n");
076: for (JClass jc : classes) {
077: buf.append(jc.toDebug());
078: }
079: return buf.toString();
080: }
081:
082: /** generate a verbose report of this JPackage */
083: public String toReport() {
084: StringBuffer buf = new StringBuffer();
085: buf.append("Package -------------------\n");
086: for (JClass jc : classes) {
087: buf.append(jc.toReport());
088: }
089: return buf.toString();
090: }
091:
092: /**
093: * two packages are equal, iff they have the same name. Note: they may have
094: * different classes.
095: */
096: public boolean equals(Object other) {
097: return (other instanceof JPackage && ((JPackage) other)
098: .getName().equals(this.getName()));
099: }
100: }
|