[libbluray-devel] javax/tv/locator: improve compatibly. Log errors.

hpi1 git at videolan.org
Wed Apr 6 11:36:52 CEST 2016


libbluray | branch: master | hpi1 <hpi1 at anonymous.org> | Wed Apr  6 12:35:00 2016 +0300| [dffe9ddd5a19762c095a6a8fc268f11d2417c915] | committer: hpi1

javax/tv/locator: improve compatibly. Log errors.

> http://git.videolan.org/gitweb.cgi/libbluray.git/?a=commit;h=dffe9ddd5a19762c095a6a8fc268f11d2417c915
---

 .../bdj/java/javax/tv/locator/LocatorFactory.java  |    1 -
 .../java/javax/tv/locator/LocatorFactoryImpl.java  |   23 +++++++++++++++-----
 .../bdj/java/javax/tv/locator/LocatorImpl.java     |   20 +++++++----------
 3 files changed, 26 insertions(+), 18 deletions(-)

diff --git a/src/libbluray/bdj/java/javax/tv/locator/LocatorFactory.java b/src/libbluray/bdj/java/javax/tv/locator/LocatorFactory.java
index 375c148..a17bdc8 100644
--- a/src/libbluray/bdj/java/javax/tv/locator/LocatorFactory.java
+++ b/src/libbluray/bdj/java/javax/tv/locator/LocatorFactory.java
@@ -21,7 +21,6 @@ package javax.tv.locator;
 
 public abstract class LocatorFactory extends Object {
     protected LocatorFactory() {
-
     }
 
     public static LocatorFactory getInstance() {
diff --git a/src/libbluray/bdj/java/javax/tv/locator/LocatorFactoryImpl.java b/src/libbluray/bdj/java/javax/tv/locator/LocatorFactoryImpl.java
index 6ee4b75..6c4e1a1 100644
--- a/src/libbluray/bdj/java/javax/tv/locator/LocatorFactoryImpl.java
+++ b/src/libbluray/bdj/java/javax/tv/locator/LocatorFactoryImpl.java
@@ -21,27 +21,40 @@
 package javax.tv.locator;
 
 import org.bluray.net.BDLocator;
+import org.videolan.Logger;
 
 public class LocatorFactoryImpl extends LocatorFactory {
     public Locator createLocator(String url) throws MalformedLocatorException {
+        if (url == null) {
+            logger.error("null locator");
+            throw new NullPointerException("Source Locator is null");
+        }
         // check if it is a bluray locator
         if (url.startsWith("bd:/")) {
             try {
                 return new BDLocator(url);
             } catch (org.davic.net.InvalidLocatorException ex) {
+                logger.error("invalid locator: " + url);
                 throw new MalformedLocatorException(ex.getMessage());
             }
         } else {
             // just return a generic locator
+            logger.error("unknown locator type: " + url);
             return new LocatorImpl(url);
         }
     }
 
-    public Locator[] transformLocator(Locator source)
-            throws InvalidLocatorException
-    {
-        org.videolan.Logger.unimplemented(LocatorFactoryImpl.class.getName(), "transformLocator");
-        throw new Error("Not implemented.");
+    public Locator[] transformLocator(Locator source) throws InvalidLocatorException {
+        if (source == null) {
+            logger.error("null locator");
+            throw new NullPointerException("Source Locator is null");
+        }
+        if (source instanceof BDLocator){
+            return new Locator[] { source };
+        }
+        logger.error("unsupported locator: " + source);
+        throw new InvalidLocatorException(source, "Source locator is invalid.");
     }
 
+    private static final Logger logger = Logger.getLogger(LocatorFactoryImpl.class.getName());
 }
diff --git a/src/libbluray/bdj/java/javax/tv/locator/LocatorImpl.java b/src/libbluray/bdj/java/javax/tv/locator/LocatorImpl.java
index a87269a..4cdbdc3 100644
--- a/src/libbluray/bdj/java/javax/tv/locator/LocatorImpl.java
+++ b/src/libbluray/bdj/java/javax/tv/locator/LocatorImpl.java
@@ -44,19 +44,15 @@ public class LocatorImpl implements Locator {
     }
 
     public boolean equals(Object obj) {
-        if (this == obj)
-            return true;
-        if (obj == null)
+        if (!(obj instanceof Locator))
             return false;
-        if (getClass() != obj.getClass())
-            return false;
-        LocatorImpl other = (LocatorImpl) obj;
-        if (url == null) {
-            if (other.url != null)
-                return false;
-        } else if (!url.equals(other.url))
-            return false;
-        return true;
+
+        Locator other = (Locator) obj;
+        String extForm = toExternalForm();
+        if (extForm == null) {
+            return other.toExternalForm() == null;
+        }
+        return extForm.equals(other.toExternalForm());
     }
 
     private String url;



More information about the libbluray-devel mailing list