mcconnell    2004/03/07 17:36:08

  Added:       merlin/facilities/finder/ecm .cvsignore maven.xml
                        project.xml
               merlin/facilities/finder/ecm/src/java/org/apache/avalon/finder/ecm
                        DefaultRoleManager.java ECM.java RoleManager.java
               merlin/facilities/finder/ecm/src/java/org/apache/avalon/finder/ecm/info
                        Hint.java Role.java
               merlin/facilities/finder/ecm/src/test/org/apache/avalon/finder/ecm/test
                        ECMTestCase.java
  Log:
  Fragments of an inital ECM adapter.
  
  Revision  Changes    Path
  1.1                  avalon/merlin/facilities/finder/ecm/.cvsignore
  
  Index: .cvsignore
  ===================================================================
  *.log
  build.properties
  repository
  .classpath
  .project
  target
  
  
  1.1                  avalon/merlin/facilities/finder/ecm/maven.xml
  
  Index: maven.xml
  ===================================================================
  <project default="jar:install">
  
    <preGoal name="java:compile">
      <attainGoal name="avalon:meta"/>
    </preGoal>
  
  </project>
  
  
  
  1.1                  avalon/merlin/facilities/finder/ecm/project.xml
  
  Index: project.xml
  ===================================================================
  <?xml version="1.0" encoding="ISO-8859-1"?>
  
  <project>
  
    <extend>${basedir}/../../../project.xml</extend>
  
    <groupId>avalon-finder</groupId>
    <id>avalon-finder-ecm</id>
    <name>Avalon Finder ECM Adapter</name>
    <currentVersion>SNAPSHOT</currentVersion>
    <shortDescription>Avalon ECM Adapter</shortDescription>
    <package>org.apache.avalon.finder.ecm</package>
  
    <dependencies>
  
      <!-- implementation dependencies -->
  
      <dependency>
        <groupId>avalon-finder</groupId>
        <artifactId>avalon-finder-api</artifactId>
        <version>SNAPSHOT</version>
      </dependency>
      <dependency>
        <groupId>avalon-framework</groupId>
        <artifactId>avalon-framework-api</artifactId>
        <version>4.1.5</version>
      </dependency>
  
    </dependencies>
    
  </project>
  
  
  
  1.1                  
avalon/merlin/facilities/finder/ecm/src/java/org/apache/avalon/finder/ecm/DefaultRoleManager.java
  
  Index: DefaultRoleManager.java
  ===================================================================
  /*
   * Copyright 2004 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.apache.avalon.finder.ecm;
  
  import org.apache.avalon.finder.Finder;
  import org.apache.avalon.finder.FinderException;
  
  import org.apache.avalon.framework.logger.Logger;
  import org.apache.avalon.framework.configuration.Configuration;
  import org.apache.avalon.framework.configuration.ConfigurationException;
  import org.apache.avalon.framework.configuration.Configurable;
  
  import org.apache.avalon.finder.ecm.info.Role;
  import org.apache.avalon.finder.ecm.info.Hint;
  
  /**
   * The default implementation of an ECM RoleManager.
   *
   * @avalon.component name="roles" lifestyle="singleton"
   * @avalon.service type="org.apache.avalon.finder.ecm.RoleManager"
   * @author <a href="mailto:[EMAIL PROTECTED]">Avalon Development Team</a>
   * @version $Revision: 1.1 $ $Date: 2004/03/08 01:36:08 $
   */
  public class DefaultRoleManager implements RoleManager, Configurable
  {
      private Role[] m_roles;
  
      public void configure( Configuration config ) 
        throws ConfigurationException
      {
          Configuration[] children = config.getChildren( "role" );
          Role[] roles = new Role[ children.length ];
          for( int i=0; i<children.length; i++ )
          {
               Configuration child = children[i];
               Role role = buildRole( child );
               roles[i] = role;
          }
          m_roles = roles;
      }
  
      //-----------------------------------------------------------
      // RoleManager
      //-----------------------------------------------------------
  
      public Role getNamedRole( String name )
      {
          for( int i=0; i<m_roles.length; i++ )
          {
              Role role = m_roles[i];
              if( role.getName().equals( name ) )
              {
                  return role;
              }
          }
          return null;
      }
  
      //-----------------------------------------------------------
      // internals
      //-----------------------------------------------------------
  
      private Role buildRole( Configuration config )
        throws ConfigurationException
      {
          String name = config.getAttribute( "name" );
          String shorthand = config.getAttribute( "shorthand" );
          String defaultClassname = config.getAttribute( "default-class" );
          Configuration[] children = config.getChildren( "hint" );
          Hint[] hints = new Hint[ children.length ];
          for( int i=0; i<children.length; i++ )
          {
               Configuration child = children[i];
               Hint hint = buildHint( child );
               hints[i] = hint;
          }
          return new Role( name, shorthand, defaultClassname, hints );
      }
  
      private Hint buildHint( Configuration config )
        throws ConfigurationException
      {
          String shorthand = config.getAttribute( "shorthand" );
          String classname = config.getAttribute( "class" );
          return new Hint( shorthand, classname );
      }
  }
  
  
  
  1.1                  
