Author: jukka Date: Thu Jul 19 10:04:40 2012 New Revision: 1363277 URL: http://svn.apache.org/viewvc?rev=1363277&view=rev Log: OAK-193: TODO class for partially implemented features First draft of the proposed TODO class. Added: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/util/TODO.java (with props) Added: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/util/TODO.java URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/util/TODO.java?rev=1363277&view=auto ============================================================================== --- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/util/TODO.java (added) +++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/util/TODO.java Thu Jul 19 10:04:40 2012 @@ -0,0 +1,71 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.jackrabbit.oak.util; + +import javax.jcr.UnsupportedRepositoryOperationException; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Helper class for identifying partially implemented features and + * controlling their runtime behavior. + * + * @see OAK-193 + */ +public class TODO { + + private static final String mode = System.getProperty("todo", "strict"); + + private static final boolean strict = "strict".equals(mode); + + private static final boolean log = "log".equals(mode); + + public static TODO unimplemented() { + return new TODO("unimplemented"); + } + + private final UnsupportedOperationException exception; + + private final Logger logger; + + private final String message; + + private TODO(String message) { + this.exception = new UnsupportedOperationException(message); + StackTraceElement[] trace = exception.getStackTrace(); + if (trace != null && trace.length > 2) { + String className = trace[2].getClassName(); + String methodName = trace[2].getMethodName(); + this.logger = LoggerFactory.getLogger(className); + this.message = + "TODO: " + className + "." + methodName + "() - " + message; + } else { + this.logger = LoggerFactory.getLogger(TODO.class); + this.message = "TODO: " + message; + } + } + + public void doNothing() throws UnsupportedRepositoryOperationException { + if (strict) { + throw new UnsupportedRepositoryOperationException( + message, exception); + } else if (log) { + logger.warn(message, exception); + } + } +} Propchange: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/util/TODO.java ------------------------------------------------------------------------------ svn:eol-style = native