hivemind-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hls...@apache.org
Subject cvs commit: jakarta-hivemind/framework/src/java/org/apache/hivemind/schema/rules QualifiedIdTranslator.java IdListTranslator.java
Date Wed, 09 Jun 2004 14:48:40 GMT
hlship      2004/06/09 07:48:40

  Added:       framework/src/java/org/apache/hivemind/util IdUtils.java
               framework/src/java/org/apache/hivemind/schema/rules
                        QualifiedIdTranslator.java IdListTranslator.java
  Log:
  Add two new translators: qualified-id and id-list.
  
  Revision  Changes    Path
  1.1                  jakarta-hivemind/framework/src/java/org/apache/hivemind/util/IdUtils.java
  
  Index: IdUtils.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.apache.hivemind.util;
  
  import org.apache.hivemind.HiveMind;
  
  /**
   * A collection of utilities for handling qualified and unqualified ids.
   *
   * @author Howard Lewis Ship
   */
  public class IdUtils
  {
  
      /**
       * Returns a fully qualfied id.  If the id contains a '.', then it
       * is returned unchanged.  Otherwise, the module's id is prefixed (with a 
       * seperator '.') and returned;
       */
      public static String qualify(String moduleId, String id)
      {
          if (id.indexOf('.') > 0)
              return id;
  
          return moduleId + "." + id;
      }
  
      /**
       * Qualifies a list of interceptor service ids provided for an interceptor
       * contribution.  The special value "*" is not qualified.
       */
      public static String qualifyList(String sourceModuleId, String list)
      {
          if (HiveMind.isBlank(list) || list.equals("*"))
              return list;
  
          String[] items = StringUtils.split(list);
  
          for (int i = 0; i < items.length; i++)
              items[i] = qualify(sourceModuleId, items[i]);
  
          return StringUtils.join(items, ',');
      }
  }
  
  
  
  1.1                  jakarta-hivemind/framework/src/java/org/apache/hivemind/schema/rules/QualifiedIdTranslator.java
  
  Index: QualifiedIdTranslator.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.apache.hivemind.schema.rules;
  
  import org.apache.hivemind.internal.Module;
  import org.apache.hivemind.schema.Translator;
  import org.apache.hivemind.util.IdUtils;
  
  /**
   * A {@link org.apache.hivemind.schema.Translator} that acts as a wrapper around
   * the {@link org.apache.hivemind.util.IdUtils#qualify(String, String)} method.
   *
   * @author Howard Lewis Ship
   */
  public class QualifiedIdTranslator implements Translator
  {
      /**
       * @returns null if the inputValue is null, otherwise, invokes
       * {@link IdUtils#qualify(String, String)}.
       */
      public Object translate(Module contributingModule, Class propertyType, String inputValue)
      {
          if (inputValue == null)
              return null;
  
          return IdUtils.qualify(contributingModule.getModuleId(), inputValue);
      }
  
  }
  
  
  
  1.1                  jakarta-hivemind/framework/src/java/org/apache/hivemind/schema/rules/IdListTranslator.java
  
  Index: IdListTranslator.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.apache.hivemind.schema.rules;
  
  import org.apache.hivemind.internal.Module;
  import org.apache.hivemind.schema.Translator;
  import org.apache.hivemind.util.IdUtils;
  
  /**
   * A {@link org.apache.hivemind.schema.Translator} that acts as a wrapper
   * around {@link org.apache.hivemind.util.IdUtils#qualifyList(String, String)}.
   *
   * @author Howard Lewis Ship
   */
  public class IdListTranslator implements Translator
  {
  
      public Object translate(Module contributingModule, Class propertyType, String inputValue)
      {
          if (inputValue == null)
              return null;
  
          return IdUtils.qualifyList(contributingModule.getModuleId(), inputValue);
      }
  
  }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: hivemind-cvs-unsubscribe@jakarta.apache.org
For additional commands, e-mail: hivemind-cvs-help@jakarta.apache.org


Mime
View raw message