avalon/merlin/facilities/finder/ecm/src/java/org/apache/avalon/finder/ecm/ECM.java
  
  Index: ECM.java
  ===================================================================
  /*
   * Copyright 2004 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.apache.avalon.finder.ecm;
  
  import org.apache.avalon.finder.Finder;
  import org.apache.avalon.finder.FinderException;
  
  import org.apache.avalon.framework.logger.Logger;
  import org.apache.avalon.framework.service.ServiceManager;
  import org.apache.avalon.framework.service.ServiceException;
  
  /**
   * A default implementation of a finder service that provides 
   * support for pull-based service activation semantics. The default 
   * implementation deals with activation of standard avalon components
   * (i.e. components that declare semantics using the Avalon Meta 
   * contract).
   *
   * @avalon.component name="ecm" lifestyle="singleton"
   * @avalon.service type="org.apache.avalon.framework.service.ServiceManager"
   * @author <a href="mailto:[EMAIL PROTECTED]">Avalon Development Team</a>
   * @version $Revision: 1.1 $ $Date: 2004/03/08 01:36:08 $
   */
  public class ECM implements ServiceManager
  {
      //---------------------------------------------------------
      // immutable state
      //---------------------------------------------------------
  
      /**
       * The logging channel for this component.
       */
      private final Logger m_logger;
  
      /**
       * The finder that will handle pull-based service activation.
       */
      private final Finder m_finder;
  
      /**
       * The roled managers.
       */
      private final RoleManager m_manager;
  
      //---------------------------------------------------------
      // constructor
      //---------------------------------------------------------
  
     /**
      * Creation of a new ecm finder.  The finder is supplied 
      * a logging channel and a service manager.  The implementation
      * aquires a classic finder the handle pull based service 
      * aquisition and a role manager to handle key dereferencing.
      * 
      * @param logger the container assigned logging channel
      * @param manager the container assigned service manager
      * @avalon.dependency key="finder"
      *    type="org.apache.avalon.finder.Finder" 
      * @avalon.dependency key="roles"
      *    type="org.apache.avalon.finder.ecm.RoleManager" 
      */
      public ECM( 
        final Logger logger, ServiceManager manager ) 
        throws ServiceException
      {
          assertNotNull( logger, "logger" );
          assertNotNull( manager, "manager" );
  
          m_logger = logger;
          m_finder = (Finder) manager.lookup( "finder" );
          m_manager = (RoleManager) manager.lookup( "roles" );
      }
  
      //---------------------------------------------------------
      // ServiceManager
      //---------------------------------------------------------
  
     /**
      * Return true if the supplied key maps to a known 
      * service.
      * 
      * @return TRUE if the key identifies a known service
      */ 
      public boolean hasService( String key )
      {
          throw new UnsupportedOperationException( "hasService" );
      }
  
      public Object lookup( String key ) throws ServiceException
      {
          throw new UnsupportedOperationException( "lookup" );
      }
  
      public void release( Object object )
      {
          throw new UnsupportedOperationException( "release" );
      }
  
      //---------------------------------------------------------
      // private implementation
      //---------------------------------------------------------
  
      private void assertNotNull( Object object, String key )
      {
          if( null == object )
          {
              throw new NullPointerException( key );
          }
      }
  
      private Logger getLogger()
      {
          return m_logger;
      }
  }
  
  
  
  1.1                  
