Author: hibou
Date: Thu Jan 6 19:34:42 2011
New Revision: 1056025
URL: http://svn.apache.org/viewvc?rev=1056025&view=rev
Log:
move constants into their handler
Modified:
ant/ivy/core/trunk/src/java/org/apache/ivy/osgi/obr/xml/OBRXMLParser.java
ant/ivy/core/trunk/src/java/org/apache/ivy/osgi/obr/xml/OBRXMLWriter.java
Modified:
ant/ivy/core/trunk/src/java/org/apache/ivy/osgi/obr/xml/OBRXMLParser.java
URL:
http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/osgi/obr/xml/OBRXMLParser.java?rev=1056025&r1=1056024&r2=1056025&view=diff
==============================================================================
--- ant/ivy/core/trunk/src/java/org/apache/ivy/osgi/obr/xml/OBRXMLParser.java
(original)
+++ ant/ivy/core/trunk/src/java/org/apache/ivy/osgi/obr/xml/OBRXMLParser.java
Thu Jan 6 19:34:42 2011
@@ -37,48 +37,6 @@ import org.xml.sax.SAXException;
public class OBRXMLParser {
- static final String REPOSITORY = "repository";
-
- static final String REPOSITORY_LASTMODIFIED = "lastmodified";
-
- static final String REPOSITORY_NAME = "name";
-
- static final String RESOURCE = "resource";
-
- static final String RESOURCE_ID = "id";
-
- static final String RESOURCE_PRESENTATION_NAME = "presentationname";
-
- static final String RESOURCE_SYMBOLIC_NAME = "symbolicname";
-
- static final String RESOURCE_URI = "uri";
-
- static final String RESOURCE_VERSION = "version";
-
- static final String CAPABILITY = "capability";
-
- static final String CAPABILITY_NAME = "name";
-
- static final String CAPABILITY_PROPERTY = "p";
-
- static final String CAPABILITY_PROPERTY_NAME = "n";
-
- static final String CAPABILITY_PROPERTY_VALUE = "v";
-
- static final String CAPABILITY_PROPERTY_TYPE = "t";
-
- static final String REQUIRE = "require";
-
- static final String REQUIRE_NAME = "name";
-
- static final String REQUIRE_OPTIONAL = "optional";
-
- static final String REQUIRE_MULTIPLE = "multiple";
-
- static final String REQUIRE_EXTEND = "extend";
-
- static final String REQUIRE_FILTER = "filter";
-
static final String TRUE = "true";
static final String FALSE = "false";
@@ -96,7 +54,13 @@ public class OBRXMLParser {
return handler.repo;
}
- private static class RepositoryHandler extends DelegetingHandler {
+ static class RepositoryHandler extends DelegetingHandler {
+
+ static final String REPOSITORY = "repository";
+
+ static final String LASTMODIFIED = "lastmodified";
+
+ static final String NAME = "name";
BundleRepoDescriptor repo;
@@ -112,9 +76,9 @@ public class OBRXMLParser {
protected void handleAttributes(Attributes atts) {
repo = new
BundleRepoDescriptor(ExecutionEnvironmentProfileProvider.getInstance());
- repo.setName(atts.getValue(REPOSITORY_NAME));
+ repo.setName(atts.getValue(NAME));
- String lastModified = atts.getValue(REPOSITORY_LASTMODIFIED);
+ String lastModified = atts.getValue(LASTMODIFIED);
if (lastModified != null) {
try {
repo.setLastModified(Long.valueOf(lastModified));
@@ -127,7 +91,19 @@ public class OBRXMLParser {
}
}
- private static class ResourceHandler extends DelegetingHandler {
+ static class ResourceHandler extends DelegetingHandler {
+
+ static final String RESOURCE = "resource";
+
+ static final String ID = "id";
+
+ static final String PRESENTATION_NAME = "presentationname";
+
+ static final String SYMBOLIC_NAME = "symbolicname";
+
+ static final String URI = "uri";
+
+ static final String VERSION = "version";
BundleInfo bundleInfo;
@@ -189,14 +165,14 @@ public class OBRXMLParser {
}
protected void handleAttributes(Attributes atts) throws SAXException {
- String symbolicname = atts.getValue(RESOURCE_SYMBOLIC_NAME);
+ String symbolicname = atts.getValue(SYMBOLIC_NAME);
if (symbolicname == null) {
printError(this, "Resource with no symobilc name, skipping
it.");
skip();
return;
}
- String v = atts.getValue(RESOURCE_VERSION);
+ String v = atts.getValue(VERSION);
Version version;
if (v == null) {
version = new Version(1, 0, 0, null);
@@ -212,14 +188,14 @@ public class OBRXMLParser {
}
bundleInfo = new BundleInfo(symbolicname, version);
-
bundleInfo.setPresentationName(atts.getValue(RESOURCE_PRESENTATION_NAME));
- bundleInfo.setUri(atts.getValue(RESOURCE_URI));
- bundleInfo.setId(atts.getValue(RESOURCE_ID));
+ bundleInfo.setPresentationName(atts.getValue(PRESENTATION_NAME));
+ bundleInfo.setUri(atts.getValue(URI));
+ bundleInfo.setId(atts.getValue(ID));
}
}
- private static class ResourceDescriptionHandler extends DelegetingHandler {
+ static class ResourceDescriptionHandler extends DelegetingHandler {
public ResourceDescriptionHandler() {
super("description");
@@ -228,7 +204,7 @@ public class OBRXMLParser {
}
- private static class ResourceDocumentationHandler extends
DelegetingHandler {
+ static class ResourceDocumentationHandler extends DelegetingHandler {
public ResourceDocumentationHandler() {
super("documentation");
@@ -236,7 +212,7 @@ public class OBRXMLParser {
}
}
- private static class ResourceLicenseHandler extends DelegetingHandler {
+ static class ResourceLicenseHandler extends DelegetingHandler {
public ResourceLicenseHandler() {
super("license");
@@ -245,7 +221,7 @@ public class OBRXMLParser {
}
- private static class ResourceSizeHandler extends DelegetingHandler {
+ static class ResourceSizeHandler extends DelegetingHandler {
public ResourceSizeHandler() {
super("size");
@@ -253,7 +229,11 @@ public class OBRXMLParser {
}
}
- private static class CapabilityHandler extends DelegetingHandler {
+ static class CapabilityHandler extends DelegetingHandler {
+
+ static final String CAPABILITY = "capability";
+
+ static final String NAME = "name";
Capability capability;
@@ -285,7 +265,7 @@ public class OBRXMLParser {
}
protected void handleAttributes(Attributes atts) throws SAXException {
- String name = atts.getValue(CAPABILITY_NAME);
+ String name = atts.getValue(NAME);
if (name == null) {
skipResourceOnError(this, "Capability with no name");
return;
@@ -296,7 +276,15 @@ public class OBRXMLParser {
}
- private static class CapabilityPropertyHandler extends DelegetingHandler {
+ static class CapabilityPropertyHandler extends DelegetingHandler {
+
+ static final String CAPABILITY_PROPERTY = "p";
+
+ static final String NAME = "n";
+
+ static final String VALUE = "v";
+
+ static final String TYPE = "t";
String name;
@@ -309,13 +297,25 @@ public class OBRXMLParser {
}
protected void handleAttributes(Attributes atts) throws SAXException {
- name = atts.getValue(CAPABILITY_PROPERTY_NAME);
- value = atts.getValue(CAPABILITY_PROPERTY_VALUE);
- type = atts.getValue(CAPABILITY_PROPERTY_TYPE);
+ name = atts.getValue(NAME);
+ value = atts.getValue(VALUE);
+ type = atts.getValue(TYPE);
}
}
- private static class RequireHandler extends DelegetingHandler {
+ static class RequireHandler extends DelegetingHandler {
+
+ static final String REQUIRE = "require";
+
+ static final String NAME = "name";
+
+ static final String OPTIONAL = "optional";
+
+ static final String MULTIPLE = "multiple";
+
+ static final String EXTEND = "extend";
+
+ static final String FILTER = "filter";
private Requirement requirement;
@@ -326,13 +326,13 @@ public class OBRXMLParser {
}
protected void handleAttributes(Attributes atts) throws SAXException {
- String name = atts.getValue(REQUIRE_NAME);
+ String name = atts.getValue(NAME);
if (name == null) {
skipResourceOnError(this, "Requirement with no name");
return;
}
- String filterText = atts.getValue(REQUIRE_FILTER);
+ String filterText = atts.getValue(FILTER);
filter = null;
if (filterText != null) {
try {
@@ -345,7 +345,7 @@ public class OBRXMLParser {
Boolean optional = null;
try {
- optional = parseBoolean(atts, REQUIRE_OPTIONAL);
+ optional = parseBoolean(atts, OPTIONAL);
} catch (ParseException e) {
skipResourceOnError(this,
"Requirement with unrecognised optional: " +
e.getMessage());
@@ -354,7 +354,7 @@ public class OBRXMLParser {
Boolean multiple = null;
try {
- multiple = parseBoolean(atts, REQUIRE_MULTIPLE);
+ multiple = parseBoolean(atts, MULTIPLE);
} catch (ParseException e) {
skipResourceOnError(this,
"Requirement with unrecognised multiple: " +
e.getMessage());
@@ -363,7 +363,7 @@ public class OBRXMLParser {
Boolean extend = null;
try {
- extend = parseBoolean(atts, REQUIRE_EXTEND);
+ extend = parseBoolean(atts, EXTEND);
} catch (ParseException e) {
skipResourceOnError(this, "Requirement with unrecognised
extend: " + e.getMessage());
return;
Modified:
ant/ivy/core/trunk/src/java/org/apache/ivy/osgi/obr/xml/OBRXMLWriter.java
URL:
http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/osgi/obr/xml/OBRXMLWriter.java?rev=1056025&r1=1056024&r2=1056025&view=diff
==============================================================================
--- ant/ivy/core/trunk/src/java/org/apache/ivy/osgi/obr/xml/OBRXMLWriter.java
(original)
+++ ant/ivy/core/trunk/src/java/org/apache/ivy/osgi/obr/xml/OBRXMLWriter.java
Thu Jan 6 19:34:42 2011
@@ -35,6 +35,11 @@ import org.apache.ivy.osgi.core.BundleIn
import org.apache.ivy.osgi.core.BundleRequirement;
import org.apache.ivy.osgi.core.ExportPackage;
import org.apache.ivy.osgi.core.ManifestParser;
+import org.apache.ivy.osgi.obr.xml.OBRXMLParser.CapabilityHandler;
+import org.apache.ivy.osgi.obr.xml.OBRXMLParser.CapabilityPropertyHandler;
+import org.apache.ivy.osgi.obr.xml.OBRXMLParser.RepositoryHandler;
+import org.apache.ivy.osgi.obr.xml.OBRXMLParser.RequireHandler;
+import org.apache.ivy.osgi.obr.xml.OBRXMLParser.ResourceHandler;
import org.apache.ivy.osgi.repo.ManifestAndLocation;
import org.apache.ivy.osgi.util.Version;
import org.apache.ivy.osgi.util.VersionRange;
@@ -62,7 +67,7 @@ public class OBRXMLWriter {
int level = quiet ? Message.MSG_DEBUG : Message.MSG_WARN;
handler.startDocument();
AttributesImpl atts = new AttributesImpl();
- handler.startElement("", OBRXMLParser.REPOSITORY,
OBRXMLParser.REPOSITORY, atts);
+ handler.startElement("", RepositoryHandler.REPOSITORY,
RepositoryHandler.REPOSITORY, atts);
int nbOk = 0;
int nbRejected = 0;
while (it.hasNext()) {
@@ -84,7 +89,7 @@ public class OBRXMLWriter {
}
saxBundleInfo(bundleInfo, handler);
}
- handler.endElement("", OBRXMLParser.REPOSITORY,
OBRXMLParser.REPOSITORY);
+ handler.endElement("", RepositoryHandler.REPOSITORY,
RepositoryHandler.REPOSITORY);
handler.endDocument();
Message.info(nbOk + " bundle" + (nbOk > 1 ? "s" : "") + " added, " +
nbRejected + " bundle"
+ (nbRejected > 1 ? "s" : "") + " rejected.");
@@ -94,24 +99,24 @@ public class OBRXMLWriter {
throws SAXException {
handler.startDocument();
AttributesImpl atts = new AttributesImpl();
- handler.startElement("", OBRXMLParser.REPOSITORY,
OBRXMLParser.REPOSITORY, atts);
+ handler.startElement("", RepositoryHandler.REPOSITORY,
RepositoryHandler.REPOSITORY, atts);
while (it.hasNext()) {
BundleInfo bundleInfo = (BundleInfo) it.next();
saxBundleInfo(bundleInfo, handler);
}
- handler.endElement("", OBRXMLParser.REPOSITORY,
OBRXMLParser.REPOSITORY);
+ handler.endElement("", RepositoryHandler.REPOSITORY,
RepositoryHandler.REPOSITORY);
handler.endDocument();
}
private static void saxBundleInfo(BundleInfo bundleInfo, ContentHandler
handler)
throws SAXException {
AttributesImpl atts = new AttributesImpl();
- addAttr(atts, OBRXMLParser.RESOURCE_SYMBOLIC_NAME,
bundleInfo.getSymbolicName());
- addAttr(atts, OBRXMLParser.RESOURCE_VERSION,
bundleInfo.getRawVersion());
+ addAttr(atts, ResourceHandler.SYMBOLIC_NAME,
bundleInfo.getSymbolicName());
+ addAttr(atts, ResourceHandler.VERSION, bundleInfo.getRawVersion());
if (bundleInfo.getUri() != null) {
- addAttr(atts, OBRXMLParser.RESOURCE_URI, bundleInfo.getUri());
+ addAttr(atts, ResourceHandler.URI, bundleInfo.getUri());
}
- handler.startElement("", OBRXMLParser.RESOURCE, OBRXMLParser.RESOURCE,
atts);
+ handler.startElement("", ResourceHandler.RESOURCE,
ResourceHandler.RESOURCE, atts);
Iterator itCapabilities = bundleInfo.getCapabilities().iterator();
while (itCapabilities.hasNext()) {
BundleCapability capability = (BundleCapability)
itCapabilities.next();
@@ -122,7 +127,7 @@ public class OBRXMLWriter {
BundleRequirement requirement = (BundleRequirement)
itRequirement.next();
saxRequirement(requirement, handler);
}
- handler.endElement("", OBRXMLParser.RESOURCE, OBRXMLParser.RESOURCE);
+ handler.endElement("", ResourceHandler.RESOURCE,
ResourceHandler.RESOURCE);
handler.characters("\n".toCharArray(), 0, 1);
}
@@ -130,8 +135,8 @@ public class OBRXMLWriter {
throws SAXException {
AttributesImpl atts = new AttributesImpl();
String type = capability.getType();
- addAttr(atts, OBRXMLParser.CAPABILITY_NAME, type);
- handler.startElement("", OBRXMLParser.CAPABILITY,
OBRXMLParser.CAPABILITY, atts);
+ addAttr(atts, CapabilityHandler.NAME, type);
+ handler.startElement("", CapabilityHandler.CAPABILITY,
CapabilityHandler.CAPABILITY, atts);
if (type.equals(BundleInfo.BUNDLE_TYPE)) {
// nothing to do, already handled with the resource tag
} else if (type.equals(BundleInfo.PACKAGE_TYPE)) {
@@ -162,7 +167,7 @@ public class OBRXMLWriter {
} else {
// oups
}
- handler.endElement("", OBRXMLParser.CAPABILITY,
OBRXMLParser.CAPABILITY);
+ handler.endElement("", CapabilityHandler.CAPABILITY,
CapabilityHandler.CAPABILITY);
handler.characters("\n".toCharArray(), 0, 1);
}
@@ -174,27 +179,28 @@ public class OBRXMLWriter {
private static void saxCapabilityProperty(String n, String t, String v,
ContentHandler handler)
throws SAXException {
AttributesImpl atts = new AttributesImpl();
- addAttr(atts, OBRXMLParser.CAPABILITY_PROPERTY_NAME, n);
+ addAttr(atts, CapabilityPropertyHandler.NAME, n);
if (t != null) {
- addAttr(atts, OBRXMLParser.CAPABILITY_PROPERTY_TYPE, t);
+ addAttr(atts, CapabilityPropertyHandler.TYPE, t);
}
- addAttr(atts, OBRXMLParser.CAPABILITY_PROPERTY_VALUE, v);
- handler.startElement("", OBRXMLParser.CAPABILITY_PROPERTY,
- OBRXMLParser.CAPABILITY_PROPERTY, atts);
- handler.endElement("", OBRXMLParser.CAPABILITY_PROPERTY,
OBRXMLParser.CAPABILITY_PROPERTY);
+ addAttr(atts, CapabilityPropertyHandler.VALUE, v);
+ handler.startElement("", CapabilityPropertyHandler.CAPABILITY_PROPERTY,
+ CapabilityPropertyHandler.CAPABILITY_PROPERTY, atts);
+ handler.endElement("", CapabilityPropertyHandler.CAPABILITY_PROPERTY,
+ CapabilityPropertyHandler.CAPABILITY_PROPERTY);
handler.characters("\n".toCharArray(), 0, 1);
}
private static void saxRequirement(BundleRequirement requirement,
ContentHandler handler)
throws SAXException {
AttributesImpl atts = new AttributesImpl();
- addAttr(atts, OBRXMLParser.REQUIRE_NAME, requirement.getType());
+ addAttr(atts, RequireHandler.NAME, requirement.getType());
if ("optional".equals(requirement.getResolution())) {
- addAttr(atts, OBRXMLParser.REQUIRE_OPTIONAL, OBRXMLParser.TRUE);
+ addAttr(atts, RequireHandler.OPTIONAL, OBRXMLParser.TRUE);
}
- addAttr(atts, OBRXMLParser.REQUIRE_FILTER, buildFilter(requirement));
- handler.startElement("", OBRXMLParser.REQUIRE, OBRXMLParser.REQUIRE,
atts);
- handler.endElement("", OBRXMLParser.REQUIRE, OBRXMLParser.REQUIRE);
+ addAttr(atts, RequireHandler.FILTER, buildFilter(requirement));
+ handler.startElement("", RequireHandler.REQUIRE,
RequireHandler.REQUIRE, atts);
+ handler.endElement("", RequireHandler.REQUIRE, RequireHandler.REQUIRE);
handler.characters("\n".toCharArray(), 0, 1);
}