Skip to content

Commit

Permalink
replace NotFoundType
Browse files Browse the repository at this point in the history
  • Loading branch information
yjfnypeu committed May 7, 2017
1 parent 5794a9f commit bbf8220
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 22 deletions.
10 changes: 5 additions & 5 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ android {

def AAVersion = '4.3.0'
def PARCELER_VERSION="0.9.1"
def ROUTER_VERSION="72b537950c"
def ROUTER_VERSION="5794a9f4c8"
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
Expand All @@ -39,9 +39,9 @@ dependencies {
annotationProcessor "org.lzh.compiler.parceler:parceler-compiler:$PARCELER_VERSION"
compile "org.lzh.compiler.parceler:parceler-api:$PARCELER_VERSION"

// compile "com.github.yjfnypeu.Router:router-api:$ROUTER_VERSION"
// annotationProcessor "com.github.yjfnypeu.Router:router-compiler:$ROUTER_VERSION"
compile "com.github.yjfnypeu.Router:router-api:$ROUTER_VERSION"
annotationProcessor "com.github.yjfnypeu.Router:router-compiler:$ROUTER_VERSION"

compile project(':routerlib')
annotationProcessor project(':compiler')
// compile project(':routerlib')
// annotationProcessor project(':compiler')
}
24 changes: 20 additions & 4 deletions routerlib/src/main/java/com/lzh/nonview/router/Router.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* Copyright (C) HaoGe <a href="https://github.com/yjfnypeu"/>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.lzh.nonview.router;

import android.content.Context;
Expand Down Expand Up @@ -118,7 +134,7 @@ public IRoute getRoute () {
return BrowserRoute.getInstance().setUri(uri);
} else {
getCallback().notFound(uri,new NotFoundException(String.format("find Route by %s failed:",uri),
NotFoundException.NotFoundType.SCHEME,uri.toString()));
NotFoundException.TYPE_SCHEMA,uri.toString()));
return IRoute.EMPTY;
}
}
Expand All @@ -136,7 +152,7 @@ public IBaseRoute getBaseRoute() {
return (IBaseRoute) route;
}
getCallback().notFound(uri, new NotFoundException(String.format("find BaseRoute by %s failed:",uri),
NotFoundException.NotFoundType.SCHEME, uri.toString()));
NotFoundException.TYPE_SCHEMA, uri.toString()));
return IBaseRoute.EMPTY;
}

Expand All @@ -152,7 +168,7 @@ public IActivityRoute getActivityRoute() {
// return an empty route to avoid NullPointException
getCallback().notFound(uri,
new NotFoundException(String.format("find Activity Route by %s failed:",uri),
NotFoundException.NotFoundType.SCHEME,uri.toString()));
NotFoundException.TYPE_SCHEMA,uri.toString()));
return IActivityRoute.EMPTY;
}

Expand All @@ -168,7 +184,7 @@ public IActionRoute getActionRoute() {
// return a empty route to avoid NullPointException
getCallback().notFound(uri,
new NotFoundException(String.format("find Action Route by %s failed:",uri),
NotFoundException.NotFoundType.SCHEME,uri.toString()));
NotFoundException.TYPE_SCHEMA,uri.toString()));
return IActionRoute.EMPTY;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,31 +1,66 @@
/*
* Copyright (C) HaoGe <a href="https://github.com/yjfnypeu"/>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.lzh.nonview.router.exception;

/**
* The custom exception represents not found
* @author haoge
* @see NotFoundType
*/
public class NotFoundException extends RuntimeException {

private final NotFoundType type;
/**
* This type represents not matching to the corresponding uri routing rules
*/
public static final int TYPE_SCHEMA = 0;
/**
* This type represents the uri matching to the routing target does not exist
*/
public static final int TYPE_CLZ = 1;

private final int type;
private final String notFoundName;

public NotFoundException(String detailMessage, NotFoundType type,String notFoundName) {
/**
* @param detailMessage detail error message
* @param type one of {@link NotFoundException#TYPE_SCHEMA} and {@link NotFoundException#TYPE_SCHEMA}
* @param notFoundName The routing target name matched with uri.
* @see NotFoundException#TYPE_SCHEMA
* @see NotFoundException#TYPE_CLZ
*/
public NotFoundException(String detailMessage, int type,String notFoundName) {
super(detailMessage);
this.type = type;
this.notFoundName = notFoundName;
}

@SuppressWarnings("unused")
public NotFoundType getType() {
/**
* @return the type of not found. it could be one of the {@link NotFoundException#TYPE_SCHEMA} and {@link NotFoundException#TYPE_SCHEMA}
* @see NotFoundException#TYPE_SCHEMA
* @see NotFoundException#TYPE_CLZ
*/
public int getType() {
return type;
}

/**
* @return the uri matching routing target class name.
*/
public String getNotFoundName() {
return notFoundName;
}

public enum NotFoundType {
CLZ,
SCHEME,
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ protected RouteRule obtainRouteMap() {
protected void realOpen(Context context) throws Throwable {
String clzName = routeRule.getClzName();
if (!Utils.isClassSupport(clzName)) {
throw new NotFoundException(String.format("target activity is not found : %s",clzName), NotFoundException.NotFoundType.CLZ,clzName);
throw new NotFoundException(String.format("target activity is not found : %s",clzName), NotFoundException.TYPE_CLZ,clzName);
}
Intent intent = createIntent(context);
if (context instanceof Activity) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import android.net.Uri;

import com.lzh.nonview.router.exception.NotFoundException;
import com.lzh.nonview.router.exception.NotFoundException.NotFoundType;
import com.lzh.nonview.router.module.ActionRouteRule;
import com.lzh.nonview.router.module.ActivityRouteRule;
import com.lzh.nonview.router.module.RouteRule;
Expand All @@ -16,8 +15,8 @@ public interface RouteCallback {

/**
* There are two types of not found exception:<br>
* <i><b>{@link NotFoundType#SCHEME}: </b>This uri can't match the corresponding routing</i><br>
* <i><b>{@link NotFoundType#CLZ}: </b>The special routing event that matched with uri does not exist.</i>
* <i><b>{@link NotFoundException#TYPE_SCHEMA}: </b>This uri can't match the corresponding routing</i><br>
* <i><b>{@link NotFoundException#TYPE_CLZ}: </b>The special routing event that matched with uri does not exist.</i>
* @param uri uri the uri to open
* @param e {@link NotFoundException}
*/
Expand Down

0 comments on commit bbf8220

Please sign in to comment.