krysalis-update/src/java/org/krysalis/depot/update/impl ReferenceManager.java,NONE,1.1 package.html,NONE,1.1 RepositorySetWrapper.java,NONE,1.1 RepositoryWrapper.java,NONE,1.1 ArtifactUpdaterContext.java,NONE,1.1
Nick Chalko <[email protected]> Wed, 08 Dec 2004 09:06:39 +0000
| Newsgroups | gmane.comp.krysalis.cvs |
|---|---|
| Message-ID | <[email protected]> |
Update of /cvsroot/krysalis/krysalis-update/src/java/org/krysalis/depot/update/impl
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24726/src/java/org/krysalis/depot/update/impl
Added Files:
ReferenceManager.java package.html RepositorySetWrapper.java
RepositoryWrapper.java ArtifactUpdaterContext.java
Log Message:
Copied from the apache incubator.
--- NEW FILE: RepositorySetWrapper.java ---
/*
* Copyright 2004 The Apache Software Foundation
*
* 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.krysalis.depot.update.impl;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.krysalis.depot.common.log.Logger;
import org.krysalis.depot.common.util.debug.DebugUtils;
import org.krysalis.depot.common.util.debug.Dumpable;
import org.krysalis.depot.update.Repository;
import org.krysalis.depot.update.repository.RepositorySet;
/**
* @author anou_mana
*/
public class RepositorySetWrapper implements Dumpable {
private ArtifactUpdaterContext m_context = null;
private RepositorySet m_repositorySet = null;
private List m_repositoryWrappers = null;
public RepositorySetWrapper(
RepositorySet repositorySet,
ArtifactUpdaterContext context) {
m_context = context;
m_repositorySet = repositorySet;
constructWrappers();
}
public RepositorySetWrapper(
Repository repository,
ArtifactUpdaterContext context) {
m_context = context;
m_repositorySet = new RepositorySet(repository);
constructWrappers();
}
private void constructWrappers() {
m_repositoryWrappers = new ArrayList();
for (Iterator i = m_repositorySet.getRepositories().iterator();
i.hasNext();
) {
m_repositoryWrappers.add(
new RepositoryWrapper((Repository) i.next(), m_context));
}
if (m_repositoryWrappers.isEmpty())
Logger.getLogger().debug("No wrappers constructed");
}
// :TODO: Work in progress ...
// Do we make it 'high level' (1 list of unique groups returned)
// or low level?
/*
public List listGroups() {
List allGroups = null;
int repoCnt = 0;
for (Iterator i = m_repositorySet.getRepositories().iterator();
i.hasNext();
repoCnt++) {
Repository r = (Repository) i.next();
RepositoryWrapper repo = new RepositoryWrapper(r, m_context);
Logger.getLogger().info("Repository: " + repo);
try {
// List groups ...
List groups = repo.listGroups(AllSelector.getInstance());
for (Iterator gi = groups.iterator(); i.hasNext();) {
ArtifactGroup group = (ArtifactGroup) gi.next();
Logger.getLogger().info(" - Group: " + group);
}
}
catch (UpdateException re) {
Logger.getLogger().warn(
" - Failed to list groups: " + re.getLocalizedMessage());
}
}
return allGroups;
}
*/
/**
* Is this empty (or does it contain repositories)?
*
* @return true = empty
*/
public boolean isEmpty() {
return m_repositorySet.isEmpty();
}
/**
* @return
*/
public RepositorySet getRepositorySet() {
return m_repositorySet;
}
/**
* @return
*/
public List getRepositoryWrappers() {
return m_repositoryWrappers;
}
public void dump(PrintWriter out, int depth, boolean verbose) {
//String indent = DebugUtils.getIndent(depth);
DebugUtils.dump(out, depth + 1, "Context: ", verbose, m_context);
DebugUtils.printSeparator(out, depth + 1);
DebugUtils.dump(out, depth + 1, "Repositories: ", verbose,
m_repositorySet);
}
}
--- NEW FILE: package.html ---
<body>
<p>The standard Ruper implementation.</p>
</body>
--- NEW FILE: ReferenceManager.java ---
/*
* Copyright 2004 The Apache Software Foundation
*
* 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.krysalis.depot.update.impl;
import java.lang.reflect.Constructor;
import java.util.HashMap;
import java.util.Map;
import org.krysalis.depot.common.log.Logger;
import org.krysalis.depot.common.util.debug.DebugUtils;
import org.krysalis.depot.update.config.UpdaterConfig;
import org.krysalis.depot.update.util.identity.GenericIdentifier;
import org.krysalis.depot.update.util.identity.GenericNamespace;
import org.krysalis.depot.update.util.reference.IReferenceable;
import org.krysalis.depot.update.util.reference.NoSuchReferenceException;
import org.krysalis.depot.update.util.reference.ReferenceTable;
import org.krysalis.depot.update.util.text.MessageConstants;
import org.krysalis.depot.update.util.text.Messages;
/**
* @author arb_jack
*/
public final class ReferenceManager {
private static Map l_tables = new HashMap();
//:TODO: Make chainable to support scoping?
//:TODO: If so, add one to ResourceUpdaterContext & keep a global
private ReferenceManager() {
UpdaterConfig.configure();
}
/**
* Does this ReferenceManager have an entry for this identifier?
*
* @param identifier
* @return true = yes
*/
public static boolean hasReference(GenericIdentifier identifier) {
boolean hasReference = false;
GenericNamespace ns = identifier.getNamespace();
synchronized (l_tables) {
ReferenceTable table = (ReferenceTable) l_tables.get(ns);
if (null == table) {
hasReference = false;
} else {
hasReference = table.hasReference(identifier);
}
}
return hasReference;
}
/**
* Get the referenced object.
*
* @param identifier
* @return
* @throws NoSuchReferenceException
*/
public static Object getReference(GenericIdentifier identifier)
throws NoSuchReferenceException {
Object reference = null;
GenericNamespace ns = identifier.getNamespace();
synchronized (l_tables) {
ReferenceTable table = (ReferenceTable) l_tables.get(ns);
if (null == table)
throw new NoSuchReferenceException(identifier);
reference = table.getReference(identifier);
if (null == reference)
throw new NoSuchReferenceException(identifier);
}
return reference;
}
public static void createReference(IReferenceable referenceable) {
GenericIdentifier identifier = referenceable.getIdentifier();
GenericNamespace ns = identifier.getNamespace();
synchronized (l_tables) {
ReferenceTable table = (ReferenceTable) l_tables.get(ns);
if (null == table) {
table = new ReferenceTable(ns);
l_tables.put(ns, table);
}
table.createReference(referenceable);
}
}
public static Object createObject(Class clazz, String tagId, String refId) {
Object reference = null;
try {
if (refId == null) {
Class[] argumentTypes = {java.lang.String.class};
Constructor idArgumentConstructor = clazz.getDeclaredConstructor(argumentTypes);
idArgumentConstructor.setAccessible(true);
reference = idArgumentConstructor.newInstance(new Object[]{tagId});
} else {
//TODO clone the object
}
} catch (Exception exp) {
Logger.getLogger().error(
Messages.getString(MessageConstants.CREATE_OBJECT_ERROR),
exp);
}
return reference;
}
public static Object createReferenceObject(Class clazz, String tagId,
String refId) {
Object reference = createObject(clazz, tagId, refId);
//add the object to the reference table
createReference((IReferenceable) reference);
return reference;
}
public static void dump() {
DebugUtils.dump("References...", l_tables);
}
}
--- NEW FILE: ArtifactUpdaterContext.java ---
/*
* Copyright 2004 The Apache Software Foundation
*
* 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.krysalis.depot.update.impl;
import java.io.File;
import org.krysalis.depot.update.ArtifactUpdaterOptions;
import org.krysalis.depot.update.UpdateException;
import org.krysalis.depot.update.protocols.DefaultProtocolOperationsManager;
import org.krysalis.depot.update.protocols.ProtocolOperationsManager;
import org.krysalis.depot.update.util.UpdateConstants;
import org.krysalis.depot.update.util.identity.GenericIdentifier;
import org.krysalis.depot.update.util.reference.IReferenceable;
import org.krysalis.version.util.SystemUtils;
/**
* The ArtifactUpdaterContext provides some contextual information for an Artifact
*
*
* @author <a href="http://incubator.apache.org/depot">The Apache Incubator Depot Project</a>
*/
public class ArtifactUpdaterContext implements IReferenceable {
public static class Identifier extends GenericIdentifier {
public final static String UPDATE_CONTEXT_URI =
"http://depot.apache.org/update/context";
public final static String UPDATE_CONTEXT_PREFIX = "context";
public Identifier(String id) {
super(UPDATE_CONTEXT_URI, UPDATE_CONTEXT_PREFIX, id);
}
}
private ArtifactUpdaterContext.Identifier m_identifier = null;
private ProtocolOperationsManager m_protocolManager = null;
private File m_baseFile = null;
private ArtifactUpdaterOptions m_options = null;
public ArtifactUpdaterContext(String identifier) {
m_baseFile = SystemUtils.getCWD();
initClass(new ArtifactUpdaterContext.Identifier(identifier));
}
public ArtifactUpdaterContext(ArtifactUpdaterContext.Identifier identifier) {
m_baseFile = SystemUtils.getCWD();
initClass(identifier);
}
public ArtifactUpdaterContext() {
m_baseFile = SystemUtils.getCWD();
initClass(new ArtifactUpdaterContext.Identifier(UpdateConstants.DEFAULT));
}
public ArtifactUpdaterContext(File baseFile) {
m_baseFile = baseFile;
initClass(new ArtifactUpdaterContext.Identifier(UpdateConstants.DEFAULT));
}
private void initClass(ArtifactUpdaterContext.Identifier identifier) {
m_identifier = identifier;
}
public static ArtifactUpdaterContext getDefaultContext() {
ArtifactUpdaterContext context = new ArtifactUpdaterContext();
context.setProtocolManager(
new DefaultProtocolOperationsManager(context));
return context;
}
public static ArtifactUpdaterContext getTestContext() {
ArtifactUpdaterContext context = new ArtifactUpdaterContext();
context.setProtocolManager(
new DefaultProtocolOperationsManager(context));
return context;
}
/**
* @return
*/
public ProtocolOperationsManager getProtocolManager() {
return m_protocolManager;
}
/**
* @param manager
*/
public void setProtocolManager(ProtocolOperationsManager manager) {
m_protocolManager = manager;
}
/**
* Does this content already have a protocol manager?
*
* @return true = yes
*/
public boolean hasProtocolManager()
{
return (null != m_protocolManager);
}
/**
* @return
*/
public File getBaseFile() {
return m_baseFile;
}
/**
* @param file
*/
public void setBaseFile(File file) {
m_baseFile = file;
}
/**
* @return
*/
public GenericIdentifier getIdentifier() {
return m_identifier;
}
/**
* @return Returns the options.
*/
public ArtifactUpdaterOptions getOptions() {
return m_options;
}
public static ArtifactUpdaterContext getResourceUpdaterContext(
ArtifactUpdaterContext.Identifier identifier,
boolean createIfRequired)
throws UpdateException {
ArtifactUpdaterContext context = null;
if (ReferenceManager.hasReference(identifier)) {
context =
(ArtifactUpdaterContext) ReferenceManager.getReference(
identifier);
}
else {
if (!createIfRequired)
throw new UpdateException(
"Failed to access ResourceUpdaterContext ["
+ identifier
+ "]");
context = new ArtifactUpdaterContext(identifier);
ReferenceManager.createReference(context);
}
return context;
}
}
--- NEW FILE: RepositoryWrapper.java ---
/*
* Copyright 2004 The Apache Software Foundation
*
* 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.krysalis.depot.update.impl;
import java.io.PrintWriter;
import java.util.Iterator;
import java.util.List;
import org.krysalis.depot.common.log.Logger;
import org.krysalis.depot.common.util.debug.DebugUtils;
import org.krysalis.depot.common.util.debug.Dumpable;
import org.krysalis.depot.update.ArtifactInstance;
import org.krysalis.depot.update.Repository;
import org.krysalis.depot.update.RepositoryManifest;
import org.krysalis.depot.update.UpdateException;
import org.krysalis.depot.update.artifact.ArtifactGroup;
import org.krysalis.depot.update.monitor.ArtifactEvent;
import org.krysalis.depot.update.monitor.Monitor;
import org.krysalis.depot.update.repository.RepositoryCapability;
import org.krysalis.depot.update.repository.RepositoryException;
import org.krysalis.depot.update.util.select.ISelector;
import org.krysalis.depot.update.util.text.MessageConstants;
import org.krysalis.depot.update.util.text.Messages;
/**
* @author arb_jack
*/
public class RepositoryWrapper implements Dumpable {
private Repository m_repository = null;
private ArtifactUpdaterContext m_context = null;
private boolean m_initialized = false;
public RepositoryWrapper(
Repository repository,
ArtifactUpdaterContext context) {
m_repository = repository;
m_context = context;
}
private synchronized void initialize(ArtifactUpdaterContext context)
throws UpdateException {
if (m_initialized)
return;
try {
m_repository.initialize(context);
}
catch (Exception e) {
throw new RepositoryException(
m_repository,
Messages.getString(
MessageConstants.INITIALIZE_FAILED,
new Object[] { m_repository, e }),
e);
}
m_initialized = true;
}
/**
* Return a list of ArtifactGroups, using selector
* @param selector
* @return
*/
public List listGroups(ISelector selector) throws UpdateException {
Logger.getLogger().debug(
Messages.getString(
MessageConstants.LIST_GROUPS,
new Object[] { m_repository, selector }));
testCapability(RepositoryCapability.LISTABLE_GROUPS);
if (!m_initialized)
initialize(m_context);
List groups = null;
try {
groups = m_repository.listGroups(m_context, selector);
}
catch (Exception e) {
throw new RepositoryException(
m_repository,
Messages.getString(
MessageConstants.LIST_GROUPS_FAILED,
new Object[] { m_repository, selector, e }),
e);
}
return groups;
}
/**
* Return a list of ArtifactSpeficiers, using selector
*
* Hmm, is this not just another query?
*
* @param selector
* @return
*/
public List listArtifacts(ArtifactGroup group, ISelector selector)
throws UpdateException {
Logger.getLogger().debug(
Messages.getString(
MessageConstants.LIST_ARTIFACTS,
new Object[] { m_repository, group, selector }));
testCapability(RepositoryCapability.LISTABLE_ARTIFACTS);
if (!m_initialized)
initialize(m_context);
List categories = null;
try {
categories =
m_repository.listArtifacts(m_context, group, selector);
}
catch (Exception e) {
throw new RepositoryException(
m_repository,
MessageConstants.LIST_ARTIFACTS_FAILED,
e);
}
return categories;
}
/**
* Return a Manifest of Artifacts, using selector
*
* :TODO: Hmm, is this not just another query?
*
* @param selector
* @return
*/
public RepositoryManifest getManifest(
ArtifactGroup group,
ISelector selector)
throws UpdateException {
Logger.getLogger().debug(
Messages.getString(
MessageConstants.GET_GROUP_MANIFEST,
new Object[] { m_repository, group, selector }));
testCapability(RepositoryCapability.GROUP_MANIFEST);
if (!m_initialized)
initialize(m_context);
RepositoryManifest manifest = null;
try {
manifest = m_repository.getManifest(m_context, group, selector);
}
catch (Exception e) {
throw new RepositoryException(
m_repository,
MessageConstants.LIST_ARTIFACTS_FAILED,
e);
}
return manifest;
}
/**
* Return a list of contents, using selector
*
* @param selector
* @return
*/
public List listInstances(ArtifactGroup group, ISelector selector)
throws UpdateException {
Logger.getLogger().debug(
Messages.getString(
MessageConstants.LIST_RESOURCES,
new Object[] { m_repository, group, selector }));
if (!m_initialized)
initialize(m_context);
List resources = null;
try {
resources = m_repository.listInstances(m_context, group, selector);
// Notify what resources were listed
for (Iterator i = resources.iterator(); i.hasNext();) {
Monitor.getMonitor().notify(
new ArtifactEvent(
ArtifactEvent.LISTED,
(ArtifactInstance) i.next()));
}
}
catch (Exception e) {
throw new RepositoryException(
m_repository,
Messages.getString(
MessageConstants.LIST_RESOURCES_FAILED,
new Object[] { m_repository, group, selector, e }),
e);
}
return resources;
}
/**
* Delete a resource from the Repository
*
* @param selector
* @return
*/
public void deleteArtifact(ArtifactInstance resource) throws UpdateException {
Logger.getLogger().debug(
Messages.getString(
MessageConstants.DELETE_RESOURCE,
new Object[] { m_repository, resource }));
testCapability(RepositoryCapability.DELETABLE);
if (!m_initialized)
initialize(m_context);
try {
m_repository.deleteArtifact(m_context, resource);
}
catch (Exception e) {
throw new RepositoryException(
m_repository,
Messages.getString(
MessageConstants.DELETE_RESOURCE_FAILED,
new Object[] { m_repository, resource }),
e);
}
}
/**
* Publish a resource to the repository
*
* @param selector
* @return
*/
public ArtifactInstance publishArtifact(ArtifactInstance instance) throws UpdateException {
Logger.getLogger().debug(
Messages.getString(
MessageConstants.PUBLISH_RESOURCE,
new Object[] { m_repository, instance }));
testCapability(RepositoryCapability.PUBLISHABLE);
if (!m_initialized)
initialize(m_context);
ArtifactInstance publishedArtifact = null;
try {
publishedArtifact =
m_repository.publishArtifact(m_context, instance);
}
catch (Exception e) {
throw new RepositoryException(m_repository, "Publish Failed", e);
}
return publishedArtifact;
}
private void testCapability(RepositoryCapability capability)
throws UpdateException {
if (!m_repository.hasCapability(capability)) {
throw new RepositoryException(
m_repository,
"Unsupported capability : " + capability);
}
}
public String toString() {
return m_repository==null?"null":m_repository.toString();
}
public void dump(PrintWriter out, int depth, boolean verbose) {
String indent = DebugUtils.getIndent(depth);
out.print(indent);
out.println("Repository: " + m_repository);
DebugUtils.dump(out, depth, verbose, m_repository);
}
}
-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://productguide.itmanagersjournal.com/