[jboss-svn-commits] JBoss Common SVN: r3457 - in declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base: path and 1 other directory.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Mon Aug 17 06:37:38 EDT 2009
Author: ALRubinger
Date: 2009-08-17 06:37:38 -0400 (Mon, 17 Aug 2009)
New Revision: 3457
Added:
declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/path/
declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/path/BasePath.java
declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/path/PathUtil.java
declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/path/PrefixPath.java
declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/path/RelativePath.java
declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/path/ResourcePath.java
Log:
[TMPARCH-12] Put back the initial Path impl prototypes
Added: declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/path/BasePath.java
===================================================================
--- declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/path/BasePath.java (rev 0)
+++ declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/path/BasePath.java 2009-08-17 10:37:38 UTC (rev 3457)
@@ -0,0 +1,79 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * 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 org.jboss.declarchive.impl.base.path;
+
+import org.jboss.declarchive.api.Path;
+
+/**
+ * BasePath
+ *
+ * A {@link Path} which has no namespace and is relative to the
+ * root.
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @author <a href="mailto:aslak at conduct.no">Aslak Knutsen</a>
+ * @version $Revision: $
+ */
+public class BasePath extends PrefixPath
+{
+
+ //-------------------------------------------------------------------------------------||
+ // Class Members ----------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ private static final String PREFIX = null;
+
+ //-------------------------------------------------------------------------------------||
+ // Constructor ------------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Creates a new Path representing the
+ * root context
+ *
+ * @param context
+ */
+ public BasePath()
+ {
+ this(null);
+ }
+
+ /**
+ * Creates a new Path representing the specified
+ * context. Null or blank may be used to
+ * denote the root.
+ *
+ * @param context
+ */
+ public BasePath(final String context)
+ {
+ super(PathUtil.fixBasePath(context));
+ }
+
+ //-------------------------------------------------------------------------------------||
+ // Required Implementations -----------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * @see org.jboss.declarchive.impl.base.path.PrefixPath#getPrefix()
+ */
+ @Override
+ String getPrefix()
+ {
+ return PREFIX;
+ }
+}
Added: declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/path/PathUtil.java
===================================================================
--- declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/path/PathUtil.java (rev 0)
+++ declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/path/PathUtil.java 2009-08-17 10:37:38 UTC (rev 3457)
@@ -0,0 +1,84 @@
+/*
+ * JBoss, Home of Professional Open Source
+
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * 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 org.jboss.declarchive.impl.base.path;
+
+/**
+ * PathUtil
+ *
+ * @author <a href="mailto:aslak at conduct.no">Aslak Knutsen</a>
+ * @version $Revision: $
+ */
+public class PathUtil
+{
+
+ private PathUtil()
+ {
+ }
+
+ public static String fixRelativePath(String path)
+ {
+ if (path == null)
+ {
+ return path;
+ }
+ String removedPrefix = removePrefix(path);
+ String addedPostfix = addPostfix(removedPrefix);
+
+ return addedPostfix;
+ }
+
+ public static String fixBasePath(String path)
+ {
+ if (path == null)
+ {
+ return path;
+ }
+ String prefixedPath = addPrefix(path);
+ String prePostfixedPath = addPostfix(prefixedPath);
+
+ return prePostfixedPath;
+ }
+
+ private static String removePrefix(String path)
+ {
+ if (path.charAt(0) == '/')
+ {
+ return path.substring(1);
+ }
+ return path;
+ }
+
+ private static String addPostfix(String path)
+ {
+ if (path.charAt(path.length() - 1) != '/')
+ {
+ return path + '/';
+ }
+ return path;
+ }
+
+ private static String addPrefix(String path)
+ {
+ if (path.charAt(0) != '/')
+ {
+ return '/' + path;
+ }
+ return path;
+ }
+
+}
Added: declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/path/PrefixPath.java
===================================================================
--- declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/path/PrefixPath.java (rev 0)
+++ declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/path/PrefixPath.java 2009-08-17 10:37:38 UTC (rev 3457)
@@ -0,0 +1,161 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * 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 org.jboss.declarchive.impl.base.path;
+
+import org.jboss.declarchive.api.Path;
+import org.jboss.declarchive.impl.base.Validate;
+
+/**
+ * PrefixPath
+ *
+ * A Path which may be optionally prefixed with some common
+ * namespace
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+abstract class PrefixPath implements Path, Comparable<Path>
+{
+
+ //-------------------------------------------------------------------------------------||
+ // Class Members ----------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Empty String
+ */
+ private static final String EMPTY_STRING = "";
+
+ //-------------------------------------------------------------------------------------||
+ // Instance Members -------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * The context which this path represents
+ */
+ private final String context;
+
+ //-------------------------------------------------------------------------------------||
+ // Constructor ------------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Creates a new Path with the specified context
+ *
+ * @param prefix The prefix to prepend to every context returned
+ * in {@link PrefixPath#get()}. May be null or blank
+ * @param context The context which this path represents. Null or
+ * blank represents the root.
+ */
+ PrefixPath(final String context)
+ {
+ Validate.notNull(context, "Context must be specified");
+ this.context = context;
+ }
+
+ //-------------------------------------------------------------------------------------||
+ // Required Implementations -----------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * @see org.jboss.declarchive.api.Path#get()
+ */
+ @Override
+ public String get()
+ {
+ // Return the prefix plus the context
+ final String prefix = this.getPrefix();
+ final String prefixToUse = prefix == null ? EMPTY_STRING : prefix;
+ final String resolvedContext = prefixToUse + context;
+ return resolvedContext;
+ }
+
+ /**
+ * @see java.lang.Comparable#compareTo(java.lang.Object)
+ */
+ @Override
+ public int compareTo(final Path path)
+ {
+ if (path == null)
+ {
+ return 1;
+ }
+ else
+ {
+ // Compare the contexts
+ return this.get().compareTo(path.get());
+ }
+ }
+
+ //-------------------------------------------------------------------------------------||
+ // Contracts --------------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Obtains the prefix to prepend to all path contexts
+ */
+ abstract String getPrefix();
+
+ //-------------------------------------------------------------------------------------||
+ // Overridden Implementations ---------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * @see java.lang.Object#hashCode()
+ */
+ @Override
+ public int hashCode()
+ {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((context == null) ? 0 : context.hashCode());
+ return result;
+ }
+
+ /**
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ @Override
+ public boolean equals(Object obj)
+ {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ final PrefixPath other = (PrefixPath) obj;
+ if (context == null)
+ {
+ if (other.context != null)
+ return false;
+ }
+ else if (!context.equals(other.context))
+ return false;
+ return true;
+ }
+
+ /**
+ * @see java.lang.Object#toString()
+ */
+ @Override
+ public String toString()
+ {
+ return this.getClass().getSimpleName() + " [context=" + context + "]";
+ }
+
+}
Added: declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/path/RelativePath.java
===================================================================
--- declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/path/RelativePath.java (rev 0)
+++ declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/path/RelativePath.java 2009-08-17 10:37:38 UTC (rev 3457)
@@ -0,0 +1,54 @@
+/*
+ * JBoss, Home of Professional Open Source
+
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * 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 org.jboss.declarchive.impl.base.path;
+
+import org.jboss.declarchive.api.Path;
+
+/**
+ * RelativePath
+ *
+ * @author <a href="mailto:aslak at conduct.no">Aslak Knutsen</a>
+ * @version $Revision: $
+ */
+public class RelativePath extends PrefixPath
+{
+ private Path basePath;
+
+ public RelativePath(Path basePath, Path context)
+ {
+ this(basePath, context.get());
+ }
+
+ public RelativePath(Path basePath, String context)
+ {
+ this(basePath.get(), context);
+ }
+
+ public RelativePath(String basePath, String context)
+ {
+ super(PathUtil.fixRelativePath(context));
+ this.basePath = new BasePath(basePath);
+ }
+
+ @Override
+ String getPrefix()
+ {
+ return basePath.get();
+ }
+
+}
Added: declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/path/ResourcePath.java
===================================================================
--- declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/path/ResourcePath.java (rev 0)
+++ declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/path/ResourcePath.java 2009-08-17 10:37:38 UTC (rev 3457)
@@ -0,0 +1,37 @@
+/*
+ * JBoss, Home of Professional Open Source
+
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * 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 org.jboss.declarchive.impl.base.path;
+
+import org.jboss.declarchive.api.Path;
+
+public class ResourcePath extends PrefixPath
+{
+ private Path basePath;
+
+ public ResourcePath(Path basePath, String resourceName)
+ {
+ super(resourceName);
+ this.basePath = basePath;
+ }
+
+ @Override
+ String getPrefix()
+ {
+ return basePath.get();
+ }
+}
More information about the jboss-svn-commits
mailing list