Author: tfmorris
Date: 2007-05-27 22:46:18-0700
New Revision: 12694
Modified:
trunk/src_new/org/argouml/uml/reveng/java/ClassifierContext.java
trunk/src_new/org/argouml/uml/reveng/java/Context.java
trunk/src_new/org/argouml/uml/reveng/java/OuterClassifierContext.java
trunk/src_new/org/argouml/uml/reveng/java/PackageContext.java
Log:
Refactor to eliminate redundant code
Modified: trunk/src_new/org/argouml/uml/reveng/java/ClassifierContext.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src_new/org/argouml/uml/reveng/java/ClassifierContext.java?view=diff&rev=12694&p1=trunk/src_new/org/argouml/uml/reveng/java/ClassifierContext.java&p2=trunk/src_new/org/argouml/uml/reveng/java/ClassifierContext.java&r1=12693&r2=12694
==============================================================================
--- trunk/src_new/org/argouml/uml/reveng/java/ClassifierContext.java (original)
+++ trunk/src_new/org/argouml/uml/reveng/java/ClassifierContext.java 2007-05-27 22:46:18-0700
@@ -1,5 +1,5 @@
// $Id$
-// Copyright (c) 1996-2006 The Regents of the University of California. All
+// Copyright (c) 1996-2007 The Regents of the University of California. All
// Rights Reserved. Permission to use, copy, modify, and distribute this
// software and its documentation without fee, and without a written
// agreement is hereby granted, provided that the above copyright notice
@@ -54,21 +54,7 @@
public Object getInterface(String name)
throws ClassifierNotFoundException
{
- // Check if it is this interface
- if (name.equals(Model.getFacade().getName(mClassifier))
- && Model.getFacade().isAInterface(mClassifier))
- {
- return mClassifier;
- }
- else {
- // Continue the search through the rest of the model
- if (getContext() != null) {
- return getContext().getInterface(name);
- }
- else {
- return null;
- }
- }
+ return get(name, true);
}
/**
@@ -77,17 +63,31 @@
* @param classifierName The name of the classifier to retrieve.
* @return A classifier for the name.
*/
- public Object get(String classifierName)
+ public Object get(String classifierName)
+ throws ClassifierNotFoundException {
+ return get(classifierName, false);
+ }
+
+ /**
+ * Get the classifier for a given name
+ *
+ * @param classifierName
+ * The name of the classifier to retrieve.
+ * @return A classifier for the name.
+ */
+ public Object get(String classifierName, boolean interfacesOnly)
throws ClassifierNotFoundException
{
// Check if it is this classifier
- if (classifierName.equals(Model.getFacade().getName(mClassifier))) {
+ if (classifierName.equals(Model.getFacade().getName(mClassifier))
+ && (!interfacesOnly || Model.getFacade().isAInterface(
+ mClassifier))) {
return mClassifier;
}
else {
// Continue the search through the rest of the model
if (getContext() != null) {
- return getContext().get(classifierName);
+ return getContext().get(classifierName, interfacesOnly);
}
else {
return null;
Modified: trunk/src_new/org/argouml/uml/reveng/java/Context.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src_new/org/argouml/uml/reveng/java/Context.java?view=diff&rev=12694&p1=trunk/src_new/org/argouml/uml/reveng/java/Context.java&p2=trunk/src_new/org/argouml/uml/reveng/java/Context.java&r1=12693&r2=12694
==============================================================================
--- trunk/src_new/org/argouml/uml/reveng/java/Context.java (original)
+++ trunk/src_new/org/argouml/uml/reveng/java/Context.java 2007-05-27 22:46:18-0700
@@ -1,5 +1,5 @@
// $Id$
-// Copyright (c) 1996-2006 The Regents of the University of California. All
+// Copyright (c) 1996-2007 The Regents of the University of California. All
// Rights Reserved. Permission to use, copy, modify, and distribute this
// software and its documentation without fee, and without a written
// agreement is hereby granted, provided that the above copyright notice
@@ -63,7 +63,17 @@
*/
public abstract Object get(String name)
throws ClassifierNotFoundException;
-
+
+ public abstract Object get(String name, boolean interfacesOnly)
+ throws ClassifierNotFoundException;
+
+ /**
+ * Return a classifier restricting the search to Interfaces only.
+ *
+ * @param name the name of the Interface to search for
+ * @return
+ * @throws ClassifierNotFoundException
+ */
public abstract Object getInterface(String name)
throws ClassifierNotFoundException;
Modified: trunk/src_new/org/argouml/uml/reveng/java/OuterClassifierContext.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src_new/org/argouml/uml/reveng/java/OuterClassifierContext.java?view=diff&rev=12694&p1=trunk/src_new/org/argouml/uml/reveng/java/OuterClassifierContext.java&p2=trunk/src_new/org/argouml/uml/reveng/java/OuterClassifierContext.java&r1=12693&r2=12694
==============================================================================
--- trunk/src_new/org/argouml/uml/reveng/java/OuterClassifierContext.java (original)
+++ trunk/src_new/org/argouml/uml/reveng/java/OuterClassifierContext.java 2007-05-27 22:46:18-0700
@@ -1,5 +1,5 @@
// $Id$
-// Copyright (c) 2003-2006 The Regents of the University of California. All
+// Copyright (c) 2003-2007 The Regents of the University of California. All
// Rights Reserved. Permission to use, copy, modify, and distribute this
// software and its documentation without fee, and without a written
// agreement is hereby granted, provided that the above copyright notice
@@ -71,76 +71,7 @@
public Object getInterface(String name)
throws ClassifierNotFoundException {
- // Search in classifier
- Object mInterface = Model.getFacade().lookupIn(mClassifier, name);
-
- if (mInterface == null) {
- Class classifier;
- // Try to find it via the classpath
- try {
-
- // Special case for model
- if (Model.getFacade().isAModel(mPackage)) {
- classifier = Class.forName(namePrefix + name);
- }
- else {
- String clazzName =
- packageJavaName + "." + namePrefix + name;
- classifier =
- Class.forName(clazzName);
- }
- if (classifier.isInterface()) {
- mInterface =
- Model.getCoreFactory()
- .buildInterface(name, mClassifier);
- }
- else {
- // Only interfaces will do
- throw new ClassNotFoundException();
- }
- }
- catch (ClassNotFoundException e) {
-
- // try USER classpath
- try {
- // Special case for model
- if (Model.getFacade().isAModel(mPackage)) {
- classifier = Class.forName(namePrefix + name);
- classifier =
- ImportClassLoader.getInstance()
- .loadClass(namePrefix + name);
- }
- else {
- String clazzName =
- packageJavaName + "." + namePrefix + name;
- classifier =
- ImportClassLoader.getInstance()
- .loadClass(clazzName);
- }
- if (classifier.isInterface()) {
- mInterface =
- Model.getCoreFactory()
- .buildInterface(name, mClassifier);
- }
- else {
- // Only interfaces will do
- throw new ClassNotFoundException();
- }
-
- }
- catch (Exception e1) {
- // TODO: This too broad an exception catch to just continue
- // with - narrow to specific expected errors that can be
- // ignored
- LOG.warn(e1);
- // Continue the search through the rest of the model
- if (getContext() != null) {
- mInterface = getContext().getInterface(name);
- }
- }
- }
- }
- return mInterface;
+ return get(name, true);
}
/**
@@ -153,6 +84,11 @@
* @return Found classifier.
*/
public Object get(String name)
+ throws ClassifierNotFoundException {
+ return get(name, false);
+ }
+
+ public Object get(String name, boolean interfacesOnly)
throws ClassifierNotFoundException {
// Search in classifier
Object iClassifier = Model.getFacade().lookupIn(mClassifier, name);
@@ -178,9 +114,13 @@
.buildInterface(name, mClassifier);
}
else {
- iClassifier =
- Model.getCoreFactory()
- .buildClass(name, mClassifier);
+ if (interfacesOnly) {
+ throw new ClassNotFoundException();
+ } else {
+ iClassifier =
+ Model.getCoreFactory().buildClass(
+ name, mClassifier);
+ }
}
}
catch (ClassNotFoundException e) {
@@ -207,9 +147,13 @@
.buildInterface(name, mClassifier);
}
else {
- iClassifier =
- Model.getCoreFactory()
- .buildClass(name, mClassifier);
+ if (interfacesOnly) {
+ throw new ClassNotFoundException();
+ } else {
+ iClassifier =
+ Model.getCoreFactory().buildClass(
+ name, mClassifier);
+ }
}
}
@@ -223,7 +167,7 @@
// Continue the search through the rest of the model
if (getContext() != null) {
- iClassifier = getContext().get(name);
+ iClassifier = getContext().get(name, interfacesOnly);
}
}
}
Modified: trunk/src_new/org/argouml/uml/reveng/java/PackageContext.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src_new/org/argouml/uml/reveng/java/PackageContext.java?view=diff&rev=12694&p1=trunk/src_new/org/argouml/uml/reveng/java/PackageContext.java&p2=trunk/src_new/org/argouml/uml/reveng/java/PackageContext.java&r1=12693&r2=12694
==============================================================================
--- trunk/src_new/org/argouml/uml/reveng/java/PackageContext.java (original)
+++ trunk/src_new/org/argouml/uml/reveng/java/PackageContext.java 2007-05-27 22:46:18-0700
@@ -60,69 +60,7 @@
public Object getInterface(String name)
throws ClassifierNotFoundException {
- // Search in model
- Object mInterface = Model.getFacade().lookupIn(mPackage, name);
-
- if (mInterface == null) {
- Class classifier;
-
- // Try to find it via the classpath
- try {
-
- // Special case for model
- if (Model.getFacade().isAModel(mPackage)) {
- classifier = Class.forName(name);
- }
- else {
- String clazzName = javaName + "." + name;
- classifier =
- Class.forName(clazzName);
- }
- if (classifier.isInterface()) {
- mInterface =
- Model.getCoreFactory()
- .buildInterface(name, mPackage);
- setGeneratedTag(mInterface);
- }
- }
- catch (ClassNotFoundException e) {
- // We didn't find any interface
- // try USER classpath
- try {
- // Special case for model
- if (Model.getFacade().isAModel(mPackage)) {
- classifier =
- ImportClassLoader.getInstance().loadClass(name);
- }
- else {
- String clazzName = javaName + "." + name;
- classifier =
- ImportClassLoader.getInstance()
- .loadClass(clazzName);
- }
- if (classifier.isInterface()) {
- mInterface =
- Model.getCoreFactory()
- .buildInterface(name, mPackage);
- setGeneratedTag(mInterface);
- }
- } catch (MalformedURLException e1) {
- LOG.warn("Classpath configuration error ", e1);
- } catch (ClassNotFoundException e1) {
- // Ignore - we'll deal with this later by checking to see
- // if we found anything.
- }
- }
- }
- if (mInterface == null && getContext() != null) {
- // Continue the search through the rest of the model
- mInterface = getContext().getInterface(name);
- }
- if (mInterface == null) {
- throw new ClassifierNotFoundException(name);
- }
-
- return mInterface;
+ return get(name, true);
}
/**
@@ -136,6 +74,21 @@
* @throws ClassifierNotFoundException if classifier couldn't be located
*/
public Object get(String name)
+ throws ClassifierNotFoundException {
+ return get(name, false);
+ }
+
+ /**
+ * Get a classifier from the model. If it is not in the model, try
+ * to find it with the CLASSPATH. If found, in the classpath, the
+ * classifier is created and added to the model. If not found at
+ * all, a datatype is created and added to the model.
+ *
+ * @param name The name of the classifier to find.
+ * @return Found classifier.
+ * @throws ClassifierNotFoundException if classifier couldn't be located
+ */
+ public Object get(String name, boolean interfacesOnly)
throws ClassifierNotFoundException {
// Search in model
Object mClassifier = Model.getFacade().lookupIn(mPackage, name);
@@ -151,20 +104,22 @@
}
else {
String clazzName = javaName + "." + name;
- classifier =
- Class.forName(clazzName);
+ classifier = Class.forName(clazzName);
}
if (classifier.isInterface()) {
mClassifier =
- Model.getCoreFactory()
- .buildInterface(name, mPackage);
- }
- else {
- mClassifier =
- Model.getCoreFactory()
- .buildClass(name, mPackage);
+ Model.getCoreFactory().buildInterface(
+ name, mPackage);
+ } else {
+ if (!interfacesOnly) {
+ mClassifier =
+ Model.getCoreFactory().buildClass(
+ name, mPackage);
+ }
}
- setGeneratedTag(mClassifier);
+ if (mClassifier != null) {
+ setGeneratedTag(mClassifier);
+ }
}
catch (ClassNotFoundException e) {
// No class or interface found
@@ -184,14 +139,18 @@
}
if (classifier.isInterface()) {
mClassifier =
- Model.getCoreFactory()
- .buildInterface(name, mPackage);
+ Model.getCoreFactory().buildInterface(
+ name, mPackage);
} else {
- mClassifier =
- Model.getCoreFactory()
- .buildClass(name, mPackage);
+ if (!interfacesOnly) {
+ mClassifier =
+ Model.getCoreFactory().buildClass(
+ name, mPackage);
+ }
}
- setGeneratedTag(mClassifier);
+ if (mClassifier != null) {
+ setGeneratedTag(mClassifier);
+ }
}
catch (ClassNotFoundException e1) {
// Ignore - we'll deal with this later by checking to see
@@ -204,21 +163,21 @@
if (mClassifier == null) {
// Continue the search through the rest of the model
if (getContext() != null) {
- mClassifier = getContext().get(name);
- }
- else {
+ mClassifier = getContext().get(name, interfacesOnly);
+ } else {
// Check for java data types
- if (name.equals("int")
- || name.equals("long")
- || name.equals("short")
- || name.equals("byte")
- || name.equals("char")
- || name.equals("float")
- || name.equals("double")
- || name.equals("boolean")
- || name.equals("void")
- // How do I represent arrays in UML?
- || name.indexOf("[]") != -1) {
+ if (!interfacesOnly
+ && name.equals("int")
+ || name.equals("long")
+ || name.equals("short")
+ || name.equals("byte")
+ || name.equals("char")
+ || name.equals("float")
+ || name.equals("double")
+ || name.equals("boolean")
+ || name.equals("void")
+ // How do I represent arrays in UML?
+ || name.indexOf("[]") != -1) {
mClassifier =
Model.getCoreFactory()
.buildDataType(name, mPackage);
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.