avalon/merlin/facilities/finder/ecm/src/java/org/apache/avalon/finder/ecm/RoleManager.java
  
  Index: RoleManager.java
  ===================================================================
  /*
   * Copyright 2004 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.apache.avalon.finder.ecm;
  
  import org.apache.avalon.finder.Finder;
  import org.apache.avalon.finder.FinderException;
  
  import org.apache.avalon.framework.logger.Logger;
  import org.apache.avalon.framework.service.ServiceManager;
  import org.apache.avalon.framework.service.ServiceException;
  
  import org.apache.avalon.finder.ecm.info.Role;
  
  /**
   * A service interface that defines a set of management operations
   * that can be performed relative to the information expressed in 
   * an ECM style roles.xml file.
   *
   * @avalon.component name="roles" lifestyle="singleton"
   * @avalon.service type="org.apache.avalon.finder.ecm.RoleManager"
   * @author <a href="mailto:[EMAIL PROTECTED]">Avalon Development Team</a>
   * @version $Revision: 1.1 $ $Date: 2004/03/08 01:36:08 $
   */
  public interface RoleManager
  {
      Role getNamedRole( String name );
  }
  
  
  
  1.1                  
avalon/merlin/facilities/finder/ecm/src/java/org/apache/avalon/finder/ecm/info/Hint.java
  
  Index: Hint.java
  ===================================================================
  /*
   * Copyright 2004 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.apache.avalon.finder.ecm.info;
  
  /**
   * Immutable descriptor of a hint.
   *
   * @author <a href="mailto:[EMAIL PROTECTED]">Avalon Development Team</a>
   * @version $Revision: 1.1 $ $Date: 2004/03/08 01:36:08 $
   */
  public class Hint
  {
      private final String m_shorthand;
      private final String m_classname;
  
      public Hint( final String shorthand, String classname )
      {
          m_shorthand = shorthand;
          m_classname = classname;
      }
  
      public String getShorthand()
      {
          return m_shorthand;
      }
  
      public String getClassname()
      {
          return m_classname;
      }
  }
  
  
  
  1.1                  
avalon/merlin/facilities/finder/ecm/src/java/org/apache/avalon/finder/ecm/info/Role.java
  
  Index: Role.java
  ===================================================================
  /*
   * Copyright 2004 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.apache.avalon.finder.ecm.info;
  
  /**
   * An immutable descriptor of a role.
   *
   * @author <a href="mailto:[EMAIL PROTECTED]">Avalon Development Team</a>
   * @version $Revision: 1.1 $ $Date: 2004/03/08 01:36:08 $
   */
  public class Role
  {
      private final String m_name;
      private final String m_shorthand;
      private final String m_classname;
      private final Hint[] m_hints;
  
      public Role( 
        final String name, final String shorthand, String classname, 
        Hint[] hints )
      {
          m_name = name;
          m_shorthand = shorthand;
          m_classname = classname;
          m_hints = hints;
      }
  
      public String getName()
      {
          return m_name;
      }
  
      public String getShorthand()
      {
          return m_shorthand;
      }
  
      public String getDefaultClassname()
      {
          return m_classname;
      }
  
      public Hint[] getHints()
      {
          return m_hints;
      }
  }
  
  
  
  1.1                  
avalon/merlin/facilities/finder/ecm/src/test/org/apache/avalon/finder/ecm/test/ECMTestCase.java
  
  Index: ECMTestCase.java
  ===================================================================
  /*
   * Copyright 2004 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.apache.avalon.finder.ecm.test;
  
  import junit.framework.TestCase;
  
  import org.apache.avalon.finder.ecm.ECM;
  import org.apache.avalon.framework.service.ServiceManager;
  
  /**
   * DefaultFinder testcase.
   *
   * @author <a href="mailto:[EMAIL PROTECTED]">Avalon Development Team</a>
   * @version $Revision: 1.1 $ $Date: 2004/03/08 01:36:08 $
   */
  public class ECMTestCase extends TestCase
  {
      //--------------------------------------------------------
      // constructors
      //--------------------------------------------------------
  
     /**
      * @param name the name of the test case
      */
      public ECMTestCase( String name )
      {
          super( name );
      }
  
      //--------------------------------------------------------
      // testcase
      //--------------------------------------------------------
  
      public void testECMConstructor() throws Exception
      {
          try
          {
              ServiceManager ecm = new ECM( null, null );
              fail( "did not throw an NPE" );
          }
          catch( NullPointerException npe )
          {
              // good
          }
          catch( Throwable bad )
          {
              fail( "unexpected constructor error: " + bad.toString() );
          }
      }
  }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to