Reformat according to Felix code style.


git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@912080 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/bundlerepository/src/main/java/org/apache/felix/bundlerepository/RepositoryImpl.java b/bundlerepository/src/main/java/org/apache/felix/bundlerepository/RepositoryImpl.java
index 43706e5..825bbac 100644
--- a/bundlerepository/src/main/java/org/apache/felix/bundlerepository/RepositoryImpl.java
+++ b/bundlerepository/src/main/java/org/apache/felix/bundlerepository/RepositoryImpl.java
@@ -109,8 +109,7 @@
         // Add to resource array.
         if (m_resources == null)
         {
-            m_resources = new Resource[]
-                { resource };
+            m_resources = new Resource[] { resource };
         }
         else
         {
@@ -133,8 +132,7 @@
         // Add to resource array.
         if (m_referrals == null)
         {
-            m_referrals = new Referral[]
-                { referral };
+            m_referrals = new Referral[] { referral };
         }
         else
         {
@@ -175,7 +173,7 @@
     /**
      * Default setter method when setting parsed data from the XML file,
      * which currently ignores everything.
-    **/
+     **/
     protected Object put(Object key, Object value)
     {
         // Ignore everything for now.
@@ -254,7 +252,9 @@
             try
             {
                 if (is != null)
+                {
                     is.close();
+                }
             }
             catch (IOException ex)
             {
@@ -269,7 +269,8 @@
         try
         {
             String className = (String) RepositoryAdminImpl.m_context.getProperty(OBR_PARSER_CLASS);
-            if (className == null || className.length() == 0) {
+            if (className == null || className.length() == 0)
+            {
                 className = OBR_PARSER_CLASS_DEFAULT;
             }
             parser = (RepositoryParser) Class.forName(className).newInstance();
@@ -285,10 +286,9 @@
         parser.parse(this, is);
     }
 
-    public interface RepositoryParser {
-
+    public interface RepositoryParser
+    {
         void parse(RepositoryImpl repository, InputStream is) throws Exception;
-
     }
 
     public static class KXml2Parser implements RepositoryParser
@@ -306,12 +306,12 @@
             };
 
             // Get default setter method for Repository.
-            Method repoSetter = RepositoryImpl.class.getDeclaredMethod("put", new Class[]
-                { Object.class, Object.class });
+            Method repoSetter = RepositoryImpl.class.getDeclaredMethod(
+                "put", new Class[] { Object.class, Object.class });
 
             // Get default setter method for Resource.
-            Method resSetter = ResourceImpl.class.getDeclaredMethod("put", new Class[]
-                { Object.class, Object.class });
+            Method resSetter = ResourceImpl.class.getDeclaredMethod(
+                "put", new Class[] { Object.class, Object.class });
 
             // Map XML tags to types.
             handler.addType("repository", factory, Repository.class, repoSetter);
@@ -329,5 +329,4 @@
             parser.parseXML(handler);
         }
     }
-
 }
\ No newline at end of file
diff --git a/bundlerepository/src/main/java/org/apache/felix/bundlerepository/StaxParser.java b/bundlerepository/src/main/java/org/apache/felix/bundlerepository/StaxParser.java
index 5331ab8..29a93e2 100644
--- a/bundlerepository/src/main/java/org/apache/felix/bundlerepository/StaxParser.java
+++ b/bundlerepository/src/main/java/org/apache/felix/bundlerepository/StaxParser.java
@@ -29,7 +29,6 @@
  */
 public class StaxParser implements RepositoryImpl.RepositoryParser
 {
-
     private static final String REPOSITORY = "repository";
     private static final String NAME = "name";
     private static final String LASTMODIFIED = "lastmodified";
@@ -50,13 +49,14 @@
     private static final String MULTIPLE = "multiple";
     private static final String OPTIONAL = "optional";
 
-
     static XMLInputFactory factory;
 
     public StaxParser()
     {
-        synchronized (StaxParser.class) {
-            if (factory == null) {
+        synchronized (StaxParser.class)
+        {
+            if (factory == null)
+            {
                 factory = XMLInputFactory.newInstance();
                 setProperty(factory, XMLInputFactory.IS_NAMESPACE_AWARE, false);
                 setProperty(factory, XMLInputFactory.IS_VALIDATING, false);
@@ -65,11 +65,15 @@
         }
     }
 
-    protected static boolean setProperty(XMLInputFactory factory, String name, boolean value) {
-        try {
+    protected static boolean setProperty(XMLInputFactory factory, String name, boolean value)
+    {
+        try
+        {
             factory.setProperty(name, Boolean.valueOf(value));
             return true;
-        } catch (Throwable t) {
+        }
+        catch (Throwable t)
+        {
         }
         return false;
     }
@@ -77,29 +81,41 @@
     public void parse(RepositoryImpl repository, InputStream is) throws Exception
     {
         XMLStreamReader reader = factory.createXMLStreamReader(is);
-        try {
+        try
+        {
             int event = reader.nextTag();
-            if (event != XMLStreamConstants.START_ELEMENT || !REPOSITORY.equals(reader.getLocalName())) {
+            if (event != XMLStreamConstants.START_ELEMENT || !REPOSITORY.equals(reader.getLocalName()))
+            {
                 throw new Exception("Expected element 'repository' at the root of the document");
             }
-            for (int i = 0, nb = reader.getAttributeCount(); i < nb; i++) {
+            for (int i = 0, nb = reader.getAttributeCount(); i < nb; i++)
+            {
                 String name = reader.getAttributeLocalName(i);
                 String value = reader.getAttributeValue(i);
-                if (NAME.equals(name)) {
+                if (NAME.equals(name))
+                {
                     repository.setName(value);
-                } else if (LASTMODIFIED.equals(name)) {
+                }
+                else if (LASTMODIFIED.equals(name))
+                {
                     repository.setLastmodified(value);
                 }
             }
-            while ((event = reader.nextTag()) == XMLStreamConstants.START_ELEMENT) {
+            while ((event = reader.nextTag()) == XMLStreamConstants.START_ELEMENT)
+            {
                 String element = reader.getLocalName();
-                if (REFERRAL.equals(element)) {
+                if (REFERRAL.equals(element))
+                {
                     Referral referral = parseReferral(reader);
                     repository.addReferral(referral);
-                } else if (RESOURCE.equals(element)) {
+                }
+                else if (RESOURCE.equals(element))
+                {
                     ResourceImpl resource = parseResource(reader);
                     repository.addResource(resource);
-                } else {
+                }
+                else
+                {
                     ignoreTag(reader);
                 }
             }
@@ -112,20 +128,27 @@
         }
     }
 
-    private void sanityCheckEndElement(XMLStreamReader reader, int event, String element) {
-        if (event != XMLStreamConstants.END_ELEMENT || !element.equals(reader.getLocalName())) {
+    private void sanityCheckEndElement(XMLStreamReader reader, int event, String element)
+    {
+        if (event != XMLStreamConstants.END_ELEMENT || !element.equals(reader.getLocalName()))
+        {
             throw new IllegalStateException("Unexpected state while finishing element " + element);
         }
     }
 
-    private Referral parseReferral(XMLStreamReader reader) throws Exception {
+    private Referral parseReferral(XMLStreamReader reader) throws Exception
+    {
         Referral referral = new Referral();
-        for (int i = 0, nb = reader.getAttributeCount(); i < nb; i++) {
+        for (int i = 0, nb = reader.getAttributeCount(); i < nb; i++)
+        {
             String name = reader.getAttributeLocalName(i);
             String value = reader.getAttributeValue(i);
-            if (DEPTH.equals(name)) {
+            if (DEPTH.equals(name))
+            {
                 referral.setDepth(value);
-            } else if (URL.equals(name)) {
+            }
+            else if (URL.equals(name))
+            {
                 referral.setUrl(value);
             }
         }
@@ -133,61 +156,83 @@
         return referral;
     }
 
-    private ResourceImpl parseResource(XMLStreamReader reader) throws Exception {
+    private ResourceImpl parseResource(XMLStreamReader reader) throws Exception
+    {
         ResourceImpl resource = new ResourceImpl();
-        for (int i = 0, nb = reader.getAttributeCount(); i < nb; i++) {
+        for (int i = 0, nb = reader.getAttributeCount(); i < nb; i++)
+        {
             resource.put(reader.getAttributeLocalName(i), reader.getAttributeValue(i));
         }
         int event;
-        while ((event = reader.nextTag()) == XMLStreamConstants.START_ELEMENT) {
+        while ((event = reader.nextTag()) == XMLStreamConstants.START_ELEMENT)
+        {
             String element = reader.getLocalName();
-            if (CATEGORY.equals(element)) {
+            if (CATEGORY.equals(element))
+            {
                 CategoryImpl category = parseCategory(reader);
                 resource.addCategory(category);
-            } else if (CAPABILITY.equals(element)) {
+            }
+            else if (CAPABILITY.equals(element))
+            {
                 CapabilityImpl capability = parseCapability(reader);
                 resource.addCapability(capability);
-            } else if (REQUIRE.equals(element)) {
+            }
+            else if (REQUIRE.equals(element))
+            {
                 RequirementImpl requirement = parseRequire(reader);
                 resource.addRequire(requirement);
-            } else {
+            }
+            else
+            {
                 ignoreTag(reader);
             }
         }
         // Sanity check
-        if (event != XMLStreamConstants.END_ELEMENT || !RESOURCE.equals(reader.getLocalName())) {
+        if (event != XMLStreamConstants.END_ELEMENT || !RESOURCE.equals(reader.getLocalName()))
+        {
             throw new Exception("Unexpected state");
         }
         return resource;
     }
 
-    private CategoryImpl parseCategory(XMLStreamReader reader) throws XMLStreamException {
+    private CategoryImpl parseCategory(XMLStreamReader reader) throws XMLStreamException
+    {
         CategoryImpl category = new CategoryImpl();
-        for (int i = 0, nb = reader.getAttributeCount(); i < nb; i++) {
-            if (ID.equals(reader.getAttributeLocalName(i))) {
-               category.setId(reader.getAttributeValue(i));
-            };
+        for (int i = 0, nb = reader.getAttributeCount(); i < nb; i++)
+        {
+            if (ID.equals(reader.getAttributeLocalName(i)))
+            {
+                category.setId(reader.getAttributeValue(i));
+            }
+            ;
         }
         sanityCheckEndElement(reader, reader.nextTag(), CATEGORY);
         return category;
     }
 
-    private CapabilityImpl parseCapability(XMLStreamReader reader) throws Exception {
+    private CapabilityImpl parseCapability(XMLStreamReader reader) throws Exception
+    {
         CapabilityImpl capability = new CapabilityImpl();
-        for (int i = 0, nb = reader.getAttributeCount(); i < nb; i++) {
+        for (int i = 0, nb = reader.getAttributeCount(); i < nb; i++)
+        {
             String name = reader.getAttributeLocalName(i);
             String value = reader.getAttributeValue(i);
-            if (NAME.equals(name)) {
+            if (NAME.equals(name))
+            {
                 capability.setName(value);
             }
         }
         int event;
-        while ((event = reader.nextTag()) == XMLStreamConstants.START_ELEMENT) {
+        while ((event = reader.nextTag()) == XMLStreamConstants.START_ELEMENT)
+        {
             String element = reader.getLocalName();
-            if (P.equals(element)) {
+            if (P.equals(element))
+            {
                 PropertyImpl prop = parseProperty(reader);
                 capability.addP(prop);
-            } else {
+            }
+            else
+            {
                 ignoreTag(reader);
             }
         }
@@ -196,16 +241,23 @@
         return capability;
     }
 
-    private PropertyImpl parseProperty(XMLStreamReader reader) throws Exception {
+    private PropertyImpl parseProperty(XMLStreamReader reader) throws Exception
+    {
         String n = null, t = null, v = null;
-        for (int i = 0, nb = reader.getAttributeCount(); i < nb; i++) {
+        for (int i = 0, nb = reader.getAttributeCount(); i < nb; i++)
+        {
             String name = reader.getAttributeLocalName(i);
             String value = reader.getAttributeValue(i);
-            if (N.equals(name)) {
+            if (N.equals(name))
+            {
                 n = value;
-            } else if (T.equals(name)) {
+            }
+            else if (T.equals(name))
+            {
                 t = value;
-            } else if (V.equals(name)) {
+            }
+            else if (V.equals(name))
+            {
                 v = value;
             }
         }
@@ -215,38 +267,53 @@
         return prop;
     }
 
-    private RequirementImpl parseRequire(XMLStreamReader reader) throws Exception {
+    private RequirementImpl parseRequire(XMLStreamReader reader) throws Exception
+    {
         RequirementImpl requirement = new RequirementImpl();
-        for (int i = 0, nb = reader.getAttributeCount(); i < nb; i++) {
+        for (int i = 0, nb = reader.getAttributeCount(); i < nb; i++)
+        {
             String name = reader.getAttributeLocalName(i);
             String value = reader.getAttributeValue(i);
-            if (NAME.equals(name)) {
+            if (NAME.equals(name))
+            {
                 requirement.setName(value);
-            } else if (FILTER.equals(name)) {
+            }
+            else if (FILTER.equals(name))
+            {
                 requirement.setFilter(value);
-            } else if (EXTEND.equals(name)) {
+            }
+            else if (EXTEND.equals(name))
+            {
                 requirement.setExtend(value);
-            } else if (MULTIPLE.equals(name)) {
+            }
+            else if (MULTIPLE.equals(name))
+            {
                 requirement.setMultiple(value);
-            } else if (OPTIONAL.equals(name)) {
+            }
+            else if (OPTIONAL.equals(name))
+            {
                 requirement.setOptional(value);
             }
         }
         int event;
         StringBuffer sb = null;
-        while ((event = reader.next()) != XMLStreamConstants.END_ELEMENT) {
-            switch (event) {
+        while ((event = reader.next()) != XMLStreamConstants.END_ELEMENT)
+        {
+            switch (event)
+            {
                 case XMLStreamConstants.START_ELEMENT:
                     throw new Exception("Unexpected element inside <require/> element");
                 case XMLStreamConstants.CHARACTERS:
-                    if (sb == null) {
+                    if (sb == null)
+                    {
                         sb = new StringBuffer();
                     }
                     sb.append(reader.getText());
                     break;
             }
         }
-        if (sb != null) {
+        if (sb != null)
+        {
             requirement.addText(sb.toString());
         }
         // Sanity check
@@ -254,17 +321,21 @@
         return requirement;
     }
 
-    private void ignoreTag(XMLStreamReader reader) throws XMLStreamException {
+    private void ignoreTag(XMLStreamReader reader) throws XMLStreamException
+    {
         int level = 1;
         int event = 0;
-        while (level > 0) {
+        while (level > 0)
+        {
             event = reader.next();
-            if (event == XMLStreamConstants.START_ELEMENT) {
+            if (event == XMLStreamConstants.START_ELEMENT)
+            {
                 level++;
-            } else if (event == XMLStreamConstants.END_ELEMENT) {
+            }
+            else if (event == XMLStreamConstants.END_ELEMENT)
+            {
                 level--;
             }
         }
     }
-
-}
+}
\ No newline at end of file
diff --git a/bundlerepository/src/test/java/org/apache/felix/bundlerepository/StaxParserTest.java b/bundlerepository/src/test/java/org/apache/felix/bundlerepository/StaxParserTest.java
index 9545727..b78e889 100644
--- a/bundlerepository/src/test/java/org/apache/felix/bundlerepository/StaxParserTest.java
+++ b/bundlerepository/src/test/java/org/apache/felix/bundlerepository/StaxParserTest.java
@@ -18,12 +18,9 @@
  */
 package org.apache.felix.bundlerepository;
 
-import java.io.File;
 import java.net.URL;
 
 import junit.framework.TestCase;
-import org.junit.Ignore;
-import org.junit.Test;
 import org.osgi.service.obr.Repository;
 import org.osgi.service.obr.Resolver;
 import org.osgi.service.obr.Resource;
@@ -32,7 +29,6 @@
 {
     public void testStaxParser() throws Exception
     {
-
         URL url = getClass().getResource("/repo_for_resolvertest.xml");
         RepositoryAdminImpl repoAdmin = createRepositoryAdmin(StaxParser.class);
         RepositoryImpl repo = (RepositoryImpl) repoAdmin.addRepository(url);
@@ -42,7 +38,8 @@
         Resource r = null;
         //MockContext doesn't support filtering!
         Resource[] discoverResources = repoAdmin.discoverResources("");
-        for (int i = 0; i < discoverResources.length; i++) {
+        for (int i = 0; i < discoverResources.length; i++)
+        {
             Resource resource = discoverResources[i];
             if (resource.getSymbolicName().contains("org.apache.felix.test"))
             {
@@ -53,10 +50,10 @@
 
         resolver.add(r);
         assertTrue(resolver.resolve());
-
     }
 
-    public void testPerfs() throws Exception {
+    public void testPerfs() throws Exception
+    {
 //        for (int i = 0; i < 10; i++) {
 //            testPerfs(new File(System.getProperty("user.home"), ".m2/repository/repository.xml").toURI().toURL(), 0, 100);
 //        }
@@ -68,12 +65,14 @@
 
         StaxParser.factory = null;
         System.setProperty("javax.xml.stream.XMLInputFactory", "com.ctc.wstx.stax.WstxInputFactory");
-        for (int i = 0; i < nbWarm; i++) {
+        for (int i = 0; i < nbWarm; i++)
+        {
             RepositoryAdminImpl repoAdmin = createRepositoryAdmin(StaxParser.class);
             RepositoryImpl repo = (RepositoryImpl) repoAdmin.addRepository(url);
         }
         t0 = System.currentTimeMillis();
-        for (int i = 0; i < nbTest; i++) {
+        for (int i = 0; i < nbTest; i++)
+        {
             RepositoryAdminImpl repoAdmin = createRepositoryAdmin(StaxParser.class);
             RepositoryImpl repo = (RepositoryImpl) repoAdmin.addRepository(url);
         }
@@ -83,46 +82,47 @@
 
         StaxParser.factory = null;
         System.setProperty("javax.xml.stream.XMLInputFactory", "com.sun.xml.internal.stream.XMLInputFactoryImpl");
-        for (int i = 0; i < nbWarm; i++) {
+        for (int i = 0; i < nbWarm; i++)
+        {
             RepositoryAdminImpl repoAdmin = createRepositoryAdmin(StaxParser.class);
             RepositoryImpl repo = (RepositoryImpl) repoAdmin.addRepository(url);
         }
         t0 = System.currentTimeMillis();
-        for (int i = 0; i < nbTest; i++) {
+        for (int i = 0; i < nbTest; i++)
+        {
             RepositoryAdminImpl repoAdmin = createRepositoryAdmin(StaxParser.class);
             RepositoryImpl repo = (RepositoryImpl) repoAdmin.addRepository(url);
         }
         t1 = System.currentTimeMillis();
         System.err.println("DefStax: " + (t1 - t0) + " ms");
 
-        for (int i = 0; i < nbWarm; i++) {
+        for (int i = 0; i < nbWarm; i++)
+        {
             RepositoryAdminImpl repoAdmin = createRepositoryAdmin(RepositoryImpl.KXml2Parser.class);
             RepositoryImpl repo = (RepositoryImpl) repoAdmin.addRepository(url);
         }
         t0 = System.currentTimeMillis();
-        for (int i = 0; i < nbTest; i++) {
+        for (int i = 0; i < nbTest; i++)
+        {
             RepositoryAdminImpl repoAdmin = createRepositoryAdmin(RepositoryImpl.KXml2Parser.class);
             RepositoryImpl repo = (RepositoryImpl) repoAdmin.addRepository(url);
         }
         t1 = System.currentTimeMillis();
         System.err.println("KXmlParser: " + (t1 - t0) + " ms");
-
-
     }
 
-    public static void main(String[] args) throws Exception {
-
+    public static void main(String[] args) throws Exception
+    {
         new StaxParserTest().testStaxParser();
-
     }
 
     private RepositoryAdminImpl createRepositoryAdmin(Class repositoryParser)
     {
         final MockBundleContext bundleContext = new MockBundleContext();
         bundleContext.setProperty(RepositoryAdminImpl.REPOSITORY_URL_PROP,
-                                  getClass().getResource("/referral1_repository.xml").toExternalForm());
+            getClass().getResource("/referral1_repository.xml").toExternalForm());
         bundleContext.setProperty(RepositoryImpl.OBR_PARSER_CLASS,
-                                  repositoryParser.getName());
+            repositoryParser.getName());
         RepositoryAdminImpl repoAdmin = new RepositoryAdminImpl(bundleContext, new Logger(bundleContext));
 
         // force initialization && remove all initial repositories
@@ -134,5 +134,4 @@
 
         return repoAdmin;
     }
-
 }
\ No newline at end of file